include/gui/widgets/wx/window_manager.hpp

Go to the documentation of this file.
00001 #ifndef GUI_WX_APP_DEMO___WINDOW_MANAGER__HPP
00002 #define GUI_WX_APP_DEMO___WINDOW_MANAGER__HPP
00003 
00004 /*  $Id: window_manager.hpp 19649 2009-07-20 22:48:36Z voronov $
00005  * ===========================================================================
00006  *
00007  *                            PUBLIC DOMAIN NOTICE
00008  *               National Center for Biotechnology Information
00009  *
00010  *  This software/database is a "United States Government Work" under the
00011  *  terms of the United States Copyright Act.  It was written as part of
00012  *  the author's official duties as a United States Government employee and
00013  *  thus cannot be copyrighted.  This software/database is freely available
00014  *  to the public for use. The National Library of Medicine and the U.S.
00015  *  Government have not placed any restriction on its use or reproduction.
00016  *
00017  *  Although all reasonable efforts have been taken to ensure the accuracy
00018  *  and reliability of the software and data, the NLM and the U.S.
00019  *  Government do not and cannot warrant the performance or results that
00020  *  may be obtained by using this software or data. The NLM and the U.S.
00021  *  Government disclaim all warranties, express or implied, including
00022  *  warranties of performance, merchantability or fitness for any particular
00023  *  purpose.
00024  *
00025  *  Please cite the author in any work or product based on this material.
00026  *
00027  * ===========================================================================
00028  *
00029  * Authors:  Andrey Yazhuk
00030  *
00031  * File Description:
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 /// IWindowManagerAdvisor
00064 ///
00065 /// This interface represents the context in which Window Manager operates,
00066 /// Window Manager delegates some of the functions / decisions to the Advisor.
00067 /// These functions should be implemented by the application to allow
00068 /// the application components to control the life cycle of IWMClients
00069 /// managed by Window Manager.
00070 
00071 class  IWindowManagerAdvisor
00072 {
00073 public:
00074     typedef vector<IWMClient*>  TClients;
00075 
00076     /// indicates that user requested closing the following clients
00077     /// (by pressing a "close" button, selecting a command etc.)
00078     /// Advisor must take necessary actions to close the clients (if needed).
00079     virtual void    OnCloseClientsRequest(const TClients& clients) = 0;
00080 
00081     /// called before removing the client
00082     virtual void    OnClientAboutToClose(IWMClient& client) = 0;
00083 
00084     /// called after the client has been removed
00085     virtual void    OnClientClosed(IWMClient& client) = 0;
00086 
00087     /// called when Active Client is changed (i.e. focus goes into another client)
00088     virtual void    OnActiveClientChanged(IWMClient* new_active) = 0;
00089 
00090     /// returns the title for the floating frames created by the Window Manager
00091     virtual string  GetFloatingFrameTitle() = 0;
00092 
00093 protected:
00094     virtual ~IWindowManagerAdvisor()    {};
00095 };
00096 
00097 
00098 ///////////////////////////////////////////////////////////////////////////////
00099 ///  CWindowManager - component controlling windowing of client windows.
00100 ///
00101 /// CWindowManager provides centralized control over multiple clients (views)
00102 /// associated with an application. Window Manager provides two ways to
00103 /// place clients - in independent top-level frame windows (Floating Frame)
00104 ///  or in containers embedded into manager's main window (docked). CWindowManager
00105 /// allows for dynamic creation of hierarchical layouts consisting of containers
00106 /// such as CSplitter and CTabControl and clients.
00107 /// IWMClient interface represents an abstract client window that can  be
00108 /// managed by CWindowManager. IWMContainer interface represents an abstract
00109 /// container that can be embedded into CWindowManager. IWMCPosition
00110 /// represents abstract notion of position in IWMContainer.
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     /// registers graphical resources used by Window Manager
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     /// @name Client manipulation routines
00144     /// @{
00145 
00146     /// adds the client to the Main Tabbed Pane
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     /// checks if the client in registered in the Window Manager
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     /// @name Event handlers
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     /// @name IWindowManager implementation
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     /// @name IWMClientFactory implementation
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     /// Called by CDockPanel to delegated DnD handling to Window Manager
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     /// overriding CCommandTarget behavior
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     /// Advisor is an external object that wants to customize the behavior
00267     /// of Window Manager by providing a callback interface
00268     IWindowManagerAdvisor*  m_Advisor;
00269 
00270     IWindowManagerMenuListener* m_MenuListener;
00271 
00272     /// main frame window hosting window manager
00273     wxFrame*        m_FrameWindow;
00274 
00275     /// wxAuiManager is required for CNotebook
00276     wxAuiManager    m_AuiManager;
00277 
00278     // path to the setting in CGuiRegistry
00279     string m_RegPath;
00280 
00281     /// the Docking Manager associated with this Window Manager
00282     CDockManager* m_DockManager;
00283 
00284     /// the collection of registered Client
00285     TClients  m_Clients;
00286 
00287     /// index wxWindow -> IWMClient
00288     TWindowToClientMap  m_WindowToClient;
00289 
00290     /// widget that was previously focused
00291     wxWindow* m_SavedFocus;
00292 
00293     /// caption panel containing m_SavedFocus
00294     IDockPanel* m_SavedFocusPanel;
00295 
00296     /// belonging to focused IWMClient
00297     IWMClient*     m_ActiveClient;
00298     CEventHandler* m_ActiveClientTarget;
00299 
00300     IWMClientFactory* m_ClientFactory;
00301 
00302     // a map for associating runtime generated command IDs with windows
00303     TCmdToWindowMap   m_CmdToWindow;
00304 
00305     // the latest menu
00306     auto_ptr<wxMenu>    m_Menu;
00307 
00308     // Dock Panel dragging
00309     CDockPanel*   m_DragDockPanel; // the panel being dragged
00310     wxPoint m_ClickPoint; // the point where DnD started
00311     bool    m_IsDragging; // DnD is in progress
00312     bool    m_Canceled;   // Dnd has been canceled
00313 };
00314 
00315 
00316 ///////////////////////////////////////////////////////////////////////////////
00317 /// CWindowManagerEvent
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; //TODO
00338     vector<IWMClient*>  m_Clients; //TODO
00339     TCmdID  m_Cmd; // the command posted
00340 };
00341 
00342 
00343 END_NCBI_SCOPE;
00344 
00345 #endif  // GUI_WX_APP_DEMO___WINDOW_MANAGER__HPP
00346 
00347 

Generated on Sun Dec 6 22:05:39 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Mon Dec 07 16:20:38 2009 by modify_doxy.py rev. 173732