From: Vadim Zeitlin Date: Sun, 28 Mar 2010 23:20:49 +0000 (+0000) Subject: Implement wxMask copy ctor for wxGTK. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/27297c823af2abf7351f4c7b3db7f116bdae6b00 Implement wxMask copy ctor for wxGTK. Without copy ctor copying masks simply crashed because the same pointer was deleted twice. Also added a (completely trivial but better than nothing...) unit test for wxBitmap to check that copying masks does work now. Closes #11854. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63774 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 1c4d35f355..fa9f11e616 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -503,6 +503,7 @@ All (GUI): GTK: - wxRadioBox constructor uses default consistent with other ports now. +- Implement wxMask copy ctor. - Partially implemented wxTextCtrl::GetStyle() (Igor Romanov). - Corrected themed border display. - Fix wxClipboard::GetData() for asymmetric wxDataObjects (Timothy Lee). diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h index 30c517a8ba..71f5d5b75c 100644 --- a/include/wx/gtk/bitmap.h +++ b/include/wx/gtk/bitmap.h @@ -21,6 +21,7 @@ class WXDLLIMPEXP_CORE wxMask: public wxMaskBase { public: wxMask(); + wxMask(const wxMask& mask); wxMask( const wxBitmap& bitmap, const wxColour& colour ); #if wxUSE_PALETTE wxMask( const wxBitmap& bitmap, int paletteIndex ); diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 0a519cf24e..c296558642 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -79,6 +79,23 @@ wxMask::wxMask() m_bitmap = NULL; } +wxMask::wxMask(const wxMask& mask) +{ + if ( !mask.m_bitmap ) + { + m_bitmap = NULL; + return; + } + + // create a copy of an existing mask + gint w, h; + gdk_drawable_get_size(mask.m_bitmap, &w, &h); + m_bitmap = gdk_pixmap_new(mask.m_bitmap, w, h, 1); + + wxGtkObject gc(gdk_gc_new(m_bitmap)); + gdk_draw_drawable(m_bitmap, gc, mask.m_bitmap, 0, 0, 0, 0, -1, -1); +} + wxMask::wxMask( const wxBitmap& bitmap, const wxColour& colour ) { m_bitmap = NULL; @@ -859,12 +876,7 @@ wxGDIRefData* wxBitmap::CloneGDIRefData(const wxGDIRefData* data) const } if (oldRef->m_mask != NULL) { - newRef->m_mask = new wxMask; - newRef->m_mask->m_bitmap = gdk_pixmap_new( - oldRef->m_mask->m_bitmap, oldRef->m_width, oldRef->m_height, 1); - wxGtkObject gc(gdk_gc_new(newRef->m_mask->m_bitmap)); - gdk_draw_drawable(newRef->m_mask->m_bitmap, - gc, oldRef->m_mask->m_bitmap, 0, 0, 0, 0, -1, -1); + newRef->m_mask = new wxMask(*oldRef->m_mask); } return newRef; diff --git a/tests/Makefile.in b/tests/Makefile.in index 06d196338f..4af8fdf6e8 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -135,6 +135,7 @@ TEST_GUI_OBJECTS = \ test_gui_rect.o \ test_gui_size.o \ test_gui_point.o \ + test_gui_bitmap.o \ test_gui_colour.o \ test_gui_ellipsization.o \ test_gui_measuring.o \ @@ -573,6 +574,9 @@ test_gui_size.o: $(srcdir)/geometry/size.cpp $(TEST_GUI_ODEP) test_gui_point.o: $(srcdir)/geometry/point.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/geometry/point.cpp +test_gui_bitmap.o: $(srcdir)/graphics/bitmap.cpp $(TEST_GUI_ODEP) + $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/graphics/bitmap.cpp + test_gui_colour.o: $(srcdir)/graphics/colour.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/graphics/colour.cpp diff --git a/tests/makefile.bcc b/tests/makefile.bcc index 241dc034fa..028783cda0 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -120,6 +120,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_rect.obj \ $(OBJS)\test_gui_size.obj \ $(OBJS)\test_gui_point.obj \ + $(OBJS)\test_gui_bitmap.obj \ $(OBJS)\test_gui_colour.obj \ $(OBJS)\test_gui_ellipsization.obj \ $(OBJS)\test_gui_measuring.obj \ @@ -627,6 +628,9 @@ $(OBJS)\test_gui_size.obj: .\geometry\size.cpp $(OBJS)\test_gui_point.obj: .\geometry\point.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\geometry\point.cpp +$(OBJS)\test_gui_bitmap.obj: .\graphics\bitmap.cpp + $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\graphics\bitmap.cpp + $(OBJS)\test_gui_colour.obj: .\graphics\colour.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\graphics\colour.cpp diff --git a/tests/makefile.gcc b/tests/makefile.gcc index 1aeb186b29..6bb33379a9 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -114,6 +114,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_rect.o \ $(OBJS)\test_gui_size.o \ $(OBJS)\test_gui_point.o \ + $(OBJS)\test_gui_bitmap.o \ $(OBJS)\test_gui_colour.o \ $(OBJS)\test_gui_ellipsization.o \ $(OBJS)\test_gui_measuring.o \ @@ -609,6 +610,9 @@ $(OBJS)\test_gui_size.o: ./geometry/size.cpp $(OBJS)\test_gui_point.o: ./geometry/point.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\test_gui_bitmap.o: ./graphics/bitmap.cpp + $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_gui_colour.o: ./graphics/colour.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index 6ca56cd97d..0f1e64a60f 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -115,6 +115,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_rect.obj \ $(OBJS)\test_gui_size.obj \ $(OBJS)\test_gui_point.obj \ + $(OBJS)\test_gui_bitmap.obj \ $(OBJS)\test_gui_colour.obj \ $(OBJS)\test_gui_ellipsization.obj \ $(OBJS)\test_gui_measuring.obj \ @@ -753,6 +754,9 @@ $(OBJS)\test_gui_size.obj: .\geometry\size.cpp $(OBJS)\test_gui_point.obj: .\geometry\point.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\geometry\point.cpp +$(OBJS)\test_gui_bitmap.obj: .\graphics\bitmap.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\graphics\bitmap.cpp + $(OBJS)\test_gui_colour.obj: .\graphics\colour.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\graphics\colour.cpp diff --git a/tests/makefile.wat b/tests/makefile.wat index 299502875f..007c9994d8 100644 --- a/tests/makefile.wat +++ b/tests/makefile.wat @@ -358,6 +358,7 @@ TEST_GUI_OBJECTS = & $(OBJS)\test_gui_rect.obj & $(OBJS)\test_gui_size.obj & $(OBJS)\test_gui_point.obj & + $(OBJS)\test_gui_bitmap.obj & $(OBJS)\test_gui_colour.obj & $(OBJS)\test_gui_ellipsization.obj & $(OBJS)\test_gui_measuring.obj & @@ -664,6 +665,9 @@ $(OBJS)\test_gui_size.obj : .AUTODEPEND .\geometry\size.cpp $(OBJS)\test_gui_point.obj : .AUTODEPEND .\geometry\point.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< +$(OBJS)\test_gui_bitmap.obj : .AUTODEPEND .\graphics\bitmap.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< + $(OBJS)\test_gui_colour.obj : .AUTODEPEND .\graphics\colour.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< diff --git a/tests/test.bkl b/tests/test.bkl index 4b85193a27..eac3d28888 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -116,6 +116,7 @@ geometry/rect.cpp geometry/size.cpp geometry/point.cpp + graphics/bitmap.cpp graphics/colour.cpp graphics/ellipsization.cpp graphics/measuring.cpp diff --git a/tests/test_test_gui.dsp b/tests/test_test_gui.dsp index afb37c5331..a22cc6ce74 100644 --- a/tests/test_test_gui.dsp +++ b/tests/test_test_gui.dsp @@ -235,6 +235,10 @@ LINK32=link.exe # PROP Default_Filter "" # Begin Source File +SOURCE=.\graphics\bitmap.cpp +# End Source File +# Begin Source File + SOURCE=.\sizers\boxsizer.cpp # End Source File # Begin Source File diff --git a/tests/test_vc7_test_gui.vcproj b/tests/test_vc7_test_gui.vcproj index dd00cfe5de..ea83d8c93c 100644 --- a/tests/test_vc7_test_gui.vcproj +++ b/tests/test_vc7_test_gui.vcproj @@ -565,6 +565,9 @@ Name="Source Files" Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> + + diff --git a/tests/test_vc8_test_gui.vcproj b/tests/test_vc8_test_gui.vcproj index 7ce61f53c7..6152dc7e6e 100644 --- a/tests/test_vc8_test_gui.vcproj +++ b/tests/test_vc8_test_gui.vcproj @@ -827,6 +827,10 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > + + diff --git a/tests/test_vc9_test_gui.vcproj b/tests/test_vc9_test_gui.vcproj index fd6952f626..7e40b0c087 100644 --- a/tests/test_vc9_test_gui.vcproj +++ b/tests/test_vc9_test_gui.vcproj @@ -799,6 +799,10 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > + +