]> git.saurik.com Git - wxWidgets.git/blob - include/wx/palmos/dc.h
refactor wxGTK mnemonics conversion functions in a separate file to be able to reuse...
[wxWidgets.git] / include / wx / palmos / dc.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/palmos/dc.h
3 // Purpose: wxDC class
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by:
6 // Created: 10/13/04
7 // RCS-ID: $Id$
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DC_H_
13 #define _WX_DC_H_
14
15 #include "wx/defs.h"
16 #include "wx/dc.h"
17
18 // ---------------------------------------------------------------------------
19 // macros
20 // ---------------------------------------------------------------------------
21
22 #if wxUSE_DC_CACHEING
23 /*
24 * Cached blitting, maintaining a cache
25 * of bitmaps required for transparent blitting
26 * instead of constant creation/deletion
27 */
28
29 class wxDCCacheEntry: public wxObject
30 {
31 public:
32 wxDCCacheEntry(WXHBITMAP hBitmap, int w, int h, int depth);
33 wxDCCacheEntry(WXHDC hDC, int depth);
34 virtual ~wxDCCacheEntry();
35
36 WXHBITMAP m_bitmap;
37 WXHDC m_dc;
38 int m_width;
39 int m_height;
40 int m_depth;
41 };
42 #endif
43
44 class WXDLLEXPORT wxDC : public wxDCBase
45 {
46 public:
47 wxDC();
48 virtual ~wxDC();
49
50 // implement base class pure virtuals
51 // ----------------------------------
52
53 virtual void Clear();
54
55 virtual bool StartDoc(const wxString& message);
56 virtual void EndDoc();
57
58 virtual void StartPage();
59 virtual void EndPage();
60
61 virtual void SetFont(const wxFont& font);
62 virtual void SetPen(const wxPen& pen);
63 virtual void SetBrush(const wxBrush& brush);
64 virtual void SetBackground(const wxBrush& brush);
65 virtual void SetBackgroundMode(int mode);
66 #if wxUSE_PALETTE
67 virtual void SetPalette(const wxPalette& palette);
68 #endif // wxUSE_PALETTE
69
70 virtual void DestroyClippingRegion();
71
72 virtual wxCoord GetCharHeight() const;
73 virtual wxCoord GetCharWidth() const;
74 virtual void DoGetTextExtent(const wxString& string,
75 wxCoord *x, wxCoord *y,
76 wxCoord *descent = NULL,
77 wxCoord *externalLeading = NULL,
78 const wxFont *theFont = NULL) const;
79 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
80
81 virtual bool CanDrawBitmap() const;
82 virtual bool CanGetTextExtent() const;
83 virtual int GetDepth() const;
84 virtual wxSize GetPPI() const;
85
86 virtual void SetMapMode(int mode);
87 virtual void SetUserScale(double x, double y);
88 virtual void SetSystemScale(double x, double y);
89 virtual void SetLogicalScale(double x, double y);
90 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
91 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
92 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
93 virtual void SetLogicalFunction(int function);
94
95 virtual wxCoord DeviceToLogicalX(wxCoord x) const;
96 virtual wxCoord DeviceToLogicalY(wxCoord y) const;
97 virtual wxCoord DeviceToLogicalXRel(wxCoord x) const;
98 virtual wxCoord DeviceToLogicalYRel(wxCoord y) const;
99 virtual wxCoord LogicalToDeviceX(wxCoord x) const;
100 virtual wxCoord LogicalToDeviceY(wxCoord y) const;
101 virtual wxCoord LogicalToDeviceXRel(wxCoord x) const;
102 virtual wxCoord LogicalToDeviceYRel(wxCoord y) const ;
103
104 // implementation from now on
105 // --------------------------
106
107 virtual void SetRop(WXHDC cdc);
108 virtual void SelectOldObjects(WXHDC dc);
109
110 wxWindow *GetWindow() const { return m_canvas; }
111 void SetWindow(wxWindow *win)
112 {
113 m_canvas = win;
114
115 #if wxUSE_PALETTE
116 // if we have palettes use the correct one for this window
117 InitializePalette();
118 #endif // wxUSE_PALETTE
119 }
120
121 WXHDC GetHDC() const { return m_hDC; }
122 void SetHDC(WXHDC dc, bool bOwnsDC = FALSE)
123 {
124 m_hDC = dc;
125 m_bOwnsDC = bOwnsDC;
126
127 // we might have a pre existing clipping region, make sure that we
128 // return it if asked -- but avoid calling ::GetClipBox() right now as
129 // it could be unnecessary wasteful
130 m_clipping = true;
131 m_clipX1 =
132 m_clipX2 = 0;
133 }
134
135 const wxBitmap& GetSelectedBitmap() const { return m_selectedBitmap; }
136 wxBitmap& GetSelectedBitmap() { return m_selectedBitmap; }
137
138 // update the internal clip box variables
139 void UpdateClipBox();
140
141 #if wxUSE_DC_CACHEING
142 static wxDCCacheEntry* FindBitmapInCache(WXHDC hDC, int w, int h);
143 static wxDCCacheEntry* FindDCInCache(wxDCCacheEntry* notThis, WXHDC hDC);
144
145 static void AddToBitmapCache(wxDCCacheEntry* entry);
146 static void AddToDCCache(wxDCCacheEntry* entry);
147 static void ClearCache();
148 #endif
149
150 protected:
151 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
152 int style = wxFLOOD_SURFACE);
153
154 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
155
156 virtual void DoDrawPoint(wxCoord x, wxCoord y);
157 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
158
159 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
160 wxCoord x2, wxCoord y2,
161 wxCoord xc, wxCoord yc);
162 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
163 wxCoord width, wxCoord height);
164 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
165 double sa, double ea);
166
167 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
168 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
169 wxCoord width, wxCoord height,
170 double radius);
171 virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
172
173 virtual void DoCrossHair(wxCoord x, wxCoord y);
174
175 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
176 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
177 bool useMask = FALSE);
178
179 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y);
180 virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
181 double angle);
182
183 virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
184 wxDC *source, wxCoord xsrc, wxCoord ysrc,
185 int rop = wxCOPY, bool useMask = FALSE, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1);
186
187 // this is gnarly - we can't even call this function DoSetClippingRegion()
188 // because of virtual function hiding
189 virtual void DoSetClippingRegionAsRegion(const wxRegion& region);
190 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
191 wxCoord width, wxCoord height);
192 virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
193 wxCoord *w, wxCoord *h) const;
194
195 virtual void DoGetSize(int *width, int *height) const;
196 virtual void DoGetSizeMM(int* width, int* height) const;
197
198 virtual void DoDrawLines(int n, wxPoint points[],
199 wxCoord xoffset, wxCoord yoffset);
200 virtual void DoDrawPolygon(int n, wxPoint points[],
201 wxCoord xoffset, wxCoord yoffset,
202 int fillStyle = wxODDEVEN_RULE);
203 virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[],
204 wxCoord xoffset, wxCoord yoffset,
205 int fillStyle = wxODDEVEN_RULE);
206
207
208 #if wxUSE_PALETTE
209 // MSW specific, select a logical palette into the HDC
210 // (tell windows to translate pixel from other palettes to our custom one
211 // and vice versa)
212 // Realize tells it to also reset the system palette to this one.
213 void DoSelectPalette(bool realize = FALSE);
214
215 // Find out what palette our parent window has, then select it into the dc
216 void InitializePalette();
217 #endif // wxUSE_PALETTE
218
219 // common part of DoDrawText() and DoDrawRotatedText()
220 void DrawAnyText(const wxString& text, wxCoord x, wxCoord y);
221
222 // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
223 void SetClippingHrgn(WXHRGN hrgn);
224
225 // MSW-specific member variables
226 // -----------------------------
227
228 // the window associated with this DC (may be NULL)
229 wxWindow *m_canvas;
230
231 wxBitmap m_selectedBitmap;
232
233 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
234 bool m_bOwnsDC:1;
235
236 // our HDC
237 WXHDC m_hDC;
238
239 // Store all old GDI objects when do a SelectObject, so we can select them
240 // back in (this unselecting user's objects) so we can safely delete the
241 // DC.
242 WXHBITMAP m_oldBitmap;
243 WXHPEN m_oldPen;
244 WXHBRUSH m_oldBrush;
245 WXHFONT m_oldFont;
246
247 #if wxUSE_PALETTE
248 WXHPALETTE m_oldPalette;
249 #endif // wxUSE_PALETTE
250
251 #if wxUSE_DC_CACHEING
252 static wxList sm_bitmapCache;
253 static wxList sm_dcCache;
254 #endif
255
256 DECLARE_DYNAMIC_CLASS(wxDC)
257 DECLARE_NO_COPY_CLASS(wxDC)
258 };
259
260 // ----------------------------------------------------------------------------
261 // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets
262 // only/mainly)
263 // ----------------------------------------------------------------------------
264
265 class WXDLLEXPORT wxDCTemp : public wxDC
266 {
267 public:
268 wxDCTemp(WXHDC hdc) { SetHDC(hdc); }
269 virtual ~wxDCTemp() { SetHDC((WXHDC)NULL); }
270
271 private:
272 DECLARE_NO_COPY_CLASS(wxDCTemp)
273 };
274
275 #endif
276 // _WX_DC_H_