1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/utilscmn.cpp
3 // Purpose: Miscellaneous utility functions and classes
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/string.h"
35 #include "wx/window.h"
38 #include "wx/msgdlg.h"
39 #include "wx/textdlg.h"
40 #include "wx/textctrl.h" // for wxTE_PASSWORD
42 #include "wx/menuitem.h"
48 #include "wx/apptrait.h"
50 #include "wx/process.h"
51 #include "wx/txtstrm.h"
53 #include "wx/mimetype.h"
54 #include "wx/config.h"
56 #if defined(__WXWINCE__) && wxUSE_DATETIME
57 #include "wx/datetime.h"
65 #if !wxONLY_WATCOM_EARLIER_THAN(1,4)
66 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
72 #include "wx/colordlg.h"
73 #include "wx/fontdlg.h"
74 #include "wx/notebook.h"
75 #include "wx/statusbr.h"
81 #include "wx/msw/wince/time.h"
85 #include "wx/mac/private.h"
87 #include "InternetConfig.h"
91 #if !defined(__MWERKS__) && !defined(__WXWINCE__)
92 #include <sys/types.h>
96 #if defined(__WXMSW__)
97 #include "wx/msw/private.h"
98 #include "wx/msw/registry.h"
99 #include <shellapi.h> // needed for SHELLEXECUTEINFO
104 // ----------------------------------------------------------------------------
106 // ----------------------------------------------------------------------------
108 // ============================================================================
110 // ============================================================================
112 #if WXWIN_COMPATIBILITY_2_4
115 copystring (const wxChar
*s
)
117 if (s
== NULL
) s
= wxEmptyString
;
118 size_t len
= wxStrlen (s
) + 1;
120 wxChar
*news
= new wxChar
[len
];
121 memcpy (news
, s
, len
* sizeof(wxChar
)); // Should be the fastest
126 #endif // WXWIN_COMPATIBILITY_2_4
128 // ----------------------------------------------------------------------------
129 // String <-> Number conversions (deprecated)
130 // ----------------------------------------------------------------------------
132 #if WXWIN_COMPATIBILITY_2_4
134 WXDLLIMPEXP_DATA_BASE(const wxChar
*) wxFloatToStringStr
= wxT("%.2f");
135 WXDLLIMPEXP_DATA_BASE(const wxChar
*) wxDoubleToStringStr
= wxT("%.2f");
138 StringToFloat (const wxChar
*s
, float *number
)
140 if (s
&& *s
&& number
)
141 *number
= (float) wxStrtod (s
, (wxChar
**) NULL
);
145 StringToDouble (const wxChar
*s
, double *number
)
147 if (s
&& *s
&& number
)
148 *number
= wxStrtod (s
, (wxChar
**) NULL
);
152 FloatToString (float number
, const wxChar
*fmt
)
154 static wxChar buf
[256];
156 wxSprintf (buf
, fmt
, number
);
161 DoubleToString (double number
, const wxChar
*fmt
)
163 static wxChar buf
[256];
165 wxSprintf (buf
, fmt
, number
);
170 StringToInt (const wxChar
*s
, int *number
)
172 if (s
&& *s
&& number
)
173 *number
= (int) wxStrtol (s
, (wxChar
**) NULL
, 10);
177 StringToLong (const wxChar
*s
, long *number
)
179 if (s
&& *s
&& number
)
180 *number
= wxStrtol (s
, (wxChar
**) NULL
, 10);
184 IntToString (int number
)
186 static wxChar buf
[20];
188 wxSprintf (buf
, wxT("%d"), number
);
193 LongToString (long number
)
195 static wxChar buf
[20];
197 wxSprintf (buf
, wxT("%ld"), number
);
201 #endif // WXWIN_COMPATIBILITY_2_4
203 // Array used in DecToHex conversion routine.
204 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
206 // Convert 2-digit hex number to decimal
207 int wxHexToDec(const wxString
& buf
)
209 int firstDigit
, secondDigit
;
211 if (buf
.GetChar(0) >= wxT('A'))
212 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
214 firstDigit
= buf
.GetChar(0) - wxT('0');
216 if (buf
.GetChar(1) >= wxT('A'))
217 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
219 secondDigit
= buf
.GetChar(1) - wxT('0');
221 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
224 // Convert decimal integer to 2-character hex string
225 void wxDecToHex(int dec
, wxChar
*buf
)
227 int firstDigit
= (int)(dec
/16.0);
228 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
229 buf
[0] = hexArray
[firstDigit
];
230 buf
[1] = hexArray
[secondDigit
];
234 // Convert decimal integer to 2-character hex string
235 wxString
wxDecToHex(int dec
)
238 wxDecToHex(dec
, buf
);
239 return wxString(buf
);
242 // ----------------------------------------------------------------------------
244 // ----------------------------------------------------------------------------
246 // Return the current date/time
251 wxDateTime now
= wxDateTime::Now();
254 return wxEmptyString
;
257 time_t now
= time((time_t *) NULL
);
258 char *date
= ctime(&now
);
260 return wxString::FromAscii(date
);
264 void wxUsleep(unsigned long milliseconds
)
266 wxMilliSleep(milliseconds
);
269 const wxChar
*wxGetInstallPrefix()
273 if ( wxGetEnv(wxT("WXPREFIX"), &prefix
) )
274 return prefix
.c_str();
276 #ifdef wxINSTALL_PREFIX
277 return wxT(wxINSTALL_PREFIX
);
279 return wxEmptyString
;
283 wxString
wxGetDataDir()
285 wxString dir
= wxGetInstallPrefix();
286 dir
<< wxFILE_SEP_PATH
<< wxT("share") << wxFILE_SEP_PATH
<< wxT("wx");
290 bool wxIsPlatformLittleEndian()
292 // Are we little or big endian? This method is from Harbison & Steele.
296 char c
[sizeof(long)];
305 * Class to make it easier to specify platform-dependent values
308 wxArrayInt
* wxPlatform::sm_customPlatforms
= NULL
;
310 void wxPlatform::Copy(const wxPlatform
& platform
)
312 m_longValue
= platform
.m_longValue
;
313 m_doubleValue
= platform
.m_doubleValue
;
314 m_stringValue
= platform
.m_stringValue
;
317 wxPlatform
wxPlatform::If(int platform
, long value
)
320 return wxPlatform(value
);
325 wxPlatform
wxPlatform::IfNot(int platform
, long value
)
328 return wxPlatform(value
);
333 wxPlatform
& wxPlatform::ElseIf(int platform
, long value
)
340 wxPlatform
& wxPlatform::ElseIfNot(int platform
, long value
)
347 wxPlatform
wxPlatform::If(int platform
, double value
)
350 return wxPlatform(value
);
355 wxPlatform
wxPlatform::IfNot(int platform
, double value
)
358 return wxPlatform(value
);
363 wxPlatform
& wxPlatform::ElseIf(int platform
, double value
)
366 m_doubleValue
= value
;
370 wxPlatform
& wxPlatform::ElseIfNot(int platform
, double value
)
373 m_doubleValue
= value
;
377 wxPlatform
wxPlatform::If(int platform
, const wxString
& value
)
380 return wxPlatform(value
);
385 wxPlatform
wxPlatform::IfNot(int platform
, const wxString
& value
)
388 return wxPlatform(value
);
393 wxPlatform
& wxPlatform::ElseIf(int platform
, const wxString
& value
)
396 m_stringValue
= value
;
400 wxPlatform
& wxPlatform::ElseIfNot(int platform
, const wxString
& value
)
403 m_stringValue
= value
;
407 wxPlatform
& wxPlatform::Else(long value
)
413 wxPlatform
& wxPlatform::Else(double value
)
415 m_doubleValue
= value
;
419 wxPlatform
& wxPlatform::Else(const wxString
& value
)
421 m_stringValue
= value
;
425 void wxPlatform::AddPlatform(int platform
)
427 if (!sm_customPlatforms
)
428 sm_customPlatforms
= new wxArrayInt
;
429 sm_customPlatforms
->Add(platform
);
432 void wxPlatform::ClearPlatforms()
434 delete sm_customPlatforms
;
435 sm_customPlatforms
= NULL
;
438 /// Function for testing current platform
440 bool wxPlatform::Is(int platform
)
443 if (platform
== wxOS_WINDOWS
)
447 if (platform
== wxOS_WINDOWS_CE
)
453 // FIXME: wxWinPocketPC and wxWinSmartPhone are unknown symbols
455 #if defined(__WXWINCE__) && defined(__POCKETPC__)
456 if (platform
== wxWinPocketPC
)
459 #if defined(__WXWINCE__) && defined(__SMARTPHONE__)
460 if (platform
== wxWinSmartPhone
)
467 if (platform
== wxPORT_GTK
)
471 if (platform
== wxPORT_MAC
)
475 if (platform
== wxPORT_X11
)
479 if (platform
== wxOS_UNIX
)
483 if (platform
== wxPORT_MGL
)
487 if (platform
== wxOS_OS2
)
491 if (platform
== wxPORT_PM
)
495 if (platform
== wxPORT_MAC
)
499 if (sm_customPlatforms
&& sm_customPlatforms
->Index(platform
) != wxNOT_FOUND
)
505 // ----------------------------------------------------------------------------
506 // network and user id functions
507 // ----------------------------------------------------------------------------
509 // Get Full RFC822 style email address
510 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
512 wxString email
= wxGetEmailAddress();
516 wxStrncpy(address
, email
, maxSize
- 1);
517 address
[maxSize
- 1] = wxT('\0');
522 wxString
wxGetEmailAddress()
526 wxString host
= wxGetFullHostName();
529 wxString user
= wxGetUserId();
532 email
<< user
<< wxT('@') << host
;
539 wxString
wxGetUserId()
541 static const int maxLoginLen
= 256; // FIXME arbitrary number
544 bool ok
= wxGetUserId(wxStringBuffer(buf
, maxLoginLen
), maxLoginLen
);
552 wxString
wxGetUserName()
554 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
557 bool ok
= wxGetUserName(wxStringBuffer(buf
, maxUserNameLen
), maxUserNameLen
);
565 wxString
wxGetHostName()
567 static const size_t hostnameSize
= 257;
570 bool ok
= wxGetHostName(wxStringBuffer(buf
, hostnameSize
), hostnameSize
);
578 wxString
wxGetFullHostName()
580 static const size_t hostnameSize
= 257;
583 bool ok
= wxGetFullHostName(wxStringBuffer(buf
, hostnameSize
), hostnameSize
);
591 wxString
wxGetHomeDir()
601 wxString
wxGetCurrentDir()
608 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
613 if ( errno
!= ERANGE
)
615 wxLogSysError(_T("Failed to get current directory"));
617 return wxEmptyString
;
621 // buffer was too small, retry with a larger one
633 // ----------------------------------------------------------------------------
635 // ----------------------------------------------------------------------------
637 // wxDoExecuteWithCapture() helper: reads an entire stream into one array
639 // returns true if ok, false if error
641 static bool ReadAll(wxInputStream
*is
, wxArrayString
& output
)
643 wxCHECK_MSG( is
, false, _T("NULL stream in wxExecute()?") );
645 // the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state
648 wxTextInputStream
tis(*is
);
653 wxString line
= tis
.ReadLine();
669 #endif // wxUSE_STREAMS
671 // this is a private function because it hasn't a clean interface: the first
672 // array is passed by reference, the second by pointer - instead we have 2
673 // public versions of wxExecute() below
674 static long wxDoExecuteWithCapture(const wxString
& command
,
675 wxArrayString
& output
,
676 wxArrayString
* error
,
679 // create a wxProcess which will capture the output
680 wxProcess
*process
= new wxProcess
;
683 long rc
= wxExecute(command
, wxEXEC_SYNC
| flags
, process
);
688 if ( !ReadAll(process
->GetInputStream(), output
) )
693 if ( !ReadAll(process
->GetErrorStream(), *error
) )
701 #endif // wxUSE_STREAMS/!wxUSE_STREAMS
708 long wxExecute(const wxString
& command
, wxArrayString
& output
, int flags
)
710 return wxDoExecuteWithCapture(command
, output
, NULL
, flags
);
713 long wxExecute(const wxString
& command
,
714 wxArrayString
& output
,
715 wxArrayString
& error
,
718 return wxDoExecuteWithCapture(command
, output
, &error
, flags
);
721 // ----------------------------------------------------------------------------
722 // Launch default browser
723 // ----------------------------------------------------------------------------
725 bool wxLaunchDefaultBrowser(const wxString
& urlOrig
, int flags
)
729 // set the scheme of url to http if it does not have one
730 // RR: This doesn't work if the url is just a local path
731 wxString
url(urlOrig
);
733 if ( !uri
.HasScheme() )
734 url
.Prepend(wxT("http://"));
737 #if defined(__WXMSW__)
740 if ( flags
& wxBROWSER_NEW_WINDOW
)
742 // ShellExecuteEx() opens the URL in an existing window by default so
743 // we can't use it if we need a new window
744 wxRegKey
key(wxRegKey::HKCR
, uri
.GetScheme() + _T("\\shell\\open"));
747 // try default browser, it must be registered at least for http URLs
748 key
.SetName(wxRegKey::HKCR
, _T("http\\shell\\open"));
753 wxRegKey
keyDDE(key
, wxT("DDEExec"));
754 if ( keyDDE
.Exists() )
756 const wxString ddeTopic
= wxRegKey(keyDDE
, wxT("topic"));
758 // we only know the syntax of WWW_OpenURL DDE request for IE,
759 // optimistically assume that all other browsers are compatible
762 bool ok
= ddeTopic
== wxT("WWW_OpenURL");
765 ddeCmd
= keyDDE
.QueryDefaultValue();
766 ok
= !ddeCmd
.empty();
771 // for WWW_OpenURL, the index of the window to open the URL
772 // in is -1 (meaning "current") by default, replace it with
773 // 0 which means "new" (see KB article 160957)
774 ok
= ddeCmd
.Replace(wxT("-1"), wxT("0"),
775 false /* only first occurence */) == 1;
780 // and also replace the parameters: the topic should
781 // contain a placeholder for the URL
782 ok
= ddeCmd
.Replace(wxT("%1"), url
, false) == 1;
787 // try to send it the DDE request now but ignore the errors
790 const wxString ddeServer
= wxRegKey(keyDDE
, wxT("application"));
791 if ( wxExecuteDDE(ddeServer
, ddeTopic
, ddeCmd
) )
794 // this is not necessarily an error: maybe browser is
795 // simply not running, but no matter, in any case we're
796 // going to launch it using ShellExecuteEx() below now and
797 // we shouldn't try to open a new window if we open a new
805 WinStruct
<SHELLEXECUTEINFO
> sei
;
806 sei
.lpFile
= url
.c_str();
807 sei
.lpVerb
= _T("open");
808 sei
.nShow
= SW_SHOWNORMAL
;
810 ::ShellExecuteEx(&sei
);
812 const int nResult
= (int) sei
.hInstApp
;
814 // Firefox returns file not found for some reason, so make an exception
816 if ( nResult
> 32 || nResult
== SE_ERR_FNF
)
819 // Log something if SE_ERR_FNF happens
820 if ( nResult
== SE_ERR_FNF
)
821 wxLogDebug(wxT("SE_ERR_FNF from ShellExecute -- maybe FireFox?"));
822 #endif // __WXDEBUG__
825 #elif defined(__WXMAC__)
831 err
= ICStart(&inst
, 'STKA'); // put your app creator code here
835 err
= ICFindConfigFile(inst
, 0, NULL
);
839 ConstStr255Param hint
= 0;
841 endSel
= url
.length();
842 err
= ICLaunchURL(inst
, hint
, url
.fn_str(), endSel
, &startSel
, &endSel
);
844 wxLogDebug(wxT("ICLaunchURL error %d"), (int) err
);
851 wxLogDebug(wxT("ICStart error %d"), (int) err
);
855 // (non-Mac, non-MSW)
859 wxString desktop
= wxTheApp
->GetTraits()->GetDesktopEnvironment();
861 // GNOME and KDE desktops have some applications which should be always installed
862 // together with their main parts, which give us the
863 if (desktop
== wxT("GNOME"))
865 wxArrayString errors
;
866 wxArrayString output
;
868 // gconf will tell us the path of the application to use as browser
869 long res
= wxExecute( wxT("gconftool-2 --get /desktop/gnome/applications/browser/exec"),
870 output
, errors
, wxEXEC_NODISABLE
);
871 if (res
>= 0 && errors
.GetCount() == 0)
873 wxString cmd
= output
[0];
874 cmd
<< _T(' ') << url
;
879 else if (desktop
== wxT("KDE"))
881 // kfmclient directly opens the given URL
882 if (wxExecute(wxT("kfmclient openURL ") + url
))
891 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(_T("html"));
895 ft
->GetMimeType(&mt
);
897 ok
= ft
->GetOpenCommand(&cmd
, wxFileType::MessageParameters(url
));
900 #endif // wxUSE_MIMETYPE
902 if ( !ok
|| cmd
.empty() )
904 // fallback to checking for the BROWSER environment variable
905 cmd
= wxGetenv(wxT("BROWSER"));
907 cmd
<< _T(' ') << url
;
910 ok
= ( !cmd
.empty() && wxExecute(cmd
) );
914 // no file type for HTML extension
915 wxLogError(_T("No default application configured for HTML files."));
917 #endif // !wxUSE_MIMETYPE && !__WXMSW__
919 wxLogSysError(_T("Failed to open URL \"%s\" in default browser."),
925 // ----------------------------------------------------------------------------
926 // wxApp::Yield() wrappers for backwards compatibility
927 // ----------------------------------------------------------------------------
931 return wxTheApp
&& wxTheApp
->Yield();
934 bool wxYieldIfNeeded()
936 return wxTheApp
&& wxTheApp
->Yield(true);
941 // ============================================================================
942 // GUI-only functions from now on
943 // ============================================================================
948 static long wxCurrentId
= 100;
952 // skip the part of IDs space that contains hard-coded values:
953 if (wxCurrentId
== wxID_LOWEST
)
954 wxCurrentId
= wxID_HIGHEST
+ 1;
956 return wxCurrentId
++;
960 wxGetCurrentId(void) { return wxCurrentId
; }
963 wxRegisterId (long id
)
965 if (id
>= wxCurrentId
)
966 wxCurrentId
= id
+ 1;
969 // ----------------------------------------------------------------------------
970 // Menu accelerators related functions
971 // ----------------------------------------------------------------------------
973 wxChar
*wxStripMenuCodes(const wxChar
*in
, wxChar
*out
)
976 wxString s
= wxMenuItem::GetLabelFromText(in
);
979 wxString s
= wxStripMenuCodes(str
);
980 #endif // wxUSE_MENUS
983 // go smash their buffer if it's not big enough - I love char * params
984 memcpy(out
, s
.c_str(), s
.length() * sizeof(wxChar
));
988 // MYcopystring - for easier search...
989 out
= new wxChar
[s
.length() + 1];
990 wxStrcpy(out
, s
.c_str());
996 wxString
wxStripMenuCodes(const wxString
& in
, int flags
)
998 wxASSERT_MSG( flags
, _T("this is useless to call without any flags") );
1002 size_t len
= in
.length();
1005 for ( size_t n
= 0; n
< len
; n
++ )
1008 if ( (flags
& wxStrip_Mnemonics
) && ch
== _T('&') )
1010 // skip it, it is used to introduce the accel char (or to quote
1011 // itself in which case it should still be skipped): note that it
1012 // can't be the last character of the string
1015 wxLogDebug(_T("Invalid menu string '%s'"), in
.c_str());
1019 // use the next char instead
1023 else if ( (flags
& wxStrip_Accel
) && ch
== _T('\t') )
1025 // everything after TAB is accel string, exit the loop
1035 // ----------------------------------------------------------------------------
1036 // Window search functions
1037 // ----------------------------------------------------------------------------
1040 * If parent is non-NULL, look through children for a label or title
1041 * matching the specified string. If NULL, look through all top-level windows.
1046 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
1048 return wxWindow::FindWindowByLabel( title
, parent
);
1053 * If parent is non-NULL, look through children for a name
1054 * matching the specified string. If NULL, look through all top-level windows.
1059 wxFindWindowByName (const wxString
& name
, wxWindow
* parent
)
1061 return wxWindow::FindWindowByName( name
, parent
);
1064 // Returns menu item id or wxNOT_FOUND if none.
1066 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
1069 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
1071 return menuBar
->FindMenuItem (menuString
, itemString
);
1072 #endif // wxUSE_MENUS
1077 // Try to find the deepest child that contains 'pt'.
1078 // We go backwards, to try to allow for controls that are spacially
1079 // within other controls, but are still siblings (e.g. buttons within
1080 // static boxes). Static boxes are likely to be created _before_ controls
1081 // that sit inside them.
1082 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
1084 if (!win
->IsShown())
1087 // Hack for wxNotebook case: at least in wxGTK, all pages
1088 // claim to be shown, so we must only deal with the selected one.
1090 if (win
->IsKindOf(CLASSINFO(wxNotebook
)))
1092 wxNotebook
* nb
= (wxNotebook
*) win
;
1093 int sel
= nb
->GetSelection();
1096 wxWindow
* child
= nb
->GetPage(sel
);
1097 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
1104 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetLast();
1107 wxWindow
* child
= node
->GetData();
1108 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
1111 node
= node
->GetPrevious();
1114 wxPoint pos
= win
->GetPosition();
1115 wxSize sz
= win
->GetSize();
1116 if ( !win
->IsTopLevel() && win
->GetParent() )
1118 pos
= win
->GetParent()->ClientToScreen(pos
);
1121 wxRect
rect(pos
, sz
);
1122 if (rect
.Contains(pt
))
1128 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
1130 // Go backwards through the list since windows
1131 // on top are likely to have been appended most
1133 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetLast();
1136 wxWindow
* win
= node
->GetData();
1137 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
1140 node
= node
->GetPrevious();
1145 // ----------------------------------------------------------------------------
1147 // ----------------------------------------------------------------------------
1150 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
1151 * since otherwise the generic code may be pulled in unnecessarily.
1156 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
1157 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
1159 long decorated_style
= style
;
1161 if ( ( style
& ( wxICON_EXCLAMATION
| wxICON_HAND
| wxICON_INFORMATION
| wxICON_QUESTION
) ) == 0 )
1163 decorated_style
|= ( style
& wxYES
) ? wxICON_QUESTION
: wxICON_INFORMATION
;
1166 wxMessageDialog
dialog(parent
, message
, caption
, decorated_style
);
1168 int ans
= dialog
.ShowModal();
1181 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
1186 #endif // wxUSE_MSGDLG
1190 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
1191 const wxString
& defaultValue
, wxWindow
*parent
,
1192 wxCoord x
, wxCoord y
, bool centre
)
1195 long style
= wxTextEntryDialogStyle
;
1202 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, style
, wxPoint(x
, y
));
1204 if (dialog
.ShowModal() == wxID_OK
)
1206 str
= dialog
.GetValue();
1212 wxString
wxGetPasswordFromUser(const wxString
& message
,
1213 const wxString
& caption
,
1214 const wxString
& defaultValue
,
1216 wxCoord x
, wxCoord y
, bool centre
)
1219 long style
= wxTextEntryDialogStyle
;
1226 wxPasswordEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
1227 style
, wxPoint(x
, y
));
1228 if ( dialog
.ShowModal() == wxID_OK
)
1230 str
= dialog
.GetValue();
1236 #endif // wxUSE_TEXTDLG
1240 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
, const wxString
& caption
)
1243 data
.SetChooseFull(true);
1246 data
.SetColour((wxColour
&)colInit
); // const_cast
1250 wxColourDialog
dialog(parent
, &data
);
1251 if (!caption
.empty())
1252 dialog
.SetTitle(caption
);
1253 if ( dialog
.ShowModal() == wxID_OK
)
1255 colRet
= dialog
.GetColourData().GetColour();
1257 //else: leave it invalid
1262 #endif // wxUSE_COLOURDLG
1266 wxFont
wxGetFontFromUser(wxWindow
*parent
, const wxFont
& fontInit
, const wxString
& caption
)
1269 if ( fontInit
.Ok() )
1271 data
.SetInitialFont(fontInit
);
1275 wxFontDialog
dialog(parent
, data
);
1276 if (!caption
.empty())
1277 dialog
.SetTitle(caption
);
1278 if ( dialog
.ShowModal() == wxID_OK
)
1280 fontRet
= dialog
.GetFontData().GetChosenFont();
1282 //else: leave it invalid
1287 #endif // wxUSE_FONTDLG
1289 // ----------------------------------------------------------------------------
1290 // wxSafeYield and supporting functions
1291 // ----------------------------------------------------------------------------
1293 void wxEnableTopLevelWindows(bool enable
)
1295 wxWindowList::compatibility_iterator node
;
1296 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1297 node
->GetData()->Enable(enable
);
1300 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
1302 // remember the top level windows which were already disabled, so that we
1303 // don't reenable them later
1304 m_winDisabled
= NULL
;
1306 wxWindowList::compatibility_iterator node
;
1307 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1309 wxWindow
*winTop
= node
->GetData();
1310 if ( winTop
== winToSkip
)
1313 // we don't need to disable the hidden or already disabled windows
1314 if ( winTop
->IsEnabled() && winTop
->IsShown() )
1320 if ( !m_winDisabled
)
1322 m_winDisabled
= new wxWindowList
;
1325 m_winDisabled
->Append(winTop
);
1330 wxWindowDisabler::~wxWindowDisabler()
1332 wxWindowList::compatibility_iterator node
;
1333 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1335 wxWindow
*winTop
= node
->GetData();
1336 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
1340 //else: had been already disabled, don't reenable
1343 delete m_winDisabled
;
1346 // Yield to other apps/messages and disable user input to all windows except
1348 bool wxSafeYield(wxWindow
*win
, bool onlyIfNeeded
)
1350 wxWindowDisabler
wd(win
);
1354 rc
= wxYieldIfNeeded();
1361 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1362 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1365 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1367 return true; // detectable auto-repeat is the only mode MSW supports