1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/palmos/dc.h
4 // Author: William Osborne - minimal working wxPalmOS port
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
18 // ---------------------------------------------------------------------------
20 // ---------------------------------------------------------------------------
24 * Cached blitting, maintaining a cache
25 * of bitmaps required for transparent blitting
26 * instead of constant creation/deletion
29 class wxDCCacheEntry
: public wxObject
32 wxDCCacheEntry(WXHBITMAP hBitmap
, int w
, int h
, int depth
);
33 wxDCCacheEntry(WXHDC hDC
, int depth
);
34 virtual ~wxDCCacheEntry();
44 class WXDLLEXPORT wxDC
: public wxDCBase
50 // implement base class pure virtuals
51 // ----------------------------------
55 virtual bool StartDoc(const wxString
& message
);
56 virtual void EndDoc();
58 virtual void StartPage();
59 virtual void EndPage();
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
);
67 virtual void SetPalette(const wxPalette
& palette
);
68 #endif // wxUSE_PALETTE
70 virtual void DestroyClippingRegion();
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 wxFont
*theFont
= NULL
) const;
79 virtual bool DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const;
81 virtual bool CanDrawBitmap() const;
82 virtual bool CanGetTextExtent() const;
83 virtual int GetDepth() const;
84 virtual wxSize
GetPPI() const;
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
);
95 // implementation from now on
96 // --------------------------
98 virtual void SetRop(WXHDC cdc
);
99 virtual void SelectOldObjects(WXHDC dc
);
101 wxWindow
*GetWindow() const { return m_canvas
; }
102 void SetWindow(wxWindow
*win
)
107 // if we have palettes use the correct one for this window
109 #endif // wxUSE_PALETTE
112 WXHDC
GetHDC() const { return m_hDC
; }
113 void SetHDC(WXHDC dc
, bool bOwnsDC
= FALSE
)
118 // we might have a pre existing clipping region, make sure that we
119 // return it if asked -- but avoid calling ::GetClipBox() right now as
120 // it could be unnecessary wasteful
126 const wxBitmap
& GetSelectedBitmap() const { return m_selectedBitmap
; }
127 wxBitmap
& GetSelectedBitmap() { return m_selectedBitmap
; }
129 // update the internal clip box variables
130 void UpdateClipBox();
132 #if wxUSE_DC_CACHEING
133 static wxDCCacheEntry
* FindBitmapInCache(WXHDC hDC
, int w
, int h
);
134 static wxDCCacheEntry
* FindDCInCache(wxDCCacheEntry
* notThis
, WXHDC hDC
);
136 static void AddToBitmapCache(wxDCCacheEntry
* entry
);
137 static void AddToDCCache(wxDCCacheEntry
* entry
);
138 static void ClearCache();
142 virtual bool DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
,
143 int style
= wxFLOOD_SURFACE
);
145 virtual bool DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const;
147 virtual void DoDrawPoint(wxCoord x
, wxCoord y
);
148 virtual void DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
);
150 virtual void DoDrawArc(wxCoord x1
, wxCoord y1
,
151 wxCoord x2
, wxCoord y2
,
152 wxCoord xc
, wxCoord yc
);
153 virtual void DoDrawCheckMark(wxCoord x
, wxCoord y
,
154 wxCoord width
, wxCoord height
);
155 virtual void DoDrawEllipticArc(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
156 double sa
, double ea
);
158 virtual void DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
159 virtual void DoDrawRoundedRectangle(wxCoord x
, wxCoord y
,
160 wxCoord width
, wxCoord height
,
162 virtual void DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
);
164 virtual void DoCrossHair(wxCoord x
, wxCoord y
);
166 virtual void DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
);
167 virtual void DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
,
168 bool useMask
= FALSE
);
170 virtual void DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
);
171 virtual void DoDrawRotatedText(const wxString
& text
, wxCoord x
, wxCoord y
,
174 virtual bool DoBlit(wxCoord xdest
, wxCoord ydest
, wxCoord width
, wxCoord height
,
175 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
176 int rop
= wxCOPY
, bool useMask
= FALSE
, wxCoord xsrcMask
= -1, wxCoord ysrcMask
= -1);
178 // this is gnarly - we can't even call this function DoSetClippingRegion()
179 // because of virtual function hiding
180 virtual void DoSetClippingRegionAsRegion(const wxRegion
& region
);
181 virtual void DoSetClippingRegion(wxCoord x
, wxCoord y
,
182 wxCoord width
, wxCoord height
);
183 virtual void DoGetClippingBox(wxCoord
*x
, wxCoord
*y
,
184 wxCoord
*w
, wxCoord
*h
) const;
186 virtual void DoGetSize(int *width
, int *height
) const;
187 virtual void DoGetSizeMM(int* width
, int* height
) const;
189 virtual void DoDrawLines(int n
, wxPoint points
[],
190 wxCoord xoffset
, wxCoord yoffset
);
191 virtual void DoDrawPolygon(int n
, wxPoint points
[],
192 wxCoord xoffset
, wxCoord yoffset
,
193 int fillStyle
= wxODDEVEN_RULE
);
194 virtual void DoDrawPolyPolygon(int n
, int count
[], wxPoint points
[],
195 wxCoord xoffset
, wxCoord yoffset
,
196 int fillStyle
= wxODDEVEN_RULE
);
200 // MSW specific, select a logical palette into the HDC
201 // (tell windows to translate pixel from other palettes to our custom one
203 // Realize tells it to also reset the system palette to this one.
204 void DoSelectPalette(bool realize
= FALSE
);
206 // Find out what palette our parent window has, then select it into the dc
207 void InitializePalette();
208 #endif // wxUSE_PALETTE
210 // common part of DoDrawText() and DoDrawRotatedText()
211 void DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
);
213 // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
214 void SetClippingHrgn(WXHRGN hrgn
);
216 // MSW-specific member variables
217 // -----------------------------
219 // the window associated with this DC (may be NULL)
222 wxBitmap m_selectedBitmap
;
224 // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it
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
233 WXHBITMAP m_oldBitmap
;
239 WXHPALETTE m_oldPalette
;
240 #endif // wxUSE_PALETTE
242 #if wxUSE_DC_CACHEING
243 static wxList sm_bitmapCache
;
244 static wxList sm_dcCache
;
247 DECLARE_DYNAMIC_CLASS(wxDC
)
248 DECLARE_NO_COPY_CLASS(wxDC
)
251 // ----------------------------------------------------------------------------
252 // wxDCTemp: a wxDC which doesn't free the given HDC (used by wxWidgets
254 // ----------------------------------------------------------------------------
256 class WXDLLEXPORT wxDCTemp
: public wxDC
259 wxDCTemp(WXHDC hdc
) { SetHDC(hdc
); }
260 virtual ~wxDCTemp() { SetHDC((WXHDC
)NULL
); }
263 DECLARE_NO_COPY_CLASS(wxDCTemp
)