1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/msw/mdi.h
3 // Purpose:     MDI (Multiple Document Interface) classes
4 // Author:      Julian Smart
5 // Modified by: 2008-10-31 Vadim Zeitlin: derive from the base classes
6 // Created:     01/02/97
7 // Copyright:   (c) 1997 Julian Smart
8 //              (c) 2008 Vadim Zeitlin
9 // Licence:     wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef _WX_MSW_MDI_H_
13 #define _WX_MSW_MDI_H_
14 
15 #include "wx/frame.h"
16 
17 class WXDLLIMPEXP_FWD_CORE wxAcceleratorTable;
18 
19 // ---------------------------------------------------------------------------
20 // wxMDIParentFrame
21 // ---------------------------------------------------------------------------
22 
23 class WXDLLIMPEXP_CORE wxMDIParentFrame : public wxMDIParentFrameBase
24 {
25 public:
wxMDIParentFrame()26     wxMDIParentFrame() { Init(); }
27     wxMDIParentFrame(wxWindow *parent,
28                      wxWindowID id,
29                      const wxString& title,
30                      const wxPoint& pos = wxDefaultPosition,
31                      const wxSize& size = wxDefaultSize,
32                      long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL,
33                      const wxString& name = wxASCII_STR(wxFrameNameStr))
34     {
35         Init();
36 
37         Create(parent, id, title, pos, size, style, name);
38     }
39 
40     virtual ~wxMDIParentFrame();
41 
42     bool Create(wxWindow *parent,
43                 wxWindowID id,
44                 const wxString& title,
45                 const wxPoint& pos = wxDefaultPosition,
46                 const wxSize& size = wxDefaultSize,
47                 long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL,
48                 const wxString& name = wxASCII_STR(wxFrameNameStr));
49 
50     // override/implement base class [pure] virtual methods
51     // ----------------------------------------------------
52 
IsTDI()53     static bool IsTDI() { return false; }
54 
55     // we don't store the active child in m_currentChild so override this
56     // function to find it dynamically
57     virtual wxMDIChildFrame *GetActiveChild() const wxOVERRIDE;
58 
59     virtual void Cascade() wxOVERRIDE;
60     virtual void Tile(wxOrientation orient = wxHORIZONTAL) wxOVERRIDE;
61     virtual void ArrangeIcons() wxOVERRIDE;
62     virtual void ActivateNext() wxOVERRIDE;
63     virtual void ActivatePrevious() wxOVERRIDE;
64 
65 #if wxUSE_MENUS
66     virtual void SetWindowMenu(wxMenu* menu) wxOVERRIDE;
67 
68     virtual void DoMenuUpdates(wxMenu* menu = NULL) wxOVERRIDE;
69 
70     // return the active child menu, if any
71     virtual WXHMENU MSWGetActiveMenu() const wxOVERRIDE;
72 #endif // wxUSE_MENUS
73 
74 
75     // implementation only from now on
76 
77     // MDI helpers
78     // -----------
79 
80 #if wxUSE_MENUS
81     // called by wxMDIChildFrame after it was successfully created
82     virtual void AddMDIChild(wxMDIChildFrame *child);
83 
84     // called by wxMDIChildFrame just before it is destroyed
85     virtual void RemoveMDIChild(wxMDIChildFrame *child);
86 #endif // wxUSE_MENUS
87 
88     // Retrieve the current window menu label: it can be different from
89     // "Window" when using non-English translations and can also be different
90     // from wxGetTranslation("Window") if the locale has changed since the
91     // "Window" menu was added.
MSWGetCurrentWindowMenuLabel()92     const wxString& MSWGetCurrentWindowMenuLabel() const
93         { return m_currentWindowMenuLabel; }
94 
95     // handlers
96     // --------
97 
98     // Responds to colour changes
99     void OnSysColourChanged(wxSysColourChangedEvent& event);
100 
101     void OnActivate(wxActivateEvent& event);
102     void OnSize(wxSizeEvent& event);
103     void OnIconized(wxIconizeEvent& event);
104 
105     bool HandleActivate(int state, bool minimized, WXHWND activate);
106 
107     // override window proc for MDI-specific message processing
108     virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) wxOVERRIDE;
109 
110     virtual WXLRESULT MSWDefWindowProc(WXUINT, WXWPARAM, WXLPARAM) wxOVERRIDE;
111     virtual bool MSWTranslateMessage(WXMSG* msg) wxOVERRIDE;
112 
113 #if wxUSE_MENUS
114     // override the menu-relayed methods to also look in the active child menu
115     // bar and the "Window" menu
116     virtual wxMenuItem *FindItemInMenuBar(int menuId) const wxOVERRIDE;
117     virtual wxMenu* MSWFindMenuFromHMENU(WXHMENU hMenu) wxOVERRIDE;
118 #endif // wxUSE_MENUS
119 
120 protected:
121 #if wxUSE_MENUS_NATIVE
122     virtual void InternalSetMenuBar() wxOVERRIDE;
123 #endif // wxUSE_MENUS_NATIVE
124 
125     virtual WXHICON GetDefaultIcon() const wxOVERRIDE;
126 
127     // set the size of the MDI client window to match the frame size
128     void UpdateClientSize();
129 
130 private:
131     // common part of all ctors
132     void Init();
133 
134 #if wxUSE_MENUS
135     // "Window" menu commands event handlers
136     void OnMDICommand(wxCommandEvent& event);
137     void OnMDIChild(wxCommandEvent& event);
138 
139 
140     // add/remove window menu if we have it (i.e. m_windowMenu != NULL)
141     void AddWindowMenu();
142     void RemoveWindowMenu();
143 
144     // update the window menu (if we have it) to enable or disable the commands
145     // which only make sense when we have more than one child
146     void UpdateWindowMenu(bool enable);
147 
148 #if wxUSE_ACCEL
149     wxAcceleratorTable *m_accelWindowMenu;
150 #endif // wxUSE_ACCEL
151 #endif // wxUSE_MENUS
152 
153     // return the number of child frames we currently have (maybe 0)
154     int GetChildFramesCount() const;
155 
156     // if true, indicates whether the event wasn't really processed even though
157     // it was "handled", see OnActivate() and HandleActivate()
158     bool m_activationNotHandled;
159 
160     // holds the current translation for the window menu label
161     wxString m_currentWindowMenuLabel;
162 
163 
164     friend class WXDLLIMPEXP_FWD_CORE wxMDIChildFrame;
165 
166     wxDECLARE_EVENT_TABLE();
167     wxDECLARE_DYNAMIC_CLASS(wxMDIParentFrame);
168     wxDECLARE_NO_COPY_CLASS(wxMDIParentFrame);
169 };
170 
171 // ---------------------------------------------------------------------------
172 // wxMDIChildFrame
173 // ---------------------------------------------------------------------------
174 
175 class WXDLLIMPEXP_CORE wxMDIChildFrame : public wxMDIChildFrameBase
176 {
177 public:
wxMDIChildFrame()178     wxMDIChildFrame() { Init(); }
179     wxMDIChildFrame(wxMDIParentFrame *parent,
180                     wxWindowID id,
181                     const wxString& title,
182                     const wxPoint& pos = wxDefaultPosition,
183                     const wxSize& size = wxDefaultSize,
184                     long style = wxDEFAULT_FRAME_STYLE,
185                     const wxString& name = wxASCII_STR(wxFrameNameStr))
186     {
187         Init();
188 
189         Create(parent, id, title, pos, size, style, name);
190     }
191 
192     bool Create(wxMDIParentFrame *parent,
193                 wxWindowID id,
194                 const wxString& title,
195                 const wxPoint& pos = wxDefaultPosition,
196                 const wxSize& size = wxDefaultSize,
197                 long style = wxDEFAULT_FRAME_STYLE,
198                 const wxString& name = wxASCII_STR(wxFrameNameStr));
199 
200     virtual ~wxMDIChildFrame();
201 
202     // implement MDI operations
203     virtual void Activate() wxOVERRIDE;
204 
205     // Override some frame operations too
206     virtual void Maximize(bool maximize = true) wxOVERRIDE;
207     virtual void Restore() wxOVERRIDE;
208 
209     virtual bool Show(bool show = true) wxOVERRIDE;
210 
211     // Implementation only from now on
212     // -------------------------------
213 
214     // Handlers
215     bool HandleMDIActivate(long bActivate, WXHWND, WXHWND);
216     bool HandleWindowPosChanging(void *lpPos);
217     bool HandleGetMinMaxInfo(void *mmInfo);
218 
219     virtual WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) wxOVERRIDE;
220     virtual WXLRESULT MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) wxOVERRIDE;
221     virtual bool MSWTranslateMessage(WXMSG *msg) wxOVERRIDE;
222 
223     virtual void MSWDestroyWindow() wxOVERRIDE;
224 
225     bool ResetWindowStyle(void *vrect);
226 
227     void OnIdle(wxIdleEvent& event);
228 
229 protected:
230     virtual void DoGetScreenPosition(int *x, int *y) const wxOVERRIDE;
231     virtual void DoGetPosition(int *x, int *y) const wxOVERRIDE;
232     virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags) wxOVERRIDE;
233     virtual void DoSetClientSize(int width, int height) wxOVERRIDE;
234     virtual void InternalSetMenuBar() wxOVERRIDE;
IsMDIChild()235     virtual bool IsMDIChild() const wxOVERRIDE { return true; }
236     virtual void DetachMenuBar() wxOVERRIDE;
237 
238     virtual WXHICON GetDefaultIcon() const wxOVERRIDE;
239 
240     // common part of all ctors
241     void Init();
242 
243 private:
244     bool m_needsResize; // flag which tells us to artificially resize the frame
245 
246     wxDECLARE_EVENT_TABLE();
247     wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxMDIChildFrame);
248 };
249 
250 // ---------------------------------------------------------------------------
251 // wxMDIClientWindow
252 // ---------------------------------------------------------------------------
253 
254 class WXDLLIMPEXP_CORE wxMDIClientWindow : public wxMDIClientWindowBase
255 {
256 public:
wxMDIClientWindow()257     wxMDIClientWindow() { Init(); }
258 
259     // Note: this is virtual, to allow overridden behaviour.
260     virtual bool CreateClient(wxMDIParentFrame *parent,
261                               long style = wxVSCROLL | wxHSCROLL) wxOVERRIDE;
262 
263     // Explicitly call default scroll behaviour
264     void OnScroll(wxScrollEvent& event);
265 
266 protected:
267     virtual void DoSetSize(int x, int y,
268                            int width, int height,
269                            int sizeFlags = wxSIZE_AUTO) wxOVERRIDE;
270 
Init()271     void Init() { m_scrollX = m_scrollY = 0; }
272 
273     int m_scrollX, m_scrollY;
274 
275 private:
276     wxDECLARE_EVENT_TABLE();
277     wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxMDIClientWindow);
278 };
279 
280 #endif // _WX_MSW_MDI_H_
281