workspace.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:9k
- /*
- * ===========================================================================
- * PRODUCTION $Log: workspace.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 21:14:56 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: workspace.cpp,v 1000.1 2004/06/01 21:14:56 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Andrey Yazhuk
- *
- * File Description:
- *
- */
- #include <ncbi_pch.hpp>
- #include <gui/widgets/workspace/workspace.hpp>
- #include <gui/widgets/workspace/test_client.hpp>
- #include <FL/Fl_Image.H>
- #include <FL/Fl_BMP_Image.H>
- BEGIN_NCBI_SCOPE
- CClientBrowser::CClientBrowser(int x, int y, int w, int h)
- : CTreeBrowser(x, y, w, h)
- {
- label("Clients");
- show_root(true);
- always_open(true);
- }
- void CClientBrowser::AddClient(IWMClient* client)
- {
- Node* p_node = AddLeaf(client->GetLabel());
- p_node->user_data(client);
- m_ClientToNode[client] = p_node;
- }
- void CClientBrowser::Update(CWindowManager& manager)
- {
-
- NON_CONST_ITERATE(TClientToNodeMap, it,m_ClientToNode) {
- IWMClient* p_client = it->first;
-
- CWindowManager::EClientState state = manager.GetClientState(p_client);
- string s = p_client->GetLabel();
- s += " [";
- switch(state) {
- case CWindowManager::eFloating: s += "Floating"; break;
- case CWindowManager::eDocked: s += "Docked"; break;
- case CWindowManager::eHidden: s += "Hiddden"; break;
- };
- s += "]";
-
- remove(it->second);
- Node* p_node = it->second = AddLeaf(s);
- p_node->user_data(p_client);
-
- m_ClientToNode[p_client] = p_node;
- }
- }
- void CClientBrowser::GetSelectedClients(vector<IWMClient*>& clients)
- {
- clients.clear();
- int n = num_selected();
- for( int i = 0; i < n; i++ ) {
- CTreeBrowser::Node* p_node = get_selected(i + 1);
-
- IWMClient* p_client = reinterpret_cast<IWMClient*>(p_node->user_data());
- clients.push_back(p_client);
- }
- }
- static
- DEFINE_MENU(Menu)
- SUBMENU("Workspace")
- MENU_ITEM(eCmdNewClient, "Create Client")
- MENU_ITEM(eCmdNewClientInTab, "Create Client in Tab")
- END_SUBMENU()
- SUBMENU("Window Manager")
- MENU_ITEM(eCmdActivateClient, "Activate Client")
- MENU_ITEM(eCmdDockClient, "Dock Client")
- MENU_ITEM(eCmdUndockClient, "Undock Client")
- MENU_ITEM(eCmdHideClient, "Hide Client")
- MENU_SEPARATOR()
- MENU_ITEM(eCmdMaximizeClient, "Maximize Client")
- MENU_ITEM(eCmdRestoreClient, "Restore Client")
- MENU_ITEM(eCmdMinimizeClient, "Minimize Client")
- END_SUBMENU()
- END_MENU()
- CWorkspace::CWorkspace(int x, int y, int w, int h, const char* label)
- : Fl_Group(x, y, w, h, label),
- m_FrameWindow(NULL),
- m_ClientsCount(0)
- {
- m_MenuRoot = CreateMenuItems(Menu);
- // create root vertical splitter
- m_pRootSplitter = new CSplitter(x, y, w, h);
- resizable(m_pRootSplitter);
- vector<int> widths;
- widths.push_back(w / 4);
- widths.push_back(w * 3 / 4);
- m_pRootSplitter->Create(CSplitter::eVertical, widths);
-
- end(); // end of immediate children
- m_WindowManager = new CWindowManager();
- AddChildCmdTarget(m_WindowManager);
- m_pRootSplitter->InsertToCell(m_WindowManager, 1, 0);
- // create horizontal splitter
- m_pLeftSplitter = new CSplitter(0, 0, 0, 0);
- vector<int> heights;
- heights.push_back(h / 2);
- heights.push_back(h / 2);
- m_pLeftSplitter->Create(CSplitter::eHorizontal, heights);
- m_pRootSplitter->InsertToCell(m_pLeftSplitter, 0, 0);
- //create browser
- m_pClientBrowser = new CClientBrowser(0, 0, 0, 0);
- m_pLeftSplitter->InsertToCell(m_pClientBrowser, 0, 0);
- m_WindowManager->SetObserver(this);
- }
- CWorkspace::~CWorkspace()
- {
- delete m_MenuRoot;
- //##delete m_WindowManager;
- }
- void CWorkspace::SetFrameWindow(CFrameWindow* frame)
- {
- m_FrameWindow = frame;
- m_WindowManager->SetFrameWindow(frame);
- }
- const CMenuItem* CWorkspace::GetMenu() const
- {
- _ASSERT(m_WindowManager);
- CMenuItem* root = m_MenuRoot;
- const CMenuItem* wm_menu = m_WindowManager->GetMenu();
- if(wm_menu) {
- root = root->Clone();
- root->Merge(*wm_menu);
- }
- return root; // memory leak
- }
- BEGIN_CMD_MAP(CWorkspace, CCommandTarget)
- ON_COMMAND(eCmdNewClient, &CWorkspace::OnNewClient)
- ON_COMMAND(eCmdNewClientInTab, &CWorkspace::OnNewClientInTab)
- ON_COMMAND(eCmdActivateClient, &CWorkspace::OnActivateClient)
- ON_COMMAND(eCmdDockClient, &CWorkspace::OnDockClient)
- ON_COMMAND(eCmdUndockClient, &CWorkspace::OnUndockClient)
- ON_COMMAND(eCmdHideClient, &CWorkspace::OnHideClient)
- ON_COMMAND(eCmdMaximizeClient, &CWorkspace::OnMaximizeClient)
- ON_COMMAND(eCmdMinimizeClient, &CWorkspace::OnMinimizeClient)
- ON_COMMAND(eCmdRestoreClient, &CWorkspace::OnRestoreClient)
- END_CMD_MAP()
- void CWorkspace::OnClientChanged(IWMClient* client)
- {
- _ASSERT(m_pClientBrowser);
- ///### stupid implementation for now
- m_pClientBrowser->Update(*m_WindowManager);
- }
- static int m_ClientsCount = 0;
- void CWorkspace::OnNewClient()
- {
- int type = m_ClientsCount % 3 + 1;
- string label = "Client " + NStr::IntToString(m_ClientsCount + 1);
- CFLTestClient* client = new CFLTestClient(type, label.c_str());
- m_ClientsCount++;
-
- m_WindowManager->AddClientInFrame(client);
-
- m_pClientBrowser->AddClient(client);
- m_pClientBrowser->Update(*m_WindowManager);
- }
- void CWorkspace::OnNewClientInTab()
- {
- int type = m_ClientsCount % 3 + 1;
- string label = "Client " + NStr::IntToString(m_ClientsCount + 1);
- CFLTestClient* client = new CFLTestClient(type, label.c_str());
- m_ClientsCount++;
-
- m_WindowManager->AddClientInTab(client);
-
- m_pClientBrowser->AddClient(client);
- m_pClientBrowser->Update(*m_WindowManager);
- }
- void CWorkspace::OnActivateClient()
- {
- x_DoFrameClientCmd(CWindowManager::eActivate);
- }
- void CWorkspace::OnDockClient()
- {
- TClients clients;
- m_pClientBrowser->GetSelectedClients(clients);
- ITERATE(TClients, it, clients) {
- m_WindowManager->MoveClientToTab(*it);
- }
- }
- void CWorkspace::OnUndockClient()
- {
- TClients clients;
- m_pClientBrowser->GetSelectedClients(clients);
- ITERATE(TClients, it, clients) {
- m_WindowManager->MoveClientToFrame(*it);
- }
- }
- void CWorkspace::OnHideClient()
- {
- TClients clients;
- m_pClientBrowser->GetSelectedClients(clients);
- ITERATE(TClients, it, clients) {
- m_WindowManager->RemoveClient(*it);
- }
- }
- void CWorkspace::OnMaximizeClient()
- {
- x_DoFrameClientCmd(CWindowManager::eMaximize);
- }
- void CWorkspace::OnMinimizeClient()
- {
- x_DoFrameClientCmd(CWindowManager::eMinimize);
- }
- void CWorkspace::OnRestoreClient()
- {
- x_DoFrameClientCmd(CWindowManager::eRestore);
- }
- void CWorkspace::x_DoFrameClientCmd(CWindowManager::EFrameCmd cmd)
- {
- TClients clients;
- m_pClientBrowser->GetSelectedClients(clients);
- ITERATE(TClients, it, clients) {
- m_WindowManager->FrameCommand(*it, cmd);
- }
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: workspace.cpp,v $
- * Revision 1000.1 2004/06/01 21:14:56 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4
- *
- * Revision 1.4 2004/05/21 22:27:56 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.3 2004/05/07 14:24:53 yazhuk
- * Implemented IFrameWindowClient interface; refactoring
- *
- * Revision 1.2 2004/02/05 16:17:20 ucko
- * Remove redundant const from menu definition.
- *
- * Revision 1.1 2004/02/04 19:41:28 yazhuk
- * Initial revision
- *
- * ===========================================================================
- */