]> git.saurik.com Git - wxWidgets.git/blob - src/common/toplvcmn.cpp
better learn the operators...
[wxWidgets.git] / src / common / toplvcmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/toplvcmn.cpp
3 // Purpose: common (for all platforms) wxTopLevelWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
5 // Created: 01/02/97
6 // Id: $Id$
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #ifdef __GNUG__
20 #pragma implementation "toplevelbase.h"
21 #endif
22
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
25
26 #ifdef __BORLANDC__
27 #pragma hdrstop
28 #endif
29
30 #ifndef WX_PRECOMP
31 #include "wx/toplevel.h"
32 #include "wx/dcclient.h"
33 #endif // WX_PRECOMP
34
35 // ----------------------------------------------------------------------------
36 // event table
37 // ----------------------------------------------------------------------------
38
39 BEGIN_EVENT_TABLE(wxTopLevelWindowBase, wxWindow)
40 EVT_CLOSE(wxTopLevelWindowBase::OnCloseWindow)
41 EVT_SIZE(wxTopLevelWindowBase::OnSize)
42 END_EVENT_TABLE()
43
44 // ============================================================================
45 // implementation
46 // ============================================================================
47
48 // ----------------------------------------------------------------------------
49 // construction/destruction
50 // ----------------------------------------------------------------------------
51
52 wxTopLevelWindowBase::wxTopLevelWindowBase()
53 {
54 }
55
56 bool wxTopLevelWindowBase::Destroy()
57 {
58 // delayed destruction: the frame will be deleted during the next idle
59 // loop iteration
60 if ( !wxPendingDelete.Member(this) )
61 wxPendingDelete.Append(this);
62
63 return TRUE;
64 }
65
66 // ----------------------------------------------------------------------------
67 // wxTopLevelWindow size management: we exclude the areas taken by menu/status/toolbars
68 // from the client area, so the client area is what's really available for the
69 // frame contents
70 // ----------------------------------------------------------------------------
71
72 void wxTopLevelWindowBase::DoScreenToClient(int *x, int *y) const
73 {
74 wxWindow::DoScreenToClient(x, y);
75
76 // We may be faking the client origin.
77 // So a window that's really at (0, 30) may appear
78 // (to wxWin apps) to be at (0, 0).
79 wxPoint pt(GetClientAreaOrigin());
80 *x -= pt.x;
81 *y -= pt.y;
82 }
83
84 void wxTopLevelWindowBase::DoClientToScreen(int *x, int *y) const
85 {
86 // We may be faking the client origin.
87 // So a window that's really at (0, 30) may appear
88 // (to wxWin apps) to be at (0, 0).
89 wxPoint pt1(GetClientAreaOrigin());
90 *x += pt1.x;
91 *y += pt1.y;
92
93 wxWindow::DoClientToScreen(x, y);
94 }
95
96
97 // ----------------------------------------------------------------------------
98 // event handlers
99 // ----------------------------------------------------------------------------
100
101 // default resizing behaviour - if only ONE subwindow, resize to fill the
102 // whole client area
103 void wxTopLevelWindowBase::OnSize(wxSizeEvent& WXUNUSED(event))
104 {
105 // if we're using constraints - do use them
106 #if wxUSE_CONSTRAINTS
107 if ( GetAutoLayout() )
108 {
109 Layout();
110 }
111 else
112 #endif // wxUSE_CONSTRAINTS
113 {
114 // do we have _exactly_ one child?
115 wxWindow *child = (wxWindow *)NULL;
116 for ( wxWindowList::Node *node = GetChildren().GetFirst();
117 node;
118 node = node->GetNext() )
119 {
120 wxWindow *win = node->GetData();
121
122 // exclude top level and managed windows (status bar isn't
123 // currently in the children list except under wxMac anyhow, but
124 // it makes no harm to test for it)
125 if ( !win->IsTopLevel() && !IsOneOfBars(win) )
126 {
127 if ( child )
128 {
129 return; // it's our second subwindow - nothing to do
130 }
131
132 child = win;
133 }
134 }
135
136 // do we have any children at all?
137 if ( child )
138 {
139 // exactly one child - set it's size to fill the whole frame
140 int clientW, clientH;
141 DoGetClientSize(&clientW, &clientH);
142
143 // for whatever reasons, wxGTK wants to have a small offset - it
144 // probably looks better with it?
145 #ifdef __WXGTK__
146 static const int ofs = 1;
147 #else
148 static const int ofs = 0;
149 #endif
150
151 child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
152 }
153 }
154 }
155
156 // The default implementation for the close window event.
157 void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
158 {
159 Destroy();
160 }
161
162 bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized)
163 {
164 wxIconizeEvent event(GetId(), iconized);
165 event.SetEventObject(this);
166
167 return GetEventHandler()->ProcessEvent(event);
168 }
169