2.7.2 ok?

Francesco Montorsi f18m_cpp217828 at yahoo.it
Tue Oct 31 05:53:41 PST 2006


Francesco Montorsi ha scritto:
> Vadim Zeitlin ha scritto:
>> On Tue, 31 Oct 2006 13:02:58 +0100 Francesco Montorsi =

>> <f18m_cpp217828 at yahoo.it> wrote:
>>
>> FM> The wxTextCtrl is not placed correctly now in the main frame
>>
>>  This is a bug in vertical/whatever toolbar patch, sorry. Fixing it right
>> now (fixed already, in fact, but need to test).
>>
>> FM> choose "controls" dialog it crashes in wxRadioBox::DoGetBestSize.
>>
>>  Fixed this too.
>>
>>  The remaining problem is the wrong menu item bitmaps background/lack of
>> transparency. If you could look into this, I'd appreciate it.
> I'm looking into it now.
> hope to solve it in few minutes.
ok - fixed.

Patch attached.

Note that maybe I've found an older problem in the copy constructor =

which I've marked with a FIXME.

Also I think some comments like the one "don't copy the bitmap data, but =

do copy the size, depth, ..." were not much sensed (as one line below =

the bitmap data was copied).

I also changed ownerdrawn to use SelectObjectAsSource() as performance =

optimization (after my patch it was causing a lot of uneeded UnShares).

It would be nice however to refactor the code and have a single =

CopyHBITMAP() function since I see that in wxDIB and wxBitmap, wxMask =

code that's a pretty common use.

Francesco


-------------- next part --------------
Index: include/wx/msw/bitmap.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /pack/cvsroots/wxwidgets/wxWidgets/include/wx/msw/bitmap.h,v
retrieving revision 1.58
diff -b -u -2 -r1.58 bitmap.h
--- include/wx/msw/bitmap.h	2006/10/30 19:26:02	1.58
+++ include/wx/msw/bitmap.h	2006/10/31 13:25:14
@@ -199,4 +199,7 @@
     wxMask();
 =

+    // Copy constructor
+    wxMask(const wxMask &mask);
+
     // Construct a mask from a bitmap and a colour indicating the transpar=
ent
     // area
Index: src/msw/bitmap.cpp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /pack/cvsroots/wxwidgets/wxWidgets/src/msw/bitmap.cpp,v
retrieving revision 1.150
diff -b -u -2 -r1.150 bitmap.cpp
--- src/msw/bitmap.cpp	2006/10/29 20:37:33	1.150
+++ src/msw/bitmap.cpp	2006/10/31 13:41:29
@@ -206,7 +206,11 @@
 #endif
 =

-    // can't copy the mask as the other bitmap destroys it
+    // (deep) copy the mask if present
     m_bitmapMask =3D NULL;
+    if (data.m_bitmapMask)
+        m_bitmapMask =3D new wxMask(*data.m_bitmapMask);
 =

+    // FIXME: shouldn't we copy the m_hBitmap handle too ?
+
     wxASSERT_MSG( !data.m_isDIB,
                     _T("can't copy bitmap locked for raw access!") );
@@ -261,9 +265,15 @@
         wxDIB dib((HBITMAP)(data->m_hBitmap));
         self->CopyFromDIB(dib);
+
+        wxBitmapRefData *selfdata =3D wx_static_cast(wxBitmapRefData *, se=
lf->m_refData);
+        wxASSERT(selfdata);     // something is very wrong if this fails!
+
+        // (deep) copy also the mask
+        selfdata->SetMask(new wxMask(*data->GetMask()));
     }
     else
 #endif // wxUSE_WXDIB
     {
-        // don't copy the bitmap data, but do copy the size, depth, ...
+        // copy the bitmap data
         self->m_refData =3D new wxBitmapRefData(*data);
     }
@@ -1326,4 +1336,36 @@
 {
     m_maskBitmap =3D 0;
+}
+
+// Copy constructor
+wxMask::wxMask(const wxMask &mask)
+{
+    BITMAP bmp;
+
+    HDC srcDC =3D CreateCompatibleDC(0);
+    HDC destDC =3D CreateCompatibleDC(0);
+
+    // GetBitmapDimensionEx won't work if SetBitmapDimensionEx wasn't used
+    // so we'll use GetObject() API here:
+    if (::GetObject((HGDIOBJ)mask.m_maskBitmap, sizeof(bmp), &bmp) =3D=3D =
0)
+    {
+        wxFAIL_MSG(wxT("Cannot retrieve the dimensions of the wxMask to co=
py"));
+        return;
+    }
+
+    // create our HBITMAP
+    int w =3D bmp.bmWidth, h =3D bmp.bmHeight;
+    m_maskBitmap =3D (WXHBITMAP)CreateCompatibleBitmap(srcDC, w, h);
+
+    // copy the mask's HBITMAP into our HBITMAP
+    SelectObject(srcDC, (HBITMAP) mask.m_maskBitmap);
+    SelectObject(destDC, (HBITMAP) m_maskBitmap);
+
+    BitBlt(destDC, 0, 0, w, h, srcDC, 0, 0, SRCCOPY);
+    =

+    SelectObject(srcDC, 0);
+    DeleteDC(srcDC);
+    SelectObject(destDC, 0);
+    DeleteDC(destDC);
 }
 =

Index: src/msw/ownerdrw.cpp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /pack/cvsroots/wxwidgets/wxWidgets/src/msw/ownerdrw.cpp,v
retrieving revision 1.71
diff -b -u -2 -r1.71 ownerdrw.cpp
--- src/msw/ownerdrw.cpp	2006/08/31 19:31:08	1.71
+++ src/msw/ownerdrw.cpp	2006/10/31 13:46:18
@@ -430,5 +430,5 @@
         {
             wxMemoryDC dcMem(&dc);
-            dcMem.SelectObject(bmp);
+            dcMem.SelectObjectAsSource(bmp);
 =

             // center bitmap


More information about the wx-dev mailing list