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 // Get user name e.g. AUTHOR
51 bool wxGetUserName(char *buf
, int maxSize
)
57 int wxKill(long pid
, int sig
)
64 // Execute a program in an Interactive Shell
66 bool wxShell(const wxString
& command
)
72 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
73 long wxGetFreeMemory()
79 void wxSleep(int nSecs
)
84 // Consume all events until no more left
89 // Output a debug message, in a system dependent fashion.
90 void wxDebugMsg(const char *fmt
...)
93 static char buffer
[512];
95 if (!wxTheApp
->GetWantDebugOutput())
100 // wvsprintf(buffer,fmt,ap) ;
101 // TODO: output buffer
106 // Non-fatal error: pop up message box and (possibly) continue
107 void wxError(const wxString
& msg
, const wxString
& title
)
113 // Fatal error: pop up message box and abort
114 void wxFatalError(const wxString
& msg
, const wxString
& title
)
125 int wxGetOsVersion(int *majorVsn
, int *minorVsn
)
131 // Reading and writing resources (eg WIN.INI, .Xdefaults)
133 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
139 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
142 sprintf(buf
, "%.4f", value
);
143 return wxWriteResource(section
, entry
, buf
, file
);
146 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
149 sprintf(buf
, "%ld", value
);
150 return wxWriteResource(section
, entry
, buf
, file
);
153 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
156 sprintf(buf
, "%d", value
);
157 return wxWriteResource(section
, entry
, buf
, file
);
160 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
166 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
169 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
172 *value
= (float)strtod(s
, NULL
);
179 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
182 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
185 *value
= strtol(s
, NULL
, 10);
192 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
195 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
198 *value
= (int)strtol(s
, NULL
, 10);
204 #endif // wxUSE_RESOURCES
206 int wxBusyCursorCount
= 0;
207 extern CursHandle gMacCurrentCursor
;
208 CursHandle gMacStoredActiveCursor
= NULL
;
210 // Set the cursor to the busy cursor for all windows
211 void wxBeginBusyCursor(wxCursor
*cursor
)
213 wxBusyCursorCount
++;
214 if (wxBusyCursorCount
== 1)
216 gMacStoredActiveCursor
= gMacCurrentCursor
;
217 ::SetCursor( *::GetCursor( watchCursor
) ) ;
225 // Restore cursor to normal
226 void wxEndBusyCursor()
228 if (wxBusyCursorCount
== 0)
231 wxBusyCursorCount
--;
232 if (wxBusyCursorCount
== 0)
234 if ( gMacStoredActiveCursor
)
235 ::SetCursor( *gMacStoredActiveCursor
) ;
239 ::SetCursor( GetQDGlobalsArrow( &MacArrow
) ) ;
241 gMacStoredActiveCursor
= NULL
;
245 // TRUE if we're between the above two calls
248 return (wxBusyCursorCount
> 0);
251 wxString
wxMacFindFolder( short vol
,
253 Boolean createFolder
)
259 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
262 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
264 strDir
= wxMacFSSpec2UnixFilename( &file
) + "/" ;
270 char *wxGetUserHome (const wxString
& user
)
276 // Check whether this window wants to process messages, e.g. Stop button
277 // in long calculations.
278 bool wxCheckForInterrupt(wxWindow
*wnd
)
284 void wxGetMousePosition( int* x
, int* y
)
289 LocalToGlobal( &pt
) ;
294 // Return TRUE if we have a colour display
295 bool wxColourDisplay()
300 // Returns depth of screen
304 SetRect(&globRect
, -32760, -32760, 32760, 32760);
305 GDHandle theMaxDevice
;
308 theMaxDevice
= GetMaxDevice(&globRect
);
309 if (theMaxDevice
!= nil
)
310 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
315 // Get size of display
316 void wxDisplaySize(int *width
, int *height
)
319 GetQDGlobalsScreenBits( &screenBits
);
321 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
322 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
325 GetThemeMenuBarHeight( &mheight
) ;
328 *height
-= LMGetMBarHeight() ;