OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [tools/] [configtool/] [standalone/] [wxwin/] [ecutils.h] - Blame information for rev 403

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 unneback
//####COPYRIGHTBEGIN####
2
//                                                                          
3
// ----------------------------------------------------------------------------
4
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5
// Copyright (C) 2003 John Dallaway
6
//
7
// This program is part of the eCos host tools.
8
//
9
// This program is free software; you can redistribute it and/or modify it 
10
// under the terms of the GNU General Public License as published by the Free 
11
// Software Foundation; either version 2 of the License, or (at your option) 
12
// any later version.
13
// 
14
// This program is distributed in the hope that it will be useful, but WITHOUT 
15
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
16
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
17
// more details.
18
// 
19
// You should have received a copy of the GNU General Public License along with
20
// this program; if not, write to the Free Software Foundation, Inc., 
21
// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
//
23
// ----------------------------------------------------------------------------
24
//                                                                          
25
//####COPYRIGHTEND####
26
//===========================================================================
27
//#####DESCRIPTIONBEGIN####
28
//
29
// Author(s):   sdf, jld
30
// Contact(s):  sdf
31
// Date:                1998/08/11
32
// Version:             0.01
33
// Purpose:     
34
// Description: Interface to various global utility functions.  Everything in this
35
//                              class is static (there are no instances).
36
//              Modified by julians for wxWindows (originally CTUtils.h)
37
// Requires:    
38
// Provides:    
39
// See also:    
40
// Known bugs:  
41
// Usage:       
42
//
43
//####DESCRIPTIONEND####
44
//  
45
//===========================================================================
46
 
47
#ifndef _ECUTILS_H_
48
#define _ECUTILS_H_
49
 
50
#ifdef __GNUG__
51
#pragma interface "ecutils.cpp"
52
#endif
53
 
54
#include "wx/hash.h"
55
#include "wx/confbase.h"
56
#include "wx/dynarray.h"
57
 
58
#include "filename.h"
59
#include "cdl.hxx"
60
 
61
//#define INCLUDEFILE <string>
62
//#include "IncludeSTL.h"
63
 
64
//#include <stdarg.h>     // vsnprintf
65
 
66
/*
67
 * ecUtils
68
 * This class implements a miscellany of utility functions.
69
 * They are being implemented as and when they are required during Configtool
70
 * development.
71
 */
72
 
73
class ecUtils {
74
public:
75
#if 0
76
    static bool Launch (const ecFileName &strFileName,const ecFileName &strViewer);
77
    static wxString GetLastErrorMessageString ();
78
#endif    
79
 
80
    static const wxString PosixToNativePath(const wxString & posix);
81
    static const wxString NativeToPosixPath(const wxString & native);
82
    static bool AddToPath (const ecFileName &strFolder, bool bAtFront=true);
83
 
84
#if 0
85
    static const wxString LoadString (UINT id);
86
 
87
    // Messagebox functions
88
 
89
    // Vararg message box compositor
90
    static int MessageBoxF (LPCTSTR pszFormat, ...);
91
    // Same, with type
92
    static int MessageBoxFT (UINT nType, LPCTSTR pszFormat, ...);
93
    // As above but with resource
94
    static int MessageBoxFR (UINT nID, UINT nType, LPCTSTR pszFormat, ...);
95
    // Same, with type
96
    static int MessageBoxFR (UINT nID, LPCTSTR pszFormat, ...);
97
    // vararg form
98
    static int vMessageBox(UINT nType, LPCTSTR  pszFormat, va_list marker);
99
 
100
#endif
101
    // String functions
102
 
103
    // Chop the string into pieces using separator cSep.
104
    // The Boolean controls whether " and \ make a difference
105
    static int Chop(const wxString& psz,wxArrayString &ar, wxChar cSep=wxT(' '),
106
        bool bObserveStrings = FALSE, bool bBackslashQuotes = FALSE);
107
 
108
    static int Chop(const wxString& psz,wxArrayString &ar, const wxString& pszSep,
109
        bool bObserveStrings=FALSE, bool bBackslashQuotes = FALSE);
110
 
111
    // String -> Integer, observing the current hex/decimal setting
112
    //static BOOL StrToItemIntegerType(const wxString &str, __int64 &d);
113
    static bool StrToItemIntegerType(const wxString &str, long &d);
114
    static bool StrToDouble (const wxString &strValue, double &dValue);
115
 
116
    // Integer -> String, observing the current hex/decimal setting
117
    static const wxString IntToStr(long d,bool bHex=false);
118
    static const wxString DoubleToStr (double dValue);
119
    static wxString StripExtraWhitespace (const wxString & strInput);
120
 
121
    static void UnicodeToCStr(const wxChar* str,char *&psz);
122
    static std::string UnicodeToStdStr(const wxChar* str);
123
 
124
#if 0    
125
    // Provide a failure explanation for what just went wrong
126
    static const wxString Explanation (CFileException &exc);
127
    static ecFileName WPath(const std::string &str);
128
    static bool CopyFile (LPCTSTR pszSource,LPCTSTR pszDest);
129
#endif
130
};
131
 
132
/*
133
 * wxStringToStringMap
134
 *
135
 * Stores string values keyed by strings.
136
 * Note that only one value is allowed per key.
137
 */
138
 
139
class wxStringToStringMap: public wxObject
140
{
141
public:
142
    wxStringToStringMap(): m_hashTable(wxKEY_STRING) {}
143
    ~wxStringToStringMap() { Clear(); }
144
 
145
//// Operations
146
 
147
    // Remove the key/value pair
148
    bool Remove(const wxString& key);
149
 
150
    // Clear the map
151
    void Clear();
152
 
153
    // Begin a search through the whole map: use Next to find key/value pairs
154
    void BeginFind();
155
 
156
    // Retrieve the next key/value pair, FALSE indicates end of data
157
    bool Next(wxString& key, wxString& value);
158
 
159
//// Accessors
160
 
161
    // Replaces the value (if any) associated with the key
162
    void Set(const wxString& key, const wxString& value);
163
 
164
    // Finds a value associated with the key, returns FALSE if none
165
    bool Find(const wxString& key, wxString& value);
166
 
167
protected:
168
    wxHashTable m_hashTable;
169
};
170
 
171
// Is str a member of arr?
172
bool wxArrayStringIsMember(const wxArrayString& arr, const wxString& str);
173
 
174
// Eliminate .. and .
175
wxString wxGetRealPath(const wxString& path);
176
 
177
// A version of the above but prepending the cwd (current path) first
178
// if 'path' is relative
179
wxString wxGetRealPath(const wxString& cwd, const wxString& path);
180
 
181
// Find the absolute path where this application has been run from.
182
// argv0 is wxTheApp->argv[0]
183
// cwd is the current working directory (at startup)
184
// appVariableName is the name of a variable containing the directory for this app, e.g.
185
//   MYAPPDIR. This is used as a last resort. Or should it be a first resort?
186
wxString wxFindAppPath(const wxString& argv0, const wxString& cwd, const wxString& appVariableName = wxEmptyString);
187
 
188
// Find the text of the list control item at the given column
189
class WXDLLEXPORT wxListCtrl;
190
wxString wxListCtrlGetItemTextColumn(wxListCtrl& listCtrl, long item, int col);
191
 
192
// Select the given item
193
void wxListCtrlSelectItem(wxListCtrl& listCtrl, long sel, bool deselectOther = TRUE);
194
 
195
// Find the selection
196
long wxListCtrlGetSelection(wxListCtrl& listCtrl);
197
 
198
// Find which column the cursor is on
199
int wxListCtrlFindColumn(wxListCtrl& listCtrl, int noCols, int x);
200
 
201
// Refresh children of this window (e.g. on Windows, laying out a window containing
202
// controls can cause screen corruption)
203
void wxRefreshControls(wxWindow* win);
204
 
205
// Make a path name with no separators, out of a full pathname,
206
// e.g. opt_ecos_ecos-1.4.5 out of /opt/ecos/ecos-1.4.5
207
wxString ecMakeNameFromPath(const wxString& path);
208
 
209
// Kill a process
210
int ecKill(long pid, wxSignal sig);
211
 
212
class WXDLLEXPORT wxOutputStream;
213
 
214
wxOutputStream& operator <<(wxOutputStream&, const wxString& s);
215
wxOutputStream& operator <<(wxOutputStream&, const char c);
216
wxOutputStream& operator <<(wxOutputStream&, long l);
217
 
218
/*
219
 * Class for recursively killing a process and its children.
220
 * This has been taken from CSubprocess, but we can't use CSubprocess
221
 * directly for killing a process because it assumes it's been used to create
222
 * the process.
223
 */
224
 
225
class wxProcessKiller
226
{
227
 
228
public:
229
    const wxString ErrorString() const;
230
 
231
    wxProcessKiller(int pid);
232
    ~wxProcessKiller();
233
 
234
    void SetVerbose   (bool b)         { m_bVerbose=b; }
235
 
236
    int Pid() const { return m_idProcess; } // returns process id (even when process is terminated)
237
 
238
    // Get the process exit code.  This can be:
239
    //   exit code of process (if terminated)
240
    //   0xffffffff (if process not yet run)
241
    //   GetLastError result (if process could not be run)
242
    int GetExitCode() { return m_nExitCode; }
243
 
244
    // Kill the process:
245
    bool Kill(bool bRecurse = true);
246
 
247
    // Is the process running?
248
    bool ProcessAlive();
249
 
250
protected:
251
    static const wxString Name (int pid); // for debugging - only works under NT
252
 
253
    struct wxPInfo;
254
    struct wxPInfo {
255
        wxPInfo *pParent;
256
#ifdef _WIN32
257
        wxLongLong_t tCreation;
258
#endif
259
        long tCpu;
260
        int PID;
261
        int PPID;
262
        bool IsChildOf(int pid) const;
263
    };
264
 
265
    typedef std::vector<wxPInfo> wxPInfoArray;
266
 
267
    static bool PSExtract(wxPInfoArray &arPinfo);
268
    static void SetParents(wxPInfoArray &arPinfo);
269
 
270
#ifdef _WIN32
271
    static long GetPlatform();
272
    WXHANDLE m_hrPipe;
273
    WXHANDLE m_hwPipe;
274
    WXHANDLE m_hProcess;     // This handle is "owned" by the ThreadFunc
275
    static WXHINSTANCE hInstLib1, hInstLib2;
276
    int m_nErr;
277
#else
278
    int m_tty;
279
    wxString m_strCmd;
280
#endif
281
 
282
    bool m_bVerbose;
283
    int m_nExitCode;
284
    int m_idProcess;
285
 
286
    static const unsigned int PROCESS_KILL_EXIT_CODE;
287
};
288
 
289
/*
290
 * ecDialog
291
 * Supports features we want to have for all dialogs in the application.
292
 * So far, this just allows dialogs to be resizeable under MSW by
293
 * refreshing the controls in OnSize (otherwise there's a mess)
294
 */
295
 
296
class ecDialog: public wxDialog
297
{
298
public:
299
    DECLARE_CLASS(ecDialog)
300
 
301
    ecDialog() {};
302
 
303
    ecDialog(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos = wxDefaultPosition,
304
        const wxSize& sz = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE)
305
    {
306
        Create(parent, id, title, pos, sz, style);
307
    }
308
/*
309
    bool Create(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos = wxDefaultPosition,
310
        const wxSize& sz = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE);
311
*/
312
 
313
    void OnSize(wxSizeEvent& event);
314
 
315
DECLARE_EVENT_TABLE()
316
};
317
 
318
/*
319
 * Implements saving/loading of window settings - fonts only for now
320
 */
321
 
322
class wxWindowSettingsObject: public wxObject
323
{
324
public:
325
    wxWindowSettingsObject(const wxString& name, wxWindow* win) { m_windowName = name; if (win) m_arrWindow.Add(win); }
326
    wxString    m_windowName;
327
    wxFont      m_font;
328
    wxArrayPtrVoid m_arrWindow;
329
};
330
 
331
class wxWindowSettings: public wxObject
332
{
333
public:
334
    wxWindowSettings() { m_useDefaults = TRUE; };
335
    ~wxWindowSettings() { Clear(); }
336
 
337
//// Operations
338
    wxWindowSettingsObject* FindSettings(const wxString& windowName) const;
339
    void Add(const wxString& name, wxWindow* win = NULL) { m_settings.Append(new wxWindowSettingsObject(name, win)); }
340
 
341
    bool LoadConfig(wxConfigBase& config);
342
    bool SaveConfig(wxConfigBase& config);
343
 
344
    bool LoadFont(wxConfigBase& config, const wxString& windowName, wxFont& font);
345
    bool SaveFont(wxConfigBase& config, const wxString& windowName, const wxFont& font);
346
 
347
    void Clear() { m_settings.DeleteContents(TRUE); m_settings.Clear(); m_settings.DeleteContents(FALSE); }
348
 
349
    bool ApplyFontsToWindows();
350
 
351
//// Accessors
352
    wxFont GetFont(const wxString& name) const;
353
    void SetFont(const wxString& name, const wxFont& font);
354
 
355
    wxWindow* GetWindow(const wxString& name) const;
356
    void SetWindow(const wxString& name, wxWindow* win);
357
 
358
    wxArrayPtrVoid* GetWindows(const wxString& name) const;
359
    void SetWindows(const wxString& name, wxArrayPtrVoid& arr);
360
 
361
    int GetCount() const { return m_settings.Number(); }
362
    wxWindowSettingsObject* GetNth(int i) const { return (wxWindowSettingsObject*) m_settings.Nth(i)->Data(); }
363
    wxString GetName(int i) const { return GetNth(i)->m_windowName; }
364
 
365
    void SetUseDefaults(bool useDefaults) { m_useDefaults = useDefaults; }
366
    bool GetUseDefaults() const { return m_useDefaults; }
367
 
368
public:
369
    wxList  m_settings;
370
    bool    m_useDefaults;
371
};
372
 
373
#endif
374
// _ECUTILS_H_

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.