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