1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Various utilities
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 // Note: this is done in utilscmn.cpp now.
14 // #pragma implementation
15 // #pragma implementation "utils.h"
21 #include "wx/mac/uma.h"
30 // get full hostname (with domain name if possible)
31 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
33 return wxGetHostName(buf
, maxSize
);
36 // Get hostname only (without domain name)
37 bool wxGetHostName(char *buf
, int maxSize
)
43 // Get user ID e.g. jacs
44 bool wxGetUserId(char *buf
, int maxSize
)
50 const wxChar
* wxGetHomeDir(wxString
*pstr
)
52 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
53 return pstr
->c_str() ;
58 // Get user name e.g. AUTHOR
59 bool wxGetUserName(char *buf
, int maxSize
)
65 int wxKill(long pid
, int sig
)
72 // Execute a program in an Interactive Shell
74 bool wxShell(const wxString
& command
)
80 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
81 long wxGetFreeMemory()
87 void wxSleep(int nSecs
)
92 // Consume all events until no more left
97 // Output a debug message, in a system dependent fashion.
98 void wxDebugMsg(const char *fmt
...)
101 static char buffer
[512];
103 if (!wxTheApp
->GetWantDebugOutput())
108 // wvsprintf(buffer,fmt,ap) ;
109 // TODO: output buffer
114 // Non-fatal error: pop up message box and (possibly) continue
115 void wxError(const wxString
& msg
, const wxString
& title
)
121 // Fatal error: pop up message box and abort
122 void wxFatalError(const wxString
& msg
, const wxString
& title
)
133 int wxGetOsVersion(int *majorVsn
, int *minorVsn
)
139 // Reading and writing resources (eg WIN.INI, .Xdefaults)
141 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
147 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
150 sprintf(buf
, "%.4f", value
);
151 return wxWriteResource(section
, entry
, buf
, file
);
154 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
157 sprintf(buf
, "%ld", value
);
158 return wxWriteResource(section
, entry
, buf
, file
);
161 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
164 sprintf(buf
, "%d", value
);
165 return wxWriteResource(section
, entry
, buf
, file
);
168 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
174 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
177 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
180 *value
= (float)strtod(s
, NULL
);
187 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
190 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
193 *value
= strtol(s
, NULL
, 10);
200 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
203 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
206 *value
= (int)strtol(s
, NULL
, 10);
212 #endif // wxUSE_RESOURCES
214 int wxBusyCursorCount
= 0;
215 extern CursHandle gMacCurrentCursor
;
216 CursHandle gMacStoredActiveCursor
= NULL
;
218 // Set the cursor to the busy cursor for all windows
219 void wxBeginBusyCursor(wxCursor
*cursor
)
221 wxBusyCursorCount
++;
222 if (wxBusyCursorCount
== 1)
224 gMacStoredActiveCursor
= gMacCurrentCursor
;
225 ::SetCursor( *::GetCursor( watchCursor
) ) ;
233 // Restore cursor to normal
234 void wxEndBusyCursor()
236 if (wxBusyCursorCount
== 0)
239 wxBusyCursorCount
--;
240 if (wxBusyCursorCount
== 0)
242 if ( gMacStoredActiveCursor
)
243 ::SetCursor( *gMacStoredActiveCursor
) ;
247 ::SetCursor( GetQDGlobalsArrow( &MacArrow
) ) ;
249 gMacStoredActiveCursor
= NULL
;
253 // TRUE if we're between the above two calls
256 return (wxBusyCursorCount
> 0);
259 wxString
wxMacFindFolder( short vol
,
261 Boolean createFolder
)
267 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
270 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
272 strDir
= wxMacFSSpec2UnixFilename( &file
) + "/" ;
278 char *wxGetUserHome (const wxString
& user
)
284 // Check whether this window wants to process messages, e.g. Stop button
285 // in long calculations.
286 bool wxCheckForInterrupt(wxWindow
*wnd
)
292 void wxGetMousePosition( int* x
, int* y
)
297 LocalToGlobal( &pt
) ;
302 // Return TRUE if we have a colour display
303 bool wxColourDisplay()
308 // Returns depth of screen
312 SetRect(&globRect
, -32760, -32760, 32760, 32760);
313 GDHandle theMaxDevice
;
316 theMaxDevice
= GetMaxDevice(&globRect
);
317 if (theMaxDevice
!= nil
)
318 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
323 // Get size of display
324 void wxDisplaySize(int *width
, int *height
)
327 GetQDGlobalsScreenBits( &screenBits
);
329 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
330 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
333 GetThemeMenuBarHeight( &mheight
) ;
336 *height
-= LMGetMBarHeight() ;
340 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
342 return wxGenericFindWindowAtPoint(pt
);