]> git.saurik.com Git - wxWidgets.git/blob - src/common/toplvcmn.cpp
Fixed wxToolbar95::FindToolForPosition
[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 IMPLEMENT_DYNAMIC_CLASS(wxTopLevelWindow, wxWindow)
49
50 // ----------------------------------------------------------------------------
51 // construction/destruction
52 // ----------------------------------------------------------------------------
53
54 wxTopLevelWindowBase::wxTopLevelWindowBase()
55 {
56 }
57
58 bool wxTopLevelWindowBase::Destroy()
59 {
60 // delayed destruction: the frame will be deleted during the next idle
61 // loop iteration
62 if ( !wxPendingDelete.Member(this) )
63 wxPendingDelete.Append(this);
64
65 return TRUE;
66 }
67
68 // ----------------------------------------------------------------------------
69 // wxTopLevelWindow size management: we exclude the areas taken by
70 // menu/status/toolbars from the client area, so the client area is what's
71 // really available for the frame contents
72 // ----------------------------------------------------------------------------
73
74 void wxTopLevelWindowBase::DoScreenToClient(int *x, int *y) const
75 {
76 wxWindow::DoScreenToClient(x, y);
77
78 // translate the wxWindow client coords to our client coords
79 wxPoint pt(GetClientAreaOrigin());
80 if ( x )
81 *x -= pt.x;
82 if ( y )
83 *y -= pt.y;
84 }
85
86 void wxTopLevelWindowBase::DoClientToScreen(int *x, int *y) const
87 {
88 // our client area origin (0, 0) may be really something like (0, 30) for
89 // wxWindow if we have a toolbar, account for it before translating
90 wxPoint pt(GetClientAreaOrigin());
91 if ( x )
92 *x += pt.x;
93 if ( y )
94 *y += pt.y;
95
96 wxWindow::DoClientToScreen(x, y);
97 }
98
99
100 // ----------------------------------------------------------------------------
101 // event handlers
102 // ----------------------------------------------------------------------------
103
104 // default resizing behaviour - if only ONE subwindow, resize to fill the
105 // whole client area
106 void wxTopLevelWindowBase::OnSize(wxSizeEvent& WXUNUSED(event))
107 {
108 // if we're using constraints - do use them
109 #if wxUSE_CONSTRAINTS
110 if ( GetAutoLayout() )
111 {
112 Layout();
113 }
114 else
115 #endif // wxUSE_CONSTRAINTS
116 {
117 // do we have _exactly_ one child?
118 wxWindow *child = (wxWindow *)NULL;
119 for ( wxWindowList::Node *node = GetChildren().GetFirst();
120 node;
121 node = node->GetNext() )
122 {
123 wxWindow *win = node->GetData();
124
125 // exclude top level and managed windows (status bar isn't
126 // currently in the children list except under wxMac anyhow, but
127 // it makes no harm to test for it)
128 if ( !win->IsTopLevel() && !IsOneOfBars(win) )
129 {
130 if ( child )
131 {
132 return; // it's our second subwindow - nothing to do
133 }
134
135 child = win;
136 }
137 }
138
139 // do we have any children at all?
140 if ( child )
141 {
142 // exactly one child - set it's size to fill the whole frame
143 int clientW, clientH;
144 DoGetClientSize(&clientW, &clientH);
145
146 // for whatever reasons, wxGTK wants to have a small offset - it
147 // probably looks better with it?
148 #ifdef __WXGTK__
149 static const int ofs = 1;
150 #else
151 static const int ofs = 0;
152 #endif
153
154 child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
155 }
156 }
157 }
158
159 // The default implementation for the close window event.
160 void wxTopLevelWindowBase::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
161 {
162 Destroy();
163 }
164
165 bool wxTopLevelWindowBase::SendIconizeEvent(bool iconized)
166 {
167 wxIconizeEvent event(GetId(), iconized);
168 event.SetEventObject(this);
169
170 return GetEventHandler()->ProcessEvent(event);
171 }
172