]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/xforms_helpers.h
xforms clean-up, described in detail in my mail of 31 May. See
[lyx.git] / src / frontends / xforms / xforms_helpers.h
1 // -*- C++ -*-
2 /**
3  * \file xforms_helpers.h
4  * Copyright 2002 the LyX Team
5  * Read the file COPYING
6  *
7  * \author Angus Leeming, a.leeming@ic.ac.uk
8  */
9
10 #ifndef XFORMSHELPERS_H
11 #define XFORMSHELPERS_H
12
13 #ifdef __GNUG__
14 #pragma interface
15 #endif
16
17 #include "forms_fwd.h"
18
19 #include "Color.h"
20 #include "LString.h"
21
22 #include <algorithm>
23 #include <vector>
24
25 class LyXLength;
26
27 // what we always need for lengths
28 string const choice_Length_All =
29     "cm|mm|in|text%%|col%%|page%%|line%%|ex|em|pt|sp|bp|dd|pc|cc|mu";
30 string const choice_Length_WithUnit =
31     "cm|mm|in|ex|em|pt|sp|bp|dd|pc|cc|mu";      // all with a Unit
32
33 /// Set an FL_OBJECT to activated or deactivated
34 void setEnabled(FL_OBJECT *, bool enable);
35
36 /// Take a string and add breaks so that it fits into a desired label width, w
37 string formatted(string const &label, int w,
38                  int = 12 /*FL_NORMAL_SIZE*/, int = 0 /*FL_NORMAL_STYLE*/);
39
40 /// Given an fl_choice, create a vector of its entries
41 std::vector<string> const getVectorFromChoice(FL_OBJECT *);
42
43 /// Given an fl_browser, create a vector of its entries
44 std::vector<string> const getVectorFromBrowser(FL_OBJECT *);
45
46 /// Given an fl_input, return its contents.
47 string const getStringFromInput(FL_OBJECT * ob);
48
49 /** Given an fl_browser, return the contents of line
50     (xforms numbering convention; starts at 1).
51 */
52 string const getStringFromBrowser(FL_OBJECT * ob, int line);
53 /** Given an fl_browser, return the contents of the currently
54     highlighted line.
55 */
56 string const getSelectedStringFromBrowser(FL_OBJECT * ob);
57
58 /// Given input and choice widgets, create a string such as "1cm"
59 string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice);
60
61 /** Given a string such as "1cm", set the input and choice widgets.
62     If the string is empty, the choice will be set to default_unit.
63  */
64 void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
65                                    string const & str,
66                                    string const & default_unit);
67
68 /** Given a LyXLength, set the input and choice widgets.
69     If the length is null, the choice will be set to default_unit.
70  */
71 void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
72                              LyXLength const & len,
73                              string const & default_unit);
74
75
76 /** Return the position of val in the vector if found.
77     If not found, return 0.
78  */
79 template<class A>
80 typename std::vector<A>::size_type
81 findPos(std::vector<A> const & vec, A const & val)
82 {
83         typename std::vector<A>::const_iterator it =
84                 std::find(vec.begin(), vec.end(), val);
85         if (it == vec.end())
86                 return 0;
87         return std::distance(vec.begin(), it);
88 }
89
90 /// Called from Preferences when the cursor color is changed.
91 void setCursorColor(int color);
92
93
94 /// struct holding xform-specific colors
95 struct XformsColor : public NamedColor {
96         int colorID;
97         XformsColor() : NamedColor(), colorID(0) {}
98         static bool read(string const &);
99         static bool write(string const &);
100 };
101
102
103 /** Some functions that perform some quite detailed tests to ascertain whether
104     the directory or file is readable or writeable. If not, then an error
105     message is placed in error_message. */
106 class RWInfo {
107 public:
108         ///
109         static bool WriteableDir(string const & dir);
110         ///
111         static bool ReadableDir(string const & dir);
112         ///
113         static bool WriteableFile(string const & file);
114         ///
115         static bool ReadableFile(string const & file);
116         ///
117         static string const & ErrorMessage() { return error_message; }
118 private:
119         ///
120         static string error_message;
121 };
122 #endif // XFORMSHELPERS_H