]> git.lyx.org Git - features.git/commitdiff
extended ButtonController so that only FL_OBJECT *s in a trigger_change_
authorAngus Leeming <leeming@lyx.org>
Wed, 14 Feb 2001 18:56:38 +0000 (18:56 +0000)
committerAngus Leeming <leeming@lyx.org>
Wed, 14 Feb 2001 18:56:38 +0000 (18:56 +0000)
vector can actually cause the Ok, Apply buttons to change state on input.
Vector created for FormCitation.

Please test!

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1514 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/xforms/ButtonController.C
src/frontends/xforms/ButtonController.h
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormBase.C
src/frontends/xforms/FormCitation.C

index da4ad9ab71f9263e0608b32b253ed89c30f9bf2b..b844ac0ac3db734803aa9fb1c726e8cba9d6789a 100644 (file)
 #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<FL_OBJECT *>::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;
 }
 
index 92e29828245460100016210809f83e3a2b39cbe3..3f3e661b92c389b844a186ddaca3a10a6753441b 100644 (file)
@@ -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<FL_OBJECT *> read_only_;
+       /// List of items that will trigger a change in activation status.
+       std::vector<FL_OBJECT *> trigger_change_;
        ///
        char const * cancel_label;
        ///
index e3afa8c0e6dacfc6eea96218fc8bea2f6aeab7cb..c0737f211879267301770e7f10cbb3634a5582ce 100644 (file)
@@ -1,3 +1,21 @@
+2001-02-14  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * 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  <a.leeming@ic.ac.uk>
 
        * FormBrowser.C: used OkCancelPolicy for ButtonController rather than
index c1f17f9a4bf70c5560951f56631f3c76fd518724..3502e471ded2205067777bb825dd21675f5a9ef7 100644 (file)
@@ -170,7 +170,7 @@ void FormBase::InputCB(FL_OBJECT * ob, long data)
        Assert(ob && ob->form);
        FormBase * pre = static_cast<FormBase*>(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<FormBase*>(ob->form->u_vdata);
        Assert(ob);
-       pre->restore();
        pre->bc_.undoAll();
+       pre->restore();
 }
 
 
index a6694383f272e928eb4baab8a1cf597709f84cd8..d9fee9a18eef2379d48d1cc6d648716041097b38 100644 (file)
@@ -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());
 }