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