]>
git.saurik.com Git - wxWidgets.git/blob - src/common/utilscmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Miscellaneous utility functions and classes
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "utils.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/string.h"
40 #include "wx/window.h"
43 #include "wx/msgdlg.h"
44 #include "wx/textdlg.h"
45 #include "wx/textctrl.h" // for wxTE_PASSWORD
47 #include "wx/menuitem.h"
54 #include "wx/process.h"
55 #include "wx/txtstrm.h"
63 #if !defined(__WATCOMC__)
64 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
70 #include "wx/colordlg.h"
71 #include "wx/fontdlg.h"
72 #include "wx/notebook.h"
74 #include "wx/statusbr.h"
75 #include "wx/toolbar.h"
81 #include <sys/types.h>
90 #include "wx/msw/private.h"
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 #if WXWIN_COMPATIBILITY_2_2
98 const wxChar
*wxInternalErrorStr
= wxT("wxWindows Internal Error");
99 const wxChar
*wxFatalErrorStr
= wxT("wxWindows Fatal Error");
100 #endif // WXWIN_COMPATIBILITY_2_2
102 // ----------------------------------------------------------------------------
103 // function protoypes
104 // ----------------------------------------------------------------------------
107 static wxWindow
*wxFindWindowByLabel1(const wxString
& title
, wxWindow
*parent
);
108 static wxWindow
*wxFindWindowByName1 (const wxString
& title
, wxWindow
*parent
);
111 // ============================================================================
113 // ============================================================================
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
119 #if defined(__WXMAC__) && !defined(__DARWIN__)
120 int strcasecmp(const char *str_1
, const char *str_2
)
122 register char c1
, c2
;
124 c1
= tolower(*str_1
++);
125 c2
= tolower(*str_2
++);
126 } while ( c1
&& (c1
== c2
) );
131 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
134 register char c1
, c2
;
137 c1
= tolower(*str_1
++);
138 c2
= tolower(*str_2
++);
148 #endif // __WXMAC__ && !__DARWIN__
150 #if defined( __VMS__ ) && ( __VMS_VER < 70000000 )
151 // we have no strI functions under VMS, therefore I have implemented
152 // an inefficient but portable version: convert copies of strings to lowercase
153 // and then use the normal comparison
154 static void myLowerString(char *s
)
157 if(isalpha(*s
)) *s
= (char)tolower(*s
);
162 int strcasecmp(const char *str_1
, const char *str_2
)
164 char *temp1
= new char[strlen(str_1
)+1];
165 char *temp2
= new char[strlen(str_2
)+1];
168 myLowerString(temp1
);
169 myLowerString(temp2
);
171 int result
= wxStrcmp(temp1
,temp2
);
178 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
180 char *temp1
= new char[strlen(str_1
)+1];
181 char *temp2
= new char[strlen(str_2
)+1];
184 myLowerString(temp1
);
185 myLowerString(temp2
);
187 int result
= strncmp(temp1
,temp2
,maxchar
);
195 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
199 #define strcasecmp stricmp
200 #define strncasecmp strnicmp
202 #define strcasecmp _stricmp
203 #define strncasecmp _strnicmp
210 #define strcasecmp stricmp
211 #define strncasecmp strnicmp
214 // This declaration is missing in SunOS!
215 // (Yes, I know it is NOT ANSI-C but its in BSD libc)
216 #if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
219 int strcasecmp (const char *, const char *);
220 int strncasecmp (const char *, const char *, size_t);
223 #endif /* __WXMSW__ */
226 #define strcasecmp stricmp
227 #define strncasecmp strnicmp
231 #define strcasecmp stricmp
232 #define strncasecmp strnicmp
236 copystring (const wxChar
*s
)
238 if (s
== NULL
) s
= wxT("");
239 size_t len
= wxStrlen (s
) + 1;
241 wxChar
*news
= new wxChar
[len
];
242 memcpy (news
, s
, len
* sizeof(wxChar
)); // Should be the fastest
248 static long wxCurrentId
= 100;
253 return wxCurrentId
++;
257 wxGetCurrentId(void) { return wxCurrentId
; }
260 wxRegisterId (long id
)
262 if (id
>= wxCurrentId
)
263 wxCurrentId
= id
+ 1;
267 StringToFloat (const wxChar
*s
, float *number
)
269 if (s
&& *s
&& number
)
270 *number
= (float) wxStrtod (s
, (wxChar
**) NULL
);
274 StringToDouble (const wxChar
*s
, double *number
)
276 if (s
&& *s
&& number
)
277 *number
= wxStrtod (s
, (wxChar
**) NULL
);
281 FloatToString (float number
, const wxChar
*fmt
)
283 static wxChar buf
[256];
285 wxSprintf (buf
, fmt
, number
);
290 DoubleToString (double number
, const wxChar
*fmt
)
292 static wxChar buf
[256];
294 wxSprintf (buf
, fmt
, number
);
299 StringToInt (const wxChar
*s
, int *number
)
301 if (s
&& *s
&& number
)
302 *number
= (int) wxStrtol (s
, (wxChar
**) NULL
, 10);
306 StringToLong (const wxChar
*s
, long *number
)
308 if (s
&& *s
&& number
)
309 *number
= wxStrtol (s
, (wxChar
**) NULL
, 10);
313 IntToString (int number
)
315 static wxChar buf
[20];
317 wxSprintf (buf
, wxT("%d"), number
);
322 LongToString (long number
)
324 static wxChar buf
[20];
326 wxSprintf (buf
, wxT("%ld"), number
);
330 // Array used in DecToHex conversion routine.
331 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
333 // Convert 2-digit hex number to decimal
334 int wxHexToDec(const wxString
& buf
)
336 int firstDigit
, secondDigit
;
338 if (buf
.GetChar(0) >= wxT('A'))
339 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
341 firstDigit
= buf
.GetChar(0) - wxT('0');
343 if (buf
.GetChar(1) >= wxT('A'))
344 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
346 secondDigit
= buf
.GetChar(1) - wxT('0');
348 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
351 // Convert decimal integer to 2-character hex string
352 void wxDecToHex(int dec
, wxChar
*buf
)
354 int firstDigit
= (int)(dec
/16.0);
355 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
356 buf
[0] = hexArray
[firstDigit
];
357 buf
[1] = hexArray
[secondDigit
];
361 // Convert decimal integer to 2-character hex string
362 wxString
wxDecToHex(int dec
)
365 wxDecToHex(dec
, buf
);
366 return wxString(buf
);
369 // Match a string INDEPENDENT OF CASE
371 StringMatch (const char *str1
, const char *str2
, bool subString
, bool exact
)
373 if (str1
== NULL
|| str2
== NULL
)
380 int len1
= strlen (str1
);
381 int len2
= strlen (str2
);
384 // Search for str1 in str2
385 // Slow .... but acceptable for short strings
386 for (i
= 0; i
<= len2
- len1
; i
++)
388 if (strncasecmp (str1
, str2
+ i
, len1
) == 0)
394 if (strcasecmp (str1
, str2
) == 0)
399 int len1
= strlen (str1
);
400 int len2
= strlen (str2
);
402 if (strncasecmp (str1
, str2
, wxMin (len1
, len2
)) == 0)
409 // Return the current date/time
413 time_t now
= time((time_t *) NULL
);
414 char *date
= ctime(&now
);
416 return wxString(date
);
423 // ----------------------------------------------------------------------------
424 // Menu accelerators related functions
425 // ----------------------------------------------------------------------------
427 wxChar
*wxStripMenuCodes(const wxChar
*in
, wxChar
*out
)
429 wxString s
= wxMenuItem::GetLabelFromText(in
);
432 // go smash their buffer if it's not big enough - I love char * params
433 memcpy(out
, s
.c_str(), s
.length() * sizeof(wxChar
));
443 wxString
wxStripMenuCodes(const wxString
& in
)
447 size_t len
= in
.length();
450 for ( size_t n
= 0; n
< len
; n
++ )
455 // skip it, it is used to introduce the accel char (or to quote
456 // itself in which case it should still be skipped): note that it
457 // can't be the last character of the string
460 wxLogDebug(_T("Invalid menu string '%s'"), in
.c_str());
464 // use the next char instead
468 else if ( ch
== _T('\t') )
470 // everything after TAB is accel string, exit the loop
480 #endif // wxUSE_MENUS
482 // ----------------------------------------------------------------------------
483 // Window search functions
484 // ----------------------------------------------------------------------------
487 * If parent is non-NULL, look through children for a label or title
488 * matching the specified string. If NULL, look through all top-level windows.
493 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
497 return wxFindWindowByLabel1(title
, parent
);
501 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
503 node
= node
->GetNext() )
505 wxWindow
*win
= node
->GetData();
506 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
512 return (wxWindow
*) NULL
;
517 wxFindWindowByLabel1 (const wxString
& title
, wxWindow
* parent
)
521 if (parent
->GetLabel() == title
)
527 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
529 node
= node
->GetNext() )
531 wxWindow
*win
= (wxWindow
*)node
->GetData();
532 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
539 return (wxWindow
*) NULL
; // Not found
543 * If parent is non-NULL, look through children for a name
544 * matching the specified string. If NULL, look through all top-level windows.
549 wxFindWindowByName (const wxString
& title
, wxWindow
* parent
)
553 return wxFindWindowByName1 (title
, parent
);
557 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
559 node
= node
->GetNext() )
561 wxWindow
*win
= node
->GetData();
562 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
569 // Failed? Try by label instead.
570 return wxFindWindowByLabel(title
, parent
);
575 wxFindWindowByName1 (const wxString
& title
, wxWindow
* parent
)
579 if ( parent
->GetName() == title
)
585 for (wxNode
* node
= parent
->GetChildren().First (); node
; node
= node
->Next ())
587 wxWindow
*win
= (wxWindow
*) node
->Data ();
588 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
595 return (wxWindow
*) NULL
; // Not found
599 // Returns menu item id or -1 if none.
601 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
604 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
606 return menuBar
->FindMenuItem (menuString
, itemString
);
607 #endif // wxUSE_MENUS
612 // Try to find the deepest child that contains 'pt'.
613 // We go backwards, to try to allow for controls that are spacially
614 // within other controls, but are still siblings (e.g. buttons within
615 // static boxes). Static boxes are likely to be created _before_ controls
616 // that sit inside them.
617 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
622 // Hack for wxNotebook case: at least in wxGTK, all pages
623 // claim to be shown, so we must only deal with the selected one.
625 if (win
->IsKindOf(CLASSINFO(wxNotebook
)))
627 wxNotebook
* nb
= (wxNotebook
*) win
;
628 int sel
= nb
->GetSelection();
631 wxWindow
* child
= nb
->GetPage(sel
);
632 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
641 else if (win->IsKindOf(CLASSINFO(wxFrame)))
643 // Pseudo-children that may not be mentioned in the child list
644 wxWindowList extraChildren;
645 wxFrame* frame = (wxFrame*) win;
646 if (frame->GetStatusBar())
647 extraChildren.Append(frame->GetStatusBar());
648 if (frame->GetToolBar())
649 extraChildren.Append(frame->GetToolBar());
651 wxNode* node = extraChildren.First();
654 wxWindow* child = (wxWindow*) node->Data();
655 wxWindow* foundWin = wxFindWindowAtPoint(child, pt);
663 wxNode
* node
= win
->GetChildren().Last();
666 wxWindow
* child
= (wxWindow
*) node
->Data();
667 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
670 node
= node
->Previous();
673 wxPoint pos
= win
->GetPosition();
674 wxSize sz
= win
->GetSize();
675 if (win
->GetParent())
677 pos
= win
->GetParent()->ClientToScreen(pos
);
680 wxRect
rect(pos
, sz
);
687 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
689 // Go backwards through the list since windows
690 // on top are likely to have been appended most
692 wxNode
* node
= wxTopLevelWindows
.Last();
695 wxWindow
* win
= (wxWindow
*) node
->Data();
696 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
699 node
= node
->Previous();
707 On Fri, 21 Jul 1995, Paul Craven wrote:
709 > Is there a way to find the path of running program's executable? I can get
710 > my home directory, and the current directory, but I don't know how to get the
711 > executable directory.
714 The code below (warty as it is), does what you want on most Unix,
715 DOS, and Mac platforms (it's from the ALS Prolog main).
717 || Ken Bowen Applied Logic Systems, Inc. PO Box 180,
718 ||==== Voice: +1 (617)965-9191 Newton Centre,
719 || FAX: +1 (617)965-1636 MA 02159 USA
720 Email: ken@als.com WWW: http://www.als.com
721 ------------------------------------------------------------------------
724 // This code is commented out but it may be integrated with wxWin at
725 // a later date, after testing. Thanks Ken!
728 /*--------------------------------------------------------------------*
729 | whereami is given a filename f in the form: whereami(argv[0])
730 | It returns the directory in which the executable file (containing
731 | this code [main.c] ) may be found. A dot will be returned to indicate
732 | the current directory.
733 *--------------------------------------------------------------------*/
739 register char *cutoff
= NULL
; /* stifle -Wall */
746 * See if the file is accessible either through the current directory
747 * or through an absolute path.
750 if (access(name
, R_OK
) == 0) {
752 /*-------------------------------------------------------------*
753 * The file was accessible without any other work. But the current
754 * working directory might change on us, so if it was accessible
755 * through the cwd, then we should get it for later accesses.
756 *-------------------------------------------------------------*/
759 if (!absolute_pathname(name
)) {
760 #if defined(__DOS__) || defined(__WIN32__)
766 if (*(name
+ 1) == ':') {
767 if (*name
>= 'a' && *name
<= 'z')
768 drive
= (int) (*name
- 'a' + 1);
770 drive
= (int) (*name
- 'A' + 1);
772 *newrbuf
++ = *(name
+ 1);
773 *newrbuf
++ = DIR_SEPARATOR
;
777 *newrbuf
++ = DIR_SEPARATOR
;
779 if (getcwd(newrbuf
, drive
) == 0) { /* } */
781 if (getcwd(newrbuf
, 1024) == 0) { /* } */
785 if (getwd(imagedir
) == 0) { /* } */
786 #else /* !HAVE_GETWD */
787 if (getcwd(imagedir
, 1024) == 0) {
788 #endif /* !HAVE_GETWD */
790 fatal_error(FE_GETCWD
, 0);
792 for (; *t
; t
++) /* Set t to end of buffer */
794 if (*(t
- 1) == DIR_SEPARATOR
) /* leave slash if already
799 cutoff
= t
; /* otherwise put one in */
800 *t
++ = DIR_SEPARATOR
;
803 #if (!defined(__MAC__) && !defined(__DJGPP__) && !defined(__GO32__) && !defined(__WIN32__))
805 (*t
++ = DIR_SEPARATOR
);
808 /*-------------------------------------------------------------*
809 * Copy the rest of the string and set the cutoff if it was not
810 * already set. If the first character of name is a slash, cutoff
811 * is not presently set but will be on the first iteration of the
813 *-------------------------------------------------------------*/
815 for ((*name
== DIR_SEPARATOR
? (s
= name
+1) : (s
= name
));;) {
816 if (*s
== DIR_SEPARATOR
)
825 /*-------------------------------------------------------------*
826 * Get the path list from the environment. If the path list is
827 * inaccessible for any reason, leave with fatal error.
828 *-------------------------------------------------------------*/
831 if ((s
= getenv("Commands")) == (char *) 0)
833 if ((s
= getenv("PATH")) == (char *) 0)
835 fatal_error(FE_PATH
, 0);
838 * Copy path list into ebuf and set the source pointer to the
839 * beginning of this buffer.
847 while (*s
&& *s
!= PATH_SEPARATOR
)
849 if (t
> imagedir
&& *(t
- 1) == DIR_SEPARATOR
)
850 ; /* do nothing -- slash already is in place */
852 *t
++ = DIR_SEPARATOR
; /* put in the slash */
853 cutoff
= t
- 1; /* set cutoff */
855 if (access(imagedir
, R_OK
) == 0)
859 s
++; /* advance source pointer */
861 fatal_error(FE_INFND
, 0);
866 /*-------------------------------------------------------------*
867 | At this point the full pathname should exist in imagedir and
868 | cutoff should be set to the final slash. We must now determine
869 | whether the file name is a symbolic link or not and chase it down
870 | if it is. Note that we reuse ebuf for getting the link.
871 *-------------------------------------------------------------*/
874 while ((cc
= readlink(imagedir
, ebuf
, 512)) != -1) {
877 if (*s
== DIR_SEPARATOR
) {
884 if (*s
== DIR_SEPARATOR
)
885 cutoff
= t
; /* mark the last slash seen */
886 if (!(*t
++ = *s
++)) /* copy the character */
891 #endif /* HAVE_SYMLINK */
893 strcpy(imagename
, cutoff
+ 1); /* keep the image name */
894 *(cutoff
+ 1) = 0; /* chop off the filename part */
901 // ----------------------------------------------------------------------------
903 // ----------------------------------------------------------------------------
906 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
907 * since otherwise the generic code may be pulled in unnecessarily.
912 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
913 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
915 wxMessageDialog
dialog(parent
, message
, caption
, style
);
917 int ans
= dialog
.ShowModal();
930 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
935 #endif // wxUSE_MSGDLG
939 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
940 const wxString
& defaultValue
, wxWindow
*parent
,
941 int x
, int y
, bool WXUNUSED(centre
) )
944 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, wxOK
|wxCANCEL
, wxPoint(x
, y
));
945 if (dialog
.ShowModal() == wxID_OK
)
947 str
= dialog
.GetValue();
953 wxString
wxGetPasswordFromUser(const wxString
& message
,
954 const wxString
& caption
,
955 const wxString
& defaultValue
,
959 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
960 wxOK
| wxCANCEL
| wxTE_PASSWORD
);
961 if ( dialog
.ShowModal() == wxID_OK
)
963 str
= dialog
.GetValue();
969 #endif // wxUSE_TEXTDLG
973 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
)
976 data
.SetChooseFull(TRUE
);
979 data
.SetColour((wxColour
&)colInit
); // const_cast
983 wxColourDialog
dialog(parent
, &data
);
984 if ( dialog
.ShowModal() == wxID_OK
)
986 colRet
= dialog
.GetColourData().GetColour();
988 //else: leave it invalid
993 #endif // wxUSE_COLOURDLG
997 wxFont
wxGetFontFromUser(wxWindow
*parent
, const wxFont
& fontInit
)
1000 if ( fontInit
.Ok() )
1002 data
.SetInitialFont(fontInit
);
1006 wxFontDialog
dialog(parent
, &data
);
1007 if ( dialog
.ShowModal() == wxID_OK
)
1009 fontRet
= dialog
.GetFontData().GetChosenFont();
1011 //else: leave it invalid
1016 #endif // wxUSE_FONTDLG
1017 // ----------------------------------------------------------------------------
1018 // missing C RTL functions (FIXME shouldn't be here at all)
1019 // ----------------------------------------------------------------------------
1022 #if __MSL__ < 0x7000
1023 char *strdup(const char *s
)
1025 return strcpy( (char*) malloc( strlen( s
) + 1 ) , s
) ;
1028 int isascii( int c
)
1030 return ( c
>= 0 && c
< 128 ) ;
1032 #endif // __MWERKS__
1034 // ----------------------------------------------------------------------------
1035 // wxSafeYield and supporting functions
1036 // ----------------------------------------------------------------------------
1038 void wxEnableTopLevelWindows(bool enable
)
1040 wxWindowList::Node
*node
;
1041 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1042 node
->GetData()->Enable(enable
);
1045 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
1047 // remember the top level windows which were already disabled, so that we
1048 // don't reenable them later
1049 m_winDisabled
= NULL
;
1051 wxWindowList::Node
*node
;
1052 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1054 wxWindow
*winTop
= node
->GetData();
1055 if ( winTop
== winToSkip
)
1058 if ( winTop
->IsEnabled() )
1064 if ( !m_winDisabled
)
1066 m_winDisabled
= new wxWindowList
;
1069 m_winDisabled
->Append(winTop
);
1074 wxWindowDisabler::~wxWindowDisabler()
1076 wxWindowList::Node
*node
;
1077 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1079 wxWindow
*winTop
= node
->GetData();
1080 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
1084 //else: had been already disabled, don't reenable
1087 delete m_winDisabled
;
1090 // Yield to other apps/messages and disable user input to all windows except
1092 bool wxSafeYield(wxWindow
*win
)
1094 wxWindowDisabler
wd(win
);
1096 bool rc
= wxYield();
1101 // ----------------------------------------------------------------------------
1103 // ----------------------------------------------------------------------------
1105 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1106 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1109 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1111 return TRUE
; // detectable auto-repeat is the only mode MSW supports
1117 const wxChar
*wxGetInstallPrefix()
1121 if ( wxGetEnv(wxT("WXPREFIX"), &prefix
) )
1122 return prefix
.c_str();
1124 #ifdef wxINSTALL_PREFIX
1125 return wxT(wxINSTALL_PREFIX
);
1131 wxString
wxGetDataDir()
1133 wxString format
= wxGetInstallPrefix();
1134 format
<< wxFILE_SEP_PATH
1135 << wxT("share") << wxFILE_SEP_PATH
1136 << wxT("wx") << wxFILE_SEP_PATH
1139 dir
.Printf(format
.c_str(), wxMAJOR_VERSION
, wxMINOR_VERSION
);
1144 // ----------------------------------------------------------------------------
1145 // network and user id functions
1146 // ----------------------------------------------------------------------------
1148 // Get Full RFC822 style email address
1149 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
1151 wxString email
= wxGetEmailAddress();
1155 wxStrncpy(address
, email
, maxSize
- 1);
1156 address
[maxSize
- 1] = wxT('\0');
1161 wxString
wxGetEmailAddress()
1165 wxString host
= wxGetFullHostName();
1168 wxString user
= wxGetUserId();
1171 email
<< user
<< wxT('@') << host
;
1178 wxString
wxGetUserId()
1180 static const int maxLoginLen
= 256; // FIXME arbitrary number
1183 bool ok
= wxGetUserId(buf
.GetWriteBuf(maxLoginLen
), maxLoginLen
);
1184 buf
.UngetWriteBuf();
1192 wxString
wxGetUserName()
1194 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
1197 bool ok
= wxGetUserName(buf
.GetWriteBuf(maxUserNameLen
), maxUserNameLen
);
1198 buf
.UngetWriteBuf();
1206 wxString
wxGetHostName()
1208 static const size_t hostnameSize
= 257;
1211 bool ok
= wxGetHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1213 buf
.UngetWriteBuf();
1221 wxString
wxGetFullHostName()
1223 static const size_t hostnameSize
= 257;
1226 bool ok
= wxGetFullHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1228 buf
.UngetWriteBuf();
1236 wxString
wxGetHomeDir()
1239 wxGetHomeDir(&home
);
1246 wxString
wxGetCurrentDir()
1253 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
1254 dir
.UngetWriteBuf();
1258 if ( errno
!= ERANGE
)
1260 wxLogSysError(_T("Failed to get current directory"));
1262 return wxEmptyString
;
1266 // buffer was too small, retry with a larger one
1278 // ----------------------------------------------------------------------------
1280 // ----------------------------------------------------------------------------
1282 // this is a private function because it hasn't a clean interface: the first
1283 // array is passed by reference, the second by pointer - instead we have 2
1284 // public versions of wxExecute() below
1285 static long wxDoExecuteWithCapture(const wxString
& command
,
1286 wxArrayString
& output
,
1287 wxArrayString
* error
)
1290 wxFAIL_MSG("Sorry, this version of wxExecute not implemented on WIN16.");
1294 // create a wxProcess which will capture the output
1295 wxProcess
*process
= new wxProcess
;
1296 process
->Redirect();
1298 long rc
= wxExecute(command
, TRUE
/* sync */, process
);
1303 wxInputStream
* is
= process
->GetInputStream();
1304 wxCHECK_MSG( is
, -1, _T("if wxExecute() succeded, stream can't be NULL") );
1305 wxTextInputStream
tis(*is
);
1307 wxTextInputStream
*tes
= NULL
;
1308 wxInputStream
*es
= NULL
;
1311 es
= process
->GetErrorStream();
1313 wxCHECK_MSG( es
, -1, _T("stderr can't be NULL") );
1315 tes
= new wxTextInputStream(*es
);
1323 if ( !is
->Eof() && is
->IsOk() )
1325 wxString line
= tis
.ReadLine();
1326 if ( is
->LastError() )
1334 if ( error
&& !es
->Eof() && es
->IsOk() )
1336 wxString line
= tes
->ReadLine();
1337 if ( es
->LastError() )
1349 #endif // wxUSE_STREAMS
1354 #endif // IO redirection supoprted
1357 long wxExecute(const wxString
& command
, wxArrayString
& output
)
1359 return wxDoExecuteWithCapture(command
, output
, NULL
);
1362 long wxExecute(const wxString
& command
,
1363 wxArrayString
& output
,
1364 wxArrayString
& error
)
1366 return wxDoExecuteWithCapture(command
, output
, &error
);
1369 // ----------------------------------------------------------------------------
1370 // wxApp::Yield() wrappers for backwards compatibility
1371 // ----------------------------------------------------------------------------
1376 return wxTheApp
&& wxTheApp
->Yield();
1382 bool wxYieldIfNeeded()
1385 return wxTheApp
&& wxTheApp
->Yield(TRUE
);