]>
git.saurik.com Git - wxWidgets.git/blob - src/palmos/dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/dc.cpp
4 // Author: William Osborne - minimal working wxPalmOS port
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
22 // For compilers that support precompilation, includes "wx.h".
23 #include "wx/wxprec.h"
31 #include "wx/window.h"
34 #include "wx/dialog.h"
36 #include "wx/bitmap.h"
37 #include "wx/dcmemory.h"
40 #include "wx/dcprint.h"
41 #include "wx/module.h"
44 #include "wx/sysopt.h"
45 #include "wx/dynlib.h"
47 #ifdef wxHAVE_RAW_BITMAP
48 #include "wx/rawbmp.h"
51 #include "wx/palmos/dc.h"
54 #define AC_SRC_ALPHA 1
61 /* Quaternary raster codes */
63 #define MAKEROP4(fore,back) (DWORD)((((back) << 8) & 0xFF000000) | (fore))
66 // apparently with MicroWindows it is possible that HDC is 0 so we have to
67 // check for this ourselves
69 #define WXMICROWIN_CHECK_HDC if ( !GetHDC() ) return;
70 #define WXMICROWIN_CHECK_HDC_RET(x) if ( !GetHDC() ) return x;
72 #define WXMICROWIN_CHECK_HDC
73 #define WXMICROWIN_CHECK_HDC_RET(x)
76 IMPLEMENT_ABSTRACT_CLASS(wxPalmDCImpl
, wxDCImpl
)
78 // ---------------------------------------------------------------------------
80 // ---------------------------------------------------------------------------
82 // ROPs which don't have standard names (see "Ternary Raster Operations" in the
83 // MSDN docs for how this and other numbers in wxDC::Blit() are obtained)
84 #define DSTCOPY 0x00AA0029 // a.k.a. NOP operation
86 // ----------------------------------------------------------------------------
87 // macros for logical <-> device coords conversion
88 // ----------------------------------------------------------------------------
91 We currently let Windows do all the translations itself so these macros are
92 not really needed (any more) but keep them to enhance readability of the
93 code by allowing to see where are the logical and where are the device
98 #define XLOG2DEV(x) ((x-m_logicalOriginX)*m_signX)
99 #define YLOG2DEV(y) ((y-m_logicalOriginY)*m_signY)
100 #define XDEV2LOG(x) ((x)*m_signX+m_logicalOriginX)
101 #define YDEV2LOG(y) ((y)*m_signY+m_logicalOriginY)
103 #define XLOG2DEV(x) (x)
104 #define YLOG2DEV(y) (y)
105 #define XDEV2LOG(x) (x)
106 #define YDEV2LOG(y) (y)
109 // ---------------------------------------------------------------------------
111 // ---------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 #if wxUSE_DYNLIB_CLASS
119 // helper class to cache dynamically loaded libraries and not attempt reloading
121 class wxOnceOnlyDLLLoader
124 // ctor argument must be a literal string as we don't make a copy of it!
125 wxOnceOnlyDLLLoader(const wxChar
*dllName
)
131 // return the symbol with the given name or NULL if the DLL not loaded
132 // or symbol not present
133 void *GetSymbol(const wxChar
*name
)
135 // we're prepared to handle errors here
140 m_dll
.Load(m_dllName
);
142 // reset the name whether we succeeded or failed so that we don't
143 // try again the next time
147 return m_dll
.IsLoaded() ? m_dll
.GetSymbol(name
) : NULL
;
152 if ( m_dll
.IsLoaded() )
159 wxDynamicLibrary m_dll
;
160 const wxChar
*m_dllName
;
163 #endif // wxUSE_DYNLIB_CLASS
165 // ===========================================================================
167 // ===========================================================================
169 // ---------------------------------------------------------------------------
171 // ---------------------------------------------------------------------------
173 wxPalmDCImpl::wxPalmDCImpl( wxDC
*owner
, WXHDC hDC
) :
180 wxPalmDCImpl::~wxPalmDCImpl()
184 // This will select current objects out of the DC,
185 // which is what you have to do before deleting the
187 void wxPalmDCImpl::SelectOldObjects(WXHDC dc
)
191 // ---------------------------------------------------------------------------
193 // ---------------------------------------------------------------------------
195 void wxPalmDCImpl::UpdateClipBox()
200 wxPalmDCImpl::DoGetClippingBox(wxCoord
*x
, wxCoord
*y
, wxCoord
*w
, wxCoord
*h
) const
204 // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
205 void wxPalmDCImpl::SetClippingHrgn(WXHRGN hrgn
)
207 wxCHECK_RET( hrgn
, wxT("invalid clipping region") );
210 void wxPalmDCImpl::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
214 void wxPalmDCImpl::DoSetClippingRegionAsRegion(const wxRegion
& region
)
218 void wxPalmDCImpl::DestroyClippingRegion()
222 // ---------------------------------------------------------------------------
223 // query capabilities
224 // ---------------------------------------------------------------------------
226 bool wxPalmDCImpl::CanDrawBitmap() const
231 bool wxPalmDCImpl::CanGetTextExtent() const
236 int wxPalmDCImpl::GetDepth() const
241 // ---------------------------------------------------------------------------
243 // ---------------------------------------------------------------------------
245 void wxPalmDCImpl::Clear()
249 bool wxPalmDCImpl::DoFloodFill(wxCoord
WXUNUSED_IN_WINCE(x
),
250 wxCoord
WXUNUSED_IN_WINCE(y
),
251 const wxColour
& WXUNUSED_IN_WINCE(col
),
252 int WXUNUSED_IN_WINCE(style
))
257 bool wxPalmDCImpl::DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
262 void wxPalmDCImpl::DoCrossHair(wxCoord x
, wxCoord y
)
266 void wxPalmDCImpl::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
270 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
271 // and ending at (x2, y2)
272 void wxPalmDCImpl::DoDrawArc(wxCoord x1
, wxCoord y1
,
273 wxCoord x2
, wxCoord y2
,
274 wxCoord xc
, wxCoord yc
)
278 void wxPalmDCImpl::DoDrawCheckMark(wxCoord x1
, wxCoord y1
,
279 wxCoord width
, wxCoord height
)
283 void wxPalmDCImpl::DoDrawPoint(wxCoord x
, wxCoord y
)
287 void wxPalmDCImpl::DoDrawPolygon(int n
,
291 int WXUNUSED_IN_WINCE(fillStyle
))
296 wxPalmDCImpl::DoDrawPolyPolygon(int n
,
305 void wxPalmDCImpl::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
309 void wxPalmDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
313 void wxPalmDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
317 void wxPalmDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
322 void wxPalmDCImpl::DoDrawSpline(const wxPointList
*points
)
327 // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
328 void wxPalmDCImpl::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
332 void wxPalmDCImpl::DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
336 void wxPalmDCImpl::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
340 void wxPalmDCImpl::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
344 void wxPalmDCImpl::DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
)
348 void wxPalmDCImpl::DoDrawRotatedText(const wxString
& text
,
349 wxCoord x
, wxCoord y
,
354 // ---------------------------------------------------------------------------
356 // ---------------------------------------------------------------------------
360 void wxPalmDCImpl::DoSelectPalette(bool realize
)
364 void wxPalmDCImpl::SetPalette(const wxPalette
& palette
)
368 void wxPalmDCImpl::InitializePalette()
372 #endif // wxUSE_PALETTE
374 // SetFont/Pen/Brush() really ask to be implemented as a single template
375 // function... but doing it is not worth breaking OpenWatcom build <sigh>
377 void wxPalmDCImpl::SetFont(const wxFont
& font
)
381 void wxPalmDCImpl::SetPen(const wxPen
& pen
)
385 void wxPalmDCImpl::SetBrush(const wxBrush
& brush
)
389 void wxPalmDCImpl::SetBackground(const wxBrush
& brush
)
393 void wxPalmDCImpl::SetBackgroundMode(int mode
)
397 void wxPalmDCImpl::SetLogicalFunction(int function
)
401 void wxPalmDCImpl::SetRop(WXHDC dc
)
405 bool wxPalmDCImpl::StartDoc(const wxString
& WXUNUSED(message
))
407 // We might be previewing, so return true to let it continue.
411 void wxPalmDCImpl::EndDoc()
415 void wxPalmDCImpl::StartPage()
419 void wxPalmDCImpl::EndPage()
423 // ---------------------------------------------------------------------------
425 // ---------------------------------------------------------------------------
427 wxCoord
wxPalmDCImpl::GetCharHeight() const
432 wxCoord
wxPalmDCImpl::GetCharWidth() const
437 void wxPalmDCImpl::DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
438 wxCoord
*descent
, wxCoord
*externalLeading
,
439 const wxFont
*font
) const
444 // Each element of the array will be the width of the string up to and
445 // including the coresoponding character in text.
447 bool wxPalmDCImpl::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
452 void wxPalmDCImpl::RealizeScaleAndOrigin()
456 void wxPalmDCImpl::SetMapMode(int mode
)
460 void wxPalmDCImpl::SetUserScale(double x
, double y
)
464 void wxPalmDCImpl::SetAxisOrientation(bool xLeftRight
,
469 void wxPalmDCImpl::SetLogicalOrigin(wxCoord x
, wxCoord y
)
473 void wxPalmDCImpl::SetDeviceOrigin(wxCoord x
, wxCoord y
)
477 // ---------------------------------------------------------------------------
479 // ---------------------------------------------------------------------------
481 bool wxPalmDCImpl::DoBlit(wxCoord dstX
, wxCoord dstY
,
482 wxCoord dstWidth
, wxCoord dstHeight
,
484 wxCoord srcX
, wxCoord srcY
,
485 int rop
, bool useMask
,
486 wxCoord srcMaskX
, wxCoord srcMaskY
)
491 bool wxPalmDCImpl::DoStretchBlit(wxCoord xdest
, wxCoord ydest
,
492 wxCoord dstWidth
, wxCoord dstHeight
,
494 wxCoord xsrc
, wxCoord ysrc
,
495 wxCoord srcWidth
, wxCoord srcHeight
,
496 int rop
, bool useMask
,
497 wxCoord xsrcMask
, wxCoord ysrcMask
)
502 void wxPalmDCImpl::GetDeviceSize(int *width
, int *height
) const
506 void wxPalmDCImpl::DoGetSizeMM(int *w
, int *h
) const
510 wxSize
wxPalmDCImpl::GetPPI() const
515 // For use by wxWidgets only, unless custom units are required.
516 void wxPalmDCImpl::SetLogicalScale(double x
, double y
)
520 // ----------------------------------------------------------------------------
522 // ----------------------------------------------------------------------------
524 #if wxUSE_DC_CACHEING
527 * This implementation is a bit ugly and uses the old-fashioned wxList class, so I will
528 * improve it in due course, either using arrays, or simply storing pointers to one
529 * entry for the bitmap, and two for the DCs. -- JACS
532 wxObjectList
wxPalmDCImpl::sm_bitmapCache
;
533 wxObjectList
wxPalmDCImpl::sm_dcCache
;
535 wxDCCacheEntry::wxDCCacheEntry(WXHBITMAP hBitmap
, int w
, int h
, int depth
)
544 wxDCCacheEntry::wxDCCacheEntry(WXHDC hDC
, int depth
)
548 wxDCCacheEntry::~wxDCCacheEntry()
552 wxDCCacheEntry
* wxPalmDCImpl::FindBitmapInCache(WXHDC dc
, int w
, int h
)
557 wxDCCacheEntry
* wxPalmDCImpl::FindDCInCache(wxDCCacheEntry
* notThis
, WXHDC dc
)
562 void wxPalmDCImpl::AddToBitmapCache(wxDCCacheEntry
* entry
)
566 void wxPalmDCImpl::AddToDCCache(wxDCCacheEntry
* entry
)
570 void wxPalmDCImpl::ClearCache()
574 // Clean up cache at app exit
575 class wxDCModule
: public wxModule
578 virtual bool OnInit() { return true; }
579 virtual void OnExit() { wxPalmDCImpl::ClearCache(); }
582 DECLARE_DYNAMIC_CLASS(wxDCModule
)
585 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
587 #endif // wxUSE_DC_CACHEING
589 void wxPalmDCImpl::DoGradientFillLinear (const wxRect
& rect
,
590 const wxColour
& initialColour
,
591 const wxColour
& destColour
,
592 wxDirection nDirection
)
596 #if wxUSE_DYNLIB_CLASS
598 wxLayoutDirection
wxPalmDCImpl::GetLayoutDirection() const
600 DWORD layout
= wxGetDCLayout(GetHdc());
602 if ( layout
== (DWORD
)-1 )
603 return wxLayout_Default
;
605 return layout
& LAYOUT_RTL
? wxLayout_RightToLeft
: wxLayout_LeftToRight
;
608 void wxPalmDCImpl::SetLayoutDirection(wxLayoutDirection dir
)
612 #else // !wxUSE_DYNLIB_CLASS
614 // we can't provide RTL support without dynamic loading, so stub it out
615 wxLayoutDirection
wxPalmDCImpl::GetLayoutDirection() const
617 return wxLayout_Default
;
620 void wxPalmDCImpl::SetLayoutDirection(wxLayoutDirection
WXUNUSED(dir
))
624 #endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS