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.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS
12 #ifndef XFORMSHELPERS_H
13 #define XFORMSHELPERS_H
19 #include "forms_fwd.h"
29 // what we always need for lengths
30 string const choice_Length_All =
31 "cm|mm|in|text%%|col%%|page%%|line%%|ex|em|pt|sp|bp|dd|pc|cc|mu";
32 string const choice_Length_WithUnit =
33 "cm|mm|in|ex|em|pt|sp|bp|dd|pc|cc|mu"; // all with a Unit
35 /// return the (in)active state of the object
36 bool isActive(FL_OBJECT * ob);
38 /// Set an FL_OBJECT to activated or deactivated
39 void setEnabled(FL_OBJECT *, bool enable);
41 /// Take a string and add breaks so that it fits into a desired label width, w
42 string formatted(string const &label, int w,
43 int = 12 /*FL_NORMAL_SIZE*/, int = 0 /*FL_NORMAL_STYLE*/);
45 /// Given an fl_choice or an fl_browser, create a vector of its entries
46 std::vector<string> const getVector(FL_OBJECT *);
48 /** Given an fl_input, an fl_choice or an fl_browser, return an entry
49 \c num is the position for the string, where 0 means "current item"
51 string const getString(FL_OBJECT * ob, int num = 0);
53 /// Given input and choice widgets, create a string such as "1cm"
54 string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice);
56 /** Given a string such as "1cm", set the input and choice widgets.
57 If the string is empty, the choice will be set to default_unit.
59 void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
61 string const & default_unit);
63 /** Given a LyXLength, set the input and choice widgets.
64 If the length is null, the choice will be set to default_unit.
66 void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
67 LyXLength const & len,
68 string const & default_unit);
71 /** Return the position of val in the vector if found.
72 If not found, return 0.
75 typename std::vector<A>::size_type
76 findPos(std::vector<A> const & vec, A const & val)
78 typename std::vector<A>::const_iterator it =
79 std::find(vec.begin(), vec.end(), val);
82 return std::distance(vec.begin(), it);
85 /// Called from Preferences when the cursor color is changed.
86 void setCursorColor(int color);
89 /// struct holding xform-specific colors
90 struct XformsColor : public NamedColor {
92 XformsColor() : NamedColor(), colorID(0) {}
93 static bool read(string const &);
94 static bool write(string const &);
98 /** Some functions that perform some quite detailed tests to ascertain whether
99 the directory or file is readable or writeable. If not, then an error
100 message is placed in error_message. */
104 static bool WriteableDir(string const & dir);
106 static bool ReadableDir(string const & dir);
108 static bool WriteableFile(string const & file);
110 static bool ReadableFile(string const & file);
112 static string const & ErrorMessage() { return error_message; }
115 static string error_message;
117 #endif // XFORMSHELPERS_H