1 ///////////////////////////////////////////////////////////////////////////// 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "bitmap.h" 
  18 #include "wx/palette.h" 
  19 #include "wx/bitmap.h" 
  22 #include "wx/control.h" 
  26 #include "wx/motif/private.h" 
  28 // TODO: correct symbol, path? 
  33 #if !USE_SHARED_LIBRARIES 
  34 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
, wxGDIObject
) 
  35 IMPLEMENT_DYNAMIC_CLASS(wxMask
, wxObject
) 
  38 wxBitmapRefData::wxBitmapRefData() 
  48     m_pixmap 
= (WXPixmap
) 0; 
  49     m_display 
= (WXDisplay
*) 0; 
  51     m_freePixmap 
= TRUE
; //TODO: necessary? 
  52     m_freeColors 
= (unsigned long*) 0; 
  53     m_freeColorsCount 
= 0; 
  55     // These 5 variables are for wxControl 
  56     m_insensPixmap 
= (WXPixmap
) 0; 
  57     m_labelPixmap 
= (WXPixmap
) 0; 
  58     m_armPixmap 
= (WXPixmap
) 0; 
  59     m_image 
= (WXImage
*) 0; 
  60     m_insensImage 
= (WXImage
*) 0; 
  63 wxBitmapRefData::~wxBitmapRefData() 
  66         XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) m_display
), (Pixmap
) m_labelPixmap
); 
  69         XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) m_display
), (Pixmap
) m_armPixmap
); 
  72         XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) m_display
), (Pixmap
) m_insensPixmap
); 
  76         XmUninstallImage ((XImage
*) m_image
); 
  77         XtFree ((char *) (XImage
*) m_image
); 
  82         XmUninstallImage ((XImage
*) m_insensImage
); 
  83         delete[] ((XImage
*) m_insensImage
)->data
; 
  84         XtFree ((char *) (XImage
*) m_insensImage
); 
  86     if (m_pixmap 
&& m_freePixmap
) 
  87         XFreePixmap ((Display
*) m_display
, (Pixmap
) m_pixmap
); 
  91        int screen 
= DefaultScreen((Display
*) m_display
); 
  92        Colormap cmp 
= DefaultColormap((Display
*) m_display
,screen
); 
  94        for(llp 
= 0;llp 
< m_freeColorsCount
;llp
++) 
  95           XFreeColors((Display
*) m_display
, cmp
, &m_freeColors
[llp
], 1, 0L); 
 104 wxList 
wxBitmap::sm_handlers
; 
 110     if ( wxTheBitmapList 
) 
 111         wxTheBitmapList
->AddBitmap(this); 
 114 wxBitmap::~wxBitmap() 
 117         wxTheBitmapList
->DeleteObject(this); 
 120 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
) 
 122     m_refData 
= new wxBitmapRefData
; 
 124     (void) Create((void*) bits
, wxBITMAP_TYPE_XBM_DATA
, width
, height
, depth
); 
 126     if ( wxTheBitmapList 
) 
 127         wxTheBitmapList
->AddBitmap(this); 
 130 wxBitmap::wxBitmap(int w
, int h
, int d
) 
 132     (void)Create(w
, h
, d
); 
 134     if ( wxTheBitmapList 
) 
 135         wxTheBitmapList
->AddBitmap(this); 
 138 wxBitmap::wxBitmap(void *data
, long type
, int width
, int height
, int depth
) 
 140     (void) Create(data
, type
, width
, height
, depth
); 
 142     if ( wxTheBitmapList 
) 
 143         wxTheBitmapList
->AddBitmap(this); 
 146 wxBitmap::wxBitmap(const wxString
& filename
, long type
) 
 148     LoadFile(filename
, (int)type
); 
 150     if ( wxTheBitmapList 
) 
 151         wxTheBitmapList
->AddBitmap(this); 
 154 // Create from XPM data 
 155 static wxControl
* sg_Control 
= NULL
; 
 156 wxBitmap::wxBitmap(char **data
, wxControl
* control
) 
 158     // Pass the control to the Create function using a global 
 159     sg_Control 
= control
; 
 161     (void) Create((void *)data
, wxBITMAP_TYPE_XPM_DATA
, 0, 0, 0); 
 163     sg_Control 
= (wxControl
*) NULL
; 
 166 bool wxBitmap::Create(int w
, int h
, int d
) 
 170     m_refData 
= new wxBitmapRefData
; 
 173       d 
= wxDisplayDepth(); 
 175     M_BITMAPDATA
->m_width 
= w
; 
 176     M_BITMAPDATA
->m_height 
= h
; 
 177     M_BITMAPDATA
->m_depth 
= d
; 
 178     M_BITMAPDATA
->m_freePixmap 
= TRUE
; 
 180     Display 
*dpy 
= (Display
*) wxGetDisplay(); 
 182     M_BITMAPDATA
->m_display 
= dpy
; /* MATTHEW: [4] Remember the display */ 
 184     M_BITMAPDATA
->m_pixmap 
= (WXPixmap
) XCreatePixmap (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)), 
 187     M_BITMAPDATA
->m_ok 
= (M_BITMAPDATA
->m_pixmap 
!= (WXPixmap
) 0) ; 
 188     return M_BITMAPDATA
->m_ok
; 
 191 bool wxBitmap::LoadFile(const wxString
& filename
, long type
) 
 195     m_refData 
= new wxBitmapRefData
; 
 197     wxBitmapHandler 
*handler 
= FindHandler(type
); 
 199     if ( handler 
== NULL 
) { 
 200         wxLogWarning("no bitmap handler for type %d defined.", type
); 
 205     return handler
->LoadFile(this, filename
, type
, -1, -1); 
 208 bool wxBitmap::Create(void *data
, long type
, int width
, int height
, int depth
) 
 212     m_refData 
= new wxBitmapRefData
; 
 214     wxBitmapHandler 
*handler 
= FindHandler(type
); 
 216     if ( handler 
== NULL 
) { 
 217         wxLogWarning("no bitmap handler for type %d defined.", type
); 
 222     return handler
->Create(this, data
, type
, width
, height
, depth
); 
 225 bool wxBitmap::SaveFile(const wxString
& filename
, int type
, const wxPalette 
*palette
) 
 227     wxBitmapHandler 
*handler 
= FindHandler(type
); 
 229     if ( handler 
== NULL 
) { 
 230         wxLogWarning("no bitmap handler for type %d defined.", type
); 
 235   return handler
->SaveFile(this, filename
, type
, palette
); 
 238 void wxBitmap::SetWidth(int w
) 
 241         m_refData 
= new wxBitmapRefData
; 
 243     M_BITMAPDATA
->m_width 
= w
; 
 246 void wxBitmap::SetHeight(int h
) 
 249         m_refData 
= new wxBitmapRefData
; 
 251     M_BITMAPDATA
->m_height 
= h
; 
 254 void wxBitmap::SetDepth(int d
) 
 257         m_refData 
= new wxBitmapRefData
; 
 259     M_BITMAPDATA
->m_depth 
= d
; 
 262 void wxBitmap::SetQuality(int q
) 
 265         m_refData 
= new wxBitmapRefData
; 
 267     M_BITMAPDATA
->m_quality 
= q
; 
 270 void wxBitmap::SetOk(bool isOk
) 
 273         m_refData 
= new wxBitmapRefData
; 
 275     M_BITMAPDATA
->m_ok 
= isOk
; 
 278 void wxBitmap::SetPalette(const wxPalette
& palette
) 
 281         m_refData 
= new wxBitmapRefData
; 
 283     M_BITMAPDATA
->m_bitmapPalette 
= palette 
; 
 286 void wxBitmap::SetMask(wxMask 
*mask
) 
 289         m_refData 
= new wxBitmapRefData
; 
 291     M_BITMAPDATA
->m_bitmapMask 
= mask 
; 
 294 void wxBitmap::AddHandler(wxBitmapHandler 
*handler
) 
 296     sm_handlers
.Append(handler
); 
 299 void wxBitmap::InsertHandler(wxBitmapHandler 
*handler
) 
 301     sm_handlers
.Insert(handler
); 
 304 bool wxBitmap::RemoveHandler(const wxString
& name
) 
 306     wxBitmapHandler 
*handler 
= FindHandler(name
); 
 309         sm_handlers
.DeleteObject(handler
); 
 316 wxBitmapHandler 
*wxBitmap::FindHandler(const wxString
& name
) 
 318     wxNode 
*node 
= sm_handlers
.First(); 
 321         wxBitmapHandler 
*handler 
= (wxBitmapHandler 
*)node
->Data(); 
 322         if ( handler
->GetName() == name 
) 
 329 wxBitmapHandler 
*wxBitmap::FindHandler(const wxString
& extension
, long bitmapType
) 
 331     wxNode 
*node 
= sm_handlers
.First(); 
 334         wxBitmapHandler 
*handler 
= (wxBitmapHandler 
*)node
->Data(); 
 335         if ( handler
->GetExtension() == extension 
&& 
 336                     (bitmapType 
== -1 || handler
->GetType() == bitmapType
) ) 
 343 wxBitmapHandler 
*wxBitmap::FindHandler(long bitmapType
) 
 345     wxNode 
*node 
= sm_handlers
.First(); 
 348         wxBitmapHandler 
*handler 
= (wxBitmapHandler 
*)node
->Data(); 
 349         if (handler
->GetType() == bitmapType
) 
 362     m_pixmap 
= (WXPixmap
) 0; 
 365 // Construct a mask from a bitmap and a colour indicating 
 366 // the transparent area 
 367 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
) 
 369     m_pixmap 
= (WXPixmap
) 0; 
 371     Create(bitmap
, colour
); 
 374 // Construct a mask from a bitmap and a palette index indicating 
 375 // the transparent area 
 376 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
) 
 378     m_pixmap 
= (WXPixmap
) 0; 
 380     Create(bitmap
, paletteIndex
); 
 383 // Construct a mask from a mono bitmap (copies the bitmap). 
 384 wxMask::wxMask(const wxBitmap
& bitmap
) 
 386     m_pixmap 
= (WXPixmap
) 0; 
 393     // TODO: this may be the wrong display 
 395         XFreePixmap ((Display
*) wxGetDisplay(), (Pixmap
) m_pixmap
); 
 398 // Create a mask from a mono bitmap (copies the bitmap). 
 399 bool wxMask::Create(const wxBitmap
& bitmap
) 
 405 // Create a mask from a bitmap and a palette index indicating 
 406 // the transparent area 
 407 bool wxMask::Create(const wxBitmap
& bitmap
, int paletteIndex
) 
 413 // Create a mask from a bitmap and a colour indicating 
 414 // the transparent area 
 415 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
) 
 425 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler
, wxObject
) 
 427 bool wxBitmapHandler::Create(wxBitmap 
*bitmap
, void *data
, long type
, int width
, int height
, int depth
) 
 432 bool wxBitmapHandler::LoadFile(wxBitmap 
*bitmap
, const wxString
& name
, long type
, 
 433         int desiredWidth
, int desiredHeight
) 
 438 bool wxBitmapHandler::SaveFile(wxBitmap 
*bitmap
, const wxString
& name
, int type
, const wxPalette 
*palette
) 
 447 class WXDLLEXPORT wxXBMFileHandler
: public wxBitmapHandler
 
 449     DECLARE_DYNAMIC_CLASS(wxXBMFileHandler
) 
 451     inline wxXBMFileHandler() 
 455         m_type 
= wxBITMAP_TYPE_XBM
; 
 458     virtual bool LoadFile(wxBitmap 
*bitmap
, const wxString
& name
, long flags
, 
 459           int desiredWidth
, int desiredHeight
); 
 461 IMPLEMENT_DYNAMIC_CLASS(wxXBMFileHandler
, wxBitmapHandler
) 
 463 bool wxXBMFileHandler::LoadFile(wxBitmap 
*bitmap
, const wxString
& name
, long flags
, 
 464           int desiredWidth
, int desiredHeight
) 
 466     M_BITMAPHANDLERDATA
->m_freePixmap 
= TRUE
; 
 472     Display 
*dpy 
= (Display
*) wxGetDisplay(); 
 473     M_BITMAPDATA
->m_display 
= (WXDisplay
*) dpy
; 
 475     int value 
= XReadBitmapFile (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)), 
 476                         (char*) (const char*) name
, &w
, &h
, &pixmap
, &hotX
, &hotY
); 
 477     M_BITMAPHANDLERDATA
->m_width 
= w
; 
 478     M_BITMAPHANDLERDATA
->m_height 
= h
; 
 479     M_BITMAPHANDLERDATA
->m_depth 
= 1; 
 480     M_BITMAPHANDLERDATA
->m_pixmap 
= (WXPixmap
) pixmap
; 
 482     if ((value 
== BitmapFileInvalid
) || 
 483         (value 
== BitmapOpenFailed
) || 
 484         (value 
== BitmapNoMemory
)) 
 486         M_BITMAPHANDLERDATA
->m_ok 
= FALSE
; 
 487         M_BITMAPHANDLERDATA
->m_pixmap 
= (WXPixmap
) 0; 
 490         M_BITMAPHANDLERDATA
->m_ok 
= TRUE
; 
 492     return M_BITMAPHANDLERDATA
->m_ok 
; 
 495 class WXDLLEXPORT wxXBMDataHandler
: public wxBitmapHandler
 
 497     DECLARE_DYNAMIC_CLASS(wxXBMDataHandler
) 
 499     inline wxXBMDataHandler() 
 503         m_type 
= wxBITMAP_TYPE_XBM_DATA
; 
 506     virtual bool Create(wxBitmap 
*bitmap
, void *data
, long flags
, int width
, int height
, int depth 
= 1); 
 508 IMPLEMENT_DYNAMIC_CLASS(wxXBMDataHandler
, wxBitmapHandler
) 
 510 bool wxXBMDataHandler::Create(wxBitmap 
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
) 
 512     M_BITMAPHANDLERDATA
->m_width 
= width
; 
 513     M_BITMAPHANDLERDATA
->m_height 
= height
; 
 514     M_BITMAPHANDLERDATA
->m_depth 
= 1; 
 515     M_BITMAPHANDLERDATA
->m_freePixmap 
= TRUE
; 
 517     Display 
*dpy 
= (Display
*) wxGetDisplay(); 
 518     M_BITMAPHANDLERDATA
->m_display 
= (WXDisplay
*) dpy
; 
 520     M_BITMAPHANDLERDATA
->m_pixmap 
= (WXPixmap
) XCreateBitmapFromData (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)), (char*) data
, width
, height
); 
 521     M_BITMAPHANDLERDATA
->m_ok 
= (M_BITMAPHANDLERDATA
->m_pixmap 
!= (WXPixmap
) 0) ; 
 523     // code for wxControl. TODO: can we avoid doing this until we need it? 
 524     // E.g. have CreateButtonPixmaps which is called on demand. 
 525     XImage
* image 
= (XImage 
*) XtMalloc (sizeof (XImage
)); 
 526     image
->width 
= width
; 
 527     image
->height 
= height
; 
 528     image
->data 
= (char*) data
; 
 531     image
->format 
= XYBitmap
; 
 532     image
->byte_order 
= LSBFirst
; 
 533     image
->bitmap_unit 
= 8; 
 534     image
->bitmap_bit_order 
= LSBFirst
; 
 535     image
->bitmap_pad 
= 8; 
 536     image
->bytes_per_line 
= (width 
+ 7) >> 3; 
 539     sprintf (tmp
, "Im%x", (unsigned int) image
); 
 540     XmInstallImage (image
, tmp
); 
 542     // Build our manually stipped pixmap. 
 544     int bpl 
= (width 
+ 7) / 8; 
 545     char *data1 
= new char[height 
* bpl
]; 
 546     char* bits 
= (char*) data
; 
 548     for (i 
= 0; i 
< height
; i
++) 
 550         int mask 
= i 
% 2 ? 0x55 : 0xaa; 
 552         for (j 
= 0; j 
< bpl
; j
++) 
 553             data1
[i 
* bpl 
+ j
] = bits
[i 
* bpl 
+ j
] & mask
; 
 555     XImage
* insensImage 
= (XImage 
*) XtMalloc (sizeof (XImage
)); 
 556     insensImage
->width 
= width
; 
 557     insensImage
->height 
= height
; 
 558     insensImage
->data 
= data1
; 
 559     insensImage
->depth 
= 1; 
 560     insensImage
->xoffset 
= 0; 
 561     insensImage
->format 
= XYBitmap
; 
 562     insensImage
->byte_order 
= LSBFirst
; 
 563     insensImage
->bitmap_unit 
= 8; 
 564     insensImage
->bitmap_bit_order 
= LSBFirst
; 
 565     insensImage
->bitmap_pad 
= 8; 
 566     insensImage
->bytes_per_line 
= bpl
; 
 568     sprintf (tmp
, "Not%x", (unsigned int)insensImage
); 
 569     XmInstallImage (insensImage
, tmp
); 
 571     M_BITMAPHANDLERDATA
->m_image 
= (WXImage
*) image
; 
 572     M_BITMAPHANDLERDATA
->m_insensImage 
= (WXImage
*) insensImage
; 
 578 class WXDLLEXPORT wxXPMFileHandler
: public wxBitmapHandler
 
 580     DECLARE_DYNAMIC_CLASS(wxXPMFileHandler
) 
 582     inline wxXPMFileHandler() 
 586         m_type 
= wxBITMAP_TYPE_XPM
; 
 589     virtual bool LoadFile(wxBitmap 
*bitmap
, const wxString
& name
, long flags
, 
 590           int desiredWidth
, int desiredHeight
); 
 591     virtual bool SaveFile(wxBitmap 
*bitmap
, const wxString
& name
, int type
, const wxPalette 
*palette 
= NULL
); 
 594 IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler
, wxBitmapHandler
) 
 596 bool wxXPMFileHandler::LoadFile(wxBitmap 
*bitmap
, const wxString
& name
, long flags
, 
 597           int desiredWidth
, int desiredHeight
) 
 599     Display 
*dpy 
= (Display
*) wxGetDisplay(); 
 600     M_BITMAPHANDLERDATA
->m_display 
= (WXDisplay
*) dpy
; 
 602     XpmAttributes xpmAttr
; 
 606     M_BITMAPHANDLERDATA
->m_ok 
= FALSE
; 
 607     xpmAttr
.valuemask 
= XpmReturnInfos 
| XpmCloseness
; 
 608     xpmAttr
.closeness 
= 40000; 
 609     int errorStatus 
= XpmReadFileToPixmap(dpy
, 
 610         RootWindow(dpy
, DefaultScreen(dpy
)), (char*) (const char*) name
, 
 611         &pixmap
, &mask
, &xpmAttr
); 
 613     if (errorStatus 
== XpmSuccess
) 
 615         M_BITMAPHANDLERDATA
->m_pixmap 
= (WXPixmap
) pixmap
; 
 618             M_BITMAPHANDLERDATA
->m_bitmapMask 
= new wxMask
; 
 619             M_BITMAPHANDLERDATA
->m_bitmapMask
->SetPixmap((WXPixmap
) mask
); 
 622         unsigned int depthRet
; 
 624         unsigned int widthRet
, heightRet
, borderWidthRet
; 
 625         Window rootWindowRet
; 
 626         XGetGeometry(dpy
, pixmap
, &rootWindowRet
, &xRet
, &yRet
, 
 627             &widthRet
, &heightRet
, &borderWidthRet
, &depthRet
); 
 629         M_BITMAPHANDLERDATA
->m_width 
= xpmAttr
.width
; 
 630         M_BITMAPHANDLERDATA
->m_height 
= xpmAttr
.height
; 
 633         if ( xpmAttr.npixels > 2 ) 
 635             M_BITMAPHANDLERDATA->m_depth = 8;   // TODO: next time not just a guess :-) ... 
 638             M_BITMAPHANDLERDATA->m_depth = 1;   // mono 
 642         M_BITMAPHANDLERDATA
->m_depth 
= depthRet
; 
 644         M_BITMAPHANDLERDATA
->m_numColors 
= xpmAttr
.npixels
; 
 646             XpmFreeAttributes(&xpmAttr
); 
 648         M_BITMAPHANDLERDATA
->m_ok 
= TRUE
; 
 652 //      XpmDebugError(errorStatus, name); 
 653         M_BITMAPHANDLERDATA
->m_ok 
= FALSE
; 
 658 bool wxXPMFileHandler::SaveFile(wxBitmap 
*bitmap
, const wxString
& name
, int type
, const wxPalette 
*palette
) 
 660     if (M_BITMAPHANDLERDATA
->m_ok 
&& M_BITMAPHANDLERDATA
->m_pixmap
) 
 662         Display 
*dpy 
=  (Display
*) M_BITMAPHANDLERDATA
->m_display
; 
 663         int errorStatus 
= XpmWriteFileFromPixmap(dpy
, (char*) (const char*) name
, 
 664           (Pixmap
) M_BITMAPHANDLERDATA
->m_pixmap
, 
 665           (M_BITMAPHANDLERDATA
->m_bitmapMask 
? (Pixmap
) M_BITMAPHANDLERDATA
->m_bitmapMask
->GetPixmap() : (Pixmap
) 0), 
 666           (XpmAttributes 
*) NULL
); 
 667         if (errorStatus 
== XpmSuccess
) 
 676 class WXDLLEXPORT wxXPMDataHandler
: public wxBitmapHandler
 
 678     DECLARE_DYNAMIC_CLASS(wxXPMDataHandler
) 
 680     inline wxXPMDataHandler() 
 684         m_type 
= wxBITMAP_TYPE_XPM_DATA
; 
 687     virtual bool Create(wxBitmap 
*bitmap
, void *data
, long flags
, int width
, int height
, int depth 
= 1); 
 689 IMPLEMENT_DYNAMIC_CLASS(wxXPMDataHandler
, wxBitmapHandler
) 
 691 bool wxXPMDataHandler::Create(wxBitmap 
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
) 
 693     M_BITMAPHANDLERDATA
->m_width 
= width
; 
 694     M_BITMAPHANDLERDATA
->m_height 
= height
; 
 695     M_BITMAPHANDLERDATA
->m_depth 
= 1; 
 696     M_BITMAPHANDLERDATA
->m_freePixmap 
= TRUE
; 
 698     Display 
*dpy 
= (Display
*) wxGetDisplay(); 
 699     M_BITMAPHANDLERDATA
->m_display 
= (WXDisplay
*) dpy
; 
 701     XpmAttributes xpmAttr
; 
 703     xpmAttr
.valuemask 
= XpmReturnInfos
;    /* nothing yet, but get infos back */ 
 705     XpmColorSymbol symbolicColors
[4]; 
 706     if (sg_Control 
&& sg_Control
->GetMainWidget()) 
 708         symbolicColors
[0].name 
= "foreground"; 
 709         symbolicColors
[0].value 
= NULL
; 
 710         symbolicColors
[1].name 
= "background"; 
 711         symbolicColors
[1].value 
= NULL
; 
 712         XtVaGetValues((Widget
) sg_Control
->GetMainWidget(), 
 713             XmNforeground
,  &symbolicColors
[0].pixel
, 
 714             XmNbackground
,  &symbolicColors
[1].pixel
,NULL
); 
 715         xpmAttr
.numsymbols 
= 2; 
 716         xpmAttr
.colorsymbols 
= symbolicColors
; 
 717         xpmAttr
.valuemask 
|= XpmColorSymbols
;    // add flag 
 722     int ErrorStatus 
= XpmCreatePixmapFromData(dpy
, RootWindow(dpy
, DefaultScreen(dpy
)), 
 723                (char**) data
, &pixmap
, &mask
, &xpmAttr
); 
 724     if (ErrorStatus 
== XpmSuccess
) 
 727         M_BITMAPHANDLERDATA
->m_width 
= xpmAttr
.width
; 
 728         M_BITMAPHANDLERDATA
->m_height 
= xpmAttr
.height
; 
 730         unsigned int depthRet
; 
 732         unsigned int widthRet
, heightRet
, borderWidthRet
; 
 733         Window rootWindowRet
; 
 734         XGetGeometry(dpy
, pixmap
, &rootWindowRet
, &xRet
, &yRet
, 
 735             &widthRet
, &heightRet
, &borderWidthRet
, &depthRet
); 
 738         if ( xpmAttr.npixels > 2 ) 
 740             M_BITMAPHANDLERDATA->m_depth = 8;    // next time not just a guess :-) ... 
 743             M_BITMAPHANDLERDATA->m_depth = 1;    // mono 
 747         M_BITMAPHANDLERDATA
->m_depth 
= depthRet
; 
 749         M_BITMAPHANDLERDATA
->m_numColors 
= xpmAttr
.npixels
; 
 750         XpmFreeAttributes(&xpmAttr
); 
 751         M_BITMAPHANDLERDATA
->m_ok 
= TRUE
; 
 752         M_BITMAPHANDLERDATA
->m_pixmap 
= (WXPixmap
) pixmap
; 
 755             M_BITMAPHANDLERDATA
->m_bitmapMask 
= new wxMask
; 
 756             M_BITMAPHANDLERDATA
->m_bitmapMask
->SetPixmap((WXPixmap
) mask
); 
 761 //      XpmDebugError(ErrorStatus, NULL); 
 762         M_BITMAPHANDLERDATA
->m_ok 
= FALSE
; 
 764     return M_BITMAPHANDLERDATA
->m_ok 
; 
 769 void wxBitmap::CleanUpHandlers() 
 771     wxNode 
*node 
= sm_handlers
.First(); 
 774         wxBitmapHandler 
*handler 
= (wxBitmapHandler 
*)node
->Data(); 
 775         wxNode 
*next 
= node
->Next(); 
 782 void wxBitmap::InitStandardHandlers() 
 784     // Initialize all standard bitmap or derived class handlers here. 
 785     AddHandler(new wxXBMFileHandler
); 
 786     AddHandler(new wxXBMDataHandler
); 
 788     // XPM is considered standard for Moif, although it can be omitted if absolutely 
 791     AddHandler(new wxXPMFileHandler
); 
 792     AddHandler(new wxXPMDataHandler
); 
 796 WXPixmap 
wxBitmap::GetLabelPixmap (WXWidget w
) 
 798   if (M_BITMAPDATA
->m_image 
== (WXPixmap
) 0) 
 799     return M_BITMAPDATA
->m_pixmap
; 
 801   Display 
*dpy 
= (Display
*) M_BITMAPDATA
->m_display
; 
 806    if (labelPixmap) return labelPixmap; 
 807    things can be wrong, because colors can have been changed. 
 811    XmDestroyPixmap(DefaultScreenOfDisplay(dpy),labelPixmap) ; 
 812    we got BadDrawable if the pixmap is referenced by multiples widgets 
 816    So, before doing thing really clean, I just do nothing; if the pixmap is 
 817    referenced by many widgets, Motif performs caching functions. 
 818    And if pixmap is referenced with multiples colors, we just have some 
 819    memory leaks... I hope we can deal with them... 
 821   // Must be destroyed, because colours can have been changed! 
 822   if (M_BITMAPDATA
->m_labelPixmap
) 
 823     XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), M_BITMAPDATA
->m_labelPixmap
); 
 827   sprintf (tmp
, "Im%x", (unsigned int) M_BITMAPDATA
->m_image
); 
 830   Widget widget 
= (Widget
) w
; 
 832   while (XmIsGadget ( widget 
)) 
 833     widget 
= XtParent (widget
); 
 834   XtVaGetValues (widget
, XmNbackground
, &bg
, XmNforeground
, &fg
, NULL
); 
 836   M_BITMAPDATA
->m_labelPixmap 
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
); 
 838   return M_BITMAPDATA
->m_labelPixmap
; 
 841 WXPixmap 
wxBitmap::GetArmPixmap (WXWidget w
) 
 843   if (M_BITMAPDATA
->m_image 
== (WXPixmap
) 0) 
 844     return M_BITMAPDATA
->m_pixmap
; 
 846   Display 
*dpy 
= (Display
*) M_BITMAPDATA
->m_display
; 
 848   See 
GetLabelPixmap () comment
 
 849   // Must be destroyed, because colours can have been changed! 
 850   if (M_BITMAPDATA
->m_armPixmap
) 
 851       XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), M_BITMAPDATA
->m_armPixmap
); 
 855   sprintf (tmp
, "Im%x", (unsigned int) M_BITMAPDATA
->m_image
); 
 858   Widget widget 
= (Widget
) w
; 
 860   XtVaGetValues (widget
, XmNarmColor
, &bg
, NULL
); 
 861   while (XmIsGadget (widget
)) 
 862     widget 
= XtParent (widget
); 
 863   XtVaGetValues (widget
, XmNforeground
, &fg
, NULL
); 
 865   M_BITMAPDATA
->m_armPixmap 
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
); 
 867   return M_BITMAPDATA
->m_armPixmap
; 
 870 WXPixmap 
wxBitmap::GetInsensPixmap (WXWidget w
) 
 872   Display 
*dpy 
= (Display
*) M_BITMAPDATA
->m_display
; 
 874   if (M_BITMAPDATA
->m_insensPixmap
) 
 875     return M_BITMAPDATA
->m_insensPixmap
; 
 879     M_BITMAPDATA
->m_insensPixmap 
= (WXPixmap
) XCreateInsensitivePixmap(dpy
, (Pixmap
) M_BITMAPDATA
->m_pixmap
); 
 880     if (M_BITMAPDATA
->m_insensPixmap
) 
 881       return M_BITMAPDATA
->m_insensPixmap
; 
 883       return M_BITMAPDATA
->m_pixmap
; 
 886   if (M_BITMAPDATA
->m_insensImage 
== (WXPixmap
) 0) 
 887     return M_BITMAPDATA
->m_pixmap
; 
 890   See 
GetLabelPixmap () comment
 
 891   // Must be destroyed, because colours can have been changed! 
 892   if (M_BITMAPDATA
->m_insensPixmap
) 
 893       XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), (Pixmap
) M_BITMAPDATA
->m_insensPixmap
); 
 897   sprintf (tmp
, "Not%x", (unsigned int) M_BITMAPDATA
->m_insensImage
); 
 900   Widget widget 
= (Widget
) w
; 
 902   while (XmIsGadget (widget
)) 
 903     widget 
= XtParent (widget
); 
 904   XtVaGetValues (widget
, XmNbackground
, &bg
, XmNforeground
, &fg
, NULL
); 
 906   M_BITMAPDATA
->m_insensPixmap 
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
); 
 908   return M_BITMAPDATA
->m_insensPixmap
; 
 911 // We may need this sometime... 
 913 /**************************************************************************** 
 916     XCreateInsensitivePixmap - create a grayed-out copy of a pixmap 
 919     Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ) 
 922     This function creates a grayed-out copy of the argument pixmap, suitable 
 923     for use as a XmLabel's XmNlabelInsensitivePixmap resource. 
 926     The return value is the new Pixmap id or zero on error.  Errors include 
 927     a NULL display argument or an invalid Pixmap argument. 
 930     If one of the XLib functions fail, it will produce a X error.  The 
 931     default X error handler prints a diagnostic and calls exit(). 
 934     XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3), 
 935     XFillRectangle(3), exit(2) 
 938     John R Veregge - john@puente.jpl.nasa.gov 
 939     Advanced Engineering and Prototyping Group (AEG) 
 940     Information Systems Technology Section (395) 
 941     Jet Propulsion Lab - Calif Institute of Technology 
 943 *****************************************************************************/ 
 946 XCreateInsensitivePixmap( Display 
*display
, Pixmap pixmap 
) 
 950     char    stipple_data
[] =  
 952             0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 
 953             0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 
 954             0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, 
 955             0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA 
 958     Pixmap    ipixmap
, stipple
; 
 959     unsigned    width
, height
, depth
; 
 961     Window    window
;    /* These return values */ 
 962     unsigned    border
;    /* from XGetGeometry() */ 
 963     int        x
, y
;    /* are not needed.     */ 
 967     if ( NULL 
== display 
|| 0 == pixmap 
) 
 970     if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
, 
 971                 &width
, &height
, &border
, &depth 
) 
 973     return ipixmap
; /* BadDrawable: probably an invalid pixmap */ 
 975     /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap. 
 977     stipple 
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 ); 
 980     gc 
= XCreateGC( display
, pixmap
, (XtGCMask
)0, (XGCValues
*)NULL 
); 
 983         /* Create an identical copy of the argument pixmap. 
 985         ipixmap 
= XCreatePixmap( display
, pixmap
, width
, height
, depth 
); 
 988         /* Copy the argument pixmap into the new pixmap. 
 990         XCopyArea( display
, pixmap
, ipixmap
, 
 991                gc
, 0, 0, width
, height
, 0, 0 ); 
 993         /* Refill the new pixmap using the stipple algorithm/pixmap. 
 995         XSetStipple( display
, gc
, stipple 
); 
 996         XSetFillStyle( display
, gc
, FillStippled 
); 
 997         XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height 
); 
 999         XFreeGC( display
, gc 
); 
1001     XFreePixmap( display
, stipple 
);