Menu

#112 TWindow::SetTextColor and GetTextColor

7
closed
API (105)
1
2020-05-18
2017-02-23
No

As discussed in the forum topic "TFontText" [discussion:214f1787], it would be nice to have a simple way to set the text color of a control. The current solution is pretty much the bare Windows API solution: implement an event handler for WM_CTLCOLORSTATIC etc. and override the text color in the device context passed to the handler. On the other hand, for the control background color TWindow::EvCtlColor already handles this for us. We can simply call TWindow::SetBkgndColor on the control, and EvCtlColor will handle the rest. What we need is a similar solution for text color, i.e. TWindow::SetTextColor and GetTextColor.

Related

Discussion: How to change the FONT attributes after TDalog has been created ?
Discussion: 214f1787
Discussion: TFontText
Discussion: Font size on TEdit
Wiki: Frequently_Asked_Questions

Discussion

  • Vidar Hasfjord

    Vidar Hasfjord - 2017-02-23

    This feature was implemented in Owlet in [r3734] and merged into the trunk in [r3743]. A new example, "examples/classes/static", was added in [r3744] to demonstrate the new feature.

    Note that the implementation of TWindow::EvCtlColor has been completely rewritten to support the new feature and enhance the logic. Color can now be set by the parent (dialog) or overridden individually by each child (control). If the child's color is TColor::None (the default) it will look to the parent for a color. If the parent's color is also TColor::None, then the system default is used (as provided by TWindow::DefaultProcessing). The parent will also handle colors for children that are not encapsulated by OWL. These will simply inherit the parent's color.

    The same logic is used for text and background color, so this change may affect background color settings as well. Hopefully it will not break existing code.

    Please review.

     

    Related

    Commit: [r3734]
    Commit: [r3743]
    Commit: [r3744]

  • Vidar Hasfjord

    Vidar Hasfjord - 2017-02-23
    • status: open --> pending
     
  • Sebastian Ledesma

    Good work!

     
  • Vidar Hasfjord

    Vidar Hasfjord - 2017-02-24
    • status: pending --> open
     
  • Vidar Hasfjord

    Vidar Hasfjord - 2017-02-24

    There is an issue in the new code. EvCtlColor doesn't always work correctly, and the dialog background color gets messed up. In one instance, I had a recursive stack overflow as well. I think it has to do with the WM_CTLCOLORDLG message. So I have reopened the ticket while I look for a solution.

     
  • Vidar Hasfjord

    Vidar Hasfjord - 2017-02-24

    I have now rewritten EvCtlColor due to the regressions. It no longer forwards the message to the child (control). Instead everything is handled at the parent (dialog) in the normal way. This avoids the regressions due to the message passing in the previous version. It is also simpler to understand, since you do not have to consider complex message routing, nor the different contexts for handling at the parent and handling at the child. And it is also more efficient. The only loss is that the WM_CTLCOLOR messages now can not be handled at the child, which admittedly was an unorthodox and brittle feature of the last version.

    The new implementation was committed on the Owlet branch in [r3750] and merged into the trunk in [r3751]. Please review.

     

    Related

    Commit: [r3750]
    Commit: [r3751]


    Last edit: Vidar Hasfjord 2017-02-24
  • Vidar Hasfjord

    Vidar Hasfjord - 2017-02-24
    • status: open --> pending
     
  • Vidar Hasfjord

    Vidar Hasfjord - 2018-03-06

    An improvement has been made in Owlet [r3894] to handle Combo Boxes. Combo Boxes encapsulated by TWindow (TComboBox) will now use the text and background colours, as specified by SetTextColor and SetBkgndColor, to render the Edit and List Box parts. Previously, the specified colours were not effective for Combo Boxes.

    This solution has not yet been merged into the trunk, since it is somewhat brute-force, i.e. needs to iterate over the children to locate the Combo Box owning the Edit or List Box handle passed through the ctl parameter to the EvCtlColor handler. However, I doubt this is an issue. If the feature proves to work well, it should be merged into the trunk.

     

    Related

    Commit: [r3894]

  • Vidar Hasfjord

    Vidar Hasfjord - 2020-05-18
    • Status: pending --> closed
     

Anonymous
Anonymous

Add attachments
Cancel