]>
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 #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 // common part of DoSetClippingRegion() and DoSetClippingRegionAsRegion()
201 void wxPalmDCImpl::SetClippingHrgn(WXHRGN hrgn
)
203 wxCHECK_RET( hrgn
, wxT("invalid clipping region") );
206 void wxPalmDCImpl::DoSetClippingRegion(wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
)
210 void wxPalmDCImpl::DoSetClippingRegionAsRegion(const wxRegion
& region
)
214 void wxPalmDCImpl::DestroyClippingRegion()
218 // ---------------------------------------------------------------------------
219 // query capabilities
220 // ---------------------------------------------------------------------------
222 bool wxPalmDCImpl::CanDrawBitmap() const
227 bool wxPalmDCImpl::CanGetTextExtent() const
232 int wxPalmDCImpl::GetDepth() const
237 // ---------------------------------------------------------------------------
239 // ---------------------------------------------------------------------------
241 void wxPalmDCImpl::Clear()
245 bool wxPalmDCImpl::DoFloodFill(wxCoord
WXUNUSED_IN_WINCE(x
),
246 wxCoord
WXUNUSED_IN_WINCE(y
),
247 const wxColour
& WXUNUSED_IN_WINCE(col
),
248 int WXUNUSED_IN_WINCE(style
))
253 bool wxPalmDCImpl::DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
258 void wxPalmDCImpl::DoCrossHair(wxCoord x
, wxCoord y
)
262 void wxPalmDCImpl::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
266 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
267 // and ending at (x2, y2)
268 void wxPalmDCImpl::DoDrawArc(wxCoord x1
, wxCoord y1
,
269 wxCoord x2
, wxCoord y2
,
270 wxCoord xc
, wxCoord yc
)
274 void wxPalmDCImpl::DoDrawCheckMark(wxCoord x1
, wxCoord y1
,
275 wxCoord width
, wxCoord height
)
279 void wxPalmDCImpl::DoDrawPoint(wxCoord x
, wxCoord y
)
283 void wxPalmDCImpl::DoDrawPolygon(int n
,
287 int WXUNUSED_IN_WINCE(fillStyle
))
292 wxPalmDCImpl::DoDrawPolyPolygon(int n
,
301 void wxPalmDCImpl::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
305 void wxPalmDCImpl::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
309 void wxPalmDCImpl::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
313 void wxPalmDCImpl::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
318 void wxPalmDCImpl::DoDrawSpline(const wxPointList
*points
)
323 // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows
324 void wxPalmDCImpl::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
328 void wxPalmDCImpl::DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
332 void wxPalmDCImpl::DoDrawBitmap( const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
336 void wxPalmDCImpl::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
340 void wxPalmDCImpl::DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
)
344 void wxPalmDCImpl::DoDrawRotatedText(const wxString
& text
,
345 wxCoord x
, wxCoord y
,
350 // ---------------------------------------------------------------------------
352 // ---------------------------------------------------------------------------
356 void wxPalmDCImpl::DoSelectPalette(bool realize
)
360 void wxPalmDCImpl::SetPalette(const wxPalette
& palette
)
364 void wxPalmDCImpl::InitializePalette()
368 #endif // wxUSE_PALETTE
370 // SetFont/Pen/Brush() really ask to be implemented as a single template
371 // function... but doing it is not worth breaking OpenWatcom build <sigh>
373 void wxPalmDCImpl::SetFont(const wxFont
& font
)
377 void wxPalmDCImpl::SetPen(const wxPen
& pen
)
381 void wxPalmDCImpl::SetBrush(const wxBrush
& brush
)
385 void wxPalmDCImpl::SetBackground(const wxBrush
& brush
)
389 void wxPalmDCImpl::SetBackgroundMode(int mode
)
393 void wxPalmDCImpl::SetLogicalFunction(int function
)
397 void wxPalmDCImpl::SetRop(WXHDC dc
)
401 bool wxPalmDCImpl::StartDoc(const wxString
& WXUNUSED(message
))
403 // We might be previewing, so return true to let it continue.
407 void wxPalmDCImpl::EndDoc()
411 void wxPalmDCImpl::StartPage()
415 void wxPalmDCImpl::EndPage()
419 // ---------------------------------------------------------------------------
421 // ---------------------------------------------------------------------------
423 wxCoord
wxPalmDCImpl::GetCharHeight() const
428 wxCoord
wxPalmDCImpl::GetCharWidth() const
433 void wxPalmDCImpl::DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
434 wxCoord
*descent
, wxCoord
*externalLeading
,
435 const wxFont
*font
) const
440 // Each element of the array will be the width of the string up to and
441 // including the coresoponding character in text.
443 bool wxPalmDCImpl::DoGetPartialTextExtents(const wxString
& text
, wxArrayInt
& widths
) const
448 void wxPalmDCImpl::RealizeScaleAndOrigin()
452 void wxPalmDCImpl::SetMapMode(int mode
)
456 void wxPalmDCImpl::SetUserScale(double x
, double y
)
460 void wxPalmDCImpl::SetAxisOrientation(bool xLeftRight
,
465 void wxPalmDCImpl::SetLogicalOrigin(wxCoord x
, wxCoord y
)
469 void wxPalmDCImpl::SetDeviceOrigin(wxCoord x
, wxCoord y
)
473 // ---------------------------------------------------------------------------
475 // ---------------------------------------------------------------------------
477 bool wxPalmDCImpl::DoBlit(wxCoord dstX
, wxCoord dstY
,
478 wxCoord dstWidth
, wxCoord dstHeight
,
480 wxCoord srcX
, wxCoord srcY
,
481 int rop
, bool useMask
,
482 wxCoord srcMaskX
, wxCoord srcMaskY
)
487 bool wxPalmDCImpl::DoStretchBlit(wxCoord xdest
, wxCoord ydest
,
488 wxCoord dstWidth
, wxCoord dstHeight
,
490 wxCoord xsrc
, wxCoord ysrc
,
491 wxCoord srcWidth
, wxCoord srcHeight
,
492 int rop
, bool useMask
,
493 wxCoord xsrcMask
, wxCoord ysrcMask
)
498 void wxPalmDCImpl::GetDeviceSize(int *width
, int *height
) const
502 void wxPalmDCImpl::DoGetSizeMM(int *w
, int *h
) const
506 wxSize
wxPalmDCImpl::GetPPI() const
511 // For use by wxWidgets only, unless custom units are required.
512 void wxPalmDCImpl::SetLogicalScale(double x
, double y
)
516 // ----------------------------------------------------------------------------
518 // ----------------------------------------------------------------------------
520 #if wxUSE_DC_CACHEING
523 * This implementation is a bit ugly and uses the old-fashioned wxList class, so I will
524 * improve it in due course, either using arrays, or simply storing pointers to one
525 * entry for the bitmap, and two for the DCs. -- JACS
528 wxObjectList
wxPalmDCImpl::sm_bitmapCache
;
529 wxObjectList
wxPalmDCImpl::sm_dcCache
;
531 wxDCCacheEntry::wxDCCacheEntry(WXHBITMAP hBitmap
, int w
, int h
, int depth
)
540 wxDCCacheEntry::wxDCCacheEntry(WXHDC hDC
, int depth
)
544 wxDCCacheEntry::~wxDCCacheEntry()
548 wxDCCacheEntry
* wxPalmDCImpl::FindBitmapInCache(WXHDC dc
, int w
, int h
)
553 wxDCCacheEntry
* wxPalmDCImpl::FindDCInCache(wxDCCacheEntry
* notThis
, WXHDC dc
)
558 void wxPalmDCImpl::AddToBitmapCache(wxDCCacheEntry
* entry
)
562 void wxPalmDCImpl::AddToDCCache(wxDCCacheEntry
* entry
)
566 void wxPalmDCImpl::ClearCache()
570 // Clean up cache at app exit
571 class wxDCModule
: public wxModule
574 virtual bool OnInit() { return true; }
575 virtual void OnExit() { wxPalmDCImpl::ClearCache(); }
578 DECLARE_DYNAMIC_CLASS(wxDCModule
)
581 IMPLEMENT_DYNAMIC_CLASS(wxDCModule
, wxModule
)
583 #endif // wxUSE_DC_CACHEING
585 void wxPalmDCImpl::DoGradientFillLinear (const wxRect
& rect
,
586 const wxColour
& initialColour
,
587 const wxColour
& destColour
,
588 wxDirection nDirection
)
592 #if wxUSE_DYNLIB_CLASS
594 wxLayoutDirection
wxPalmDCImpl::GetLayoutDirection() const
596 DWORD layout
= wxGetDCLayout(GetHdc());
598 if ( layout
== (DWORD
)-1 )
599 return wxLayout_Default
;
601 return layout
& LAYOUT_RTL
? wxLayout_RightToLeft
: wxLayout_LeftToRight
;
604 void wxPalmDCImpl::SetLayoutDirection(wxLayoutDirection dir
)
608 #else // !wxUSE_DYNLIB_CLASS
610 // we can't provide RTL support without dynamic loading, so stub it out
611 wxLayoutDirection
wxPalmDCImpl::GetLayoutDirection() const
613 return wxLayout_Default
;
616 void wxPalmDCImpl::SetLayoutDirection(wxLayoutDirection
WXUNUSED(dir
))
620 #endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS