]> git.saurik.com Git - wxWidgets.git/blame - utils/configtool/src/utils.h
removed BuildRequires: wx-base-devel from RPM .spec files
[wxWidgets.git] / utils / configtool / src / utils.h
CommitLineData
d7463f75
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: utils.h
3// Purpose: Utility functions and classes
4// Author: Julian Smart
5// Modified by:
6// Created: 2002-09-04
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence:
10/////////////////////////////////////////////////////////////////////////////
11
12/*!
13 * \file
14 * \brief A file of utility functions and classes.
15 */
16
17#ifdef __GNUG__
18// #pragma interface
19#endif
20
21#ifndef _AP_UTILS_H_
22#define _AP_UTILS_H_
23
24#ifndef DOXYGEN_SKIP
25
26/*!
27 * \defgroup ForwardDeclarations Forward Declations
28 */
29
30/*@{*/
31
32class WXDLLEXPORT wxImage;
33class WXDLLEXPORT wxNotebook;
34class WXDLLEXPORT wxInputStream;
35class WXDLLEXPORT wxOutputStream;
36class WXDLLEXPORT wxFileInputStream;
37class WXDLLEXPORT wxFileOutputStream;
38class WXDLLEXPORT wxDataInputStream;
39class WXDLLEXPORT wxDataOutputStream;
40class WXDLLEXPORT wxSplitterWindow;
41class WXDLLEXPORT wxVariant;
42class WXDLLEXPORT wxListCtrl;
43
44 /* \endif
45 */
46
47/*@}*/
48
49#endif
50
51#ifdef __WXMSW__
52#define wxNEWLINE wxT("\r\n")
53#else
54#define wxNEWLINE wxT("\n")
55#endif
56
57/// Returns the image type, or -1, determined from the extension.
58int apDetermineImageType(const wxString& filename);
59
60/// Convert a colour to a 6-digit hex string
61wxString apColourToHexString(const wxColour& col);
62
63/// Convert 6-digit hex string to a colour
64wxColour apHexStringToColour(const wxString& hex);
65
66/// Convert a wxFont to a string
67wxString apFontToString(const wxFont& font);
68
69/// Convert a string to a wxFont
70wxFont apStringToFont(const wxString& str);
71
72/// Get the index of the given named wxNotebook page
73int apFindNotebookPage(wxNotebook* notebook, const wxString& name);
74
75/// View the given URL
76void apViewHTMLFile(const wxString& url);
77
78/// Returns the system temporary directory.
79wxString wxGetTempDir();
80
81/// Launch the application associated with the filename's extension
82bool apInvokeAppForFile(const wxString& filename);
83
84/// \brief Find the absolute path where this application has been run from.
85///
86/// \param argv0 wxTheApp->argv[0]
87/// \param cwd The current working directory (at startup)
88/// \param appVariableName The name of a variable containing the directory for this app, e.g.
89/// MYAPPDIR. This is used as a last resort.
90wxString apFindAppPath(const wxString& argv0, const wxString& cwd, const wxString& appVariableName = wxEmptyString);
91
92/// Adds a context-sensitive help button, for non-Windows platforms
93void apAddContextHelpButton(wxWindow* parent, wxSizer* sizer, int sizerFlags = wxALIGN_CENTRE|wxALL, int sizerBorder = 5);
94
95/// Get selected wxNotebook page
96wxWindow* apNotebookGetSelectedPage(wxNotebook* notebook);
97
98#define wxMAX_ICON_STATES 4
99
100/*
101
102wxIconInfo, wxIconTable
103associate multiple state icons with items in tree controls
104(and potentially other controls).
105
106So instead of having to remember a lot of image list ids,
107you have a named state info object which contains up to 4 different states
108(identified by the integers 0 - 3). Each of these states can
109be in a further 2 sub-states - enabled or disabled.
110
111wxIconTable holds a list of these state info objects
112and has a convenient API. For example, the following adds
113icons for a checkbox item that can be: on/enabled, off/enabled,
114on/disabled,off/disabled.
115
116 m_iconTable.AddInfo("Checkbox", wxICON(checked), 0, TRUE);
117 m_iconTable.AddInfo("Checkbox", wxICON(checked_dis), 0, FALSE);
118 m_iconTable.AddInfo("Checkbox", wxICON(unchecked), 1, TRUE);
119 m_iconTable.AddInfo("Checkbox", wxICON(unchecked_dis), 1, FALSE);
120
121When you update the item image in response to (e.g.) user interaction,
122you can say something like this:
123
124 int iconId = m_iconTable.GetIconId("Checkbox", 0, FALSE);
125
126 treeCtrl.SetItemImage(itemId, iconId, wxTreeItemIcon_Normal);
127 treeCtrl.SetItemImage(itemId, iconId, wxTreeItemIcon_Selected);
128
129 */
130
131/*
132 * wxIconInfo
133 * Stores information about the visual state of an item in a tree control
134 */
135
136class wxIconInfo: public wxObject
137{
138public:
139 wxIconInfo(const wxString& name);
140
141 // How many states? (Each state
142 // has enabled/disabled state)
143 // Max (say) 4 states, each with
144 // enabled/disabled
145 int GetStateCount() const { return m_maxStates; };
146
147 void SetStateCount(int count) { m_maxStates; }
148 int GetIconId(int state, bool enabled = TRUE) const;
149 void SetIconId(int state, bool enabled, int iconId);
150
151 const wxString& GetName() const { return m_name; }
152
153protected:
154 int m_maxStates;
155 int m_states[wxMAX_ICON_STATES * 2]; // Enabled/disabled
156 wxString m_name; // Name of icon, e.g. "Package"
157};
158
159/*!
160 * wxIconTable
161 * Contains a list of wxIconInfos
162 */
163
164class wxIconTable: public wxList
165{
166public:
167 wxIconTable(wxImageList* imageList = NULL);
168
169 void AppendInfo(wxIconInfo* info);
170
171 // Easy way of initialising both the image list and the
172 // info db. It will generate image ids itself while appending the icon.
173 // 'state' is an integer from 0 up to the max allowed, representing a different
174 // state. There may be only one, or (for a checkbox) there may be two.
175 // A folder that can be open or closed would have two states.
176 // Enabled/disabled is taken as a special case.
177 bool AddInfo(const wxString& name, const wxIcon& icon, int state, bool enabled);
178
179 wxIconInfo* FindInfo(const wxString& name) const;
180
181 int GetIconId(const wxString& name, int state, bool enabled = TRUE) const;
182 bool SetIconId(const wxString& name, int state, bool enabled, int iconId) ;
183
184 void SetImageList(wxImageList* imageList) { m_imageList = imageList; }
185 wxImageList* GetImageList() const { return m_imageList; }
186
187protected:
188 wxImageList* m_imageList;
189};
190
191/// Useful insertion operators for wxOutputStream.
192wxOutputStream& operator <<(wxOutputStream&, const wxString& s);
193wxOutputStream& operator <<(wxOutputStream&, const char c);
194wxOutputStream& operator <<(wxOutputStream&, long l);
195
196// Convert characters to HTML equivalents
197wxString ctEscapeHTMLCharacters(const wxString& str);
198
e7767867
JS
199// Match 'matchText' against 'matchAgainst', optionally constraining to
200// whole-word only.
201bool ctMatchString(const wxString& matchAgainst, const wxString& matchText, bool wholeWordOnly);
202
203
d7463f75
JS
204#endif
205 // _AP_UTILS_H_