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