]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/xforms_helpers.h
Change glob() API to accept a dir parameter.
[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 #include "forms_fwd.h"
16
17 #include "Color.h"
18
19 #include <algorithm>
20 #include <vector>
21
22 class LyXLength;
23
24 namespace lyx {
25 namespace frontend {
26
27 /// parse "&Save" etc. to <"Save", "#S">. Does not handle &&
28 std::pair<std::string, std::string> parse_shortcut(std::string const & str);
29
30 // A wrapper for the xforms routine, but this one accepts uint args
31 unsigned long fl_getmcolor(int i, unsigned int * r, unsigned int * g,
32                            unsigned int * b);
33
34 /** Generate a string of available length units with which to
35  *  populate a choice widget.
36  */
37 std::string const buildChoiceLengthString();
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 std::string and add breaks so that it fits into a desired label width, w
46 std::string formatted(std::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<std::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 std::string const getString(FL_OBJECT * ob, int num = 0);
56
57 /// Given input and choice widgets, create a std::string such as "1cm"
58 std::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                                    std::string const & str,
65                                    std::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                              std::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(std::string const &);
98         static bool write(std::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(std::string const & dir);
109         ///
110         static bool ReadableDir(std::string const & dir);
111         ///
112         static bool WriteableFile(std::string const & file);
113         ///
114         static bool ReadableFile(std::string const & file);
115         ///
116         static std::string const & ErrorMessage() { return error_message; }
117 private:
118         ///
119         static std::string error_message;
120 };
121
122 } // namespace frontend
123 } // namespace lyx
124
125 #endif // XFORMSHELPERS_H