window_manager.cpp

来自「ncbi源码」· C++ 代码 · 共 766 行 · 第 1/2 页

CPP
766
字号
/* * =========================================================================== * PRODUCTION $Log: window_manager.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 21:14:47  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3 * PRODUCTION * =========================================================================== *//*  $Id: window_manager.cpp,v 1000.1 2004/06/01 21:14:47 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/window_manager.hpp>#include <gui/widgets/workspace/wm_tab_control.hpp>#include <gui/widgets/workspace/wm_frame_window.hpp>#include <algorithm>BEGIN_NCBI_SCOPEDEFINE_MENU(BaseMenu)    SUBMENU("Window")        MENU_ITEM(eCmdInsHorzSplitter, "Insert Horz Splitter")        MENU_ITEM(eCmdInsVertSplitter, "Insert Vert Splitter")        MENU_ITEM(eCmdIns2x2Splitter, "Insert 2x2 Splitter")        MENU_ITEM(eCmdInsTabControl, "Insert Tab Control")    END_SUBMENU()END_MENU()BEGIN_CMD_MAP(CWindowManager, CCommandTarget)    ON_COMMAND_RANGE(eCmdInsHorzSplitter, eCmdInsTabControl, &CWindowManager::OnInsertSplitter)END_CMD_MAP()////////////////////////////////////////////////////////////////////////////////// CWindowManager::SClientRecCWindowManager::SClientRec::SClientRec():   m_pClient(NULL),    m_pContainer(NULL),    m_bFrame(false){}////////////////////////////////////////////////////////////////////////////////// CWindowManagerCWindowManager::CWindowManager():   Fl_Group(0, 0, 1, 1),    m_MenuRoot(NULL),    m_pRootCont(NULL),    m_PosIncr(40),    m_pObserver(NULL),    m_FrameWindow(NULL),    m_PrevFocus(NULL),    m_ActiveClient(NULL){    end();    m_FrameX = Fl::x();    m_FrameY = Fl::y();    m_DefFrameW = Fl::w() * 3 / 5;    m_DefFrameH = Fl::h() * 3 / 5;        static int ar_size[] = { 200, 200, -1    };    if(m_pRootCont == NULL) {        CWMTabControl* tab = new CWMTabControl(0, 0, 1, 1);        tab->SetResizePolicies(CTabControl::fShrink);        tab->SetManager(this);        m_pRootCont = tab;        add(tab);        resizable(tab);    }    m_MenuRoot = CreateMenuItems(BaseMenu);}CWindowManager::~CWindowManager(){    RemoveAllClients();    delete m_pRootCont;    /*ITERATE(TClientToRecMap, it, m_ClientToRec)  {        delete it->second;    }*/    delete m_MenuRoot;}void    CWindowManager::SetObserver(IWindowManagerObserver* observer){    m_pObserver = observer;}Fl_Group*  CWindowManager::GetRootWMContainer(){    return dynamic_cast<Fl_Group*>(m_pRootCont);}bool    CWindowManager::AddClientInFrame(IWMClient* client){    return x_AddClient(client, true);}bool    CWindowManager::AddClientInTab(IWMClient* client){    return x_AddClient(client, false);}bool    CWindowManager::x_AddClient(IWMClient* client, bool b_frame){    Fl_Widget* widget = dynamic_cast<Fl_Widget*>(client);    if(widget)  {        if(x_RegisterClient(client))    {            // menus            const CMenuItem* root = client->GetMenu();            if(root)    { // merge Client's menu into Manager's menu                m_MenuRoot->Merge(*root);            }            if(m_FrameWindow)   { // merge Client's menu into Frame's menu                m_FrameWindow->MergeMenu(*root);            }            // add to command routing            CCommandTarget* target = dynamic_cast<CCommandTarget*>(client);            if(target)  {                AddChildCmdTarget(target);            }                    if(b_frame) {                x_PutClientInFrame(client);            }   else {                x_PutClientInTab(client);            }            return true;        }    }    _ASSERT(false);    return false;}bool    CWindowManager::MoveClientToFrame(IWMClient* client){    if(client  &&  GetClientState(client) != eFloating)  {        x_RemoveClient(client);        x_PutClientInFrame(client);        x_UpdateObserver(client);        return true;    }    return false;}bool    CWindowManager::MoveClientToTab(IWMClient* client){    if(client  &&  GetClientState(client) != eDocked)    {        x_RemoveClient(client);        x_PutClientInTab(client);        x_UpdateObserver(client);        return true;    }    return false;}    bool    CWindowManager::FrameCommand(IWMClient* client, EFrameCmd cmd){    const SClientRec* p_rec = x_GetClientRec(client);    if(p_rec)   {        CWMFrameWindow* p_frame =             dynamic_cast<CWMFrameWindow*>(p_rec->m_pContainer);        if(p_frame) {            switch(cmd) {            case    eActivate:  p_frame->show(); break;            case    eMaximize:  {                //if(p_frame->IsMinimized())                //    p_frame->show();                p_frame->fullscreen();             };  break;            case    eMinimize:  p_frame->iconize(); break;            case    eRestore:  {                p_frame->show();                //p_frame->fullscreen_off();            }; break;            };        }    }    return false;}void    CWindowManager::GetPopupItems(IWMContainer* container, const IWMPosition& pos,                                   vector<CMenuItem*>& items){    m_PseudoCmdCount = 0;    m_PseudoCmdMap.clear();    if(container)   {        /*if(container != m_pRootCont)    {            items.push_back(new CMenuItem("Delete Container", eCmdDelContainer));            items.push_back(new CMenuItem()); // separator        }*/        if(container->IsVacant(pos))    {            items.push_back(new CMenuItem("Insert Horz Splitter", eCmdInsHorzSplitter));            items.push_back(new CMenuItem("Insert Vert Splitter", eCmdInsVertSplitter));            items.push_back(new CMenuItem("Insert 2x2 Splitter", eCmdIns2x2Splitter));            items.push_back(new CMenuItem("Insert Tab Control", eCmdInsTabControl));                        // eCmdMoveFromFrame submenu            CMenuItem* submenu = x_GetMoveFromFrameMenu(container, pos);            if(submenu) {                items.push_back(new CMenuItem()); // separator                items.push_back(submenu);            }            // eCmdMoveHere submenu                        submenu = x_GetMoveHereMenu(container, pos);            if(submenu) {                items.push_back(new CMenuItem()); // separator                items.push_back(submenu);            }        } else {            if(items.size())                items.push_back(new CMenuItem());                        if(dynamic_cast<const CWMTabPos*>(&pos))  {                items.push_back(new CMenuItem("Delete Tab", eCmdDelTabPane));            }            items.push_back(new CMenuItem("Move to Frame", eCmdMoveToFrame));        }    }}/// generates a pseudo-command for popup menus. PSeudo command encodes both the/// real command and the client this command should be applied to.int CWindowManager::x_GeneratePseudoCommand(IWMClient* client, int cmd){    int pseudo_cmd = eCmdClientXXXX + m_PseudoCmdCount;    m_PseudoCmdMap[pseudo_cmd] = make_pair(client, cmd);    m_PseudoCmdCount++;    return pseudo_cmd;}CMenuItem*  CWindowManager::x_GetMoveFromFrameMenu(IWMContainer* container,                                                    const IWMPosition& pos){    CMenuItem* p_submenu = NULL;    if(container->IsVacant(pos)) {        int i = 0;        ITERATE(TClientToRecMap, it, m_ClientToRec) {            SClientRec* p_rec = it->second;            if(p_rec->m_pContainer  && p_rec->m_bFrame) {                if(! p_submenu)                    p_submenu = new CMenuItem("Dock Here");                                 int pcmd = x_GeneratePseudoCommand(p_rec->m_pClient, eCmdMoveFromFrame);                p_submenu->AddSubItem(p_rec->m_pClient->GetLabel(), pcmd);            }        }    }    return p_submenu;}CMenuItem*  CWindowManager::x_GetMoveHereMenu(IWMContainer* container,                                                    const IWMPosition& pos){    CMenuItem* p_submenu = NULL;    if(container->IsVacant(pos)) {        int i = 0;        ITERATE(TClientToRecMap, it, m_ClientToRec) {            SClientRec* p_rec = it->second;            if(! (p_rec->m_pContainer  && p_rec->m_bFrame)) {                if(! p_submenu)                    p_submenu = new CMenuItem("Move Here");                                                int pcmd = x_GeneratePseudoCommand(p_rec->m_pClient, eCmdMoveToPos);                p_submenu->AddSubItem(p_rec->m_pClient->GetLabel(), pcmd);            }        }    }    return p_submenu;}bool    CWindowManager::OnContainerCommand(IWMContainer* container, const IWMPosition& pos,                                            TCmdID cmd){    if(container)   {        switch(cmd) {        case eCmdInsHorzSplitter:   {            x_InsertSplitter(container, pos, CSplitter::eHorizontal);            return true;        };        case eCmdInsVertSplitter:   {            x_InsertSplitter(container, pos, CSplitter::eVertical);            return true;        };        case eCmdIns2x2Splitter:   {            x_InsertSplitter(container, pos, CSplitter::eGrid);            return true;        };        case eCmdInsTabControl:   {            CWMTabControl* tab = new CWMTabControl(0, 0, 200, 200);            tab->SetManager(this);                container->Insert(tab, pos);            return true;        }; break;        case eCmdDelContainer:  x_RemoveContainer(container);        case eCmdDelTabPane:    x_Remove(container, pos);   return true;        case eCmdMoveToFrame:   OnMoveToFrame(container, pos);    return true;        default:             if(cmd >= eCmdClientXXXX  &&  cmd < eCmdClientLast)  {                return x_OnPseudoCommand(container, pos, cmd);                }        }    }    return false;}bool    CWindowManager::x_OnPseudoCommand(IWMContainer* container, const IWMPosition& pos,                                            TCmdID cmd){    TPseudoCmdMap::iterator it = m_PseudoCmdMap.find(cmd);    if(it != m_PseudoCmdMap.end())  {        IWMClient* p_client = it->second.first;        int orig_cmd = it->second.second;                switch(orig_cmd)    {        case eCmdMoveToPos:    {            x_RemoveClient(p_client);            x_InsertClient(p_client, container, pos);            x_UpdateObserver(p_client);            return true;        }; break;        case eCmdMoveFromFrame:    {            x_RemoveClient(p_client);            x_InsertClient(p_client, container, pos);            x_UpdateObserver(p_client);            return true;        }; break;        default: break;        }; //switch    } else _ASSERT(false);    return false;}   void    CWindowManager::OnMoveToFrame(IWMContainer* container, const IWMPosition& pos){    _ASSERT(pos.IsValid());        Fl_Widget* widget = container->GetChild(pos);    IWMClient* p_client = dynamic_cast<IWMClient*>(widget);    if(p_client)    {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?