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 // Array used in DecToHex conversion routine.
113 static wxChar hexArray
[] = wxT("0123456789ABCDEF");
115 // Convert 2-digit hex number to decimal
116 int wxHexToDec(const wxString
& buf
)
118 int firstDigit
, secondDigit
;
120 if (buf
.GetChar(0) >= wxT('A'))
121 firstDigit
= buf
.GetChar(0) - wxT('A') + 10;
123 firstDigit
= buf
.GetChar(0) - wxT('0');
125 if (buf
.GetChar(1) >= wxT('A'))
126 secondDigit
= buf
.GetChar(1) - wxT('A') + 10;
128 secondDigit
= buf
.GetChar(1) - wxT('0');
130 return (firstDigit
& 0xF) * 16 + (secondDigit
& 0xF );
133 // Convert decimal integer to 2-character hex string
134 void wxDecToHex(int dec
, wxChar
*buf
)
136 int firstDigit
= (int)(dec
/16.0);
137 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
138 buf
[0] = hexArray
[firstDigit
];
139 buf
[1] = hexArray
[secondDigit
];
143 // Convert decimal integer to 2 characters
144 void wxDecToHex(int dec
, char* ch1
, char* ch2
)
146 int firstDigit
= (int)(dec
/16.0);
147 int secondDigit
= (int)(dec
- (firstDigit
*16.0));
148 (*ch1
) = (char) hexArray
[firstDigit
];
149 (*ch2
) = (char) hexArray
[secondDigit
];
152 // Convert decimal integer to 2-character hex string
153 wxString
wxDecToHex(int dec
)
156 wxDecToHex(dec
, buf
);
157 return wxString(buf
);
160 // ----------------------------------------------------------------------------
162 // ----------------------------------------------------------------------------
164 // Return the current date/time
169 wxDateTime now
= wxDateTime::Now();
172 return wxEmptyString
;
175 time_t now
= time((time_t *) NULL
);
176 char *date
= ctime(&now
);
178 return wxString::FromAscii(date
);
182 void wxUsleep(unsigned long milliseconds
)
184 wxMilliSleep(milliseconds
);
187 const wxChar
*wxGetInstallPrefix()
191 if ( wxGetEnv(wxT("WXPREFIX"), &prefix
) )
192 return prefix
.c_str();
194 #ifdef wxINSTALL_PREFIX
195 return wxT(wxINSTALL_PREFIX
);
197 return wxEmptyString
;
201 wxString
wxGetDataDir()
203 wxString dir
= wxGetInstallPrefix();
204 dir
<< wxFILE_SEP_PATH
<< wxT("share") << wxFILE_SEP_PATH
<< wxT("wx");
208 bool wxIsPlatformLittleEndian()
210 // Are we little or big endian? This method is from Harbison & Steele.
214 char c
[sizeof(long)];
223 * Class to make it easier to specify platform-dependent values
226 wxArrayInt
* wxPlatform::sm_customPlatforms
= NULL
;
228 void wxPlatform::Copy(const wxPlatform
& platform
)
230 m_longValue
= platform
.m_longValue
;
231 m_doubleValue
= platform
.m_doubleValue
;
232 m_stringValue
= platform
.m_stringValue
;
235 wxPlatform
wxPlatform::If(int platform
, long value
)
238 return wxPlatform(value
);
243 wxPlatform
wxPlatform::IfNot(int platform
, long value
)
246 return wxPlatform(value
);
251 wxPlatform
& wxPlatform::ElseIf(int platform
, long value
)
258 wxPlatform
& wxPlatform::ElseIfNot(int platform
, long value
)
265 wxPlatform
wxPlatform::If(int platform
, double value
)
268 return wxPlatform(value
);
273 wxPlatform
wxPlatform::IfNot(int platform
, double value
)
276 return wxPlatform(value
);
281 wxPlatform
& wxPlatform::ElseIf(int platform
, double value
)
284 m_doubleValue
= value
;
288 wxPlatform
& wxPlatform::ElseIfNot(int platform
, double value
)
291 m_doubleValue
= value
;
295 wxPlatform
wxPlatform::If(int platform
, const wxString
& value
)
298 return wxPlatform(value
);
303 wxPlatform
wxPlatform::IfNot(int platform
, const wxString
& value
)
306 return wxPlatform(value
);
311 wxPlatform
& wxPlatform::ElseIf(int platform
, const wxString
& value
)
314 m_stringValue
= value
;
318 wxPlatform
& wxPlatform::ElseIfNot(int platform
, const wxString
& value
)
321 m_stringValue
= value
;
325 wxPlatform
& wxPlatform::Else(long value
)
331 wxPlatform
& wxPlatform::Else(double value
)
333 m_doubleValue
= value
;
337 wxPlatform
& wxPlatform::Else(const wxString
& value
)
339 m_stringValue
= value
;
343 void wxPlatform::AddPlatform(int platform
)
345 if (!sm_customPlatforms
)
346 sm_customPlatforms
= new wxArrayInt
;
347 sm_customPlatforms
->Add(platform
);
350 void wxPlatform::ClearPlatforms()
352 delete sm_customPlatforms
;
353 sm_customPlatforms
= NULL
;
356 /// Function for testing current platform
358 bool wxPlatform::Is(int platform
)
361 if (platform
== wxOS_WINDOWS
)
365 if (platform
== wxOS_WINDOWS_CE
)
371 // FIXME: wxWinPocketPC and wxWinSmartPhone are unknown symbols
373 #if defined(__WXWINCE__) && defined(__POCKETPC__)
374 if (platform
== wxWinPocketPC
)
377 #if defined(__WXWINCE__) && defined(__SMARTPHONE__)
378 if (platform
== wxWinSmartPhone
)
385 if (platform
== wxPORT_GTK
)
389 if (platform
== wxPORT_MAC
)
393 if (platform
== wxPORT_X11
)
397 if (platform
== wxOS_UNIX
)
401 if (platform
== wxPORT_MGL
)
405 if (platform
== wxOS_OS2
)
409 if (platform
== wxPORT_PM
)
413 if (platform
== wxPORT_MAC
)
417 if (sm_customPlatforms
&& sm_customPlatforms
->Index(platform
) != wxNOT_FOUND
)
423 // ----------------------------------------------------------------------------
424 // network and user id functions
425 // ----------------------------------------------------------------------------
427 // Get Full RFC822 style email address
428 bool wxGetEmailAddress(wxChar
*address
, int maxSize
)
430 wxString email
= wxGetEmailAddress();
434 wxStrncpy(address
, email
, maxSize
- 1);
435 address
[maxSize
- 1] = wxT('\0');
440 wxString
wxGetEmailAddress()
444 wxString host
= wxGetFullHostName();
447 wxString user
= wxGetUserId();
450 email
<< user
<< wxT('@') << host
;
457 wxString
wxGetUserId()
459 static const int maxLoginLen
= 256; // FIXME arbitrary number
462 bool ok
= wxGetUserId(wxStringBuffer(buf
, maxLoginLen
), maxLoginLen
);
470 wxString
wxGetUserName()
472 static const int maxUserNameLen
= 1024; // FIXME arbitrary number
475 bool ok
= wxGetUserName(wxStringBuffer(buf
, maxUserNameLen
), maxUserNameLen
);
483 wxString
wxGetHostName()
485 static const size_t hostnameSize
= 257;
488 bool ok
= wxGetHostName(wxStringBuffer(buf
, hostnameSize
), hostnameSize
);
496 wxString
wxGetFullHostName()
498 static const size_t hostnameSize
= 257;
501 bool ok
= wxGetFullHostName(wxStringBuffer(buf
, hostnameSize
), hostnameSize
);
509 wxString
wxGetHomeDir()
519 wxString
wxGetCurrentDir()
526 ok
= getcwd(dir
.GetWriteBuf(len
+ 1), len
) != NULL
;
531 if ( errno
!= ERANGE
)
533 wxLogSysError(_T("Failed to get current directory"));
535 return wxEmptyString
;
539 // buffer was too small, retry with a larger one
551 // ----------------------------------------------------------------------------
553 // ----------------------------------------------------------------------------
555 // wxDoExecuteWithCapture() helper: reads an entire stream into one array
557 // returns true if ok, false if error
559 static bool ReadAll(wxInputStream
*is
, wxArrayString
& output
)
561 wxCHECK_MSG( is
, false, _T("NULL stream in wxExecute()?") );
563 // the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state
566 wxTextInputStream
tis(*is
);
570 wxString line
= tis
.ReadLine();
572 // check for EOF before other errors as it's not really an error
575 // add the last, possibly incomplete, line
581 // any other error is fatal
590 #endif // wxUSE_STREAMS
592 // this is a private function because it hasn't a clean interface: the first
593 // array is passed by reference, the second by pointer - instead we have 2
594 // public versions of wxExecute() below
595 static long wxDoExecuteWithCapture(const wxString
& command
,
596 wxArrayString
& output
,
597 wxArrayString
* error
,
600 // create a wxProcess which will capture the output
601 wxProcess
*process
= new wxProcess
;
604 long rc
= wxExecute(command
, wxEXEC_SYNC
| flags
, process
);
609 if ( !ReadAll(process
->GetInputStream(), output
) )
614 if ( !ReadAll(process
->GetErrorStream(), *error
) )
622 #endif // wxUSE_STREAMS/!wxUSE_STREAMS
629 long wxExecute(const wxString
& command
, wxArrayString
& output
, int flags
)
631 return wxDoExecuteWithCapture(command
, output
, NULL
, flags
);
634 long wxExecute(const wxString
& command
,
635 wxArrayString
& output
,
636 wxArrayString
& error
,
639 return wxDoExecuteWithCapture(command
, output
, &error
, flags
);
642 // ----------------------------------------------------------------------------
643 // wxApp::Yield() wrappers for backwards compatibility
644 // ----------------------------------------------------------------------------
648 return wxTheApp
&& wxTheApp
->Yield();
651 bool wxYieldIfNeeded()
653 return wxTheApp
&& wxTheApp
->Yield(true);
657 static long wxCurrentId
= 100;
661 // skip the part of IDs space that contains hard-coded values:
662 if (wxCurrentId
== wxID_LOWEST
)
663 wxCurrentId
= wxID_HIGHEST
+ 1;
665 return wxCurrentId
++;
669 wxGetCurrentId(void) { return wxCurrentId
; }
672 wxRegisterId (long id
)
674 if (id
>= wxCurrentId
)
675 wxCurrentId
= id
+ 1;
680 // ============================================================================
681 // GUI-only functions from now on
682 // ============================================================================
686 // ----------------------------------------------------------------------------
687 // Launch default browser
688 // ----------------------------------------------------------------------------
691 // Private method in Objective-C++ source file.
692 bool wxCocoaLaunchDefaultBrowser(const wxString
& url
, int flags
);
695 bool wxLaunchDefaultBrowser(const wxString
& urlOrig
, int flags
)
699 // set the scheme of url to http if it does not have one
700 // RR: This doesn't work if the url is just a local path
701 wxString
url(urlOrig
);
703 if ( !uri
.HasScheme() )
705 if (wxFileExists(urlOrig
))
706 url
.Prepend( wxT("file://") );
708 url
.Prepend(wxT("http://"));
712 #if defined(__WXMSW__)
715 if ( flags
& wxBROWSER_NEW_WINDOW
)
717 // ShellExecuteEx() opens the URL in an existing window by default so
718 // we can't use it if we need a new window
719 wxRegKey
key(wxRegKey::HKCR
, uri
.GetScheme() + _T("\\shell\\open"));
722 // try default browser, it must be registered at least for http URLs
723 key
.SetName(wxRegKey::HKCR
, _T("http\\shell\\open"));
728 wxRegKey
keyDDE(key
, wxT("DDEExec"));
729 if ( keyDDE
.Exists() )
731 const wxString ddeTopic
= wxRegKey(keyDDE
, wxT("topic"));
733 // we only know the syntax of WWW_OpenURL DDE request for IE,
734 // optimistically assume that all other browsers are compatible
737 bool ok
= ddeTopic
== wxT("WWW_OpenURL");
740 ddeCmd
= keyDDE
.QueryDefaultValue();
741 ok
= !ddeCmd
.empty();
746 // for WWW_OpenURL, the index of the window to open the URL
747 // in is -1 (meaning "current") by default, replace it with
748 // 0 which means "new" (see KB article 160957)
749 ok
= ddeCmd
.Replace(wxT("-1"), wxT("0"),
750 false /* only first occurence */) == 1;
755 // and also replace the parameters: the topic should
756 // contain a placeholder for the URL
757 ok
= ddeCmd
.Replace(wxT("%1"), url
, false) == 1;
762 // try to send it the DDE request now but ignore the errors
765 const wxString ddeServer
= wxRegKey(keyDDE
, wxT("application"));
766 if ( wxExecuteDDE(ddeServer
, ddeTopic
, ddeCmd
) )
769 // this is not necessarily an error: maybe browser is
770 // simply not running, but no matter, in any case we're
771 // going to launch it using ShellExecuteEx() below now and
772 // we shouldn't try to open a new window if we open a new
780 WinStruct
<SHELLEXECUTEINFO
> sei
;
781 sei
.lpFile
= url
.c_str();
782 sei
.lpVerb
= _T("open");
783 sei
.nShow
= SW_SHOWNORMAL
;
785 ::ShellExecuteEx(&sei
);
787 const int nResult
= (int) sei
.hInstApp
;
789 // Firefox returns file not found for some reason, so make an exception
791 if ( nResult
> 32 || nResult
== SE_ERR_FNF
)
794 // Log something if SE_ERR_FNF happens
795 if ( nResult
== SE_ERR_FNF
)
796 wxLogDebug(wxT("SE_ERR_FNF from ShellExecute -- maybe FireFox?"));
797 #endif // __WXDEBUG__
800 #elif defined(__WXCOCOA__)
801 // NOTE: We need to call the real implementation from src/cocoa/utils.mm
802 // because the code must use Objective-C features.
803 return wxCocoaLaunchDefaultBrowser(url
, flags
);
804 #elif defined(__WXMAC__)
810 err
= ICStart(&inst
, 'STKA'); // put your app creator code here
814 err
= ICFindConfigFile(inst
, 0, NULL
);
818 ConstStr255Param hint
= 0;
820 endSel
= url
.length();
821 err
= ICLaunchURL(inst
, hint
, url
.fn_str(), endSel
, &startSel
, &endSel
);
823 wxLogDebug(wxT("ICLaunchURL error %d"), (int) err
);
830 wxLogDebug(wxT("ICStart error %d"), (int) err
);
834 // (non-Mac, non-MSW)
838 wxString desktop
= wxTheApp
->GetTraits()->GetDesktopEnvironment();
840 // GNOME and KDE desktops have some applications which should be always installed
841 // together with their main parts, which give us the
842 if (desktop
== wxT("GNOME"))
844 wxArrayString errors
;
845 wxArrayString output
;
847 // gconf will tell us the path of the application to use as browser
848 long res
= wxExecute( wxT("gconftool-2 --get /desktop/gnome/applications/browser/exec"),
849 output
, errors
, wxEXEC_NODISABLE
);
850 if (res
>= 0 && errors
.GetCount() == 0)
852 wxString cmd
= output
[0];
853 cmd
<< _T(' ') << url
;
858 else if (desktop
== wxT("KDE"))
860 // kfmclient directly opens the given URL
861 if (wxExecute(wxT("kfmclient openURL ") + url
))
870 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(_T("html"));
874 ft
->GetMimeType(&mt
);
876 ok
= ft
->GetOpenCommand(&cmd
, wxFileType::MessageParameters(url
));
879 #endif // wxUSE_MIMETYPE
881 if ( !ok
|| cmd
.empty() )
883 // fallback to checking for the BROWSER environment variable
884 cmd
= wxGetenv(wxT("BROWSER"));
886 cmd
<< _T(' ') << url
;
889 ok
= ( !cmd
.empty() && wxExecute(cmd
) );
893 // no file type for HTML extension
894 wxLogError(_T("No default application configured for HTML files."));
896 #endif // !wxUSE_MIMETYPE && !__WXMSW__
898 wxLogSysError(_T("Failed to open URL \"%s\" in default browser."),
904 // ----------------------------------------------------------------------------
905 // Menu accelerators related functions
906 // ----------------------------------------------------------------------------
908 wxChar
*wxStripMenuCodes(const wxChar
*in
, wxChar
*out
)
911 wxString s
= wxMenuItem::GetLabelFromText(in
);
914 wxString s
= wxStripMenuCodes(str
);
915 #endif // wxUSE_MENUS
918 // go smash their buffer if it's not big enough - I love char * params
919 memcpy(out
, s
.c_str(), s
.length() * sizeof(wxChar
));
923 out
= new wxChar
[s
.length() + 1];
924 wxStrcpy(out
, s
.c_str());
930 wxString
wxStripMenuCodes(const wxString
& in
, int flags
)
932 wxASSERT_MSG( flags
, _T("this is useless to call without any flags") );
936 size_t len
= in
.length();
939 for ( size_t n
= 0; n
< len
; n
++ )
942 if ( (flags
& wxStrip_Mnemonics
) && ch
== _T('&') )
944 // skip it, it is used to introduce the accel char (or to quote
945 // itself in which case it should still be skipped): note that it
946 // can't be the last character of the string
949 wxLogDebug(_T("Invalid menu string '%s'"), in
.c_str());
953 // use the next char instead
957 else if ( (flags
& wxStrip_Accel
) && ch
== _T('\t') )
959 // everything after TAB is accel string, exit the loop
969 // ----------------------------------------------------------------------------
970 // Window search functions
971 // ----------------------------------------------------------------------------
974 * If parent is non-NULL, look through children for a label or title
975 * matching the specified string. If NULL, look through all top-level windows.
980 wxFindWindowByLabel (const wxString
& title
, wxWindow
* parent
)
982 return wxWindow::FindWindowByLabel( title
, parent
);
987 * If parent is non-NULL, look through children for a name
988 * matching the specified string. If NULL, look through all top-level windows.
993 wxFindWindowByName (const wxString
& name
, wxWindow
* parent
)
995 return wxWindow::FindWindowByName( name
, parent
);
998 // Returns menu item id or wxNOT_FOUND if none.
1000 wxFindMenuItemId (wxFrame
* frame
, const wxString
& menuString
, const wxString
& itemString
)
1003 wxMenuBar
*menuBar
= frame
->GetMenuBar ();
1005 return menuBar
->FindMenuItem (menuString
, itemString
);
1006 #endif // wxUSE_MENUS
1011 // Try to find the deepest child that contains 'pt'.
1012 // We go backwards, to try to allow for controls that are spacially
1013 // within other controls, but are still siblings (e.g. buttons within
1014 // static boxes). Static boxes are likely to be created _before_ controls
1015 // that sit inside them.
1016 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
)
1018 if (!win
->IsShown())
1021 // Hack for wxNotebook case: at least in wxGTK, all pages
1022 // claim to be shown, so we must only deal with the selected one.
1024 if (win
->IsKindOf(CLASSINFO(wxNotebook
)))
1026 wxNotebook
* nb
= (wxNotebook
*) win
;
1027 int sel
= nb
->GetSelection();
1030 wxWindow
* child
= nb
->GetPage(sel
);
1031 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
1038 wxWindowList::compatibility_iterator node
= win
->GetChildren().GetLast();
1041 wxWindow
* child
= node
->GetData();
1042 wxWindow
* foundWin
= wxFindWindowAtPoint(child
, pt
);
1045 node
= node
->GetPrevious();
1048 wxPoint pos
= win
->GetPosition();
1049 wxSize sz
= win
->GetSize();
1050 if ( !win
->IsTopLevel() && win
->GetParent() )
1052 pos
= win
->GetParent()->ClientToScreen(pos
);
1055 wxRect
rect(pos
, sz
);
1056 if (rect
.Contains(pt
))
1062 wxWindow
* wxGenericFindWindowAtPoint(const wxPoint
& pt
)
1064 // Go backwards through the list since windows
1065 // on top are likely to have been appended most
1067 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetLast();
1070 wxWindow
* win
= node
->GetData();
1071 wxWindow
* found
= wxFindWindowAtPoint(win
, pt
);
1074 node
= node
->GetPrevious();
1079 // ----------------------------------------------------------------------------
1081 // ----------------------------------------------------------------------------
1084 * N.B. these convenience functions must be separate from msgdlgg.cpp, textdlgg.cpp
1085 * since otherwise the generic code may be pulled in unnecessarily.
1090 int wxMessageBox(const wxString
& message
, const wxString
& caption
, long style
,
1091 wxWindow
*parent
, int WXUNUSED(x
), int WXUNUSED(y
) )
1093 long decorated_style
= style
;
1095 if ( ( style
& ( wxICON_EXCLAMATION
| wxICON_HAND
| wxICON_INFORMATION
| wxICON_QUESTION
) ) == 0 )
1097 decorated_style
|= ( style
& wxYES
) ? wxICON_QUESTION
: wxICON_INFORMATION
;
1100 wxMessageDialog
dialog(parent
, message
, caption
, decorated_style
);
1102 int ans
= dialog
.ShowModal();
1115 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
1120 #endif // wxUSE_MSGDLG
1124 wxString
wxGetTextFromUser(const wxString
& message
, const wxString
& caption
,
1125 const wxString
& defaultValue
, wxWindow
*parent
,
1126 wxCoord x
, wxCoord y
, bool centre
)
1129 long style
= wxTextEntryDialogStyle
;
1136 wxTextEntryDialog
dialog(parent
, message
, caption
, defaultValue
, style
, wxPoint(x
, y
));
1138 if (dialog
.ShowModal() == wxID_OK
)
1140 str
= dialog
.GetValue();
1146 wxString
wxGetPasswordFromUser(const wxString
& message
,
1147 const wxString
& caption
,
1148 const wxString
& defaultValue
,
1150 wxCoord x
, wxCoord y
, bool centre
)
1153 long style
= wxTextEntryDialogStyle
;
1160 wxPasswordEntryDialog
dialog(parent
, message
, caption
, defaultValue
,
1161 style
, wxPoint(x
, y
));
1162 if ( dialog
.ShowModal() == wxID_OK
)
1164 str
= dialog
.GetValue();
1170 #endif // wxUSE_TEXTDLG
1174 wxColour
wxGetColourFromUser(wxWindow
*parent
, const wxColour
& colInit
, const wxString
& caption
)
1177 data
.SetChooseFull(true);
1180 data
.SetColour((wxColour
&)colInit
); // const_cast
1184 wxColourDialog
dialog(parent
, &data
);
1185 if (!caption
.empty())
1186 dialog
.SetTitle(caption
);
1187 if ( dialog
.ShowModal() == wxID_OK
)
1189 colRet
= dialog
.GetColourData().GetColour();
1191 //else: leave it invalid
1196 #endif // wxUSE_COLOURDLG
1200 wxFont
wxGetFontFromUser(wxWindow
*parent
, const wxFont
& fontInit
, const wxString
& caption
)
1203 if ( fontInit
.Ok() )
1205 data
.SetInitialFont(fontInit
);
1209 wxFontDialog
dialog(parent
, data
);
1210 if (!caption
.empty())
1211 dialog
.SetTitle(caption
);
1212 if ( dialog
.ShowModal() == wxID_OK
)
1214 fontRet
= dialog
.GetFontData().GetChosenFont();
1216 //else: leave it invalid
1221 #endif // wxUSE_FONTDLG
1223 // ----------------------------------------------------------------------------
1224 // wxSafeYield and supporting functions
1225 // ----------------------------------------------------------------------------
1227 void wxEnableTopLevelWindows(bool enable
)
1229 wxWindowList::compatibility_iterator node
;
1230 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1231 node
->GetData()->Enable(enable
);
1234 wxWindowDisabler::wxWindowDisabler(wxWindow
*winToSkip
)
1236 // remember the top level windows which were already disabled, so that we
1237 // don't reenable them later
1238 m_winDisabled
= NULL
;
1240 wxWindowList::compatibility_iterator node
;
1241 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1243 wxWindow
*winTop
= node
->GetData();
1244 if ( winTop
== winToSkip
)
1247 // we don't need to disable the hidden or already disabled windows
1248 if ( winTop
->IsEnabled() && winTop
->IsShown() )
1254 if ( !m_winDisabled
)
1256 m_winDisabled
= new wxWindowList
;
1259 m_winDisabled
->Append(winTop
);
1264 wxWindowDisabler::~wxWindowDisabler()
1266 wxWindowList::compatibility_iterator node
;
1267 for ( node
= wxTopLevelWindows
.GetFirst(); node
; node
= node
->GetNext() )
1269 wxWindow
*winTop
= node
->GetData();
1270 if ( !m_winDisabled
|| !m_winDisabled
->Find(winTop
) )
1274 //else: had been already disabled, don't reenable
1277 delete m_winDisabled
;
1280 // Yield to other apps/messages and disable user input to all windows except
1282 bool wxSafeYield(wxWindow
*win
, bool onlyIfNeeded
)
1284 wxWindowDisabler
wd(win
);
1288 rc
= wxYieldIfNeeded();
1295 // Don't synthesize KeyUp events holding down a key and producing KeyDown
1296 // events with autorepeat. On by default and always on in wxMSW. wxGTK version
1299 bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag
) )
1301 return true; // detectable auto-repeat is the only mode MSW supports