(Rob Lahaye): miscellaneous bits 'n' bobs.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5477 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2002-10-23 08:31:10 +00:00
parent 357ece3f85
commit fe66fc4644
8 changed files with 68 additions and 55 deletions

View File

@ -1,3 +1,21 @@
2002-10-22 Rob Lahaye <lahaye@snu.ac.kr>
* 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 <lahaye@snu.ac.kr> 2002-10-22 Rob Lahaye <lahaye@snu.ac.kr>
* forms/form_aboutlyx.fd: implement the text widgets as browsers * forms/form_aboutlyx.fd: implement the text widgets as browsers

View File

@ -39,7 +39,7 @@ void FeedbackController::setMessageWidget(FL_OBJECT * ob)
{ {
lyx::Assert(ob && ob->objclass == FL_TEXT); lyx::Assert(ob && ob->objclass == FL_TEXT);
message_widget_ = ob; 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 else
str = message; 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_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); fl_set_object_lcol(message_widget_, label_color);
if (!message_widget_->visible) if (!message_widget_->visible)

View File

@ -18,7 +18,6 @@
#endif #endif
#include "FormBase.h" #include "FormBase.h"
#include "RadioButtonGroup.h"
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>

View File

@ -34,8 +34,7 @@ using std::make_pair;
typedef FormCB<ControlPrint, FormDB<FD_print> > base_class; typedef FormCB<ControlPrint, FormDB<FD_print> > base_class;
FormPrint::FormPrint() FormPrint::FormPrint()
: base_class(_("Print")), : base_class(_("Print"))
target_(2), which_pages_(2)
{} {}
@ -70,10 +69,8 @@ void FormPrint::build()
bc().addReadOnly(dialog_->check_sorted_copies); bc().addReadOnly(dialog_->check_sorted_copies);
bc().addReadOnly(dialog_->check_reverse_order); bc().addReadOnly(dialog_->check_reverse_order);
target_.reset();
target_.init(dialog_->radio_printer, PrinterParams::PRINTER); target_.init(dialog_->radio_printer, PrinterParams::PRINTER);
target_.init(dialog_->radio_file, PrinterParams::FILE); target_.init(dialog_->radio_file, PrinterParams::FILE);
which_pages_.reset();
which_pages_.init(dialog_->radio_all_pages, true); which_pages_.init(dialog_->radio_all_pages, true);
which_pages_.init(dialog_->radio_from_to, false); which_pages_.init(dialog_->radio_from_to, false);

View File

@ -6,6 +6,7 @@
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author Baruch Even * \author Baruch Even
* \author Rob Lahaye
* *
* Full author contact details are available in file CREDITS * Full author contact details are available in file CREDITS
*/ */
@ -22,24 +23,16 @@
#include "debug.h" // for lyxerr #include "debug.h" // for lyxerr
#include "support/lyxfunctional.h" #include "support/lyxfunctional.h"
//#include <functional>
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
using std::find_if; using std::find_if;
//using std::bind2nd;
using std::endl; 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)); map.push_back(ButtonValuePair(ob, value));
}
void RadioButtonGroup::reset()
{
map.clear();
} }
@ -49,15 +42,19 @@ void RadioButtonGroup::set(size_type value)
find_if(map.begin(), map.end(), find_if(map.begin(), map.end(),
lyx::equal_2nd_in_pair<ButtonValuePair>(value)); lyx::equal_2nd_in_pair<ButtonValuePair>(value));
// If we found nothing, report it and return if (it != map.end()) {
if (it == map.end()) { set(it->first);
lyxerr << "BUG: Requested value in RadioButtonGroup doesn't exists" } else {
<< endl; // We found nothing: report it and do nothing.
} lyxerr << "BUG: Requested value in RadioButtonGroup "
else { "doesn't exist" << endl;
fl_set_button(it->first, 1);
} }
}
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 RadioButtonGroup::size_type RadioButtonGroup::get() const
{ {
// Find the first button that is active // Find the active button.
ButtonValueMap::const_iterator it = ButtonValueMap::const_iterator it =
find_if(map.begin(), map.end(), find_if(map.begin(), map.end(),
is_set_button<ButtonValuePair> ()); is_set_button<ButtonValuePair> ());
// If such a button was found, return its value. if (it != map.end())
if (it != map.end()) {
return it->second; return it->second;
}
lyxerr << "BUG: No radio button found to be active." << endl; // We found nothing: report it and return 0
lyxerr << "BUG: No active radio button found." << endl;
// Else return 0.
return 0; return 0;
} }

View File

@ -6,6 +6,7 @@
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author Baruch Even * \author Baruch Even
* \author Rob Lahaye
* *
* Full author contact details are available in file CREDITS * Full author contact details are available in file CREDITS
*/ */
@ -23,28 +24,28 @@
#include <utility> #include <utility>
#include "forms_fwd.h" #include "forms_fwd.h"
/** This class simplifies the work with a group of radio buttons, /** This class simplifies interaction with a group of radio buttons:
* the idea is that you register a bunch of radio buttons with the accompanying * one, and only one, can be selected.
* value for each radio button and then you get to query or set the active * The idea is that you register a bunch of radio buttons with
* button in a single function call. * 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 { class RadioButtonGroup {
public: public:
/// ///
typedef lyx::size_type size_type; typedef lyx::size_type size_type;
/// Constructor. Allocate space for 'n' items in the group. /// Register a radio button with its corresponding value.
RadioButtonGroup(unsigned n = 5) : map(n) {}; void init(FL_OBJECT * ob, size_type value);
/// Register a radio button with it's corresponding value. // Set a single active button.
void init(FL_OBJECT * button, size_type value);
/// Reset registrations.
void reset();
// Set the active button.
void set(size_type value); void set(size_type value);
void set(FL_OBJECT * ob);
// Get the active button. // Get the active button's value.
size_type get() const; size_type get() const;
private: private:

View File

@ -29,6 +29,7 @@
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
#include <vector> #include <vector>
#include FORMS_H_LOCATION #include FORMS_H_LOCATION
using std::ofstream; using std::ofstream;
@ -46,7 +47,7 @@ void setEnabled(FL_OBJECT * ob, bool enable)
{ {
if (enable) { if (enable) {
fl_activate_object(ob); fl_activate_object(ob);
fl_set_object_lcol(ob, FL_BLACK); fl_set_object_lcol(ob, FL_LCOL);
} else { } else {
fl_deactivate_object(ob); fl_deactivate_object(ob);
fl_set_object_lcol(ob, FL_INACTIVE); fl_set_object_lcol(ob, FL_INACTIVE);
@ -83,15 +84,17 @@ vector<string> const getVector(FL_OBJECT * ob)
/// ///
string const getString(FL_OBJECT * ob, int line) 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) { switch (ob->objclass) {
case FL_INPUT: case FL_INPUT:
lyx::Assert(line == -1);
tmp = fl_get_input(ob); tmp = fl_get_input(ob);
break; break;
case FL_BROWSER: case FL_BROWSER:
if (line == -1) if (line == 0)
line = fl_get_browser(ob); line = fl_get_browser(ob);
if (line >= 1 && line <= fl_get_browser_maxline(ob)) if (line >= 1 && line <= fl_get_browser_maxline(ob))
@ -99,7 +102,7 @@ string const getString(FL_OBJECT * ob, int line)
break; break;
case FL_CHOICE: case FL_CHOICE:
if (line == -1) if (line == 0)
line = fl_get_choice(ob); line = fl_get_choice(ob);
if (line >= 1 && line <= fl_get_choice_maxitems(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); lyx::Assert(0);
} }
return (tmp) ? trim(tmp) : string(); return tmp ? trim(tmp) : string();
} }
string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice) string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
@ -123,7 +126,7 @@ string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
if (length.empty()) if (length.empty())
return string(); 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)) if (isValidGlueLength(length))
return length; return length;

View File

@ -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 /// Given an fl_choice or an fl_browser, create a vector of its entries
std::vector<string> const getVector(FL_OBJECT *); std::vector<string> const getVector(FL_OBJECT *);
/// Given an fl_input, an fl_choice or an fl_browser, return an entry /** 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" */ \c num is the position for the string, where 0 means "current item"
string const getString(FL_OBJECT * ob, int num = -1); */
string const getString(FL_OBJECT * ob, int num = 0);
/// Given input and choice widgets, create a string such as "1cm" /// Given input and choice widgets, create a string such as "1cm"
string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice); string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice);