]> git.lyx.org Git - features.git/commitdiff
more docs for ButtonPolicies; fix form_document segfault in lyx_gui_misc.C
authorAllan Rae <rae@lyx.org>
Mon, 21 Aug 2000 01:03:31 +0000 (01:03 +0000)
committerAllan Rae <rae@lyx.org>
Mon, 21 Aug 2000 01:03:31 +0000 (01:03 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@980 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
src/ext_l10n.h
src/frontends/ButtonPolicies.h
src/frontends/xforms/ButtonController.h
src/frontends/xforms/form_preferences.C
src/frontends/xforms/forms/form_preferences.fd
src/lyx_gui_misc.C

index dadb68a58831bd50374e84b3c3ef1eaef025b364..a804da49ffa1b3f3b76a3f8bc4c9674c4018bde3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2000-08-21  Allan Rae  <rae@lyx.org>
+
+       * src/frontends/xforms/ButtonController.h (class ButtonController): Allow
+       automatic [de]activation of arbitrary objects when in a read-only state.
+
+       * src/frontends/ButtonPolicies.h: More documentation
+       (isReadOnly): added to support the above.
+
+       * src/frontends/xforms/forms/form_preferences.fd: Changed Ok -> Save
+
 2000-08-18  Juergen Vigna  <jug@sad.it>
 
        * src/insets/insettabular.C (getStatus): changed to return func_status.
index d4c5eae411a746cdb5359fed42d30de5c9b70e64..bdefdb55be4ecc1e34344d00a292042a8e2633d0 100644 (file)
@@ -84,11 +84,11 @@ _("Undo last check in|U");
 _("Show History|H");
 _("Character...|C");
 _("Paragraph...|P");
-_("Paper...|a");
 _("Document...|D");
-_("Table...|T");
-_("Tabular...|a");
+_("Paper...|a");
 _("Quotes...|Q");
+_("Tabular...|a");
+_("Table...|T");
 _("Emphasize Style|E");
 _("Noun Style|N");
 _("Bold Style|B");
index d817ad233ca4a830c50c42a024d04ff5d18aec02..29a7483792eb680f59a96fc77e128b17792a3358 100644 (file)
     A state machine implementation of the various button policies used by the
     dialogs. Only the policy is implemented here.  Separate ButtonController
     classes are needed for each GUI implementation.
+
+               Policy          | ReadOnly | Apply Button | Repeated Apply
+    ========================================================================
+    OkCancel                   |       N  |    N         |     -
+    OkCancelReadOnly           |       Y  |    N         |     -
+    OkApplyCancel              |       N  |    Y         |     Y
+    OkApplyCancelReadOnly      |       Y  |    Y         |     Y
+    NoRepeatedApply            |       N  |    Y         |     N
+    NoRepeatedApplyReadOnly    |       Y  |    Y         |     N
+    Preferences                        |       N  |    Y         | No (Ok-Close)
+    ========================================================================
+
+    Policy
+       The name of the policy
+    ReadOnly
+       Does the policy treat read-only docs differently to read-write docs?
+       This usually means that when an SMI_READ_ONLY input arrives then
+       all the buttons are disabled except Cancel/Close.  The state
+       machine tracks the inputs (valid/invalid) and has states for all
+       combinations. When an SMI_READ_WRITE input arrives the appropriate
+       machine state is entered (just as if the document had always been
+       read-write).
+       NOTE: If a dialog doesn't care about the read-only status of a document
+       (and uses an appropriate policy) it can never get into a read-only state
+       so isReadOnly() can only ever return false even though the document may
+       be read-only.
+    Repeated Apply
+       Simply means that it is alright to use the Apply button multiple times
+       without requiring a change of the dialog contents.  If no repeating is
+       allowed the Ok+Apply buttons are deactivated.  The Preferences dialog
+       has its own special version of repeated apply handling because its Ok
+       button is actually a Save button -- its always reasonable to Save the
+       preferences if the dialog has changed since the last save.
  */
 class ButtonPolicy : public noncopyable
 {
@@ -89,8 +122,10 @@ public:
        //@{
        /// Trigger a transition with this input.
        virtual void input(SMInput) = 0;
-       /// Activation status of OK
+       /// Activation status of a button
        virtual bool buttonStatus(Button) = 0;
+       /// Are we in a read-only state?
+       virtual bool isReadOnly() = 0;
        //@}
 
        /**@name Typedefs */
@@ -104,19 +139,20 @@ public:
 };
 
 
-/** Defines the policy used by the Preferences dialog.
-    Four buttons: Ok (Save), Apply, Cancel/Close, Restore.
+//--------------------- Actual Policy Classes ----------------------------------
+
+/** Ok and Cancel buttons for dialogs with read-only operation.
     Note: This scheme supports the relabelling of Cancel to Close and vice versa.
     This is based on the value of the bool state of the Button::CANCEL.
     true == Cancel, false == Close
  */
-class PreferencesPolicy : public ButtonPolicy
+class OkCancelPolicy : public ButtonPolicy
 {
 public:
        ///
-       PreferencesPolicy();
+       OkCancelPolicy();
        ///
-       virtual ~PreferencesPolicy() {}
+       virtual ~OkCancelPolicy() {}
        
        /**@name Access Functions */
        //@{
@@ -131,41 +167,9 @@ public:
         */
        virtual bool buttonStatus(Button button)
                { return button & outputs_[state_]; }
-       //@}
-private:
-       /**@name Private Data Members */
-       //@{
-       /// Current state.
-       State state_;
-       /// Which buttons are active for a given state.
-       StateOutputs outputs_;
-       ///
-       StateMachine state_machine_;
-       //@}
-};
-
-
-
-/** Ok and Cancel buttons for dialogs with read-only operation.
-    Note: This scheme supports the relabelling of Cancel to Close and vice versa.
-    This is based on the value of the bool state of the Button::CANCEL.
-    true == Cancel, false == Close
- */
-class OkCancelPolicy : public ButtonPolicy
-{
-public:
-       ///
-       OkCancelPolicy();
-       ///
-       virtual ~OkCancelPolicy() {}
-       
-       /**@name Access Functions */
-       //@{
-       /// Trigger a transition with this input.
-       virtual void input(SMInput);
-       /// Activation status of a button.
-       virtual bool buttonStatus(Button button)
-               { return button & outputs_[state_]; }
+       /// Are we in a read-only state?
+       virtual bool isReadOnly()
+               { return false; }
        //@}
 private:
        /**@name Private Data Members */
@@ -204,6 +208,14 @@ public:
        /// Activation status of a button.
        virtual bool buttonStatus(Button button)
                { return button & outputs_[state_]; }
+       /// Are we in a read-only state?
+       virtual bool isReadOnly()
+               {
+                       return RO_INITIAL == state_
+                               || RO_VALID == state_
+                               || RO_INVALID == state_
+                               || RO_APPLIED == state_;
+               }
        //@}
 private:
        /**@name Private Data Members */
@@ -246,6 +258,14 @@ public:
        /// Activation status of a button.
        virtual bool buttonStatus(Button button)
                { return button & outputs_[state_]; }
+       /// Are we in a read-only state?
+       virtual bool isReadOnly()
+               {
+                       return RO_INITIAL == state_
+                               || RO_VALID == state_
+                               || RO_INVALID == state_
+                               || RO_APPLIED == state_;
+               }
        //@}
 private:
        /**@name Private Data Members */
@@ -286,6 +306,14 @@ public:
        /// Activation status of a button.
        virtual bool buttonStatus(Button button)
                { return button & outputs_[state_]; }
+       /// Are we in a read-only state?
+       virtual bool isReadOnly()
+               {
+                       return RO_INITIAL == state_
+                               || RO_VALID == state_
+                               || RO_INVALID == state_
+                               || RO_APPLIED == state_;
+               }
        //@}
 private:
        /**@name Private Data Members */
@@ -320,6 +348,9 @@ public:
        /// Activation status of a button.
        virtual bool buttonStatus(Button button)
                { return button & outputs_[state_]; }
+       /// Are we in a read-only state?
+       virtual bool isReadOnly()
+               { return false; }
        //@}
 private:
        /**@name Private Data Members */
@@ -354,6 +385,47 @@ public:
        /// Activation status of a button.
        virtual bool buttonStatus(Button button)
                { return button & outputs_[state_]; }
+       /// Are we in a read-only state?
+       virtual bool isReadOnly()
+               { return false; }
+       //@}
+private:
+       /**@name Private Data Members */
+       //@{
+       /// Current state.
+       State state_;
+       /// Which buttons are active for a given state.
+       StateOutputs outputs_;
+       ///
+       StateMachine state_machine_;
+       //@}
+};
+
+
+/** Defines the policy used by the Preferences dialog.
+    Four buttons: Ok (Save), Apply, Cancel/Close, Restore.
+    Note: This scheme supports the relabelling of Cancel to Close and vice versa.
+    This is based on the value of the bool state of the Button::CANCEL.
+    true == Cancel, false == Close
+ */
+class PreferencesPolicy : public ButtonPolicy
+{
+public:
+       ///
+       PreferencesPolicy();
+       ///
+       virtual ~PreferencesPolicy() {}
+       
+       /**@name Access Functions */
+       //@{
+       /// Trigger a transition with this input.
+       virtual void input(SMInput);
+       /// Activation status of a button.
+       virtual bool buttonStatus(Button button)
+               { return button & outputs_[state_]; }
+       /// Are we in a read-only state?
+       virtual bool isReadOnly()
+               { return false; }
        //@}
 private:
        /**@name Private Data Members */
index b6f1086d5aa7b8b75985f50adb50ce3a256ab986..b85c4f45329ba4bbb6bcfdd81888fcb4852c7ae4 100644 (file)
@@ -22,6 +22,7 @@
 #define BUTTONCONTROLLER_H
 
 #include "ButtonPolicies.h"
+#include <list>
 
 /** General purpose button controller for up to four buttons.
     Controls the activation of the OK, Apply and Cancel buttons.
@@ -45,7 +46,7 @@ public:
         */
        ButtonController(char const * cancel, char const * close)
                : bp_(), okay_(0), apply_(0), cancel_(0), undo_all_(0),
-                 cancel_label(cancel), close_label(close) {}
+                 read_only_(), cancel_label(cancel), close_label(close) {}
        /// Somebody else owns the FL_OBJECTs we just manipulate them.
        ~ButtonController() {}
        //@}
@@ -70,6 +71,12 @@ public:
        ///
        void setCancelFalseLabel(char const * c)
                { close_label = c; }
+       ///
+       void addReadOnly(FL_OBJECT * obj)
+               { read_only_.push_front(obj); }
+       ///
+       void eraseReadOnly()
+               { read_only_.erase(read_only_.begin(), read_only_.end()); }
        //@}
 
        /**@name Action Functions */
@@ -161,6 +168,27 @@ public:
                                                            close_label);
                                }
                        }
+                       if (!read_only_.empty()) {
+                               if (bp_.isReadOnly()) {
+                                       for (std::list<FL_OBJECT *>::iterator
+                                                    iter = read_only_.begin();
+                                            iter != read_only_.end();
+                                            ++iter) {
+                                               fl_deactivate_object(*iter);
+                                               fl_set_object_lcol(undo_all_,
+                                                                  FL_INACTIVE);
+                                       }
+                               } else {
+                                       for (std::list<FL_OBJECT *>::iterator
+                                                    iter = read_only_.begin();
+                                            iter != read_only_.end();
+                                            ++iter) {
+                                               fl_activate_object(undo_all_);
+                                               fl_set_object_lcol(undo_all_,
+                                                                  FL_BLACK);
+                                       }
+                               }
+                       }
                }
        //@}
 private:
@@ -176,6 +204,8 @@ private:
        FL_OBJECT * cancel_;
        ///
        FL_OBJECT * undo_all_;
+       /// List of items to be deactivated when in one of the read-only states
+       std::list<FL_OBJECT *> read_only_;
        //@}
        /**@name Cancel/Close Button Labels */
        //@{
index 4863eba76d6575e5c5ed9bf4496cbde952b2a5fd..41a2ab478c0bc17d2bc94e4f459f1aa195c78b1f 100644 (file)
@@ -371,7 +371,7 @@ FD_form_preferences * FormPreferences::build_preferences()
     fl_set_button_shortcut(obj, scex(_("Cancel|^[")), 1);
     fl_set_object_lsize(obj, FL_NORMAL_SIZE);
     fl_set_object_callback(obj, C_FormPreferencesCancelCB, 0);
-  fdui->button_ok = obj = fl_add_button(FL_RETURN_BUTTON, 175, 395, 90, 30, _("Ok"));
+  fdui->button_ok = obj = fl_add_button(FL_RETURN_BUTTON, 175, 395, 90, 30, _("Save"));
     fl_set_object_lsize(obj, FL_NORMAL_SIZE);
     fl_set_object_callback(obj, C_FormPreferencesOKCB, 0);
   fdui->tabfolder_prefs = obj = fl_add_tabfolder(FL_TOP_TABFOLDER, 5, 5, 450, 385, "");
index 0a29b656263aa1537a45de348d1c45f7acf4e2af..fd3931392e1aafe58ecdf3d8ce14c966cb1b4555 100644 (file)
@@ -1307,7 +1307,7 @@ alignment: FL_ALIGN_CENTER
 style: FL_NORMAL_STYLE
 size: FL_NORMAL_SIZE
 lcol: FL_BLACK
-label: Ok
+label: Save
 shortcut: ^M
 resize: FL_RESIZE_ALL
 gravity: FL_NoGravity FL_NoGravity
index 03e29092053996e6c5924065ce89ed57b1750838..bbeea7c3dbe1a56b64b3d20b725352c2fb6eb07f 100644 (file)
@@ -100,12 +100,17 @@ void CloseAllBufferRelatedDialogs()
        if (fd_form_character->form_character->visible) {
                fl_hide_form(fd_form_character->form_character);
        }
+#ifdef USE_OLD_DOCUMENT_LAYOUT
        if (fd_form_document->form_document->visible) {
                fl_hide_form(fd_form_document->form_document);
        }
        if (fd_form_quotes->form_quotes->visible) {
                fl_hide_form(fd_form_quotes->form_quotes);
        }
+       if (fd_form_paper->form_paper->visible) {
+               fl_hide_form(fd_form_paper->form_paper);
+       }
+#endif
        if (fd_form_preamble->form_preamble->visible) {
                fl_hide_form(fd_form_preamble->form_preamble);
        }
@@ -115,9 +120,6 @@ void CloseAllBufferRelatedDialogs()
        if (fd_form_figure->form_figure->visible) {
                fl_hide_form(fd_form_figure->form_figure);
        }
-       if (fd_form_paper->form_paper->visible) {
-               fl_hide_form(fd_form_paper->form_paper);
-       }
        if (fd_form_table_options->form_table_options->visible) {
                fl_hide_form(fd_form_table_options->form_table_options);
        }