From fe66fc4644fe336a08e2ce4528b0ccec3d3dd0a8 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Wed, 23 Oct 2002 08:31:10 +0000 Subject: [PATCH] (Rob Lahaye): miscellaneous bits 'n' bobs. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5477 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/xforms/ChangeLog | 18 ++++++++++ src/frontends/xforms/FeedbackController.C | 6 ++-- src/frontends/xforms/FormGraphics.h | 1 - src/frontends/xforms/FormPrint.C | 5 +-- src/frontends/xforms/RadioButtonGroup.C | 42 ++++++++++------------- src/frontends/xforms/RadioButtonGroup.h | 27 ++++++++------- src/frontends/xforms/xforms_helpers.C | 17 +++++---- src/frontends/xforms/xforms_helpers.h | 7 ++-- 8 files changed, 68 insertions(+), 55 deletions(-) diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 654cebb957..f53667e729 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,21 @@ +2002-10-22 Rob Lahaye + + * FeedbackController.C: use the NORMAL rather than the SMALL sized font + to display messages in the message_widget. + + * FormGraphics.h: remove un-needed #include. + + * FormPrint.C (build): minimal change due to change in + RadioButtonGroup's semantics. + + * RadioButtonGroup.[Ch]: something of a clean-up. + (reset): removed. + (set): new method, accepting an FL_OBJECT *. + + * xforms_helpers.[Ch] (setEnabled): change lcol setting from + FL_BLACK to FL_LCOL. + (getString) use line=0 instead of line=-1 as default case; + 2002-10-22 Rob Lahaye * forms/form_aboutlyx.fd: implement the text widgets as browsers diff --git a/src/frontends/xforms/FeedbackController.C b/src/frontends/xforms/FeedbackController.C index 01dcc2bf29..12d44a675c 100644 --- a/src/frontends/xforms/FeedbackController.C +++ b/src/frontends/xforms/FeedbackController.C @@ -39,7 +39,7 @@ void FeedbackController::setMessageWidget(FL_OBJECT * ob) { lyx::Assert(ob && ob->objclass == FL_TEXT); message_widget_ = ob; - fl_set_object_lsize(message_widget_, FL_SMALL_SIZE); + fl_set_object_lsize(message_widget_, FL_NORMAL_SIZE); } @@ -140,10 +140,10 @@ void FeedbackController::postMessage(string const & message) else str = message; - str = formatted(str, message_widget_->w-10, FL_SMALL_SIZE); + str = formatted(str, message_widget_->w - 10, FL_NORMAL_SIZE); fl_set_object_label(message_widget_, str.c_str()); - FL_COLOR const label_color = warning_posted_ ? FL_TOMATO : FL_BLACK; + FL_COLOR const label_color = warning_posted_ ? FL_RED : FL_BLACK; fl_set_object_lcol(message_widget_, label_color); if (!message_widget_->visible) diff --git a/src/frontends/xforms/FormGraphics.h b/src/frontends/xforms/FormGraphics.h index 3facf82c76..5f327a207d 100644 --- a/src/frontends/xforms/FormGraphics.h +++ b/src/frontends/xforms/FormGraphics.h @@ -18,7 +18,6 @@ #endif #include "FormBase.h" -#include "RadioButtonGroup.h" #include diff --git a/src/frontends/xforms/FormPrint.C b/src/frontends/xforms/FormPrint.C index 8d09539009..05422954b6 100644 --- a/src/frontends/xforms/FormPrint.C +++ b/src/frontends/xforms/FormPrint.C @@ -34,8 +34,7 @@ using std::make_pair; typedef FormCB > base_class; FormPrint::FormPrint() - : base_class(_("Print")), - target_(2), which_pages_(2) + : base_class(_("Print")) {} @@ -70,10 +69,8 @@ void FormPrint::build() bc().addReadOnly(dialog_->check_sorted_copies); bc().addReadOnly(dialog_->check_reverse_order); - target_.reset(); target_.init(dialog_->radio_printer, PrinterParams::PRINTER); target_.init(dialog_->radio_file, PrinterParams::FILE); - which_pages_.reset(); which_pages_.init(dialog_->radio_all_pages, true); which_pages_.init(dialog_->radio_from_to, false); diff --git a/src/frontends/xforms/RadioButtonGroup.C b/src/frontends/xforms/RadioButtonGroup.C index 19e350c5f8..0d9531e2fd 100644 --- a/src/frontends/xforms/RadioButtonGroup.C +++ b/src/frontends/xforms/RadioButtonGroup.C @@ -6,6 +6,7 @@ * Licence details can be found in the file COPYING. * * \author Baruch Even + * \author Rob Lahaye * * Full author contact details are available in file CREDITS */ @@ -22,24 +23,16 @@ #include "debug.h" // for lyxerr #include "support/lyxfunctional.h" -//#include #include #include using std::find_if; -//using std::bind2nd; using std::endl; -void RadioButtonGroup::init(FL_OBJECT *button, size_type value) +void RadioButtonGroup::init(FL_OBJECT * ob, size_type value) { - map.push_back(ButtonValuePair(button, value)); -} - - -void RadioButtonGroup::reset() -{ - map.clear(); + map.push_back(ButtonValuePair(ob, value)); } @@ -49,15 +42,19 @@ void RadioButtonGroup::set(size_type value) find_if(map.begin(), map.end(), lyx::equal_2nd_in_pair(value)); - // If we found nothing, report it and return - if (it == map.end()) { - lyxerr << "BUG: Requested value in RadioButtonGroup doesn't exists" - << endl; - } - else { - fl_set_button(it->first, 1); + if (it != map.end()) { + set(it->first); + } else { + // We found nothing: report it and do nothing. + lyxerr << "BUG: Requested value in RadioButtonGroup " + "doesn't exist" << endl; } +} + +void RadioButtonGroup::set(FL_OBJECT * ob) +{ + fl_set_button(ob, 1); } @@ -72,18 +69,15 @@ struct is_set_button { RadioButtonGroup::size_type RadioButtonGroup::get() const { - // Find the first button that is active + // Find the active button. ButtonValueMap::const_iterator it = find_if(map.begin(), map.end(), is_set_button ()); - // If such a button was found, return its value. - if (it != map.end()) { + if (it != map.end()) return it->second; - } - - lyxerr << "BUG: No radio button found to be active." << endl; - // Else return 0. + // We found nothing: report it and return 0 + lyxerr << "BUG: No active radio button found." << endl; return 0; } diff --git a/src/frontends/xforms/RadioButtonGroup.h b/src/frontends/xforms/RadioButtonGroup.h index 0236b8fe5a..603e82b430 100644 --- a/src/frontends/xforms/RadioButtonGroup.h +++ b/src/frontends/xforms/RadioButtonGroup.h @@ -6,6 +6,7 @@ * Licence details can be found in the file COPYING. * * \author Baruch Even + * \author Rob Lahaye * * Full author contact details are available in file CREDITS */ @@ -23,28 +24,28 @@ #include #include "forms_fwd.h" -/** This class simplifies the work with a group of radio buttons, - * the idea is that you register a bunch of radio buttons with the accompanying - * value for each radio button and then you get to query or set the active - * button in a single function call. +/** This class simplifies interaction with a group of radio buttons: + * one, and only one, can be selected. + * The idea is that you register a bunch of radio buttons with + * an accompanying value. Then you can get or set the active button with a + * single function call. + * It is necessary to also group a family of radio buttons in the + * corresponding .fd file in order to unset the previously chosen button + * when a new one is selected. */ class RadioButtonGroup { public: /// typedef lyx::size_type size_type; - /// Constructor. Allocate space for 'n' items in the group. - RadioButtonGroup(unsigned n = 5) : map(n) {}; + /// Register a radio button with its corresponding value. + void init(FL_OBJECT * ob, size_type value); - /// Register a radio button with it's corresponding value. - void init(FL_OBJECT * button, size_type value); - /// Reset registrations. - void reset(); - - // Set the active button. + // Set a single active button. void set(size_type value); + void set(FL_OBJECT * ob); - // Get the active button. + // Get the active button's value. size_type get() const; private: diff --git a/src/frontends/xforms/xforms_helpers.C b/src/frontends/xforms/xforms_helpers.C index bf9ce98074..fab98d9d8d 100644 --- a/src/frontends/xforms/xforms_helpers.C +++ b/src/frontends/xforms/xforms_helpers.C @@ -29,6 +29,7 @@ #include #include #include + #include FORMS_H_LOCATION using std::ofstream; @@ -46,7 +47,7 @@ void setEnabled(FL_OBJECT * ob, bool enable) { if (enable) { fl_activate_object(ob); - fl_set_object_lcol(ob, FL_BLACK); + fl_set_object_lcol(ob, FL_LCOL); } else { fl_deactivate_object(ob); fl_set_object_lcol(ob, FL_INACTIVE); @@ -83,15 +84,17 @@ vector const getVector(FL_OBJECT * ob) /// string const getString(FL_OBJECT * ob, int line) { - char const * tmp = 0; + // Negative line value does not make sense. + lyx::Assert(line >= 0); + char const * tmp = 0; switch (ob->objclass) { case FL_INPUT: - lyx::Assert(line == -1); tmp = fl_get_input(ob); break; + case FL_BROWSER: - if (line == -1) + if (line == 0) line = fl_get_browser(ob); if (line >= 1 && line <= fl_get_browser_maxline(ob)) @@ -99,7 +102,7 @@ string const getString(FL_OBJECT * ob, int line) break; case FL_CHOICE: - if (line == -1) + if (line == 0) line = fl_get_choice(ob); if (line >= 1 && line <= fl_get_choice_maxitems(ob)) @@ -110,7 +113,7 @@ string const getString(FL_OBJECT * ob, int line) lyx::Assert(0); } - return (tmp) ? trim(tmp) : string(); + return tmp ? trim(tmp) : string(); } string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice) @@ -123,7 +126,7 @@ string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice) if (length.empty()) return string(); - //don't return unit-from-choice if the input(field) contains a unit + // don't return unit-from-choice if the input(field) contains a unit if (isValidGlueLength(length)) return length; diff --git a/src/frontends/xforms/xforms_helpers.h b/src/frontends/xforms/xforms_helpers.h index c413697f9e..cccfeb6f86 100644 --- a/src/frontends/xforms/xforms_helpers.h +++ b/src/frontends/xforms/xforms_helpers.h @@ -45,9 +45,10 @@ string formatted(string const &label, int w, /// Given an fl_choice or an fl_browser, create a vector of its entries std::vector const getVector(FL_OBJECT *); -/// Given an fl_input, an fl_choice or an fl_browser, return an entry -/** \c num is the position for the string, where -1 means "current item" */ -string const getString(FL_OBJECT * ob, int num = -1); +/** Given an fl_input, an fl_choice or an fl_browser, return an entry + \c num is the position for the string, where 0 means "current item" + */ +string const getString(FL_OBJECT * ob, int num = 0); /// Given input and choice widgets, create a string such as "1cm" string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice); -- 2.39.5