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
16 #include "forms_fwd.h"
25 /// parse "&Save" etc. to <"Save", "#S">. Does not handle &&
26 std::pair<std::string, std::string> parse_shortcut(std::string const & str);
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,
32 /** Generate a string of available length units with which to
33 * populate a choice widget.
35 std::string const buildChoiceLengthString();
37 /// return the (in)active state of the object
38 bool isActive(FL_OBJECT * ob);
40 /// Set an FL_OBJECT to activated or deactivated
41 void setEnabled(FL_OBJECT *, bool enable);
43 /// Take a std::string and add breaks so that it fits into a desired label width, w
44 std::string formatted(std::string const &label, int w,
45 int = 12 /*FL_NORMAL_SIZE*/, int = 0 /*FL_NORMAL_STYLE*/);
47 /// Given an fl_choice or an fl_browser, create a vector of its entries
48 std::vector<std::string> const getVector(FL_OBJECT *);
50 /** Given an fl_input, an fl_choice or an fl_browser, return an entry
51 \c num is the position for the string, where 0 means "current item"
53 std::string const getString(FL_OBJECT * ob, int num = 0);
55 /// Given input and choice widgets, create a std::string such as "1cm"
56 std::string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice);
58 /** Given a string such as "1cm", set the input and choice widgets.
59 If the string is empty, the choice will be set to default_unit.
61 void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
62 std::string const & str,
63 std::string const & default_unit);
65 /** Given a LyXLength, set the input and choice widgets.
66 If the length is null, the choice will be set to default_unit.
68 void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
69 LyXLength const & len,
70 std::string const & default_unit);
73 /** Return the position of val in the vector if found.
74 If not found, return 0.
77 typename std::vector<A>::size_type
78 findPos(std::vector<A> const & vec, A const & val)
80 typename std::vector<A>::const_iterator it =
81 std::find(vec.begin(), vec.end(), val);
84 return std::distance(vec.begin(), it);
87 /// Called from Preferences when the cursor color is changed.
88 void setCursorColor(int color);
91 /// struct holding xform-specific colors
92 struct XformsColor : public NamedColor {
94 XformsColor() : NamedColor(), colorID(0) {}
95 static bool read(std::string const &);
96 static bool write(std::string const &);
100 /** Some functions that perform some quite detailed tests to ascertain whether
101 the directory or file is readable or writeable. If not, then an error
102 message is placed in error_message. */
106 static bool WriteableDir(std::string const & dir);
108 static bool ReadableDir(std::string const & dir);
110 static bool WriteableFile(std::string const & file);
112 static bool ReadableFile(std::string const & file);
114 static std::string const & ErrorMessage() { return error_message; }
117 static std::string error_message;
119 #endif // XFORMSHELPERS_H