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"
25 #include "wx/motif/private.h"
27 // TODO: correct symbol, path?
32 #if !USE_SHARED_LIBRARIES
33 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
, wxGDIObject
)
34 IMPLEMENT_DYNAMIC_CLASS(wxMask
, wxObject
)
37 wxBitmapRefData::wxBitmapRefData()
47 m_pixmap
= (WXPixmap
) 0;
48 m_display
= (WXDisplay
*) 0;
50 m_freePixmap
= TRUE
; //TODO: necessary?
51 m_freeColors
= (unsigned long*) 0;
52 m_freeColorsCount
= 0;
54 // These 5 variables are for wxControl
55 m_insensPixmap
= (WXPixmap
) 0;
56 m_labelPixmap
= (WXPixmap
) 0;
57 m_armPixmap
= (WXPixmap
) 0;
58 m_image
= (WXImage
*) 0;
59 m_insensImage
= (WXImage
*) 0;
62 wxBitmapRefData::~wxBitmapRefData()
65 XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) m_display
), (Pixmap
) m_labelPixmap
);
68 XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) m_display
), (Pixmap
) m_armPixmap
);
71 XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) m_display
), (Pixmap
) m_insensPixmap
);
75 XmUninstallImage ((XImage
*) m_image
);
76 XtFree ((char *) (XImage
*) m_image
);
81 XmUninstallImage ((XImage
*) m_insensImage
);
82 delete[] ((XImage
*) m_insensImage
)->data
;
83 XtFree ((char *) (XImage
*) m_insensImage
);
85 if (m_pixmap
&& m_freePixmap
)
86 XFreePixmap ((Display
*) m_display
, (Pixmap
) m_pixmap
);
90 int screen
= DefaultScreen((Display
*) m_display
);
91 Colormap cmp
= DefaultColormap((Display
*) m_display
,screen
);
93 for(llp
= 0;llp
< m_freeColorsCount
;llp
++)
94 XFreeColors((Display
*) m_display
, cmp
, &m_freeColors
[llp
], 1, 0L);
103 wxList
wxBitmap::sm_handlers
;
109 if ( wxTheBitmapList
)
110 wxTheBitmapList
->AddBitmap(this);
113 wxBitmap::~wxBitmap()
116 wxTheBitmapList
->DeleteObject(this);
119 wxBitmap::wxBitmap(const char bits
[], int width
, int height
, int depth
)
121 m_refData
= new wxBitmapRefData
;
123 (void) Create((void*) bits
, wxBITMAP_TYPE_XBM_DATA
, width
, height
, depth
);
125 if ( wxTheBitmapList
)
126 wxTheBitmapList
->AddBitmap(this);
129 wxBitmap::wxBitmap(int w
, int h
, int d
)
131 (void)Create(w
, h
, d
);
133 if ( wxTheBitmapList
)
134 wxTheBitmapList
->AddBitmap(this);
137 wxBitmap::wxBitmap(void *data
, long type
, int width
, int height
, int depth
)
139 (void) Create(data
, type
, width
, height
, depth
);
141 if ( wxTheBitmapList
)
142 wxTheBitmapList
->AddBitmap(this);
145 wxBitmap::wxBitmap(const wxString
& filename
, long type
)
147 LoadFile(filename
, (int)type
);
149 if ( wxTheBitmapList
)
150 wxTheBitmapList
->AddBitmap(this);
153 // Create from XPM data
154 static wxControl
* sg_Control
= NULL
;
155 wxBitmap::wxBitmap(const char **data
, wxControl
* control
)
157 // Pass the control to the Create function using a global
158 sg_Control
= control
;
160 (void) Create((void *)data
, wxBITMAP_TYPE_XPM_DATA
, 0, 0, 0);
162 sg_Control
= (wxControl
*) NULL
;
165 bool wxBitmap::Create(int w
, int h
, int d
)
169 m_refData
= new wxBitmapRefData
;
172 d
= wxDisplayDepth();
174 M_BITMAPDATA
->m_width
= w
;
175 M_BITMAPDATA
->m_height
= h
;
176 M_BITMAPDATA
->m_depth
= d
;
177 M_BITMAPDATA
->m_freePixmap
= TRUE
;
179 Display
*dpy
= (Display
*) wxGetDisplay();
181 M_BITMAPDATA
->m_display
= dpy
; /* MATTHEW: [4] Remember the display */
183 M_BITMAPDATA
->m_pixmap
= (WXPixmap
) XCreatePixmap (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)),
186 M_BITMAPDATA
->m_ok
= (M_BITMAPDATA
->m_pixmap
!= (WXPixmap
) 0) ;
187 return M_BITMAPDATA
->m_ok
;
190 bool wxBitmap::LoadFile(const wxString
& filename
, long type
)
194 m_refData
= new wxBitmapRefData
;
196 wxBitmapHandler
*handler
= FindHandler(type
);
198 if ( handler
== NULL
) {
199 wxLogWarning("no bitmap handler for type %d defined.", type
);
204 return handler
->LoadFile(this, filename
, type
, -1, -1);
207 bool wxBitmap::Create(void *data
, long type
, int width
, int height
, int depth
)
211 m_refData
= new wxBitmapRefData
;
213 wxBitmapHandler
*handler
= FindHandler(type
);
215 if ( handler
== NULL
) {
216 wxLogWarning("no bitmap handler for type %d defined.", type
);
221 return handler
->Create(this, data
, type
, width
, height
, depth
);
224 bool wxBitmap::SaveFile(const wxString
& filename
, int type
, const wxPalette
*palette
)
226 wxBitmapHandler
*handler
= FindHandler(type
);
228 if ( handler
== NULL
) {
229 wxLogWarning("no bitmap handler for type %d defined.", type
);
234 return handler
->SaveFile(this, filename
, type
, palette
);
237 void wxBitmap::SetWidth(int w
)
240 m_refData
= new wxBitmapRefData
;
242 M_BITMAPDATA
->m_width
= w
;
245 void wxBitmap::SetHeight(int h
)
248 m_refData
= new wxBitmapRefData
;
250 M_BITMAPDATA
->m_height
= h
;
253 void wxBitmap::SetDepth(int d
)
256 m_refData
= new wxBitmapRefData
;
258 M_BITMAPDATA
->m_depth
= d
;
261 void wxBitmap::SetQuality(int q
)
264 m_refData
= new wxBitmapRefData
;
266 M_BITMAPDATA
->m_quality
= q
;
269 void wxBitmap::SetOk(bool isOk
)
272 m_refData
= new wxBitmapRefData
;
274 M_BITMAPDATA
->m_ok
= isOk
;
277 void wxBitmap::SetPalette(const wxPalette
& palette
)
280 m_refData
= new wxBitmapRefData
;
282 M_BITMAPDATA
->m_bitmapPalette
= palette
;
285 void wxBitmap::SetMask(wxMask
*mask
)
288 m_refData
= new wxBitmapRefData
;
290 M_BITMAPDATA
->m_bitmapMask
= mask
;
293 void wxBitmap::AddHandler(wxBitmapHandler
*handler
)
295 sm_handlers
.Append(handler
);
298 void wxBitmap::InsertHandler(wxBitmapHandler
*handler
)
300 sm_handlers
.Insert(handler
);
303 bool wxBitmap::RemoveHandler(const wxString
& name
)
305 wxBitmapHandler
*handler
= FindHandler(name
);
308 sm_handlers
.DeleteObject(handler
);
315 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& name
)
317 wxNode
*node
= sm_handlers
.First();
320 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
321 if ( handler
->GetName() == name
)
328 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& extension
, long bitmapType
)
330 wxNode
*node
= sm_handlers
.First();
333 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
334 if ( handler
->GetExtension() == extension
&&
335 (bitmapType
== -1 || handler
->GetType() == bitmapType
) )
342 wxBitmapHandler
*wxBitmap::FindHandler(long bitmapType
)
344 wxNode
*node
= sm_handlers
.First();
347 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
348 if (handler
->GetType() == bitmapType
)
361 m_pixmap
= (WXPixmap
) 0;
364 // Construct a mask from a bitmap and a colour indicating
365 // the transparent area
366 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
368 m_pixmap
= (WXPixmap
) 0;
370 Create(bitmap
, colour
);
373 // Construct a mask from a bitmap and a palette index indicating
374 // the transparent area
375 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
377 m_pixmap
= (WXPixmap
) 0;
379 Create(bitmap
, paletteIndex
);
382 // Construct a mask from a mono bitmap (copies the bitmap).
383 wxMask::wxMask(const wxBitmap
& bitmap
)
385 m_pixmap
= (WXPixmap
) 0;
392 // TODO: this may be the wrong display
394 XFreePixmap ((Display
*) wxGetDisplay(), (Pixmap
) m_pixmap
);
397 // Create a mask from a mono bitmap (copies the bitmap).
398 bool wxMask::Create(const wxBitmap
& bitmap
)
404 // Create a mask from a bitmap and a palette index indicating
405 // the transparent area
406 bool wxMask::Create(const wxBitmap
& bitmap
, int paletteIndex
)
412 // Create a mask from a bitmap and a colour indicating
413 // the transparent area
414 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
424 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler
, wxObject
)
426 bool wxBitmapHandler::Create(wxBitmap
*bitmap
, void *data
, long type
, int width
, int height
, int depth
)
431 bool wxBitmapHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long type
,
432 int desiredWidth
, int desiredHeight
)
437 bool wxBitmapHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
)
446 class WXDLLEXPORT wxXBMFileHandler
: public wxBitmapHandler
448 DECLARE_DYNAMIC_CLASS(wxXBMFileHandler
)
450 inline wxXBMFileHandler()
454 m_type
= wxBITMAP_TYPE_XBM
;
457 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
458 int desiredWidth
, int desiredHeight
);
460 IMPLEMENT_DYNAMIC_CLASS(wxXBMFileHandler
, wxBitmapHandler
)
462 bool wxXBMFileHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
463 int desiredWidth
, int desiredHeight
)
465 M_BITMAPHANDLERDATA
->m_freePixmap
= TRUE
;
471 Display
*dpy
= (Display
*) wxGetDisplay();
472 M_BITMAPDATA
->m_display
= (WXDisplay
*) dpy
;
474 int value
= XReadBitmapFile (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)),
475 (char*) (const char*) name
, &w
, &h
, &pixmap
, &hotX
, &hotY
);
476 M_BITMAPHANDLERDATA
->m_width
= w
;
477 M_BITMAPHANDLERDATA
->m_height
= h
;
478 M_BITMAPHANDLERDATA
->m_depth
= 1;
479 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) pixmap
;
481 if ((value
== BitmapFileInvalid
) ||
482 (value
== BitmapOpenFailed
) ||
483 (value
== BitmapNoMemory
))
485 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
486 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) 0;
489 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
491 return M_BITMAPHANDLERDATA
->m_ok
;
494 class WXDLLEXPORT wxXBMDataHandler
: public wxBitmapHandler
496 DECLARE_DYNAMIC_CLASS(wxXBMDataHandler
)
498 inline wxXBMDataHandler()
502 m_type
= wxBITMAP_TYPE_XBM_DATA
;
505 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
507 IMPLEMENT_DYNAMIC_CLASS(wxXBMDataHandler
, wxBitmapHandler
)
509 bool wxXBMDataHandler::Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
)
511 M_BITMAPHANDLERDATA
->m_width
= width
;
512 M_BITMAPHANDLERDATA
->m_height
= height
;
513 M_BITMAPHANDLERDATA
->m_depth
= 1;
514 M_BITMAPHANDLERDATA
->m_freePixmap
= TRUE
;
516 Display
*dpy
= (Display
*) wxGetDisplay();
517 M_BITMAPHANDLERDATA
->m_display
= (WXDisplay
*) dpy
;
519 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) XCreateBitmapFromData (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)), (char*) data
, width
, height
);
520 M_BITMAPHANDLERDATA
->m_ok
= (M_BITMAPHANDLERDATA
->m_pixmap
!= (WXPixmap
) 0) ;
522 // code for wxControl. TODO: can we avoid doing this until we need it?
523 // E.g. have CreateButtonPixmaps which is called on demand.
524 XImage
* image
= (XImage
*) XtMalloc (sizeof (XImage
));
525 image
->width
= width
;
526 image
->height
= height
;
527 image
->data
= (char*) data
;
530 image
->format
= XYBitmap
;
531 image
->byte_order
= LSBFirst
;
532 image
->bitmap_unit
= 8;
533 image
->bitmap_bit_order
= LSBFirst
;
534 image
->bitmap_pad
= 8;
535 image
->bytes_per_line
= (width
+ 7) >> 3;
538 sprintf (tmp
, "Im%x", (unsigned int) image
);
539 XmInstallImage (image
, tmp
);
541 // Build our manually stipped pixmap.
543 int bpl
= (width
+ 7) / 8;
544 char *data1
= new char[height
* bpl
];
545 char* bits
= (char*) data
;
547 for (i
= 0; i
< height
; i
++)
549 int mask
= i
% 2 ? 0x55 : 0xaa;
551 for (j
= 0; j
< bpl
; j
++)
552 data1
[i
* bpl
+ j
] = bits
[i
* bpl
+ j
] & mask
;
554 XImage
* insensImage
= (XImage
*) XtMalloc (sizeof (XImage
));
555 insensImage
->width
= width
;
556 insensImage
->height
= height
;
557 insensImage
->data
= data1
;
558 insensImage
->depth
= 1;
559 insensImage
->xoffset
= 0;
560 insensImage
->format
= XYBitmap
;
561 insensImage
->byte_order
= LSBFirst
;
562 insensImage
->bitmap_unit
= 8;
563 insensImage
->bitmap_bit_order
= LSBFirst
;
564 insensImage
->bitmap_pad
= 8;
565 insensImage
->bytes_per_line
= bpl
;
567 sprintf (tmp
, "Not%x", (unsigned int)insensImage
);
568 XmInstallImage (insensImage
, tmp
);
570 M_BITMAPHANDLERDATA
->m_image
= (WXImage
*) image
;
571 M_BITMAPHANDLERDATA
->m_insensImage
= (WXImage
*) insensImage
;
577 class WXDLLEXPORT wxXPMFileHandler
: public wxBitmapHandler
579 DECLARE_DYNAMIC_CLASS(wxXPMFileHandler
)
581 inline wxXPMFileHandler()
585 m_type
= wxBITMAP_TYPE_XPM
;
588 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
589 int desiredWidth
, int desiredHeight
);
590 virtual bool SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
593 IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler
, wxBitmapHandler
)
595 bool wxXPMFileHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
596 int desiredWidth
, int desiredHeight
)
598 Display
*dpy
= wxGetDisplay();
599 M_BITMAPHANDLERDATA
->m_display
= (WXDisplay
*) dpy
;
601 XpmAttributes xpmAttr
;
605 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
606 xpmAttr
.valuemask
= XpmReturnInfos
| XpmCloseness
;
607 xpmAttr
.closeness
= 40000;
608 int errorStatus
= XpmReadFileToPixmap(dpy
,
609 RootWindow(dpy
, DefaultScreen(dpy
)), (char*) (const char*) name
,
610 &pixmap
, &mask
, &xpmAttr
);
612 if (errorStatus
== XpmSuccess
)
614 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) pixmap
;
617 M_BITMAPHANDLERDATA
->m_bitmapMask
= new wxMask
;
618 M_BITMAPHANDLERDATA
->m_bitmapMask
->SetPixmap((WXPixmap
) mask
);
621 M_BITMAPHANDLERDATA
->m_width
= xpmAttr
.width
;
622 M_BITMAPHANDLERDATA
->m_height
= xpmAttr
.height
;
623 if ( xpmAttr
.npixels
> 2 )
625 M_BITMAPHANDLERDATA
->m_depth
= 8; // TODO: next time not just a guess :-) ...
628 M_BITMAPHANDLERDATA
->m_depth
= 1; // mono
631 M_BITMAPHANDLERDATA
->m_numColors
= xpmAttr
.npixels
;
633 XpmFreeAttributes(&xpmAttr
);
635 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
638 // XpmDebugError(errorStatus, name);
639 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
644 bool wxXPMFileHandler::SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
)
646 if (M_BITMAPHANDLERDATA
->m_ok
&& M_BITMAPHANDLERDATA
->m_pixmap
)
648 Display
*dpy
= (Display
*) M_BITMAPHANDLERDATA
->m_display
;
649 int errorStatus
= XpmWriteFileFromPixmap(dpy
, (char*) (const char*) name
,
650 (Pixmap
) M_BITMAPHANDLERDATA
->m_pixmap
,
651 (M_BITMAPHANDLERDATA
->m_bitmapMask
? (Pixmap
) M_BITMAPHANDLERDATA
->m_bitmapMask
->GetPixmap() : (Pixmap
) 0),
652 (XpmAttributes
*) NULL
);
653 if (errorStatus
== XpmSuccess
)
662 class WXDLLEXPORT wxXPMDataHandler
: public wxBitmapHandler
664 DECLARE_DYNAMIC_CLASS(wxXPMDataHandler
)
666 inline wxXBMDataHandler()
670 m_type
= wxBITMAP_TYPE_XPM_DATA
;
673 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
675 IMPLEMENT_DYNAMIC_CLASS(wxXPMDataHandler
, wxBitmapHandler
)
677 bool wxXPMDataHandler::Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
)
679 M_BITMAPHANDLERDATA
->m_width
= width
;
680 M_BITMAPHANDLERDATA
->m_height
= height
;
681 M_BITMAPHANDLERDATA
->m_depth
= 1;
682 M_BITMAPHANDLERDATA
->m_freePixmap
= TRUE
;
684 Display
*dpy
= wxGetDisplay();
685 M_BITMAPHANDLERDATA
->m_display
= (WXDisplay
*) dpy
;
687 XpmAttributes xpmAttr
;
689 xpmAttr
.valuemask
= XpmReturnInfos
; /* nothing yet, but get infos back */
691 XpmColorSymbol symbolicColors
[4];
692 if (sg_Control
&& sg_Control
->GetMainWidget())
694 symbolicColors
[0].name
= "foreground";
695 symbolicColors
[0].value
= NULL
;
696 symbolicColors
[1].name
= "background";
697 symbolicColors
[1].value
= NULL
;
698 XtVaGetValues((Widget
) sg_Control
->GetMainWidget(),
699 XmNforeground
, &symbolicColors
[0].pixel
,
700 XmNbackground
, &symbolicColors
[1].pixel
,NULL
);
701 xpmAttr
.numsymbols
= 2;
702 xpmAttr
.colorsymbols
= symbolicColors
;
703 xpmAttr
.valuemask
|= XpmColorSymbols
; // add flag
708 int ErrorStatus
= XpmCreatePixmapFromData(dpy
, RootWindow(dpy
, DefaultScreen(dpy
)),
709 (char**) data
, &pixmap
, &mask
, &xpmAttr
);
710 if (ErrorStatus
== XpmSuccess
)
713 M_BITMAPHANDLERDATA
->m_width
= xpmAttr
.width
;
714 M_BITMAPHANDLERDATA
->m_height
= xpmAttr
.height
;
715 if ( xpmAttr
.npixels
> 2 )
717 M_BITMAPHANDLERDATA
->m_depth
= 8; // next time not just a guess :-) ...
720 M_BITMAPHANDLERDATA
->m_depth
= 1; // mono
722 M_BITMAPHANDLERDATA
->m_numColors
= xpmAttr
.npixels
;
723 XpmFreeAttributes(&xpmAttr
);
724 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
725 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) pixmap
;
728 M_BITMAPHANDLERDATA
->m_bitmapMask
= new wxMask
;
729 M_BITMAPHANDLERDATA
->m_bitmapMask
->SetPixmap((WXPixmap
) mask
);
734 // XpmDebugError(ErrorStatus, NULL);
735 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
737 return M_BITMAPHANDLERDATA
->m_ok
;
742 void wxBitmap::CleanUpHandlers()
744 wxNode
*node
= sm_handlers
.First();
747 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
748 wxNode
*next
= node
->Next();
755 void wxBitmap::InitStandardHandlers()
757 // Initialize all standard bitmap or derived class handlers here.
758 AddHandler(new wxXBMFileHandler
);
759 AddHandler(new wxXBMDataHandler
);
761 // XPM is considered standard for Moif, although it can be omitted if absolutely
764 AddHandler(new wxXPMFileHandler
);
765 AddHandler(new wxXPMDataHandler
);
769 WXPixmap
wxBitmap::GetLabelPixmap (WXWidget w
)
771 if (M_BITMAPDATA
->m_image
== (WXPixmap
) 0)
772 return M_BITMAPDATA
->m_pixmap
;
774 Display
*dpy
= (Display
*) M_BITMAPDATA
->m_display
;
779 if (labelPixmap) return labelPixmap;
780 things can be wrong, because colors can have been changed.
784 XmDestroyPixmap(DefaultScreenOfDisplay(dpy),labelPixmap) ;
785 we got BadDrawable if the pixmap is referenced by multiples widgets
789 So, before doing thing really clean, I just do nothing; if the pixmap is
790 referenced by many widgets, Motif performs caching functions.
791 And if pixmap is referenced with multiples colors, we just have some
792 memory leaks... I hope we can deal with them...
794 // Must be destroyed, because colours can have been changed!
795 if (M_BITMAPDATA
->m_labelPixmap
)
796 XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), M_BITMAPDATA
->m_labelPixmap
);
800 sprintf (tmp
, "Im%x", (unsigned int) M_BITMAPDATA
->m_image
);
803 Widget widget
= (Widget
) w
;
805 while (XmIsGadget ( widget
))
806 widget
= XtParent (widget
);
807 XtVaGetValues (widget
, XmNbackground
, &bg
, XmNforeground
, &fg
, NULL
);
809 M_BITMAPDATA
->m_labelPixmap
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
);
811 return M_BITMAPDATA
->m_labelPixmap
;
814 WXPixmap
wxBitmap::GetArmPixmap (WXWidget w
)
816 if (M_BITMAPDATA
->m_image
== (WXPixmap
) 0)
817 return M_BITMAPDATA
->m_pixmap
;
819 Display
*dpy
= (Display
*) M_BITMAPDATA
->m_display
;
821 See
GetLabelPixmap () comment
822 // Must be destroyed, because colours can have been changed!
823 if (M_BITMAPDATA
->m_armPixmap
)
824 XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), M_BITMAPDATA
->m_armPixmap
);
828 sprintf (tmp
, "Im%x", (unsigned int) M_BITMAPDATA
->m_image
);
831 Widget widget
= (Widget
) w
;
833 XtVaGetValues (widget
, XmNarmColor
, &bg
, NULL
);
834 while (XmIsGadget (widget
))
835 widget
= XtParent (widget
);
836 XtVaGetValues (widget
, XmNforeground
, &fg
, NULL
);
838 M_BITMAPDATA
->m_armPixmap
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
);
840 return M_BITMAPDATA
->m_armPixmap
;
843 WXPixmap
wxBitmap::GetInsensPixmap (WXWidget w
)
845 Display
*dpy
= (Display
*) M_BITMAPDATA
->m_display
;
847 if (M_BITMAPDATA
->m_insensImage
== (WXPixmap
) 0)
848 return M_BITMAPDATA
->m_pixmap
;
851 See
GetLabelPixmap () comment
852 // Must be destroyed, because colours can have been changed!
853 if (M_BITMAPDATA
->m_insensPixmap
)
854 XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), (Pixmap
) M_BITMAPDATA
->m_insensPixmap
);
858 sprintf (tmp
, "Not%x", (unsigned int) M_BITMAPDATA
->m_insensImage
);
861 Widget widget
= (Widget
) w
;
863 while (XmIsGadget (widget
))
864 widget
= XtParent (widget
);
865 XtVaGetValues (widget
, XmNbackground
, &bg
, XmNforeground
, &fg
, NULL
);
867 M_BITMAPDATA
->m_insensPixmap
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
);
869 return M_BITMAPDATA
->m_insensPixmap
;
872 // We may need this sometime...
874 /****************************************************************************
877 XCreateInsensitivePixmap - create a grayed-out copy of a pixmap
880 Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap )
883 This function creates a grayed-out copy of the argument pixmap, suitable
884 for use as a XmLabel's XmNlabelInsensitivePixmap resource.
887 The return value is the new Pixmap id or zero on error. Errors include
888 a NULL display argument or an invalid Pixmap argument.
891 If one of the XLib functions fail, it will produce a X error. The
892 default X error handler prints a diagnostic and calls exit().
895 XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3),
896 XFillRectangle(3), exit(2)
899 John R Veregge - john@puente.jpl.nasa.gov
900 Advanced Engineering and Prototyping Group (AEG)
901 Information Systems Technology Section (395)
902 Jet Propulsion Lab - Calif Institute of Technology
904 *****************************************************************************/
907 XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
)
911 char stipple_data
[] =
913 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
914 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
915 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
916 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA
919 Pixmap ipixmap
, stipple
;
920 unsigned width
, height
, depth
;
922 Window window
; /* These return values */
923 unsigned border
; /* from XGetGeometry() */
924 int x
, y
; /* are not needed. */
928 if ( NULL
== display
|| 0 == pixmap
)
931 if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
,
932 &width
, &height
, &border
, &depth
)
934 return ipixmap
; /* BadDrawable: probably an invalid pixmap */
936 /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap.
938 stipple
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 );
941 gc
= XCreateGC( display
, pixmap
, (XtGCMask
)0, (XGCValues
*)NULL
);
944 /* Create an identical copy of the argument pixmap.
946 ipixmap
= XCreatePixmap( display
, pixmap
, width
, height
, depth
);
949 /* Copy the argument pixmap into the new pixmap.
951 XCopyArea( display
, pixmap
, ipixmap
,
952 gc
, 0, 0, width
, height
, 0, 0 );
954 /* Refill the new pixmap using the stipple algorithm/pixmap.
956 XSetStipple( display
, gc
, stipple
);
957 XSetFillStyle( display
, gc
, FillStippled
);
958 XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height
);
960 XFreeGC( display
, gc
);
962 XFreePixmap( display
, stipple
);