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