1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Utility functions and classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
14 * \brief A file of utility functions and classes.
27 * \defgroup ForwardDeclarations Forward Declations
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
;
52 #define wxNEWLINE wxT("\r\n")
54 #define wxNEWLINE wxT("\n")
57 /// Returns the image type, or -1, determined from the extension.
58 int apDetermineImageType(const wxString
& filename
);
60 /// Convert a colour to a 6-digit hex string
61 wxString
apColourToHexString(const wxColour
& col
);
63 /// Convert 6-digit hex string to a colour
64 wxColour
apHexStringToColour(const wxString
& hex
);
66 /// Convert a wxFont to a string
67 wxString
apFontToString(const wxFont
& font
);
69 /// Convert a string to a wxFont
70 wxFont
apStringToFont(const wxString
& str
);
72 /// Get the index of the given named wxNotebook page
73 int apFindNotebookPage(wxNotebook
* notebook
, const wxString
& name
);
75 /// View the given URL
76 void apViewHTMLFile(const wxString
& url
);
78 /// Returns the system temporary directory.
79 wxString
wxGetTempDir();
81 /// Launch the application associated with the filename's extension
82 bool apInvokeAppForFile(const wxString
& filename
);
84 /// \brief Find the absolute path where this application has been run from.
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
);
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);
95 /// Get selected wxNotebook page
96 wxWindow
* apNotebookGetSelectedPage(wxNotebook
* notebook
);
98 #define wxMAX_ICON_STATES 4
102 wxIconInfo, wxIconTable
103 associate multiple state icons with items in tree controls
104 (and potentially other controls).
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.
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.
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);
121 When you update the item image in response to (e.g.) user interaction,
122 you can say something like this:
124 int iconId = m_iconTable.GetIconId("Checkbox", 0, FALSE);
126 treeCtrl.SetItemImage(itemId, iconId, wxTreeItemIcon_Normal);
127 treeCtrl.SetItemImage(itemId, iconId, wxTreeItemIcon_Selected);
133 * Stores information about the visual state of an item in a tree control
136 class wxIconInfo
: public wxObject
139 wxIconInfo(const wxString
& name
);
141 // How many states? (Each state
142 // has enabled/disabled state)
143 // Max (say) 4 states, each with
145 int GetStateCount() const { return m_maxStates
; };
147 void SetStateCount(int count
) { m_maxStates
= count
; }
148 int GetIconId(int state
, bool enabled
= TRUE
) const;
149 void SetIconId(int state
, bool enabled
, int iconId
);
151 const wxString
& GetName() const { return m_name
; }
155 int m_states
[wxMAX_ICON_STATES
* 2]; // Enabled/disabled
156 wxString m_name
; // Name of icon, e.g. "Package"
161 * Contains a list of wxIconInfos
164 class wxIconTable
: public wxList
167 wxIconTable(wxImageList
* imageList
= NULL
);
169 void AppendInfo(wxIconInfo
* info
);
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
);
179 wxIconInfo
* FindInfo(const wxString
& name
) const;
181 int GetIconId(const wxString
& name
, int state
, bool enabled
= TRUE
) const;
182 bool SetIconId(const wxString
& name
, int state
, bool enabled
, int iconId
) ;
184 void SetImageList(wxImageList
* imageList
) { m_imageList
= imageList
; }
185 wxImageList
* GetImageList() const { return m_imageList
; }
188 wxImageList
* m_imageList
;
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
);
196 // Convert characters to HTML equivalents
197 wxString
ctEscapeHTMLCharacters(const wxString
& str
);
199 // Match 'matchText' against 'matchAgainst', optionally constraining to
201 bool ctMatchString(const wxString
& matchAgainst
, const wxString
& matchText
, bool wholeWordOnly
);