Menu

#113 TWindow::SetWindowFont overload for TFont

7
closed
API (116)
1
2022-07-29
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 font for a control. OWLNext currently requires that the parent (dialog) manages the lifetime of the font, which requires additional class members (e.g. TFont objects). What we need is the ability to pass a TFont to TWindow::SetWindowFont and forget about it.

Related

Bugs: #507
Commit: [r8608]
Discussion: Selecting and restoring objects in TDC
Discussion: How to change the FONT attributes after TDalog has been created ?
Discussion: 214f1787
Discussion: TFontText
Discussion: TWindow::Create fails for TTooltip after port to OWLNext 7
Discussion: Font size on TEdit
Discussion: Font size on TEdit
Discussion: Example
News: 2026/08/owlet---gdi-overhaul-and-new-shared-pointer-semantics
Wiki: Frequently_Asked_Questions

Discussion

  • Vidar Hasfjord

    Vidar Hasfjord - 2017-02-23

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

    Note that a TFont object can be an owner or a non-owner of the underlying font handle. A copy of a TFont object does not create a new font. Both objects will share the underlying handle, and reference-counting is used to ensure that the handle is deleted when the last owner is destructed.

    The solution exploits these semantics. If a TFont is created as a temporary object at the point of call to SetWindowFont, the TFont copy constructor will share the handle with the callee. The reference count will be 2, then decremented to 1 as the temporary object is destructed after the call. The result is that the callee is now the owner of the font.

    However, note that a TFont can be a non-owner as well. In this case, there is no ownership transfer in the call, and the caller is responsible for ensuring that the font handle outlives the window:

    :::C++
    Label1.SetWindowFont(TFont{"Arial", -9}); // Font handle ownership transfer.
    Label1.SetWindowFont({"Arial", -9}); // Same as above; TFont is inferred.
    
    TFont f{GetWindowFont()}; // Aliasing; f does not own the handle.
    Label2.SetWindowFont(f); // No font handle ownership transfer.
    Label2.SetWindowFont(f.GetHandle()); // Equivalent to above.
    


    Please review.

     

    Related

    Commit: [r3731]
    Commit: [r3739]
    Commit: [r3744]


    Last edit: Vidar Hasfjord 2018-05-03
  • Vidar Hasfjord

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

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

    Vidar Hasfjord - 2021-12-04

    Unfortunately the fix implemented in [r4177] for the crash in the dispatch of WM_SETFONT causes a regression.

    See [bugs:#507] "Font change in SetupWindow is ignored (regression in 7.0)".

     

    Related

    Bugs: #507
    Commit: [r4177]

Anonymous
Anonymous

Add attachments
Cancel