]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/mdi.cpp
added link to wxFileHistory
[wxWidgets.git] / src / mac / carbon / mdi.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: mdi.cpp
3// Purpose: MDI classes
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "mdi.h"
14#endif
15
3d1a4878
SC
16#include "wx/wxprec.h"
17
179e085f
RN
18#if wxUSE_MDI
19
e9576ca5
SC
20#include "wx/mdi.h"
21#include "wx/menu.h"
22#include "wx/settings.h"
70024cfb 23#include "wx/log.h"
e9576ca5 24
76a5e5d2 25#include "wx/mac/private.h"
70024cfb 26#include "wx/mac/uma.h"
76a5e5d2 27
fe08e597 28extern wxWindowList wxModelessWindows;
e9576ca5 29
e9576ca5
SC
30IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
31IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
32IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow)
33
34BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
e9576ca5
SC
35 EVT_ACTIVATE(wxMDIParentFrame::OnActivate)
36 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
37END_EVENT_TABLE()
38
39BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow)
40 EVT_SCROLL(wxMDIClientWindow::OnScroll)
41END_EVENT_TABLE()
42
fd8278bf
VZ
43static const wxChar *TRACE_MDI = _T("mdi");
44
0a67a93b
SC
45static const int IDM_WINDOWTILE = 4001;
46static const int IDM_WINDOWTILEHOR = 4001;
47static const int IDM_WINDOWCASCADE = 4002;
48static const int IDM_WINDOWICONS = 4003;
49static const int IDM_WINDOWNEXT = 4004;
50static const int IDM_WINDOWTILEVERT = 4005;
4f3b37fd 51static const int IDM_WINDOWPREV = 4006;
0a67a93b
SC
52
53// This range gives a maximum of 500 MDI children. Should be enough :-)
54static const int wxFIRST_MDI_CHILD = 4100;
55static const int wxLAST_MDI_CHILD = 4600;
56
57// Status border dimensions
58static const int wxTHICK_LINE_BORDER = 3;
59
e9576ca5
SC
60// Parent frame
61
62wxMDIParentFrame::wxMDIParentFrame()
63{
0a67a93b
SC
64 m_clientWindow = NULL;
65 m_currentChild = NULL;
66 m_windowMenu = (wxMenu*) NULL;
67 m_parentFrameActive = TRUE;
e9576ca5
SC
68}
69
70bool wxMDIParentFrame::Create(wxWindow *parent,
71 wxWindowID id,
72 const wxString& title,
73 const wxPoint& pos,
74 const wxSize& size,
75 long style,
76 const wxString& name)
77{
e40298d5
JS
78 m_clientWindow = NULL;
79 m_currentChild = NULL;
80
81 // this style can be used to prevent a window from having the standard MDI
82 // "Window" menu
83 if ( style & wxFRAME_NO_WINDOW_MENU )
84 {
85 m_windowMenu = (wxMenu *)NULL;
86 style -= wxFRAME_NO_WINDOW_MENU ;
87 }
88 else // normal case: we have the window menu, so construct it
89 {
90 m_windowMenu = new wxMenu;
0a67a93b 91
e40298d5
JS
92 m_windowMenu->Append(IDM_WINDOWCASCADE, wxT("&Cascade"));
93 m_windowMenu->Append(IDM_WINDOWTILEHOR, wxT("Tile &Horizontally"));
94 m_windowMenu->Append(IDM_WINDOWTILEVERT, wxT("Tile &Vertically"));
95 m_windowMenu->AppendSeparator();
96 m_windowMenu->Append(IDM_WINDOWICONS, wxT("&Arrange Icons"));
97 m_windowMenu->Append(IDM_WINDOWNEXT, wxT("&Next"));
98 }
99
70024cfb 100 wxFrame::Create( parent , id , title , pos , size , style , name ) ;
e40298d5
JS
101 m_parentFrameActive = TRUE;
102
103 OnCreateClient();
104
e9576ca5
SC
105 return TRUE;
106}
107
108wxMDIParentFrame::~wxMDIParentFrame()
109{
0a67a93b 110 DestroyChildren();
ea3cdc4f 111 // already deleted by DestroyChildren()
0a67a93b 112 m_clientWindow = NULL ;
e40298d5 113
ea3cdc4f 114 delete m_windowMenu;
e9576ca5
SC
115}
116
0a67a93b 117
e9576ca5
SC
118void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar)
119{
e40298d5 120 wxFrame::SetMenuBar( menu_bar ) ;
e9576ca5
SC
121}
122
0bba37f5
DE
123void wxMDIParentFrame::GetRectForTopLevelChildren(int *x, int *y, int *w, int *h)
124{
125 if(x)
126 *x = 0;
127 if(y)
128 *y = 0;
129 wxDisplaySize(w,h);
130}
131
70024cfb 132void wxMDIParentFrame::MacActivate(long timestamp, bool activating)
e9576ca5 133{
fd8278bf 134 wxLogTrace(TRACE_MDI, wxT("MDI PARENT=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact"));
70024cfb 135 if(activating)
e40298d5 136 {
70024cfb
DE
137 if(s_macDeactivateWindow && s_macDeactivateWindow->GetParent()==this)
138 {
fd8278bf 139 wxLogTrace(TRACE_MDI, wxT("child had been scheduled for deactivation, rehighlighting"));
70024cfb 140 UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true);
fd8278bf 141 wxLogTrace(TRACE_MDI, wxT("done highliting child"));
70024cfb
DE
142 s_macDeactivateWindow = NULL;
143 }
144 else if(s_macDeactivateWindow == this)
145 {
fd8278bf 146 wxLogTrace(TRACE_MDI, wxT("Avoided deactivation/activation of this=%p"), this);
70024cfb
DE
147 s_macDeactivateWindow = NULL;
148 }
149 else // window to deactivate is NULL or is not us or one of our kids
150 {
151 // activate kid instead
152 if(m_currentChild)
153 m_currentChild->MacActivate(timestamp,activating);
154 else
155 wxFrame::MacActivate(timestamp,activating);
156 }
e40298d5 157 }
70024cfb 158 else
e40298d5 159 {
70024cfb
DE
160 // We were scheduled for deactivation, and now we do it.
161 if(s_macDeactivateWindow==this)
e40298d5 162 {
70024cfb
DE
163 s_macDeactivateWindow = NULL;
164 if(m_currentChild)
165 m_currentChild->MacActivate(timestamp,activating);
166 wxFrame::MacActivate(timestamp,activating);
167 }
168 else // schedule ourselves for deactivation
169 {
170 if(s_macDeactivateWindow)
fd8278bf
VZ
171 wxLogTrace(TRACE_MDI, wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow);
172 wxLogTrace(TRACE_MDI, wxT("Scheduling delayed MDI Parent deactivation"));
70024cfb 173 s_macDeactivateWindow = this;
e40298d5 174 }
e40298d5 175 }
e9576ca5
SC
176}
177
70024cfb
DE
178void wxMDIParentFrame::OnActivate(wxActivateEvent& event)
179{
180 event.Skip();
181}
182
e9576ca5
SC
183// Returns the active MDI child window
184wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const
185{
e40298d5 186 return m_currentChild ;
e9576ca5
SC
187}
188
189// Create the client window class (don't Create the window,
190// just return a new class)
191wxMDIClientWindow *wxMDIParentFrame::OnCreateClient()
192{
0a67a93b
SC
193 m_clientWindow = new wxMDIClientWindow( this );
194 return m_clientWindow;
e9576ca5
SC
195}
196
197// Responds to colour changes, and passes event on to children.
198void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
199{
200 // TODO
e40298d5 201
e9576ca5
SC
202 // Propagate the event to the non-top-level children
203 wxFrame::OnSysColourChanged(event);
204}
205
206// MDI operations
207void wxMDIParentFrame::Cascade()
208{
209 // TODO
210}
211
0d97c090 212void wxMDIParentFrame::Tile(wxOrientation WXUNUSED(orient))
e9576ca5
SC
213{
214 // TODO
215}
216
217void wxMDIParentFrame::ArrangeIcons()
218{
219 // TODO
220}
221
222void wxMDIParentFrame::ActivateNext()
223{
224 // TODO
225}
226
227void wxMDIParentFrame::ActivatePrevious()
228{
229 // TODO
230}
231
29e92efb
VZ
232bool wxMDIParentFrame::Show( bool show )
233{
29e92efb
VZ
234 // don't really show the MDI frame unless it has any children other than
235 // MDI children as it is pretty useless in this case
507ad426 236
29e92efb
VZ
237 if ( show )
238 {
239 // TODO: check for other children
7bf8eb78
DE
240 if(!GetToolBar())
241 Move(-10000, -10000);
29e92efb
VZ
242 }
243
507ad426
SC
244 if ( !wxFrame::Show(show) )
245 return false;
246
29e92efb
VZ
247 return true;
248}
249
e9576ca5
SC
250// Child frame
251
252wxMDIChildFrame::wxMDIChildFrame()
0a67a93b
SC
253{
254 Init() ;
255}
256void wxMDIChildFrame::Init()
e9576ca5
SC
257{
258}
259
260bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
e40298d5
JS
261 wxWindowID id,
262 const wxString& title,
263 const wxPoint& pos,
264 const wxSize& size,
265 long style,
266 const wxString& name)
e9576ca5
SC
267{
268 SetName(name);
e40298d5 269
e9576ca5
SC
270 if ( id > -1 )
271 m_windowId = id;
272 else
273 m_windowId = (int)NewControlId();
e40298d5 274
e9576ca5 275 if (parent) parent->AddChild(this);
e40298d5
JS
276
277 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
278
facd6764
SC
279 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
280
e9576ca5
SC
281 wxModelessWindows.Append(this);
282 return FALSE;
283}
284
285wxMDIChildFrame::~wxMDIChildFrame()
286{
70024cfb
DE
287 wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
288 wxASSERT(mdiparent);
289 if(mdiparent->m_currentChild == this)
290 mdiparent->m_currentChild = NULL;
0a67a93b 291 DestroyChildren();
e9576ca5
SC
292}
293
294void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
295{
e40298d5 296 return wxFrame::SetMenuBar( menu_bar ) ;
e9576ca5
SC
297}
298
70024cfb
DE
299void wxMDIChildFrame::MacActivate(long timestamp, bool activating)
300{
fd8278bf 301 wxLogTrace(TRACE_MDI, wxT("MDI child=%p MacActivate(0x%08lx,%s)"),this,timestamp,activating?wxT("ACTIV"):wxT("deact"));
70024cfb
DE
302 wxMDIParentFrame *mdiparent = wxDynamicCast(m_parent, wxMDIParentFrame);
303 wxASSERT(mdiparent);
304 if(activating)
305 {
306 if(s_macDeactivateWindow == m_parent)
307 {
fd8278bf 308 wxLogTrace(TRACE_MDI, wxT("parent had been scheduled for deactivation, rehighlighting"));
70024cfb 309 UMAHighlightAndActivateWindow((WindowRef)s_macDeactivateWindow->MacGetWindowRef(), true);
fd8278bf 310 wxLogTrace(TRACE_MDI, wxT("done highliting parent"));
70024cfb
DE
311 s_macDeactivateWindow = NULL;
312 }
313 else if((mdiparent->m_currentChild==this) || !s_macDeactivateWindow)
314 mdiparent->wxFrame::MacActivate(timestamp,activating);
315
316 if(mdiparent->m_currentChild && mdiparent->m_currentChild!=this)
317 mdiparent->m_currentChild->wxFrame::MacActivate(timestamp,false);
318 mdiparent->m_currentChild = this;
319
320 if(s_macDeactivateWindow==this)
321 {
fd8278bf 322 wxLogTrace(TRACE_MDI, wxT("Avoided deactivation/activation of this=%p"),this);
70024cfb
DE
323 s_macDeactivateWindow=NULL;
324 }
325 else
326 wxFrame::MacActivate(timestamp, activating);
327 }
328 else
329 {
330 // We were scheduled for deactivation, and now we do it.
331 if(s_macDeactivateWindow==this)
332 {
333 s_macDeactivateWindow = NULL;
334 wxFrame::MacActivate(timestamp,activating);
335 if(mdiparent->m_currentChild==this)
336 mdiparent->wxFrame::MacActivate(timestamp,activating);
337 }
338 else // schedule ourselves for deactivation
339 {
340 if(s_macDeactivateWindow)
fd8278bf
VZ
341 wxLogTrace(TRACE_MDI, wxT("window=%p SHOULD have been deactivated, oh well!"),s_macDeactivateWindow);
342 wxLogTrace(TRACE_MDI, wxT("Scheduling delayed deactivation"));
70024cfb
DE
343 s_macDeactivateWindow = this;
344 }
345 }
346}
347
e9576ca5
SC
348// MDI operations
349void wxMDIChildFrame::Maximize()
350{
0a67a93b 351 wxFrame::Maximize() ;
e9576ca5
SC
352}
353
354void wxMDIChildFrame::Restore()
355{
0a67a93b 356 wxFrame::Restore() ;
e9576ca5
SC
357}
358
359void wxMDIChildFrame::Activate()
360{
e9576ca5
SC
361}
362
0a67a93b
SC
363//-----------------------------------------------------------------------------
364// wxMDIClientWindow
365//-----------------------------------------------------------------------------
e9576ca5
SC
366
367wxMDIClientWindow::wxMDIClientWindow()
368{
369}
370
371wxMDIClientWindow::~wxMDIClientWindow()
372{
0a67a93b 373 DestroyChildren();
e9576ca5
SC
374}
375
376bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
377{
84be293d
KO
378 if ( !wxWindow::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style))
379 return FALSE;
e40298d5 380
0a67a93b
SC
381 wxModelessWindows.Append(this);
382 return TRUE;
e9576ca5
SC
383}
384
be7a1013
DE
385// Get size *available for subwindows* i.e. excluding menu bar.
386void wxMDIClientWindow::DoGetClientSize(int *x, int *y) const
387{
388 wxDisplaySize( x , y ) ;
389}
390
e9576ca5
SC
391// Explicitly call default scroll behaviour
392void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
393{
e9576ca5
SC
394}
395
179e085f
RN
396#endif
397