lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] PATCH: Stop using wxClientDC unnecessarily


From: Vadim Zeitlin
Subject: [lmi] PATCH: Stop using wxClientDC unnecessarily
Date: Tue, 18 Oct 2022 02:30:56 +0200

 Hello,

 I'm thinking about deprecating wxClientDC in wxWidgets because in addition
to not working under Mac and GTK with Wayland backend, it now doesn't work
for drawing under MSW neither in wx master, since we've enabled double
buffering for all windows. This won't happen immediately (or maybe even at
all), but I'd still like to remove the only use of this class from lmi code
just not to have to remember to do it later if it does and because this use
is completely unnecessary and removing it seems like a good idea
independently of what happens to wxClientDC.

 After this long introduction, please let me introduce the small and trivial
patch itself (this is the result of git-format-patch output and can be
applied using git-am directly):

---------------------------------- >8 --------------------------------------
>From cce266666d5400f8342360318342bf90788bd8e6 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@tt-solutions.com>
Date: Tue, 18 Oct 2022 01:22:15 +0200
Subject: [PATCH] Don't use wxClientDC class unnecessarily

It is not really needed here as wxWindow itself provides the same
GetTextExtent() function too and not using it makes the code shorter and
simpler.

No real changes.
---
 rounding_view_editor.cpp | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/rounding_view_editor.cpp b/rounding_view_editor.cpp
index d2135b99f..d1c20431b 100644
--- a/rounding_view_editor.cpp
+++ b/rounding_view_editor.cpp
@@ -29,7 +29,6 @@

 #include <wx/bitmap.h>
 #include <wx/bmpbuttn.h>
-#include <wx/dcclient.h>                // class wxClientDC
 #include <wx/sizer.h>
 #include <wx/spinctrl.h>
 #include <wx/tglbtn.h>
@@ -228,12 +227,9 @@ RoundingButtons::RoundingButtons()
     ,unsigned int n
     )
 {
-    wxClientDC dc(window);
-    dc.SetFont(window->GetFont());
-
     wxCoord w, h;
     // Assume that 'W' is the widest letter.
-    dc.GetTextExtent("W", &w, &h);
+    window->GetTextExtent("W", &w, &h);

     wxSize size(w * n, h);
     size += window->GetSize() - window->GetClientSize();
--
2.36.0
---------------------------------- >8 --------------------------------------

 As you can see, it simply uses wxWindow::GetTextExtent() which does
exactly the same thing as the current code, but in a shorter and simpler
way.

 The corresponding commit is in xanadu/dont-use-client-dc branch and also
corresponds to https://github.com/let-me-illustrate/lmi/pull/222 

 This is not urgent at all, of course, but please apply it if you can.

 Thanks in advance!
VZ

Attachment: pgpPzdzy2hfmC.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]