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"
23 #include "wx/dcmemory.h"
27 #pragma message disable nosimpint
31 #pragma message enable nosimpint
34 #include "wx/motif/private.h"
40 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
, wxGDIObject
)
41 IMPLEMENT_DYNAMIC_CLASS(wxMask
, wxObject
)
43 wxBitmapRefData::wxBitmapRefData()
53 m_pixmap
= (WXPixmap
) 0;
54 m_display
= (WXDisplay
*) 0;
56 m_freePixmap
= TRUE
; //TODO: necessary?
57 m_freeColors
= (unsigned long*) 0;
58 m_freeColorsCount
= 0;
60 // These 5 variables are for wxControl
61 m_insensPixmap
= (WXPixmap
) 0;
62 m_labelPixmap
= (WXPixmap
) 0;
63 m_armPixmap
= (WXPixmap
) 0;
64 m_image
= (WXImage
*) 0;
65 m_insensImage
= (WXImage
*) 0;
68 wxBitmapRefData::~wxBitmapRefData()
71 XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) m_display
), (Pixmap
) m_labelPixmap
);
74 XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) m_display
), (Pixmap
) m_armPixmap
);
77 XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) m_display
), (Pixmap
) m_insensPixmap
);
81 XmUninstallImage ((XImage
*) m_image
);
82 XtFree ((char *) (XImage
*) m_image
);
87 XmUninstallImage ((XImage
*) m_insensImage
);
88 delete[] ((XImage
*) m_insensImage
)->data
;
89 XtFree ((char *) (XImage
*) m_insensImage
);
91 if (m_pixmap
&& m_freePixmap
)
92 XFreePixmap ((Display
*) m_display
, (Pixmap
) m_pixmap
);
96 int screen
= DefaultScreen((Display
*) m_display
);
97 Colormap cmp
= DefaultColormap((Display
*) m_display
,screen
);
99 for(llp
= 0;llp
< m_freeColorsCount
;llp
++)
100 XFreeColors((Display
*) m_display
, cmp
, &m_freeColors
[llp
], 1, 0L);
109 wxList
wxBitmap::sm_handlers
;
115 if ( wxTheBitmapList
)
116 wxTheBitmapList
->AddBitmap(this);
119 wxBitmap::~wxBitmap()
122 wxTheBitmapList
->DeleteObject(this);
125 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
)
127 m_refData
= new wxBitmapRefData
;
129 (void) Create((void*) bits
, wxBITMAP_TYPE_XBM_DATA
, width
, height
, depth
);
131 if ( wxTheBitmapList
)
132 wxTheBitmapList
->AddBitmap(this);
135 wxBitmap::wxBitmap(int w
, int h
, int d
)
137 (void)Create(w
, h
, d
);
139 if ( wxTheBitmapList
)
140 wxTheBitmapList
->AddBitmap(this);
143 wxBitmap::wxBitmap(void *data
, long type
, int width
, int height
, int depth
)
145 (void) Create(data
, type
, width
, height
, depth
);
147 if ( wxTheBitmapList
)
148 wxTheBitmapList
->AddBitmap(this);
151 wxBitmap::wxBitmap(const wxString
& filename
, long type
)
153 LoadFile(filename
, (int)type
);
155 if ( wxTheBitmapList
)
156 wxTheBitmapList
->AddBitmap(this);
159 // Create from XPM data
160 static wxControl
* sg_Control
= NULL
;
161 wxBitmap::wxBitmap(char **data
, wxControl
* control
)
163 // Pass the control to the Create function using a global
164 sg_Control
= control
;
166 (void) Create((void *)data
, wxBITMAP_TYPE_XPM_DATA
, 0, 0, 0);
168 sg_Control
= (wxControl
*) NULL
;
171 bool wxBitmap::Create(int w
, int h
, int d
)
175 m_refData
= new wxBitmapRefData
;
178 d
= wxDisplayDepth();
180 M_BITMAPDATA
->m_width
= w
;
181 M_BITMAPDATA
->m_height
= h
;
182 M_BITMAPDATA
->m_depth
= d
;
183 M_BITMAPDATA
->m_freePixmap
= TRUE
;
185 Display
*dpy
= (Display
*) wxGetDisplay();
187 M_BITMAPDATA
->m_display
= dpy
; /* MATTHEW: [4] Remember the display */
189 M_BITMAPDATA
->m_pixmap
= (WXPixmap
) XCreatePixmap (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)),
192 M_BITMAPDATA
->m_ok
= (M_BITMAPDATA
->m_pixmap
!= (WXPixmap
) 0) ;
193 return M_BITMAPDATA
->m_ok
;
196 bool wxBitmap::LoadFile(const wxString
& filename
, long type
)
200 m_refData
= new wxBitmapRefData
;
202 wxBitmapHandler
*handler
= FindHandler(type
);
204 if ( handler
== NULL
) {
206 if (!image
.LoadFile( filename
, type
)) return FALSE
;
209 *this = image
.ConvertToBitmap();
215 return handler
->LoadFile(this, filename
, type
, -1, -1);
218 bool wxBitmap::Create(void *data
, long type
, int width
, int height
, int depth
)
222 m_refData
= new wxBitmapRefData
;
224 wxBitmapHandler
*handler
= FindHandler(type
);
226 if ( handler
== NULL
) {
227 wxLogWarning("no data bitmap handler for type %d defined.", type
);
232 return handler
->Create(this, data
, type
, width
, height
, depth
);
235 bool wxBitmap::SaveFile(const wxString
& filename
, int type
, const wxPalette
*palette
)
237 wxBitmapHandler
*handler
= FindHandler(type
);
239 if ( handler
== NULL
) { // try wxImage
240 wxImage
image( *this );
241 if (image
.Ok()) return image
.SaveFile( filename
, type
);
245 return handler
->SaveFile(this, filename
, type
, palette
);
248 void wxBitmap::SetWidth(int w
)
251 m_refData
= new wxBitmapRefData
;
253 M_BITMAPDATA
->m_width
= w
;
256 void wxBitmap::SetHeight(int h
)
259 m_refData
= new wxBitmapRefData
;
261 M_BITMAPDATA
->m_height
= h
;
264 void wxBitmap::SetDepth(int d
)
267 m_refData
= new wxBitmapRefData
;
269 M_BITMAPDATA
->m_depth
= d
;
272 void wxBitmap::SetQuality(int q
)
275 m_refData
= new wxBitmapRefData
;
277 M_BITMAPDATA
->m_quality
= q
;
280 void wxBitmap::SetOk(bool isOk
)
283 m_refData
= new wxBitmapRefData
;
285 M_BITMAPDATA
->m_ok
= isOk
;
288 void wxBitmap::SetPalette(const wxPalette
& palette
)
291 m_refData
= new wxBitmapRefData
;
293 M_BITMAPDATA
->m_bitmapPalette
= palette
;
296 void wxBitmap::SetMask(wxMask
*mask
)
299 m_refData
= new wxBitmapRefData
;
301 M_BITMAPDATA
->m_bitmapMask
= mask
;
304 void wxBitmap::AddHandler(wxBitmapHandler
*handler
)
306 sm_handlers
.Append(handler
);
309 void wxBitmap::InsertHandler(wxBitmapHandler
*handler
)
311 sm_handlers
.Insert(handler
);
314 bool wxBitmap::RemoveHandler(const wxString
& name
)
316 wxBitmapHandler
*handler
= FindHandler(name
);
319 sm_handlers
.DeleteObject(handler
);
326 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& name
)
328 wxNode
*node
= sm_handlers
.First();
331 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
332 if ( handler
->GetName() == name
)
339 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& extension
, long bitmapType
)
341 wxNode
*node
= sm_handlers
.First();
344 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
345 if ( handler
->GetExtension() == extension
&&
346 (bitmapType
== -1 || handler
->GetType() == bitmapType
) )
353 wxBitmapHandler
*wxBitmap::FindHandler(long bitmapType
)
355 wxNode
*node
= sm_handlers
.First();
358 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
359 if (handler
->GetType() == bitmapType
)
372 m_pixmap
= (WXPixmap
) 0;
375 // Construct a mask from a bitmap and a colour indicating
376 // the transparent area
377 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
379 m_pixmap
= (WXPixmap
) 0;
381 Create(bitmap
, colour
);
384 // Construct a mask from a bitmap and a palette index indicating
385 // the transparent area
386 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
388 m_pixmap
= (WXPixmap
) 0;
390 Create(bitmap
, paletteIndex
);
393 // Construct a mask from a mono bitmap (copies the bitmap).
394 wxMask::wxMask(const wxBitmap
& bitmap
)
396 m_pixmap
= (WXPixmap
) 0;
403 // TODO: this may be the wrong display
405 XFreePixmap ((Display
*) wxGetDisplay(), (Pixmap
) m_pixmap
);
408 // Create a mask from a mono bitmap (copies the bitmap).
409 bool wxMask::Create(const wxBitmap
& WXUNUSED(bitmap
))
415 // Create a mask from a bitmap and a palette index indicating
416 // the transparent area
417 bool wxMask::Create(const wxBitmap
& WXUNUSED(bitmap
), int WXUNUSED(paletteIndex
))
423 // Create a mask from a bitmap and a colour indicating
424 // the transparent area
425 bool wxMask::Create(const wxBitmap
& WXUNUSED(bitmap
), const wxColour
& WXUNUSED(colour
))
435 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler
, wxObject
)
437 bool wxBitmapHandler::Create(wxBitmap
*WXUNUSED(bitmap
), void *WXUNUSED(data
), long WXUNUSED(type
),
438 int WXUNUSED(width
), int WXUNUSED(height
), int WXUNUSED(depth
))
443 bool wxBitmapHandler::LoadFile(wxBitmap
*WXUNUSED(bitmap
), const wxString
& WXUNUSED(name
), long WXUNUSED(type
),
444 int WXUNUSED(desiredWidth
), int WXUNUSED(desiredHeight
))
449 bool wxBitmapHandler::SaveFile(wxBitmap
*WXUNUSED(bitmap
), const wxString
& WXUNUSED(name
), int WXUNUSED(type
),
450 const wxPalette
*WXUNUSED(palette
))
459 class WXDLLEXPORT wxXBMFileHandler
: public wxBitmapHandler
461 DECLARE_DYNAMIC_CLASS(wxXBMFileHandler
)
463 inline wxXBMFileHandler()
467 m_type
= wxBITMAP_TYPE_XBM
;
470 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
471 int desiredWidth
, int desiredHeight
);
473 IMPLEMENT_DYNAMIC_CLASS(wxXBMFileHandler
, wxBitmapHandler
)
475 bool wxXBMFileHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long WXUNUSED(flags
),
476 int WXUNUSED(desiredWidth
), int WXUNUSED(desiredHeight
))
478 M_BITMAPHANDLERDATA
->m_freePixmap
= TRUE
;
484 Display
*dpy
= (Display
*) wxGetDisplay();
485 M_BITMAPDATA
->m_display
= (WXDisplay
*) dpy
;
487 int value
= XReadBitmapFile (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)),
488 (char*) (const char*) name
, &w
, &h
, &pixmap
, &hotX
, &hotY
);
489 M_BITMAPHANDLERDATA
->m_width
= w
;
490 M_BITMAPHANDLERDATA
->m_height
= h
;
491 M_BITMAPHANDLERDATA
->m_depth
= 1;
492 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) pixmap
;
494 if ((value
== BitmapFileInvalid
) ||
495 (value
== BitmapOpenFailed
) ||
496 (value
== BitmapNoMemory
))
498 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
499 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) 0;
502 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
504 return M_BITMAPHANDLERDATA
->m_ok
;
507 class WXDLLEXPORT wxXBMDataHandler
: public wxBitmapHandler
509 DECLARE_DYNAMIC_CLASS(wxXBMDataHandler
)
511 inline wxXBMDataHandler()
515 m_type
= wxBITMAP_TYPE_XBM_DATA
;
518 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
520 IMPLEMENT_DYNAMIC_CLASS(wxXBMDataHandler
, wxBitmapHandler
)
522 bool wxXBMDataHandler::Create( wxBitmap
*bitmap
, void *data
, long WXUNUSED(flags
),
523 int width
, int height
, int WXUNUSED(depth
))
525 M_BITMAPHANDLERDATA
->m_width
= width
;
526 M_BITMAPHANDLERDATA
->m_height
= height
;
527 M_BITMAPHANDLERDATA
->m_depth
= 1;
528 M_BITMAPHANDLERDATA
->m_freePixmap
= TRUE
;
530 Display
*dpy
= (Display
*) wxGetDisplay();
531 M_BITMAPHANDLERDATA
->m_display
= (WXDisplay
*) dpy
;
533 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) XCreateBitmapFromData (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)), (char*) data
, width
, height
);
534 M_BITMAPHANDLERDATA
->m_ok
= (M_BITMAPHANDLERDATA
->m_pixmap
!= (WXPixmap
) 0) ;
536 // code for wxControl. TODO: can we avoid doing this until we need it?
537 // E.g. have CreateButtonPixmaps which is called on demand.
538 XImage
* image
= (XImage
*) XtMalloc (sizeof (XImage
));
539 image
->width
= width
;
540 image
->height
= height
;
541 image
->data
= (char*) data
;
544 image
->format
= XYBitmap
;
545 image
->byte_order
= LSBFirst
;
546 image
->bitmap_unit
= 8;
547 image
->bitmap_bit_order
= LSBFirst
;
548 image
->bitmap_pad
= 8;
549 image
->bytes_per_line
= (width
+ 7) >> 3;
552 sprintf (tmp
, "Im%x", (unsigned int) image
);
553 XmInstallImage (image
, tmp
);
555 // Build our manually stipped pixmap.
557 int bpl
= (width
+ 7) / 8;
558 char *data1
= new char[height
* bpl
];
559 char* bits
= (char*) data
;
561 for (i
= 0; i
< height
; i
++)
563 int mask
= i
% 2 ? 0x55 : 0xaa;
565 for (j
= 0; j
< bpl
; j
++)
566 data1
[i
* bpl
+ j
] = bits
[i
* bpl
+ j
] & mask
;
568 XImage
* insensImage
= (XImage
*) XtMalloc (sizeof (XImage
));
569 insensImage
->width
= width
;
570 insensImage
->height
= height
;
571 insensImage
->data
= data1
;
572 insensImage
->depth
= 1;
573 insensImage
->xoffset
= 0;
574 insensImage
->format
= XYBitmap
;
575 insensImage
->byte_order
= LSBFirst
;
576 insensImage
->bitmap_unit
= 8;
577 insensImage
->bitmap_bit_order
= LSBFirst
;
578 insensImage
->bitmap_pad
= 8;
579 insensImage
->bytes_per_line
= bpl
;
581 sprintf (tmp
, "Not%x", (unsigned int)insensImage
);
582 XmInstallImage (insensImage
, tmp
);
584 M_BITMAPHANDLERDATA
->m_image
= (WXImage
*) image
;
585 M_BITMAPHANDLERDATA
->m_insensImage
= (WXImage
*) insensImage
;
591 class WXDLLEXPORT wxXPMFileHandler
: public wxBitmapHandler
593 DECLARE_DYNAMIC_CLASS(wxXPMFileHandler
)
595 inline wxXPMFileHandler()
599 m_type
= wxBITMAP_TYPE_XPM
;
602 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
603 int desiredWidth
, int desiredHeight
);
604 virtual bool SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
607 IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler
, wxBitmapHandler
)
609 bool wxXPMFileHandler::LoadFile( wxBitmap
*bitmap
, const wxString
& name
, long WXUNUSED(flags
),
610 int WXUNUSED(desiredWidth
), int WXUNUSED(desiredHeight
) )
612 Display
*dpy
= (Display
*) wxGetDisplay();
613 M_BITMAPHANDLERDATA
->m_display
= (WXDisplay
*) dpy
;
615 XpmAttributes xpmAttr
;
619 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
620 xpmAttr
.valuemask
= XpmReturnInfos
| XpmCloseness
;
621 xpmAttr
.closeness
= 40000;
622 int errorStatus
= XpmReadFileToPixmap(dpy
,
623 RootWindow(dpy
, DefaultScreen(dpy
)), (char*) (const char*) name
,
624 &pixmap
, &mask
, &xpmAttr
);
626 if (errorStatus
== XpmSuccess
)
628 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) pixmap
;
631 M_BITMAPHANDLERDATA
->m_bitmapMask
= new wxMask
;
632 M_BITMAPHANDLERDATA
->m_bitmapMask
->SetPixmap((WXPixmap
) mask
);
635 unsigned int depthRet
;
637 unsigned int widthRet
, heightRet
, borderWidthRet
;
638 Window rootWindowRet
;
639 XGetGeometry(dpy
, pixmap
, &rootWindowRet
, &xRet
, &yRet
,
640 &widthRet
, &heightRet
, &borderWidthRet
, &depthRet
);
642 M_BITMAPHANDLERDATA
->m_width
= xpmAttr
.width
;
643 M_BITMAPHANDLERDATA
->m_height
= xpmAttr
.height
;
646 if ( xpmAttr.npixels > 2 )
648 M_BITMAPHANDLERDATA->m_depth = 8; // TODO: next time not just a guess :-) ...
651 M_BITMAPHANDLERDATA->m_depth = 1; // mono
655 M_BITMAPHANDLERDATA
->m_depth
= depthRet
;
657 M_BITMAPHANDLERDATA
->m_numColors
= xpmAttr
.npixels
;
659 XpmFreeAttributes(&xpmAttr
);
661 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
665 // XpmDebugError(errorStatus, name);
666 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
671 bool wxXPMFileHandler::SaveFile( wxBitmap
*bitmap
, const wxString
& name
, int WXUNUSED(type
),
672 const wxPalette
*WXUNUSED(palette
))
674 if (M_BITMAPHANDLERDATA
->m_ok
&& M_BITMAPHANDLERDATA
->m_pixmap
)
676 Display
*dpy
= (Display
*) M_BITMAPHANDLERDATA
->m_display
;
677 int errorStatus
= XpmWriteFileFromPixmap(dpy
, (char*) (const char*) name
,
678 (Pixmap
) M_BITMAPHANDLERDATA
->m_pixmap
,
679 (M_BITMAPHANDLERDATA
->m_bitmapMask
? (Pixmap
) M_BITMAPHANDLERDATA
->m_bitmapMask
->GetPixmap() : (Pixmap
) 0),
680 (XpmAttributes
*) NULL
);
681 if (errorStatus
== XpmSuccess
)
690 class WXDLLEXPORT wxXPMDataHandler
: public wxBitmapHandler
692 DECLARE_DYNAMIC_CLASS(wxXPMDataHandler
)
694 inline wxXPMDataHandler()
698 m_type
= wxBITMAP_TYPE_XPM_DATA
;
701 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
703 IMPLEMENT_DYNAMIC_CLASS(wxXPMDataHandler
, wxBitmapHandler
)
705 bool wxXPMDataHandler::Create( wxBitmap
*bitmap
, void *data
, long WXUNUSED(flags
),
706 int width
, int height
, int WXUNUSED(depth
))
708 M_BITMAPHANDLERDATA
->m_width
= width
;
709 M_BITMAPHANDLERDATA
->m_height
= height
;
710 M_BITMAPHANDLERDATA
->m_depth
= 1;
711 M_BITMAPHANDLERDATA
->m_freePixmap
= TRUE
;
713 Display
*dpy
= (Display
*) wxGetDisplay();
714 M_BITMAPHANDLERDATA
->m_display
= (WXDisplay
*) dpy
;
716 XpmAttributes xpmAttr
;
718 xpmAttr
.valuemask
= XpmReturnInfos
; /* nothing yet, but get infos back */
720 XpmColorSymbol symbolicColors
[4];
721 if (sg_Control
&& sg_Control
->GetMainWidget())
723 symbolicColors
[0].name
= "foreground";
724 symbolicColors
[0].value
= NULL
;
725 symbolicColors
[1].name
= "background";
726 symbolicColors
[1].value
= NULL
;
727 XtVaGetValues((Widget
) sg_Control
->GetMainWidget(),
728 XmNforeground
, &symbolicColors
[0].pixel
,
729 XmNbackground
, &symbolicColors
[1].pixel
,NULL
);
730 xpmAttr
.numsymbols
= 2;
731 xpmAttr
.colorsymbols
= symbolicColors
;
732 xpmAttr
.valuemask
|= XpmColorSymbols
; // add flag
737 int ErrorStatus
= XpmCreatePixmapFromData(dpy
, RootWindow(dpy
, DefaultScreen(dpy
)),
738 (char**) data
, &pixmap
, &mask
, &xpmAttr
);
739 if (ErrorStatus
== XpmSuccess
)
742 M_BITMAPHANDLERDATA
->m_width
= xpmAttr
.width
;
743 M_BITMAPHANDLERDATA
->m_height
= xpmAttr
.height
;
745 unsigned int depthRet
;
747 unsigned int widthRet
, heightRet
, borderWidthRet
;
748 Window rootWindowRet
;
749 XGetGeometry(dpy
, pixmap
, &rootWindowRet
, &xRet
, &yRet
,
750 &widthRet
, &heightRet
, &borderWidthRet
, &depthRet
);
753 if ( xpmAttr.npixels > 2 )
755 M_BITMAPHANDLERDATA->m_depth = 8; // next time not just a guess :-) ...
758 M_BITMAPHANDLERDATA->m_depth = 1; // mono
762 M_BITMAPHANDLERDATA
->m_depth
= depthRet
;
764 M_BITMAPHANDLERDATA
->m_numColors
= xpmAttr
.npixels
;
765 XpmFreeAttributes(&xpmAttr
);
766 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
767 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) pixmap
;
770 M_BITMAPHANDLERDATA
->m_bitmapMask
= new wxMask
;
771 M_BITMAPHANDLERDATA
->m_bitmapMask
->SetPixmap((WXPixmap
) mask
);
776 // XpmDebugError(ErrorStatus, NULL);
777 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
779 return M_BITMAPHANDLERDATA
->m_ok
;
782 #endif // wxHAVE_LIB_XPM
784 void wxBitmap::CleanUpHandlers()
786 wxNode
*node
= sm_handlers
.First();
789 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
790 wxNode
*next
= node
->Next();
797 void wxBitmap::InitStandardHandlers()
799 // Initialize all standard bitmap or derived class handlers here.
800 AddHandler(new wxXBMFileHandler
);
801 AddHandler(new wxXBMDataHandler
);
803 // XPM is considered standard for Motif, although it can be omitted if
804 // libXpm is not installed
806 AddHandler(new wxXPMFileHandler
);
807 AddHandler(new wxXPMDataHandler
);
808 #endif // wxHAVE_LIB_XPM
811 WXPixmap
wxBitmap::GetLabelPixmap (WXWidget w
)
813 if (M_BITMAPDATA
->m_image
== (WXPixmap
) 0)
814 return M_BITMAPDATA
->m_pixmap
;
816 Display
*dpy
= (Display
*) M_BITMAPDATA
->m_display
;
821 if (labelPixmap) return labelPixmap;
822 things can be wrong, because colors can have been changed.
826 XmDestroyPixmap(DefaultScreenOfDisplay(dpy),labelPixmap) ;
827 we got BadDrawable if the pixmap is referenced by multiples widgets
831 So, before doing thing really clean, I just do nothing; if the pixmap is
832 referenced by many widgets, Motif performs caching functions.
833 And if pixmap is referenced with multiples colors, we just have some
834 memory leaks... I hope we can deal with them...
836 // Must be destroyed, because colours can have been changed!
837 if (M_BITMAPDATA
->m_labelPixmap
)
838 XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), M_BITMAPDATA
->m_labelPixmap
);
842 sprintf (tmp
, "Im%x", (unsigned int) M_BITMAPDATA
->m_image
);
845 Widget widget
= (Widget
) w
;
847 while (XmIsGadget ( widget
))
848 widget
= XtParent (widget
);
849 XtVaGetValues (widget
, XmNbackground
, &bg
, XmNforeground
, &fg
, NULL
);
851 M_BITMAPDATA
->m_labelPixmap
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
);
853 return M_BITMAPDATA
->m_labelPixmap
;
856 WXPixmap
wxBitmap::GetArmPixmap (WXWidget w
)
858 if (M_BITMAPDATA
->m_image
== (WXPixmap
) 0)
859 return M_BITMAPDATA
->m_pixmap
;
861 Display
*dpy
= (Display
*) M_BITMAPDATA
->m_display
;
863 See
GetLabelPixmap () comment
864 // Must be destroyed, because colours can have been changed!
865 if (M_BITMAPDATA
->m_armPixmap
)
866 XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), M_BITMAPDATA
->m_armPixmap
);
870 sprintf (tmp
, "Im%x", (unsigned int) M_BITMAPDATA
->m_image
);
873 Widget widget
= (Widget
) w
;
875 XtVaGetValues (widget
, XmNarmColor
, &bg
, NULL
);
876 while (XmIsGadget (widget
))
877 widget
= XtParent (widget
);
878 XtVaGetValues (widget
, XmNforeground
, &fg
, NULL
);
880 M_BITMAPDATA
->m_armPixmap
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
);
882 return M_BITMAPDATA
->m_armPixmap
;
885 WXPixmap
wxBitmap::GetInsensPixmap (WXWidget w
)
887 Display
*dpy
= (Display
*) M_BITMAPDATA
->m_display
;
889 if (M_BITMAPDATA
->m_insensPixmap
)
890 return M_BITMAPDATA
->m_insensPixmap
;
894 M_BITMAPDATA
->m_insensPixmap
= (WXPixmap
) XCreateInsensitivePixmap(dpy
, (Pixmap
) M_BITMAPDATA
->m_pixmap
);
895 if (M_BITMAPDATA
->m_insensPixmap
)
896 return M_BITMAPDATA
->m_insensPixmap
;
898 return M_BITMAPDATA
->m_pixmap
;
901 if (M_BITMAPDATA
->m_insensImage
== (WXPixmap
) 0)
902 return M_BITMAPDATA
->m_pixmap
;
905 See
GetLabelPixmap () comment
906 // Must be destroyed, because colours can have been changed!
907 if (M_BITMAPDATA
->m_insensPixmap
)
908 XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), (Pixmap
) M_BITMAPDATA
->m_insensPixmap
);
912 sprintf (tmp
, "Not%x", (unsigned int) M_BITMAPDATA
->m_insensImage
);
915 Widget widget
= (Widget
) w
;
917 while (XmIsGadget (widget
))
918 widget
= XtParent (widget
);
919 XtVaGetValues (widget
, XmNbackground
, &bg
, XmNforeground
, &fg
, NULL
);
921 M_BITMAPDATA
->m_insensPixmap
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
);
923 return M_BITMAPDATA
->m_insensPixmap
;
926 // We may need this sometime...
928 /****************************************************************************
931 XCreateInsensitivePixmap - create a grayed-out copy of a pixmap
934 Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap )
937 This function creates a grayed-out copy of the argument pixmap, suitable
938 for use as a XmLabel's XmNlabelInsensitivePixmap resource.
941 The return value is the new Pixmap id or zero on error. Errors include
942 a NULL display argument or an invalid Pixmap argument.
945 If one of the XLib functions fail, it will produce a X error. The
946 default X error handler prints a diagnostic and calls exit().
949 XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3),
950 XFillRectangle(3), exit(2)
953 John R Veregge - john@puente.jpl.nasa.gov
954 Advanced Engineering and Prototyping Group (AEG)
955 Information Systems Technology Section (395)
956 Jet Propulsion Lab - Calif Institute of Technology
958 *****************************************************************************/
961 XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
)
965 char stipple_data
[] =
967 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
968 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
969 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
970 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA
973 Pixmap ipixmap
, stipple
;
974 unsigned width
, height
, depth
;
976 Window window
; /* These return values */
977 unsigned border
; /* from XGetGeometry() */
978 int x
, y
; /* are not needed. */
982 if ( NULL
== display
|| 0 == pixmap
)
985 if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
,
986 &width
, &height
, &border
, &depth
)
988 return ipixmap
; /* BadDrawable: probably an invalid pixmap */
990 /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap.
992 stipple
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 );
995 gc
= XCreateGC( display
, pixmap
, (XtGCMask
)0, (XGCValues
*)NULL
);
998 /* Create an identical copy of the argument pixmap.
1000 ipixmap
= XCreatePixmap( display
, pixmap
, width
, height
, depth
);
1003 /* Copy the argument pixmap into the new pixmap.
1005 XCopyArea( display
, pixmap
, ipixmap
,
1006 gc
, 0, 0, width
, height
, 0, 0 );
1008 /* Refill the new pixmap using the stipple algorithm/pixmap.
1010 XSetStipple( display
, gc
, stipple
);
1011 XSetFillStyle( display
, gc
, FillStippled
);
1012 XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height
);
1014 XFreeGC( display
, gc
);
1016 XFreePixmap( display
, stipple
);
1021 // Creates a bitmap with transparent areas drawn in
1022 // the given colour.
1023 wxBitmap
wxCreateMaskedBitmap(const wxBitmap
& bitmap
, wxColour
& colour
)
1025 wxBitmap
newBitmap(bitmap
.GetWidth(),
1030 srcDC
.SelectObject(bitmap
);
1031 destDC
.SelectObject(newBitmap
);
1033 wxBrush
brush(colour
, wxSOLID
);
1034 destDC
.SetOptimization(FALSE
);
1035 destDC
.SetBackground(brush
);
1037 destDC
.Blit(0, 0, bitmap
.GetWidth(), bitmap
.GetHeight(), & srcDC
, 0, 0, wxCOPY
, TRUE
);