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