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