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