]>
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"
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))
64 // OS/2's App.h is being included first which includes nerrno.h
65 // so these are already defined. Undef them if defined before
94 #include "wx/colordlg.h"
95 #include "wx/notebook.h"
97 #include "wx/statusbr.h"
98 #include "wx/toolbar.h"
104 #include <sys/types.h>
105 #include <sys/stat.h>
113 #include "wx/msw/private.h"
116 // ----------------------------------------------------------------------------
117 // function protoypes
118 // ----------------------------------------------------------------------------
121 static wxWindow
*wxFindWindowByLabel1(const wxString
& title
, wxWindow
*parent
);
122 static wxWindow
*wxFindWindowByName1 (const wxString
& title
, wxWindow
*parent
);
125 // ============================================================================
127 // ============================================================================
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
134 int strcasecmp(const char *str_1
, const char *str_2
)
136 register char c1
, c2
;
138 c1
= tolower(*str_1
++);
139 c2
= tolower(*str_2
++);
140 } while ( c1
&& (c1
== c2
) );
145 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
148 register char c1
, c2
;
151 c1
= tolower(*str_1
++);
152 c2
= tolower(*str_2
++);
164 #if defined( __VMS__ ) && ( __VMS_VER < 70000000 )
165 // we have no strI functions under VMS, therefore I have implemented
166 // an inefficient but portable version: convert copies of strings to lowercase
167 // and then use the normal comparison
168 static void myLowerString(char *s
)
171 if(isalpha(*s
)) *s
= (char)tolower(*s
);
176 int strcasecmp(const char *str_1
, const char *str_2
)
178 char *temp1
= new char[strlen(str_1
)+1];
179 char *temp2
= new char[strlen(str_2
)+1];
182 myLowerString(temp1
);
183 myLowerString(temp2
);
185 int result
= wxStrcmp(temp1
,temp2
);
192 int strncasecmp(const char *str_1
, const char *str_2
, size_t maxchar
)
194 char *temp1
= new char[strlen(str_1
)+1];
195 char *temp2
= new char[strlen(str_2
)+1];
198 myLowerString(temp1
);
199 myLowerString(temp2
);
201 int result
= strncmp(temp1
,temp2
,maxchar
);
213 #define strcasecmp stricmp
214 #define strncasecmp strnicmp
216 #define strcasecmp _stricmp
217 #define strncasecmp _strnicmp
224 #define strcasecmp stricmp
225 #define strncasecmp strnicmp
228 // This declaration is missing in SunOS!
229 // (Yes, I know it is NOT ANSI-C but its in BSD libc)
230 #if defined(__xlC) || defined(__AIX__) || defined(__GNUG__)
233 int strcasecmp (const char *, const char *);
234 int strncasecmp (const char *, const char *, size_t);
237 #endif /* __WXMSW__ */
240 #define strcasecmp stricmp
241 #define strncasecmp strnicmp
245 copystring (const wxChar
*s
)
247 if (s
== NULL
) s
= wxT("");
248 size_t len
= wxStrlen (s
) + 1;
250 wxChar
*news
= new wxChar
[len
];
251 memcpy (news
, s
, len
* sizeof(wxChar
)); // Should be the fastest
257 static long wxCurrentId
= 100;
262 return wxCurrentId
++;
266 wxGetCurrentId(void) { return wxCurrentId
; }
269 wxRegisterId (long id
)
271 if (id
>= wxCurrentId
)
272 wxCurrentId
= id
+ 1;
276 StringToFloat (wxChar
*s
, float *number
)
278 if (s
&& *s
&& number
)
279 *number
= (float) wxStrtod (s
, (wxChar
**) NULL
);
283 StringToDouble (wxChar
*s
, double *number
)
285 if (s
&& *s
&& number
)
286 *number
= wxStrtod (s
, (wxChar
**) NULL
);
290 FloatToString (float number
, const wxChar
*fmt
)
292 static wxChar buf
[256];
294 // sprintf (buf, "%.2f", number);
295 wxSprintf (buf
, fmt
, number
);
300 DoubleToString (double number
, const wxChar
*fmt
)
302 static wxChar buf
[256];
304 wxSprintf (buf
, fmt
, number
);
309 StringToInt (wxChar
*s
, int *number
)
311 if (s
&& *s
&& number
)
312 *number
= (int) wxStrtol (s
, (wxChar
**) NULL
, 10);
316 StringToLong (wxChar
*s
, long *number
)
318 if (s
&& *s
&& number
)
319 *number
= wxStrtol (s
, (wxChar
**) NULL
, 10);
323 IntToString (int number
)
325 static wxChar buf
[20];
327 wxSprintf (buf
, wxT("%d"), number
);
332 LongToString (long number
)
334 static wxChar buf
[20];
336 wxSprintf (buf
, wxT("%ld"), number
);
340 // Array used in DecToHex conversion routine.
341 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
343 // Convert 2-digit hex number to decimal
344 int wxHexToDec(const wxString
& buf
)
346 int firstDigit
, secondDigit
;
348 if (buf
.GetChar(0) >= wxT('A'))
349 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
351 firstDigit
= buf
.GetChar(0) - wxT('0');
353 if (buf
.GetChar(1) >= wxT('A'))
354 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
356 secondDigit
= buf
.GetChar(1) - wxT('0');
358 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
361 // Convert decimal integer to 2-character hex string
362 void wxDecToHex(int dec
, wxChar
*buf
)
364 int firstDigit
= (int)(dec
/16.0);
365 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
366 buf
[0] = hexArray
[firstDigit
];
367 buf
[1] = hexArray
[secondDigit
];
371 // Convert decimal integer to 2-character hex string
372 wxString
wxDecToHex(int dec
)
375 wxDecToHex(dec
, buf
);
376 return wxString(buf
);
379 // Match a string INDEPENDENT OF CASE
381 StringMatch (char *str1
, char *str2
, bool subString
, bool exact
)
383 if (str1
== NULL
|| str2
== NULL
)
390 int len1
= strlen (str1
);
391 int len2
= strlen (str2
);
394 // Search for str1 in str2
395 // Slow .... but acceptable for short strings
396 for (i
= 0; i
<= len2
- len1
; i
++)
398 if (strncasecmp (str1
, str2
+ i
, len1
) == 0)
404 if (strcasecmp (str1
, str2
) == 0)
409 int len1
= strlen (str1
);
410 int len2
= strlen (str2
);
412 if (strncasecmp (str1
, str2
, wxMin (len1
, len2
)) == 0)
419 // Return the current date/time
423 time_t now
= time((time_t *) NULL
);
424 char *date
= ctime(&now
);
426 return wxString(date
);
431 // ----------------------------------------------------------------------------
432 // Menu accelerators related functions
433 // ----------------------------------------------------------------------------
435 wxChar
*wxStripMenuCodes (wxChar
*in
, wxChar
*out
)
438 return (wxChar
*) NULL
;
441 out
= copystring(in
);
443 wxChar
*tmpOut
= out
;
449 // Check && -> &, &x -> x
450 if (*++in
== wxT('&'))
453 else if (*in
== wxT('\t'))
455 // Remove all stuff after \t in X mode, and let the stuff as is
457 // Accelerators are handled in wx_item.cc for Motif, and are not
458 // YET supported in XView
470 wxString
wxStripMenuCodes(const wxString
& str
)
472 wxChar
*buf
= new wxChar
[str
.Length() + 1];
473 wxStripMenuCodes(WXSTRINGCAST str
, buf
);
481 // return wxAcceleratorEntry for the given menu string or NULL if none
483 wxAcceleratorEntry
*wxGetAccelFromString(const wxString
& label
)
485 // check for accelerators: they are given after '\t'
486 int posTab
= label
.Find(wxT('\t'));
487 if ( posTab
!= wxNOT_FOUND
) {
488 // parse the accelerator string
490 int accelFlags
= wxACCEL_NORMAL
;
492 for ( size_t n
= (size_t)posTab
+ 1; n
< label
.Len(); n
++ ) {
493 if ( (label
[n
] == '+') || (label
[n
] == '-') ) {
494 if ( current
== _("ctrl") )
495 accelFlags
|= wxACCEL_CTRL
;
496 else if ( current
== _("alt") )
497 accelFlags
|= wxACCEL_ALT
;
498 else if ( current
== _("shift") )
499 accelFlags
|= wxACCEL_SHIFT
;
501 wxLogDebug(wxT("Unknown accel modifier: '%s'"),
508 current
+= wxTolower(label
[n
]);
512 if ( current
.IsEmpty() ) {
513 wxLogDebug(wxT("No accel key found, accel string ignored."));
516 if ( current
.Len() == 1 ) {
518 keyCode
= wxToupper(current
[0U]);
521 // is it a function key?
522 if ( current
[0U] == 'f' && isdigit(current
[1U]) &&
523 (current
.Len() == 2 ||
524 (current
.Len() == 3 && isdigit(current
[2U]))) ) {
526 wxSscanf(current
.c_str() + 1, wxT("%d"), &n
);
528 keyCode
= WXK_F1
+ n
- 1;
531 // several special cases
533 if ( current
== _("DEL") ) {
534 keyCode
= WXK_DELETE
;
536 else if ( current
== _("DELETE") ) {
537 keyCode
= WXK_DELETE
;
539 else if ( current
== _("INS") ) {
540 keyCode
= WXK_INSERT
;
542 else if ( current
== _("INSERT") ) {
543 keyCode
= WXK_INSERT
;
546 else if ( current
== _("PGUP") ) {
549 else if ( current
== _("PGDN") ) {
555 wxLogDebug(wxT("Unrecognized accel key '%s', accel string ignored."),
563 // we do have something
564 return new wxAcceleratorEntry(accelFlags
, keyCode
);
568 return (wxAcceleratorEntry
*)NULL
;
571 #endif // wxUSE_ACCEL
573 // ----------------------------------------------------------------------------
574 // Window search functions
575 // ----------------------------------------------------------------------------
578 * If parent is non-NULL, look through children for a label or title
579 * matching the specified string. If NULL, look through all top-level windows.
584 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
588 return wxFindWindowByLabel1(title
, parent
);
592 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
594 node
= node
->GetNext() )
596 wxWindow
*win
= node
->GetData();
597 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
603 return (wxWindow
*) NULL
;
608 wxFindWindowByLabel1 (const wxString
& title
, wxWindow
* parent
)
612 if (parent
->GetLabel() == title
)
618 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
620 node
= node
->GetNext() )
622 wxWindow
*win
= (wxWindow
*)node
->GetData();
623 wxWindow
*retwin
= wxFindWindowByLabel1 (title
, win
);
630 return (wxWindow
*) NULL
; // Not found
634 * If parent is non-NULL, look through children for a name
635 * matching the specified string. If NULL, look through all top-level windows.
640 wxFindWindowByName (const wxString
& title
, wxWindow
* parent
)
644 return wxFindWindowByName1 (title
, parent
);
648 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
650 node
= node
->GetNext() )
652 wxWindow
*win
= node
->GetData();
653 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
660 // Failed? Try by label instead.
661 return wxFindWindowByLabel(title
, parent
);
666 wxFindWindowByName1 (const wxString
& title
, wxWindow
* parent
)
670 if ( parent
->GetName() == title
)
676 for (wxNode
* node
= parent
->GetChildren().First (); node
; node
= node
->Next ())
678 wxWindow
*win
= (wxWindow
*) node
->Data ();
679 wxWindow
*retwin
= wxFindWindowByName1 (title
, win
);
686 return (wxWindow
*) NULL
; // Not found
690 // Returns menu item id or -1 if none.
692 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
694 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
697 return menuBar
->FindMenuItem (menuString
, itemString
);
700 // Try to find the deepest child that contains 'pt'.
701 // We go backwards, to try to allow for controls that are spacially
702 // within other controls, but are still siblings (e.g. buttons within
703 // static boxes). Static boxes are likely to be created _before_ controls
704 // that sit inside them.
705 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
710 // Hack for wxNotebook case: at least in wxGTK, all pages
711 // claim to be shown, so we must only deal with the selected one.
712 if (win
->IsKindOf(CLASSINFO(wxNotebook
)))
714 wxNotebook
* nb
= (wxNotebook
*) win
;
715 int sel
= nb
->GetSelection();
718 wxWindow
* child
= nb
->GetPage(sel
);
719 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
726 else if (win->IsKindOf(CLASSINFO(wxFrame)))
728 // Pseudo-children that may not be mentioned in the child list
729 wxWindowList extraChildren;
730 wxFrame* frame = (wxFrame*) win;
731 if (frame->GetStatusBar())
732 extraChildren.Append(frame->GetStatusBar());
733 if (frame->GetToolBar())
734 extraChildren.Append(frame->GetToolBar());
736 wxNode* node = extraChildren.First();
739 wxWindow* child = (wxWindow*) node->Data();
740 wxWindow* foundWin = wxFindWindowAtPoint(child, pt);
748 wxNode
* node
= win
->GetChildren().Last();
751 wxWindow
* child
= (wxWindow
*) node
->Data();
752 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
755 node
= node
->Previous();
758 wxPoint pos
= win
->GetPosition();
759 wxSize sz
= win
->GetSize();
760 if (win
->GetParent())
762 pos
= win
->GetParent()->ClientToScreen(pos
);
765 wxRect
rect(pos
, sz
);
772 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
774 // Go backwards through the list since windows
775 // on top are likely to have been appended most
777 wxNode
* node
= wxTopLevelWindows
.Last();
780 wxWindow
* win
= (wxWindow
*) node
->Data();
781 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
784 node
= node
->Previous();
792 On Fri, 21 Jul 1995, Paul Craven wrote:
794 > Is there a way to find the path of running program's executable? I can get
795 > my home directory, and the current directory, but I don't know how to get the
796 > executable directory.
799 The code below (warty as it is), does what you want on most Unix,
800 DOS, and Mac platforms (it's from the ALS Prolog main).
802 || Ken Bowen Applied Logic Systems, Inc. PO Box 180,
803 ||==== Voice: +1 (617)965-9191 Newton Centre,
804 || FAX: +1 (617)965-1636 MA 02159 USA
805 Email: ken@als.com WWW: http://www.als.com
806 ------------------------------------------------------------------------
809 // This code is commented out but it may be integrated with wxWin at
810 // a later date, after testing. Thanks Ken!
813 /*--------------------------------------------------------------------*
814 | whereami is given a filename f in the form: whereami(argv[0])
815 | It returns the directory in which the executable file (containing
816 | this code [main.c] ) may be found. A dot will be returned to indicate
817 | the current directory.
818 *--------------------------------------------------------------------*/
824 register char *cutoff
= NULL
; /* stifle -Wall */
831 * See if the file is accessible either through the current directory
832 * or through an absolute path.
835 if (access(name
, R_OK
) == 0) {
837 /*-------------------------------------------------------------*
838 * The file was accessible without any other work. But the current
839 * working directory might change on us, so if it was accessible
840 * through the cwd, then we should get it for later accesses.
841 *-------------------------------------------------------------*/
844 if (!absolute_pathname(name
)) {
845 #if defined(DOS) || defined(__WIN32__)
851 if (*(name
+ 1) == ':') {
852 if (*name
>= 'a' && *name
<= 'z')
853 drive
= (int) (*name
- 'a' + 1);
855 drive
= (int) (*name
- 'A' + 1);
857 *newrbuf
++ = *(name
+ 1);
858 *newrbuf
++ = DIR_SEPARATOR
;
862 *newrbuf
++ = DIR_SEPARATOR
;
864 if (getcwd(newrbuf
, drive
) == 0) { /* } */
866 if (getcwd(newrbuf
, 1024) == 0) { /* } */
870 if (getwd(imagedir
) == 0) { /* } */
871 #else /* !HAVE_GETWD */
872 if (getcwd(imagedir
, 1024) == 0) {
873 #endif /* !HAVE_GETWD */
875 fatal_error(FE_GETCWD
, 0);
877 for (; *t
; t
++) /* Set t to end of buffer */
879 if (*(t
- 1) == DIR_SEPARATOR
) /* leave slash if already
884 cutoff
= t
; /* otherwise put one in */
885 *t
++ = DIR_SEPARATOR
;
888 #if (!defined(__MAC__) && !defined(__DJGPP__) && !defined(__GO32__) && !defined(__WIN32__))
890 (*t
++ = DIR_SEPARATOR
);
893 /*-------------------------------------------------------------*
894 * Copy the rest of the string and set the cutoff if it was not
895 * already set. If the first character of name is a slash, cutoff
896 * is not presently set but will be on the first iteration of the
898 *-------------------------------------------------------------*/
900 for ((*name
== DIR_SEPARATOR
? (s
= name
+1) : (s
= name
));;) {
901 if (*s
== DIR_SEPARATOR
)
910 /*-------------------------------------------------------------*
911 * Get the path list from the environment. If the path list is
912 * inaccessible for any reason, leave with fatal error.
913 *-------------------------------------------------------------*/
916 if ((s
= getenv("Commands")) == (char *) 0)
918 if ((s
= getenv("PATH")) == (char *) 0)
920 fatal_error(FE_PATH
, 0);
923 * Copy path list into ebuf and set the source pointer to the
924 * beginning of this buffer.
932 while (*s
&& *s
!= PATH_SEPARATOR
)
934 if (t
> imagedir
&& *(t
- 1) == DIR_SEPARATOR
)
935 ; /* do nothing -- slash already is in place */
937 *t
++ = DIR_SEPARATOR
; /* put in the slash */
938 cutoff
= t
- 1; /* set cutoff */
940 if (access(imagedir
, R_OK
) == 0)
944 s
++; /* advance source pointer */
946 fatal_error(FE_INFND
, 0);
951 /*-------------------------------------------------------------*
952 | At this point the full pathname should exist in imagedir and
953 | cutoff should be set to the final slash. We must now determine
954 | whether the file name is a symbolic link or not and chase it down
955 | if it is. Note that we reuse ebuf for getting the link.
956 *-------------------------------------------------------------*/
959 while ((cc
= readlink(imagedir
, ebuf
, 512)) != -1) {
962 if (*s
== DIR_SEPARATOR
) {
969 if (*s
== DIR_SEPARATOR
)
970 cutoff
= t
; /* mark the last slash seen */
971 if (!(*t
++ = *s
++)) /* copy the character */
976 #endif /* HAVE_SYMLINK */
978 strcpy(imagename
, cutoff
+ 1); /* keep the image name */
979 *(cutoff
+ 1) = 0; /* chop off the filename part */
986 // ----------------------------------------------------------------------------
988 // ----------------------------------------------------------------------------
991 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
992 * since otherwise the generic code may be pulled in unnecessarily.
995 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
996 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
998 wxMessageDialog
dialog(parent
, message
, caption
, style
);
1000 int ans
= dialog
.ShowModal();
1013 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
1019 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
1020 const wxString
& defaultValue
, wxWindow
*parent
,
1021 int x
, int y
, bool WXUNUSED(centre
) )
1024 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, wxOK
|wxCANCEL
, wxPoint(x
, y
));
1025 if (dialog
.ShowModal() == wxID_OK
)
1027 str
= dialog
.GetValue();
1033 wxString
wxGetPasswordFromUser(const wxString
& message
,
1034 const wxString
& caption
,
1035 const wxString
& defaultValue
,
1039 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
1040 wxOK
| wxCANCEL
| wxTE_PASSWORD
);
1041 if ( dialog
.ShowModal() == wxID_OK
)
1043 str
= dialog
.GetValue();
1049 #endif // wxUSE_TEXTDLG
1051 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
)
1054 data
.SetChooseFull(TRUE
);
1057 data
.SetColour((wxColour
&)colInit
); // const_cast
1061 wxColourDialog
dialog(parent
, &data
);
1062 if ( dialog
.ShowModal() == wxID_OK
)
1064 colRet
= dialog
.GetColourData().GetColour();
1066 //else: leave it invalid
1071 // ----------------------------------------------------------------------------
1072 // missing C RTL functions (FIXME shouldn't be here at all)
1073 // ----------------------------------------------------------------------------
1076 char *strdup(const char *s
)
1078 return strcpy( (char*) malloc( strlen( s
) + 1 ) , s
) ;
1081 int isascii( int c
)
1083 return ( c
>= 0 && c
< 128 ) ;
1085 #endif // __MWERKS__
1087 // ----------------------------------------------------------------------------
1088 // wxSafeYield and supporting functions
1089 // ----------------------------------------------------------------------------
1091 void wxEnableTopLevelWindows(bool enable
)
1093 wxWindowList::Node
*node
;
1094 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1095 node
->GetData()->Enable(enable
);
1098 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
1100 // remember the top level windows which were already disabled, so that we
1101 // don't reenable them later
1102 m_winDisabled
= NULL
;
1104 wxWindowList::Node
*node
;
1105 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1107 wxWindow
*winTop
= node
->GetData();
1108 if ( winTop
== winToSkip
)
1111 if ( winTop
->IsEnabled() )
1117 if ( !m_winDisabled
)
1119 m_winDisabled
= new wxWindowList
;
1122 m_winDisabled
->Append(winTop
);
1127 wxWindowDisabler::~wxWindowDisabler()
1129 wxWindowList::Node
*node
;
1130 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1132 wxWindow
*winTop
= node
->GetData();
1133 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
1137 //else: had been already disabled, don't reenable
1140 delete m_winDisabled
;
1143 // Yield to other apps/messages and disable user input to all windows except
1145 bool wxSafeYield(wxWindow
*win
)
1147 wxWindowDisabler
wd(win
);
1149 bool rc
= wxYield();
1154 // ----------------------------------------------------------------------------
1156 // ----------------------------------------------------------------------------
1158 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1159 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1162 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1164 return TRUE
; // detectable auto-repeat is the only mode MSW supports
1170 // ----------------------------------------------------------------------------
1171 // network and user id functions
1172 // ----------------------------------------------------------------------------
1174 // Get Full RFC822 style email address
1175 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
1177 wxString email
= wxGetEmailAddress();
1181 wxStrncpy(address
, email
, maxSize
- 1);
1182 address
[maxSize
- 1] = wxT('\0');
1187 wxString
wxGetEmailAddress()
1191 wxString host
= wxGetFullHostName();
1194 wxString user
= wxGetUserId();
1197 email
<< user
<< wxT('@') << host
;
1204 wxString
wxGetUserId()
1206 static const int maxLoginLen
= 256; // FIXME arbitrary number
1209 bool ok
= wxGetUserId(buf
.GetWriteBuf(maxLoginLen
), maxLoginLen
);
1210 buf
.UngetWriteBuf();
1218 wxString
wxGetUserName()
1220 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
1223 bool ok
= wxGetUserName(buf
.GetWriteBuf(maxUserNameLen
), maxUserNameLen
);
1224 buf
.UngetWriteBuf();
1232 wxString
wxGetHostName()
1234 static const size_t hostnameSize
= 257;
1237 bool ok
= wxGetHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1239 buf
.UngetWriteBuf();
1247 wxString
wxGetFullHostName()
1249 static const size_t hostnameSize
= 257;
1252 bool ok
= wxGetFullHostName(buf
.GetWriteBuf(hostnameSize
), hostnameSize
);
1254 buf
.UngetWriteBuf();
1262 wxString
wxGetHomeDir()
1265 wxGetHomeDir(&home
);
1272 wxString
wxGetCurrentDir()
1279 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
1280 dir
.UngetWriteBuf();
1284 if ( errno
!= ERANGE
)
1286 wxLogSysError(_T("Failed to get current directory"));
1288 return wxEmptyString
;
1292 // buffer was too small, retry with a larger one
1304 // ----------------------------------------------------------------------------
1306 // ----------------------------------------------------------------------------
1308 // this is a private function because it hasn't a clean interface: the first
1309 // array is passed by reference, the second by pointer - instead we have 2
1310 // public versions of wxExecute() below
1311 static long wxDoExecuteWithCapture(const wxString
& command
,
1312 wxArrayString
& output
,
1313 wxArrayString
* error
)
1316 wxFAIL_MSG("Sorry, this version of wxExecute not implemented on WIN16.");
1320 // create a wxProcess which will capture the output
1321 wxProcess
*process
= new wxProcess
;
1322 process
->Redirect();
1324 long rc
= wxExecute(command
, TRUE
/* sync */, process
);
1329 wxInputStream
* is
= process
->GetInputStream();
1330 wxCHECK_MSG( is
, -1, _T("if wxExecute() succeded, stream can't be NULL") );
1331 wxTextInputStream
tis(*is
);
1333 wxTextInputStream
*tes
= NULL
;
1334 wxInputStream
*es
= NULL
;
1337 es
= process
->GetErrorStream();
1339 wxCHECK_MSG( es
, -1, _T("stderr can't be NULL") );
1341 tes
= new wxTextInputStream(*es
);
1349 if ( !is
->Eof() && is
->IsOk() )
1351 wxString line
= tis
.ReadLine();
1352 if ( is
->LastError() )
1360 if ( error
&& !es
->Eof() && es
->IsOk() )
1362 wxString line
= tes
->ReadLine();
1363 if ( es
->LastError() )
1375 #endif // wxUSE_STREAMS
1380 #endif // IO redirection supoprted
1383 long wxExecute(const wxString
& command
, wxArrayString
& output
)
1385 return wxDoExecuteWithCapture(command
, output
, NULL
);
1388 long wxExecute(const wxString
& command
,
1389 wxArrayString
& output
,
1390 wxArrayString
& error
)
1392 return wxDoExecuteWithCapture(command
, output
, &error
);