menu_demo_window.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:11k
- /*
- * ===========================================================================
- * PRODUCTION $Log: menu_demo_window.cpp,v $
- * PRODUCTION Revision 1000.0 2004/06/01 21:30:49 gouriano
- * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.4
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: menu_demo_window.cpp,v 1000.0 2004/06/01 21:30:49 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 <corelib/ncbidiag.hpp>
- #include "menu_demo.hpp"
- #include <FL/Fl_Tile.H>
- USING_NCBI_SCOPE;
- enum ETestCommands {
- eCmdFirst = 5000,
- eCmdSecond,
- eCmdThird,
- eCmdRadioA,
- eCmdRadioB,
- eCmdRadioC,
- eCmdCheck1,
- eCmdCheck2
- };
- static
- DEFINE_MENU(Menu)
- SUBMENU("&Zoom")
- MENU_ITEM_IM(eCmdZoomIn, "Zoom &In", "menu::zoom_in")
- MENU_ITEM_IM(eCmdZoomIn, "Zoom &Out", "menu::zoom_out")
- MENU_ITEM_IM(eCmdZoomIn, "Zoom &All", "menu::zoom_all")
- MENU_ITEM_IM(eCmdZoomSel, "Zoom &Sel", "menu::zoom_sel")
- MENU_SEPARATOR()
- SUBMENU("&More...")
- MENU_ITEM(eCmdZoomIn, "Zoom &In")
- MENU_ITEM(eCmdZoomOut, "Zoom &Out")
- MENU_ITEM(eCmdZoomAll, "Zoom &All")
- MENU_ITEM(eCmdZoomSel, "Zoom &Sel")
- END_SUBMENU()
- SUBMENU("&Even More...")
- MENU_ITEM(eCmdZoomIn, "Zoom &In")
- MENU_ITEM(eCmdZoomOut, "Zoom &Out")
- MENU_ITEM(eCmdZoomAll, "Zoom &All")
- MENU_ITEM(eCmdZoomSel, "Zoom &Sel")
- END_SUBMENU()
- END_SUBMENU()
- SUBMENU("&Updates")
- MENU_ITEM(eCmdFirst, "&First")
- MENU_ITEM(eCmdSecond, "&Second")
- MENU_ITEM(eCmdThird, "&Third")
- MENU_SEPARATOR()
- MENU_ITEM(eCmdRadioA, "Radio A")
- MENU_ITEM(eCmdRadioB, "Radio B")
- MENU_ITEM(eCmdRadioC, "Radio C")
- MENU_SEPARATOR()
- MENU_ITEM(eCmdCheck1, "Check 1")
- MENU_ITEM(eCmdCheck2, "Check 2")
- END_SUBMENU()
- MENU_SEPARATOR()
- MENU_ITEM_IM(eCmdZoomIn, "Zoom &In", "menu::zoom_in")
- MENU_ITEM_IM(eCmdZoomIn, "Zoom &Out", "menu::zoom_out")
- END_MENU()
- static
- DEFINE_MENU(ToolBar)
- MENU_ITEM_IM(eCmdZoomIn, "Zoom In", "menu::zoom_in")
- MENU_ITEM_IM(eCmdZoomOut, "Zoom Out", "menu::zoom_out")
- MENU_ITEM_IM(eCmdZoomAll, "Zoom All", "menu::zoom_all")
- MENU_ITEM_IM(eCmdZoomSel, "Zoom &Sel", "menu::zoom_sel")
- MENU_SEPARATOR()
- MENU_ITEM_IM(eCmdZoomIn, "", "menu::zoom_in")
- MENU_ITEM_IM(eCmdZoomOut, "", "menu::zoom_out")
- MENU_ITEM_IM(eCmdZoomAll, "", "menu::zoom_all")
- MENU_ITEM_IM(eCmdZoomSel, "", "menu::zoom_sel")
- MENU_SEPARATOR()
- MENU_ITEM(eCmdZoomIn, "Zoom In")
- MENU_ITEM(eCmdZoomOut, "Zoom Out")
- MENU_ITEM(eCmdZoomAll, "Zoom All")
- MENU_ITEM(eCmdZoomSel, "Zoom &Sel")
- END_MENU()
- ////////////////////////////////////////////////////////////////////////////////
- ///
- CMenuDemoClient::CMenuDemoClient(int x, int y, int w, int h)
- : CDiagPanel(x, y, w, h)
- {
- m_Index = 3;
- m_Radio = 'A';
- m_Check1 = true;
- m_Check1 = false;
- }
- BEGIN_CMD_MAP(CMenuDemoClient, CCommandTarget)
- ON_COMMAND(eCmdZoomIn, &CMenuDemoClient::OnZoomIn)
- ON_COMMAND(eCmdZoomOut, &CMenuDemoClient::OnZoomOut)
- ON_COMMAND(eCmdZoomAll, &CMenuDemoClient::OnZoomAll)
- ON_COMMAND(eCmdZoomSel, &CMenuDemoClient::OnZoomSel)
-
- ON_COMMAND(eCmdFirst, &CMenuDemoClient::OnFirst)
- ON_COMMAND(eCmdSecond, &CMenuDemoClient::OnSecond)
- ON_COMMAND(eCmdThird, &CMenuDemoClient::OnThird)
- // register update handler enabling/disabling commands
- ON_UPDATE_COMMAND_UI(eCmdFirst, &CMenuDemoClient::OnUpdateFirst)
- ON_UPDATE_COMMAND_UI(eCmdSecond, &CMenuDemoClient::OnUpdateSecond)
- ON_UPDATE_COMMAND_UI(eCmdThird, &CMenuDemoClient::OnUpdateThird)
-
- // register one command handler and one update handler for
- // [eCmdRadioA..eCmdRadioC] command range
- ON_COMMAND_RANGE(eCmdRadioA, eCmdRadioC, &CMenuDemoClient::OnRadio)
- ON_UPDATE_COMMAND_UI_RANGE(eCmdRadioA, eCmdRadioC, &CMenuDemoClient::OnUpdateRadio)
-
- ON_COMMAND(eCmdCheck1, &CMenuDemoClient::OnCheck1)
- ON_COMMAND(eCmdCheck2, &CMenuDemoClient::OnCheck2)
-
- // register update handler checkin/unchecking items
- ON_UPDATE_COMMAND_UI(eCmdCheck1, &CMenuDemoClient::OnUpdateCheck1)
- ON_UPDATE_COMMAND_UI(eCmdCheck2, &CMenuDemoClient::OnUpdateCheck2)
- END_CMD_MAP()
- int CMenuDemoClient::handle(int event)
- {
- // Popup menu should be shown on CGUIEvent::ePopupSignal, however it is not
- // possible in this example, so we use FL_PUSH
- if(event == FL_PUSH) {
-
- CPopupMenu1 menu(Fl::event_x_root(), Fl::event_y_root(), Menu, this);
- menu.Popup();
-
- return 1;
- }
- return CDiagPanel::handle(event);
- }
- void CMenuDemoClient::PostMessage(const char* message)
- {
- Post(SDiagMessage(eDiag_Info, message, strlen(message)));
- }
- void CMenuDemoClient::OnZoomIn()
- {
- PostMessage("OnZoomIn()");
- }
- void CMenuDemoClient::OnZoomOut()
- {
- PostMessage("OnZoomOut()");
- }
- void CMenuDemoClient::OnZoomAll()
- {
- PostMessage("OnZoomAll()");
- }
- void CMenuDemoClient::OnZoomSel()
- {
- PostMessage("OnZoomSel()");
- }
- void CMenuDemoClient::OnFirst()
- {
- m_Index = 1;
- PostMessage("OnFirst()");
- }
- void CMenuDemoClient::OnSecond()
- {
- m_Index = 2;
- PostMessage("OnSecond()");
- }
- void CMenuDemoClient::OnThird()
- {
- m_Index = 3;
- PostMessage("OnThird()");
- }
- void CMenuDemoClient::OnUpdateFirst(ICmdUI* pCmdUI)
- {
- pCmdUI->Enable(m_Index != 1);
- PostMessage("OnUpdateFirst()");
- }
- void CMenuDemoClient::OnUpdateSecond(ICmdUI* pCmdUI)
- {
- pCmdUI->Enable(m_Index != 2);
- PostMessage("OnUpdateSecond()");
- }
- void CMenuDemoClient::OnUpdateThird(ICmdUI* pCmdUI)
- {
- pCmdUI->Enable(m_Index != 3);
- PostMessage("OnUpdateThird()");
- }
- void CMenuDemoClient::OnRadio(TCmdID cmd)
- {
- switch(cmd) {
- case eCmdRadioA: m_Radio = 'A'; break;
- case eCmdRadioB: m_Radio = 'B'; break;
- case eCmdRadioC: m_Radio = 'C'; break;
- };
- string s = "OnRadio() for ";
- s += m_Radio;
- PostMessage(s.c_str());
- }
- // here we are handling 3 commands in one handler
- void CMenuDemoClient::OnUpdateRadio(ICmdUI* pCmdUI)
- {
- char ch = 0;
- switch(pCmdUI->GetCommand()) {
- case eCmdRadioA: ch = 'A'; break;
- case eCmdRadioB: ch = 'B'; break;
- case eCmdRadioC: ch = 'C'; break;
- };
- pCmdUI->SetRadio(m_Radio == ch);
-
- string s = "OnUpdateRadio() for ";
- s += ch;
- PostMessage(s.c_str());
- }
- void CMenuDemoClient::OnCheck1()
- {
- m_Check1 = ! m_Check1;
- PostMessage("OnCheck1()");
- }
- void CMenuDemoClient::OnCheck2()
- {
- m_Check2 = ! m_Check2;
- PostMessage("OnCheck2()");
- }
- void CMenuDemoClient::OnUpdateCheck1(ICmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_Check1);
- PostMessage("OnUpdateCheck1");
- }
- void CMenuDemoClient::OnUpdateCheck2(ICmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_Check2);
- PostMessage("OnUpdateCheck2");
- }
- ////////////////////////////////////////////////////////////////////////////////
- ///
- CMenuDemoWindow::CMenuDemoWindow()
- {
- //CRef<CResourceManager> manager(new CResourceManager("E:\Projects\c++\src\gui\res\"));
- CRef<CResourceManager> manager(new CResourceManager("<std> ; <home>"));
- manager->RegisterAlias("menu::zoom", "zoom.png");
- manager->RegisterAlias("menu::zoom_in", "zoom_in.png");
- manager->RegisterAlias("menu::zoom_out", "zoom_out.png");
- manager->RegisterAlias("menu::zoom_all", "zoom_all.png");
- manager->RegisterAlias("menu::zoom_sel", "zoom_sel.png");
- CMenu::SetResourceManager(manager);
- m_Window.reset(x_CreateWindow());
- }
- CMenuDemoWindow::~CMenuDemoWindow()
- {
- CRef<CResourceManager> empty;
- CMenu::SetResourceManager(empty);
- }
- const static int kWidth = 600;
- const static int kHeight = 400;
- Fl_Double_Window* CMenuDemoWindow::x_CreateWindow()
- {
- Fl_Double_Window* window = new Fl_Double_Window(kWidth, kHeight, "Menu Demo");
- window->user_data((void*)(this));
-
- m_Client = new CMenuDemoClient(0, 0, kWidth, kHeight);
- m_Client->end();
- m_MenuBar = new CMenuBar1(0, 0, kWidth, 0);
- m_MenuBar->SetItems(Menu);
- m_MenuBar->SetCmdTarget(m_Client);
- CPoint sz = m_MenuBar->GetPreferredSize();
- m_MenuBar->size(kWidth, sz.Y());
-
- m_ToolBar = new CMenuBar1(0, sz.Y(), kWidth, 0);
- m_ToolBar->SetItems(ToolBar);
- m_ToolBar->SetCmdTarget(m_Client);
- sz = m_ToolBar->GetPreferredSize();
- m_ToolBar->size(sz.X(), sz.Y());
-
- int off = m_MenuBar->h() + m_ToolBar->h();
- m_Client->resize(0, off, kWidth, kHeight - off);
-
- Fl_Group::current()->resizable(m_Client);
- window->end();
-
- m_Client->PostMessage("Started...");
- m_Client->PostMessage("Press mouse button in empty space to display Popup menu");
- return window;
- }
- /*
- * ===========================================================================
- * $Log: menu_demo_window.cpp,v $
- * Revision 1000.0 2004/06/01 21:30:49 gouriano
- * PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.4
- *
- * Revision 1.4 2004/05/21 22:27:53 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.3 2004/05/13 17:59:18 yazhuk
- * Replaced CDiagPanel1 with CDiagPanel
- *
- * Revision 1.2 2004/05/03 19:51:37 yazhuk
- * Implemented command updates, pluged-in new resources
- *
- * Revision 1.1 2004/04/22 17:05:15 yazhuk
- * Initial revision
- *
- * ===========================================================================
- */