mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-27 14:29:21 +00:00
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
This commit is contained in:
parent
61a3cac30d
commit
f2c777f585
10
ChangeLog
10
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.
|
||||
|
@ -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");
|
||||
|
@ -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,47 +139,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/** 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.
|
||||
We assume that we haven't gotten into an undefined state.
|
||||
This is reasonable since we can only reach states defined
|
||||
in the state machine and they should all have been defined in
|
||||
the outputs_ variable. Perhaps we can do something at compile
|
||||
time to check that all the states have corresponding outputs.
|
||||
*/
|
||||
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_;
|
||||
//@}
|
||||
};
|
||||
|
||||
|
||||
//--------------------- 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.
|
||||
@ -163,9 +158,18 @@ public:
|
||||
//@{
|
||||
/// Trigger a transition with this input.
|
||||
virtual void input(SMInput);
|
||||
/// Activation status of a button.
|
||||
/** Activation status of a button.
|
||||
We assume that we haven't gotten into an undefined state.
|
||||
This is reasonable since we can only reach states defined
|
||||
in the state machine and they should all have been defined in
|
||||
the outputs_ variable. Perhaps we can do something at compile
|
||||
time to check that all the states have corresponding outputs.
|
||||
*/
|
||||
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 */
|
||||
|
@ -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 */
|
||||
//@{
|
||||
|
@ -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, "");
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user