From aae91497f6ac36a76d3313cf405cae0f098ea1d1 Mon Sep 17 00:00:00 2001 From: Mattia Barbon Date: Thu, 27 Mar 2003 19:40:32 +0000 Subject: [PATCH] Removed some old cruft from wxBitmap, moved wxMotif- and wxControl-specific functionality (GetXXXPixmap) into a separate class, and fixed the implementation. Adapted wxStaticBitmap, wxBitmapButton and wxToolBar to the new situation. Various fixes to wxToolBar: Realize does not create buttons multiple times anymore, use the disabled bitmap as the disabled bitmap, not as the toggled bitmap for toggle buttons (!), reposition buttons/controls when a tool is removed/deleted. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19836 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- distrib/msw/tmake/filelist.txt | 2 + include/wx/motif/bitmap.h | 20 ++- include/wx/motif/bmpbuttn.h | 6 +- include/wx/motif/bmpmotif.h | 59 ++++++++ include/wx/motif/statbmp.h | 3 +- samples/toolbar/toolbar.cpp | 4 +- src/motif/bitmap.cpp | 72 +++++++--- src/motif/bmpbuttn.cpp | 18 ++- src/motif/bmpmotif.cpp | 204 ++++++++++++++++++++++++++ src/motif/files.lst | 5 +- src/motif/frame.cpp | 2 +- src/motif/statbmp.cpp | 7 +- src/motif/toolbar.cpp | 255 +++++++++++++++++++++------------ 13 files changed, 523 insertions(+), 134 deletions(-) create mode 100644 include/wx/motif/bmpmotif.h create mode 100644 src/motif/bmpmotif.cpp diff --git a/distrib/msw/tmake/filelist.txt b/distrib/msw/tmake/filelist.txt index 1e39a99f88..69f874cc28 100644 --- a/distrib/msw/tmake/filelist.txt +++ b/distrib/msw/tmake/filelist.txt @@ -622,6 +622,7 @@ accel.cpp Motif app.cpp Motif bitmap.cpp Motif bmpbuttn.cpp Motif +bmpmotif.cpp Motif button.cpp Motif checkbox.cpp Motif checklst.cpp Motif @@ -1249,6 +1250,7 @@ accel.h MotifH app.h MotifH bitmap.h MotifH bmpbuttn.h MotifH +bmpmotif.h MotifH button.h MotifH checkbox.h MotifH checklst.h MotifH diff --git a/include/wx/motif/bitmap.h b/include/wx/motif/bitmap.h index c23f4e315c..0ac2394b9b 100644 --- a/include/wx/motif/bitmap.h +++ b/include/wx/motif/bitmap.h @@ -76,9 +76,9 @@ public: int m_height; int m_depth; bool m_ok; - int m_numColors; + // XXX int m_numColors; wxPalette m_bitmapPalette; - int m_quality; + // XXX int m_quality; wxMask * m_bitmapMask; // Optional mask @@ -86,16 +86,22 @@ public: public: WXPixmap m_pixmap; WXDisplay* m_display; - bool m_freePixmap; + // XXX bool m_freePixmap; +#if 0 unsigned long* m_freeColors; long m_freeColorsCount; - +#endif + +#if 0 // These 5 variables are for wxControl WXPixmap m_insensPixmap ; WXPixmap m_labelPixmap ; WXPixmap m_armPixmap ; +#endif +#if 0 WXImage* m_image ; WXImage* m_insensImage ; +#endif }; #define M_BITMAPDATA ((wxBitmapRefData *)m_refData) @@ -186,11 +192,11 @@ public: int GetWidth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_width : 0); } int GetHeight() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_height : 0); } int GetDepth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_depth : 0); } - int GetQuality() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); } + // XXX int GetQuality() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); } void SetWidth(int w); void SetHeight(int h); void SetDepth(int d); - void SetQuality(int q); + // XXX void SetQuality(int q); void SetOk(bool isOk); wxPalette* GetPalette() const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); } @@ -210,9 +216,11 @@ public: public: WXDisplay* GetDisplay() const { return M_BITMAPDATA->m_display; } WXPixmap GetPixmap() const { return (WXPixmap) M_BITMAPDATA->m_pixmap; } +#if 0 virtual WXPixmap GetLabelPixmap(WXWidget w) ; virtual WXPixmap GetArmPixmap(WXWidget w) ; virtual WXPixmap GetInsensPixmap(WXWidget w = (WXWidget) 0) ; +#endif void SetPixmapNull() { M_BITMAPDATA->m_pixmap = 0; } protected: diff --git a/include/wx/motif/bmpbuttn.h b/include/wx/motif/bmpbuttn.h index 8ce933170d..30f3d86636 100644 --- a/include/wx/motif/bmpbuttn.h +++ b/include/wx/motif/bmpbuttn.h @@ -16,6 +16,8 @@ #pragma interface "bmpbuttn.h" #endif +#include "wx/motif/bmpmotif.h" + WXDLLEXPORT_DATA(extern const char*) wxButtonNameStr; #define wxDEFAULT_BUTTON_MARGIN 4 @@ -67,7 +69,9 @@ protected: // to reflect button background colour wxBitmap m_bmpSelectedOriginal; wxBitmap m_bmpDisabledOriginal; - + + wxBitmapCache m_bitmapCache; + WXPixmap m_insensPixmap; }; diff --git a/include/wx/motif/bmpmotif.h b/include/wx/motif/bmpmotif.h new file mode 100644 index 0000000000..d0003b7df6 --- /dev/null +++ b/include/wx/motif/bmpmotif.h @@ -0,0 +1,59 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: bmpmotif.h +// Purpose: Motif-specific bitmap routines +// Author: Julian Smart, originally in bitmap.h +// Modified by: +// Created: 25/03/2003 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_BMPMOTIF_H_ +#define _WX_BMPMOTIF_H_ + +#ifdef __GNUG__ +#pragma interface "bmpmotif.h" +#endif + +#include "wx/defs.h" +#include "wx/bitmap.h" + +class WXDLLEXPORT wxBitmapCache +{ +public: + wxBitmapCache() + { + m_labelPixmap = (WXPixmap)NULL; + m_armPixmap = (WXPixmap)NULL; + m_insensPixmap = (WXPixmap)NULL; + m_image = (WXImage)NULL; + m_display = (WXDisplay*)NULL; + SetColoursChanged(); + } + + ~wxBitmapCache(); + + void SetColoursChanged(); + void SetBitmap( const wxBitmap& bitmap ); + + WXPixmap GetLabelPixmap( WXWidget w ); + WXPixmap GetInsensPixmap( WXWidget w = (WXWidget)NULL ); + WXPixmap GetArmPixmap( WXWidget w ); +private: + void InvalidateCache(); + void CreateImageIfNeeded( WXWidget w ); + + struct + { + bool label : 1; + bool arm : 1; + bool insens : 1; + } m_recalcPixmaps; + wxBitmap m_bitmap; + WXDisplay* m_display; + WXPixmap m_labelPixmap, m_armPixmap, m_insensPixmap; + WXImage m_image; +}; + +#endif // _WX_BMPMOTIF_H_ diff --git a/include/wx/motif/statbmp.h b/include/wx/motif/statbmp.h index ae5698036b..004edc60af 100644 --- a/include/wx/motif/statbmp.h +++ b/include/wx/motif/statbmp.h @@ -16,7 +16,7 @@ #pragma interface "statbmp.h" #endif -#include "wx/control.h" +#include "wx/motif/bmpmotif.h" #include "wx/icon.h" WXDLLEXPORT_DATA(extern const char*) wxStaticBitmapNameStr; @@ -82,6 +82,7 @@ protected: protected: wxBitmap m_messageBitmap; wxBitmap m_messageBitmapOriginal; + wxBitmapCache m_bitmapCache; }; #endif diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index 1dd8595958..b08c9cae87 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -298,8 +298,8 @@ void MyFrame::RecreateToolbar() toolBar->AddTool(wxID_NEW, _T("New"), toolBarBitmaps[0], _T("New file")); toolBar->AddTool(wxID_OPEN, _T("Open"), toolBarBitmaps[1], _T("Open file")); - // neither the generic nor Motif native toolbars really support this -#if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXMOTIF__) && !defined(__WXX11__) || defined(__WXUNIVERSAL__) + // the generic toolbar doesn't really support this +#if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXX11__) || defined(__WXUNIVERSAL__) // adding a combo to a vertical toolbar is not very smart if ( m_horzToolbar ) { diff --git a/src/motif/bitmap.cpp b/src/motif/bitmap.cpp index 4e380b6df2..d9bb25a96d 100644 --- a/src/motif/bitmap.cpp +++ b/src/motif/bitmap.cpp @@ -36,7 +36,7 @@ #pragma message enable nosimpint #endif -#include "wx/motif/private.h" +// #include "wx/motif/private.h" #if wxHAVE_LIB_XPM #include @@ -53,27 +53,34 @@ wxBitmapRefData::wxBitmapRefData() m_width = 0; m_height = 0; m_depth = 0; - m_quality = 0; - m_numColors = 0; + // XXX m_quality = 0; + // m_numColors = 0; m_bitmapMask = NULL; m_pixmap = (WXPixmap) 0; m_display = (WXDisplay*) 0; - m_freePixmap = TRUE; //TODO: necessary? + // m_freePixmap = TRUE; //TODO: necessary? +#if 0 m_freeColors = (unsigned long*) 0; m_freeColorsCount = 0; +#endif // These 5 variables are for wxControl +#if 0 m_insensPixmap = (WXPixmap) 0; m_labelPixmap = (WXPixmap) 0; m_armPixmap = (WXPixmap) 0; +#endif +#if 0 m_image = (WXImage*) 0; m_insensImage = (WXImage*) 0; +#endif } wxBitmapRefData::~wxBitmapRefData() { +#if 0 if (m_labelPixmap) XmDestroyPixmap (DefaultScreenOfDisplay ((Display*) m_display), (Pixmap) m_labelPixmap); @@ -82,22 +89,28 @@ wxBitmapRefData::~wxBitmapRefData() if (m_insensPixmap) XmDestroyPixmap (DefaultScreenOfDisplay ((Display*) m_display), (Pixmap) m_insensPixmap); +#endif +#if 0 if (m_image) { XmUninstallImage ((XImage*) m_image); XtFree ((char *) (XImage*) m_image); } +#endif +#if 0 if (m_insensImage) { XmUninstallImage ((XImage*) m_insensImage); delete[] ((XImage*) m_insensImage)->data; XtFree ((char *) (XImage*) m_insensImage); } - if (m_pixmap && m_freePixmap) +#endif + if (m_pixmap /* && m_freePixmap */) XFreePixmap ((Display*) m_display, (Pixmap) m_pixmap); +#if 0 if (m_freeColors) { int screen = DefaultScreen((Display*) m_display); @@ -107,6 +120,7 @@ wxBitmapRefData::~wxBitmapRefData() XFreeColors((Display*) m_display, cmp, &m_freeColors[llp], 1, 0L); delete m_freeColors; }; +#endif if (m_bitmapMask) delete m_bitmapMask; @@ -184,7 +198,7 @@ bool wxBitmap::Create(int w, int h, int d) M_BITMAPDATA->m_width = w; M_BITMAPDATA->m_height = h; M_BITMAPDATA->m_depth = d; - M_BITMAPDATA->m_freePixmap = TRUE; + // M_BITMAPDATA->m_freePixmap = TRUE; Display *dpy = (Display*) wxGetDisplay(); @@ -276,6 +290,9 @@ void wxBitmap::SetDepth(int d) M_BITMAPDATA->m_depth = d; } +#if 0 + +// XXX void wxBitmap::SetQuality(int q) { if (!M_BITMAPDATA) @@ -284,6 +301,8 @@ void wxBitmap::SetQuality(int q) M_BITMAPDATA->m_quality = q; } +#endif + void wxBitmap::SetOk(bool isOk) { if (!M_BITMAPDATA) @@ -419,7 +438,7 @@ bool wxXBMFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name, int WXUNUSED(desiredWidth), int WXUNUSED(desiredHeight)) { - M_BITMAPHANDLERDATA->m_freePixmap = TRUE; + // M_BITMAPHANDLERDATA->m_freePixmap = TRUE; int hotX, hotY; unsigned int w, h; @@ -471,7 +490,7 @@ bool wxXBMDataHandler::Create( wxBitmap *bitmap, void *data, M_BITMAPHANDLERDATA->m_width = width; M_BITMAPHANDLERDATA->m_height = height; M_BITMAPHANDLERDATA->m_depth = 1; - M_BITMAPHANDLERDATA->m_freePixmap = TRUE; + // M_BITMAPHANDLERDATA->m_freePixmap = TRUE; Display *dpy = (Display*) wxGetDisplay(); M_BITMAPHANDLERDATA->m_display = (WXDisplay*) dpy; @@ -479,6 +498,7 @@ bool wxXBMDataHandler::Create( wxBitmap *bitmap, void *data, M_BITMAPHANDLERDATA->m_pixmap = (WXPixmap) XCreateBitmapFromData (dpy, RootWindow (dpy, DefaultScreen (dpy)), (char*) data, width, height); M_BITMAPHANDLERDATA->m_ok = (M_BITMAPHANDLERDATA->m_pixmap != (WXPixmap) 0) ; +#if 0 // code for wxControl. TODO: can we avoid doing this until we need it? // E.g. have CreateButtonPixmaps which is called on demand. XImage* image = (XImage *) XtMalloc (sizeof (XImage)); @@ -529,6 +549,9 @@ bool wxXBMDataHandler::Create( wxBitmap *bitmap, void *data, M_BITMAPHANDLERDATA->m_image = (WXImage*) image; M_BITMAPHANDLERDATA->m_insensImage = (WXImage*) insensImage; +#endif + + return TRUE; } @@ -604,7 +627,7 @@ bool wxXPMFileHandler::LoadFile( wxBitmap *bitmap, const wxString& name, M_BITMAPHANDLERDATA->m_depth = depthRet; - M_BITMAPHANDLERDATA->m_numColors = xpmAttr.npixels; + // M_BITMAPHANDLERDATA->m_numColors = xpmAttr.npixels; XpmFreeAttributes(&xpmAttr); @@ -662,7 +685,7 @@ bool wxXPMDataHandler::Create( wxBitmap *bitmap, void *data, M_BITMAPHANDLERDATA->m_width = width; M_BITMAPHANDLERDATA->m_height = height; M_BITMAPHANDLERDATA->m_depth = 1; - M_BITMAPHANDLERDATA->m_freePixmap = TRUE; + // M_BITMAPHANDLERDATA->m_freePixmap = TRUE; Display *dpy = (Display*) wxGetDisplay(); M_BITMAPHANDLERDATA->m_display = (WXDisplay*) dpy; @@ -686,7 +709,7 @@ bool wxXPMDataHandler::Create( wxBitmap *bitmap, void *data, xpmAttr.valuemask |= XpmColorSymbols; // add flag } - Pixmap pixmap; + Pixmap pixmap = 0; Pixmap mask = 0; int ErrorStatus = XpmCreatePixmapFromData(dpy, RootWindow(dpy, DefaultScreen(dpy)), (char**) data, &pixmap, &mask, &xpmAttr); @@ -715,7 +738,7 @@ bool wxXPMDataHandler::Create( wxBitmap *bitmap, void *data, M_BITMAPHANDLERDATA->m_depth = depthRet; - M_BITMAPHANDLERDATA->m_numColors = xpmAttr.npixels; + // M_BITMAPHANDLERDATA->m_numColors = xpmAttr.npixels; XpmFreeAttributes(&xpmAttr); M_BITMAPHANDLERDATA->m_ok = TRUE; M_BITMAPHANDLERDATA->m_pixmap = (WXPixmap) pixmap; @@ -749,13 +772,15 @@ void wxBitmap::InitStandardHandlers() #endif // wxHAVE_LIB_XPM } +#if 0 WXPixmap wxBitmap::GetLabelPixmap (WXWidget w) { if (!M_BITMAPDATA) return (WXPixmap)NULL; - if (M_BITMAPDATA->m_image == (WXPixmap) 0) + // if (M_BITMAPDATA->m_image == (WXPixmap) 0) return M_BITMAPDATA->m_pixmap; +#if 0 Display *dpy = (Display*) M_BITMAPDATA->m_display; #ifdef FOO @@ -794,13 +819,15 @@ WXPixmap wxBitmap::GetLabelPixmap (WXWidget w) M_BITMAPDATA->m_labelPixmap = (WXPixmap) XmGetPixmap (DefaultScreenOfDisplay (dpy), tmp, fg, bg); return M_BITMAPDATA->m_labelPixmap; +#endif } WXPixmap wxBitmap::GetArmPixmap (WXWidget w) { - if (M_BITMAPDATA->m_image == (WXPixmap) 0) + // if (M_BITMAPDATA->m_image == (WXPixmap) 0) return M_BITMAPDATA->m_pixmap; +#if 0 Display *dpy = (Display*) M_BITMAPDATA->m_display; #ifdef FOO // See GetLabelPixmap () comment @@ -824,6 +851,7 @@ WXPixmap wxBitmap::GetArmPixmap (WXWidget w) M_BITMAPDATA->m_armPixmap = (WXPixmap) XmGetPixmap (DefaultScreenOfDisplay (dpy), tmp, fg, bg); return M_BITMAPDATA->m_armPixmap; +#endif } WXPixmap wxBitmap::GetInsensPixmap (WXWidget w) @@ -844,9 +872,10 @@ WXPixmap wxBitmap::GetInsensPixmap (WXWidget w) return M_BITMAPDATA->m_pixmap; } - if (M_BITMAPDATA->m_insensImage == (WXPixmap) 0) + // if (M_BITMAPDATA->m_insensImage == (WXPixmap) 0) return M_BITMAPDATA->m_pixmap; +#if 0 #ifdef FOO See GetLabelPixmap () comment // Must be destroyed, because colours can have been changed! @@ -867,7 +896,9 @@ WXPixmap wxBitmap::GetInsensPixmap (WXWidget w) M_BITMAPDATA->m_insensPixmap = (WXPixmap) XmGetPixmap (DefaultScreenOfDisplay (dpy), tmp, fg, bg); return M_BITMAPDATA->m_insensPixmap; +#endif } +#endif // We may need this sometime... @@ -1075,8 +1106,8 @@ wxSearchColor::wxSearchColor( int size_, XColor *colors_ ) wxSearchColor::~wxSearchColor( void ) { - if ( color ) delete color; - if ( entry ) delete entry; + if ( color ) delete[] color; + if ( entry ) delete[] entry; } int wxSearchColor::SearchColor( int r, int g, int b ) @@ -1208,12 +1239,11 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) vinfo_template.depth = bpp; int nitem = 0; - vi = XGetVisualInfo( dpy, VisualIDMask|VisualDepthMask, &vinfo_template, &nitem ); + vi = XGetVisualInfo( dpy, VisualIDMask|VisualDepthMask, + &vinfo_template, &nitem ); wxCHECK_MSG( vi, FALSE, wxT("no visual") ); - XFree( vi ); - if ((bpp == 16) && (vi->red_mask != 0xf800)) bpp = 15; if (bpp < 8) bpp = 8; @@ -1232,6 +1262,8 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) else if ((vi->green_mask > vi->blue_mask) && (vi->blue_mask > vi->red_mask)) b_o = GBR; } + XFree( vi ); + int r_mask = image.GetMaskRed(); int g_mask = image.GetMaskGreen(); int b_mask = image.GetMaskBlue(); diff --git a/src/motif/bmpbuttn.cpp b/src/motif/bmpbuttn.cpp index 3bb0990002..d252d26a56 100644 --- a/src/motif/bmpbuttn.cpp +++ b/src/motif/bmpbuttn.cpp @@ -35,7 +35,7 @@ // Implemented in button.cpp void wxButtonCallback (Widget w, XtPointer clientData, XtPointer ptr); -Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ); +// Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ); IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) @@ -175,11 +175,15 @@ void wxBitmapButton::DoSetBitmap() wxBitmap newBitmap = wxCreateMaskedBitmap(m_bmpNormalOriginal, col); m_bmpNormal = newBitmap; + m_bitmapCache.SetBitmap( m_bmpNormal ); pixmap = (Pixmap) m_bmpNormal.GetPixmap(); } else - pixmap = (Pixmap) m_bmpNormal.GetLabelPixmap(m_mainWidget); + { + m_bitmapCache.SetBitmap( m_bmpNormal ); + pixmap = (Pixmap) m_bitmapCache.GetLabelPixmap(m_mainWidget); + } if (m_bmpDisabledOriginal.Ok()) { @@ -200,10 +204,10 @@ void wxBitmapButton::DoSetBitmap() insensPixmap = (Pixmap) m_bmpDisabled.GetPixmap(); } else - insensPixmap = (Pixmap) m_bmpNormal.GetInsensPixmap(m_mainWidget); + insensPixmap = (Pixmap) m_bitmapCache.GetInsensPixmap(m_mainWidget); } else - insensPixmap = (Pixmap) m_bmpNormal.GetInsensPixmap(m_mainWidget); + insensPixmap = (Pixmap) m_bitmapCache.GetInsensPixmap(m_mainWidget); // Now make the bitmap representing the armed state if (m_bmpSelectedOriginal.Ok()) @@ -225,11 +229,12 @@ void wxBitmapButton::DoSetBitmap() armPixmap = (Pixmap) m_bmpSelected.GetPixmap(); } else - armPixmap = (Pixmap) m_bmpNormal.GetArmPixmap(m_mainWidget); + armPixmap = (Pixmap) m_bitmapCache.GetArmPixmap(m_mainWidget); } else - armPixmap = (Pixmap) m_bmpNormal.GetArmPixmap(m_mainWidget); + armPixmap = (Pixmap) m_bitmapCache.GetArmPixmap(m_mainWidget); +#if 0 // <- the Get...Pixmap()-functions return the same pixmap! if (insensPixmap == pixmap) { @@ -237,6 +242,7 @@ void wxBitmapButton::DoSetBitmap() XCreateInsensitivePixmap(DisplayOfScreen(XtScreen((Widget) m_mainWidget)), pixmap); m_insensPixmap = (WXPixmap) insensPixmap; } +#endif XtVaSetValues ((Widget) m_mainWidget, XmNlabelPixmap, pixmap, diff --git a/src/motif/bmpmotif.cpp b/src/motif/bmpmotif.cpp new file mode 100644 index 0000000000..0cb1dbadeb --- /dev/null +++ b/src/motif/bmpmotif.cpp @@ -0,0 +1,204 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: bitmap.cpp +// Purpose: wxBitmap +// Author: Julian Smart, originally in bitmap.cpp +// Modified by: +// Created: 25/03/2003 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "bmpmotif.h" +#endif + +#ifdef __VMS +#define XtParent XTPARENT +#endif + +#include "wx/defs.h" +#include "wx/motif/bmpmotif.h" + +#ifdef __VMS__ +#pragma message disable nosimpint +#endif +#include +#ifdef __VMS__ +#pragma message enable nosimpint +#endif + +#include "wx/motif/private.h" + +#if wxHAVE_LIB_XPM + #include +#endif +#include + +Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ); + +wxBitmapCache::~wxBitmapCache() +{ + if( m_display ) + { + Screen* screen = DefaultScreenOfDisplay( (Display*)m_display ); + + if( m_labelPixmap ) + XmDestroyPixmap( screen, (Pixmap)m_labelPixmap ); + + if( m_armPixmap ) + XmDestroyPixmap( screen, (Pixmap)m_armPixmap ); + + if( m_insensPixmap ) + XmDestroyPixmap( screen, (Pixmap)m_insensPixmap ); + + } + + if( m_image ) + { + XmUninstallImage( (XImage*)m_image ); + XtFree( (char*)(XImage*)m_image ); + } +} + +void wxBitmapCache::SetBitmap( const wxBitmap& bitmap ) +{ + if( m_bitmap != bitmap ) + { + InvalidateCache(); + m_bitmap = bitmap; + + if( m_image ) + { + XmUninstallImage( (XImage*)m_image ); + XtFree( (char*)(XImage*)m_image ); + m_image = (WXImage*)NULL; + } + } +} + +void wxBitmapCache::InvalidateCache() +{ + m_recalcPixmaps.label = true; + m_recalcPixmaps.arm = true; + m_recalcPixmaps.insens = true; +} + +void wxBitmapCache::SetColoursChanged() +{ + InvalidateCache(); +} + +void wxBitmapCache::CreateImageIfNeeded( WXWidget w ) +{ + if( m_image ) + return; + + m_display = w ? + (WXDisplay*)XtDisplay( (Widget)w ) : + (WXDisplay*)wxGetDisplay(); + + XImage *ximage = XGetImage( (Display*)m_display, + (Drawable)m_bitmap.GetPixmap(), + 0, 0, + m_bitmap.GetWidth(), m_bitmap.GetHeight(), + AllPlanes, ZPixmap ); + + m_image = (WXImage*)ximage; + + if( m_image ) + { + char tmp[128]; + sprintf( tmp, "Im%x", (unsigned int)ximage ); + XmInstallImage( ximage, tmp ); + } +} + +WXPixmap wxBitmapCache::GetLabelPixmap( WXWidget w ) +{ + if( m_labelPixmap && !m_recalcPixmaps.label ) + return m_labelPixmap; + + CreateImageIfNeeded( w ); + + Screen* screen = DefaultScreenOfDisplay( (Display*)m_display ); + + if( m_labelPixmap ) + XmDestroyPixmap( screen, (Pixmap)m_labelPixmap ); + + if( !m_image ) + return (WXPixmap)NULL; + + char tmp[128]; + sprintf( tmp, "Im%x", (unsigned int)m_image ); + + Pixel fg, bg; + Widget widget = (Widget)w; + + while( XmIsGadget( widget ) ) + widget = XtParent( widget ); + XtVaGetValues( widget, + XmNbackground, &bg, + XmNforeground, &fg, + NULL ); + + m_labelPixmap = (WXPixmap)XmGetPixmap( screen, tmp, fg, bg ); + + m_recalcPixmaps.label = !m_labelPixmap; + return m_labelPixmap; +} + +WXPixmap wxBitmapCache::GetArmPixmap( WXWidget w ) +{ + if( m_armPixmap && !m_recalcPixmaps.arm ) + return m_armPixmap; + + CreateImageIfNeeded( w ); + + Screen* screen = DefaultScreenOfDisplay( (Display*)m_display ); + + if( m_armPixmap ) + XmDestroyPixmap( screen, (Pixmap)m_armPixmap ); + + if( !m_image ) + return (WXPixmap)NULL; + + char tmp[128]; + sprintf( tmp, "Im%x", (unsigned int)m_image ); + + Pixel fg, bg; + Widget widget = (Widget) w; + + XtVaGetValues( widget, XmNarmColor, &bg, NULL ); + while( XmIsGadget( widget ) ) + widget = XtParent( widget ); + XtVaGetValues( widget, XmNforeground, &fg, NULL ); + + m_armPixmap = (WXPixmap)XmGetPixmap( screen, tmp, fg, bg ); + + m_recalcPixmaps.arm = !m_armPixmap; + return m_armPixmap; +} + +WXPixmap wxBitmapCache::GetInsensPixmap( WXWidget w ) +{ + if( m_insensPixmap && !m_recalcPixmaps.insens ) + return m_insensPixmap; + + CreateImageIfNeeded( w ); + + Screen* screen = DefaultScreenOfDisplay( (Display*)m_display ); + + if( m_insensPixmap ) + XmDestroyPixmap( screen, (Pixmap)m_insensPixmap ); + + if( !m_image ) + return (WXPixmap)NULL; + + m_insensPixmap = + (WXPixmap)XCreateInsensitivePixmap( (Display*)m_display, + (Pixmap)m_bitmap.GetPixmap() ); + + m_recalcPixmaps.insens = !m_insensPixmap; + return m_insensPixmap; +} diff --git a/src/motif/files.lst b/src/motif/files.lst index d3c01b4ba7..9610dcb1c4 100644 --- a/src/motif/files.lst +++ b/src/motif/files.lst @@ -184,6 +184,7 @@ ALL_SOURCES = \ motif/app.cpp \ motif/bitmap.cpp \ motif/bmpbuttn.cpp \ + motif/bmpmotif.cpp \ motif/button.cpp \ motif/checkbox.cpp \ motif/checklst.cpp \ @@ -305,7 +306,6 @@ ALL_HEADERS = \ ctrlsub.h \ cursor.h \ dataobj.h \ - date.h \ datetime.h \ datetime.inl \ datstrm.h \ @@ -479,7 +479,6 @@ ALL_HEADERS = \ tglbtn.h \ thread.h \ thrimpl.cpp \ - time.h \ timer.h \ tipdlg.h \ tipwin.h \ @@ -519,6 +518,7 @@ ALL_HEADERS = \ motif/app.h \ motif/bitmap.h \ motif/bmpbuttn.h \ + motif/bmpmotif.h \ motif/button.h \ motif/checkbox.h \ motif/checklst.h \ @@ -828,6 +828,7 @@ GUIOBJS = \ app.o \ bitmap.o \ bmpbuttn.o \ + bmpmotif.o \ button.o \ checkbox.o \ checklst.o \ diff --git a/src/motif/frame.cpp b/src/motif/frame.cpp index 978b6e6200..ef7ab95de2 100644 --- a/src/motif/frame.cpp +++ b/src/motif/frame.cpp @@ -660,7 +660,7 @@ void wxFrame::PositionToolBar() tw = cw; } - tb->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS); + tb->SetSize(0, 0, -1, -1, wxSIZE_NO_ADJUSTMENTS); } } #endif // wxUSE_TOOLBAR diff --git a/src/motif/statbmp.cpp b/src/motif/statbmp.cpp index e0d2ac766e..5209698fb0 100644 --- a/src/motif/statbmp.cpp +++ b/src/motif/statbmp.cpp @@ -124,7 +124,10 @@ void wxStaticBitmap::DoSetBitmap() pixmap = (Pixmap) m_messageBitmap.GetPixmap(); } else - pixmap = (Pixmap) m_messageBitmap.GetLabelPixmap(widget); + { + m_bitmapCache.SetBitmap( m_messageBitmap ); + pixmap = (Pixmap)m_bitmapCache.GetLabelPixmap(widget); + } XtVaSetValues (widget, XmNlabelPixmap, pixmap, @@ -164,11 +167,13 @@ void wxStaticBitmap::ChangeBackgroundColour() wxWindow::ChangeBackgroundColour(); // must recalculate the background colour + m_bitmapCache.SetColoursChanged(); DoSetBitmap(); } void wxStaticBitmap::ChangeForegroundColour() { + m_bitmapCache.SetColoursChanged(); wxWindow::ChangeForegroundColour(); } diff --git a/src/motif/toolbar.cpp b/src/motif/toolbar.cpp index c02fbac244..a4279e48bf 100644 --- a/src/motif/toolbar.cpp +++ b/src/motif/toolbar.cpp @@ -46,6 +46,7 @@ #endif #include "wx/motif/private.h" +#include "wx/motif/bmpmotif.h" // ---------------------------------------------------------------------------- // wxWin macros @@ -108,14 +109,22 @@ public: void SetWidget(Widget widget) { m_widget = widget; } Widget GetButtonWidget() const { return m_widget; } - void SetPixmap(Pixmap pixmap) { m_pixmap = pixmap; } - Pixmap GetPixmap() const { return m_pixmap; } + Pixmap GetArmPixmap() + { + m_bitmapCache.SetBitmap( GetNormalBitmap() ); + return (Pixmap)m_bitmapCache.GetArmPixmap( (WXWidget)m_widget ); + } + Pixmap GetInsensPixmap() + { + m_bitmapCache.SetBitmap( GetNormalBitmap() ); + return (Pixmap)m_bitmapCache.GetInsensPixmap( (WXWidget)m_widget ); + } protected: void Init(); Widget m_widget; - Pixmap m_pixmap; + wxBitmapCache m_bitmapCache; }; // ---------------------------------------------------------------------------- @@ -158,15 +167,12 @@ wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) void wxToolBarTool::Init() { m_widget = (Widget)0; - m_pixmap = (Pixmap)0; } wxToolBarTool::~wxToolBarTool() { if ( m_widget ) XtDestroyWidget(m_widget); - // note: do not delete m_pixmap here because it will be deleted - // by the base class when the bitmap is destroyed. } // ---------------------------------------------------------------------------- @@ -274,7 +280,7 @@ bool wxToolBar::Realize() Widget button; Pixmap pixmap, insensPixmap; - wxBitmap bmp; + wxBitmap bmp, insensBmp; wxToolBarToolsList::Node *node = m_tools.GetFirst(); while ( node ) @@ -291,8 +297,8 @@ bool wxToolBar::Realize() // Allow a control to specify a y[x]-offset by setting // its initial position, but still don't allow it to // position itself above the top[left] margin. - int controlY = (pos.y > 0) ? currentY + pos.y : currentY; - int controlX = (pos.x > 0) ? currentX + pos.x : currentX; + int controlY = (pos.y > 0) ? pos.y : currentY; + int controlX = (pos.x > 0) ? pos.x : currentX; control->Move( isVertical ? controlX : currentX, isVertical ? currentY : controlY ); if ( isVertical ) @@ -303,15 +309,17 @@ bool wxToolBar::Realize() break; } case wxTOOL_STYLE_SEPARATOR: - // skip separators for vertical toolbars - if( isVertical ) break; - currentX += separatorSize; + // skip separators for vertical toolbars + if( !isVertical ) + { + currentX += separatorSize; + } break; case wxTOOL_STYLE_BUTTON: button = (Widget) 0; - if ( tool->CanBeToggled() ) + if ( tool->CanBeToggled() && !tool->GetButtonWidget() ) { button = XtVaCreateWidget("toggleButton", xmToggleButtonWidgetClass, (Widget) m_mainWidget, @@ -325,14 +333,18 @@ bool wxToolBar::Realize() XmNmultiClick, XmMULTICLICK_KEEP, XmNlabelType, XmPIXMAP, NULL); - XtAddCallback ((Widget) button, XmNvalueChangedCallback, (XtCallbackProc) wxToolButtonCallback, - (XtPointer) this); + XtAddCallback ((Widget) button, + XmNvalueChangedCallback, + (XtCallbackProc) wxToolButtonCallback, + (XtPointer) this); XtVaSetValues ((Widget) button, - XmNselectColor, m_backgroundColour.AllocColour(XtDisplay((Widget) button)), - NULL); + XmNselectColor, + m_backgroundColour.AllocColour + (XtDisplay((Widget) button)), + NULL); } - else + else if( !tool->GetButtonWidget() ) { button = XtVaCreateWidget("button", xmPushButtonWidgetClass, (Widget) m_mainWidget, @@ -342,30 +354,52 @@ bool wxToolBar::Realize() XmNlabelType, XmPIXMAP, NULL); XtAddCallback (button, - XmNactivateCallback, (XtCallbackProc) wxToolButtonCallback, - (XtPointer) this); + XmNactivateCallback, + (XtCallbackProc) wxToolButtonCallback, + (XtPointer) this); } - DoChangeBackgroundColour((WXWidget) button, m_backgroundColour, TRUE); + if( !tool->GetButtonWidget() ) + { + DoChangeBackgroundColour((WXWidget) button, + m_backgroundColour, TRUE); - tool->SetWidget(button); + tool->SetWidget(button); + } + else + { + button = (Widget)tool->GetButtonWidget(); + XtVaSetValues( button, + XmNx, currentX, XmNy, currentY, + NULL ); + } // For each button, if there is a mask, we must create // a new wxBitmap that has the correct background colour // for the button. Otherwise the background will just be // e.g. black if a transparent XPM has been loaded. bmp = tool->GetNormalBitmap(); - if ( bmp.GetMask() ) + insensBmp = tool->GetDisabledBitmap(); + if ( bmp.GetMask() || insensBmp.GetMask() ) { int backgroundPixel; XtVaGetValues(button, XmNbackground, &backgroundPixel, - NULL); + NULL); wxColour col; col.SetPixel(backgroundPixel); - bmp = wxCreateMaskedBitmap(bmp, col); - tool->SetNormalBitmap(bmp); + if( bmp.GetMask() ) + { + bmp = wxCreateMaskedBitmap(bmp, col); + tool->SetNormalBitmap(bmp); + } + + if( insensBmp.GetMask() ) + { + insensBmp = wxCreateMaskedBitmap(insensBmp, col); + tool->SetDisabledBitmap(insensBmp); + } } // Create a selected/toggled bitmap. If there isn't a 2nd @@ -374,60 +408,27 @@ bool wxToolBar::Realize() int backgroundPixel; if ( tool->CanBeToggled() ) XtVaGetValues(button, XmNselectColor, &backgroundPixel, - NULL); + NULL); else XtVaGetValues(button, XmNarmColor, &backgroundPixel, - NULL); + NULL); wxColour col; col.SetPixel(backgroundPixel); - // FIXME: we use disabled bitmap as the bitmap for the toggled - // state, we probably need a GetToggledBitmap() instead - wxBitmap bmpToggled = tool->GetDisabledBitmap(); - if ( bmpToggled.Ok() && bmpToggled.GetMask()) - { - // Use what's there - wxBitmap newBitmap = wxCreateMaskedBitmap(bmpToggled, col); - tool->SetDisabledBitmap(newBitmap); - } - else - { - // Use unselected bitmap - if ( bmp.GetMask() ) - { - wxBitmap newBitmap = wxCreateMaskedBitmap(bmp, col); - tool->SetDisabledBitmap(newBitmap); - } - else - tool->SetDisabledBitmap(bmp); - } - - // FIXME: and here we should use GetDisabledBitmap()... pixmap = (Pixmap) bmp.GetPixmap(); - insensPixmap = (Pixmap) bmp.GetInsensPixmap(); + { + wxBitmap tmp = tool->GetDisabledBitmap(); + insensPixmap = tmp.Ok() ? + (Pixmap)tmp.GetPixmap() : + tool->GetInsensPixmap(); + } + if (tool->CanBeToggled()) { // Toggle button - Pixmap pixmap2 = (Pixmap) 0; - Pixmap insensPixmap2 = (Pixmap) 0; - - // If there's a bitmap for the toggled state, use it, - // otherwise generate one. - // - // FIXME: see above - if ( bmpToggled.Ok() ) - { - pixmap2 = (Pixmap) bmpToggled.GetPixmap(); - insensPixmap2 = (Pixmap) bmpToggled.GetInsensPixmap(); - } - else - { - pixmap2 = (Pixmap) bmp.GetArmPixmap(button); - insensPixmap2 = XCreateInsensitivePixmap((Display*) wxGetDisplay(), pixmap2); - } - - tool->SetPixmap(pixmap2); + Pixmap pixmap2 = tool->GetArmPixmap(); + Pixmap insensPixmap2 = tool->GetInsensPixmap(); XtVaSetValues (button, XmNfillOnSelect, True, @@ -440,21 +441,7 @@ bool wxToolBar::Realize() } else { - Pixmap pixmap2 = (Pixmap) 0; - - // If there's a bitmap for the armed state, use it, - // otherwise generate one. - if ( bmpToggled.Ok() ) - { - pixmap2 = (Pixmap) bmpToggled.GetPixmap(); - } - else - { - pixmap2 = (Pixmap) bmp.GetArmPixmap(button); - - } - - tool->SetPixmap(pixmap2); + Pixmap pixmap2 = tool->GetArmPixmap(); // Normal button XtVaSetValues(button, @@ -491,8 +478,8 @@ bool wxToolBar::Realize() } SetSize( -1, -1, - isVertical ? buttonWidth + 2 * marginX : currentX, - isVertical ? currentY : buttonHeight + 2*marginY ); + isVertical ? buttonWidth + 2 * marginX : -1, + isVertical ? -1 : buttonHeight + 2*marginY ); return TRUE; } @@ -512,10 +499,91 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) return TRUE; } -bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) +bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) { tool->Detach(); + bool isVertical = GetWindowStyle() & wxTB_VERTICAL; + const int separatorSize = GetToolSeparation(); // 8; + int packing = GetToolPacking(); + int offset = 0; + + for( wxToolBarToolsList::Node *node = m_tools.GetFirst(); + node; node = node->GetNext() ) + { + wxToolBarTool *t = (wxToolBarTool*)node->GetData(); + + if( t == tool ) + { + switch ( t->GetStyle() ) + { + case wxTOOL_STYLE_CONTROL: + { + wxSize size = t->GetControl()->GetSize(); + offset = isVertical ? size.y : size.x; + offset += packing; + break; + } + case wxTOOL_STYLE_SEPARATOR: + offset = isVertical ? 0 : separatorSize; + break; + case wxTOOL_STYLE_BUTTON: + { + Widget w = t->GetButtonWidget(); + Dimension width, height; + + XtVaGetValues( w, + XmNwidth, &width, + XmNheight, &height, + NULL ); + + offset = isVertical ? height : width; + offset += packing; + break; + } + } + } + else if( offset ) + { + switch ( t->GetStyle() ) + { + case wxTOOL_STYLE_CONTROL: + { + wxPoint pos = t->GetControl()->GetPosition(); + + if( isVertical ) + pos.y -= offset; + else + pos.x -= offset; + + t->GetControl()->Move( pos ); + break; + } + case wxTOOL_STYLE_SEPARATOR: + break; + case wxTOOL_STYLE_BUTTON: + { + Dimension x, y; + XtVaGetValues( t->GetButtonWidget(), + XmNx, &x, + XmNy, &y, + NULL ); + + if( isVertical ) + y -= offset; + else + x -= offset; + + XtVaSetValues( t->GetButtonWidget(), + XmNx, x, + XmNy, y, + NULL ); + break; + } + } + } + } + return TRUE; } @@ -544,19 +612,18 @@ void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags) int old_width, old_height; GetSize(&old_width, &old_height); - wxToolBarBase::DoSetSize(x, y, width, height, sizeFlags); - // Correct width and height if needed. if ( width == -1 || height == -1 ) { - int tmp_width, tmp_height; - GetSize(&tmp_width, &tmp_height); + wxSize defaultSize = GetSize(); if ( width == -1 ) - width = tmp_width; + width = defaultSize.x; if ( height == -1 ) - height = tmp_height; + height = defaultSize.y; } + + wxToolBarBase::DoSetSize(x, y, width, height, sizeFlags); // We must refresh the frame size when the toolbar changes size // otherwise the toolbar can be shown incorrectly -- 2.45.2