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