00001 #ifndef GUI_WX_APP_DEMO___WINDOW_MANAGER__HPP
00002 #define GUI_WX_APP_DEMO___WINDOW_MANAGER__HPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <corelib/ncbistl.hpp>
00035 #include <corelib/ncbistd.hpp>
00036 #include <corelib/ncbiobj.hpp>
00037
00038 #include <gui/widgets/wx/iwindow_manager.hpp>
00039 #include <gui/widgets/wx/splitter.hpp>
00040
00041 #include <gui/widgets/wx/dock_manager.hpp>
00042
00043 #include <gui/utils/event_handler.hpp>
00044
00045 #include <wx/panel.h>
00046 #include <wx/aui/aui.h>
00047
00048 class wxFileArtProvider;
00049
00050
00051 BEGIN_NCBI_SCOPE
00052
00053 class CDockPanel;
00054 class CDockManager;
00055 class CWindowManagerEvent;
00056 class IWMClientFactory;
00057
00058 BEGIN_SCOPE(objects)
00059 class CUser_object;
00060 END_SCOPE(objects)
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 class IWindowManagerAdvisor
00072 {
00073 public:
00074 typedef vector<IWMClient*> TClients;
00075
00076
00077
00078
00079 virtual void OnCloseClientsRequest(const TClients& clients) = 0;
00080
00081
00082 virtual void OnClientAboutToClose(IWMClient& client) = 0;
00083
00084
00085 virtual void OnClientClosed(IWMClient& client) = 0;
00086
00087
00088 virtual void OnActiveClientChanged(IWMClient* new_active) = 0;
00089
00090
00091 virtual string GetFloatingFrameTitle() = 0;
00092
00093 protected:
00094 virtual ~IWindowManagerAdvisor() {};
00095 };
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 class CWindowManager
00113 : public wxPanel,
00114 public IWindowManager,
00115 public IWMClientFactory,
00116 public CEventHandler
00117 {
00118 typedef wxPanel TParent;
00119 public:
00120 typedef vector<IWMClient*> TClients;
00121 typedef CWindowManagerEvent TEvent;
00122 typedef wxFrame TFrame;
00123
00124 public:
00125
00126 static void RegisterImageAliases(wxFileArtProvider& provider);
00127
00128 public:
00129 CWindowManager(wxFrame* frame);
00130 virtual ~CWindowManager();
00131
00132 virtual bool Create(wxWindow *parent,
00133 wxWindowID id,
00134 const wxPoint& pos = wxDefaultPosition,
00135 const wxSize& size = wxDefaultSize);
00136
00137 virtual void SetAdvisor(IWindowManagerAdvisor* advisor);
00138 virtual void SetMenuListener(IWindowManagerMenuListener* listener);
00139
00140 wxFrame* GetFrameWindow();
00141 wxWindow* GetRootWMContainer();
00142
00143
00144
00145
00146
00147 bool AddClientInTab(IWMClient& client);
00148
00149 void MoveToMainTab(IWMClient& client);
00150 wxFrame* MoveToFloatingFrame(IWMClient& client);
00151
00152 void Minimize(IWMClient& client);
00153 void Restore(IWMClient& client);
00154
00155 bool IsInMainTab(IWMClient& client) const;
00156 bool IsFloating(IWMClient& client) const;
00157 bool IsMinimized(IWMClient& client) const;
00158
00159 bool CloseClient(IWMClient& client);
00160 void CloseClients(const TClients& clients);
00161 void CloseAllClients();
00162
00163
00164 bool IsRegistered(IWMClient& client) const;
00165
00166 void GetAllClients(TClients& clients);
00167 IWMClient* GetActiveClient();
00168
00169 void ActivateClient(IWMClient& client);
00170 void ActivateClients(TClients& clients);
00171
00172 void RefreshClient(IWMClient& client);
00173
00174
00175 void ApplyLayout(const objects::CUser_object& layout);
00176 void LoadLayout(const objects::CUser_object& layout, IWMClientFactory& factory);
00177 objects::CUser_object* SaveLayout();
00178
00179 bool HasToolBar(const string& name);
00180 void AddToolBar(wxToolBar* toolbar);
00181 void DeleteToolBar(const string& name);
00182
00183
00184
00185 virtual bool ProcessEvent(wxEvent& event);
00186 virtual bool Dispatch(CEvent* evt, EDispatch disp_how, int pool);
00187
00188 void OnPostCommand(CEvent* evt);
00189 void OnCloseClientsRequestEvent(CEvent* evt);
00190 void OnMoveToTopLevel(CEvent* evt);
00191
00192 void OnLeftUp(wxMouseEvent& evt);
00193 void OnMotion(wxMouseEvent& evt);
00194 void OnMouseCaptureLost(wxMouseCaptureLostEvent& event);
00195
00196 void OnActivateWindow(wxCommandEvent& event);
00197 void OnShowWindowsDlg(wxCommandEvent& event);
00198 void OnWindowCommand(wxCommandEvent& event);
00199 void OnUpdateWindowCommand(wxUpdateUIEvent& event);
00200 void OnUpdateWindowCommand_Client(wxUpdateUIEvent& event, IWMClient* client);
00201
00202
00203
00204
00205 virtual bool OnCaptionPanelCommand(IDockPanel& panel, TCmdID cmd);
00206 virtual bool OnCloseClientsRequest(const TClients& clients);
00207 virtual IWMClient* GetClientByWindow(wxWindow* widget);
00208 virtual void OnFocusChanged(wxWindow* new_focus);
00209 virtual string GetNewFloatingFrameTitle();
00210
00211
00212
00213
00214 virtual IWMClient* CreateClient(const TFingerprint& fingerprint, wxWindow* parent);
00215
00216
00217 virtual void SetRegistryPath(const string& reg_path);
00218
00219 bool OnSetClientColor(IDockPanel& panel);
00220
00221
00222 void OnDockPanelStartDrag(CDockPanel* panel, const wxPoint& pt);
00223
00224 virtual const wxMenu* GetMenu();
00225 virtual void UpdateMenuBar(wxMenu& _menu);
00226
00227 protected:
00228 DECLARE_EVENT_MAP();
00229 DECLARE_EVENT_TABLE();
00230
00231 protected:
00232 bool x_RegisterClient(IWMClient& client);
00233 bool x_UnRegisterClient(IWMClient& client);
00234
00235 bool x_AddClient(IWMClient& client);
00236
00237 bool x_CloseClient(IWMClient& client);
00238 void x_RemoveClient(IWMClient& client);
00239
00240 void x_UpdateListener(IWMClient& client);
00241
00242 virtual void x_SetActiveClient( wxWindow* focused );
00243 virtual void x_UpdateActiveClient();
00244
00245
00246 virtual bool OnCommand(const TCmdID cmd);
00247
00248 void x_HandlePanelCommand(IWMClient& client, int cmd);
00249
00250 IDockPanel* x_GetCaptionPanelByWindow(wxWindow* widget);
00251
00252 virtual void x_UpdateWindowsMenu(wxMenu& root_menu);
00253 string x_GetClientLabelForMenu(IWMClient& client);
00254
00255 virtual void x_ResetMenuBar();
00256
00257 virtual void x_OnBeginDrag(const wxPoint& mouse_pos);
00258 virtual void x_OnDrag(const wxPoint& mouse_pos);
00259 virtual void x_OnEndDrag(const wxPoint& mouse_pos, CDockManager::EDragResult result);
00260
00261 protected:
00262 typedef map<wxWindow*, IWMClient*> TWindowToClientMap;
00263 typedef map<int, IWMClient*> TCmdToWindowMap;
00264
00265 protected:
00266
00267
00268 IWindowManagerAdvisor* m_Advisor;
00269
00270 IWindowManagerMenuListener* m_MenuListener;
00271
00272
00273 wxFrame* m_FrameWindow;
00274
00275
00276 wxAuiManager m_AuiManager;
00277
00278
00279 string m_RegPath;
00280
00281
00282 CDockManager* m_DockManager;
00283
00284
00285 TClients m_Clients;
00286
00287
00288 TWindowToClientMap m_WindowToClient;
00289
00290
00291 wxWindow* m_SavedFocus;
00292
00293
00294 IDockPanel* m_SavedFocusPanel;
00295
00296
00297 IWMClient* m_ActiveClient;
00298 CEventHandler* m_ActiveClientTarget;
00299
00300 IWMClientFactory* m_ClientFactory;
00301
00302
00303 TCmdToWindowMap m_CmdToWindow;
00304
00305
00306 auto_ptr<wxMenu> m_Menu;
00307
00308
00309 CDockPanel* m_DragDockPanel;
00310 wxPoint m_ClickPoint;
00311 bool m_IsDragging;
00312 bool m_Canceled;
00313 };
00314
00315
00316
00317
00318 class CWindowManagerEvent
00319 : public CEvent
00320 {
00321 public:
00322 enum EEventType {
00323 eClientChanged = CEvent::eEvent_MinClientID,
00324 eCloseClientsRequest,
00325 ePostCommand,
00326 };
00327
00328 CWindowManagerEvent(EEventType type, IWMClient* client);
00329 CWindowManagerEvent(IWMClient* client, TCmdID cmd);
00330 CWindowManagerEvent(EEventType type, const vector<IWMClient*>& clients);
00331
00332 IWMClient* GetClient();
00333 void GetClients(vector<IWMClient*>& clients);
00334 TCmdID GetCmd() const { return m_Cmd; }
00335
00336 protected:
00337 IWMClient* m_Client;
00338 vector<IWMClient*> m_Clients;
00339 TCmdID m_Cmd;
00340 };
00341
00342
00343 END_NCBI_SCOPE;
00344
00345 #endif // GUI_WX_APP_DEMO___WINDOW_MANAGER__HPP
00346
00347