]>
git.saurik.com Git - wxWidgets.git/blob - src/common/utilscmn.cpp
f563515d18e553ed91c1f40c5ac4031e1181efcc
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"
39 #include "wx/window.h"
42 #include "wx/msgdlg.h"
43 #include "wx/textdlg.h"
45 #include "wx/menuitem.h"
52 #include "wx/process.h"
53 #include "wx/txtstrm.h"
61 #if !defined(__WATCOMC__)
62 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
68 #include "wx/colordlg.h"
69 #include "wx/notebook.h"
71 #include "wx/statusbr.h"
72 #include "wx/toolbar.h"
78 #include <sys/types.h>
87 #include "wx/msw/private.h"
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
95 static wxWindow
*wxFindWindowByLabel1(const wxString
& title
, wxWindow
*parent
);
96 static wxWindow
*wxFindWindowByName1 (const wxString
& title
, wxWindow
*parent
);
99 // ============================================================================
101 // ============================================================================
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
108 int strcasecmp(const char *str_1
, const char *str_2
)
110 register char c1
, c2
;
112 c1
= tolower(*str_1
++);
113 c2
= tolower(*str_2
++);
114 } while ( c1
&& (c1
== c2
) );
119 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
122 register char c1
, c2
;
125 c1
= tolower(*str_1
++);
126 c2
= tolower(*str_2
++);
138 #if defined( __VMS__ ) && ( __VMS_VER < 70000000 )
139 // we have no strI functions under VMS, therefore I have implemented
140 // an inefficient but portable version: convert copies of strings to lowercase
141 // and then use the normal comparison
142 static void myLowerString(char *s
)
145 if(isalpha(*s
)) *s
= (char)tolower(*s
);
150 int strcasecmp(const char *str_1
, const char *str_2
)
152 char *temp1
= new char[strlen(str_1
)+1];
153 char *temp2
= new char[strlen(str_2
)+1];
156 myLowerString(temp1
);
157 myLowerString(temp2
);
159 int result
= wxStrcmp(temp1
,temp2
);
166 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
168 char *temp1
= new char[strlen(str_1
)+1];
169 char *temp2
= new char[strlen(str_2
)+1];
172 myLowerString(temp1
);
173 myLowerString(temp2
);
175 int result
= strncmp(temp1
,temp2
,maxchar
);
187 #define strcasecmp stricmp
188 #define strncasecmp strnicmp
190 #define strcasecmp _stricmp
191 #define strncasecmp _strnicmp
198 #define strcasecmp stricmp
199 #define strncasecmp strnicmp
202 // This declaration is missing in SunOS!
203 // (Yes, I know it is NOT ANSI-C but its in BSD libc)
204 #if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
207 int strcasecmp (const char *, const char *);
208 int strncasecmp (const char *, const char *, size_t);
211 #endif /* __WXMSW__ */
214 #define strcasecmp stricmp
215 #define strncasecmp strnicmp
219 copystring (const wxChar
*s
)
221 if (s
== NULL
) s
= wxT("");
222 size_t len
= wxStrlen (s
) + 1;
224 wxChar
*news
= new wxChar
[len
];
225 memcpy (news
, s
, len
* sizeof(wxChar
)); // Should be the fastest
231 static long wxCurrentId
= 100;
236 return wxCurrentId
++;
240 wxGetCurrentId(void) { return wxCurrentId
; }
243 wxRegisterId (long id
)
245 if (id
>= wxCurrentId
)
246 wxCurrentId
= id
+ 1;
250 StringToFloat (wxChar
*s
, float *number
)
252 if (s
&& *s
&& number
)
253 *number
= (float) wxStrtod (s
, (wxChar
**) NULL
);
257 StringToDouble (wxChar
*s
, double *number
)
259 if (s
&& *s
&& number
)
260 *number
= wxStrtod (s
, (wxChar
**) NULL
);
264 FloatToString (float number
, const wxChar
*fmt
)
266 static wxChar buf
[256];
268 // sprintf (buf, "%.2f", number);
269 wxSprintf (buf
, fmt
, number
);
274 DoubleToString (double number
, const wxChar
*fmt
)
276 static wxChar buf
[256];
278 wxSprintf (buf
, fmt
, number
);
283 StringToInt (wxChar
*s
, int *number
)
285 if (s
&& *s
&& number
)
286 *number
= (int) wxStrtol (s
, (wxChar
**) NULL
, 10);
290 StringToLong (wxChar
*s
, long *number
)
292 if (s
&& *s
&& number
)
293 *number
= wxStrtol (s
, (wxChar
**) NULL
, 10);
297 IntToString (int number
)
299 static wxChar buf
[20];
301 wxSprintf (buf
, wxT("%d"), number
);
306 LongToString (long number
)
308 static wxChar buf
[20];
310 wxSprintf (buf
, wxT("%ld"), number
);
314 // Array used in DecToHex conversion routine.
315 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
317 // Convert 2-digit hex number to decimal
318 int wxHexToDec(const wxString
& buf
)
320 int firstDigit
, secondDigit
;
322 if (buf
.GetChar(0) >= wxT('A'))
323 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
325 firstDigit
= buf
.GetChar(0) - wxT('0');
327 if (buf
.GetChar(1) >= wxT('A'))
328 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
330 secondDigit
= buf
.GetChar(1) - wxT('0');
332 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
335 // Convert decimal integer to 2-character hex string
336 void wxDecToHex(int dec
, wxChar
*buf
)
338 int firstDigit
= (int)(dec
/16.0);
339 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
340 buf
[0] = hexArray
[firstDigit
];
341 buf
[1] = hexArray
[secondDigit
];
345 // Convert decimal integer to 2-character hex string
346 wxString
wxDecToHex(int dec
)
349 wxDecToHex(dec
, buf
);
350 return wxString(buf
);
353 // Match a string INDEPENDENT OF CASE
355 StringMatch (char *str1
, char *str2
, bool subString
, bool exact
)
357 if (str1
== NULL
|| str2
== NULL
)
364 int len1
= strlen (str1
);
365 int len2
= strlen (str2
);
368 // Search for str1 in str2
369 // Slow .... but acceptable for short strings
370 for (i
= 0; i
<= len2
- len1
; i
++)
372 if (strncasecmp (str1
, str2
+ i
, len1
) == 0)
378 if (strcasecmp (str1
, str2
) == 0)
383 int len1
= strlen (str1
);
384 int len2
= strlen (str2
);
386 if (strncasecmp (str1
, str2
, wxMin (len1
, len2
)) == 0)
393 // Return the current date/time
397 time_t now
= time((time_t *) NULL
);
398 char *date
= ctime(&now
);
400 return wxString(date
);
405 // ----------------------------------------------------------------------------
406 // Menu accelerators related functions
407 // ----------------------------------------------------------------------------
409 wxChar
*wxStripMenuCodes (wxChar
*in
, wxChar
*out
)
412 return (wxChar
*) NULL
;
415 out
= copystring(in
);
417 wxChar
*tmpOut
= out
;
423 // Check && -> &, &x -> x
424 if (*++in
== wxT('&'))
427 else if (*in
== wxT('\t'))
429 // Remove all stuff after \t in X mode, and let the stuff as is
431 // Accelerators are handled in wx_item.cc for Motif, and are not
432 // YET supported in XView
444 wxString
wxStripMenuCodes(const wxString
& str
)
446 wxChar
*buf
= new wxChar
[str
.Length() + 1];
447 wxStripMenuCodes(WXSTRINGCAST str
, buf
);
455 // return wxAcceleratorEntry for the given menu string or NULL if none
457 wxAcceleratorEntry
*wxGetAccelFromString(const wxString
& label
)
459 // check for accelerators: they are given after '\t'
460 int posTab
= label
.Find(wxT('\t'));
461 if ( posTab
!= wxNOT_FOUND
) {
462 // parse the accelerator string
464 int accelFlags
= wxACCEL_NORMAL
;
466 for ( size_t n
= (size_t)posTab
+ 1; n
< label
.Len(); n
++ ) {
467 if ( (label
[n
] == '+') || (label
[n
] == '-') ) {
468 if ( current
== _("ctrl") )
469 accelFlags
|= wxACCEL_CTRL
;
470 else if ( current
== _("alt") )
471 accelFlags
|= wxACCEL_ALT
;
472 else if ( current
== _("shift") )
473 accelFlags
|= wxACCEL_SHIFT
;
475 wxLogDebug(wxT("Unknown accel modifier: '%s'"),
482 current
+= wxTolower(label
[n
]);
486 if ( current
.IsEmpty() ) {
487 wxLogDebug(wxT("No accel key found, accel string ignored."));
490 if ( current
.Len() == 1 ) {
492 keyCode
= wxToupper(current
[0U]);
495 // is it a function key?
496 if ( current
[0U] == 'f' && isdigit(current
[1U]) &&
497 (current
.Len() == 2 ||
498 (current
.Len() == 3 && isdigit(current
[2U]))) ) {
500 wxSscanf(current
.c_str() + 1, wxT("%d"), &n
);
502 keyCode
= WXK_F1
+ n
- 1;
505 // several special cases
507 if ( current
== wxT("DEL") ) {
508 keyCode
= WXK_DELETE
;
510 else if ( current
== wxT("DELETE") ) {
511 keyCode
= WXK_DELETE
;
513 else if ( current
== wxT("INS") ) {
514 keyCode
= WXK_INSERT
;
516 else if ( current
== wxT("INSERT") ) {
517 keyCode
= WXK_INSERT
;
520 else if ( current
== wxT("PGUP") ) {
523 else if ( current
== wxT("PGDN") ) {
529 wxLogDebug(wxT("Unrecognized accel key '%s', accel string ignored."),
537 // we do have something
538 return new wxAcceleratorEntry(accelFlags
, keyCode
);
542 return (wxAcceleratorEntry
*)NULL
;
545 #endif // wxUSE_ACCEL
547 // ----------------------------------------------------------------------------
548 // Window search functions
549 // ----------------------------------------------------------------------------
552 * If parent is non-NULL, look through children for a label or title
553 * matching the specified string. If NULL, look through all top-level windows.
558 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
562 return wxFindWindowByLabel1(title
, parent
);
566 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
568 node
= node
->GetNext() )
570 wxWindow
*win
= node
->GetData();
571 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
577 return (wxWindow
*) NULL
;
582 wxFindWindowByLabel1 (const wxString
& title
, wxWindow
* parent
)
586 if (parent
->GetLabel() == title
)
592 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
594 node
= node
->GetNext() )
596 wxWindow
*win
= (wxWindow
*)node
->GetData();
597 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
604 return (wxWindow
*) NULL
; // Not found
608 * If parent is non-NULL, look through children for a name
609 * matching the specified string. If NULL, look through all top-level windows.
614 wxFindWindowByName (const wxString
& title
, wxWindow
* parent
)
618 return wxFindWindowByName1 (title
, parent
);
622 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
624 node
= node
->GetNext() )
626 wxWindow
*win
= node
->GetData();
627 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
634 // Failed? Try by label instead.
635 return wxFindWindowByLabel(title
, parent
);
640 wxFindWindowByName1 (const wxString
& title
, wxWindow
* parent
)
644 if ( parent
->GetName() == title
)
650 for (wxNode
* node
= parent
->GetChildren().First (); node
; node
= node
->Next ())
652 wxWindow
*win
= (wxWindow
*) node
->Data ();
653 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
660 return (wxWindow
*) NULL
; // Not found
664 // Returns menu item id or -1 if none.
666 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
668 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
671 return menuBar
->FindMenuItem (menuString
, itemString
);
674 // Try to find the deepest child that contains 'pt'.
675 // We go backwards, to try to allow for controls that are spacially
676 // within other controls, but are still siblings (e.g. buttons within
677 // static boxes). Static boxes are likely to be created _before_ controls
678 // that sit inside them.
679 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
684 // Hack for wxNotebook case: at least in wxGTK, all pages
685 // claim to be shown, so we must only deal with the selected one.
686 if (win
->IsKindOf(CLASSINFO(wxNotebook
)))
688 wxNotebook
* nb
= (wxNotebook
*) win
;
689 int sel
= nb
->GetSelection();
692 wxWindow
* child
= nb
->GetPage(sel
);
693 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
700 else if (win->IsKindOf(CLASSINFO(wxFrame)))
702 // Pseudo-children that may not be mentioned in the child list
703 wxWindowList extraChildren;
704 wxFrame* frame = (wxFrame*) win;
705 if (frame->GetStatusBar())
706 extraChildren.Append(frame->GetStatusBar());
707 if (frame->GetToolBar())
708 extraChildren.Append(frame->GetToolBar());
710 wxNode* node = extraChildren.First();
713 wxWindow* child = (wxWindow*) node->Data();
714 wxWindow* foundWin = wxFindWindowAtPoint(child, pt);
722 wxNode
* node
= win
->GetChildren().Last();
725 wxWindow
* child
= (wxWindow
*) node
->Data();
726 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
729 node
= node
->Previous();
732 wxPoint pos
= win
->GetPosition();
733 wxSize sz
= win
->GetSize();
734 if (win
->GetParent())
736 pos
= win
->GetParent()->ClientToScreen(pos
);
739 wxRect
rect(pos
, sz
);
746 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
748 // Go backwards through the list since windows
749 // on top are likely to have been appended most
751 wxNode
* node
= wxTopLevelWindows
.Last();
754 wxWindow
* win
= (wxWindow
*) node
->Data();
755 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
758 node
= node
->Previous();
766 On Fri, 21 Jul 1995, Paul Craven wrote:
768 > Is there a way to find the path of running program's executable? I can get
769 > my home directory, and the current directory, but I don't know how to get the
770 > executable directory.
773 The code below (warty as it is), does what you want on most Unix,
774 DOS, and Mac platforms (it's from the ALS Prolog main).
776 || Ken Bowen Applied Logic Systems, Inc. PO Box 180,
777 ||==== Voice: +1 (617)965-9191 Newton Centre,
778 || FAX: +1 (617)965-1636 MA 02159 USA
779 Email: ken@als.com WWW: http://www.als.com
780 ------------------------------------------------------------------------
783 // This code is commented out but it may be integrated with wxWin at
784 // a later date, after testing. Thanks Ken!
787 /*--------------------------------------------------------------------*
788 | whereami is given a filename f in the form: whereami(argv[0])
789 | It returns the directory in which the executable file (containing
790 | this code [main.c] ) may be found. A dot will be returned to indicate
791 | the current directory.
792 *--------------------------------------------------------------------*/
798 register char *cutoff
= NULL
; /* stifle -Wall */
805 * See if the file is accessible either through the current directory
806 * or through an absolute path.
809 if (access(name
, R_OK
) == 0) {
811 /*-------------------------------------------------------------*
812 * The file was accessible without any other work. But the current
813 * working directory might change on us, so if it was accessible
814 * through the cwd, then we should get it for later accesses.
815 *-------------------------------------------------------------*/
818 if (!absolute_pathname(name
)) {
819 #if defined(DOS) || defined(__WIN32__)
825 if (*(name
+ 1) == ':') {
826 if (*name
>= 'a' && *name
<= 'z')
827 drive
= (int) (*name
- 'a' + 1);
829 drive
= (int) (*name
- 'A' + 1);
831 *newrbuf
++ = *(name
+ 1);
832 *newrbuf
++ = DIR_SEPARATOR
;
836 *newrbuf
++ = DIR_SEPARATOR
;
838 if (getcwd(newrbuf
, drive
) == 0) { /* } */
840 if (getcwd(newrbuf
, 1024) == 0) { /* } */
844 if (getwd(imagedir
) == 0) { /* } */
845 #else /* !HAVE_GETWD */
846 if (getcwd(imagedir
, 1024) == 0) {
847 #endif /* !HAVE_GETWD */
849 fatal_error(FE_GETCWD
, 0);
851 for (; *t
; t
++) /* Set t to end of buffer */
853 if (*(t
- 1) == DIR_SEPARATOR
) /* leave slash if already
858 cutoff
= t
; /* otherwise put one in */
859 *t
++ = DIR_SEPARATOR
;
862 #if (!defined(__MAC__) && !defined(__DJGPP__) && !defined(__GO32__) && !defined(__WIN32__))
864 (*t
++ = DIR_SEPARATOR
);
867 /*-------------------------------------------------------------*
868 * Copy the rest of the string and set the cutoff if it was not
869 * already set. If the first character of name is a slash, cutoff
870 * is not presently set but will be on the first iteration of the
872 *-------------------------------------------------------------*/
874 for ((*name
== DIR_SEPARATOR
? (s
= name
+1) : (s
= name
));;) {
875 if (*s
== DIR_SEPARATOR
)
884 /*-------------------------------------------------------------*
885 * Get the path list from the environment. If the path list is
886 * inaccessible for any reason, leave with fatal error.
887 *-------------------------------------------------------------*/
890 if ((s
= getenv("Commands")) == (char *) 0)
892 if ((s
= getenv("PATH")) == (char *) 0)
894 fatal_error(FE_PATH
, 0);
897 * Copy path list into ebuf and set the source pointer to the
898 * beginning of this buffer.
906 while (*s
&& *s
!= PATH_SEPARATOR
)
908 if (t
> imagedir
&& *(t
- 1) == DIR_SEPARATOR
)
909 ; /* do nothing -- slash already is in place */
911 *t
++ = DIR_SEPARATOR
; /* put in the slash */
912 cutoff
= t
- 1; /* set cutoff */
914 if (access(imagedir
, R_OK
) == 0)
918 s
++; /* advance source pointer */
920 fatal_error(FE_INFND
, 0);
925 /*-------------------------------------------------------------*
926 | At this point the full pathname should exist in imagedir and
927 | cutoff should be set to the final slash. We must now determine
928 | whether the file name is a symbolic link or not and chase it down
929 | if it is. Note that we reuse ebuf for getting the link.
930 *-------------------------------------------------------------*/
933 while ((cc
= readlink(imagedir
, ebuf
, 512)) != -1) {
936 if (*s
== DIR_SEPARATOR
) {
943 if (*s
== DIR_SEPARATOR
)
944 cutoff
= t
; /* mark the last slash seen */
945 if (!(*t
++ = *s
++)) /* copy the character */
950 #endif /* HAVE_SYMLINK */
952 strcpy(imagename
, cutoff
+ 1); /* keep the image name */
953 *(cutoff
+ 1) = 0; /* chop off the filename part */
960 // ----------------------------------------------------------------------------
962 // ----------------------------------------------------------------------------
965 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
966 * since otherwise the generic code may be pulled in unnecessarily.
969 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
970 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
972 wxMessageDialog
dialog(parent
, message
, caption
, style
);
974 int ans
= dialog
.ShowModal();
987 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
993 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
994 const wxString
& defaultValue
, wxWindow
*parent
,
995 int x
, int y
, bool WXUNUSED(centre
) )
998 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, wxOK
|wxCANCEL
, wxPoint(x
, y
));
999 if (dialog
.ShowModal() == wxID_OK
)
1001 str
= dialog
.GetValue();
1007 wxString
wxGetPasswordFromUser(const wxString
& message
,
1008 const wxString
& caption
,
1009 const wxString
& defaultValue
,
1013 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
1014 wxOK
| wxCANCEL
| wxTE_PASSWORD
);
1015 if ( dialog
.ShowModal() == wxID_OK
)
1017 str
= dialog
.GetValue();
1023 #endif // wxUSE_TEXTDLG
1025 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
)
1028 data
.SetChooseFull(TRUE
);
1031 data
.SetColour((wxColour
&)colInit
); // const_cast
1035 wxColourDialog
dialog(parent
, &data
);
1036 if ( dialog
.ShowModal() == wxID_OK
)
1038 colRet
= dialog
.GetColourData().GetColour();
1040 //else: leave it invalid
1045 // ----------------------------------------------------------------------------
1046 // missing C RTL functions (FIXME shouldn't be here at all)
1047 // ----------------------------------------------------------------------------
1050 char *strdup(const char *s
)
1052 return strcpy( (char*) malloc( strlen( s
) + 1 ) , s
) ;
1055 int isascii( int c
)
1057 return ( c
>= 0 && c
< 128 ) ;
1059 #endif // __MWERKS__
1061 // ----------------------------------------------------------------------------
1062 // wxSafeYield and supporting functions
1063 // ----------------------------------------------------------------------------
1065 void wxEnableTopLevelWindows(bool enable
)
1067 wxWindowList::Node
*node
;
1068 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1069 node
->GetData()->Enable(enable
);
1072 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
1074 // remember the top level windows which were already disabled, so that we
1075 // don't reenable them later
1076 m_winDisabled
= NULL
;
1078 wxWindowList::Node
*node
;
1079 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1081 wxWindow
*winTop
= node
->GetData();
1082 if ( winTop
== winToSkip
)
1085 if ( winTop
->IsEnabled() )
1091 if ( !m_winDisabled
)
1093 m_winDisabled
= new wxWindowList
;
1096 m_winDisabled
->Append(winTop
);
1101 wxWindowDisabler::~wxWindowDisabler()
1103 wxWindowList::Node
*node
;
1104 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1106 wxWindow
*winTop
= node
->GetData();
1107 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
1111 //else: had been already disabled, don't reenable
1114 delete m_winDisabled
;
1117 // Yield to other apps/messages and disable user input to all windows except
1119 bool wxSafeYield(wxWindow
*win
)
1121 wxWindowDisabler
wd(win
);
1123 bool rc
= wxYield();
1128 // ----------------------------------------------------------------------------
1130 // ----------------------------------------------------------------------------
1132 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1133 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1136 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1138 return TRUE
; // detectable auto-repeat is the only mode MSW supports
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
);