theme_config_panel2.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:12k
- /*
- * ===========================================================================
- * PRODUCTION $Log: theme_config_panel2.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 20:45:49 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.5
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id $
- * ===========================================================================
- *
- * 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:
- *
- */
- #include <ncbi_pch.hpp>
- #include <gui/dialogs/config/theme_config_panel2.hpp>
- BEGIN_NCBI_SCOPE
- typedef Fl_Choice TDropDownMenu;
- static void ClearDDM(TDropDownMenu* dd_menu)
- {
- dd_menu->clear();
- }
-
- static void AddDDM(TDropDownMenu* dd_menu, const string& s)
- {
- // dd_menu->Add(s.c_str()); // CComboxBox
- dd_menu->add(s.c_str()); // Fl_Choice
- }
- static string GetValueDDM(TDropDownMenu* dd_menu)
- {
- // return dd_menu->value(); // CComboBox
-
- // Fl_Choice
- const char *t = dd_menu->text();
- if (t) {
- return t;
- }
- return kEmptyStr;
-
- }
- static void SetValueDDM(TDropDownMenu* dd_menu, const string& s)
- {
- // dd_menu->value(s.c_str()); // CComboBox
-
- // Fl_Choice
- const Fl_Menu_Item* menu_items = dd_menu->menu();
- for (int item_n = 0; menu_items != NULL && menu_items->label() != NULL; ++menu_items, ++item_n) {
- if (s == menu_items->label()) {
- dd_menu->value(item_n);
- return;
- }
- }
- return;
- }
- CThemeConfigPanel2::CThemeConfigPanel2() :
- m_ConfigPanel(0),
- m_Preview(0),
- m_LayoutDirection(CThemeConfigPanel2::eLayoutDirection_Horizontal)
- {
- }
- Fl_Group* CThemeConfigPanel2::GetConfigPanel()
- {
- return m_ConfigPanel;
- }
- void CThemeConfigPanel2::MakeWidgets()
- {
- x_MakeWidgets();
- UpdateWidgets();
- }
- void CThemeConfigPanel2::UpdateWidgets()
- {
- ITERATE (vector <SItemData>, item_it, m_ItemData) {
- const string& item_desc = item_it->desc;
- x_SetStyles(item_desc);
-
- string this_style = GetCurrentStyleByDesc(item_desc);
-
- SetValueDDM(x_GetChoice(item_desc), this_style);
- }
- m_ConfigPanel->redraw();
- }
- void CThemeConfigPanel2::x_SetStyles(const string& item)
- {
- Fl_Choice* this_menu = x_GetChoice(item);
- if (this_menu) {
- ClearDDM(this_menu);
- const TStyleList& styles = GetStylesByDesc(item);
- ITERATE(TStyleList, style_it, styles) {
- AddDDM(this_menu, *style_it);
- }
- }
- }
- void CThemeConfigPanel2::x_StyleChosen(Fl_Choice * w)
- {
- SetCurrentStyleByDesc(x_GetItem(w), GetValueDDM(w) );
- // m_Preview->redraw();
- }
- void CThemeConfigPanel2::SetLayoutDirection(CThemeConfigPanel2::ELayoutDirection d)
- {
- m_LayoutDirection = d;
- }
- CThemeConfigPanel2::ELayoutDirection CThemeConfigPanel2::GetLayoutDirection()
- {
- return m_LayoutDirection;
- }
- namespace {
- const int kSpaceVertical = 5;
- const int kMarginLeft = 10;
- const int kMarginRight = 5;
- const int kSpaceHoriz = 5;
-
- const int kWidgetHeight = 25;
- const int kLabelWidth = 100;
- const int kWidgetWidth = 150; // must be greater than or equal to kLabelWidth.
- #if NCBI_THEME_PANEL_CHANGE_DIR_BTN
- const int kToggleHeight = kWidgetHeight;
- const int kToggleWidth = kToggleHeight;
- #else
- const int kToggleHeight = 0;
- const int kToggleWidth = 0;
- #endif
- const int kPreviewWidthMin = 315;
- const int kPreviewHeightMin = 160;
- }
- Fl_Group* CThemeConfigPanel2::x_MakeWidgets()
- {
- int n_items = m_ItemData.size();
-
- int panel_h;
- int panel_w;
- int panel_x = 0;
- int panel_y = 0;
- int widget_group_h;
- int widget_group_w;
-
- if (m_LayoutDirection == eLayoutDirection_Horizontal) {
- panel_h = 2 * kSpaceVertical + 2 * kWidgetHeight + kPreviewHeightMin;
- panel_w = n_items * (kSpaceHoriz + kWidgetWidth) + kSpaceHoriz;
- #if NCBI_THEME_PANEL_CHANGE_DIR_BTN
- panel_w += kToggleWidth + kSpaceHoriz;
- #endif
- panel_w = max(kPreviewWidthMin, panel_w);
- } else {
- panel_w = kMarginLeft + kWidgetWidth + kSpaceHoriz + kPreviewWidthMin;
- panel_h = n_items * (kSpaceVertical + 2*kWidgetHeight) + kSpaceVertical;
- #if NCBI_THEME_PANEL_CHANGE_DIR_BTN
- panel_h += kToggleHeight + kSpaceVertical;
- #endif
- panel_h = max(kPreviewHeightMin, panel_h);
- }
- if ( ! m_ConfigPanel) {
- m_ConfigPanel = new Fl_Group(0, 0, panel_w, panel_h);
- m_ConfigPanel->box(FL_FLAT_BOX);
- m_ConfigPanel->color(FL_BACKGROUND_COLOR);
- m_ConfigPanel->selection_color(FL_BACKGROUND_COLOR);
- m_ConfigPanel->labeltype(FL_NO_LABEL);
- m_ConfigPanel->activate();
- m_ConfigPanel->user_data((void*)(this));
- } else {
- m_ConfigPanel->clear();
- m_ConfigPanel->begin();
- panel_x = m_ConfigPanel->x();
- panel_y = m_ConfigPanel->y();
- }
- if (m_LayoutDirection == eLayoutDirection_Horizontal) {
- widget_group_h = 2 * kSpaceVertical + 2 * kWidgetHeight;
- widget_group_w = panel_w;
- } else {
- widget_group_w = kMarginLeft + kWidgetWidth + kSpaceHoriz;
- widget_group_h = panel_h;
- }
-
- if (m_LayoutDirection == eLayoutDirection_Horizontal) {
- m_Preview = new Fl_Group(panel_x, panel_y + widget_group_h, panel_w, kPreviewHeightMin);
- m_ConfigPanel->resizable(m_Preview);
- } else {
- m_Preview = new Fl_Group(widget_group_w, panel_y, kPreviewWidthMin, panel_h);
- }
- m_Preview->box(FL_DOWN_BOX);
- m_Preview->end();
-
- Fl_Group* widget_group = new Fl_Group(panel_x, panel_y, widget_group_w, widget_group_h);
- // widget_group->box(FL_DOWN_BOX);
- widget_group->activate();
-
- #if NCBI_THEME_PANEL_CHANGE_DIR_BTN
- m_DirectionBtn = new Fl_Button(panel_x + kSpaceHoriz, panel_y + kSpaceVertical, kToggleWidth, kToggleHeight);
- m_DirectionBtn->label(m_LayoutDirection == eLayoutDirection_Horizontal ? "@->": "@2->" );
- m_DirectionBtn->user_data((void*)(this));
- m_DirectionBtn->callback((Fl_Callback*) cb_SwitchDirections );
- #endif
-
- // intialize the widget positions.
- int label_x, label_y;
- int widget_x, widget_y;
- if (m_LayoutDirection == eLayoutDirection_Horizontal) {
- label_x = panel_x + kSpaceHoriz;
- #if NCBI_THEME_PANEL_CHANGE_DIR_BTN
- label_x += kToggleWidth + kSpaceHoriz;
- #endif
- label_y = panel_y + kSpaceVertical;
- widget_x = label_x;
- widget_y = label_y + kWidgetHeight;
- } else {
- label_x = panel_x + kMarginLeft;
- label_y = panel_y + kSpaceVertical;
- #if NCBI_THEME_PANEL_CHANGE_DIR_BTN
- label_y += kToggleHeight + kSpaceVertical;
- #endif
- widget_x = label_x;
- widget_y = label_y + kWidgetHeight;
- }
-
- // create the widgets.
- ITERATE(vector<SItemData>, item_it, m_ItemData) {
-
- Fl_Box* label_box = new Fl_Box(label_x, label_y, kLabelWidth, kWidgetHeight, item_it->desc.c_str());
- label_box->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
-
- Fl_Choice* choice = new Fl_Choice(widget_x, widget_y, kWidgetWidth, kWidgetHeight);
- choice->down_box(FL_BORDER_BOX);
- choice->user_data((void*)(this));
- choice->callback((Fl_Callback*) cb_StyleChosen );
- choice->when(FL_WHEN_RELEASE);
- bool act_ive = choice->active_r();
- x_AddChoice(item_it->desc, choice);
-
- // increment the widget positions.
- if (m_LayoutDirection == eLayoutDirection_Horizontal) {
- widget_x += kWidgetWidth + kSpaceHoriz;
- label_x = widget_x;
- } else {
- label_y += 2*kWidgetHeight + kSpaceVertical;
- widget_y = label_y + kWidgetHeight;
- }
- }
-
- // make the widget group's resizable box.
- // This will let the choice boxes expand in width, but not height.
- Fl_Box* resizable_box;
- if (m_LayoutDirection == eLayoutDirection_Horizontal) {
- resizable_box = new Fl_Box(panel_x, widget_group_h - 1, widget_group_w, 0, "resizable");
- } else {
- resizable_box = new Fl_Box(widget_x, widget_group_h - 1, kWidgetWidth, 0, "resizable");
- }
- resizable_box->labeltype(FL_NO_LABEL);
- resizable_box->hide();
- resizable_box->deactivate();
- widget_group->resizable(resizable_box);
-
-
- widget_group->end();
- m_ConfigPanel->end();
-
- return m_ConfigPanel;
- }
- void CThemeConfigPanel2::cb_StyleChosen(Fl_Choice* o, void* v)
- {
- ((CThemeConfigPanel2*)v)->x_StyleChosen(o);
- }
- void CThemeConfigPanel2::x_AddChoice(const string& item, Fl_Choice* widget)
- {
- m_ChoiceWidgets[item] = widget;
- }
- Fl_Choice* CThemeConfigPanel2::x_GetChoice(const string& item) const
- {
- TItemChoiceMap::const_iterator it = m_ChoiceWidgets.find(item);
- if (it == m_ChoiceWidgets.end()) {
- return NULL;
- }
- return it->second;
- }
- string CThemeConfigPanel2::x_GetItem(const Fl_Choice* widget) const
- {
- ITERATE(TItemChoiceMap, it, m_ChoiceWidgets) {
- if (it->second == widget) {
- return it->first;
- }
- }
- return kEmptyStr;
- }
-
- #if NCBI_THEME_PANEL_CHANGE_DIR_BTN
- void CThemeConfigPanel2::x_SwitchDirections()
- {
- if (GetLayoutDirection() == eLayoutDirection_Horizontal) {
- SetLayoutDirection(eLayoutDirection_Vertical);
- m_DirectionBtn->label("@2->");
- } else {
- SetLayoutDirection(eLayoutDirection_Horizontal);
- m_DirectionBtn->label("@->");
- }
- MakeWidgets();
- }
- void CThemeConfigPanel2::cb_SwitchDirections(Fl_Choice* o, void* v)
- {
- ((CThemeConfigPanel2*)v)->x_SwitchDirections();
- }
- #endif
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: theme_config_panel2.cpp,v $
- * Revision 1000.1 2004/06/01 20:45:49 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.5
- *
- * Revision 1.5 2004/05/21 22:27:41 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.4 2004/02/20 16:16:50 rsmith
- * Add and disable a button to dynamically switch the widget directions.
- * Not currently used since the dialog/mediator architecture makes it very hard for
- * this to work right with the dialog.
- *
- * Revision 1.3 2004/02/02 19:18:07 rsmith
- * change obsolete types
- *
- * Revision 1.2 2004/02/02 18:39:36 rsmith
- * change implementation to work with the new base class.
- *
- * Revision 1.1 2004/01/29 21:25:50 rsmith
- * initial checkin
- *
- * Revision 1.2 2004/01/02 21:02:16 rsmith
- * Change CComboBox to Fl_Choice and various cleanups.
- *
- * Revision 1.1 2003/12/30 14:09:41 dicuccio
- * Initial check-in - moved from gui/config
- *
- * Revision 1.1 2003/12/29 14:41:36 rsmith
- * initial checkin
- *
- *
- * ===========================================================================
- */