2001-06-13 14:33:31 +00:00
|
|
|
// -*- C++ -*-
|
2002-03-11 17:00:41 +00:00
|
|
|
/**
|
|
|
|
* \file xforms_helpers.h
|
|
|
|
* Copyright 2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author Angus Leeming, a.leeming@ic.ac.uk
|
|
|
|
*/
|
2001-06-13 14:33:31 +00:00
|
|
|
|
2001-03-05 19:02:40 +00:00
|
|
|
#ifndef XFORMSHELPERS_H
|
|
|
|
#define XFORMSHELPERS_H
|
2000-11-02 14:47:47 +00:00
|
|
|
|
2002-04-23 08:16:27 +00:00
|
|
|
#ifdef __GNUG__
|
2000-11-02 14:47:47 +00:00
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
2001-11-26 10:19:58 +00:00
|
|
|
#include FORMS_H_LOCATION
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2000-11-15 18:02:45 +00:00
|
|
|
#include "Color.h"
|
2001-12-12 09:56:03 +00:00
|
|
|
#include "LString.h"
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-05-01 09:25:51 +00:00
|
|
|
#include <algorithm>
|
2001-11-26 10:19:58 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2001-12-12 09:56:03 +00:00
|
|
|
class LyXLength;
|
|
|
|
|
2002-01-29 09:26:24 +00:00
|
|
|
// what we always need for lengths
|
|
|
|
string const choice_Length_All =
|
2002-03-27 12:27:17 +00:00
|
|
|
"cm|mm|in|text%%|col%%|page%%|line%%|ex|em|pt|sp|bp|dd|pc|cc|mu";
|
2002-01-29 09:26:24 +00:00
|
|
|
string const choice_Length_WithUnit =
|
2002-03-21 21:21:28 +00:00
|
|
|
"cm|mm|in|ex|em|pt|sp|bp|dd|pc|cc|mu"; // all with a Unit
|
2002-01-29 09:26:24 +00:00
|
|
|
|
2001-11-26 10:19:58 +00:00
|
|
|
/// Extract shortcut from <ident>|<shortcut> string
|
|
|
|
char const * flyx_shortcut_extract(char const * sc);
|
|
|
|
/// Shortcut for flyx_shortcut_extract
|
|
|
|
#define scex flyx_shortcut_extract
|
|
|
|
|
|
|
|
/// Extract shortcut from <ident>|<shortcut> string
|
|
|
|
char const * flyx_ident_extract(char const * sc);
|
|
|
|
/// Shortcut for flyx_ident_extract
|
|
|
|
#define idex flyx_ident_extract
|
2000-11-02 14:47:47 +00:00
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
/// Set an FL_OBJECT to activated or deactivated
|
2001-03-05 19:02:40 +00:00
|
|
|
void setEnabled(FL_OBJECT *, bool enable);
|
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
/// Take a string and add breaks so that it fits into a desired label width, w
|
2001-03-15 13:37:04 +00:00
|
|
|
string formatted(string const &label, int w,
|
2001-12-12 09:56:03 +00:00
|
|
|
int = FL_NORMAL_SIZE, int = FL_NORMAL_STYLE);
|
2000-11-02 14:47:47 +00:00
|
|
|
|
2001-09-24 16:37:24 +00:00
|
|
|
/// Given an fl_choice, create a vector of its entries
|
|
|
|
std::vector<string> const getVectorFromChoice(FL_OBJECT *);
|
|
|
|
|
|
|
|
/// Given an fl_browser, create a vector of its entries
|
|
|
|
std::vector<string> const getVectorFromBrowser(FL_OBJECT *);
|
|
|
|
|
2002-01-15 15:31:19 +00:00
|
|
|
/// Given an fl_input, return its contents.
|
|
|
|
string const getStringFromInput(FL_OBJECT * ob);
|
|
|
|
|
2002-01-14 12:47:17 +00:00
|
|
|
/** Given an fl_browser, return the contents of line
|
|
|
|
(xforms numbering convention; starts at 1).
|
2002-01-08 10:05:53 +00:00
|
|
|
*/
|
|
|
|
string const getStringFromBrowser(FL_OBJECT * ob, int line);
|
2002-01-14 12:47:17 +00:00
|
|
|
/** Given an fl_browser, return the contents of the currently
|
|
|
|
highlighted line.
|
|
|
|
*/
|
|
|
|
string const getSelectedStringFromBrowser(FL_OBJECT * ob);
|
2002-01-08 10:05:53 +00:00
|
|
|
|
2001-10-09 12:36:36 +00:00
|
|
|
/// Given input and choice widgets, create a string such as "1cm"
|
|
|
|
string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice);
|
|
|
|
|
2001-10-15 10:28:31 +00:00
|
|
|
/** Given a string such as "1cm", set the input and choice widgets.
|
|
|
|
If the string is empty, the choice will be set to default_unit.
|
|
|
|
*/
|
2001-10-09 12:36:36 +00:00
|
|
|
void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
|
2001-10-15 10:28:31 +00:00
|
|
|
string const & str,
|
|
|
|
string const & default_unit);
|
2001-10-09 12:36:36 +00:00
|
|
|
|
2001-12-11 17:26:52 +00:00
|
|
|
/** Given a LyXLength, set the input and choice widgets.
|
|
|
|
If the length is null, the choice will be set to default_unit.
|
|
|
|
*/
|
|
|
|
void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
|
|
|
|
LyXLength const & len,
|
|
|
|
string const & default_unit);
|
|
|
|
|
2002-03-13 11:26:36 +00:00
|
|
|
|
2002-05-01 09:25:51 +00:00
|
|
|
/** Return the position of val in the vector if found.
|
|
|
|
If not found, return 0.
|
|
|
|
*/
|
|
|
|
template<class A>
|
|
|
|
typename std::vector<A>::size_type
|
|
|
|
findPos(std::vector<A> const & vec, A const & val)
|
|
|
|
{
|
|
|
|
typename std::vector<A>::const_iterator it =
|
|
|
|
std::find(vec.begin(), vec.end(), val);
|
|
|
|
if (it == vec.end())
|
|
|
|
return 0;
|
|
|
|
return std::distance(vec.begin(), it);
|
|
|
|
}
|
|
|
|
|
2002-03-13 11:26:36 +00:00
|
|
|
/// Called from Preferences when the cursor color is changed.
|
|
|
|
void setCursorColor(int color);
|
|
|
|
|
|
|
|
|
2000-11-15 18:02:45 +00:00
|
|
|
/// struct holding xform-specific colors
|
2001-03-05 19:02:40 +00:00
|
|
|
struct XformsColor : public NamedColor {
|
2000-11-15 18:02:45 +00:00
|
|
|
int colorID;
|
2001-03-05 19:02:40 +00:00
|
|
|
XformsColor() : NamedColor(), colorID(0) {}
|
2000-11-15 18:02:45 +00:00
|
|
|
static bool read(string const &);
|
|
|
|
static bool write(string const &);
|
|
|
|
};
|
|
|
|
|
2000-11-21 15:46:13 +00:00
|
|
|
|
|
|
|
/** Some functions that perform some quite detailed tests to ascertain whether
|
|
|
|
the directory or file is readable or writeable. If not, then an error
|
|
|
|
message is placed in error_message. */
|
|
|
|
class RWInfo {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
static bool WriteableDir(string const & dir);
|
|
|
|
///
|
|
|
|
static bool ReadableDir(string const & dir);
|
|
|
|
///
|
|
|
|
static bool WriteableFile(string const & file);
|
|
|
|
///
|
|
|
|
static bool ReadableFile(string const & file);
|
|
|
|
///
|
|
|
|
static string const & ErrorMessage() { return error_message; }
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
static string error_message;
|
|
|
|
};
|
2001-03-05 19:02:40 +00:00
|
|
|
#endif // XFORMSHELPERS_H
|