From: Allan Rae Date: Mon, 21 Aug 2000 01:03:31 +0000 (+0000) Subject: more docs for ButtonPolicies; fix form_document segfault in lyx_gui_misc.C X-Git-Tag: 1.6.10~22027 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f2c777f585981dad0647ae43428a5aac43d422c2;p=features.git more docs for ButtonPolicies; fix form_document segfault in lyx_gui_misc.C git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@980 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index dadb68a588..a804da49ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2000-08-21 Allan Rae + + * 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 * src/insets/insettabular.C (getStatus): changed to return func_status. diff --git a/src/ext_l10n.h b/src/ext_l10n.h index d4c5eae411..bdefdb55be 100644 --- a/src/ext_l10n.h +++ b/src/ext_l10n.h @@ -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"); diff --git a/src/frontends/ButtonPolicies.h b/src/frontends/ButtonPolicies.h index d817ad233c..29a7483792 100644 --- a/src/frontends/ButtonPolicies.h +++ b/src/frontends/ButtonPolicies.h @@ -28,6 +28,39 @@ 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 */ diff --git a/src/frontends/xforms/ButtonController.h b/src/frontends/xforms/ButtonController.h index b6f1086d5a..b85c4f4532 100644 --- a/src/frontends/xforms/ButtonController.h +++ b/src/frontends/xforms/ButtonController.h @@ -22,6 +22,7 @@ #define BUTTONCONTROLLER_H #include "ButtonPolicies.h" +#include /** 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::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::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 read_only_; //@} /**@name Cancel/Close Button Labels */ //@{ diff --git a/src/frontends/xforms/form_preferences.C b/src/frontends/xforms/form_preferences.C index 4863eba76d..41a2ab478c 100644 --- a/src/frontends/xforms/form_preferences.C +++ b/src/frontends/xforms/form_preferences.C @@ -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, ""); diff --git a/src/frontends/xforms/forms/form_preferences.fd b/src/frontends/xforms/forms/form_preferences.fd index 0a29b65626..fd3931392e 100644 --- a/src/frontends/xforms/forms/form_preferences.fd +++ b/src/frontends/xforms/forms/form_preferences.fd @@ -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 diff --git a/src/lyx_gui_misc.C b/src/lyx_gui_misc.C index 03e2909205..bbeea7c3db 100644 --- a/src/lyx_gui_misc.C +++ b/src/lyx_gui_misc.C @@ -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); }