diff --git a/src/frontends/xforms/ButtonController.C b/src/frontends/xforms/ButtonController.C index da4ad9ab71..b844ac0ac3 100644 --- a/src/frontends/xforms/ButtonController.C +++ b/src/frontends/xforms/ButtonController.C @@ -11,11 +11,14 @@ #include "gettext.h" // _() //#include "debug.h" +using std::find; +using std::vector; ButtonController::ButtonController(ButtonPolicy * bp, char const * cancel, char const * close) : bp_(bp), okay_(0), apply_(0), cancel_(0), undo_all_(0), - read_only_(), cancel_label(cancel), close_label(close) + read_only_(), trigger_change_(), + cancel_label(cancel), close_label(close) { Assert(bp); } @@ -143,13 +146,29 @@ void ButtonController::readWrite() } -bool ButtonController::valid(bool v) +bool ButtonController::valid(bool v, FL_OBJECT * obj) { - if (v) { - input(ButtonPolicy::SMI_VALID); + if (obj && !trigger_change_.empty()) { + vector::const_iterator cit = + find(trigger_change_.begin(), trigger_change_.end(), + obj); + + // Only trigger a change if the obj is in the list + if (cit != trigger_change_.end()) { + if (v) { + input(ButtonPolicy::SMI_VALID); + } else { + input(ButtonPolicy::SMI_INVALID); + } + } } else { - input(ButtonPolicy::SMI_INVALID); + if (v) { + input(ButtonPolicy::SMI_VALID); + } else { + input(ButtonPolicy::SMI_INVALID); + } } + return v; } diff --git a/src/frontends/xforms/ButtonController.h b/src/frontends/xforms/ButtonController.h index 92e2982824..3f3e661b92 100644 --- a/src/frontends/xforms/ButtonController.h +++ b/src/frontends/xforms/ButtonController.h @@ -89,6 +89,15 @@ public: read_only_.erase(read_only_.begin(), read_only_.end()); } + /// + void addTriggerChange(FL_OBJECT * obj) { + trigger_change_.push_back(obj); + } + /// + void eraseTriggerChange() { + trigger_change_.clear(); + } + /* Action Functions */ /// force a refresh of the buttons void refresh(); @@ -110,7 +119,7 @@ public: /// void readWrite(); /// Passthrough function -- returns its input value - bool valid(bool v = true); + bool valid(bool v = true, FL_OBJECT * obj = 0); /// void invalid(); private: @@ -126,6 +135,8 @@ private: FL_OBJECT * undo_all_; /// List of items to be deactivated when in one of the read-only states std::list read_only_; + /// List of items that will trigger a change in activation status. + std::vector trigger_change_; /// char const * cancel_label; /// diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index e3afa8c0e6..c0737f2118 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,21 @@ +2001-02-14 Angus Leeming + + * ButtonController.[Ch] (addTriggerChange, eraseTriggerChange): + new methods. + (valid): method can now be passed an optional FL_OBJECT *. If it is, and + the vector of FL_OBJECT *s that can trigger a change in the button state + is not empty, then a change of state will occur only if the FL_OBJECT * + is present in this vector. + + * FormBase.C (RestoreCB): call bc.undoAll() before restore(). Allows + the user to deactivate specific fields within restore(). + (InputCB): pass the FL_OBJECT * to bc_.valid(). + + * FormCitation.C (build): create a vector of FL_OBJECT *s that can + trigger a change of state in the Ok,Apply buttons. + (update): bc_.readOnly() to the start of the method. Similar reasoning + to that for FormBase::RestoreCB, above. + 2001-02-14 Angus Leeming * FormBrowser.C: used OkCancelPolicy for ButtonController rather than diff --git a/src/frontends/xforms/FormBase.C b/src/frontends/xforms/FormBase.C index c1f17f9a4b..3502e471de 100644 --- a/src/frontends/xforms/FormBase.C +++ b/src/frontends/xforms/FormBase.C @@ -170,7 +170,7 @@ void FormBase::InputCB(FL_OBJECT * ob, long data) Assert(ob && ob->form); FormBase * pre = static_cast(ob->form->u_vdata); Assert(ob); - pre->bc_.valid(pre->input(ob, data)); + pre->bc_.valid(pre->input(ob, data), ob); } @@ -179,8 +179,8 @@ void FormBase::RestoreCB(FL_OBJECT * ob, long) Assert(ob && ob->form); FormBase * pre = static_cast(ob->form->u_vdata); Assert(ob); - pre->restore(); pre->bc_.undoAll(); + pre->restore(); } diff --git a/src/frontends/xforms/FormCitation.C b/src/frontends/xforms/FormCitation.C index a6694383f2..d9fee9a18e 100644 --- a/src/frontends/xforms/FormCitation.C +++ b/src/frontends/xforms/FormCitation.C @@ -96,11 +96,20 @@ void FormCitation::build() bc_.addReadOnly(dialog_->downBtn); bc_.addReadOnly(dialog_->textBefore); bc_.addReadOnly(dialog_->textAftr); + + bc_.addTriggerChange(dialog_->addBtn); + bc_.addTriggerChange(dialog_->delBtn); + bc_.addTriggerChange(dialog_->upBtn); + bc_.addTriggerChange(dialog_->downBtn); + bc_.addTriggerChange(dialog_->textBefore); + bc_.addTriggerChange(dialog_->textAftr); } void FormCitation::update() { + bc_.readOnly(lv_->buffer()->isReadonly()); + bibkeys.clear(); bibkeysInfo.clear(); @@ -141,8 +150,6 @@ void FormCitation::update() setSize( size, bibPresent ); fl_set_input( dialog_->textAftr, params.getOptions().c_str()); - - bc_.readOnly(lv_->buffer()->isReadonly()); }