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