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 M_BITMAPHANDLERDATA
->m_width
= xpmAttr
.width
;
623 M_BITMAPHANDLERDATA
->m_height
= xpmAttr
.height
;
624 if ( xpmAttr
.npixels
> 2 )
626 M_BITMAPHANDLERDATA
->m_depth
= 8; // TODO: next time not just a guess :-) ...
629 M_BITMAPHANDLERDATA
->m_depth
= 1; // mono
632 M_BITMAPHANDLERDATA
->m_numColors
= xpmAttr
.npixels
;
634 XpmFreeAttributes(&xpmAttr
);
636 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
640 // XpmDebugError(errorStatus, name);
641 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
646 bool wxXPMFileHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
)
648 if (M_BITMAPHANDLERDATA
->m_ok
&& M_BITMAPHANDLERDATA
->m_pixmap
)
650 Display
*dpy
= (Display
*) M_BITMAPHANDLERDATA
->m_display
;
651 int errorStatus
= XpmWriteFileFromPixmap(dpy
, (char*) (const char*) name
,
652 (Pixmap
) M_BITMAPHANDLERDATA
->m_pixmap
,
653 (M_BITMAPHANDLERDATA
->m_bitmapMask
? (Pixmap
) M_BITMAPHANDLERDATA
->m_bitmapMask
->GetPixmap() : (Pixmap
) 0),
654 (XpmAttributes
*) NULL
);
655 if (errorStatus
== XpmSuccess
)
664 class WXDLLEXPORT wxXPMDataHandler
: public wxBitmapHandler
666 DECLARE_DYNAMIC_CLASS(wxXPMDataHandler
)
668 inline wxXPMDataHandler()
672 m_type
= wxBITMAP_TYPE_XPM_DATA
;
675 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
677 IMPLEMENT_DYNAMIC_CLASS(wxXPMDataHandler
, wxBitmapHandler
)
679 bool wxXPMDataHandler::Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
)
681 M_BITMAPHANDLERDATA
->m_width
= width
;
682 M_BITMAPHANDLERDATA
->m_height
= height
;
683 M_BITMAPHANDLERDATA
->m_depth
= 1;
684 M_BITMAPHANDLERDATA
->m_freePixmap
= TRUE
;
686 Display
*dpy
= (Display
*) wxGetDisplay();
687 M_BITMAPHANDLERDATA
->m_display
= (WXDisplay
*) dpy
;
689 XpmAttributes xpmAttr
;
691 xpmAttr
.valuemask
= XpmReturnInfos
; /* nothing yet, but get infos back */
693 XpmColorSymbol symbolicColors
[4];
694 if (sg_Control
&& sg_Control
->GetMainWidget())
696 symbolicColors
[0].name
= "foreground";
697 symbolicColors
[0].value
= NULL
;
698 symbolicColors
[1].name
= "background";
699 symbolicColors
[1].value
= NULL
;
700 XtVaGetValues((Widget
) sg_Control
->GetMainWidget(),
701 XmNforeground
, &symbolicColors
[0].pixel
,
702 XmNbackground
, &symbolicColors
[1].pixel
,NULL
);
703 xpmAttr
.numsymbols
= 2;
704 xpmAttr
.colorsymbols
= symbolicColors
;
705 xpmAttr
.valuemask
|= XpmColorSymbols
; // add flag
710 int ErrorStatus
= XpmCreatePixmapFromData(dpy
, RootWindow(dpy
, DefaultScreen(dpy
)),
711 (char**) data
, &pixmap
, &mask
, &xpmAttr
);
712 if (ErrorStatus
== XpmSuccess
)
715 M_BITMAPHANDLERDATA
->m_width
= xpmAttr
.width
;
716 M_BITMAPHANDLERDATA
->m_height
= xpmAttr
.height
;
717 if ( xpmAttr
.npixels
> 2 )
719 M_BITMAPHANDLERDATA
->m_depth
= 8; // next time not just a guess :-) ...
722 M_BITMAPHANDLERDATA
->m_depth
= 1; // mono
724 M_BITMAPHANDLERDATA
->m_numColors
= xpmAttr
.npixels
;
725 XpmFreeAttributes(&xpmAttr
);
726 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
727 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) pixmap
;
730 M_BITMAPHANDLERDATA
->m_bitmapMask
= new wxMask
;
731 M_BITMAPHANDLERDATA
->m_bitmapMask
->SetPixmap((WXPixmap
) mask
);
736 // XpmDebugError(ErrorStatus, NULL);
737 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
739 return M_BITMAPHANDLERDATA
->m_ok
;
744 void wxBitmap::CleanUpHandlers()
746 wxNode
*node
= sm_handlers
.First();
749 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
750 wxNode
*next
= node
->Next();
757 void wxBitmap::InitStandardHandlers()
759 // Initialize all standard bitmap or derived class handlers here.
760 AddHandler(new wxXBMFileHandler
);
761 AddHandler(new wxXBMDataHandler
);
763 // XPM is considered standard for Moif, although it can be omitted if absolutely
766 AddHandler(new wxXPMFileHandler
);
767 AddHandler(new wxXPMDataHandler
);
771 WXPixmap
wxBitmap::GetLabelPixmap (WXWidget w
)
773 if (M_BITMAPDATA
->m_image
== (WXPixmap
) 0)
774 return M_BITMAPDATA
->m_pixmap
;
776 Display
*dpy
= (Display
*) M_BITMAPDATA
->m_display
;
781 if (labelPixmap) return labelPixmap;
782 things can be wrong, because colors can have been changed.
786 XmDestroyPixmap(DefaultScreenOfDisplay(dpy),labelPixmap) ;
787 we got BadDrawable if the pixmap is referenced by multiples widgets
791 So, before doing thing really clean, I just do nothing; if the pixmap is
792 referenced by many widgets, Motif performs caching functions.
793 And if pixmap is referenced with multiples colors, we just have some
794 memory leaks... I hope we can deal with them...
796 // Must be destroyed, because colours can have been changed!
797 if (M_BITMAPDATA
->m_labelPixmap
)
798 XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), M_BITMAPDATA
->m_labelPixmap
);
802 sprintf (tmp
, "Im%x", (unsigned int) M_BITMAPDATA
->m_image
);
805 Widget widget
= (Widget
) w
;
807 while (XmIsGadget ( widget
))
808 widget
= XtParent (widget
);
809 XtVaGetValues (widget
, XmNbackground
, &bg
, XmNforeground
, &fg
, NULL
);
811 M_BITMAPDATA
->m_labelPixmap
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
);
813 return M_BITMAPDATA
->m_labelPixmap
;
816 WXPixmap
wxBitmap::GetArmPixmap (WXWidget w
)
818 if (M_BITMAPDATA
->m_image
== (WXPixmap
) 0)
819 return M_BITMAPDATA
->m_pixmap
;
821 Display
*dpy
= (Display
*) M_BITMAPDATA
->m_display
;
823 See
GetLabelPixmap () comment
824 // Must be destroyed, because colours can have been changed!
825 if (M_BITMAPDATA
->m_armPixmap
)
826 XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), M_BITMAPDATA
->m_armPixmap
);
830 sprintf (tmp
, "Im%x", (unsigned int) M_BITMAPDATA
->m_image
);
833 Widget widget
= (Widget
) w
;
835 XtVaGetValues (widget
, XmNarmColor
, &bg
, NULL
);
836 while (XmIsGadget (widget
))
837 widget
= XtParent (widget
);
838 XtVaGetValues (widget
, XmNforeground
, &fg
, NULL
);
840 M_BITMAPDATA
->m_armPixmap
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
);
842 return M_BITMAPDATA
->m_armPixmap
;
845 WXPixmap
wxBitmap::GetInsensPixmap (WXWidget w
)
847 Display
*dpy
= (Display
*) M_BITMAPDATA
->m_display
;
849 if (M_BITMAPDATA
->m_insensImage
== (WXPixmap
) 0)
850 return M_BITMAPDATA
->m_pixmap
;
853 See
GetLabelPixmap () comment
854 // Must be destroyed, because colours can have been changed!
855 if (M_BITMAPDATA
->m_insensPixmap
)
856 XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), (Pixmap
) M_BITMAPDATA
->m_insensPixmap
);
860 sprintf (tmp
, "Not%x", (unsigned int) M_BITMAPDATA
->m_insensImage
);
863 Widget widget
= (Widget
) w
;
865 while (XmIsGadget (widget
))
866 widget
= XtParent (widget
);
867 XtVaGetValues (widget
, XmNbackground
, &bg
, XmNforeground
, &fg
, NULL
);
869 M_BITMAPDATA
->m_insensPixmap
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
);
871 return M_BITMAPDATA
->m_insensPixmap
;
874 // We may need this sometime...
876 /****************************************************************************
879 XCreateInsensitivePixmap - create a grayed-out copy of a pixmap
882 Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap )
885 This function creates a grayed-out copy of the argument pixmap, suitable
886 for use as a XmLabel's XmNlabelInsensitivePixmap resource.
889 The return value is the new Pixmap id or zero on error. Errors include
890 a NULL display argument or an invalid Pixmap argument.
893 If one of the XLib functions fail, it will produce a X error. The
894 default X error handler prints a diagnostic and calls exit().
897 XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3),
898 XFillRectangle(3), exit(2)
901 John R Veregge - john@puente.jpl.nasa.gov
902 Advanced Engineering and Prototyping Group (AEG)
903 Information Systems Technology Section (395)
904 Jet Propulsion Lab - Calif Institute of Technology
906 *****************************************************************************/
909 XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
)
913 char stipple_data
[] =
915 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
916 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
917 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
918 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA
921 Pixmap ipixmap
, stipple
;
922 unsigned width
, height
, depth
;
924 Window window
; /* These return values */
925 unsigned border
; /* from XGetGeometry() */
926 int x
, y
; /* are not needed. */
930 if ( NULL
== display
|| 0 == pixmap
)
933 if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
,
934 &width
, &height
, &border
, &depth
)
936 return ipixmap
; /* BadDrawable: probably an invalid pixmap */
938 /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap.
940 stipple
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 );
943 gc
= XCreateGC( display
, pixmap
, (XtGCMask
)0, (XGCValues
*)NULL
);
946 /* Create an identical copy of the argument pixmap.
948 ipixmap
= XCreatePixmap( display
, pixmap
, width
, height
, depth
);
951 /* Copy the argument pixmap into the new pixmap.
953 XCopyArea( display
, pixmap
, ipixmap
,
954 gc
, 0, 0, width
, height
, 0, 0 );
956 /* Refill the new pixmap using the stipple algorithm/pixmap.
958 XSetStipple( display
, gc
, stipple
);
959 XSetFillStyle( display
, gc
, FillStippled
);
960 XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height
);
962 XFreeGC( display
, gc
);
964 XFreePixmap( display
, stipple
);