]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/xforms_helpers.h
Internationalise the rotation origin strings in the graphics dialog in the
[lyx.git] / src / frontends / xforms / xforms_helpers.h
1 // -*- C++ -*-
2 /**
3  * \file xforms_helpers.h
4  * Copyright 2002 the LyX Team
5  * Read the file COPYING
6  *
7  * \author Angus Leeming, a.leeming@ic.ac.uk
8  */
9
10 #ifndef XFORMSHELPERS_H
11 #define XFORMSHELPERS_H
12
13 #ifdef __GNUG__
14 #pragma interface
15 #endif
16
17 #include FORMS_H_LOCATION
18
19 #include "Color.h"
20 #include "LString.h"
21
22 #include <algorithm>
23 #include <vector>
24
25 class LyXLength;
26
27 // what we always need for lengths
28 string const choice_Length_All =
29     "cm|mm|in|text%%|col%%|page%%|line%%|ex|em|pt|sp|bp|dd|pc|cc|mu";
30 string const choice_Length_WithUnit =
31     "cm|mm|in|ex|em|pt|sp|bp|dd|pc|cc|mu";      // all with a Unit
32
33 /// Extract shortcut from <ident>|<shortcut> string
34 char const * flyx_shortcut_extract(char const * sc);
35 /// Shortcut for flyx_shortcut_extract
36 #define scex flyx_shortcut_extract
37
38 /// Extract shortcut from <ident>|<shortcut> string
39 char const * flyx_ident_extract(char const * sc);
40 /// Shortcut for flyx_ident_extract
41 #define idex flyx_ident_extract
42
43 /// Set an FL_OBJECT to activated or deactivated
44 void setEnabled(FL_OBJECT *, bool enable);
45
46 /// Take a string and add breaks so that it fits into a desired label width, w
47 string formatted(string const &label, int w,
48                  int = FL_NORMAL_SIZE, int = FL_NORMAL_STYLE);
49
50 /// Given an fl_choice, create a vector of its entries
51 std::vector<string> const getVectorFromChoice(FL_OBJECT *);
52
53 /// Given an fl_browser, create a vector of its entries
54 std::vector<string> const getVectorFromBrowser(FL_OBJECT *);
55
56 /// Given an fl_input, return its contents.
57 string const getStringFromInput(FL_OBJECT * ob);
58
59 /** Given an fl_browser, return the contents of line
60     (xforms numbering convention; starts at 1).
61 */
62 string const getStringFromBrowser(FL_OBJECT * ob, int line);
63 /** Given an fl_browser, return the contents of the currently
64     highlighted line.
65 */
66 string const getSelectedStringFromBrowser(FL_OBJECT * ob);
67
68 /// Given input and choice widgets, create a string such as "1cm"
69 string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice);
70
71 /** Given a string such as "1cm", set the input and choice widgets.
72     If the string is empty, the choice will be set to default_unit.
73  */
74 void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
75                                    string const & str,
76                                    string const & default_unit);
77
78 /** Given a LyXLength, set the input and choice widgets.
79     If the length is null, the choice will be set to default_unit.
80  */
81 void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
82                              LyXLength const & len,
83                              string const & default_unit);
84
85
86 /** Return the position of val in the vector if found.
87     If not found, return 0.
88  */
89 template<class A>
90 typename std::vector<A>::size_type
91 findPos(std::vector<A> const & vec, A const & val)
92 {
93         typename std::vector<A>::const_iterator it =
94                 std::find(vec.begin(), vec.end(), val);
95         if (it == vec.end())
96                 return 0;
97         return std::distance(vec.begin(), it);
98 }
99
100 /// Called from Preferences when the cursor color is changed.
101 void setCursorColor(int color);
102
103
104 /// struct holding xform-specific colors
105 struct XformsColor : public NamedColor {
106         int colorID;
107         XformsColor() : NamedColor(), colorID(0) {}
108         static bool read(string const &);
109         static bool write(string const &);
110 };
111
112
113 /** Some functions that perform some quite detailed tests to ascertain whether
114     the directory or file is readable or writeable. If not, then an error
115     message is placed in error_message. */
116 class RWInfo {
117 public:
118         ///
119         static bool WriteableDir(string const & dir);
120         ///
121         static bool ReadableDir(string const & dir);
122         ///
123         static bool WriteableFile(string const & file);
124         ///
125         static bool ReadableFile(string const & file);
126         ///
127         static string const & ErrorMessage() { return error_message; }
128 private:
129         ///
130         static string error_message;
131 };
132 #endif // XFORMSHELPERS_H