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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [standalone/] [wxwin/] [ecutils.h] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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