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