]>
Commit | Line | Data |
---|---|---|
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 | ||
32 | class WXDLLEXPORT wxImage; | |
33 | class WXDLLEXPORT wxNotebook; | |
34 | class WXDLLEXPORT wxInputStream; | |
35 | class WXDLLEXPORT wxOutputStream; | |
36 | class WXDLLEXPORT wxFileInputStream; | |
37 | class WXDLLEXPORT wxFileOutputStream; | |
38 | class WXDLLEXPORT wxDataInputStream; | |
39 | class WXDLLEXPORT wxDataOutputStream; | |
40 | class WXDLLEXPORT wxSplitterWindow; | |
41 | class WXDLLEXPORT wxVariant; | |
42 | class 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. | |
58 | int apDetermineImageType(const wxString& filename); | |
59 | ||
60 | /// Convert a colour to a 6-digit hex string | |
61 | wxString apColourToHexString(const wxColour& col); | |
62 | ||
63 | /// Convert 6-digit hex string to a colour | |
64 | wxColour apHexStringToColour(const wxString& hex); | |
65 | ||
66 | /// Convert a wxFont to a string | |
67 | wxString apFontToString(const wxFont& font); | |
68 | ||
69 | /// Convert a string to a wxFont | |
70 | wxFont apStringToFont(const wxString& str); | |
71 | ||
72 | /// Get the index of the given named wxNotebook page | |
73 | int apFindNotebookPage(wxNotebook* notebook, const wxString& name); | |
74 | ||
75 | /// View the given URL | |
76 | void apViewHTMLFile(const wxString& url); | |
77 | ||
78 | /// Returns the system temporary directory. | |
79 | wxString wxGetTempDir(); | |
80 | ||
81 | /// Launch the application associated with the filename's extension | |
82 | bool 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. | |
90 | wxString apFindAppPath(const wxString& argv0, const wxString& cwd, const wxString& appVariableName = wxEmptyString); | |
91 | ||
92 | /// Adds a context-sensitive help button, for non-Windows platforms | |
93 | void apAddContextHelpButton(wxWindow* parent, wxSizer* sizer, int sizerFlags = wxALIGN_CENTRE|wxALL, int sizerBorder = 5); | |
94 | ||
95 | /// Get selected wxNotebook page | |
96 | wxWindow* apNotebookGetSelectedPage(wxNotebook* notebook); | |
97 | ||
98 | #define wxMAX_ICON_STATES 4 | |
99 | ||
100 | /* | |
101 | ||
102 | wxIconInfo, wxIconTable | |
103 | associate multiple state icons with items in tree controls | |
104 | (and potentially other controls). | |
105 | ||
106 | So instead of having to remember a lot of image list ids, | |
107 | you 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 | |
109 | be in a further 2 sub-states - enabled or disabled. | |
110 | ||
111 | wxIconTable holds a list of these state info objects | |
112 | and has a convenient API. For example, the following adds | |
113 | icons for a checkbox item that can be: on/enabled, off/enabled, | |
114 | on/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 | ||
121 | When you update the item image in response to (e.g.) user interaction, | |
122 | you 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 | ||
136 | class wxIconInfo: public wxObject | |
137 | { | |
138 | public: | |
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 | ||
917ad696 | 147 | void SetStateCount(int count) { m_maxStates = count; } |
d7463f75 JS |
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 | ||
153 | protected: | |
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 | ||
164 | class wxIconTable: public wxList | |
165 | { | |
166 | public: | |
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 | ||
187 | protected: | |
188 | wxImageList* m_imageList; | |
189 | }; | |
190 | ||
191 | /// Useful insertion operators for wxOutputStream. | |
192 | wxOutputStream& operator <<(wxOutputStream&, const wxString& s); | |
193 | wxOutputStream& operator <<(wxOutputStream&, const char c); | |
194 | wxOutputStream& operator <<(wxOutputStream&, long l); | |
195 | ||
196 | // Convert characters to HTML equivalents | |
197 | wxString ctEscapeHTMLCharacters(const wxString& str); | |
198 | ||
e7767867 JS |
199 | // Match 'matchText' against 'matchAgainst', optionally constraining to |
200 | // whole-word only. | |
201 | bool ctMatchString(const wxString& matchAgainst, const wxString& matchText, bool wholeWordOnly); | |
202 | ||
203 | ||
d7463f75 JS |
204 | #endif |
205 | // _AP_UTILS_H_ |