]>
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_DYNAMIC_CLASS(wxRect
, wxObject
)
40 IMPLEMENT_CLASS(wxColourDatabase
, wxList
)
41 IMPLEMENT_DYNAMIC_CLASS(wxFontList
, wxList
)
42 IMPLEMENT_DYNAMIC_CLASS(wxPenList
, wxList
)
43 IMPLEMENT_DYNAMIC_CLASS(wxBrushList
, wxList
)
44 IMPLEMENT_DYNAMIC_CLASS(wxBitmapList
, wxList
)
45 IMPLEMENT_DYNAMIC_CLASS(wxPoint
, wxObject
)
46 IMPLEMENT_DYNAMIC_CLASS(wxRealPoint
, wxObject
)
51 x
= 0; y
= 0; width
= 0; height
= 0;
54 wxRect::wxRect(const long xx
, const long yy
, const long w
, const long h
)
56 x
= xx
; y
= yy
; width
= w
; height
= h
;
59 wxRect::wxRect(const wxPoint
& topLeft
, const wxPoint
& bottomRight
)
63 width
= bottomRight
.x
- topLeft
.x
;
64 height
= bottomRight
.y
- topLeft
.y
;
79 wxRect::wxRect(const wxPoint
& point
, const wxSize
& size
)
81 x
= point
.x
; y
= point
.y
;
82 width
= size
.x
; height
= size
.y
;
85 wxRect::wxRect(const wxRect
& rect
)
93 wxRect
& wxRect::operator = (const wxRect
& rect
)
95 x
= rect
.x
; y
= rect
.y
; width
= rect
.width
; height
= rect
.height
;
99 bool wxRect::operator == (const wxRect
& rect
)
101 return ((x
== rect
.x
) &&
103 (width
== rect
.width
) &&
104 (height
== rect
.height
));
107 bool wxRect::operator != (const wxRect
& rect
)
109 return ((x
!= rect
.x
) ||
111 (width
!= rect
.width
) ||
112 (height
!= rect
.height
));
115 wxColourDatabase::wxColourDatabase (int type
):
120 wxColourDatabase::~wxColourDatabase (void)
122 // Cleanup Colour allocated in Initialize()
123 wxNode
*node
= First ();
126 wxColour
*col
= (wxColour
*) node
->Data ();
127 wxNode
*next
= node
->Next ();
133 // Colour database stuff
134 void wxColourDatabase::Initialize (void)
136 // Don't initialize for X: colours are found
137 // in FindColour below.
145 static cdef table
[]={
148 {"AQUAMARINE",112, 219, 147},
151 {"BLUE VIOLET", 159, 95, 159},
152 {"BROWN", 165, 42, 42},
153 {"CADET BLUE", 95, 159, 159},
154 {"CORAL", 255, 127, 0},
155 {"CORNFLOWER BLUE", 66, 66, 111},
156 {"CYAN", 0, 255, 255},
157 {"DARK GREY", 47, 47, 47}, // ?
159 {"DARK GREEN", 47, 79, 47},
160 {"DARK OLIVE GREEN", 79, 79, 47},
161 {"DARK ORCHID", 153, 50, 204},
162 {"DARK SLATE BLUE", 107, 35, 142},
163 {"DARK SLATE GREY", 47, 79, 79},
164 {"DARK TURQUOISE", 112, 147, 219},
165 {"DIM GREY", 84, 84, 84},
166 {"FIREBRICK", 142, 35, 35},
167 {"FOREST GREEN", 35, 142, 35},
168 {"GOLD", 204, 127, 50},
169 {"GOLDENROD", 219, 219, 112},
170 {"GREY", 128, 128, 128},
171 {"GREEN", 0, 255, 0},
172 {"GREEN YELLOW", 147, 219, 112},
173 {"INDIAN RED", 79, 47, 47},
174 {"KHAKI", 159, 159, 95},
175 {"LIGHT BLUE", 191, 216, 216},
176 {"LIGHT GREY", 192, 192, 192},
177 {"LIGHT STEEL BLUE", 143, 143, 188},
178 {"LIME GREEN", 50, 204, 50},
179 {"LIGHT MAGENTA", 255, 0, 255},
180 {"MAGENTA", 255, 0, 255},
181 {"MAROON", 142, 35, 107},
182 {"MEDIUM AQUAMARINE", 50, 204, 153},
183 {"MEDIUM GREY", 100, 100, 100},
184 {"MEDIUM BLUE", 50, 50, 204},
185 {"MEDIUM FOREST GREEN", 107, 142, 35},
186 {"MEDIUM GOLDENROD", 234, 234, 173},
187 {"MEDIUM ORCHID", 147, 112, 219},
188 {"MEDIUM SEA GREEN", 66, 111, 66},
189 {"MEDIUM SLATE BLUE", 127, 0, 255},
190 {"MEDIUM SPRING GREEN", 127, 255, 0},
191 {"MEDIUM TURQUOISE", 112, 219, 219},
192 {"MEDIUM VIOLET RED", 219, 112, 147},
193 {"MIDNIGHT BLUE", 47, 47, 79},
194 {"NAVY", 35, 35, 142},
195 {"ORANGE", 204, 50, 50},
196 {"ORANGE RED", 255, 0, 127},
197 {"ORCHID", 219, 112, 219},
198 {"PALE GREEN", 143, 188, 143},
199 {"PINK", 188, 143, 234},
200 {"PLUM", 234, 173, 234},
201 {"PURPLE", 176, 0, 255},
203 {"SALMON", 111, 66, 66},
204 {"SEA GREEN", 35, 142, 107},
205 {"SIENNA", 142, 107, 35},
206 {"SKY BLUE", 50, 153, 204},
207 {"SLATE BLUE", 0, 127, 255},
208 {"SPRING GREEN", 0, 255, 127},
209 {"STEEL BLUE", 35, 107, 142},
210 {"TAN", 219, 147, 112},
211 {"THISTLE", 216, 191, 216},
212 {"TURQUOISE", 173, 234, 234},
213 {"VIOLET", 79, 47, 79},
214 {"VIOLET RED", 204, 50, 153},
215 {"WHEAT", 216, 216, 191},
216 {"WHITE", 255, 255, 255},
217 {"YELLOW", 255, 255, 0},
218 {"YELLOW GREEN", 153, 204, 50},
221 #if defined(__GTK__) || defined(__X__)
222 {"MEDIUM GOLDENROD", 234, 234, 173},
223 {"MEDIUM FOREST GREEN", 107, 142, 35},
224 {"LIGHT MAGENTA", 255, 0, 255},
225 {"MEDIUM GREY", 100, 100, 100},
231 for (i
=0;cc
=table
[i
],cc
.name
!=0;i
++)
233 Append(cc
.name
,new wxColour(cc
.r
,cc
.g
,cc
.b
));
239 * Changed by Ian Brown, July 1994.
241 * When running under X, the Colour Database starts off empty. The X server
242 * is queried for the colour first time after which it is entered into the
243 * database. This allows our client to use the server colour database which
244 * is hopefully gamma corrected for the display being used.
247 wxColour
*wxColourDatabase::FindColour(const wxString
& colour
)
249 wxNode
*node
= Find((char *) (const char *)colour
);
251 return (wxColour
*)node
->Data();
259 wxColour
*col
= new wxColour( colour
);
265 Append( colour
, col
);
275 Display
*display
= XtDisplay(wxTheApp
->topLevel
) ;
278 Xv_Screen screen
= xv_get(xview_server
, SERVER_NTH_SCREEN
, 0);
279 Xv_opaque root_window
= xv_get(screen
, XV_ROOT
);
280 Display
*display
= (Display
*)xv_get(root_window
, XV_DISPLAY
);
283 /* MATTHEW: [4] Use wxGetMainColormap */
284 if (!XParseColor(display
, wxGetMainColormap(display
), colour
,&xcolour
))
287 unsigned char r
= (unsigned char)(xcolour
.red
>> 8);
288 unsigned char g
= (unsigned char)(xcolour
.green
>> 8);
289 unsigned char b
= (unsigned char)(xcolour
.blue
>> 8);
291 wxColour
*col
= new wxColour(r
, g
, b
);
299 wxString
wxColourDatabase::FindName (const wxColour
& colour
) const
301 unsigned char red
= colour
.Red ();
302 unsigned char green
= colour
.Green ();
303 unsigned char blue
= colour
.Blue ();
305 for (wxNode
* node
= First (); node
; node
= node
->Next ())
307 wxColour
*col
= (wxColour
*) node
->Data ();
308 if (col
->Red () == red
&& col
->Green () == green
&& col
->Blue () == blue
)
310 char *found
= node
->key
.string
;
312 return wxString(found
);
315 return wxString(""); // Not Found
320 wxInitializeStockObjects (void)
322 wxTheBrushList
= new wxBrushList
;
323 wxThePenList
= new wxPenList
;
324 wxTheFontList
= new wxFontList
;
325 wxTheBitmapList
= new wxBitmapList
;
330 wxFontPool
= new XFontPool
;
333 wxNORMAL_FONT
= new wxFont (12, wxMODERN
, wxNORMAL
, wxNORMAL
);
334 wxSMALL_FONT
= new wxFont (10, wxSWISS
, wxNORMAL
, wxNORMAL
);
335 wxITALIC_FONT
= new wxFont (12, wxROMAN
, wxITALIC
, wxNORMAL
);
336 wxSWISS_FONT
= new wxFont (12, wxSWISS
, wxNORMAL
, wxNORMAL
);
338 wxRED_PEN
= new wxPen ("RED", 1, wxSOLID
);
339 wxCYAN_PEN
= new wxPen ("CYAN", 1, wxSOLID
);
340 wxGREEN_PEN
= new wxPen ("GREEN", 1, wxSOLID
);
341 wxBLACK_PEN
= new wxPen ("BLACK", 1, wxSOLID
);
342 wxWHITE_PEN
= new wxPen ("WHITE", 1, wxSOLID
);
343 wxTRANSPARENT_PEN
= new wxPen ("BLACK", 1, wxTRANSPARENT
);
344 wxBLACK_DASHED_PEN
= new wxPen ("BLACK", 1, wxSHORT_DASH
);
345 wxGREY_PEN
= new wxPen ("GREY", 1, wxSOLID
);
346 wxMEDIUM_GREY_PEN
= new wxPen ("MEDIUM GREY", 1, wxSOLID
);
347 wxLIGHT_GREY_PEN
= new wxPen ("LIGHT GREY", 1, wxSOLID
);
349 wxBLUE_BRUSH
= new wxBrush ("BLUE", wxSOLID
);
350 wxGREEN_BRUSH
= new wxBrush ("GREEN", wxSOLID
);
351 wxWHITE_BRUSH
= new wxBrush ("WHITE", wxSOLID
);
352 wxBLACK_BRUSH
= new wxBrush ("BLACK", wxSOLID
);
353 wxTRANSPARENT_BRUSH
= new wxBrush ("BLACK", wxTRANSPARENT
);
354 wxCYAN_BRUSH
= new wxBrush ("CYAN", wxSOLID
);
355 wxRED_BRUSH
= new wxBrush ("RED", wxSOLID
);
356 wxGREY_BRUSH
= new wxBrush ("GREY", wxSOLID
);
357 wxMEDIUM_GREY_BRUSH
= new wxBrush ("MEDIUM GREY", wxSOLID
);
358 wxLIGHT_GREY_BRUSH
= new wxBrush ("LIGHT GREY", wxSOLID
);
360 wxBLACK
= new wxColour ("BLACK");
361 wxWHITE
= new wxColour ("WHITE");
362 wxRED
= new wxColour ("RED");
363 wxBLUE
= new wxColour ("BLUE");
364 wxGREEN
= new wxColour ("GREEN");
365 wxCYAN
= new wxColour ("CYAN");
366 wxLIGHT_GREY
= new wxColour ("LIGHT GREY");
368 wxSTANDARD_CURSOR
= new wxCursor (wxCURSOR_ARROW
);
369 wxHOURGLASS_CURSOR
= new wxCursor (wxCURSOR_WAIT
);
370 wxCROSS_CURSOR
= new wxCursor (wxCURSOR_CROSS
);
374 wxDeleteStockObjects (void)
376 DELETEP(wxNORMAL_FONT
);
377 DELETEP(wxSMALL_FONT
);
378 DELETEP(wxITALIC_FONT
);
379 DELETEP(wxSWISS_FONT
);
383 DELETEP(wxGREEN_PEN
);
384 DELETEP(wxBLACK_PEN
);
385 DELETEP(wxWHITE_PEN
);
386 DELETEP(wxTRANSPARENT_PEN
);
387 DELETEP(wxBLACK_DASHED_PEN
);
389 DELETEP(wxMEDIUM_GREY_PEN
);
390 DELETEP(wxLIGHT_GREY_PEN
);
392 DELETEP(wxBLUE_BRUSH
);
393 DELETEP(wxGREEN_BRUSH
);
394 DELETEP(wxWHITE_BRUSH
);
395 DELETEP(wxBLACK_BRUSH
);
396 DELETEP(wxTRANSPARENT_BRUSH
);
397 DELETEP(wxCYAN_BRUSH
);
398 DELETEP(wxRED_BRUSH
);
399 DELETEP(wxGREY_BRUSH
);
400 DELETEP(wxMEDIUM_GREY_BRUSH
);
401 DELETEP(wxLIGHT_GREY_BRUSH
);
409 DELETEP(wxLIGHT_GREY
);
411 DELETEP(wxSTANDARD_CURSOR
);
412 DELETEP(wxHOURGLASS_CURSOR
);
413 DELETEP(wxCROSS_CURSOR
);
416 wxBitmapList::wxBitmapList (void)
420 wxBitmapList::~wxBitmapList (void)
422 wxNode
*node
= First ();
425 wxBitmap
*bitmap
= (wxBitmap
*) node
->Data ();
426 wxNode
*next
= node
->Next ();
428 // bitmap->FreeResource(TRUE);
433 // Pen and Brush lists
434 wxPenList::~wxPenList (void)
436 wxNode
*node
= First ();
439 wxPen
*pen
= (wxPen
*) node
->Data ();
440 wxNode
*next
= node
->Next ();
442 // pen->FreeResource(TRUE);
447 void wxPenList::AddPen (wxPen
* pen
)
452 void wxPenList::RemovePen (wxPen
* pen
)
457 wxPen
*wxPenList::FindOrCreatePen (const wxColour
& colour
, const int width
, const int style
)
459 for (wxNode
* node
= First (); node
; node
= node
->Next ())
461 wxPen
*each_pen
= (wxPen
*) node
->Data ();
462 if (each_pen
&& each_pen
->GetVisible() &&
463 each_pen
->GetWidth () == width
&&
464 each_pen
->GetStyle () == style
&&
465 each_pen
->GetColour ().Red () == colour
.Red () &&
466 each_pen
->GetColour ().Green () == colour
.Green () &&
467 each_pen
->GetColour ().Blue () == colour
.Blue ())
470 wxPen
*pen
= new wxPen (colour
, width
, style
);
472 // Yes, we can return a pointer to this in a later FindOrCreatePen call,
473 // because we created it within FindOrCreatePen. Safeguards against
474 // returning a pointer to an automatic variable and hanging on to it
475 // (dangling pointer).
476 pen
->SetVisible(TRUE
);
480 wxPen
*wxPenList::FindOrCreatePen (const wxString
& colour
, const int width
, const int style
)
482 wxColour
*the_colour
= wxTheColourDatabase
->FindColour (colour
);
484 return FindOrCreatePen (*the_colour
, width
, style
);
489 wxBrushList::~wxBrushList (void)
491 wxNode
*node
= First ();
494 wxBrush
*brush
= (wxBrush
*) node
->Data ();
495 wxNode
*next
= node
->Next ();
501 void wxBrushList::AddBrush (wxBrush
* brush
)
506 wxBrush
*wxBrushList::FindOrCreateBrush (const wxColour
& colour
, const int style
)
508 for (wxNode
* node
= First (); node
; node
= node
->Next ())
510 wxBrush
*each_brush
= (wxBrush
*) node
->Data ();
511 if (each_brush
&& each_brush
->GetVisible() &&
512 each_brush
->GetStyle () == style
&&
513 each_brush
->GetColour ().Red () == colour
.Red () &&
514 each_brush
->GetColour ().Green () == colour
.Green () &&
515 each_brush
->GetColour ().Blue () == colour
.Blue ())
518 // Yes, we can return a pointer to this in a later FindOrCreateBrush call,
519 // because we created it within FindOrCreateBrush. Safeguards against
520 // returning a pointer to an automatic variable and hanging on to it
521 // (dangling pointer).
522 wxBrush
*brush
= new wxBrush (colour
, style
);
523 brush
->SetVisible(TRUE
);
527 wxBrush
*wxBrushList::FindOrCreateBrush (const wxString
& colour
, const int style
)
529 wxColour
*the_colour
= wxTheColourDatabase
->FindColour (colour
);
531 return FindOrCreateBrush (*the_colour
, style
);
536 void wxBrushList::RemoveBrush (wxBrush
* brush
)
538 DeleteObject (brush
);
541 wxFontList::~wxFontList (void)
544 wxNode
*node
= First ();
548 wxFont *font = (wxFont *) node->Data ();
549 wxNode *next = node->Next ();
553 // New for 2.0: don't delete the font (it may be a member
554 // of a wxDC, for example)
555 wxFont
*font
= (wxFont
*) node
->Data ();
556 wxNode
*next
= node
->Next ();
558 // Force the font to be deleted
559 font
->FreeResource(TRUE
);
565 void wxFontList::AddFont (wxFont
* font
)
570 void wxFontList::RemoveFont (wxFont
* font
)
576 FindOrCreateFont (const int PointSize
, const int FamilyOrFontId
, const int Style
, const int Weight
, const bool underline
, const wxString
& Face
)
578 for (wxNode
* node
= First (); node
; node
= node
->Next ())
580 wxFont
*each_font
= (wxFont
*) node
->Data ();
581 if (each_font
&& each_font
->GetVisible() && each_font
->Ok() &&
582 each_font
->GetPointSize () == PointSize
&&
583 each_font
->GetStyle () == Style
&&
584 each_font
->GetWeight () == Weight
&&
585 each_font
->GetUnderlined () == underline
&&
586 #if defined(__X__) || (defined(__WINDOWS__) && USE_PORTABLE_FONTS_IN_MSW)
587 each_font
->GetFontId () == FamilyOrFontId
) /* New font system */
589 each_font
->GetFamily () == FamilyOrFontId
&&
590 (!each_font
->GetFaceName() || each_font
->GetFaceName() == Face
))
594 wxFont
*font
= new wxFont (PointSize
, FamilyOrFontId
, Style
, Weight
, underline
, Face
);
595 font
->SetVisible(TRUE
);
599 void wxBitmapList::AddBitmap(wxBitmap
*bitmap
)
601 void wxBitmapList::RemoveBitmap(wxBitmap
*bitmap
)
602 { DeleteObject(bitmap
); }