From ccb3cb54e5c9f14428a74a8c9b5611f0eb7ff563 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Tue, 28 Aug 2001 13:48:40 +0000 Subject: [PATCH] Clean fix for Michael's reported bug with the character dialog. Occurred because build() is called from the controller meaning that minw_ etc were not reset. Fix to citation dialog; the style should now remain centred within the frame. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2607 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/xforms/ChangeLog | 18 ++++++++ src/frontends/xforms/FormAboutlyx.C | 5 +-- src/frontends/xforms/FormBase.C | 16 +++++-- src/frontends/xforms/FormBase.h | 19 ++++---- src/frontends/xforms/FormBrowser.C | 4 +- src/frontends/xforms/FormBrowser.h | 2 +- src/frontends/xforms/FormCharacter.C | 4 +- src/frontends/xforms/FormCitation.C | 48 +++++++++++---------- src/frontends/xforms/FormCitation.h | 2 +- src/frontends/xforms/FormThesaurus.C | 4 +- src/frontends/xforms/form_citation.C | 2 +- src/frontends/xforms/form_citation.h | 1 + src/frontends/xforms/forms/form_citation.fd | 3 +- 13 files changed, 76 insertions(+), 52 deletions(-) diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 492ebcf0d8..6a5e1f9800 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,21 @@ +2001-08-26 Angus Leeming + + * FormCitation.C: + * forms/form_citation.fd: a littl;e tweaking to ensure that the + style choice remains centred within the frame if its contents change. + + * FormBase.h: added an allow_resize_ member variable. If false + resizing the dialog is prohibitted. + + * FormBase.[Ch]: + * FormBrowser.[Ch]: modify c-tors to pass this new variable to FormBase. + + * FormAboutlyx.C: + * FormCharacter.C: + * FormThesaurus.C: + make use of this functionality to ensure that the dialog cannot be + resized. + 2001-08-24 John Levon * FormCitation.h: diff --git a/src/frontends/xforms/FormAboutlyx.C b/src/frontends/xforms/FormAboutlyx.C index e1b7ee7ea1..b87ae46c9c 100644 --- a/src/frontends/xforms/FormAboutlyx.C +++ b/src/frontends/xforms/FormAboutlyx.C @@ -25,7 +25,7 @@ using std::getline; typedef FormCB > base_class; FormAboutlyx::FormAboutlyx(ControlAboutlyx & c) - : base_class(c, _("About LyX")) + : base_class(c, _("About LyX"), false) {} FL_FORM * FormAboutlyx::form() const @@ -70,9 +70,6 @@ void FormAboutlyx::build() fl_addto_tabfolder(dialog_->tabbed_folder,_("Credits"), credits_->form); - fl_set_form_maxsize( dialog_->form, - dialog_->form->w, dialog_->form->h); - // Manage the cancel/close button bc().setCancel(dialog_->close); } diff --git a/src/frontends/xforms/FormBase.C b/src/frontends/xforms/FormBase.C index 8881b25738..70038eb489 100644 --- a/src/frontends/xforms/FormBase.C +++ b/src/frontends/xforms/FormBase.C @@ -24,8 +24,9 @@ extern "C" int C_FormBaseWMHideCB(FL_FORM * form, void *); -FormBase::FormBase(ControlButtons & c, string const & t) - : ViewBC(c), minw_(0), minh_(0), title_(t) +FormBase::FormBase(ControlButtons & c, string const & t, bool allowResize) + : ViewBC(c), minw_(0), minh_(0), allow_resize_(allowResize), + title_(t) {} @@ -40,7 +41,11 @@ void FormBase::show() { if (!form()) { build(); - + } + + // use minw_ to flag whether the dialog has ever been shown + // (Needed now that build() is/should be called from the controller) + if (minw_ == 0) { bc().refresh(); // work around dumb xforms sizing bug @@ -49,7 +54,7 @@ void FormBase::show() fl_set_form_atclose(form(), C_FormBaseWMHideCB, 0); } - + fl_freeze_form(form()); update(); // make sure its up-to-date fl_unfreeze_form(form()); @@ -69,6 +74,9 @@ void FormBase::show() // calls to fl_set_form_minsize/maxsize apply only to the next // fl_show_form(), so this comes first. fl_set_form_minsize(form(), minw_, minh_); + if (!allow_resize_) + fl_set_form_maxsize(form(), minw_, minh_); + fl_show_form(form(), FL_PLACE_MOUSE | FL_FREE_SIZE, 0, title_.c_str()); diff --git a/src/frontends/xforms/FormBase.h b/src/frontends/xforms/FormBase.h index d61281893d..4bc4d06e38 100644 --- a/src/frontends/xforms/FormBase.h +++ b/src/frontends/xforms/FormBase.h @@ -33,7 +33,7 @@ class FormBase : public ViewBC { public: /// - FormBase(ControlButtons &, string const &); + FormBase(ControlButtons &, string const &, bool allowResize); /// virtual ~FormBase() {} @@ -59,13 +59,13 @@ private: that the xform colors have been re-mapped). */ virtual void redraw(); -protected: /// Overcome a dumb xforms sizing bug mutable int minw_; /// mutable int minh_; + /// Can the dialog be resized after it has been created? + bool allow_resize_; -private: /// dialog title, displayed by WM. string title_; }; @@ -76,7 +76,7 @@ class FormDB: public FormBase { protected: /// - FormDB(ControlButtons &, string const &); + FormDB(ControlButtons &, string const &, bool allowResize=true); /// Pointer to the actual instantiation of xform's form virtual FL_FORM * form() const; /// Real GUI implementation. @@ -85,8 +85,8 @@ protected: template -FormDB::FormDB(ControlButtons & c, string const & t) - : FormBase(c, t) +FormDB::FormDB(ControlButtons & c, string const & t, bool allowResize) + : FormBase(c, t, allowResize) {} @@ -103,15 +103,16 @@ class FormCB: public Base { protected: /// - FormCB(ControlButtons &, string const &); + FormCB(ControlButtons &, string const &, bool allowResize=true); /// The parent controller Controller & controller() const; }; template -FormCB::FormCB(ControlButtons & c, string const & t) - : Base(c, t) +FormCB::FormCB(ControlButtons & c, string const & t, + bool allowResize) + : Base(c, t, allowResize) {} diff --git a/src/frontends/xforms/FormBrowser.C b/src/frontends/xforms/FormBrowser.C index 54a1f355f0..f75ff009a3 100644 --- a/src/frontends/xforms/FormBrowser.C +++ b/src/frontends/xforms/FormBrowser.C @@ -12,8 +12,8 @@ #include "form_browser.h" #include "xformsBC.h" -FormBrowser::FormBrowser(ControlButtons & c, string const & t) - : FormDB(c, t) +FormBrowser::FormBrowser(ControlButtons & c, string const & t, bool allowResize) + : FormDB(c, t, allowResize) {} diff --git a/src/frontends/xforms/FormBrowser.h b/src/frontends/xforms/FormBrowser.h index 1e6a891e3e..58be37f7ae 100644 --- a/src/frontends/xforms/FormBrowser.h +++ b/src/frontends/xforms/FormBrowser.h @@ -25,7 +25,7 @@ struct FD_form_browser; class FormBrowser : public FormDB { public: /// - FormBrowser(ControlButtons &, string const &); + FormBrowser(ControlButtons &, string const &, bool allowResize=true); private: /// Build the dialog. diff --git a/src/frontends/xforms/FormCharacter.C b/src/frontends/xforms/FormCharacter.C index 3b5765ae7a..57aa52abc2 100644 --- a/src/frontends/xforms/FormCharacter.C +++ b/src/frontends/xforms/FormCharacter.C @@ -31,7 +31,7 @@ using namespace character; typedef FormCB > base_class; FormCharacter::FormCharacter(ControlCharacter & c) - : base_class(c, _("Character Layout")) + : base_class(c, _("Character Layout"), false) {} @@ -45,8 +45,6 @@ void FormCharacter::build() { dialog_.reset(build_character()); - fl_set_form_maxsize(dialog_->form, minw_, minh_); - vector const family = getFamilyData(); vector const series = getSeriesData(); vector const shape = getShapeData(); diff --git a/src/frontends/xforms/FormCitation.C b/src/frontends/xforms/FormCitation.C index 4f9857f7fb..6ad5f47e49 100644 --- a/src/frontends/xforms/FormCitation.C +++ b/src/frontends/xforms/FormCitation.C @@ -46,12 +46,15 @@ int string_width(string const & str) } -void fillChoice(FL_OBJECT * choice, vector const & vec) +void fillChoice(FD_form_citation * dialog, vector vec) { string const str = " " + getStringFromVector(vec, " | ") + " "; - fl_clear_choice(choice); - fl_addto_choice(choice, str.c_str()); + fl_clear_choice(dialog->choice_style); + fl_addto_choice(dialog->choice_style, str.c_str()); + + // The width of the choice varies with the contents. + // Ensure that it is centred in the frame. int width = 0; for (vector::const_iterator it = vec.begin(); @@ -59,16 +62,18 @@ void fillChoice(FL_OBJECT * choice, vector const & vec) width = max(width, string_width(*it)); } - // Paranoia checks - int const x = max(5, int(choice->x + 0.5 * (choice->w - width))); - if (x + width > choice->form->w) - width = choice->form->w - 10; - - fl_set_object_geometry(choice, x, choice->y, width + 5, choice->h); + int const dx = + max(5, int(0.5 * (dialog->frame_style->w - width))); + + fl_set_object_geometry(dialog->choice_style, + dialog->frame_style->x + dx, + dialog->choice_style->y, + width, + dialog->choice_style->h); } -void updateStyle(FL_OBJECT * choice, FL_OBJECT * full, FL_OBJECT * force, - string command) + +void updateStyle(FD_form_citation * dialog, string command) { // Find the style of the citekeys vector const & styles = @@ -80,14 +85,14 @@ void updateStyle(FL_OBJECT * choice, FL_OBJECT * full, FL_OBJECT * force, // Use this to initialise the GUI if (cit == styles.end()) { - fl_set_choice(choice, 1); - fl_set_button(full, 0); - fl_set_button(force, 0); + fl_set_choice(dialog->choice_style, 1); + fl_set_button(dialog->button_full_author_list, 0); + fl_set_button(dialog->button_force_uppercase, 0); } else { int const i = int(cit - styles.begin()); - fl_set_choice(choice, i+1); - fl_set_button(full, cs.full); - fl_set_button(force, cs.forceUCase); + fl_set_choice(dialog->choice_style, i+1); + fl_set_button(dialog->button_full_author_list, cs.full); + fl_set_button(dialog->button_force_uppercase, cs.forceUCase); } } @@ -357,7 +362,7 @@ ButtonPolicy::SMInput FormCitation::input(FL_OBJECT * ob, long) if (topCitekey != currentCitekey) { int choice = fl_get_choice(dialog_->choice_style); - fillChoice(dialog_->choice_style, + fillChoice(dialog_.get(), controller().getCiteStrings(currentCitekey)); fl_set_choice(dialog_->choice_style, choice); } @@ -380,13 +385,10 @@ void FormCitation::update() string key; if (!citekeys.empty()) key = citekeys[0]; - fillChoice(dialog_->choice_style, controller().getCiteStrings(key)); + fillChoice(dialog_.get(), controller().getCiteStrings(key)); // Use the citation command to update the GUI - updateStyle(dialog_->choice_style, - dialog_->button_full_author_list, - dialog_->button_force_uppercase, - controller().params().getCmdName()); + updateStyle(dialog_.get(), controller().params().getCmdName()); bool const natbib = controller().usingNatbib(); setEnabled(dialog_->button_full_author_list, natbib); diff --git a/src/frontends/xforms/FormCitation.h b/src/frontends/xforms/FormCitation.h index 1bac28bb52..cef3dc4edb 100644 --- a/src/frontends/xforms/FormCitation.h +++ b/src/frontends/xforms/FormCitation.h @@ -56,7 +56,7 @@ private: FD_form_citation * build_citation(); /// search for a citation - void FormCitation::findBiblio(biblio::Direction const dir); + void findBiblio(biblio::Direction const dir); /// void updateBrowser(FL_OBJECT *, std::vector const &) const; diff --git a/src/frontends/xforms/FormThesaurus.C b/src/frontends/xforms/FormThesaurus.C index 31d2ed9a42..c385da9677 100644 --- a/src/frontends/xforms/FormThesaurus.C +++ b/src/frontends/xforms/FormThesaurus.C @@ -24,7 +24,7 @@ typedef FormCB > base_class; FormThesaurus::FormThesaurus(ControlThesaurus & c) - : base_class(c, _("LyX: Thesaurus")), + : base_class(c, _("LyX: Thesaurus"), false), clickline_(-1) { } @@ -39,8 +39,6 @@ void FormThesaurus::build() adverb_.reset(build_adverb()); other_.reset(build_other()); - fl_set_form_maxsize(dialog_->form, minw_, minh_); - // Manage the ok, apply and cancel/close buttons bc().setCancel(dialog_->button_close); bc().addReadOnly(dialog_->input_replace); diff --git a/src/frontends/xforms/form_citation.C b/src/frontends/xforms/form_citation.C index c5e1d69c71..7cdefe5c77 100644 --- a/src/frontends/xforms/form_citation.C +++ b/src/frontends/xforms/form_citation.C @@ -93,7 +93,7 @@ FD_form_citation * FormCitation::build_citation() } fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); fl_set_object_callback(obj, C_FormBaseInputCB, 0); - obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 410, 280, 370, 80, _("Citation style")); + fdui->frame_style = obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 410, 280, 370, 80, _("Citation style")); fl_set_object_shortcut(obj, _("frame_style"), 1); fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_lstyle(obj, FL_BOLD_STYLE); diff --git a/src/frontends/xforms/form_citation.h b/src/frontends/xforms/form_citation.h index 49c2f8e2e3..828287e8d6 100644 --- a/src/frontends/xforms/form_citation.h +++ b/src/frontends/xforms/form_citation.h @@ -31,6 +31,7 @@ struct FD_form_citation { FL_OBJECT *button_search_case; FL_OBJECT *button_previous; FL_OBJECT *button_next; + FL_OBJECT *frame_style; FL_OBJECT *choice_style; FL_OBJECT *button_full_author_list; FL_OBJECT *button_force_uppercase; diff --git a/src/frontends/xforms/forms/form_citation.fd b/src/frontends/xforms/forms/form_citation.fd index d88e6bb198..10eb4896df 100644 --- a/src/frontends/xforms/forms/form_citation.fd +++ b/src/frontends/xforms/forms/form_citation.fd @@ -157,6 +157,7 @@ callback: argument: -------------------- + class: FL_LABELFRAME type: ENGRAVED_FRAME box: 410 140 370 120 @@ -278,7 +279,7 @@ label: Citation style shortcut: frame_style resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity -name: +name: frame_style callback: argument: -- 2.39.5