frame_window.cpp
来自「ncbi源码」· C++ 代码 · 共 323 行
CPP
323 行
/* * =========================================================================== * PRODUCTION $Log: frame_window.cpp,v $ * PRODUCTION Revision 1000.0 2004/06/01 21:32:04 gouriano * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.4 * PRODUCTION * =========================================================================== *//* $Id: frame_window.cpp,v 1000.0 2004/06/01 21:32:04 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/frame_window.hpp>#include <gui/utils/accel_table.hpp>BEGIN_NCBI_SCOPEconst static double kUpdateUIPeriod = 0.5;const static int kUpdateTimerID = 1;CFrameWindow::CFrameWindow(int w, int h, const char* title): TParent(w, h, title), m_BaseMenu(NULL), m_MenuBar(NULL), m_MenuBarH(0), m_CmdHintSlot(-1), m_StatusBarH(24), m_ClientGroup(NULL), m_Client(NULL), m_CmdTarget(NULL){ m_BaseMenu = new CMenuItem("Root"); m_MenuBar = new CMenuBar1(0 , 0, w, 0); m_MenuBar->SetItems(m_BaseMenu); m_MenuBarH = m_MenuBar->GetPreferredSize().Y(); m_MenuBar->size(w, m_MenuBarH); m_MenuBar->SetCmdTarget(this); m_MenuBar->SetHintListener(this); m_ClientGroup = new Fl_Group(0, m_MenuBarH, w, h - m_MenuBarH - m_StatusBarH); m_ClientGroup->box(FL_DOWN_BOX); m_ClientGroup->color(FL_WHITE); x_SetupStatusBar(); resizable(m_ClientGroup); end(); m_UpdateUITimer.Init(kUpdateTimerID, kUpdateUIPeriod, true, this); m_Event.StandardConfig();}CFrameWindow::~CFrameWindow(){ hide(); delete m_MenuBar;}/// override this function in derived class to create application-specific status barvoid CFrameWindow::x_SetupStatusBar(){ m_StatusBar = new CStatusBar1(0, h() - m_StatusBarH, w(), m_StatusBarH); m_CmdHintSlot = m_StatusBar->CreateSlot(200); m_StatusBar->SetSlotStyles(m_CmdHintSlot, ISBSlot::fResizable); /*CStatusBar1::TSlotHandle h_slot2 = m_StatusBar->CreateSlot(150); m_StatusBar->SetSlotStyles(h_slot2, ISBSlot::fDownBox | ISBSlot::fCenterText); m_StatusBar->SetSlotText(h_slot2, "The second one"); CStatusBar1::TSlotHandle h_slot3 = m_StatusBar->CreateSlot(40); m_StatusBar->SetSlotStyles(h_slot3, ISBSlot::fUpBox | ISBSlot::fCenterText); m_StatusBar->SetSlotText(h_slot3, "Ins");*/}void CFrameWindow::ResetMenu(const CMenuItem& item){ m_MenuBar->SetItems((CMenuItem*) NULL); //reset m_BaseMenu = new CMenuItem("Root"); m_BaseMenu->Merge(item); m_MenuBar->SetItems(m_BaseMenu->Clone()); x_AddClientMenu(); m_MenuBarH = m_MenuBar->GetPreferredSize().Y(); x_Layout(); redraw();}void CFrameWindow::ResetMenu(){ m_MenuBar->SetItems(m_BaseMenu->Clone()); m_MenuBarH = m_MenuBar->GetPreferredSize().Y(); x_AddClientMenu(); x_Layout(); redraw();}void CFrameWindow::MergeMenu(const CMenuItem& item){ CMenuItem* root = m_MenuBar->GetRootItem(); root = root->Clone(); root->Merge(item); m_MenuBar->SetItems(root); m_MenuBarH = m_MenuBar->GetPreferredSize().Y(); x_Layout(); redraw();}void CFrameWindow::x_AddClientMenu(){ const CMenuItem* item = m_Client ? m_Client->GetMenu() : NULL; if(item) { MergeMenu(*item); }}void CFrameWindow::RemoveClient(){ if(m_Client) { if(m_CmdTarget) { RemoveChildCmdTarget(m_CmdTarget); } m_MenuBar->SetItems((CMenuItem*) NULL); m_MenuBarH = m_MenuBar->GetPreferredSize().Y(); Fl_Widget* widget = dynamic_cast<Fl_Widget*>(m_Client); m_ClientGroup->remove(widget); m_ClientGroup->resizable(NULL); m_Client->SetFrameWindow(NULL); m_Client = NULL; } x_Layout();} void CFrameWindow::SetClient(IFrameWindowClient* client){ RemoveClient(); Fl_Widget* widget = dynamic_cast<Fl_Widget*>(client); if(widget) { m_Client = client; m_Client->SetFrameWindow(this); m_ClientGroup->add(widget); widget->resize(m_ClientGroup->x(), m_ClientGroup->y(), m_ClientGroup->w(), m_ClientGroup->h()); m_ClientGroup->resizable(widget); // update Menu Bar x_AddClientMenu(); m_MenuBarH = m_MenuBar->GetPreferredSize().Y(); m_CmdTarget = dynamic_cast<CCommandTarget*>(client); if(m_CmdTarget) { AddChildCmdTarget(m_CmdTarget); } } x_Layout();}void CFrameWindow::show(){ if(! m_UpdateUITimer.IsRunning()) { m_UpdateUITimer.Start(); } TParent::show();}void CFrameWindow::hide(){ m_UpdateUITimer.Stop(); TParent::hide();}void CFrameWindow::resize(int x, int y, int w, int h){ TParent::resize(x, y, w, h); x_Layout(); }int CFrameWindow::handle(int event){ m_Event.OnFLTKEvent(event); bool handled = false; if(event == FL_KEYDOWN) { handled = x_HandleAccelerator(); } if(! handled) { handled = (TParent::handle(event) != 0); if(! handled && event == FL_KEYDOWN) { handled = x_HandleMenuActivate(); } } return handled;}bool CFrameWindow::x_HandleAccelerator(){ int accel = m_Event.GetAccelByEvent(); TCmdID cmd = eCmdInvalid; if(CAccelTable::GetCommandByAccel(accel, cmd)) { OnCommand(cmd); return true; } return false;}bool CFrameWindow::x_HandleMenuActivate(){ if(m_Event.GetGUISignal() == CGUIEvent::eMenuActivateSignal) { if(m_MenuBar) { m_MenuBar->Activate(); } } return false;}Fl_Widget* CFrameWindow::x_ClientWidget(){ return dynamic_cast<Fl_Widget*>(m_Client);}// layouts child widgetsvoid CFrameWindow::x_Layout(){ m_MenuBar->size(w(), m_MenuBarH); if(m_Client) { m_ClientGroup->resize(0, m_MenuBarH, w(), h() - m_MenuBarH - m_StatusBarH); } m_StatusBar->resize(0, h() - m_StatusBarH, w(), m_StatusBarH);}void CFrameWindow::OnTimeout(int timer_id){ if(timer_id == kUpdateTimerID) { x_OnUpdateUI(); }}void CFrameWindow::x_OnUpdateUI(){ if(Fl::grab() == NULL && m_MenuBar) { m_MenuBar->UpdateItems(); }}void CFrameWindow::OnHint(const string& hint){ m_StatusBar->SetSlotText(m_CmdHintSlot, hint); if(Fl::grab()) { flush(); // force repainting }}END_NCBI_SCOPE/* * =========================================================================== * $Log: frame_window.cpp,v $ * Revision 1000.0 2004/06/01 21:32:04 gouriano * PRODUCTION: IMPORTED [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/20 12:42:56 dicuccio * Fix compiler warning about int -> bool conversion * * Revision 1.2 2004/05/13 17:33:12 yazhuk * Added support for status bar, accelerators, keyboard activated menu bar * * Revision 1.1 2004/05/07 14:23:15 yazhuk * Initial revision * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?