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