]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/dcclient.cpp
don't use negative windows sizes
[wxWidgets.git] / src / dfb / dcclient.cpp
CommitLineData
b3c86150
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/dfb/dcclient.cpp
3// Purpose: wxWindowDC, wxClientDC and wxPaintDC
4// Author: Vaclav Slavik
5// Created: 2006-08-10
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#include "wx/dcclient.h"
27
28#ifndef WX_PRECOMP
29 #include "wx/window.h"
30#endif
31
32#include "wx/dfb/private.h"
33
34// ===========================================================================
35// implementation
36// ===========================================================================
37
38//-----------------------------------------------------------------------------
39// wxWindowDC
40//-----------------------------------------------------------------------------
41
42IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
43
44wxWindowDC::wxWindowDC(wxWindow *win)
b3c86150 45{
78d2c241 46 InitForWin(win, NULL);
b3c86150
VS
47}
48
78d2c241 49void wxWindowDC::InitForWin(wxWindow *win, const wxRect *rect)
b3c86150
VS
50{
51 wxCHECK_RET( win, _T("invalid window") );
52
17dd5538
VS
53 // FIXME: this should be made to work: we need to detect that the window
54 // is not visible and in that case, a) ignore any drawing actions
55 // and b) provide dummy surface that can still be used to get
56 // information (e.g. text extents):
17dd5538
VS
57 for ( wxWindow *w = win; w; w = w->GetParent() )
58 {
59 // painting on hidden TLW when non-TLW windows are shown is OK,
60 // DirectFB manages that:
61 if ( w->IsTopLevel() )
62 break;
63
64 wxASSERT_MSG( w->IsShown(),
65 _T("painting on hidden window not implemented yet") );
66 }
67
78d2c241
VS
68 // check if the rectangle covers full window and so is not needed:
69 if ( rect && *rect == wxRect(win->GetSize()) )
70 rect = NULL;
17dd5538 71
78d2c241
VS
72 // obtain the surface used for painting:
73 wxIDirectFBSurfacePtr surface;
74 if ( !rect )
75 {
76 wxCHECK_RET( win->GetSize().x > 0 && win->GetSize().y > 0,
77 _T("window has invalid size") );
78
79 surface = win->GetDfbSurface();
80 }
81 else
82 {
83 wxCHECK_RET( !rect || !rect->IsEmpty(), _T("invalid rectangle") );
84
85 DFBRectangle dfbrect = { rect->x, rect->y, rect->width, rect->height };
86 surface = win->GetDfbSurface()->GetSubSurface(&dfbrect);
87 }
88
89 if ( !surface )
90 return;
91
92 Init(surface);
b3c86150 93 SetFont(win->GetFont());
78d2c241
VS
94
95 // offset coordinates to account for subsurface's origin coordinates:
96 if ( rect )
97 SetDeviceOrigin(rect->x, rect->y);
b3c86150
VS
98}
99
100//-----------------------------------------------------------------------------
101// base class for wxClientDC and wxPaintDC
102//-----------------------------------------------------------------------------
103
104wxClientDCBase::wxClientDCBase(wxWindow *win)
105{
106 wxCHECK_RET( win, _T("invalid window") );
107
108 wxRect rect = win->GetClientRect();
78d2c241 109 InitForWin(win, &rect);
b3c86150
VS
110}
111
112//-----------------------------------------------------------------------------
113// wxClientDC
114//-----------------------------------------------------------------------------
115
116IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
117
118wxClientDC::~wxClientDC()
119{
120 // flip to surface so that the changes become visible
52c8d32a 121 wxIDirectFBSurfacePtr surface(GetDirectFBSurface());
17dd5538
VS
122
123 // FIXME: do this only if the surface was modified (as opposed to e.g.
124 // used only to obtain text metrics)
b3c86150 125 if ( surface )
52c8d32a 126 surface->Flip(NULL, DSFLIP_NONE);
b3c86150
VS
127}
128
129//-----------------------------------------------------------------------------
130// wxPaintDC
131//-----------------------------------------------------------------------------
132
133IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
134
135#warning "wxPaintDC ctor must respect m_updateRegion"
136
137wxPaintDC::~wxPaintDC()
138{
139 // NB: do *not* flip the surface: wxPaintDC is used with EVT_PAINT and the
140 // surface will be flipped for the entire TLW once all children are
141 // repainted
142}