]>
git.saurik.com Git - wxWidgets.git/blob - src/common/gdicmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common GDI classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "gdicmn.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/gdicmn.h"
26 #include "wx/bitmap.h"
28 #include "wx/cursor.h"
30 #include "wx/palette.h"
38 #if !USE_SHARED_LIBRARY
39 IMPLEMENT_CLASS(wxColourDatabase
, wxList
)
40 IMPLEMENT_DYNAMIC_CLASS(wxFontList
, wxList
)
41 IMPLEMENT_DYNAMIC_CLASS(wxPenList
, wxList
)
42 IMPLEMENT_DYNAMIC_CLASS(wxBrushList
, wxList
)
43 IMPLEMENT_DYNAMIC_CLASS(wxBitmapList
, wxList
)
45 IMPLEMENT_DYNAMIC_CLASS(wxRect, wxObject)
46 IMPLEMENT_DYNAMIC_CLASS(wxPoint, wxObject)
47 IMPLEMENT_DYNAMIC_CLASS(wxRealPoint, wxObject)
53 x
= 0; y
= 0; width
= 0; height
= 0;
56 wxRect::wxRect(long xx
, long yy
, long w
, long h
)
58 x
= xx
; y
= yy
; width
= w
; height
= h
;
61 wxRect::wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
)
65 width
= bottomRight
.x
- topLeft
.x
;
66 height
= bottomRight
.y
- topLeft
.y
;
81 wxRect::wxRect(const wxPoint
& point
, const wxSize
& size
)
83 x
= point
.x
; y
= point
.y
;
84 width
= size
.x
; height
= size
.y
;
87 wxRect::wxRect(const wxRect
& rect
)
95 wxRect
& wxRect::operator = (const wxRect
& rect
)
97 x
= rect
.x
; y
= rect
.y
; width
= rect
.width
; height
= rect
.height
;
101 bool wxRect::operator == (const wxRect
& rect
)
103 return ((x
== rect
.x
) &&
105 (width
== rect
.width
) &&
106 (height
== rect
.height
));
109 bool wxRect::operator != (const wxRect
& rect
)
111 return ((x
!= rect
.x
) ||
113 (width
!= rect
.width
) ||
114 (height
!= rect
.height
));
117 wxColourDatabase::wxColourDatabase (int type
):
122 wxColourDatabase::~wxColourDatabase ()
124 // Cleanup Colour allocated in Initialize()
125 wxNode
*node
= First ();
128 wxColour
*col
= (wxColour
*) node
->Data ();
129 wxNode
*next
= node
->Next ();
135 // Colour database stuff
136 void wxColourDatabase::Initialize ()
138 // Don't initialize for X: colours are found
139 // in FindColour below.
147 static cdef table
[]={
150 {"AQUAMARINE",112, 219, 147},
153 {"BLUE VIOLET", 159, 95, 159},
154 {"BROWN", 165, 42, 42},
155 {"CADET BLUE", 95, 159, 159},
156 {"CORAL", 255, 127, 0},
157 {"CORNFLOWER BLUE", 66, 66, 111},
158 {"CYAN", 0, 255, 255},
159 {"DARK GREY", 47, 47, 47}, // ?
161 {"DARK GREEN", 47, 79, 47},
162 {"DARK OLIVE GREEN", 79, 79, 47},
163 {"DARK ORCHID", 153, 50, 204},
164 {"DARK SLATE BLUE", 107, 35, 142},
165 {"DARK SLATE GREY", 47, 79, 79},
166 {"DARK TURQUOISE", 112, 147, 219},
167 {"DIM GREY", 84, 84, 84},
168 {"FIREBRICK", 142, 35, 35},
169 {"FOREST GREEN", 35, 142, 35},
170 {"GOLD", 204, 127, 50},
171 {"GOLDENROD", 219, 219, 112},
172 {"GREY", 128, 128, 128},
173 {"GREEN", 0, 255, 0},
174 {"GREEN YELLOW", 147, 219, 112},
175 {"INDIAN RED", 79, 47, 47},
176 {"KHAKI", 159, 159, 95},
177 {"LIGHT BLUE", 191, 216, 216},
178 {"LIGHT GREY", 192, 192, 192},
179 {"LIGHT STEEL BLUE", 143, 143, 188},
180 {"LIME GREEN", 50, 204, 50},
181 {"LIGHT MAGENTA", 255, 0, 255},
182 {"MAGENTA", 255, 0, 255},
183 {"MAROON", 142, 35, 107},
184 {"MEDIUM AQUAMARINE", 50, 204, 153},
185 {"MEDIUM GREY", 100, 100, 100},
186 {"MEDIUM BLUE", 50, 50, 204},
187 {"MEDIUM FOREST GREEN", 107, 142, 35},
188 {"MEDIUM GOLDENROD", 234, 234, 173},
189 {"MEDIUM ORCHID", 147, 112, 219},
190 {"MEDIUM SEA GREEN", 66, 111, 66},
191 {"MEDIUM SLATE BLUE", 127, 0, 255},
192 {"MEDIUM SPRING GREEN", 127, 255, 0},
193 {"MEDIUM TURQUOISE", 112, 219, 219},
194 {"MEDIUM VIOLET RED", 219, 112, 147},
195 {"MIDNIGHT BLUE", 47, 47, 79},
196 {"NAVY", 35, 35, 142},
197 {"ORANGE", 204, 50, 50},
198 {"ORANGE RED", 255, 0, 127},
199 {"ORCHID", 219, 112, 219},
200 {"PALE GREEN", 143, 188, 143},
201 {"PINK", 188, 143, 234},
202 {"PLUM", 234, 173, 234},
203 {"PURPLE", 176, 0, 255},
205 {"SALMON", 111, 66, 66},
206 {"SEA GREEN", 35, 142, 107},
207 {"SIENNA", 142, 107, 35},
208 {"SKY BLUE", 50, 153, 204},
209 {"SLATE BLUE", 0, 127, 255},
210 {"SPRING GREEN", 0, 255, 127},
211 {"STEEL BLUE", 35, 107, 142},
212 {"TAN", 219, 147, 112},
213 {"THISTLE", 216, 191, 216},
214 {"TURQUOISE", 173, 234, 234},
215 {"VIOLET", 79, 47, 79},
216 {"VIOLET RED", 204, 50, 153},
217 {"WHEAT", 216, 216, 191},
218 {"WHITE", 255, 255, 255},
219 {"YELLOW", 255, 255, 0},
220 {"YELLOW GREEN", 153, 204, 50},
223 #if defined(__WXGTK__) || defined(__X__)
224 {"MEDIUM GOLDENROD", 234, 234, 173},
225 {"MEDIUM FOREST GREEN", 107, 142, 35},
226 {"LIGHT MAGENTA", 255, 0, 255},
227 {"MEDIUM GREY", 100, 100, 100},
233 for (i
=0;cc
=table
[i
],cc
.name
!=0;i
++)
235 Append(cc
.name
,new wxColour(cc
.r
,cc
.g
,cc
.b
));
241 * Changed by Ian Brown, July 1994.
243 * When running under X, the Colour Database starts off empty. The X server
244 * is queried for the colour first time after which it is entered into the
245 * database. This allows our client to use the server colour database which
246 * is hopefully gamma corrected for the display being used.
249 wxColour
*wxColourDatabase::FindColour(const wxString
& colour
)
251 wxNode
*node
= Find((char *) (const char *)colour
);
253 return (wxColour
*)node
->Data();
261 wxColour
*col
= new wxColour( colour
);
267 Append( colour
, col
);
277 Display
*display
= XtDisplay(wxTheApp
->topLevel
) ;
280 Xv_Screen screen
= xv_get(xview_server
, SERVER_NTH_SCREEN
, 0);
281 Xv_opaque root_window
= xv_get(screen
, XV_ROOT
);
282 Display
*display
= (Display
*)xv_get(root_window
, XV_DISPLAY
);
285 /* MATTHEW: [4] Use wxGetMainColormap */
286 if (!XParseColor(display
, wxGetMainColormap(display
), colour
,&xcolour
))
289 unsigned char r
= (unsigned char)(xcolour
.red
>> 8);
290 unsigned char g
= (unsigned char)(xcolour
.green
>> 8);
291 unsigned char b
= (unsigned char)(xcolour
.blue
>> 8);
293 wxColour
*col
= new wxColour(r
, g
, b
);
301 wxString
wxColourDatabase::FindName (const wxColour
& colour
) const
303 unsigned char red
= colour
.Red ();
304 unsigned char green
= colour
.Green ();
305 unsigned char blue
= colour
.Blue ();
307 for (wxNode
* node
= First (); node
; node
= node
->Next ())
309 wxColour
*col
= (wxColour
*) node
->Data ();
311 if (col
->Red () == red
&& col
->Green () == green
&& col
->Blue () == blue
)
313 char *found
= node
->key
.string
;
315 return wxString(found
);
318 return wxString(""); // Not Found
323 wxInitializeStockObjects ()
325 wxTheBrushList
= new wxBrushList
;
326 wxThePenList
= new wxPenList
;
327 wxTheFontList
= new wxFontList
;
328 wxTheBitmapList
= new wxBitmapList
;
333 wxFontPool
= new XFontPool
;
336 wxNORMAL_FONT
= new wxFont (12, wxMODERN
, wxNORMAL
, wxNORMAL
);
337 wxSMALL_FONT
= new wxFont (10, wxSWISS
, wxNORMAL
, wxNORMAL
);
338 wxITALIC_FONT
= new wxFont (12, wxROMAN
, wxITALIC
, wxNORMAL
);
339 wxSWISS_FONT
= new wxFont (12, wxSWISS
, wxNORMAL
, wxNORMAL
);
341 wxRED_PEN
= new wxPen ("RED", 1, wxSOLID
);
342 wxCYAN_PEN
= new wxPen ("CYAN", 1, wxSOLID
);
343 wxGREEN_PEN
= new wxPen ("GREEN", 1, wxSOLID
);
344 wxBLACK_PEN
= new wxPen ("BLACK", 1, wxSOLID
);
345 wxWHITE_PEN
= new wxPen ("WHITE", 1, wxSOLID
);
346 wxTRANSPARENT_PEN
= new wxPen ("BLACK", 1, wxTRANSPARENT
);
347 wxBLACK_DASHED_PEN
= new wxPen ("BLACK", 1, wxSHORT_DASH
);
348 wxGREY_PEN
= new wxPen ("GREY", 1, wxSOLID
);
349 wxMEDIUM_GREY_PEN
= new wxPen ("MEDIUM GREY", 1, wxSOLID
);
350 wxLIGHT_GREY_PEN
= new wxPen ("LIGHT GREY", 1, wxSOLID
);
352 wxBLUE_BRUSH
= new wxBrush ("BLUE", wxSOLID
);
353 wxGREEN_BRUSH
= new wxBrush ("GREEN", wxSOLID
);
354 wxWHITE_BRUSH
= new wxBrush ("WHITE", wxSOLID
);
355 wxBLACK_BRUSH
= new wxBrush ("BLACK", wxSOLID
);
356 wxTRANSPARENT_BRUSH
= new wxBrush ("BLACK", wxTRANSPARENT
);
357 wxCYAN_BRUSH
= new wxBrush ("CYAN", wxSOLID
);
358 wxRED_BRUSH
= new wxBrush ("RED", wxSOLID
);
359 wxGREY_BRUSH
= new wxBrush ("GREY", wxSOLID
);
360 wxMEDIUM_GREY_BRUSH
= new wxBrush ("MEDIUM GREY", wxSOLID
);
361 wxLIGHT_GREY_BRUSH
= new wxBrush ("LIGHT GREY", wxSOLID
);
363 wxBLACK
= new wxColour ("BLACK");
364 wxWHITE
= new wxColour ("WHITE");
365 wxRED
= new wxColour ("RED");
366 wxBLUE
= new wxColour ("BLUE");
367 wxGREEN
= new wxColour ("GREEN");
368 wxCYAN
= new wxColour ("CYAN");
369 wxLIGHT_GREY
= new wxColour ("LIGHT GREY");
371 wxSTANDARD_CURSOR
= new wxCursor (wxCURSOR_ARROW
);
372 wxHOURGLASS_CURSOR
= new wxCursor (wxCURSOR_WAIT
);
373 wxCROSS_CURSOR
= new wxCursor (wxCURSOR_CROSS
);
377 wxDeleteStockObjects ()
379 DELETEP(wxNORMAL_FONT
);
380 DELETEP(wxSMALL_FONT
);
381 DELETEP(wxITALIC_FONT
);
382 DELETEP(wxSWISS_FONT
);
386 DELETEP(wxGREEN_PEN
);
387 DELETEP(wxBLACK_PEN
);
388 DELETEP(wxWHITE_PEN
);
389 DELETEP(wxTRANSPARENT_PEN
);
390 DELETEP(wxBLACK_DASHED_PEN
);
392 DELETEP(wxMEDIUM_GREY_PEN
);
393 DELETEP(wxLIGHT_GREY_PEN
);
395 DELETEP(wxBLUE_BRUSH
);
396 DELETEP(wxGREEN_BRUSH
);
397 DELETEP(wxWHITE_BRUSH
);
398 DELETEP(wxBLACK_BRUSH
);
399 DELETEP(wxTRANSPARENT_BRUSH
);
400 DELETEP(wxCYAN_BRUSH
);
401 DELETEP(wxRED_BRUSH
);
402 DELETEP(wxGREY_BRUSH
);
403 DELETEP(wxMEDIUM_GREY_BRUSH
);
404 DELETEP(wxLIGHT_GREY_BRUSH
);
412 DELETEP(wxLIGHT_GREY
);
414 DELETEP(wxSTANDARD_CURSOR
);
415 DELETEP(wxHOURGLASS_CURSOR
);
416 DELETEP(wxCROSS_CURSOR
);
419 wxBitmapList::wxBitmapList ()
423 wxBitmapList::~wxBitmapList ()
425 wxNode
*node
= First ();
428 wxBitmap
*bitmap
= (wxBitmap
*) node
->Data ();
429 wxNode
*next
= node
->Next ();
431 // bitmap->FreeResource(TRUE);
436 // Pen and Brush lists
437 wxPenList::~wxPenList ()
439 wxNode
*node
= First ();
442 wxPen
*pen
= (wxPen
*) node
->Data ();
443 wxNode
*next
= node
->Next ();
445 // pen->FreeResource(TRUE);
450 void wxPenList::AddPen (wxPen
* pen
)
455 void wxPenList::RemovePen (wxPen
* pen
)
460 wxPen
*wxPenList::FindOrCreatePen (const wxColour
& colour
, int width
, int style
)
462 for (wxNode
* node
= First (); node
; node
= node
->Next ())
464 wxPen
*each_pen
= (wxPen
*) node
->Data ();
465 if (each_pen
&& each_pen
->GetVisible() &&
466 each_pen
->GetWidth () == width
&&
467 each_pen
->GetStyle () == style
&&
468 each_pen
->GetColour ().Red () == colour
.Red () &&
469 each_pen
->GetColour ().Green () == colour
.Green () &&
470 each_pen
->GetColour ().Blue () == colour
.Blue ())
473 wxPen
*pen
= new wxPen (colour
, width
, style
);
475 // Yes, we can return a pointer to this in a later FindOrCreatePen call,
476 // because we created it within FindOrCreatePen. Safeguards against
477 // returning a pointer to an automatic variable and hanging on to it
478 // (dangling pointer).
479 pen
->SetVisible(TRUE
);
483 wxPen
*wxPenList::FindOrCreatePen (const wxString
& colour
, int width
, int style
)
485 wxColour
*the_colour
= wxTheColourDatabase
->FindColour (colour
);
487 return FindOrCreatePen (*the_colour
, width
, style
);
492 wxBrushList::~wxBrushList ()
494 wxNode
*node
= First ();
497 wxBrush
*brush
= (wxBrush
*) node
->Data ();
498 wxNode
*next
= node
->Next ();
504 void wxBrushList::AddBrush (wxBrush
* brush
)
509 wxBrush
*wxBrushList::FindOrCreateBrush (const wxColour
& colour
, int style
)
511 for (wxNode
* node
= First (); node
; node
= node
->Next ())
513 wxBrush
*each_brush
= (wxBrush
*) node
->Data ();
514 if (each_brush
&& each_brush
->GetVisible() &&
515 each_brush
->GetStyle () == style
&&
516 each_brush
->GetColour ().Red () == colour
.Red () &&
517 each_brush
->GetColour ().Green () == colour
.Green () &&
518 each_brush
->GetColour ().Blue () == colour
.Blue ())
521 // Yes, we can return a pointer to this in a later FindOrCreateBrush call,
522 // because we created it within FindOrCreateBrush. Safeguards against
523 // returning a pointer to an automatic variable and hanging on to it
524 // (dangling pointer).
525 wxBrush
*brush
= new wxBrush (colour
, style
);
526 brush
->SetVisible(TRUE
);
530 wxBrush
*wxBrushList::FindOrCreateBrush (const wxString
& colour
, int style
)
532 wxColour
*the_colour
= wxTheColourDatabase
->FindColour (colour
);
534 return FindOrCreateBrush (*the_colour
, style
);
539 void wxBrushList::RemoveBrush (wxBrush
* brush
)
541 DeleteObject (brush
);
544 wxFontList::~wxFontList ()
547 wxNode
*node
= First ();
551 wxFont *font = (wxFont *) node->Data ();
552 wxNode *next = node->Next ();
556 // New for 2.0: don't delete the font (it may be a member
557 // of a wxDC, for example)
558 wxFont
*font
= (wxFont
*) node
->Data ();
559 wxNode
*next
= node
->Next ();
561 // Force the font to be deleted
562 font
->FreeResource(TRUE
);
568 void wxFontList::AddFont (wxFont
* font
)
573 void wxFontList::RemoveFont (wxFont
* font
)
579 FindOrCreateFont (int PointSize
, int FamilyOrFontId
, int Style
, int Weight
, bool underline
, const wxString
& Face
)
581 for (wxNode
* node
= First (); node
; node
= node
->Next ())
583 wxFont
*each_font
= (wxFont
*) node
->Data ();
584 if (each_font
&& each_font
->GetVisible() && each_font
->Ok() &&
585 each_font
->GetPointSize () == PointSize
&&
586 each_font
->GetStyle () == Style
&&
587 each_font
->GetWeight () == Weight
&&
588 each_font
->GetUnderlined () == underline
&&
589 #if defined(__X__) || (defined(__WXMSW__) && USE_PORTABLE_FONTS_IN_MSW)
590 each_font
->GetFontId () == FamilyOrFontId
) /* New font system */
592 each_font
->GetFamily () == FamilyOrFontId
&&
593 (!each_font
->GetFaceName() || each_font
->GetFaceName() == Face
))
597 wxFont
*font
= new wxFont (PointSize
, FamilyOrFontId
, Style
, Weight
, underline
, Face
);
598 font
->SetVisible(TRUE
);
602 void wxBitmapList::AddBitmap(wxBitmap
*bitmap
)
604 void wxBitmapList::RemoveBitmap(wxBitmap
*bitmap
)
605 { DeleteObject(bitmap
); }
607 wxSize
wxGetDisplaySize()
610 wxDisplaySize(& x
, & y
);