config_dlg.cpp
来自「ncbi源码」· C++ 代码 · 共 407 行
CPP
407 行
/* * =========================================================================== * PRODUCTION $Log: config_dlg.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 20:45:26 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3 * PRODUCTION * =========================================================================== *//* $Id: config_dlg.cpp,v 1000.1 2004/06/01 20:45:26 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: Robert G. Smith * * File Description: * User-modifiable implementation file for extension of basic class, * CConfigDlg, a prototype dialog box used for editing preferences. * A suitable mediator must be supplied to instantiate one. */#include <ncbi_pch.hpp>#include <gui/dialogs/config/config_dlg.hpp>#include <gui/dialogs/config/iconfig_mediator.hpp>#include <gui/dialogs/config/config_panel.hpp>#include <gui/utils/message_box.hpp>#include <FL/fl_ask.H>BEGIN_NCBI_SCOPE#include "config_dlg_.cpp"CConfigDlg::CConfigDlg(IConfigMediator& mediator){ m_ConfigMediator.Reset(& mediator); m_Window.reset(x_CreateWindow()); SetTitle(m_ConfigMediator->GetWindowTitle()); x_SetConfigPanel(* m_ConfigMediator->GetPanel().GetConfigPanel()); // populate our browser x_SetStates(m_ConfigMediator->GetStates()); // select the first thing in the state browser and Load it // NO. find out what the current state/style is and load that. // m_StyleBrowser->deselect(); // m_StyleBrowser->value(1); m_ConfigMediator->Load(kEmptyStr); string first_state = m_ConfigMediator->GetCurrentState(); x_SetSelectedState(first_state); x_SetLoadedState(first_state);}void CConfigDlg::x_SetConfigPanel(Fl_Group& new_group){ // we don't know the size of the new group of widgets // so most of this code is moving things to accomodate it. const int configPanelOffset = 0; Fl_Window* dlg_win = m_ConfigPanelHolder->window(); // find out things relative positions before we start moving stuff around. int right_margin = dlg_win->w() - (m_ConfigPanelHolder->x() + m_ConfigPanelHolder->w()); int pack_bot_margin = dlg_win->h() - (m_ConfigPanelHolder->y() + m_ConfigPanelHolder->h()); int win_h = dlg_win->h(); int win_w = dlg_win->w(); // make the whole window the right size. // do not decrease its size. It starts at its minimum. int new_window_width = right_margin + (m_ConfigPanelHolder->x() + new_group.w() + 2*configPanelOffset); new_window_width = max(new_window_width, dlg_win->w()); int new_window_height = pack_bot_margin + (m_ConfigPanelHolder->y() + new_group.h() + 2*configPanelOffset); new_window_height = max(new_window_height, dlg_win->h()); dlg_win->size(new_window_width, new_window_height); // Right now, is the smallest this window can be. dlg_win->size_range(dlg_win->w(), dlg_win->h()); // make the Fl_Pack just wide enough (don't let it stretch our new group). m_ConfigPanelHolder->clear(); // and Add it. new_group.position(m_ConfigPanelHolder->x() + configPanelOffset, m_ConfigPanelHolder->y() + configPanelOffset); m_ConfigPanelHolder->size(new_group.w() + 2*configPanelOffset, new_group.h() + 2*configPanelOffset); m_ConfigPanelHolder->add(& new_group); // necessary before we resize the window // since we might not have drawn this all yet. m_Tile->init_sizes(); new_group.init_sizes(); m_ConfigPanelHolder->init_sizes(); m_RightGroup->init_sizes();}void CConfigDlg::x_SetStates(list<string> const& states){ m_StyleBrowser->clear(); ITERATE(list<string>, state_it, states) { m_StyleBrowser->add(state_it->c_str()); }}//// Browser selection -> State// Return in the state param the string displayed// on the selected line in the browser.// If nothing was selected returns false and 'state'// is unmodified.//bool CConfigDlg::x_GetSelectedState(string& state){ int sel_idx = m_StyleBrowser->value(); if (sel_idx == 0) { return false; } const char *browser_text = m_StyleBrowser->text(sel_idx); if (browser_text == NULL) { return false; } string the_state(browser_text); state.swap(the_state); return true;}// State -> Browser selection// Select the line in the browser that has text the same// as the 'state' parameter. // Does nothing if that text was not found.void CConfigDlg::x_SetSelectedState(const string& state){ int n = m_StyleBrowser->size(); int i; for (i = 1; i <= n; ++i) { const char *a_text = m_StyleBrowser->text(i); if (a_text != NULL && state == a_text) { m_StyleBrowser->deselect(); m_StyleBrowser->value(i); x_UpdateSetBtns(); return; } }}void CConfigDlg::x_SelectFirstState(){ m_StyleBrowser->deselect(); m_StyleBrowser->value(1); x_UpdateSetBtns();}string CConfigDlg::x_GetLoadedState(){ return m_CurrentStyleText->value();}// show which state is loaded.void CConfigDlg::x_SetLoadedState(const string& state){ m_CurrentStyleText->value(state.c_str());}// load the currently selected state.void CConfigDlg::x_OnUse(){ string this_state; if ( ! x_GetSelectedState(this_state) ) { return; } // TODO: Make auto-save optional m_ConfigMediator->Save(kEmptyStr); m_ConfigMediator->Load(this_state); x_SetLoadedState(this_state); m_Window->redraw();}void CConfigDlg::x_OnAdd(){ string new_state; if ( m_ConfigMediator->AddState(new_state) ) { x_SetStates(m_ConfigMediator->GetStates()); x_SetSelectedState(new_state); // x_OnUse(); m_Window->redraw(); } else { NcbiMessageBox("Failed to add new state."); }}void CConfigDlg::x_OnCopy(){ string this_state; if ( ! x_GetSelectedState(this_state) ) { return; } string new_state; if ( m_ConfigMediator->DuplicateState(this_state, new_state) ) { x_SetStates(m_ConfigMediator->GetStates()); x_SetSelectedState(new_state); // x_OnUse(); m_Window->redraw(); } else { string msg("Can not copy "); msg += this_state; NcbiMessageBox(msg); }}void CConfigDlg::x_OnRename(){ string this_state; if ( ! x_GetSelectedState(this_state) ) { return; } // can we do this? if ( ! m_ConfigMediator->CanRenameState(this_state)) { string msg("Can not rename "); msg += this_state; NcbiMessageBox(msg); return; } // Get a new name from the user (requested name). const char * req_state_cp = fl_input("Rename %s as:", this_state.c_str(), this_state.c_str()); if (req_state_cp == 0) { // Canceled input return; } string req_state(req_state_cp); if (req_state.empty() || req_state == this_state) { // requested name blank or no change to the name. return; } // rename it, get back the new name actually used. string new_state; if ( m_ConfigMediator->RenameState(this_state, req_state, new_state) ) { x_SetStates(m_ConfigMediator->GetStates()); x_SetSelectedState(new_state); // did we rename the currently loaded state? if (x_GetLoadedState() == this_state) { x_SetLoadedState(new_state); } m_Window->redraw(); } else { // something else went wrong. string msg("Can not rename "); msg += this_state; NcbiMessageBox(msg); }}void CConfigDlg::x_OnDelete(){ string this_state; if ( ! x_GetSelectedState(this_state) ) { return; } if ( m_ConfigMediator->DeleteState(this_state) ) { m_StyleBrowser->deselect(); x_SetStates(m_ConfigMediator->GetStates()); // did we delete the currently loaded state? if (x_GetLoadedState() == this_state) { // select and load the first state in the list. x_SelectFirstState(); x_OnUse(); } m_Window->redraw(); } else { string msg("Can not delete "); msg += this_state; NcbiMessageBox(msg); }}// Default callback for clicking the 'OK' buttonvoid CConfigDlg::x_OnOK(){ m_ConfigMediator->Save(kEmptyStr); CDialog::x_OnOK();}void CConfigDlg::x_OnDefVals(){ m_ConfigMediator->LoadDefault(); m_Window->redraw();}void CConfigDlg::x_OnClicks(){ x_UpdateSetBtns(); if (Fl::event_clicks()) { x_OnUse(); }}void CConfigDlg::x_UpdateSetBtns(){ bool delRenameOn = true; string this_state; if ( x_GetSelectedState(this_state) ) { if ( ! m_ConfigMediator->CanRenameState(this_state)) { delRenameOn = false; } } if (delRenameOn) { m_RenameBtn->activate(); m_DeleteBtn->activate(); } else { m_RenameBtn->deactivate(); m_DeleteBtn->deactivate(); } }END_NCBI_SCOPE/* * =========================================================================== * $Log: config_dlg.cpp,v $ * Revision 1000.1 2004/06/01 20:45:26 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3 * * Revision 1.3 2004/05/21 22:27:41 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.2 2004/01/02 21:04:53 rsmith * remove misleading comment * * Revision 1.1 2003/12/30 14:09:38 dicuccio * Initial check-in - moved from gui/config * * Revision 1.5 2003/12/29 14:38:14 rsmith * take out SetTitle since it is supplied by the parent class. * * Revision 1.4 2003/11/21 12:52:25 rsmith * Fix bug with renaming loaded set of values. * * Revision 1.3 2003/11/18 20:23:46 rsmith * Various bug fixes and enhancements. * * Revision 1.2 2003/10/14 12:48:54 dicuccio * Inherit from CDialog. Fix resizing issues. Standardized widget sizes. * * Revision 1.1 2003/10/10 17:43:42 rsmith * moved from gui/core to gui/config * * Revision 1.1 2003/09/26 18:15:31 rsmith * plugin configration data and dialog * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?