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