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 #include "wx/palmos/dc.h"
50 #define AC_SRC_ALPHA 1
57 /* Quaternary raster codes */
59 #define MAKEROP4(fore,back) (DWORD)((((back) << 8) & 0xFF000000) | (fore))
62 // apparently with MicroWindows it is possible that HDC is 0 so we have to
63 // check for this ourselves
65 #define WXMICROWIN_CHECK_HDC if ( !GetHDC() ) return;
66 #define WXMICROWIN_CHECK_HDC_RET(x) if ( !GetHDC() ) return x;
68 #define WXMICROWIN_CHECK_HDC
69 #define WXMICROWIN_CHECK_HDC_RET(x)
72 IMPLEMENT_ABSTRACT_CLASS(wxPalmDCImpl
, wxDCImpl
)
74 // ---------------------------------------------------------------------------
76 // ---------------------------------------------------------------------------
78 // ROPs which don't have standard names (see "Ternary Raster Operations" in the
79 // MSDN docs for how this and other numbers in wxDC::Blit() are obtained)
80 #define DSTCOPY 0x00AA0029 // a.k.a. NOP operation
82 // ----------------------------------------------------------------------------
83 // macros for logical <-> device coords conversion
84 // ----------------------------------------------------------------------------
87 We currently let Windows do all the translations itself so these macros are
88 not really needed (any more) but keep them to enhance readability of the
89 code by allowing to see where are the logical and where are the device
94 #define XLOG2DEV(x) ((x-m_logicalOriginX)*m_signX)
95 #define YLOG2DEV(y) ((y-m_logicalOriginY)*m_signY)
96 #define XDEV2LOG(x) ((x)*m_signX+m_logicalOriginX)
97 #define YDEV2LOG(y) ((y)*m_signY+m_logicalOriginY)
99 #define XLOG2DEV(x) (x)
100 #define YLOG2DEV(y) (y)
101 #define XDEV2LOG(x) (x)
102 #define YDEV2LOG(y) (y)
105 // ---------------------------------------------------------------------------
107 // ---------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 // ----------------------------------------------------------------------------
113 #if wxUSE_DYNLIB_CLASS
115 // helper class to cache dynamically loaded libraries and not attempt reloading
117 class wxOnceOnlyDLLLoader
120 // ctor argument must be a literal string as we don't make a copy of it!
121 wxOnceOnlyDLLLoader(const wxChar
*dllName
)
127 // return the symbol with the given name or NULL if the DLL not loaded
128 // or symbol not present
129 void *GetSymbol(const wxChar
*name
)
131 // we're prepared to handle errors here
136 m_dll
.Load(m_dllName
);
138 // reset the name whether we succeeded or failed so that we don't
139 // try again the next time
143 return m_dll
.IsLoaded() ? m_dll
.GetSymbol(name
) : NULL
;
148 if ( m_dll
.IsLoaded() )
155 wxDynamicLibrary m_dll
;
156 const wxChar
*m_dllName
;
159 #endif // wxUSE_DYNLIB_CLASS
161 // ===========================================================================
163 // ===========================================================================
165 // ---------------------------------------------------------------------------
167 // ---------------------------------------------------------------------------
169 wxPalmDCImpl::wxPalmDCImpl( wxDC
*owner
, WXHDC hDC
) :
176 wxPalmDCImpl::~wxPalmDCImpl()
180 // This will select current objects out of the DC,
181 // which is what you have to do before deleting the
183 void wxPalmDCImpl::SelectOldObjects(WXHDC dc
)
187 // ---------------------------------------------------------------------------
189 // ---------------------------------------------------------------------------
191 void wxPalmDCImpl::UpdateClipBox()
196 wxPalmDCImpl::DoGetClippingBox(wxCoord
*x
, wxCoord
*y
, wxCoord
*w
, wxCoord
*h
) const
200 void wxPalmDCImpl::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
204 void wxPalmDCImpl::DoSetDeviceClippingRegion(const wxRegion
& region
)
208 void wxPalmDCImpl::DestroyClippingRegion()
212 // ---------------------------------------------------------------------------
213 // query capabilities
214 // ---------------------------------------------------------------------------
216 bool wxPalmDCImpl::CanDrawBitmap() const
221 bool wxPalmDCImpl::CanGetTextExtent() const
226 int wxPalmDCImpl::GetDepth() const
231 // ---------------------------------------------------------------------------
233 // ---------------------------------------------------------------------------
235 void wxPalmDCImpl::Clear()
239 bool wxPalmDCImpl::DoFloodFill(wxCoord
WXUNUSED_IN_WINCE(x
),
240 wxCoord
WXUNUSED_IN_WINCE(y
),
241 const wxColour
& WXUNUSED_IN_WINCE(col
),
242 wxFloodFillStyle
WXUNUSED_IN_WINCE(style
))
247 bool wxPalmDCImpl::DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
252 void wxPalmDCImpl::DoCrossHair(wxCoord x
, wxCoord y
)
256 void wxPalmDCImpl::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
260 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
261 // and ending at (x2, y2)
262 void wxPalmDCImpl::DoDrawArc(wxCoord x1
, wxCoord y1
,
263 wxCoord x2
, wxCoord y2
,
264 wxCoord xc
, wxCoord yc
)
268 void wxPalmDCImpl::DoDrawCheckMark(wxCoord x1
, wxCoord y1
,
269 wxCoord width
, wxCoord height
)
273 void wxPalmDCImpl::DoDrawPoint(wxCoord x
, wxCoord y
)
277 void wxPalmDCImpl::DoDrawPolygon(int n
,
281 wxPolygonFillMode
WXUNUSED_IN_WINCE(fillStyle
))
286 wxPalmDCImpl::DoDrawPolyPolygon(int n
,
291 wxPolygonFillMode fillStyle
)
295 void wxPalmDCImpl::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
299 void wxPalmDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
303 void wxPalmDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
307 void wxPalmDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
312 void wxPalmDCImpl::DoDrawSpline(const wxPointList
*points
)
317 // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
318 void wxPalmDCImpl::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
322 void wxPalmDCImpl::DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
326 void wxPalmDCImpl::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
330 void wxPalmDCImpl::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
334 void wxPalmDCImpl::DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
)
338 void wxPalmDCImpl::DoDrawRotatedText(const wxString
& text
,
339 wxCoord x
, wxCoord y
,
344 // ---------------------------------------------------------------------------
346 // ---------------------------------------------------------------------------
350 void wxPalmDCImpl::DoSelectPalette(bool realize
)
354 void wxPalmDCImpl::SetPalette(const wxPalette
& palette
)
358 void wxPalmDCImpl::InitializePalette()
362 #endif // wxUSE_PALETTE
364 // SetFont/Pen/Brush() really ask to be implemented as a single template
365 // function... but doing it is not worth breaking OpenWatcom build <sigh>
367 void wxPalmDCImpl::SetFont(const wxFont
& font
)
371 void wxPalmDCImpl::SetPen(const wxPen
& pen
)
375 void wxPalmDCImpl::SetBrush(const wxBrush
& brush
)
379 void wxPalmDCImpl::SetBackground(const wxBrush
& brush
)
383 void wxPalmDCImpl::SetBackgroundMode(int mode
)
387 void wxPalmDCImpl::SetLogicalFunction(wxRasterOperationMode function
)
391 void wxPalmDCImpl::SetRop(WXHDC dc
)
395 bool wxPalmDCImpl::StartDoc(const wxString
& WXUNUSED(message
))
397 // We might be previewing, so return true to let it continue.
401 void wxPalmDCImpl::EndDoc()
405 void wxPalmDCImpl::StartPage()
409 void wxPalmDCImpl::EndPage()
413 // ---------------------------------------------------------------------------
415 // ---------------------------------------------------------------------------
417 wxCoord
wxPalmDCImpl::GetCharHeight() const
422 wxCoord
wxPalmDCImpl::GetCharWidth() const
427 void wxPalmDCImpl::DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
428 wxCoord
*descent
, wxCoord
*externalLeading
,
429 const wxFont
*font
) const
434 // Each element of the array will be the width of the string up to and
435 // including the coresoponding character in text.
437 bool wxPalmDCImpl::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
442 void wxPalmDCImpl::RealizeScaleAndOrigin()
446 void wxPalmDCImpl::SetMapMode(wxMappingMode mode
)
450 void wxPalmDCImpl::SetUserScale(double x
, double y
)
454 void wxPalmDCImpl::SetAxisOrientation(bool xLeftRight
,
459 void wxPalmDCImpl::SetLogicalOrigin(wxCoord x
, wxCoord y
)
463 void wxPalmDCImpl::SetDeviceOrigin(wxCoord x
, wxCoord y
)
467 // ---------------------------------------------------------------------------
469 // ---------------------------------------------------------------------------
471 bool wxPalmDCImpl::DoBlit(wxCoord dstX
, wxCoord dstY
,
472 wxCoord dstWidth
, wxCoord dstHeight
,
474 wxCoord srcX
, wxCoord srcY
,
475 wxRasterOperationMode rop
, bool useMask
,
476 wxCoord srcMaskX
, wxCoord srcMaskY
)
481 bool wxPalmDCImpl::DoStretchBlit(wxCoord xdest
, wxCoord ydest
,
482 wxCoord dstWidth
, wxCoord dstHeight
,
484 wxCoord xsrc
, wxCoord ysrc
,
485 wxCoord srcWidth
, wxCoord srcHeight
,
486 wxRasterOperationMode rop
, bool useMask
,
487 wxCoord xsrcMask
, wxCoord ysrcMask
)
492 void wxPalmDCImpl::GetDeviceSize(int *width
, int *height
) const
496 void wxPalmDCImpl::DoGetSizeMM(int *w
, int *h
) const
500 wxSize
wxPalmDCImpl::GetPPI() const
505 // For use by wxWidgets only, unless custom units are required.
506 void wxPalmDCImpl::SetLogicalScale(double x
, double y
)
510 // ----------------------------------------------------------------------------
512 // ----------------------------------------------------------------------------
514 #if wxUSE_DC_CACHEING
517 * This implementation is a bit ugly and uses the old-fashioned wxList class, so I will
518 * improve it in due course, either using arrays, or simply storing pointers to one
519 * entry for the bitmap, and two for the DCs. -- JACS
522 wxObjectList
wxPalmDCImpl::sm_bitmapCache
;
523 wxObjectList
wxPalmDCImpl::sm_dcCache
;
525 wxDCCacheEntry::wxDCCacheEntry(WXHBITMAP hBitmap
, int w
, int h
, int depth
)
534 wxDCCacheEntry::wxDCCacheEntry(WXHDC hDC
, int depth
)
538 wxDCCacheEntry::~wxDCCacheEntry()
542 wxDCCacheEntry
* wxPalmDCImpl::FindBitmapInCache(WXHDC dc
, int w
, int h
)
547 wxDCCacheEntry
* wxPalmDCImpl::FindDCInCache(wxDCCacheEntry
* notThis
, WXHDC dc
)
552 void wxPalmDCImpl::AddToBitmapCache(wxDCCacheEntry
* entry
)
556 void wxPalmDCImpl::AddToDCCache(wxDCCacheEntry
* entry
)
560 void wxPalmDCImpl::ClearCache()
564 // Clean up cache at app exit
565 class wxDCModule
: public wxModule
568 virtual bool OnInit() { return true; }
569 virtual void OnExit() { wxPalmDCImpl::ClearCache(); }
572 DECLARE_DYNAMIC_CLASS(wxDCModule
)
575 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
577 #endif // wxUSE_DC_CACHEING
579 void wxPalmDCImpl::DoGradientFillLinear (const wxRect
& rect
,
580 const wxColour
& initialColour
,
581 const wxColour
& destColour
,
582 wxDirection nDirection
)
586 #if wxUSE_DYNLIB_CLASS
588 wxLayoutDirection
wxPalmDCImpl::GetLayoutDirection() const
590 DWORD layout
= wxGetDCLayout(GetHdc());
592 if ( layout
== (DWORD
)-1 )
593 return wxLayout_Default
;
595 return layout
& LAYOUT_RTL
? wxLayout_RightToLeft
: wxLayout_LeftToRight
;
598 void wxPalmDCImpl::SetLayoutDirection(wxLayoutDirection dir
)
602 #else // !wxUSE_DYNLIB_CLASS
604 // we can't provide RTL support without dynamic loading, so stub it out
605 wxLayoutDirection
wxPalmDCImpl::GetLayoutDirection() const
607 return wxLayout_Default
;
610 void wxPalmDCImpl::SetLayoutDirection(wxLayoutDirection
WXUNUSED(dir
))
614 #endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS