]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/xforms_helpers.h
Nothing but a changed email address (trying to factor my tree in in small steps)
[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 <leeming@lyx.org>
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 or an fl_browser, create a vector of its entries
41 std::vector<string> const getVector(FL_OBJECT *);
42
43 /// Given an fl_input, an fl_choice or an fl_browser, return an entry
44 /** \c num is the position for the string, where -1 means "current item" */
45 string const getString(FL_OBJECT * ob, int num = -1);
46
47 /// Given input and choice widgets, create a string such as "1cm"
48 string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice);
49
50 /** Given a string such as "1cm", set the input and choice widgets.
51     If the string is empty, the choice will be set to default_unit.
52  */
53 void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
54                                    string const & str,
55                                    string const & default_unit);
56
57 /** Given a LyXLength, set the input and choice widgets.
58     If the length is null, the choice will be set to default_unit.
59  */
60 void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
61                              LyXLength const & len,
62                              string const & default_unit);
63
64
65 /** Return the position of val in the vector if found.
66     If not found, return 0.
67  */
68 template<class A>
69 typename std::vector<A>::size_type
70 findPos(std::vector<A> const & vec, A const & val)
71 {
72         typename std::vector<A>::const_iterator it =
73                 std::find(vec.begin(), vec.end(), val);
74         if (it == vec.end())
75                 return 0;
76         return std::distance(vec.begin(), it);
77 }
78
79 /// Called from Preferences when the cursor color is changed.
80 void setCursorColor(int color);
81
82
83 /// struct holding xform-specific colors
84 struct XformsColor : public NamedColor {
85         int colorID;
86         XformsColor() : NamedColor(), colorID(0) {}
87         static bool read(string const &);
88         static bool write(string const &);
89 };
90
91
92 /** Some functions that perform some quite detailed tests to ascertain whether
93     the directory or file is readable or writeable. If not, then an error
94     message is placed in error_message. */
95 class RWInfo {
96 public:
97         ///
98         static bool WriteableDir(string const & dir);
99         ///
100         static bool ReadableDir(string const & dir);
101         ///
102         static bool WriteableFile(string const & file);
103         ///
104         static bool ReadableFile(string const & file);
105         ///
106         static string const & ErrorMessage() { return error_message; }
107 private:
108         ///
109         static string error_message;
110 };
111 #endif // XFORMSHELPERS_H