]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: mdi.cpp | |
3 | // Purpose: MDI classes | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "mdi.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/mdi.h" | |
17 | #include "wx/menu.h" | |
18 | #include "wx/settings.h" | |
19 | ||
20 | #include "wx/mac/private.h" | |
21 | ||
22 | extern wxWindowList wxModelessWindows; | |
23 | ||
24 | #if !USE_SHARED_LIBRARY | |
25 | IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame) | |
26 | IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame) | |
27 | IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow) | |
28 | ||
29 | BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame) | |
30 | EVT_SIZE(wxMDIParentFrame::OnSize) | |
31 | EVT_ACTIVATE(wxMDIParentFrame::OnActivate) | |
32 | EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged) | |
33 | END_EVENT_TABLE() | |
34 | ||
35 | BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow) | |
36 | EVT_SCROLL(wxMDIClientWindow::OnScroll) | |
37 | END_EVENT_TABLE() | |
38 | ||
39 | #endif | |
40 | ||
41 | static const int IDM_WINDOWTILE = 4001; | |
42 | static const int IDM_WINDOWTILEHOR = 4001; | |
43 | static const int IDM_WINDOWCASCADE = 4002; | |
44 | static const int IDM_WINDOWICONS = 4003; | |
45 | static const int IDM_WINDOWNEXT = 4004; | |
46 | static const int IDM_WINDOWTILEVERT = 4005; | |
47 | static const int IDM_WINDOWPREV = 4006; | |
48 | ||
49 | // This range gives a maximum of 500 MDI children. Should be enough :-) | |
50 | static const int wxFIRST_MDI_CHILD = 4100; | |
51 | static const int wxLAST_MDI_CHILD = 4600; | |
52 | ||
53 | // Status border dimensions | |
54 | static const int wxTHICK_LINE_BORDER = 3; | |
55 | ||
56 | // Parent frame | |
57 | ||
58 | wxMDIParentFrame::wxMDIParentFrame() | |
59 | { | |
60 | m_clientWindow = NULL; | |
61 | m_currentChild = NULL; | |
62 | m_windowMenu = (wxMenu*) NULL; | |
63 | m_parentFrameActive = TRUE; | |
64 | } | |
65 | ||
66 | bool wxMDIParentFrame::Create(wxWindow *parent, | |
67 | wxWindowID id, | |
68 | const wxString& title, | |
69 | const wxPoint& pos, | |
70 | const wxSize& size, | |
71 | long style, | |
72 | const wxString& name) | |
73 | { | |
74 | m_clientWindow = NULL; | |
75 | m_currentChild = NULL; | |
76 | ||
77 | // this style can be used to prevent a window from having the standard MDI | |
78 | // "Window" menu | |
79 | if ( style & wxFRAME_NO_WINDOW_MENU ) | |
80 | { | |
81 | m_windowMenu = (wxMenu *)NULL; | |
82 | style -= wxFRAME_NO_WINDOW_MENU ; | |
83 | } | |
84 | else // normal case: we have the window menu, so construct it | |
85 | { | |
86 | m_windowMenu = new wxMenu; | |
87 | ||
88 | m_windowMenu->Append(IDM_WINDOWCASCADE, wxT("&Cascade")); | |
89 | m_windowMenu->Append(IDM_WINDOWTILEHOR, wxT("Tile &Horizontally")); | |
90 | m_windowMenu->Append(IDM_WINDOWTILEVERT, wxT("Tile &Vertically")); | |
91 | m_windowMenu->AppendSeparator(); | |
92 | m_windowMenu->Append(IDM_WINDOWICONS, wxT("&Arrange Icons")); | |
93 | m_windowMenu->Append(IDM_WINDOWNEXT, wxT("&Next")); | |
94 | } | |
95 | ||
96 | wxFrame::Create( parent , id , title , wxPoint( 2000 , 2000 ) , size , style , name ) ; | |
97 | m_parentFrameActive = TRUE; | |
98 | ||
99 | OnCreateClient(); | |
100 | ||
101 | return TRUE; | |
102 | } | |
103 | ||
104 | wxMDIParentFrame::~wxMDIParentFrame() | |
105 | { | |
106 | DestroyChildren(); | |
107 | // already delete by DestroyChildren() | |
108 | m_frameToolBar = NULL; | |
109 | m_frameStatusBar = NULL; | |
110 | m_clientWindow = NULL ; | |
111 | ||
112 | if (m_windowMenu) | |
113 | { | |
114 | delete m_windowMenu; | |
115 | m_windowMenu = (wxMenu*) NULL; | |
116 | } | |
117 | ||
118 | if ( m_clientWindow ) | |
119 | { | |
120 | delete m_clientWindow; | |
121 | m_clientWindow = NULL ; | |
122 | } | |
123 | } | |
124 | ||
125 | ||
126 | // Get size *available for subwindows* i.e. excluding menu bar. | |
127 | void wxMDIParentFrame::DoGetClientSize(int *x, int *y) const | |
128 | { | |
129 | wxDisplaySize( x , y ) ; | |
130 | } | |
131 | ||
132 | void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar) | |
133 | { | |
134 | wxFrame::SetMenuBar( menu_bar ) ; | |
135 | } | |
136 | ||
137 | void wxMDIParentFrame::OnSize(wxSizeEvent& event) | |
138 | { | |
139 | #if wxUSE_CONSTRAINTS | |
140 | if (GetAutoLayout()) | |
141 | Layout(); | |
142 | #endif | |
143 | int x = 0; | |
144 | int y = 0; | |
145 | int width, height; | |
146 | GetClientSize(&width, &height); | |
147 | ||
148 | if ( GetClientWindow() ) | |
149 | GetClientWindow()->SetSize(x, y, width, height); | |
150 | } | |
151 | ||
152 | void wxMDIParentFrame::OnActivate(wxActivateEvent& event) | |
153 | { | |
154 | if ( m_currentChild && event.GetActive() ) | |
155 | { | |
156 | wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_currentChild->GetId()); | |
157 | event.SetEventObject( m_currentChild ); | |
158 | m_currentChild->GetEventHandler()->ProcessEvent(event) ; | |
159 | } | |
160 | else if ( event.GetActive() ) | |
161 | { | |
162 | if ( m_frameMenuBar != NULL ) | |
163 | { | |
164 | m_frameMenuBar->MacInstallMenuBar() ; | |
165 | } | |
166 | ||
167 | } | |
168 | } | |
169 | ||
170 | // Returns the active MDI child window | |
171 | wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const | |
172 | { | |
173 | return m_currentChild ; | |
174 | } | |
175 | ||
176 | // Create the client window class (don't Create the window, | |
177 | // just return a new class) | |
178 | wxMDIClientWindow *wxMDIParentFrame::OnCreateClient() | |
179 | { | |
180 | m_clientWindow = new wxMDIClientWindow( this ); | |
181 | return m_clientWindow; | |
182 | } | |
183 | ||
184 | // Responds to colour changes, and passes event on to children. | |
185 | void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
186 | { | |
187 | // TODO | |
188 | ||
189 | // Propagate the event to the non-top-level children | |
190 | wxFrame::OnSysColourChanged(event); | |
191 | } | |
192 | ||
193 | // MDI operations | |
194 | void wxMDIParentFrame::Cascade() | |
195 | { | |
196 | // TODO | |
197 | } | |
198 | ||
199 | void wxMDIParentFrame::Tile() | |
200 | { | |
201 | // TODO | |
202 | } | |
203 | ||
204 | void wxMDIParentFrame::ArrangeIcons() | |
205 | { | |
206 | // TODO | |
207 | } | |
208 | ||
209 | void wxMDIParentFrame::ActivateNext() | |
210 | { | |
211 | // TODO | |
212 | } | |
213 | ||
214 | void wxMDIParentFrame::ActivatePrevious() | |
215 | { | |
216 | // TODO | |
217 | } | |
218 | ||
219 | // Child frame | |
220 | ||
221 | wxMDIChildFrame::wxMDIChildFrame() | |
222 | { | |
223 | Init() ; | |
224 | } | |
225 | void wxMDIChildFrame::Init() | |
226 | { | |
227 | } | |
228 | ||
229 | bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, | |
230 | wxWindowID id, | |
231 | const wxString& title, | |
232 | const wxPoint& pos, | |
233 | const wxSize& size, | |
234 | long style, | |
235 | const wxString& name) | |
236 | { | |
237 | SetName(name); | |
238 | ||
239 | if ( id > -1 ) | |
240 | m_windowId = id; | |
241 | else | |
242 | m_windowId = (int)NewControlId(); | |
243 | ||
244 | if (parent) parent->AddChild(this); | |
245 | ||
246 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; | |
247 | ||
248 | m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; | |
249 | SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ; | |
250 | ||
251 | wxModelessWindows.Append(this); | |
252 | return FALSE; | |
253 | } | |
254 | ||
255 | wxMDIChildFrame::~wxMDIChildFrame() | |
256 | { | |
257 | DestroyChildren(); | |
258 | // already delete by DestroyChildren() | |
259 | m_frameToolBar = NULL; | |
260 | m_frameStatusBar = NULL; | |
261 | } | |
262 | ||
263 | void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar) | |
264 | { | |
265 | return wxFrame::SetMenuBar( menu_bar ) ; | |
266 | } | |
267 | ||
268 | // MDI operations | |
269 | void wxMDIChildFrame::Maximize() | |
270 | { | |
271 | wxFrame::Maximize() ; | |
272 | } | |
273 | ||
274 | void wxMDIChildFrame::Restore() | |
275 | { | |
276 | wxFrame::Restore() ; | |
277 | } | |
278 | ||
279 | void wxMDIChildFrame::Activate() | |
280 | { | |
281 | } | |
282 | ||
283 | //----------------------------------------------------------------------------- | |
284 | // wxMDIClientWindow | |
285 | //----------------------------------------------------------------------------- | |
286 | ||
287 | wxMDIClientWindow::wxMDIClientWindow() | |
288 | { | |
289 | } | |
290 | ||
291 | wxMDIClientWindow::~wxMDIClientWindow() | |
292 | { | |
293 | DestroyChildren(); | |
294 | } | |
295 | ||
296 | bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style) | |
297 | { | |
298 | ||
299 | m_windowId = (int)NewControlId(); | |
300 | ||
301 | if ( parent ) | |
302 | { | |
303 | parent->AddChild(this); | |
304 | } | |
305 | m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE); | |
306 | ||
307 | wxModelessWindows.Append(this); | |
308 | return TRUE; | |
309 | } | |
310 | ||
311 | // Explicitly call default scroll behaviour | |
312 | void wxMDIClientWindow::OnScroll(wxScrollEvent& event) | |
313 | { | |
314 | } | |
315 |