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::CreateFromXpm(const char **bits
)
173 wxCHECK_MSG( bits
, FALSE
, _T("NULL pointer in wxBitmap::CreateFromXpm") );
175 return Create(bits
, wxBITMAP_TYPE_XPM_DATA
, 0, 0, 0);
178 bool wxBitmap::Create(int w
, int h
, int d
)
182 m_refData
= new wxBitmapRefData
;
185 d
= wxDisplayDepth();
187 M_BITMAPDATA
->m_width
= w
;
188 M_BITMAPDATA
->m_height
= h
;
189 M_BITMAPDATA
->m_depth
= d
;
190 M_BITMAPDATA
->m_freePixmap
= TRUE
;
192 Display
*dpy
= (Display
*) wxGetDisplay();
194 M_BITMAPDATA
->m_display
= dpy
; /* MATTHEW: [4] Remember the display */
196 M_BITMAPDATA
->m_pixmap
= (WXPixmap
) XCreatePixmap (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)),
199 M_BITMAPDATA
->m_ok
= (M_BITMAPDATA
->m_pixmap
!= (WXPixmap
) 0) ;
200 return M_BITMAPDATA
->m_ok
;
203 bool wxBitmap::LoadFile(const wxString
& filename
, long type
)
207 m_refData
= new wxBitmapRefData
;
209 wxBitmapHandler
*handler
= FindHandler(type
);
211 if ( handler
== NULL
) {
213 if (!image
.LoadFile( filename
, type
)) return FALSE
;
216 *this = image
.ConvertToBitmap();
222 return handler
->LoadFile(this, filename
, type
, -1, -1);
225 bool wxBitmap::Create(void *data
, long type
, int width
, int height
, int depth
)
229 m_refData
= new wxBitmapRefData
;
231 wxBitmapHandler
*handler
= FindHandler(type
);
233 if ( handler
== NULL
) {
234 wxLogWarning("no data bitmap handler for type %d defined.", type
);
239 return handler
->Create(this, data
, type
, width
, height
, depth
);
242 bool wxBitmap::SaveFile(const wxString
& filename
, int type
, const wxPalette
*palette
)
244 wxBitmapHandler
*handler
= FindHandler(type
);
246 if ( handler
== NULL
) { // try wxImage
247 wxImage
image( *this );
248 if (image
.Ok()) return image
.SaveFile( filename
, type
);
252 return handler
->SaveFile(this, filename
, type
, palette
);
255 void wxBitmap::SetWidth(int w
)
258 m_refData
= new wxBitmapRefData
;
260 M_BITMAPDATA
->m_width
= w
;
263 void wxBitmap::SetHeight(int h
)
266 m_refData
= new wxBitmapRefData
;
268 M_BITMAPDATA
->m_height
= h
;
271 void wxBitmap::SetDepth(int d
)
274 m_refData
= new wxBitmapRefData
;
276 M_BITMAPDATA
->m_depth
= d
;
279 void wxBitmap::SetQuality(int q
)
282 m_refData
= new wxBitmapRefData
;
284 M_BITMAPDATA
->m_quality
= q
;
287 void wxBitmap::SetOk(bool isOk
)
290 m_refData
= new wxBitmapRefData
;
292 M_BITMAPDATA
->m_ok
= isOk
;
295 void wxBitmap::SetPalette(const wxPalette
& palette
)
298 m_refData
= new wxBitmapRefData
;
300 M_BITMAPDATA
->m_bitmapPalette
= palette
;
303 void wxBitmap::SetMask(wxMask
*mask
)
306 m_refData
= new wxBitmapRefData
;
308 M_BITMAPDATA
->m_bitmapMask
= mask
;
311 void wxBitmap::AddHandler(wxBitmapHandler
*handler
)
313 sm_handlers
.Append(handler
);
316 void wxBitmap::InsertHandler(wxBitmapHandler
*handler
)
318 sm_handlers
.Insert(handler
);
321 bool wxBitmap::RemoveHandler(const wxString
& name
)
323 wxBitmapHandler
*handler
= FindHandler(name
);
326 sm_handlers
.DeleteObject(handler
);
333 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& name
)
335 wxNode
*node
= sm_handlers
.First();
338 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
339 if ( handler
->GetName() == name
)
346 wxBitmapHandler
*wxBitmap::FindHandler(const wxString
& extension
, long bitmapType
)
348 wxNode
*node
= sm_handlers
.First();
351 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
352 if ( handler
->GetExtension() == extension
&&
353 (bitmapType
== -1 || handler
->GetType() == bitmapType
) )
360 wxBitmapHandler
*wxBitmap::FindHandler(long bitmapType
)
362 wxNode
*node
= sm_handlers
.First();
365 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
366 if (handler
->GetType() == bitmapType
)
379 m_pixmap
= (WXPixmap
) 0;
382 // Construct a mask from a bitmap and a colour indicating
383 // the transparent area
384 wxMask::wxMask(const wxBitmap
& bitmap
, const wxColour
& colour
)
386 m_pixmap
= (WXPixmap
) 0;
388 Create(bitmap
, colour
);
391 // Construct a mask from a bitmap and a palette index indicating
392 // the transparent area
393 wxMask::wxMask(const wxBitmap
& bitmap
, int paletteIndex
)
395 m_pixmap
= (WXPixmap
) 0;
397 Create(bitmap
, paletteIndex
);
400 // Construct a mask from a mono bitmap (copies the bitmap).
401 wxMask::wxMask(const wxBitmap
& bitmap
)
403 m_pixmap
= (WXPixmap
) 0;
410 // TODO: this may be the wrong display
412 XFreePixmap ((Display
*) wxGetDisplay(), (Pixmap
) m_pixmap
);
415 // Create a mask from a mono bitmap (copies the bitmap).
416 bool wxMask::Create(const wxBitmap
& WXUNUSED(bitmap
))
422 // Create a mask from a bitmap and a palette index indicating
423 // the transparent area
424 bool wxMask::Create(const wxBitmap
& WXUNUSED(bitmap
), int WXUNUSED(paletteIndex
))
430 // Create a mask from a bitmap and a colour indicating
431 // the transparent area
432 bool wxMask::Create(const wxBitmap
& WXUNUSED(bitmap
), const wxColour
& WXUNUSED(colour
))
442 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler
, wxObject
)
444 bool wxBitmapHandler::Create(wxBitmap
*WXUNUSED(bitmap
), void *WXUNUSED(data
), long WXUNUSED(type
),
445 int WXUNUSED(width
), int WXUNUSED(height
), int WXUNUSED(depth
))
450 bool wxBitmapHandler::LoadFile(wxBitmap
*WXUNUSED(bitmap
), const wxString
& WXUNUSED(name
), long WXUNUSED(type
),
451 int WXUNUSED(desiredWidth
), int WXUNUSED(desiredHeight
))
456 bool wxBitmapHandler::SaveFile(wxBitmap
*WXUNUSED(bitmap
), const wxString
& WXUNUSED(name
), int WXUNUSED(type
),
457 const wxPalette
*WXUNUSED(palette
))
466 class WXDLLEXPORT wxXBMFileHandler
: public wxBitmapHandler
468 DECLARE_DYNAMIC_CLASS(wxXBMFileHandler
)
470 inline wxXBMFileHandler()
474 m_type
= wxBITMAP_TYPE_XBM
;
477 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
478 int desiredWidth
, int desiredHeight
);
480 IMPLEMENT_DYNAMIC_CLASS(wxXBMFileHandler
, wxBitmapHandler
)
482 bool wxXBMFileHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long WXUNUSED(flags
),
483 int WXUNUSED(desiredWidth
), int WXUNUSED(desiredHeight
))
485 M_BITMAPHANDLERDATA
->m_freePixmap
= TRUE
;
491 Display
*dpy
= (Display
*) wxGetDisplay();
492 M_BITMAPDATA
->m_display
= (WXDisplay
*) dpy
;
494 int value
= XReadBitmapFile (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)),
495 (char*) (const char*) name
, &w
, &h
, &pixmap
, &hotX
, &hotY
);
496 M_BITMAPHANDLERDATA
->m_width
= w
;
497 M_BITMAPHANDLERDATA
->m_height
= h
;
498 M_BITMAPHANDLERDATA
->m_depth
= 1;
499 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) pixmap
;
501 if ((value
== BitmapFileInvalid
) ||
502 (value
== BitmapOpenFailed
) ||
503 (value
== BitmapNoMemory
))
505 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
506 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) 0;
509 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
511 return M_BITMAPHANDLERDATA
->m_ok
;
514 class WXDLLEXPORT wxXBMDataHandler
: public wxBitmapHandler
516 DECLARE_DYNAMIC_CLASS(wxXBMDataHandler
)
518 inline wxXBMDataHandler()
522 m_type
= wxBITMAP_TYPE_XBM_DATA
;
525 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
527 IMPLEMENT_DYNAMIC_CLASS(wxXBMDataHandler
, wxBitmapHandler
)
529 bool wxXBMDataHandler::Create( wxBitmap
*bitmap
, void *data
, long WXUNUSED(flags
),
530 int width
, int height
, int WXUNUSED(depth
))
532 M_BITMAPHANDLERDATA
->m_width
= width
;
533 M_BITMAPHANDLERDATA
->m_height
= height
;
534 M_BITMAPHANDLERDATA
->m_depth
= 1;
535 M_BITMAPHANDLERDATA
->m_freePixmap
= TRUE
;
537 Display
*dpy
= (Display
*) wxGetDisplay();
538 M_BITMAPHANDLERDATA
->m_display
= (WXDisplay
*) dpy
;
540 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) XCreateBitmapFromData (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)), (char*) data
, width
, height
);
541 M_BITMAPHANDLERDATA
->m_ok
= (M_BITMAPHANDLERDATA
->m_pixmap
!= (WXPixmap
) 0) ;
543 // code for wxControl. TODO: can we avoid doing this until we need it?
544 // E.g. have CreateButtonPixmaps which is called on demand.
545 XImage
* image
= (XImage
*) XtMalloc (sizeof (XImage
));
546 image
->width
= width
;
547 image
->height
= height
;
548 image
->data
= (char*) data
;
551 image
->format
= XYBitmap
;
552 image
->byte_order
= LSBFirst
;
553 image
->bitmap_unit
= 8;
554 image
->bitmap_bit_order
= LSBFirst
;
555 image
->bitmap_pad
= 8;
556 image
->bytes_per_line
= (width
+ 7) >> 3;
559 sprintf (tmp
, "Im%x", (unsigned int) image
);
560 XmInstallImage (image
, tmp
);
562 // Build our manually stipped pixmap.
564 int bpl
= (width
+ 7) / 8;
565 char *data1
= new char[height
* bpl
];
566 char* bits
= (char*) data
;
568 for (i
= 0; i
< height
; i
++)
570 int mask
= i
% 2 ? 0x55 : 0xaa;
572 for (j
= 0; j
< bpl
; j
++)
573 data1
[i
* bpl
+ j
] = bits
[i
* bpl
+ j
] & mask
;
575 XImage
* insensImage
= (XImage
*) XtMalloc (sizeof (XImage
));
576 insensImage
->width
= width
;
577 insensImage
->height
= height
;
578 insensImage
->data
= data1
;
579 insensImage
->depth
= 1;
580 insensImage
->xoffset
= 0;
581 insensImage
->format
= XYBitmap
;
582 insensImage
->byte_order
= LSBFirst
;
583 insensImage
->bitmap_unit
= 8;
584 insensImage
->bitmap_bit_order
= LSBFirst
;
585 insensImage
->bitmap_pad
= 8;
586 insensImage
->bytes_per_line
= bpl
;
588 sprintf (tmp
, "Not%x", (unsigned int)insensImage
);
589 XmInstallImage (insensImage
, tmp
);
591 M_BITMAPHANDLERDATA
->m_image
= (WXImage
*) image
;
592 M_BITMAPHANDLERDATA
->m_insensImage
= (WXImage
*) insensImage
;
598 class WXDLLEXPORT wxXPMFileHandler
: public wxBitmapHandler
600 DECLARE_DYNAMIC_CLASS(wxXPMFileHandler
)
602 inline wxXPMFileHandler()
606 m_type
= wxBITMAP_TYPE_XPM
;
609 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
610 int desiredWidth
, int desiredHeight
);
611 virtual bool SaveFile(wxBitmap
*bitmap
, const wxString
& name
, int type
, const wxPalette
*palette
= NULL
);
614 IMPLEMENT_DYNAMIC_CLASS(wxXPMFileHandler
, wxBitmapHandler
)
616 bool wxXPMFileHandler::LoadFile( wxBitmap
*bitmap
, const wxString
& name
, long WXUNUSED(flags
),
617 int WXUNUSED(desiredWidth
), int WXUNUSED(desiredHeight
) )
619 Display
*dpy
= (Display
*) wxGetDisplay();
620 M_BITMAPHANDLERDATA
->m_display
= (WXDisplay
*) dpy
;
622 XpmAttributes xpmAttr
;
626 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
627 xpmAttr
.valuemask
= XpmReturnInfos
| XpmCloseness
;
628 xpmAttr
.closeness
= 40000;
629 int errorStatus
= XpmReadFileToPixmap(dpy
,
630 RootWindow(dpy
, DefaultScreen(dpy
)), (char*) (const char*) name
,
631 &pixmap
, &mask
, &xpmAttr
);
633 if (errorStatus
== XpmSuccess
)
635 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) pixmap
;
638 M_BITMAPHANDLERDATA
->m_bitmapMask
= new wxMask
;
639 M_BITMAPHANDLERDATA
->m_bitmapMask
->SetPixmap((WXPixmap
) mask
);
642 unsigned int depthRet
;
644 unsigned int widthRet
, heightRet
, borderWidthRet
;
645 Window rootWindowRet
;
646 XGetGeometry(dpy
, pixmap
, &rootWindowRet
, &xRet
, &yRet
,
647 &widthRet
, &heightRet
, &borderWidthRet
, &depthRet
);
649 M_BITMAPHANDLERDATA
->m_width
= xpmAttr
.width
;
650 M_BITMAPHANDLERDATA
->m_height
= xpmAttr
.height
;
653 if ( xpmAttr.npixels > 2 )
655 M_BITMAPHANDLERDATA->m_depth = 8; // TODO: next time not just a guess :-) ...
658 M_BITMAPHANDLERDATA->m_depth = 1; // mono
662 M_BITMAPHANDLERDATA
->m_depth
= depthRet
;
664 M_BITMAPHANDLERDATA
->m_numColors
= xpmAttr
.npixels
;
666 XpmFreeAttributes(&xpmAttr
);
668 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
672 // XpmDebugError(errorStatus, name);
673 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
678 bool wxXPMFileHandler::SaveFile( wxBitmap
*bitmap
, const wxString
& name
, int WXUNUSED(type
),
679 const wxPalette
*WXUNUSED(palette
))
681 if (M_BITMAPHANDLERDATA
->m_ok
&& M_BITMAPHANDLERDATA
->m_pixmap
)
683 Display
*dpy
= (Display
*) M_BITMAPHANDLERDATA
->m_display
;
684 int errorStatus
= XpmWriteFileFromPixmap(dpy
, (char*) (const char*) name
,
685 (Pixmap
) M_BITMAPHANDLERDATA
->m_pixmap
,
686 (M_BITMAPHANDLERDATA
->m_bitmapMask
? (Pixmap
) M_BITMAPHANDLERDATA
->m_bitmapMask
->GetPixmap() : (Pixmap
) 0),
687 (XpmAttributes
*) NULL
);
688 if (errorStatus
== XpmSuccess
)
697 class WXDLLEXPORT wxXPMDataHandler
: public wxBitmapHandler
699 DECLARE_DYNAMIC_CLASS(wxXPMDataHandler
)
701 inline wxXPMDataHandler()
705 m_type
= wxBITMAP_TYPE_XPM_DATA
;
708 virtual bool Create(wxBitmap
*bitmap
, void *data
, long flags
, int width
, int height
, int depth
= 1);
710 IMPLEMENT_DYNAMIC_CLASS(wxXPMDataHandler
, wxBitmapHandler
)
712 bool wxXPMDataHandler::Create( wxBitmap
*bitmap
, void *data
, long WXUNUSED(flags
),
713 int width
, int height
, int WXUNUSED(depth
))
715 M_BITMAPHANDLERDATA
->m_width
= width
;
716 M_BITMAPHANDLERDATA
->m_height
= height
;
717 M_BITMAPHANDLERDATA
->m_depth
= 1;
718 M_BITMAPHANDLERDATA
->m_freePixmap
= TRUE
;
720 Display
*dpy
= (Display
*) wxGetDisplay();
721 M_BITMAPHANDLERDATA
->m_display
= (WXDisplay
*) dpy
;
723 XpmAttributes xpmAttr
;
725 xpmAttr
.valuemask
= XpmReturnInfos
; /* nothing yet, but get infos back */
727 XpmColorSymbol symbolicColors
[4];
728 if (sg_Control
&& sg_Control
->GetMainWidget())
730 symbolicColors
[0].name
= "foreground";
731 symbolicColors
[0].value
= NULL
;
732 symbolicColors
[1].name
= "background";
733 symbolicColors
[1].value
= NULL
;
734 XtVaGetValues((Widget
) sg_Control
->GetMainWidget(),
735 XmNforeground
, &symbolicColors
[0].pixel
,
736 XmNbackground
, &symbolicColors
[1].pixel
,NULL
);
737 xpmAttr
.numsymbols
= 2;
738 xpmAttr
.colorsymbols
= symbolicColors
;
739 xpmAttr
.valuemask
|= XpmColorSymbols
; // add flag
744 int ErrorStatus
= XpmCreatePixmapFromData(dpy
, RootWindow(dpy
, DefaultScreen(dpy
)),
745 (char**) data
, &pixmap
, &mask
, &xpmAttr
);
746 if (ErrorStatus
== XpmSuccess
)
749 M_BITMAPHANDLERDATA
->m_width
= xpmAttr
.width
;
750 M_BITMAPHANDLERDATA
->m_height
= xpmAttr
.height
;
752 unsigned int depthRet
;
754 unsigned int widthRet
, heightRet
, borderWidthRet
;
755 Window rootWindowRet
;
756 XGetGeometry(dpy
, pixmap
, &rootWindowRet
, &xRet
, &yRet
,
757 &widthRet
, &heightRet
, &borderWidthRet
, &depthRet
);
760 if ( xpmAttr.npixels > 2 )
762 M_BITMAPHANDLERDATA->m_depth = 8; // next time not just a guess :-) ...
765 M_BITMAPHANDLERDATA->m_depth = 1; // mono
769 M_BITMAPHANDLERDATA
->m_depth
= depthRet
;
771 M_BITMAPHANDLERDATA
->m_numColors
= xpmAttr
.npixels
;
772 XpmFreeAttributes(&xpmAttr
);
773 M_BITMAPHANDLERDATA
->m_ok
= TRUE
;
774 M_BITMAPHANDLERDATA
->m_pixmap
= (WXPixmap
) pixmap
;
777 M_BITMAPHANDLERDATA
->m_bitmapMask
= new wxMask
;
778 M_BITMAPHANDLERDATA
->m_bitmapMask
->SetPixmap((WXPixmap
) mask
);
783 // XpmDebugError(ErrorStatus, NULL);
784 M_BITMAPHANDLERDATA
->m_ok
= FALSE
;
786 return M_BITMAPHANDLERDATA
->m_ok
;
789 #endif // wxHAVE_LIB_XPM
791 void wxBitmap::CleanUpHandlers()
793 wxNode
*node
= sm_handlers
.First();
796 wxBitmapHandler
*handler
= (wxBitmapHandler
*)node
->Data();
797 wxNode
*next
= node
->Next();
804 void wxBitmap::InitStandardHandlers()
806 // Initialize all standard bitmap or derived class handlers here.
807 AddHandler(new wxXBMFileHandler
);
808 AddHandler(new wxXBMDataHandler
);
810 // XPM is considered standard for Motif, although it can be omitted if
811 // libXpm is not installed
813 AddHandler(new wxXPMFileHandler
);
814 AddHandler(new wxXPMDataHandler
);
815 #endif // wxHAVE_LIB_XPM
818 WXPixmap
wxBitmap::GetLabelPixmap (WXWidget w
)
820 if (M_BITMAPDATA
->m_image
== (WXPixmap
) 0)
821 return M_BITMAPDATA
->m_pixmap
;
823 Display
*dpy
= (Display
*) M_BITMAPDATA
->m_display
;
828 if (labelPixmap) return labelPixmap;
829 things can be wrong, because colors can have been changed.
833 XmDestroyPixmap(DefaultScreenOfDisplay(dpy),labelPixmap) ;
834 we got BadDrawable if the pixmap is referenced by multiples widgets
838 So, before doing thing really clean, I just do nothing; if the pixmap is
839 referenced by many widgets, Motif performs caching functions.
840 And if pixmap is referenced with multiples colors, we just have some
841 memory leaks... I hope we can deal with them...
843 // Must be destroyed, because colours can have been changed!
844 if (M_BITMAPDATA
->m_labelPixmap
)
845 XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), M_BITMAPDATA
->m_labelPixmap
);
849 sprintf (tmp
, "Im%x", (unsigned int) M_BITMAPDATA
->m_image
);
852 Widget widget
= (Widget
) w
;
854 while (XmIsGadget ( widget
))
855 widget
= XtParent (widget
);
856 XtVaGetValues (widget
, XmNbackground
, &bg
, XmNforeground
, &fg
, NULL
);
858 M_BITMAPDATA
->m_labelPixmap
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
);
860 return M_BITMAPDATA
->m_labelPixmap
;
863 WXPixmap
wxBitmap::GetArmPixmap (WXWidget w
)
865 if (M_BITMAPDATA
->m_image
== (WXPixmap
) 0)
866 return M_BITMAPDATA
->m_pixmap
;
868 Display
*dpy
= (Display
*) M_BITMAPDATA
->m_display
;
870 // See GetLabelPixmap () comment
872 // Must be destroyed, because colours can have been changed!
873 if (M_BITMAPDATA
->m_armPixmap
)
874 XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), M_BITMAPDATA
->m_armPixmap
);
878 sprintf (tmp
, "Im%x", (unsigned int) M_BITMAPDATA
->m_image
);
881 Widget widget
= (Widget
) w
;
883 XtVaGetValues (widget
, XmNarmColor
, &bg
, NULL
);
884 while (XmIsGadget (widget
))
885 widget
= XtParent (widget
);
886 XtVaGetValues (widget
, XmNforeground
, &fg
, NULL
);
888 M_BITMAPDATA
->m_armPixmap
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
);
890 return M_BITMAPDATA
->m_armPixmap
;
893 WXPixmap
wxBitmap::GetInsensPixmap (WXWidget w
)
895 Display
*dpy
= (Display
*) M_BITMAPDATA
->m_display
;
897 if (M_BITMAPDATA
->m_insensPixmap
)
898 return M_BITMAPDATA
->m_insensPixmap
;
902 M_BITMAPDATA
->m_insensPixmap
= (WXPixmap
) XCreateInsensitivePixmap(dpy
, (Pixmap
) M_BITMAPDATA
->m_pixmap
);
903 if (M_BITMAPDATA
->m_insensPixmap
)
904 return M_BITMAPDATA
->m_insensPixmap
;
906 return M_BITMAPDATA
->m_pixmap
;
909 if (M_BITMAPDATA
->m_insensImage
== (WXPixmap
) 0)
910 return M_BITMAPDATA
->m_pixmap
;
913 See
GetLabelPixmap () comment
914 // Must be destroyed, because colours can have been changed!
915 if (M_BITMAPDATA
->m_insensPixmap
)
916 XmDestroyPixmap (DefaultScreenOfDisplay (dpy
), (Pixmap
) M_BITMAPDATA
->m_insensPixmap
);
920 sprintf (tmp
, "Not%x", (unsigned int) M_BITMAPDATA
->m_insensImage
);
923 Widget widget
= (Widget
) w
;
925 while (XmIsGadget (widget
))
926 widget
= XtParent (widget
);
927 XtVaGetValues (widget
, XmNbackground
, &bg
, XmNforeground
, &fg
, NULL
);
929 M_BITMAPDATA
->m_insensPixmap
= (WXPixmap
) XmGetPixmap (DefaultScreenOfDisplay (dpy
), tmp
, fg
, bg
);
931 return M_BITMAPDATA
->m_insensPixmap
;
934 // We may need this sometime...
936 /****************************************************************************
939 XCreateInsensitivePixmap - create a grayed-out copy of a pixmap
942 Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap )
945 This function creates a grayed-out copy of the argument pixmap, suitable
946 for use as a XmLabel's XmNlabelInsensitivePixmap resource.
949 The return value is the new Pixmap id or zero on error. Errors include
950 a NULL display argument or an invalid Pixmap argument.
953 If one of the XLib functions fail, it will produce a X error. The
954 default X error handler prints a diagnostic and calls exit().
957 XCopyArea(3), XCreateBitmapFromData(3), XCreateGC(3), XCreatePixmap(3),
958 XFillRectangle(3), exit(2)
961 John R Veregge - john@puente.jpl.nasa.gov
962 Advanced Engineering and Prototyping Group (AEG)
963 Information Systems Technology Section (395)
964 Jet Propulsion Lab - Calif Institute of Technology
966 *****************************************************************************/
969 XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
)
972 static char stipple_data
[] =
974 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
975 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
976 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
977 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA
980 Pixmap ipixmap
, stipple
;
981 unsigned width
, height
, depth
;
983 Window window
; /* These return values */
984 unsigned border
; /* from XGetGeometry() */
985 int x
, y
; /* are not needed. */
989 if ( NULL
== display
|| 0 == pixmap
)
992 if ( 0 == XGetGeometry( display
, pixmap
, &window
, &x
, &y
,
993 &width
, &height
, &border
, &depth
)
995 return ipixmap
; /* BadDrawable: probably an invalid pixmap */
997 /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap.
999 stipple
= XCreateBitmapFromData( display
, pixmap
, stipple_data
, 16, 16 );
1002 gc
= XCreateGC( display
, pixmap
, (XtGCMask
)0, (XGCValues
*)NULL
);
1005 /* Create an identical copy of the argument pixmap.
1007 ipixmap
= XCreatePixmap( display
, pixmap
, width
, height
, depth
);
1010 /* Copy the argument pixmap into the new pixmap.
1012 XCopyArea( display
, pixmap
, ipixmap
,
1013 gc
, 0, 0, width
, height
, 0, 0 );
1015 /* Refill the new pixmap using the stipple algorithm/pixmap.
1017 XSetStipple( display
, gc
, stipple
);
1018 XSetFillStyle( display
, gc
, FillStippled
);
1019 XFillRectangle( display
, ipixmap
, gc
, 0, 0, width
, height
);
1021 XFreeGC( display
, gc
);
1023 XFreePixmap( display
, stipple
);
1028 // Creates a bitmap with transparent areas drawn in
1029 // the given colour.
1030 wxBitmap
wxCreateMaskedBitmap(const wxBitmap
& bitmap
, wxColour
& colour
)
1032 wxBitmap
newBitmap(bitmap
.GetWidth(),
1037 srcDC
.SelectObject(bitmap
);
1038 destDC
.SelectObject(newBitmap
);
1040 wxBrush
brush(colour
, wxSOLID
);
1041 destDC
.SetOptimization(FALSE
);
1042 destDC
.SetBackground(brush
);
1044 destDC
.Blit(0, 0, bitmap
.GetWidth(), bitmap
.GetHeight(), & srcDC
, 0, 0, wxCOPY
, TRUE
);