From e838cc14684f8dfd4ede39e4649e04a5bd79d149 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 16 Dec 1999 19:36:05 +0000 Subject: [PATCH] 1. wxMotif toolbar works; the toggle buttons have the same width as the other ones and not twice as big 2. wxMotif::wxBitmap(from XPM) ctor now takes either "char **" or "const char **", as in wxGTK 3. added an X error handler to wxMotif (debug only) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4995 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/bitmap.h | 7 +- include/wx/gtk1/bitmap.h | 7 +- include/wx/motif/bitmap.h | 11 ++- samples/toolbar/toolbar.cpp | 7 -- src/gtk/bitmap.cpp | 31 ++------- src/gtk1/bitmap.cpp | 31 ++------- src/motif/app.cpp | 17 +++++ src/motif/bitmap.cpp | 135 +++++++++++++++++++----------------- src/motif/toolbar.cpp | 17 +++-- src/motif/window.cpp | 2 +- 10 files changed, 126 insertions(+), 139 deletions(-) diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h index 8449a01cdb..2917413d43 100644 --- a/include/wx/gtk/bitmap.h +++ b/include/wx/gtk/bitmap.h @@ -64,8 +64,8 @@ public: wxBitmap(); wxBitmap( int width, int height, int depth = -1 ); wxBitmap( const char bits[], int width, int height, int depth = 1 ); - wxBitmap( const char **bits ); - wxBitmap( char **bits ); + wxBitmap( const char **bits ) { (void)CreateFromXpm(bits); } + wxBitmap( char **bits ) { (void)CreateFromXpm((const char **)bits); } wxBitmap( const wxBitmap& bmp ); wxBitmap( const wxString &filename, int type = wxBITMAP_TYPE_XPM ); ~wxBitmap(); @@ -99,6 +99,9 @@ public: GdkPixmap *GetPixmap() const; GdkBitmap *GetBitmap() const; +protected: + bool CreateFromXpm(const char **bits); + private: DECLARE_DYNAMIC_CLASS(wxBitmap) }; diff --git a/include/wx/gtk1/bitmap.h b/include/wx/gtk1/bitmap.h index 8449a01cdb..2917413d43 100644 --- a/include/wx/gtk1/bitmap.h +++ b/include/wx/gtk1/bitmap.h @@ -64,8 +64,8 @@ public: wxBitmap(); wxBitmap( int width, int height, int depth = -1 ); wxBitmap( const char bits[], int width, int height, int depth = 1 ); - wxBitmap( const char **bits ); - wxBitmap( char **bits ); + wxBitmap( const char **bits ) { (void)CreateFromXpm(bits); } + wxBitmap( char **bits ) { (void)CreateFromXpm((const char **)bits); } wxBitmap( const wxBitmap& bmp ); wxBitmap( const wxString &filename, int type = wxBITMAP_TYPE_XPM ); ~wxBitmap(); @@ -99,6 +99,9 @@ public: GdkPixmap *GetPixmap() const; GdkBitmap *GetBitmap() const; +protected: + bool CreateFromXpm(const char **bits); + private: DECLARE_DYNAMIC_CLASS(wxBitmap) }; diff --git a/include/wx/motif/bitmap.h b/include/wx/motif/bitmap.h index 76f3912dd2..49495e6563 100644 --- a/include/wx/motif/bitmap.h +++ b/include/wx/motif/bitmap.h @@ -140,8 +140,12 @@ public: // Initialize with raw XBM data wxBitmap(const char bits[], int width, int height, int depth = 1); - // Initialize with XPM data - wxBitmap(char **data, wxControl* control = NULL); + // from XPM + wxBitmap(const char **data) { (void)CreateFromXpm(data); } + wxBitmap(char **data) { (void)CreateFromXpm((const char **)data); } + + // Initialize with XPM data -- deprecated + wxBitmap(char **data, wxControl* control); // Load a file or resource wxBitmap(const wxString& name, long type = wxBITMAP_TYPE_XPM); @@ -201,6 +205,9 @@ public: protected: static wxList sm_handlers; + +protected: + bool CreateFromXpm(const char **bits); }; // Creates a bitmap with transparent areas drawn in diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index 9106c8f504..09f9f36a4c 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -217,13 +217,6 @@ void MyFrame::RecreateToolbar() wxBitmap toolBarBitmaps[8]; toolBarBitmaps[0] = wxBITMAP(new); -#if 0 - toolBar->AddTool(wxID_NEW, toolBarBitmaps[0], wxNullBitmap, FALSE, -1, -1, - (wxObject *) NULL, "New file"); - toolBar->Realize(); - return; -#endif - toolBarBitmaps[1] = wxBITMAP(open); if ( !m_smallToolbar ) { diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 59428e9024..572a176c3b 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -245,9 +245,9 @@ wxBitmap::wxBitmap( int width, int height, int depth ) if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); } -wxBitmap::wxBitmap( const char **bits ) +bool wxBitmap::CreateFromXpm( const char **bits ) { - wxCHECK_RET( bits != NULL, wxT("invalid bitmap data") ) + wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") ) m_refData = new wxBitmapRefData(); @@ -256,30 +256,7 @@ wxBitmap::wxBitmap( const char **bits ) M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( parent, &mask, NULL, (gchar **) bits ); - if (mask) - { - M_BMPDATA->m_mask = new wxMask(); - M_BMPDATA->m_mask->m_bitmap = mask; - } - - gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); - - M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; // ? - if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); -} - -wxBitmap::wxBitmap( char **bits ) -{ - wxCHECK_RET( bits != NULL, wxT("invalid bitmap data") ) - - m_refData = new wxBitmapRefData(); - - GdkBitmap *mask = (GdkBitmap*) NULL; - GdkWindow *parent = (GdkWindow*) &gdk_root_parent; - - M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( parent, &mask, NULL, (gchar **) bits ); - - wxCHECK_RET( M_BMPDATA->m_pixmap, wxT("couldn't create pixmap") ); + wxCHECK_MSG( M_BMPDATA->m_pixmap, FALSE, wxT("couldn't create pixmap") ); if (mask) { @@ -291,6 +268,8 @@ wxBitmap::wxBitmap( char **bits ) M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; // ? if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); + + return TRUE; } wxBitmap::wxBitmap( const wxBitmap& bmp ) diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index 59428e9024..572a176c3b 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -245,9 +245,9 @@ wxBitmap::wxBitmap( int width, int height, int depth ) if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); } -wxBitmap::wxBitmap( const char **bits ) +bool wxBitmap::CreateFromXpm( const char **bits ) { - wxCHECK_RET( bits != NULL, wxT("invalid bitmap data") ) + wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") ) m_refData = new wxBitmapRefData(); @@ -256,30 +256,7 @@ wxBitmap::wxBitmap( const char **bits ) M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( parent, &mask, NULL, (gchar **) bits ); - if (mask) - { - M_BMPDATA->m_mask = new wxMask(); - M_BMPDATA->m_mask->m_bitmap = mask; - } - - gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); - - M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; // ? - if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); -} - -wxBitmap::wxBitmap( char **bits ) -{ - wxCHECK_RET( bits != NULL, wxT("invalid bitmap data") ) - - m_refData = new wxBitmapRefData(); - - GdkBitmap *mask = (GdkBitmap*) NULL; - GdkWindow *parent = (GdkWindow*) &gdk_root_parent; - - M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( parent, &mask, NULL, (gchar **) bits ); - - wxCHECK_RET( M_BMPDATA->m_pixmap, wxT("couldn't create pixmap") ); + wxCHECK_MSG( M_BMPDATA->m_pixmap, FALSE, wxT("couldn't create pixmap") ); if (mask) { @@ -291,6 +268,8 @@ wxBitmap::wxBitmap( char **bits ) M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; // ? if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); + + return TRUE; } wxBitmap::wxBitmap( const wxBitmap& bmp ) diff --git a/src/motif/app.cpp b/src/motif/app.cpp index 916c8b9419..53b01e0f35 100644 --- a/src/motif/app.cpp +++ b/src/motif/app.cpp @@ -68,6 +68,18 @@ BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) EVT_IDLE(wxApp::OnIdle) END_EVENT_TABLE() +#ifdef __WXDEBUG__ + typedef int (*XErrorHandlerFunc)(Display *, XErrorEvent *); + + XErrorHandlerFunc gs_pfnXErrorHandler = 0; + + static int wxXErrorHandler(Display *dpy, XErrorEvent *xevent) + { + // just forward to the default handler for now + return gs_pfnXErrorHandler(dpy, xevent); + } +#endif // __WXDEBUG__ + long wxApp::sm_lastMessageTime = 0; bool wxApp::Initialize() @@ -575,6 +587,11 @@ bool wxApp::OnInitGui() } m_initialDisplay = (WXDisplay*) dpy; +#ifdef __WXDEBUG__ + // install the X error handler + gs_pfnXErrorHandler = XSetErrorHandler(wxXErrorHandler); +#endif // __WXDEBUG__ + wxTheApp->m_topLevelWidget = (WXWidget) XtAppCreateShell((String)NULL, (const char*) wxTheApp->GetClassName(), applicationShellWidgetClass,dpy, NULL,0) ; diff --git a/src/motif/bitmap.cpp b/src/motif/bitmap.cpp index 90c225d8ae..077f20cd3b 100644 --- a/src/motif/bitmap.cpp +++ b/src/motif/bitmap.cpp @@ -37,8 +37,8 @@ #include #endif - IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) - IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) +IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) +IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) wxBitmapRefData::wxBitmapRefData() { @@ -168,6 +168,13 @@ wxBitmap::wxBitmap(char **data, wxControl* control) sg_Control = (wxControl*) NULL; } +bool wxBitmap::CreateFromXpm(const char **bits) +{ + wxCHECK_MSG( bits, FALSE, _T("NULL pointer in wxBitmap::CreateFromXpm") ); + + return Create(bits, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0); +} + bool wxBitmap::Create(int w, int h, int d) { UnRef(); @@ -828,10 +835,10 @@ WXPixmap wxBitmap::GetLabelPixmap (WXWidget w) this is a catch22!! - So, before doing thing really clean, I just do nothing; if the pixmap is - referenced by many widgets, Motif performs caching functions. - And if pixmap is referenced with multiples colors, we just have some - memory leaks... I hope we can deal with them... + So, before doing thing really clean, I just do nothing; if the pixmap is + referenced by many widgets, Motif performs caching functions. + And if pixmap is referenced with multiples colors, we just have some + memory leaks... I hope we can deal with them... */ // Must be destroyed, because colours can have been changed! if (M_BITMAPDATA->m_labelPixmap) @@ -860,26 +867,27 @@ WXPixmap wxBitmap::GetArmPixmap (WXWidget w) Display *dpy = (Display*) M_BITMAPDATA->m_display; #ifdef FOO - See GetLabelPixmap () comment - // Must be destroyed, because colours can have been changed! - if (M_BITMAPDATA->m_armPixmap) - XmDestroyPixmap (DefaultScreenOfDisplay (dpy), M_BITMAPDATA->m_armPixmap); + // See GetLabelPixmap () comment + + // Must be destroyed, because colours can have been changed! + if (M_BITMAPDATA->m_armPixmap) + XmDestroyPixmap (DefaultScreenOfDisplay (dpy), M_BITMAPDATA->m_armPixmap); #endif - char tmp[128]; - sprintf (tmp, "Im%x", (unsigned int) M_BITMAPDATA->m_image); + char tmp[128]; + sprintf (tmp, "Im%x", (unsigned int) M_BITMAPDATA->m_image); - Pixel fg, bg; - Widget widget = (Widget) w; + Pixel fg, bg; + Widget widget = (Widget) w; - XtVaGetValues (widget, XmNarmColor, &bg, NULL); - while (XmIsGadget (widget)) - widget = XtParent (widget); - XtVaGetValues (widget, XmNforeground, &fg, NULL); + XtVaGetValues (widget, XmNarmColor, &bg, NULL); + while (XmIsGadget (widget)) + widget = XtParent (widget); + XtVaGetValues (widget, XmNforeground, &fg, NULL); - M_BITMAPDATA->m_armPixmap = (WXPixmap) XmGetPixmap (DefaultScreenOfDisplay (dpy), tmp, fg, bg); + M_BITMAPDATA->m_armPixmap = (WXPixmap) XmGetPixmap (DefaultScreenOfDisplay (dpy), tmp, fg, bg); - return M_BITMAPDATA->m_armPixmap; + return M_BITMAPDATA->m_armPixmap; } WXPixmap wxBitmap::GetInsensPixmap (WXWidget w) @@ -908,19 +916,19 @@ WXPixmap wxBitmap::GetInsensPixmap (WXWidget w) XmDestroyPixmap (DefaultScreenOfDisplay (dpy), (Pixmap) M_BITMAPDATA->m_insensPixmap); #endif - char tmp[128]; - sprintf (tmp, "Not%x", (unsigned int) M_BITMAPDATA->m_insensImage); + char tmp[128]; + sprintf (tmp, "Not%x", (unsigned int) M_BITMAPDATA->m_insensImage); - Pixel fg, bg; - Widget widget = (Widget) w; + Pixel fg, bg; + Widget widget = (Widget) w; - while (XmIsGadget (widget)) - widget = XtParent (widget); - XtVaGetValues (widget, XmNbackground, &bg, XmNforeground, &fg, NULL); + while (XmIsGadget (widget)) + widget = XtParent (widget); + XtVaGetValues (widget, XmNbackground, &bg, XmNforeground, &fg, NULL); - M_BITMAPDATA->m_insensPixmap = (WXPixmap) XmGetPixmap (DefaultScreenOfDisplay (dpy), tmp, fg, bg); + M_BITMAPDATA->m_insensPixmap = (WXPixmap) XmGetPixmap (DefaultScreenOfDisplay (dpy), tmp, fg, bg); - return M_BITMAPDATA->m_insensPixmap; + return M_BITMAPDATA->m_insensPixmap; } // We may need this sometime... @@ -930,30 +938,30 @@ WXPixmap wxBitmap::GetInsensPixmap (WXWidget w) NAME XCreateInsensitivePixmap - create a grayed-out copy of a pixmap - SYNOPSIS - Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ) + SYNOPSIS + Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ) - DESCRIPTION - This function creates a grayed-out copy of the argument pixmap, suitable - for use as a XmLabel's XmNlabelInsensitivePixmap resource. + DESCRIPTION + This function creates a grayed-out copy of the argument pixmap, suitable + for use as a XmLabel's XmNlabelInsensitivePixmap resource. - RETURN VALUES - The return value is the new Pixmap id or zero on error. Errors include - a NULL display argument or an invalid Pixmap argument. + RETURN VALUES + The return value is the new Pixmap id or zero on error. Errors include + a NULL display argument or an invalid Pixmap argument. - ERRORS - If one of the XLib functions fail, it will produce a X error. The - default X error handler prints a diagnostic and calls exit(). + ERRORS + If one of the XLib functions fail, it will produce a X error. The + default X error handler prints a diagnostic and calls exit(). - SEE ALSO - XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3), - XFillRectangle(3), exit(2) + SEE ALSO + XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3), + XFillRectangle(3), exit(2) - AUTHOR - John R Veregge - john@puente.jpl.nasa.gov - Advanced Engineering and Prototyping Group (AEG) - Information Systems Technology Section (395) - Jet Propulsion Lab - Calif Institute of Technology + AUTHOR + John R Veregge - john@puente.jpl.nasa.gov + Advanced Engineering and Prototyping Group (AEG) + Information Systems Technology Section (395) + Jet Propulsion Lab - Calif Institute of Technology *****************************************************************************/ @@ -961,14 +969,13 @@ Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ) { - static - char stipple_data[] = - { - 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, + static char stipple_data[] = + { + 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA - }; + }; GC gc; Pixmap ipixmap, stipple; unsigned width, height, depth; @@ -983,30 +990,30 @@ XCreateInsensitivePixmap( Display *display, Pixmap pixmap ) return ipixmap; if ( 0 == XGetGeometry( display, pixmap, &window, &x, &y, - &width, &height, &border, &depth ) - ) + &width, &height, &border, &depth ) + ) return ipixmap; /* BadDrawable: probably an invalid pixmap */ - /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap. - */ + /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap. + */ stipple = XCreateBitmapFromData( display, pixmap, stipple_data, 16, 16 ); if ( 0 != stipple ) { gc = XCreateGC( display, pixmap, (XtGCMask)0, (XGCValues*)NULL ); if ( NULL != gc ) { - /* Create an identical copy of the argument pixmap. - */ + /* Create an identical copy of the argument pixmap. + */ ipixmap = XCreatePixmap( display, pixmap, width, height, depth ); if ( 0 != ipixmap ) { - /* Copy the argument pixmap into the new pixmap. - */ + /* Copy the argument pixmap into the new pixmap. + */ XCopyArea( display, pixmap, ipixmap, - gc, 0, 0, width, height, 0, 0 ); + gc, 0, 0, width, height, 0, 0 ); - /* Refill the new pixmap using the stipple algorithm/pixmap. - */ + /* Refill the new pixmap using the stipple algorithm/pixmap. + */ XSetStipple( display, gc, stipple ); XSetFillStyle( display, gc, FillStippled ); XFillRectangle( display, ipixmap, gc, 0, 0, width, height ); diff --git a/src/motif/toolbar.cpp b/src/motif/toolbar.cpp index 70227436b5..5652912227 100644 --- a/src/motif/toolbar.cpp +++ b/src/motif/toolbar.cpp @@ -282,7 +282,12 @@ bool wxToolBar::Realize() button = XtVaCreateWidget("toggleButton", xmToggleButtonWidgetClass, (Widget) m_mainWidget, XmNx, currentX, XmNy, currentY, - // XmNpushButtonEnabled, True, + XmNindicatorOn, False, + XmNshadowThickness, 2, + XmNborderWidth, 0, + XmNspacing, 0, + XmNmarginWidth, 0, + XmNmarginHeight, 0, XmNmultiClick, XmMULTICLICK_KEEP, XmNlabelType, XmPIXMAP, NULL); @@ -325,9 +330,9 @@ bool wxToolBar::Realize() wxColour col; col.SetPixel(backgroundPixel); - wxBitmap newBitmap = wxCreateMaskedBitmap(bmp, col); + bmp = wxCreateMaskedBitmap(bmp, col); - tool->SetBitmap1(newBitmap); + tool->SetBitmap1(bmp); } // Create a selected/toggled bitmap. If there isn't a 2nd @@ -388,12 +393,6 @@ bool wxToolBar::Realize() tool->SetPixmap(pixmap2); XtVaSetValues (button, - XmNindicatorOn, False, - XmNshadowThickness, 2, - // XmNborderWidth, 0, - // XmNspacing, 0, - XmNmarginWidth, 0, - XmNmarginHeight, 0, XmNfillOnSelect, True, XmNlabelPixmap, pixmap, XmNselectPixmap, pixmap2, diff --git a/src/motif/window.cpp b/src/motif/window.cpp index 56072c4c0e..627a7afd8a 100644 --- a/src/motif/window.cpp +++ b/src/motif/window.cpp @@ -1718,7 +1718,7 @@ bool wxAddWindowToTable(Widget w, wxWindow *win) wxWidgetHashTable->Put((long) w, win); - wxLogDebug("Widget 0x%08x <-> window %p (%s)", + wxLogTrace("widget", "Widget 0x%08x <-> window %p (%s)", w, win, win->GetClassInfo()->GetClassName()); return TRUE; -- 2.45.2