main_window.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:16k
- /*
- * ===========================================================================
- * PRODUCTION $Log: main_window.cpp,v $
- * PRODUCTION Revision 1000.7 2004/06/01 20:48:16 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.32
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: main_window.cpp,v 1000.7 2004/06/01 20:48:16 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: Mike DiCuccio
- *
- * File Description:
- * CMainWindow -- main window for Genome Workbench
- */
- #include <ncbi_pch.hpp>
- #include "main_window.hpp"
- #include "plugin_mgr_dlg.hpp"
- #include "document_dlg.hpp"
- #include "gbench_frame.hpp"
- #include "about_dlg.hpp"
- #include "scanner_output_dlg.hpp"
- #include "browser_config_dlg.hpp"
- #include "browser_config.hpp"
- #include <corelib/ncbireg.hpp>
- #include <corelib/ncbiapp.hpp>
- #include <gui/core/algo_menu.hpp>
- #include <gui/core/dload_menu.hpp>
- #include <gui/core/selection_buffer.hpp>
- #include <gui/core/doc_manager.hpp>
- #include <gui/core/idocument.hpp>
- #include <gui/config/settings.hpp>
- #include <gui/core/version.hpp>
- #include <gui/core/iview.hpp>
- #include <gui/core/view_menu.hpp>
- #include <gui/utils/app_popup.hpp>
- #include <gui/widgets/fl/diag_panel.hpp>
- BEGIN_NCBI_SCOPE
- #include "main_window_.cpp"
- CMainWindow::CMainWindow()
- : m_LastConsoleHeight(100)
- {
- m_Window.reset(x_CreateWindow());
- CNcbiApplication* app = CNcbiApplication::Instance();
- _ASSERT(app);
- const CNcbiRegistry& reg = app->GetConfig();
- // make sure we position our window correctly
- string window_size = reg.Get("APP.MainWindow", "Position");
- if ( !window_size.empty() ) {
- list<string> toks;
- NStr::Split(window_size, ", ", toks);
- try {
- int win_x = m_Window->x();
- int win_y = m_Window->y();
- int win_w = m_Window->w();
- int win_h = m_Window->h();
- switch (toks.size()) {
- case 2:
- {{
- list<string>::const_iterator iter = toks.begin();
- win_x = NStr::StringToInt(*iter++);
- win_y = NStr::StringToInt(*iter++);
- }}
- break;
- case 4:
- {{
- list<string>::const_iterator iter = toks.begin();
- win_x = NStr::StringToInt(*iter++);
- win_y = NStr::StringToInt(*iter++);
- win_w = NStr::StringToInt(*iter++);
- win_h = NStr::StringToInt(*iter++);
- }}
- break;
- default:
- // unhandled
- LOG_POST(Warning << "CMainWindow(): "
- "window size = " << window_size
- << " is poorly formatted");
- break;
- }
- m_Window->resize(win_x, win_y, win_w, win_h);
- }
- catch (...){
- }
- }
- /** FIXME: not yet working
- // hide the console window, if we need to
- if (reg.Get("APP.MainWindow", "console") == "false") {
- x_OnToggleConsole();
- }
- **/
- // m_VersionStr and m_BuildStr must either be static or member variables
- // (FLTK doesn't copy the contents, it just stores a pointer)
- m_VersionStr = "version ";
- m_VersionStr += NStr::IntToString(CPluginVersion::eMajor) + ".";
- m_VersionStr += NStr::IntToString(CPluginVersion::eMinor);
- m_Version->label(m_VersionStr.c_str());
- m_BuildStr = "build ";
- m_BuildStr += __DATE__;
- m_BuildStr += " ";
- m_BuildStr += __TIME__;
- m_BuildDate->label(m_BuildStr.c_str());
- // establish the console window
- m_ShowConsoleBtn->clear_visible_focus();
- m_LastConsoleHeight = m_Console->h();;
- m_Console->SetTextSize(10);
- // create the menu managers
- m_ToolMgr.reset (new CAlgoMenuMgr (m_ToolsMenu, "", this));
- m_ViewMgr.reset (new CViewMenuMgr (m_ViewsMenu, "", this));
- m_DocLoaderMgr.reset(new CDocLoaderMenuMgr(m_OpenMenu, ""));
- // refresh our dynamic menus
- x_RefreshDynMenus();
- }
- CMainWindow::~CMainWindow()
- {
- //
- // here we dump the window state to the config file
- //
- // window size and position
- string win_size;
- win_size += NStr::IntToString(m_Window->x()) + ", ";
- win_size += NStr::IntToString(m_Window->y()) + ", ";
- win_size += NStr::IntToString(m_Window->w()) + ", ";
- win_size += NStr::IntToString(m_Window->h());
-
- CNcbiApplication* app = CNcbiApplication::Instance();
- _ASSERT(app);
- CNcbiRegistry& reg = app->GetConfig();
- reg.Set("APP.MainWindow", "Position", win_size,
- CNcbiRegistry::ePersistent);
- // hide state of the window
- reg.Set("APP.MainWindow", "Console",
- NStr::BoolToString(m_Console->visible() ? true : false),
- CNcbiRegistry::ePersistent);
- }
- bool CMainWindow::Shown(void) const
- {
- return (m_Window.get() && m_Window->shown());
- }
- void CMainWindow::Show(int argc, char** argv)
- {
- if (m_Window.get()) {
- m_Window->show(argc, argv);
- }
- }
- void CMainWindow::Show()
- {
- if (m_Window.get()) {
- m_Window->show();
- m_Window->take_focus();
- }
- }
- void CMainWindow::Hide()
- {
- if (m_Window.get()) {
- m_Window->hide();
- }
- }
- void CMainWindow::x_OnSwitchDocs()
- {
- const Fl_Menu_Item* item = m_OpenDocs->mvalue();
- m_CurrentDoc.Reset(reinterpret_cast<IDocument*>(item->user_data()));
- m_OpenDocs->label(item->label());
- x_HideAllBut(m_CurrentDoc);
- x_Show(m_CurrentDoc);
- x_RefreshDynMenus();
- }
- void CMainWindow::Update(TUpdateFlags flags)
- {
- if (flags & (fDocumentCreated | fDocumentReleased) ) {
- // remove the document items from the menu
- for (int i = 0; i < m_OpenDocs->size() - 1; ++i) {
- if (m_OpenDocs->menu()[i].label()[0] == '{') {
- m_OpenDocs->remove(i);
- }
- }
- int val = 0;
- NON_CONST_ITERATE (CDocManager::TDocList, doc_iter,
- CDocManager::GetDocuments()) {
- IDocument* doc = *doc_iter;
- string label("{");
- label += NStr::IntToString(doc->GetDocID());
- label += "} " + doc->GetTitle();
- // escape the forward slashes
- string::size_type pos = 0;
- while ( (pos = label.find_first_of("/", pos)) != string::npos) {
- label.insert(pos, "\");
- pos += 2;
- }
- val = m_OpenDocs->add(label.c_str(), "", NULL, doc);
- }
- m_OpenDocs->value(val);
- if (val != 0) {
- m_OpenDocs->label(m_OpenDocs->mvalue()->label());
- m_OpenDocs->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_CLIP);
- }
- m_CurrentDoc.Reset();
- if (CDocManager::GetDocuments().size()) {
- m_CurrentDoc.Reset(CDocManager::GetDocuments().back());
- }
- }
- if (m_OpenDocs->size() > 0) {
- m_OpenDocs->activate();
- m_ViewsMenu->activate();
- } else {
- m_OpenDocs->deactivate();
- m_ViewsMenu->deactivate();
- m_CurrentDoc.Reset();
- }
- // refresh our dynamic menus
- x_RefreshDynMenus();
- }
- void CMainWindow::GetSelections(TConstScopedObjects& objs) const
- {
- objs = GetSelBuffer().DecomposeToPairs();
- }
- void CMainWindow::SetSelections(const TConstScopedObjects& objs)
- {
- // FIXME: stub only
- }
- string CMainWindow::GetTitle(void) const
- {
- return "NCBI Genome Workbench";
- }
- void CMainWindow::x_OnToggleConsole()
- {
- if (m_Console->visible()) {
- m_LastConsoleHeight = m_Console->h();
- m_Window->size(m_Window->w(), m_Window->h() - m_LastConsoleHeight);
- m_Console->hide();
- m_ShowConsoleBtn->label("@-22UpArrow");
- } else {
- m_Console->show();
- m_ShowConsoleBtn->label("@-28DnArrow");
- _TRACE("showing console: " << m_Window->h() << " + " << m_LastConsoleHeight);
- m_Window->size(m_Window->w(), m_Window->h() + m_LastConsoleHeight);
- _TRACE("showed console: " << m_Window->h());
- }
- }
- void CMainWindow::x_RefreshDynMenus()
- {
- GetSelBuffer().Clear();
- if (m_CurrentDoc) {
- GetSelBuffer().AddSelection(m_CurrentDoc);
- }
- //
- // fill the algorithm plugins menus
- //
- m_ToolMgr->Clear();
- m_ToolMgr->AddAlgoMenu();
- //
- // fill the Open View menu button
- //
- m_ViewMgr->Clear();
- m_ViewMgr->AddActiveViews(m_CurrentDoc);
- m_ViewMgr->AddNewViews();// (m_CurrentDoc);
- //
- // fill the doc loader plugins menus
- //
- m_DocLoaderMgr->Clear();
- m_DocLoaderMgr->AddOpenMenu();
- m_DocLoaderMgr->AddRecentMenu();
- m_DocLoaderMgr->AddImportMenu();
- m_DocLoaderMgr->AddSaveAsMenu();
- m_DocLoaderMgr->AddUnloadMenu();
- m_DocLoaderMgr->AddSearchMenu();
- m_DocLoaderMgr->AddManageMenu();
- }
- void CMainWindow::x_OnManagePlugins()
- {
- if ( !m_PluginMgrDlg.get() ) {
- m_PluginMgrDlg.reset(new CPluginMgrDlg());
- }
- m_PluginMgrDlg->Show();
- }
- void CMainWindow::x_OnBrowserConfig()
- {
- //GBenchBrowserConfig();
- if ( !m_BrowserConfigDlg.get() ) {
- m_BrowserConfigDlg.reset(new CBrowserConfigDlg());
- }
- m_BrowserConfigDlg->Show();
- }
- void CMainWindow::x_OnShowFrame()
- {
- x_GetMainFrame().show();
- }
- void CMainWindow::x_OnShowAllRecords()
- {
- if ( !m_DocumentDlg ) {
- m_DocumentDlg.Reset(new CDocumentDlg());
- CDocManager::AttachView(m_DocumentDlg);
- }
- m_DocumentDlg->Show();
- }
- void CMainWindow::x_OnHelpIndex()
- {
- static const string url("http://www.ncbi.nlm.nih.gov/books/bv.fcgi?"
- "call=bv.View..ShowSection&rid=toolkit.section.3528");
- CAppPopup::PopupURL(url);
- }
- void CMainWindow::x_OnHelpAbout()
- {
- if ( !m_AboutDlg.get() ) {
- m_AboutDlg.reset(new CAboutDlg());
- }
- m_AboutDlg->Show();
- }
- void CMainWindow::x_HideAllBut(IDocument* doc)
- {
- NON_CONST_ITERATE (CDocManager::TDocList, doc_iter,
- CDocManager::GetDocuments()) {
- IDocument* this_doc = *doc_iter;
- if (this_doc == doc) {
- continue;
- }
- NON_CONST_ITERATE (IDocument::TViews, view_iter, doc->SetViews()) {
- IView* view = *view_iter;
- view->Hide();
- }
- }
- }
- void CMainWindow::x_Show(IDocument* doc)
- {
- NON_CONST_ITERATE (IDocument::TViews, view_iter, doc->SetViews()) {
- IView* view = *view_iter;
- view->Show();
- }
- }
- CGBenchFrameWindow& CMainWindow::x_GetMainFrame()
- {
- if ( !m_AppFrame.get() ) {
- m_AppFrame.reset(new CGBenchFrameWindow(1024, 768));
- }
- return *m_AppFrame;
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: main_window.cpp,v $
- * Revision 1000.7 2004/06/01 20:48:16 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.32
- *
- * Revision 1.32 2004/05/21 22:27:42 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.31 2004/05/18 11:14:45 friedman
- * Add "Recent Documents" menu entry.
- *
- * Revision 1.30 2004/05/17 13:25:32 dicuccio
- * First implementation of new document workspace
- *
- * Revision 1.29 2004/04/21 17:06:58 dicuccio
- * Only add current document if the document is valid
- *
- * Revision 1.28 2004/04/16 14:40:33 dicuccio
- * Inherit from ISelection for selection marshalling
- *
- * Revision 1.27 2004/04/09 17:24:47 jcherry
- * Implemented browser configuration for Windows, and changed how
- * it works on unix for consistency
- *
- * Revision 1.26 2004/04/07 21:08:51 jcherry
- * Added web browser configuration for gbench MIME types
- * (functinal on unix only so far)
- *
- * Revision 1.25 2004/02/17 20:35:24 rsmith
- * moved core/settings.[ch]pp and core/system_path.[ch]pp to config and utils, respectively.
- *
- * Revision 1.24 2003/12/04 18:12:20 dicuccio
- * Fixed escaping of document names that contain a '/'.
- *
- * Revision 1.23 2003/11/24 15:42:02 dicuccio
- * Renamed CVersion to CPluginVersion
- *
- * Revision 1.22 2003/11/18 17:45:29 dicuccio
- * Changed handling of m_CurrentDoc inside of Update()
- *
- * Revision 1.21 2003/11/06 20:08:53 dicuccio
- * Added help menu items
- *
- * Revision 1.20 2003/11/04 17:22:38 dicuccio
- * Changed registry settings - use uppercase for sections, up-and-down style for
- * items. Removed some unneeded TRACE()s
- *
- * Revision 1.19 2003/10/27 17:40:38 dicuccio
- * Restructured diagnostic handler - use CDiagPanel
- *
- * Revision 1.18 2003/09/04 14:02:36 dicuccio
- * Introduce IDocument as abstract base class for CDocument; replace use of
- * CDocument with IDocument
- *
- * Revision 1.17 2003/08/22 15:46:43 dicuccio
- * Removed config file from CSettings - accessible through CNcbiApplication
- *
- * Revision 1.16 2003/08/06 13:24:31 dicuccio
- * Deprecated old main window; introduced new, compact window for multiple
- * document management
- *
- * Revision 1.15 2003/07/31 17:00:51 dicuccio
- * Cleaned up handling of document menu button / label. Added search and manage
- * menu options to the data drop-down menu. Changed "Open a record" to "Data"
- *
- * Revision 1.14 2003/07/30 12:21:53 dicuccio
- * Added saving state of console window (not yet restored on APP restart)
- *
- * Revision 1.13 2003/07/21 19:30:48 dicuccio
- * Changed calling conventions of CAlgoMenuMgr to match CViewMenuMgr /
- * CDocMenuMgr() - updated window to match
- *
- * Revision 1.12 2003/07/11 15:06:37 kans
- * use NcbiApplication instead of doc manager settings for registry (MND)
- *
- * Revision 1.11 2003/06/30 13:35:51 dicuccio
- * Lots of clean-up. Restore the original diagnostic handler before shutting
- * down the application. Moved debug settings into the .ini file. Minor
- * clean-up of handling of config file
- *
- * Revision 1.10 2003/06/25 17:02:56 dicuccio
- * Split CPluginHandle into a handle (pointer-to-implementation) and
- * implementation file. Lots of #include file clean-ups.
- *
- * Revision 1.9 2003/06/09 19:19:52 dicuccio
- * Added ability for window to save/restore its position
- *
- * Revision 1.8 2003/05/06 15:58:03 dicuccio
- * Fixed bug: don't reset the current document in Update() unless the menu itself needs to be changed
- *
- * Revision 1.7 2003/05/05 12:44:01 dicuccio
- * Add views only for current document
- *
- * Revision 1.6 2003/04/29 14:51:52 dicuccio
- * Reworked FLUID-generated code: more explicit control over constructor, better
- * memeory management
- *
- * Revision 1.5 2003/04/24 16:36:19 dicuccio
- * Updated to reflect changes in IDocument API
- *
- * Revision 1.4 2003/04/08 20:09:37 dicuccio
- * Minor layout changes. Made main window smaller; reduced size of console
- * window. Also, added clipping and left-justification to items in the documents
- * drop-down.
- *
- * Revision 1.3 2003/04/08 18:10:58 lebedev
- * Document organizer added
- *
- * Revision 1.2 2003/04/07 17:30:26 dicuccio
- * Cleaned up window initialization to support multiple top-level doc manager
- * windows
- *
- * Revision 1.1 2003/03/31 13:36:37 dicuccio
- * Initial revision.
- *
- * ===========================================================================
- */