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