]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/dc.cpp
don't use negative windows sizes
[wxWidgets.git] / src / dfb / dc.cpp
CommitLineData
b3c86150
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/dfb/dc.cpp
3// Purpose: wxDC class
4// Author: Vaclav Slavik
5// Created: 2006-08-07
6// RCS-ID: $Id$
7// Copyright: (c) 2006 REA Elektronik GmbH
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// ===========================================================================
12// declarations
13// ===========================================================================
14
15// ---------------------------------------------------------------------------
16// headers
17// ---------------------------------------------------------------------------
18
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#ifndef WX_PRECOMP
27 #include "wx/dc.h"
28 #include "wx/log.h"
29#endif
30
31#include "wx/dfb/private.h"
32
33// ===========================================================================
34// implementation
35// ===========================================================================
36
37//-----------------------------------------------------------------------------
38// wxDC
39//-----------------------------------------------------------------------------
40
41IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase)
42
43// Default constructor
44wxDC::wxDC()
45{
46 m_ok = false;
47}
48
52c8d32a 49wxDC::wxDC(const wxIDirectFBSurfacePtr& surface)
b3c86150
VS
50{
51 Init(surface);
52}
53
52c8d32a 54void wxDC::Init(const wxIDirectFBSurfacePtr& surface)
b3c86150
VS
55{
56 m_ok = (surface != NULL);
57 wxCHECK_RET( surface != NULL, _T("invalid surface") );
58
59 m_surface = surface;
60
61 m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() /
62 (double)wxGetDisplaySizeMM().GetWidth();
63 m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() /
64 (double)wxGetDisplaySizeMM().GetHeight();
65
66 SetFont(*wxNORMAL_FONT);
67 SetPen(*wxBLACK_PEN);
68 SetBrush(*wxWHITE_BRUSH);
69}
70
71
72// ---------------------------------------------------------------------------
73// clipping
74// ---------------------------------------------------------------------------
75
76
77#define DO_SET_CLIPPING_BOX(rg) \
78{ \
79 wxRect rect = rg.GetBox(); \
80 m_clipX1 = (wxCoord) XDEV2LOG(rect.GetLeft()); \
81 m_clipY1 = (wxCoord) YDEV2LOG(rect.GetTop()); \
82 m_clipX2 = (wxCoord) XDEV2LOG(rect.GetRight()); \
83 m_clipY2 = (wxCoord) YDEV2LOG(rect.GetBottom()); \
84}
85
86void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch)
87{
88 wxCHECK_RET( Ok(), wxT("invalid dc") );
89
90 DFBRegion r;
91 r.x1 = XLOG2DEV(cx);
92 r.y1 = YLOG2DEV(cy);
93 r.x2 = r.x1 + XLOG2DEVREL(cw) - 1;
94 r.y2 = r.y1 + XLOG2DEVREL(ch) - 1;
95
52c8d32a 96 if ( !m_surface->SetClip(&r) )
b3c86150
VS
97 return;
98
99 m_clipX1 = cx;
100 m_clipY1 = cy;
101 m_clipX2 = cx + cw - 1;
102 m_clipY2 = cy + ch -1;
103 m_clipping = true;
104}
105
106void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region)
107{
108 // NB: this can be done because wxDFB only supports
109 // rectangular regions
110 SetClippingRegion(region.AsRect());
111}
112
113void wxDC::DestroyClippingRegion()
114{
115 wxCHECK_RET( Ok(), wxT("invalid dc") );
116
52c8d32a 117 m_surface->SetClip(NULL);
b3c86150
VS
118
119 ResetClipping();
120}
121
122// ---------------------------------------------------------------------------
123// query capabilities
124// ---------------------------------------------------------------------------
125
126int wxDC::GetDepth() const
127{
128 return wxDfbGetSurfaceDepth(m_surface);
129}
130
131// ---------------------------------------------------------------------------
132// drawing
133// ---------------------------------------------------------------------------
134
135void wxDC::Clear()
136{
137 wxCHECK_RET( Ok(), wxT("invalid dc") );
138
139 if ( m_backgroundBrush.GetStyle() == wxTRANSPARENT )
140 return;
141
142 wxColour clr = m_backgroundBrush.GetColour();
52c8d32a 143 m_surface->Clear(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha());
b3c86150
VS
144}
145
146extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
147 const wxColour & col, int style);
148
149bool wxDC::DoFloodFill(wxCoord x, wxCoord y,
150 const wxColour& col, int style)
151{
152 return wxDoFloodFill(this, x, y, col, style);
153}
154
155bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
156{
157 wxCHECK_MSG( col, false, _T("NULL colour parameter in wxDC::GetPixel"));
158
159 wxFAIL_MSG( _T("GetPixel not implemented") );
160 return false;
161}
162
163void wxDC::DoCrossHair(wxCoord x, wxCoord y)
164{
165 wxCHECK_RET( Ok(), wxT("invalid dc") );
166
167 wxFAIL_MSG( _T("CrossHair not implemented") );
168}
169
170void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
171{
172 wxCHECK_RET( Ok(), wxT("invalid dc") );
173
174 if ( m_pen.GetStyle() == wxTRANSPARENT )
175 return;
176
52c8d32a
VS
177 m_surface->DrawLine(XLOG2DEV(x1), YLOG2DEV(y1),
178 XLOG2DEV(x2), YLOG2DEV(y2));
b3c86150
VS
179
180 CalcBoundingBox(x1, y1);
181 CalcBoundingBox(x2, y2);
182}
183
184// Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
185// and ending at (x2, y2)
186void wxDC::DoDrawArc(wxCoord x1, wxCoord y1,
187 wxCoord x2, wxCoord y2,
188 wxCoord xc, wxCoord yc)
189{
190 wxCHECK_RET( Ok(), wxT("invalid dc") );
191
192 wxFAIL_MSG( _T("DrawArc not implemented") );
193}
194
195void wxDC::DoDrawPoint(wxCoord x, wxCoord y)
196{
197 wxCHECK_RET( Ok(), wxT("invalid dc") );
198
199 wxFAIL_MSG( _T("DrawPoint not implemented") );
200}
201
202void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int WXUNUSED(fillStyle))
203{
204 wxCHECK_RET( Ok(), wxT("invalid dc") );
205
206 wxFAIL_MSG( _T("DrawPolygon not implemented") );
207}
208
209void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
210{
211 wxCHECK_RET( Ok(), wxT("invalid dc") );
212
213 // TODO: impl. using DirectDB's DrawLines
214 wxFAIL_MSG( _T("DrawLines not implemented") );
215}
216
217void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
218{
219 wxCHECK_RET( Ok(), wxT("invalid dc") );
220
221 wxCoord xx = XLOG2DEV(x);
222 wxCoord yy = YLOG2DEV(y);
223 wxCoord ww = m_signX * XLOG2DEVREL(width);
224 wxCoord hh = m_signY * YLOG2DEVREL(height);
225
226 if ( ww == 0 || hh == 0 ) return;
227
228 if ( ww < 0 )
229 {
230 ww = -ww;
231 xx = xx - ww;
232 }
233 if ( hh < 0 )
234 {
235 hh = -hh;
236 yy = yy - hh;
237 }
238
239 if ( m_brush.GetStyle() != wxTRANSPARENT )
240 {
241 SelectColour(m_brush.GetColour());
52c8d32a 242 m_surface->FillRectangle(xx, yy, ww, hh);
b3c86150
VS
243 // restore pen's colour
244 SelectColour(m_pen.GetColour());
245 }
246
247 if ( m_pen.GetStyle() != wxTRANSPARENT )
248 {
52c8d32a 249 m_surface->DrawRectangle(xx, yy, ww, hh);
b3c86150
VS
250 }
251
252 CalcBoundingBox(x, y);
253 CalcBoundingBox(x + width, y + height);
254}
255
256void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
257{
258 wxCHECK_RET( Ok(), wxT("invalid dc") );
259
260 wxFAIL_MSG( _T("DrawRoundedRectangle not implemented") );
261}
262
263void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
264{
265 wxCHECK_RET( Ok(), wxT("invalid dc") );
266
267 wxFAIL_MSG( _T("DrawElipse not implemented") );
268}
269
270void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
271{
272 wxCHECK_RET( Ok(), wxT("invalid dc") );
273
274 wxFAIL_MSG( _T("DrawElipticArc not implemented") );
275}
276
277void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
278{
279 wxCHECK_RET( Ok(), wxT("invalid dc") );
280
281 wxCoord xx = XLOG2DEV(x);
282 wxCoord yy = XLOG2DEV(y);
283
284 // update the bounding box
285 wxCoord w, h;
286 CalcBoundingBox(x, y);
287 GetTextExtent(text, &w, &h);
288 CalcBoundingBox(x + w, y + h);
289
290 // if background mode is solid, DrawText must paint text's background:
291 if ( m_backgroundMode == wxSOLID )
292 {
293 wxCHECK_RET( m_backgroundBrush.Ok(), wxT("invalid background brush") );
294
295 SelectColour(m_backgroundBrush.GetColour());
52c8d32a 296 m_surface->FillRectangle(xx, yy, XLOG2DEVREL(w), YLOG2DEVREL(h));
b3c86150
VS
297 // restore pen's colour
298 SelectColour(m_pen.GetColour());
299 }
300
301 // finally draw the text itself:
52c8d32a 302 m_surface->DrawString(wxSTR_TO_DFB(text), -1, xx, yy, DSTF_LEFT | DSTF_TOP);
b3c86150
VS
303}
304
305void wxDC::DoDrawRotatedText(const wxString& text,
306 wxCoord x, wxCoord y,
307 double angle)
308{
309 wxCHECK_RET( Ok(), wxT("invalid dc") );
310
311 wxFAIL_MSG( _T("DrawRotatedText not implemented") );
312}
313
314// ---------------------------------------------------------------------------
315// set GDI objects
316// ---------------------------------------------------------------------------
317
318void wxDC::SetPen(const wxPen& pen)
319{
320 if ( !pen.Ok() ) return;
321 m_pen = pen;
322
323 SelectColour(m_pen.GetColour());
324}
325
326void wxDC::SetBrush(const wxBrush& brush)
327{
328 if ( !brush.Ok() ) return;
329 m_brush = brush;
330}
331
332void wxDC::SelectColour(const wxColour& clr)
333{
52c8d32a 334 m_surface->SetColor(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha());
b3c86150
VS
335 #warning "use SetColorIndex?"
336}
337
338#if wxUSE_PALETTE
339void wxDC::SetPalette(const wxPalette& WXUNUSED(palette))
340{
341 wxCHECK_RET( Ok(), wxT("invalid dc") );
342
343 wxFAIL_MSG( _T("SetPalette not implemented") );
344}
345#endif // wxUSE_PALETTE
346
347void wxDC::SetFont(const wxFont& font)
348{
349 wxCHECK_RET( Ok(), wxT("invalid dc") );
350
351 if ( !font.Ok() )
352 return;
353
52c8d32a 354 if ( !m_surface->SetFont(font.GetDirectFBFont()) )
b3c86150
VS
355 return;
356
357 m_font = font;
358}
359
360void wxDC::SetBackground(const wxBrush& brush)
361{
362 wxCHECK_RET( Ok(), wxT("invalid dc") );
363
364 if (!brush.Ok()) return;
365
366 m_backgroundBrush = brush;
367}
368
369void wxDC::SetBackgroundMode(int mode)
370{
371 m_backgroundMode = mode;
372}
373
374void wxDC::SetLogicalFunction(int function)
375{
376 wxCHECK_RET( Ok(), wxT("invalid dc") );
377
378 wxFAIL_MSG( _T("SetLogicalFunction not implemented") );
379
380 m_logicalFunction = function;
381}
382
383bool wxDC::StartDoc(const wxString& WXUNUSED(message))
384{
385 // We might be previewing, so return true to let it continue.
386 return true;
387}
388
389void wxDC::EndDoc()
390{
391}
392
393void wxDC::StartPage()
394{
395}
396
397void wxDC::EndPage()
398{
399}
400
401// ---------------------------------------------------------------------------
402// text metrics
403// ---------------------------------------------------------------------------
404
405wxCoord wxDC::GetCharHeight() const
406{
407 wxCHECK_MSG( Ok(), -1, wxT("invalid dc") );
408 wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") );
409
410 int h = -1;
52c8d32a 411 m_font.GetDirectFBFont()->GetHeight(&h);
b3c86150
VS
412 return YDEV2LOGREL(h);
413}
414
415wxCoord wxDC::GetCharWidth() const
416{
417 wxCHECK_MSG( Ok(), -1, wxT("invalid dc") );
418 wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") );
419
420 int w = -1;
52c8d32a 421 m_font.GetDirectFBFont()->GetStringWidth("H", 1, &w);
b3c86150
VS
422 // VS: YDEV is corrent, it should *not* be XDEV, because font's are only
423 // scaled according to m_scaleY
424 return YDEV2LOGREL(w);
425}
426
427void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
428 wxCoord *descent, wxCoord *externalLeading,
429 wxFont *theFont) const
430{
431 wxCHECK_RET( Ok(), wxT("invalid dc") );
432 wxCHECK_RET( m_font.Ok(), wxT("no font selected") );
433 wxCHECK_RET( !theFont || theFont->Ok(), wxT("invalid font") );
434
435 wxFont oldFont;
436 if ( theFont != NULL )
437 {
438 oldFont = m_font;
439 wxConstCast(this, wxDC)->SetFont(*theFont);
440 }
441
442 wxCoord xx = 0, yy = 0;
443 DFBRectangle rect;
52c8d32a 444 wxIDirectFBFontPtr f = m_font.GetDirectFBFont();
b3c86150 445
52c8d32a 446 if ( f->GetStringExtents(wxSTR_TO_DFB(string), -1, &rect, NULL) )
b3c86150
VS
447 {
448 // VS: YDEV is corrent, it should *not* be XDEV, because font's are
449 // only scaled according to m_scaleY
450 xx = YDEV2LOGREL(rect.w);
451 yy = YDEV2LOGREL(rect.h);
452
453 if ( descent )
454 {
455 int d;
52c8d32a 456 if ( f->GetDescender(&d) )
b3c86150
VS
457 *descent = YDEV2LOGREL(-d);
458 else
459 *descent = 0;
460 }
461 }
462
463 if ( x ) *x = xx;
464 if ( y ) *y = yy;
465 if ( externalLeading ) *externalLeading = 0;
466
467 if ( theFont != NULL )
468 wxConstCast(this, wxDC)->SetFont(oldFont);
469}
470
471
472
473// ---------------------------------------------------------------------------
474// mapping modes
475// ---------------------------------------------------------------------------
476
477void wxDC::ComputeScaleAndOrigin()
478{
479 m_scaleX = m_logicalScaleX * m_userScaleX;
480 m_scaleY = m_logicalScaleY * m_userScaleY;
481
482 // FIXME_DFB: scaling affects pixel size of font, pens, brushes, which
483 // is not currently implemented here; probably makes sense to
484 // switch to Cairo instead of implementing everything for DFB
485 wxASSERT_MSG( m_scaleX == 1.0 && m_scaleY == 1.0,
486 _T("scaling is not implemented in wxDFB") );
487}
488
489void wxDC::SetMapMode(int mode)
490{
491 #warning "move this to common code, it's shared by almost all ports!"
492 switch (mode)
493 {
494 case wxMM_TWIPS:
495 SetLogicalScale(twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y);
496 break;
497 case wxMM_POINTS:
498 SetLogicalScale(pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y);
499 break;
500 case wxMM_METRIC:
501 SetLogicalScale(m_mm_to_pix_x, m_mm_to_pix_y);
502 break;
503 case wxMM_LOMETRIC:
504 SetLogicalScale(m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0);
505 break;
506 default:
507 case wxMM_TEXT:
508 SetLogicalScale(1.0, 1.0);
509 break;
510 }
511 m_mappingMode = mode;
512}
513
514void wxDC::SetUserScale(double x, double y)
515{
516 #warning "move this to common code?"
517 // allow negative ? -> no
518 m_userScaleX = x;
519 m_userScaleY = y;
520 ComputeScaleAndOrigin();
521}
522
523void wxDC::SetLogicalScale(double x, double y)
524{
525 #warning "move this to common code?"
526 // allow negative ?
527 m_logicalScaleX = x;
528 m_logicalScaleY = y;
529 ComputeScaleAndOrigin();
530}
531
532void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
533{
534 #warning "move this to common code?"
535 m_logicalOriginX = x * m_signX; // is this still correct ?
536 m_logicalOriginY = y * m_signY;
537 ComputeScaleAndOrigin();
538}
539
540void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
541{
542 #warning "move this to common code?"
543 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
544 m_deviceOriginX = x;
545 m_deviceOriginY = y;
546 ComputeScaleAndOrigin();
547}
548
549void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
550{
551 #warning "move this to common code?"
552 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
553 m_signX = (xLeftRight ? 1 : -1);
554 m_signY = (yBottomUp ? -1 : 1);
555 ComputeScaleAndOrigin();
556}
557
558// ---------------------------------------------------------------------------
559// coordinates transformations
560// ---------------------------------------------------------------------------
561
562wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
563{
564 return ((wxDC *)this)->XDEV2LOG(x);
565}
566
567wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
568{
569 return ((wxDC *)this)->YDEV2LOG(y);
570}
571
572wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
573{
574 return ((wxDC *)this)->XDEV2LOGREL(x);
575}
576
577wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
578{
579 return ((wxDC *)this)->YDEV2LOGREL(y);
580}
581
582wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
583{
584 return ((wxDC *)this)->XLOG2DEV(x);
585}
586
587wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
588{
589 return ((wxDC *)this)->YLOG2DEV(y);
590}
591
592wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
593{
594 return ((wxDC *)this)->XLOG2DEVREL(x);
595}
596
597wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
598{
599 return ((wxDC *)this)->YLOG2DEVREL(y);
600}
601
602
603void wxDC::DoGetSize(int *w, int *h) const
604{
605 wxCHECK_RET( Ok(), wxT("invalid dc") );
606
52c8d32a 607 m_surface->GetSize(w, h);
b3c86150
VS
608}
609
610void wxDC::DoGetSizeMM(int *width, int *height) const
611{
612 #warning "move this to common code?"
613 int w = 0;
614 int h = 0;
615 GetSize(&w, &h);
616 if ( width ) *width = int(double(w) / (m_userScaleX*m_mm_to_pix_x));
617 if ( height ) *height = int(double(h) / (m_userScaleY*m_mm_to_pix_y));
618}
619
620wxSize wxDC::GetPPI() const
621{
622 #warning "move this to common code?"
623 return wxSize(int(double(m_mm_to_pix_x) * inches2mm),
624 int(double(m_mm_to_pix_y) * inches2mm));
625}
626
627
628// ---------------------------------------------------------------------------
629// Blitting
630// ---------------------------------------------------------------------------
631
632bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
633 wxCoord width, wxCoord height,
634 wxDC *source, wxCoord xsrc, wxCoord ysrc,
635 int rop, bool useMask,
636 wxCoord xsrcMask, wxCoord ysrcMask)
637{
638#warning "FIXME"
639 return false;
640#if 0
641 wxCHECK_MSG( Ok(), false, wxT("invalid dc") );
642 wxCHECK_MSG( source, false, wxT("invalid source dc") );
643
644 // transform the source DC coords to the device ones
645 xsrc = source->LogicalToDeviceX(xsrc);
646 ysrc = source->LogicalToDeviceY(ysrc);
647
648 /* FIXME_MGL: use the mask origin when drawing transparently */
649 if (xsrcMask == -1 && ysrcMask == -1)
650 {
651 xsrcMask = xsrc; ysrcMask = ysrc;
652 }
653 else
654 {
655 xsrcMask = source->LogicalToDeviceX(xsrcMask);
656 ysrcMask = source->LogicalToDeviceY(ysrcMask);
657 }
658
659 CalcBoundingBox(xdest, ydest);
660 CalcBoundingBox(xdest + width, ydest + height);
661
662 /* scale/translate size and position */
663 wxCoord xx = XLOG2DEV(xdest);
664 wxCoord yy = YLOG2DEV(ydest);
665 wxCoord ww = XLOG2DEVREL(width);
666 wxCoord hh = YLOG2DEVREL(height);
667
668 if ( source->m_isMemDC )
669 {
670 wxMemoryDC *memDC = (wxMemoryDC*) source;
671 DoDrawSubBitmap(memDC->GetSelectedObject(), xsrc, ysrc, ww, hh,
672 xdest, ydest, rop, useMask);
673 }
674 else
675 {
676 m_MGLDC->makeCurrent(); // will go away with MGL6.0
677 m_MGLDC->bitBlt(*source->GetMGLDC(),
678 xsrc, ysrc, xsrc + ww, ysrc + hh,
679 xx, yy, LogicalFunctionToMGLRop(rop));
680 }
681
682 return true;
683#endif
684}
685
686void wxDC::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask)
687{
688 wxCHECK_RET( Ok(), wxT("invalid dc") );
689 wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") );
690
691 wxCoord w = bmp.GetWidth();
692 wxCoord h = bmp.GetHeight();
693
694 DoDrawSubBitmap(bmp, 0, 0, w, h, x, y, m_logicalFunction, useMask);
695}
696
697void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
698{
699 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
700 DoDrawBitmap((const wxBitmap&)icon, x, y, true);
701}
702
703void wxDC::DoDrawSubBitmap(const wxBitmap &bmp,
704 wxCoord x, wxCoord y, wxCoord w, wxCoord h,
705 wxCoord destx, wxCoord desty, int rop, bool useMask)
706{
707#if 0
708 wxCHECK_RET( Ok(), wxT("invalid dc") );
709 wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") );
710
711 CalcBoundingBox(x, y);
712 CalcBoundingBox(x + w, y + h);
713
714 wxCoord dx = XLOG2DEV(destx);
715 wxCoord dy = YLOG2DEV(desty);
716 wxCoord dw = XLOG2DEVREL(w);
717 wxCoord dh = YLOG2DEVREL(h);
718
719 m_MGLDC->makeCurrent(); // will go away with MGL6.0
720
721 bool useStretching = ((w != dw) || (h != dh));
722 bool putSection = (w != bmp.GetWidth() || h != bmp.GetHeight());
723 MGL_writeModeType mglRop = (MGL_writeModeType)LogicalFunctionToMGLRop(rop);
724
725 if ( bmp.GetDepth() == 1 )
726 {
727 // Mono bitmaps are handled in special way -- all 1s are drawn in
728 // foreground colours, all 0s in background colour.
729
730 ((wxBitmap&)bmp).SetMonoPalette(m_textForegroundColour, m_textBackgroundColour);
731 }
732
733 if ( useMask && bmp.GetMask() )
734 {
735 // Since MGL does not support masks directly (in MGL, mask is handled
736 // in same way as in wxImage, i.e. there is one "key" color), we
737 // simulate masked bitblt in 6 steps (same as in MSW):
738 //
739 // 1. Create a temporary bitmap and copy the destination area into it.
740 // 2. Copy the source area into the temporary bitmap using the
741 // specified logical function.
742 // 3. Set the masked area in the temporary bitmap to BLACK by ANDing
743 // the mask bitmap with the temp bitmap with the foreground colour
744 // set to WHITE and the bg colour set to BLACK.
745 // 4. Set the unmasked area in the destination area to BLACK by
746 // ANDing the mask bitmap with the destination area with the
747 // foreground colour set to BLACK and the background colour set
748 // to WHITE.
749 // 5. OR the temporary bitmap with the destination area.
750 // 6. Delete the temporary bitmap.
751 //
752 // This sequence of operations ensures that the source's transparent
753 // area need not be black, and logical functions are supported.
754
755 wxBitmap *mask = bmp.GetMask()->GetBitmap();
756
757 MGLMemoryDC *temp;
758
759 if ( GetDepth() <= 8 )
760 {
761 temp = new MGLMemoryDC(dw, dh, GetDepth(), NULL);
762 wxDC tempdc;
763 tempdc.SetMGLDC(temp, false);
764 tempdc.SetPalette(m_palette);
765 }
766 else
767 {
768 pixel_format_t pf;
769 m_MGLDC->getPixelFormat(pf);
770 temp = new MGLMemoryDC(dw, dh, GetDepth(), &pf);
771 }
772
773 wxCHECK_RET( temp->isValid(), wxT("cannot create temporary dc") );
774
775 temp->bitBlt(*m_MGLDC, dx, dy, dx + dw, dy + dh, 0, 0, MGL_REPLACE_MODE);
776
777 DoBitBlt(bmp, temp, x, y, w, h, 0, 0, dw, dh, mglRop,
778 useStretching, putSection);
779
780 mask->SetMonoPalette(wxColour(0,0,0), wxColour(255,255,255));
781 DoBitBlt(*mask, temp, x, y, w, h, 0, 0, dw, dh, MGL_R2_MASKSRC,
782 useStretching, putSection);
783 DoBitBlt(*mask, m_MGLDC, x, y, w, h, dx, dy, dw, dh, MGL_R2_MASKNOTSRC,
784 useStretching, putSection);
785
786 m_MGLDC->bitBlt(*temp, 0, 0, dw, dh, dx, dy, MGL_OR_MODE);
787
788 delete temp;
789 }
790
791 else
792 {
793 DoBitBlt(bmp, m_MGLDC, x, y, w, h, dx, dy, dw, dh, mglRop,
794 useStretching, putSection);
795 }
796#endif
797}