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"
31 // defined in unix/utilsunx.cpp for Mac OS X
33 // get full hostname (with domain name if possible)
34 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
36 return wxGetHostName(buf
, maxSize
);
39 // Get hostname only (without domain name)
40 bool wxGetHostName(char *buf
, int maxSize
)
46 // Get user ID e.g. jacs
47 bool wxGetUserId(char *buf
, int maxSize
)
53 const wxChar
* wxGetHomeDir(wxString
*pstr
)
55 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
56 return pstr
->c_str() ;
61 // Get user name e.g. AUTHOR
62 bool wxGetUserName(char *buf
, int maxSize
)
68 int wxKill(long pid
, int sig
)
75 // Execute a program in an Interactive Shell
77 bool wxShell(const wxString
& command
)
83 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
84 long wxGetFreeMemory()
90 void wxSleep(int nSecs
)
95 // Consume all events until no more left
100 // Output a debug message, in a system dependent fashion.
101 void wxDebugMsg(const char *fmt
...)
104 static char buffer
[512];
106 if (!wxTheApp
->GetWantDebugOutput())
111 // wvsprintf(buffer,fmt,ap) ;
112 // TODO: output buffer
117 // Non-fatal error: pop up message box and (possibly) continue
118 void wxError(const wxString
& msg
, const wxString
& title
)
124 // Fatal error: pop up message box and abort
125 void wxFatalError(const wxString
& msg
, const wxString
& title
)
137 int wxGetOsVersion(int *majorVsn
, int *minorVsn
)
143 // Reading and writing resources (eg WIN.INI, .Xdefaults)
145 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
151 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
154 sprintf(buf
, "%.4f", value
);
155 return wxWriteResource(section
, entry
, buf
, file
);
158 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
161 sprintf(buf
, "%ld", value
);
162 return wxWriteResource(section
, entry
, buf
, file
);
165 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
168 sprintf(buf
, "%d", value
);
169 return wxWriteResource(section
, entry
, buf
, file
);
172 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
178 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
181 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
184 *value
= (float)strtod(s
, NULL
);
191 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
194 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
197 *value
= strtol(s
, NULL
, 10);
204 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
207 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
210 *value
= (int)strtol(s
, NULL
, 10);
216 #endif // wxUSE_RESOURCES
218 int wxBusyCursorCount
= 0;
219 extern CursHandle gMacCurrentCursor
;
220 CursHandle gMacStoredActiveCursor
= NULL
;
222 // Set the cursor to the busy cursor for all windows
223 void wxBeginBusyCursor(wxCursor
*cursor
)
225 wxBusyCursorCount
++;
226 if (wxBusyCursorCount
== 1)
228 gMacStoredActiveCursor
= gMacCurrentCursor
;
229 ::SetCursor( *::GetCursor( watchCursor
) ) ;
237 // Restore cursor to normal
238 void wxEndBusyCursor()
240 if (wxBusyCursorCount
== 0)
243 wxBusyCursorCount
--;
244 if (wxBusyCursorCount
== 0)
246 if ( gMacStoredActiveCursor
)
247 ::SetCursor( *gMacStoredActiveCursor
) ;
251 ::SetCursor( GetQDGlobalsArrow( &MacArrow
) ) ;
253 gMacStoredActiveCursor
= NULL
;
257 // TRUE if we're between the above two calls
260 return (wxBusyCursorCount
> 0);
264 wxString
wxMacFindFolder( short vol
,
266 Boolean createFolder
)
272 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
275 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
277 strDir
= wxMacFSSpec2UnixFilename( &file
) + "/" ;
285 char *wxGetUserHome (const wxString
& user
)
292 // Check whether this window wants to process messages, e.g. Stop button
293 // in long calculations.
294 bool wxCheckForInterrupt(wxWindow
*wnd
)
300 void wxGetMousePosition( int* x
, int* y
)
305 LocalToGlobal( &pt
) ;
310 // Return TRUE if we have a colour display
311 bool wxColourDisplay()
316 // Returns depth of screen
320 SetRect(&globRect
, -32760, -32760, 32760, 32760);
321 GDHandle theMaxDevice
;
324 theMaxDevice
= GetMaxDevice(&globRect
);
325 if (theMaxDevice
!= nil
)
326 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
331 // Get size of display
332 void wxDisplaySize(int *width
, int *height
)
335 GetQDGlobalsScreenBits( &screenBits
);
337 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
338 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
341 GetThemeMenuBarHeight( &mheight
) ;
344 *height
-= LMGetMBarHeight() ;
348 void wxDisplaySizeMM(int *width
, int *height
)
350 wxDisplaySize(width
, height
);
353 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
355 // This is supposed to return desktop dimensions minus any window
356 // manager panels, menus, taskbars, etc. If there is a way to do that
357 // for this platform please fix this function, otherwise it defaults
358 // to the entire desktop.
361 wxDisplaySize(width
, height
);
364 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
366 return wxGenericFindWindowAtPoint(pt
);