]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormPreferences.h
use exclicit temp var
[lyx.git] / src / frontends / xforms / FormPreferences.h
index 80eb46027903afad7b9e41e25a5c07d5e0d2739f..2dcb6c4190d4c5d4f282470c30c2bc7ef6c0dc1f 100644 (file)
@@ -5,9 +5,9 @@
  *           LyX, The Document Processor
  *      
  *         Copyright 1995 Matthias Ettrich
- *          Copyright 1995-2000 The LyX Team.
+ *          Copyright 1995-2001 The LyX Team.
  *
- *         This file copyright 1999-2000
+ *         This file copyright 1999-2001
  *         Allan Rae
  *======================================================*/
 /* FormPreferences.h
 #ifndef FORMPREFERENCES_H
 #define FORMPREFERENCES_H
 
-#include "FormBase.h"
+#include <utility> // pair
+#include <boost/smart_ptr.hpp>
 
 #ifdef __GNUG_
 #pragma interface
 #endif
 
+#include "FormBaseDeprecated.h"
+#include "Color.h" // NamedColor
+#include "xforms_helpers.h" // XformColor
+
 class Combox;
-class Command;
 class Dialogs;
-class Format;
 class LyXView;
-struct FD_form_colours;
+class RGBColor;
+struct FD_form_colors;
 struct FD_form_converters;
 struct FD_form_formats;
 struct FD_form_inputs_misc;
 struct FD_form_interface;
 struct FD_form_language;
 struct FD_form_lnf_misc;
-struct FD_form_outer_tab;
+struct FD_form_inner_tab;
 struct FD_form_outputs_misc;
 struct FD_form_paths;
 struct FD_form_preferences;
 struct FD_form_printer;
 struct FD_form_screen_fonts;
-struct FD_form_spellchecker;
+struct FD_form_spelloptions;
+
 
 /** This class provides an XForms implementation of the FormPreferences Dialog.
     The preferences dialog allows users to set/save their preferences.
@@ -51,34 +56,22 @@ public:
        /// #FormPreferences x(LyXFunc ..., Dialogs ...);#
        FormPreferences(LyXView *, Dialogs *);
        ///
-       ~FormPreferences();
-       ///
-       static void ComboLanguageCB(int, void *, Combox *);
-       ///
        static int FeedbackCB(FL_OBJECT *, int,
                              FL_Coord, FL_Coord, int, void *);
 
 private:
-       /// helper struct for Colours
-       struct RGB {
-               int r;
-               int g;
-               int b;
-               RGB() : r(0), g(0), b(0) {}
-               RGB(int red, int green, int blue) : r(red), g(green), b(blue) {}
-       };
-       ///
-       friend bool operator==(RGB const &, RGB const &);
-       ///
-       friend bool operator!=(RGB const &, RGB const &);
-       ///
-       typedef std::pair<string, RGB> X11Colour;
-
+       /// Pointer to the actual instantiation of the ButtonController.
+       virtual xformsBC & bc();
+       /** Redraw the form (on receipt of a Signal indicating, for example,
+           that the xforms colours have been re-mapped). */
+       virtual void redraw();
        /// Update the dialog.
        virtual void update();
-       ///
+       /// show the spellchecker tab
+       void showSpellPref();
+       /// Hide the dialog.
        virtual void hide();
-       /// OK from dialog
+       /// OK (Save) from dialog
        virtual void ok();
        /// Apply from dialog
        virtual void apply();
@@ -86,295 +79,506 @@ private:
        virtual bool input(FL_OBJECT *, long);
        /// Build the dialog
        virtual void build();
-       /// control which feedback message is output
-       void feedback( FL_OBJECT * );
-       /// The handler for the preemptive feedback
-       void Feedback(FL_OBJECT *, int);
-       ///
+       /// Pointer to the actual instantiation of the xforms form.
        virtual FL_FORM * form() const;
+       /// control which feedback message is output
+       void feedback(FL_OBJECT *);
 
-       /** Folder specific apply functions.
+               /// Set the preemptive handler for each FL_OBJECT.
+       static void setPreHandler(FL_OBJECT *);
+       /// The preemptive handler for feedback messages.
+       void Feedback(FL_OBJECT *, int);
+       /// Print a warning message and set warning flag.
+       void printWarning(string const &);
+       /** Launch a file dialog and modify input if it returns a new file.
+           For an explanation of the various parameters, see xforms_helpers.h.
         */
+       void browse(FL_OBJECT * input,
+                    string const & title, string const & pattern, 
+                    std::pair<string,string> const & dir1= std::make_pair(string(),string()), 
+                    std::pair<string,string> const & dir2 = std::make_pair(string(),string()));
        
+       /// Fdesign generated methods
+       FD_form_preferences * build_preferences();
        ///
-       void applyColours() const;
-       ///
-       void applyConverters() const;
-       ///
-       void applyFormats() const;
-       ///
-       void applyInputsMisc() const;
-       ///
-       void applyInterface() const;
-       ///
-       void applyLanguage(); // not const because calls updateLanguage!
-       ///
-       void applyLnFmisc() const;
-       ///
-       void applyOutputsMisc() const;
-       ///
-       void applyPaths(); // not const because calls updatePaths!
-       ///
-       void applyPrinter() const;
-       ///
-       void applyScreenFonts() const;
-       ///
-       void applySpellChecker(); // not const because calls updateSpellChecker!
-
-       /** Folder specific build functions.
-        */
-       
+       FD_form_inner_tab * build_inner_tab();
        ///
-       void buildColours();
+       FD_form_colors * build_colors();
        ///
-       void buildConverters();
+       FD_form_converters * build_converters();
        ///
-       void buildFormats();
+       FD_form_formats * build_formats();
        ///
-       void buildInputsMisc();
+       FD_form_inputs_misc * build_inputs_misc();
        ///
-       void buildInterface();
+       FD_form_interface * build_interface();
        ///
-       void buildLanguage();
+       FD_form_language * build_language();
        ///
-       void buildLnFmisc();
+       FD_form_lnf_misc * build_lnf_misc();
        ///
-       void buildOutputsMisc();
+       FD_form_outputs_misc * build_outputs_misc();
        ///
-       void buildPaths();
+       FD_form_paths * build_paths();
        ///
-       void buildPrinter();
+       FD_form_printer * build_printer();
        ///
-       void buildScreenFonts();
+       FD_form_screen_fonts * build_screen_fonts();
        ///
-       void buildSpellchecker();
+       FD_form_spelloptions * build_spelloptions();
 
-       /** Folder specific feedback functions.
-        */
-       
-       ///
-       string const feedbackColours(FL_OBJECT const * const) const;
-       ///
-       string const feedbackConverters(FL_OBJECT const * const) const;
-       ///
-       string const feedbackFormats( FL_OBJECT const * const ) const;
-       ///
-       string const feedbackInputsMisc(FL_OBJECT const * const) const;
-       ///
-       string const feedbackInterface(FL_OBJECT const * const) const;
-       ///
-       string const feedbackLanguage(FL_OBJECT const * const) const;
-       ///
-       string const feedbackLnFmisc(FL_OBJECT const * const) const;
-       ///
-       string const feedbackOutputsMisc(FL_OBJECT const * const) const;
-       ///
-       string const feedbackPaths(FL_OBJECT const * const) const;
-       ///
-       string const feedbackPrinter(FL_OBJECT const * const) const;
-       ///
-       string const feedbackScreenFonts(FL_OBJECT const * const) const;
-       ///
-       string const feedbackSpellChecker(FL_OBJECT const * const) const;
+       /// Real GUI implementation.
+       boost::scoped_ptr<FD_form_preferences> dialog_;
+       /// Converters tabfolder
+       boost::scoped_ptr<FD_form_inner_tab> converters_tab_;
+       /// reLyX and other import/input stuff
+       boost::scoped_ptr<FD_form_inner_tab> inputs_tab_;
+       /// HCI configuration
+       boost::scoped_ptr<FD_form_inner_tab> look_n_feel_tab_;
+       /// Outputs tabfolder
+       boost::scoped_ptr<FD_form_inner_tab> outputs_tab_;
+       /// Spellchecker, language stuff, etc
+       boost::scoped_ptr<FD_form_inner_tab> lang_opts_tab_;
 
-       /** Folder specific input functions. Not all folders require one.
-        */
+       /** Flag whether a warning has been posted to the text window.
+           If so, don't redraw the window when the mouse leaves an object. */
+       bool warningPosted;
        
-       ///
-       bool inputColours(FL_OBJECT const * const);
-       ///
-       bool inputConverters( FL_OBJECT const * const );
-       ///
-       bool inputFormats( FL_OBJECT const * const );
-       ///
-       bool inputLanguage(FL_OBJECT const * const);
-       ///
-       bool inputPaths(FL_OBJECT const * const);
-       ///
-       bool inputScreenFonts();
-       ///
-       bool inputSpellChecker(FL_OBJECT const * const);
-
-       /** Folder specific update functions.
+       /** Each tab folder is encapsulated in its own class.
         */
-       
-       ///
-       void updateColours();
-       ///
-       void updateConverters();
-       ///
-       void updateFormats();
-       ///
-       void updateInputsMisc();
-       ///
-       void updateInterface();
-       ///
-       void updateLanguage();
-       ///
-       void updateLnFmisc();
-       ///
-       void updateOutputsMisc();
-       ///
-       void updatePaths();
-       ///
-       void updatePrinter();
-       ///
-       void updateScreenFonts();
-       ///
-       void updateSpellChecker();
 
-       /** Some helper functions for specific folders.
-        */
-       
-       ///
-       bool ColoursLoadBrowser( string const & );
-       ///
-       int  ColoursSearchEntry(RGB const & ) const;
-       ///
-       void ColoursUpdateBrowser( int );
-       ///
-       void ColoursUpdateRGB();
+       class Colors {
+       public:
+               ///
+               enum GuiColors {
+                       GUI_COLOR_CHOICE = FL_FREE_COL1,
+                       GUI_COLOR_HUE_DIAL = FL_FREE_COL2,
+                       GUI_COLOR_CURSOR = FL_FREE_COL3
+               };
+               ///
+               Colors(FormPreferences & p);
+               ///
+               FD_form_colors const * dialog();
+               ///
+               void apply(); // not const as modifies modifiedXformsPrefs.
+               ///
+               void build();
+               ///
+               string const feedback(FL_OBJECT const * const) const;
+               ///
+               void input(FL_OBJECT const * const);
+               ///
+               void update() { LoadBrowserLyX(); }
+               
+               /// Flag whether Xforms colors have changed since last file save
+               bool modifiedXformsPrefs;
 
-       ///
-       bool ConvertersAdd();
-       ///
-       bool ConvertersBrowser();
-       ///
-       void ConvertersClear() const;
-       ///
-       bool ConvertersContainFormat( Format const &) const;
-       ///
-       bool ConvertersDelete();
-       ///
-       bool ConvertersInput();
-       ///
-       bool ConvertersSetCommand( Command & ) const;
-       ///
-       void ConvertersUpdateChoices();
+       private:
+               ///
+               void AdjustVal(int, int, double) const;
+               ///
+               void InputBrowserLyX() const;
+               ///
+               void InputHSV();
+               ///
+               void InputRGB();
+               ///
+               void LoadBrowserLyX();
+               ///
+               void Modify();
+               ///
+               void SwitchColorSpace() const;
+               ///
+               string const X11hexname(RGBColor const &) const;
 
-       bool FormatsAdd();
-       ///
-       bool FormatsBrowser();
+               ///
+               FormPreferences & parent_;
+               ///
+               boost::scoped_ptr<FD_form_colors> dialog_;
+
+               /// A vector of LyX LColor GUI name and associated RGB color.
+               std::vector<NamedColor> lyxColorDB;
+               /// A vector of xforms color ID, RGB colors and associated name.
+               std::vector<XformsColor> xformsColorDB;
+       };
        ///
-       void FormatsClear() const;
+       friend class Colors;
+
        ///
-       bool FormatsDelete();
+       class Converters {
+       public:
+               ///
+               Converters(FormPreferences & p);
+               ///
+               FD_form_converters const * dialog();
+               ///
+               void apply() const;
+               ///
+               void build();
+               ///
+               string const feedback(FL_OBJECT const * const) const;
+               ///
+               bool input(FL_OBJECT const * const);
+               ///
+               void update();
+               ///
+               void UpdateBrowser();
+               ///
+               void UpdateChoices() const;
+
+       private:
+               ///
+               bool Add();
+               ///
+               bool Browser();
+               ///
+               bool erase();
+               ///
+               bool Input();
+               ///
+               string const GetFrom() const;
+               ///
+               string const GetTo() const;
+
+               ///
+               FormPreferences & parent_;
+               ///
+               boost::scoped_ptr<FD_form_converters> dialog_;
+       };
        ///
-       bool FormatsInput();
+       friend class Converters;
 
        ///
-       bool WriteableDir( string const & );
+       class Formats {
+       public:
+               ///
+               Formats(FormPreferences &  p);
+               ///
+               FD_form_formats const * dialog();
+               ///
+               void apply() const;
+               ///
+               void build();
+               ///
+               string const feedback(FL_OBJECT const * const) const;
+               ///
+               bool input(FL_OBJECT const * const);
+               ///
+               void update();
+
+       private:
+               ///
+               bool Add();
+               ///
+               bool Browser();
+               ///
+               void UpdateBrowser();
+               ///
+               bool erase();
+               ///
+               bool Input();
+
+               ///
+               FormPreferences & parent_;
+               ///
+               boost::scoped_ptr<FD_form_formats> dialog_;
+       };
        ///
-       bool ReadableDir( string const & );
+       friend class Formats;
+
        ///
-       bool WriteableFile( string const &, string const & = string() );
+       class InputsMisc {
+       public:
+               ///
+               InputsMisc(FormPreferences &  p);
+               ///
+               FD_form_inputs_misc const * dialog();
+               ///
+               void apply() const;
+               ///
+               void build();
+               ///
+               string const feedback(FL_OBJECT const * const) const;
+               ///
+               void update();
 
+       private:
+               ///
+               FormPreferences & parent_;
+               ///
+               boost::scoped_ptr<FD_form_inputs_misc> dialog_;
+       };
        ///
-       void setPreHandler( FL_OBJECT * ) const;
+       friend class InputsMisc;
+       
        ///
-       void printWarning( string const & );
+       class Interface {
+       public:
+               ///
+               Interface(FormPreferences &  p);
+               ///
+               FD_form_interface const * dialog();
+               ///
+               void apply() const;
+               ///
+               void build();
+               ///
+               string const feedback(FL_OBJECT const * const) const;
+               ///
+               bool input(FL_OBJECT const * const);
+               ///
+               void update();
 
-       /// Type definitions from the fdesign produced header file.
-       FD_form_preferences * build_preferences();
-       ///
-       FD_form_outer_tab * build_outer_tab();
+       private:
+               ///
+               FormPreferences & parent_;
+               ///
+               boost::scoped_ptr<FD_form_interface> dialog_;
+       };
        ///
-       FD_form_colours * build_colours();
+       friend class Interface;
+
        ///
-       FD_form_converters * build_converters();
+       class Language {
+       public:
+               ///
+               Language(FormPreferences &  p);
+               ///
+               FD_form_language const * dialog();
+               ///
+               void apply(); // not const because calls update()
+               ///
+               void build();
+               ///
+               string const feedback(FL_OBJECT const * const) const;
+               ///
+               bool input(FL_OBJECT const * const);
+               ///
+               void update();
+               ///
+               static void ComboCB(int, void *, Combox *);
+
+       private:
+               ///
+               FormPreferences & parent_;
+               ///
+               boost::scoped_ptr<FD_form_language> dialog_;
+               ///
+               boost::scoped_ptr<Combox> combo_default_lang;
+       };
        ///
-       FD_form_formats * build_formats();
+       friend class Language;
+       
        ///
-       FD_form_inputs_misc * build_inputs_misc();
+       class LnFmisc {
+       public:
+               ///
+               LnFmisc(FormPreferences &  p);
+               ///
+               FD_form_lnf_misc const * dialog();
+               ///
+               void apply() const;
+               ///
+               void build();
+               ///
+               string const feedback(FL_OBJECT const * const) const;
+               ///
+               void update();
+
+       private:
+               ///
+               FormPreferences & parent_;
+               ///
+               boost::scoped_ptr<FD_form_lnf_misc> dialog_;
+       };
        ///
-       FD_form_interface * build_interface();
+       friend class LnFmisc;
+
        ///
-       FD_form_language * build_language();
+       class OutputsMisc {
+       public:
+               ///
+               OutputsMisc(FormPreferences &  p);
+               ///
+               FD_form_outputs_misc const * dialog();
+               ///
+               void apply() const;
+               ///
+               void build();
+               ///
+               string const feedback(FL_OBJECT const * const) const;
+               ///
+               void update();
+
+       private:
+               ///
+               FormPreferences & parent_;
+               ///
+               boost::scoped_ptr<FD_form_outputs_misc> dialog_;
+       };
        ///
-       FD_form_lnf_misc * build_lnf_misc();
+       friend class OutputsMisc;
+
        ///
-       FD_form_outputs_misc * build_outputs_misc();
+       class Paths {
+       public:
+               ///
+               Paths(FormPreferences &  p);
+               ///
+               FD_form_paths const * dialog();
+               ///
+               void apply();
+               ///
+               void build();
+               ///
+               string const feedback(FL_OBJECT const * const) const;
+               ///
+               bool input(FL_OBJECT const * const);
+               ///
+               void update();
+
+       private:
+               ///
+               FormPreferences & parent_;
+               ///
+               boost::scoped_ptr<FD_form_paths> dialog_;
+       };
        ///
-       FD_form_paths * build_paths();
+       friend class Paths;
+
        ///
-       FD_form_printer * build_printer();
+       class Printer {
+       public:
+               ///
+               Printer(FormPreferences &  p);
+               ///
+               FD_form_printer const * dialog();
+               ///
+               void apply() const;
+               ///
+               void build();
+               ///
+               string const feedback(FL_OBJECT const * const) const;
+               ///
+               void update();
+
+       private:
+               ///
+               FormPreferences & parent_;
+               ///
+               boost::scoped_ptr<FD_form_printer> dialog_;
+       };
        ///
-       FD_form_screen_fonts * build_screen_fonts();
+       friend class Printer;
+
        ///
-       FD_form_spellchecker * build_spellchecker();
+       class ScreenFonts {
+       public:
+               ///
+               ScreenFonts(FormPreferences &  p);
+               ///
+               FD_form_screen_fonts const * dialog();
+               ///
+               void apply() const;
+               ///
+               void build();
+               ///
+               string const feedback(FL_OBJECT const * const) const;
+               ///
+               bool input();
+               ///
+               void update();
 
-       /// Real GUI implementation.
-       FD_form_preferences * dialog_;
-       /// Converters tabfolder
-       FD_form_outer_tab * converters_tab_;
-       /// reLyX and other import/input stuff
-       FD_form_outer_tab * inputs_tab_;
-       /// HCI configuration
-       FD_form_outer_tab * look_n_feel_tab_;
-       /// Outputs tabfolder
-       FD_form_outer_tab * outputs_tab_;
-       /// Spellchecker, language stuff, etc
-       FD_form_outer_tab * usage_tab_;
+       private:
+               ///
+               FormPreferences & parent_;
+               ///
+               boost::scoped_ptr<FD_form_screen_fonts> dialog_;
+       };
        ///
-       FD_form_colours * colours_;
+       friend class ScreenFonts;
+
        ///
-       FD_form_converters * converters_;
+       class SpellOptions {
+       public:
+               ///
+               SpellOptions(FormPreferences &  p);
+               ///
+               FD_form_spelloptions const * dialog();
+               ///
+               void apply(); // not const because calls update()!
+               ///
+               void build();
+               ///
+               string const feedback(FL_OBJECT const * const) const;
+               ///
+               bool input(FL_OBJECT const * const);
+               ///
+               void update();
+
+       private:
+               ///
+               FormPreferences & parent_;
+               ///
+               boost::scoped_ptr<FD_form_spelloptions> dialog_;
+       };
        ///
-       FD_form_formats * formats_;
+       friend class SpellOptions;
+
+       /** The tab folders.
+        */
+       
        ///
-       FD_form_inputs_misc * inputs_misc_;
+       Colors colors_;
        ///
-       FD_form_interface * interface_;
+       Converters converters_;
        ///
-       FD_form_language * language_;
+       InputsMisc inputs_misc_;
        ///
-       FD_form_lnf_misc * lnf_misc_;
+       Formats formats_;
        ///
-       FD_form_outputs_misc * outputs_misc_;
+       Interface interface_;
        ///
-       FD_form_paths * paths_;
+       Language language_;
        ///
-       FD_form_printer * printer_;
+       LnFmisc lnf_misc_;
        ///
-       FD_form_screen_fonts * screen_fonts_;
+       OutputsMisc outputs_misc_;
        ///
-       FD_form_spellchecker * spellchecker_;
+       Paths paths_;
        ///
-       Combox * combo_default_lang;
+       Printer printer_;
        ///
-       Combox * combo_kbmap_1;
+       ScreenFonts screen_fonts_;
        ///
-       Combox * combo_kbmap_2;
+       SpellOptions spelloptions_;
 
-       /// A vector of Formats, to be manipulated in the Format browser.
-       std::vector<Format> formats_vec;
-       /// A vector of Commands, to be manipulated in the Converter browser.
-       std::vector<Command> commands_vec;
-       /// A vector of RGB colours and associated name.
-       static std::vector<X11Colour> colourDB;
-       /** A collection of kmap files.
-           First entry is the file name, full path.
-           Second entry is the shorthand, as appears in the fl_choice.
-           Eg, system_lyxdir/kbd/american2.kmap, american2
-       */
-       static std::pair<std::vector<string>, std::vector<string> > dirlist;
+       /** A couple of helper structs to enable colors to be sorted by name
+           and by color */
        ///
-       bool warningPosted;
+       struct SortColorsByName {
+               ///
+               int operator()(NamedColor const & a, NamedColor const & b) const
+                       { return (a.getname() < b.getname()); }
+       };
+       ///
+       struct SortColorsByColor {
+               ///
+               SortColorsByColor(RGBColor c) : col(c) {}
+               ///
+               int operator()(RGBColor const &, RGBColor const &) const;
+               ///
+               RGBColor col;
+       };
+       /// The ButtonController
+       ButtonController<PreferencesPolicy, xformsBC> bc_;
 };
 
-inline
-bool operator==(FormPreferences::RGB const & c1,
-               FormPreferences::RGB const & c2)
-{
-       return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b);
-}
-
 
 inline
-bool operator!=(FormPreferences::RGB const & c1,
-               FormPreferences::RGB const & c2)
+xformsBC & FormPreferences::bc()
 {
-       return !(c1 == c2);
+       return bc_;
 }
 
 #endif