]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/dc.h
Fixed typo.
[wxWidgets.git] / include / wx / msw / dc.h
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
ad0ac642 2// Name: wx/msw/dc.h
2bda0e17
KB
3// Purpose: wxDC class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
bbcdf8bc 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
7d09b97f
VZ
12#ifndef _WX_MSW_DC_H_
13#define _WX_MSW_DC_H_
2bda0e17 14
2662e49e 15#include "wx/defs.h"
888dde65 16#include "wx/dc.h"
2662e49e 17
e6f1ad22
HH
18// ---------------------------------------------------------------------------
19// macros
20// ---------------------------------------------------------------------------
21
0cbff120
JS
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
29class wxDCCacheEntry: public wxObject
30{
31public:
32 wxDCCacheEntry(WXHBITMAP hBitmap, int w, int h, int depth);
33 wxDCCacheEntry(WXHDC hDC, int depth);
d3c7fc99 34 virtual ~wxDCCacheEntry();
0cbff120
JS
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
7d09b97f
VZ
44// this is an ABC: use one of the derived classes to create a DC associated
45// with a window, screen, printer and so on
53a2db12 46class WXDLLIMPEXP_CORE wxMSWDCImpl: public wxDCImpl
2bda0e17 47{
2bda0e17 48public:
888dde65
RR
49 wxMSWDCImpl(wxDC *owner, WXHDC hDC);
50 virtual ~wxMSWDCImpl();
a23fd0e1
VZ
51
52 // implement base class pure virtuals
53 // ----------------------------------
54
55 virtual void Clear();
56
57 virtual bool StartDoc(const wxString& message);
58 virtual void EndDoc();
59
60 virtual void StartPage();
61 virtual void EndPage();
62
63 virtual void SetFont(const wxFont& font);
64 virtual void SetPen(const wxPen& pen);
65 virtual void SetBrush(const wxBrush& brush);
66 virtual void SetBackground(const wxBrush& brush);
67 virtual void SetBackgroundMode(int mode);
d275c7eb 68#if wxUSE_PALETTE
a23fd0e1 69 virtual void SetPalette(const wxPalette& palette);
d275c7eb 70#endif // wxUSE_PALETTE
a23fd0e1
VZ
71
72 virtual void DestroyClippingRegion();
73
72cdf4c9
VZ
74 virtual wxCoord GetCharHeight() const;
75 virtual wxCoord GetCharWidth() const;
a23fd0e1
VZ
76
77 virtual bool CanDrawBitmap() const;
78 virtual bool CanGetTextExtent() const;
79 virtual int GetDepth() const;
80 virtual wxSize GetPPI() const;
81
621b83d9 82
89efaf2b 83 virtual void SetMapMode(wxMappingMode mode);
a23fd0e1 84 virtual void SetUserScale(double x, double y);
a23fd0e1 85 virtual void SetLogicalScale(double x, double y);
72cdf4c9
VZ
86 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
87 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
a23fd0e1 88 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
f0875501 89
89efaf2b 90 virtual void SetLogicalFunction(wxRasterOperationMode function);
a23fd0e1
VZ
91
92 // implementation from now on
93 // --------------------------
94
95 virtual void SetRop(WXHDC cdc);
a23fd0e1
VZ
96 virtual void SelectOldObjects(WXHDC dc);
97
b95edd47
VZ
98 void SetWindow(wxWindow *win)
99 {
888dde65 100 m_window = win;
b95edd47 101
574c939e
KB
102#if wxUSE_PALETTE
103 // if we have palettes use the correct one for this window
104 InitializePalette();
b95edd47
VZ
105#endif // wxUSE_PALETTE
106 }
a23fd0e1
VZ
107
108 WXHDC GetHDC() const { return m_hDC; }
d71cc120 109 void SetHDC(WXHDC dc, bool bOwnsDC = false)
a23fd0e1
VZ
110 {
111 m_hDC = dc;
112 m_bOwnsDC = bOwnsDC;
2e76da54
VZ
113
114 // we might have a pre existing clipping region, make sure that we
115 // return it if asked -- but avoid calling ::GetClipBox() right now as
116 // it could be unnecessary wasteful
117 m_clipping = true;
118 m_clipX1 =
119 m_clipX2 = 0;
a23fd0e1 120 }
2bda0e17 121
4b7f2165
VZ
122 const wxBitmap& GetSelectedBitmap() const { return m_selectedBitmap; }
123 wxBitmap& GetSelectedBitmap() { return m_selectedBitmap; }
124
1e6feb95
VZ
125 // update the internal clip box variables
126 void UpdateClipBox();
127
0cbff120
JS
128#if wxUSE_DC_CACHEING
129 static wxDCCacheEntry* FindBitmapInCache(WXHDC hDC, int w, int h);
130 static wxDCCacheEntry* FindDCInCache(wxDCCacheEntry* notThis, WXHDC hDC);
131
132 static void AddToBitmapCache(wxDCCacheEntry* entry);
133 static void AddToDCCache(wxDCCacheEntry* entry);
134 static void ClearCache();
135#endif
136
6ae7410f
VZ
137 // RTL related functions
138 // ---------------------
139
140 // get or change the layout direction (LTR or RTL) for this dc,
141 // wxLayout_Default is returned if layout direction is not supported
142 virtual wxLayoutDirection GetLayoutDirection() const;
143 virtual void SetLayoutDirection(wxLayoutDirection dir);
144
a23fd0e1 145protected:
7d09b97f
VZ
146 void Init()
147 {
7d09b97f
VZ
148 m_bOwnsDC = false;
149 m_hDC = NULL;
150
151 m_oldBitmap = NULL;
152 m_oldPen = NULL;
153 m_oldBrush = NULL;
154 m_oldFont = NULL;
155
156#if wxUSE_PALETTE
157 m_oldPalette = NULL;
158#endif // wxUSE_PALETTE
159 }
160
161 // create an uninitialized DC: this should be only used by the derived
162 // classes
888dde65 163 wxMSWDCImpl( wxDC *owner ) : wxDCImpl( owner ) { Init(); }
7d09b97f 164
04ab8b6d
RR
165 void RealizeScaleAndOrigin();
166
512cfcc3 167public:
e29bf4b0
VZ
168 virtual void DoGetFontMetrics(int *height,
169 int *ascent,
170 int *descent,
171 int *internalLeading,
172 int *externalLeading,
173 int *averageWidth) const;
6f02a879
VZ
174 virtual void DoGetTextExtent(const wxString& string,
175 wxCoord *x, wxCoord *y,
176 wxCoord *descent = NULL,
177 wxCoord *externalLeading = NULL,
c94f845b 178 const wxFont *theFont = NULL) const;
6f02a879
VZ
179 virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
180
387ebd3e 181 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
89efaf2b 182 wxFloodFillStyle style = wxFLOOD_SURFACE);
a23fd0e1 183
213ad8e7
VZ
184 virtual void DoGradientFillLinear(const wxRect& rect,
185 const wxColour& initialColour,
186 const wxColour& destColour,
187 wxDirection nDirection = wxEAST);
188
72cdf4c9 189 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
a23fd0e1 190
72cdf4c9
VZ
191 virtual void DoDrawPoint(wxCoord x, wxCoord y);
192 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
a23fd0e1 193
72cdf4c9
VZ
194 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
195 wxCoord x2, wxCoord y2,
196 wxCoord xc, wxCoord yc);
cd9da200
VZ
197 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
198 wxCoord width, wxCoord height);
72cdf4c9 199 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
a23fd0e1
VZ
200 double sa, double ea);
201
72cdf4c9
VZ
202 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
203 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
204 wxCoord width, wxCoord height,
a23fd0e1 205 double radius);
72cdf4c9 206 virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
a23fd0e1 207
3e9db38e 208#if wxUSE_SPLINES && !defined(__WXWINCE__)
b0d7707b 209 virtual void DoDrawSpline(const wxPointList *points);
ad0ac642
WS
210#endif
211
72cdf4c9 212 virtual void DoCrossHair(wxCoord x, wxCoord y);
a23fd0e1 213
72cdf4c9
VZ
214 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
215 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
d71cc120 216 bool useMask = false);
a23fd0e1 217
72cdf4c9 218 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y);
95724b1a
VZ
219 virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
220 double angle);
a23fd0e1 221
72cdf4c9
VZ
222 virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
223 wxDC *source, wxCoord xsrc, wxCoord ysrc,
03647350 224 wxRasterOperationMode rop = wxCOPY, bool useMask = false,
89efaf2b 225 wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
a23fd0e1 226
e3b81044
VZ
227 virtual bool DoStretchBlit(wxCoord xdest, wxCoord ydest,
228 wxCoord dstWidth, wxCoord dstHeight,
229 wxDC *source,
230 wxCoord xsrc, wxCoord ysrc,
231 wxCoord srcWidth, wxCoord srcHeight,
89efaf2b 232 wxRasterOperationMode rop = wxCOPY, bool useMask = false,
e3b81044
VZ
233 wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
234
72cdf4c9
VZ
235 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
236 wxCoord width, wxCoord height);
fdaad94e 237 virtual void DoSetDeviceClippingRegion(const wxRegion& region);
2e76da54
VZ
238 virtual void DoGetClippingBox(wxCoord *x, wxCoord *y,
239 wxCoord *w, wxCoord *h) const;
a23fd0e1 240
a23fd0e1
VZ
241 virtual void DoGetSizeMM(int* width, int* height) const;
242
243 virtual void DoDrawLines(int n, wxPoint points[],
72cdf4c9 244 wxCoord xoffset, wxCoord yoffset);
a23fd0e1 245 virtual void DoDrawPolygon(int n, wxPoint points[],
72cdf4c9 246 wxCoord xoffset, wxCoord yoffset,
89efaf2b 247 wxPolygonFillMode fillStyle = wxODDEVEN_RULE);
793db755 248 virtual void DoDrawPolyPolygon(int n, int count[], wxPoint points[],
6e76b35d 249 wxCoord xoffset, wxCoord yoffset,
89efaf2b 250 wxPolygonFillMode fillStyle = wxODDEVEN_RULE);
f0875501
VZ
251 virtual wxBitmap DoGetAsBitmap(const wxRect *subrect) const
252 {
253 return subrect == NULL ? GetSelectedBitmap()
254 : GetSelectedBitmap().GetSubBitmap(*subrect);
255 }
6a6c0a8b 256
a23fd0e1 257
574c939e
KB
258#if wxUSE_PALETTE
259 // MSW specific, select a logical palette into the HDC
260 // (tell windows to translate pixel from other palettes to our custom one
261 // and vice versa)
262 // Realize tells it to also reset the system palette to this one.
d71cc120 263 void DoSelectPalette(bool realize = false);
b95edd47 264
574c939e
KB
265 // Find out what palette our parent window has, then select it into the dc
266 void InitializePalette();
b95edd47
VZ
267#endif // wxUSE_PALETTE
268
512cfcc3 269protected:
4314ec48
VZ
270 // common part of DoDrawText() and DoDrawRotatedText()
271 void DrawAnyText(const wxString& text, wxCoord x, wxCoord y);
272
fdaad94e 273 // common part of DoSetClippingRegion() and DoSetDeviceClippingRegion()
5230934a
VZ
274 void SetClippingHrgn(WXHRGN hrgn);
275
7d09b97f
VZ
276 // implementation of DoGetSize() for wxScreen/PrinterDC: this simply
277 // returns the size of the entire device this DC is associated with
278 //
279 // notice that we intentionally put it in a separate function instead of
280 // DoGetSize() itself because we want it to remain pure virtual both
281 // because each derived class should take care to define it as needed (this
282 // implementation is not at all always appropriate) and because we want
283 // wxDC to be an ABC to prevent it from being created directly
284 void GetDeviceSize(int *width, int *height) const;
285
286
a23fd0e1 287 // MSW-specific member variables
1e2081a1 288 // -----------------------------
a23fd0e1
VZ
289
290 // the window associated with this DC (may be NULL)
291 wxWindow *m_canvas;
292
293 wxBitmap m_selectedBitmap;
294
295 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
296 bool m_bOwnsDC:1;
297
b5badcb5 298 // our HDC
a23fd0e1 299 WXHDC m_hDC;
a23fd0e1
VZ
300
301 // Store all old GDI objects when do a SelectObject, so we can select them
302 // back in (this unselecting user's objects) so we can safely delete the
303 // DC.
304 WXHBITMAP m_oldBitmap;
305 WXHPEN m_oldPen;
306 WXHBRUSH m_oldBrush;
307 WXHFONT m_oldFont;
d275c7eb
VZ
308
309#if wxUSE_PALETTE
a23fd0e1 310 WXHPALETTE m_oldPalette;
d275c7eb 311#endif // wxUSE_PALETTE
7561aacd 312
0cbff120 313#if wxUSE_DC_CACHEING
888dde65
RR
314 static wxObjectList sm_bitmapCache;
315 static wxObjectList sm_dcCache;
0cbff120
JS
316#endif
317
888dde65 318 DECLARE_CLASS(wxMSWDCImpl)
c0c133e1 319 wxDECLARE_NO_COPY_CLASS(wxMSWDCImpl);
7561aacd
VZ
320};
321
322// ----------------------------------------------------------------------------
77ffb593 323// wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets
7561aacd
VZ
324// only/mainly)
325// ----------------------------------------------------------------------------
326
53a2db12 327class WXDLLIMPEXP_CORE wxDCTempImpl : public wxMSWDCImpl
7561aacd
VZ
328{
329public:
e0e6ac8a
VZ
330 // construct a temporary DC with the specified HDC and size (it should be
331 // specified whenever we know it for this HDC)
888dde65
RR
332 wxDCTempImpl(wxDC *owner, WXHDC hdc, const wxSize& size )
333 : wxMSWDCImpl( owner, hdc ),
e0e6ac8a 334 m_size(size)
7d09b97f
VZ
335 {
336 }
337
888dde65 338 virtual ~wxDCTempImpl()
7d09b97f
VZ
339 {
340 // prevent base class dtor from freeing it
341 SetHDC((WXHDC)NULL);
342 }
343
344 virtual void DoGetSize(int *w, int *h) const
345 {
e0e6ac8a 346 wxASSERT_MSG( m_size.IsFullySpecified(),
9a83f860 347 wxT("size of this DC hadn't been set and is unknown") );
7d09b97f
VZ
348
349 if ( w )
e0e6ac8a 350 *w = m_size.x;
7d09b97f 351 if ( h )
e0e6ac8a 352 *h = m_size.y;
7d09b97f 353 }
fc7a2a60
VZ
354
355private:
e0e6ac8a
VZ
356 // size of this DC must be explicitly set by SetSize() as we have no way to
357 // find it ourselves
358 const wxSize m_size;
359
c0c133e1 360 wxDECLARE_NO_COPY_CLASS(wxDCTempImpl);
2bda0e17
KB
361};
362
53a2db12 363class WXDLLIMPEXP_CORE wxDCTemp : public wxDC
888dde65
RR
364{
365public:
f0875501
VZ
366 wxDCTemp(WXHDC hdc, const wxSize& size = wxDefaultSize)
367 : wxDC(new wxDCTempImpl(this, hdc, size))
888dde65 368 {
888dde65 369 }
888dde65
RR
370};
371
7d09b97f
VZ
372#endif // _WX_MSW_DC_H_
373