]> git.saurik.com Git - wxWidgets.git/blame - src/common/utilscmn.cpp
sockets work with wxDFB now
[wxWidgets.git] / src / common / utilscmn.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
3452f00b 2// Name: src/common/utilscmn.cpp
c801d85f
KB
3// Purpose: Miscellaneous utility functions and classes
4// Author: Julian Smart
5// Modified by:
6// Created: 29/01/98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Julian Smart
65571936 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
e90c1d2a
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
c801d85f
KB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
e90c1d2a 24 #pragma hdrstop
c801d85f
KB
25#endif
26
27#ifndef WX_PRECOMP
fcdb9b38 28 #include "wx/app.h"
e90c1d2a
VZ
29 #include "wx/string.h"
30 #include "wx/utils.h"
974e8d94
VZ
31 #include "wx/intl.h"
32 #include "wx/log.h"
e90c1d2a
VZ
33
34 #if wxUSE_GUI
35 #include "wx/window.h"
e90c1d2a 36 #include "wx/frame.h"
1e6feb95 37 #include "wx/menu.h"
e90c1d2a
VZ
38 #include "wx/msgdlg.h"
39 #include "wx/textdlg.h"
78bcfcfc 40 #include "wx/textctrl.h" // for wxTE_PASSWORD
974e8d94
VZ
41 #if wxUSE_ACCEL
42 #include "wx/menuitem.h"
43 #include "wx/accel.h"
44 #endif // wxUSE_ACCEL
e90c1d2a
VZ
45 #endif // wxUSE_GUI
46#endif // WX_PRECOMP
c801d85f 47
2739d4f0
VZ
48#include "wx/apptrait.h"
49
cd6ce4a9
VZ
50#include "wx/process.h"
51#include "wx/txtstrm.h"
498a1eeb
RN
52#include "wx/uri.h"
53#include "wx/mimetype.h"
54#include "wx/config.h"
cd6ce4a9 55
4676948b
JS
56#if defined(__WXWINCE__) && wxUSE_DATETIME
57#include "wx/datetime.h"
58#endif
59
c801d85f
KB
60#include <ctype.h>
61#include <stdio.h>
62#include <stdlib.h>
63#include <string.h>
e90c1d2a 64
13ff2485 65#if !wxONLY_WATCOM_EARLIER_THAN(1,4)
3f4a0c5b
VZ
66 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
67 #include <errno.h>
68 #endif
c801d85f 69#endif
e90c1d2a 70
91b4c08d
VZ
71#if wxUSE_GUI
72 #include "wx/colordlg.h"
bf31fa26 73 #include "wx/fontdlg.h"
d1c8aaa3 74 #include "wx/notebook.h"
d1c8aaa3 75 #include "wx/statusbr.h"
91b4c08d
VZ
76#endif // wxUSE_GUI
77
1c193821 78#ifndef __WXWINCE__
c801d85f 79#include <time.h>
1c193821
JS
80#else
81#include "wx/msw/wince/time.h"
82#endif
e90c1d2a 83
f14d6dd1
JS
84#ifdef __WXMAC__
85#include "wx/mac/private.h"
86#ifndef __DARWIN__
87#include "InternetConfig.h"
88#endif
89#endif
90
4676948b 91#if !defined(__MWERKS__) && !defined(__WXWINCE__)
e90c1d2a
VZ
92 #include <sys/types.h>
93 #include <sys/stat.h>
469e1e5c 94#endif
c801d85f 95
82ef81ed 96#if defined(__WXMSW__)
5e1febfa 97 #include "wx/msw/private.h"
3452f00b 98 #include "wx/msw/registry.h"
b21d68c6 99 #include <shellapi.h> // needed for SHELLEXECUTEINFO
c801d85f
KB
100#endif
101
ec67cff1 102#if wxUSE_BASE
7c072018 103
73deed44
VZ
104// ----------------------------------------------------------------------------
105// common data
106// ----------------------------------------------------------------------------
107
e90c1d2a
VZ
108// ============================================================================
109// implementation
110// ============================================================================
c801d85f 111
7c072018
VZ
112#if WXWIN_COMPATIBILITY_2_4
113
0080691b
OK
114wxChar *
115copystring (const wxChar *s)
c801d85f 116{
657a7545
WS
117 if (s == NULL) s = wxEmptyString;
118 size_t len = wxStrlen (s) + 1;
c801d85f 119
657a7545
WS
120 wxChar *news = new wxChar[len];
121 memcpy (news, s, len * sizeof(wxChar)); // Should be the fastest
c801d85f 122
657a7545 123 return news;
c801d85f
KB
124}
125
7c072018
VZ
126#endif // WXWIN_COMPATIBILITY_2_4
127
e12c92c2
VZ
128// ----------------------------------------------------------------------------
129// String <-> Number conversions (deprecated)
130// ----------------------------------------------------------------------------
131
132#if WXWIN_COMPATIBILITY_2_4
133
fd242375
VS
134WXDLLIMPEXP_DATA_BASE(const wxChar *) wxFloatToStringStr = wxT("%.2f");
135WXDLLIMPEXP_DATA_BASE(const wxChar *) wxDoubleToStringStr = wxT("%.2f");
e12c92c2 136
3f4a0c5b 137void
bc87fd68 138StringToFloat (const wxChar *s, float *number)
c801d85f 139{
657a7545
WS
140 if (s && *s && number)
141 *number = (float) wxStrtod (s, (wxChar **) NULL);
c801d85f
KB
142}
143
3f4a0c5b 144void
bc87fd68 145StringToDouble (const wxChar *s, double *number)
c801d85f 146{
657a7545
WS
147 if (s && *s && number)
148 *number = wxStrtod (s, (wxChar **) NULL);
c801d85f
KB
149}
150
0080691b
OK
151wxChar *
152FloatToString (float number, const wxChar *fmt)
c801d85f 153{
657a7545 154 static wxChar buf[256];
c801d85f 155
657a7545
WS
156 wxSprintf (buf, fmt, number);
157 return buf;
c801d85f
KB
158}
159
0080691b
OK
160wxChar *
161DoubleToString (double number, const wxChar *fmt)
c801d85f 162{
657a7545 163 static wxChar buf[256];
c801d85f 164
657a7545
WS
165 wxSprintf (buf, fmt, number);
166 return buf;
c801d85f
KB
167}
168
3f4a0c5b 169void
bc87fd68 170StringToInt (const wxChar *s, int *number)
c801d85f 171{
657a7545
WS
172 if (s && *s && number)
173 *number = (int) wxStrtol (s, (wxChar **) NULL, 10);
c801d85f
KB
174}
175
3f4a0c5b 176void
bc87fd68 177StringToLong (const wxChar *s, long *number)
c801d85f 178{
657a7545
WS
179 if (s && *s && number)
180 *number = wxStrtol (s, (wxChar **) NULL, 10);
c801d85f
KB
181}
182
84fff0b3 183wxChar *
c801d85f
KB
184IntToString (int number)
185{
657a7545 186 static wxChar buf[20];
c801d85f 187
657a7545
WS
188 wxSprintf (buf, wxT("%d"), number);
189 return buf;
c801d85f
KB
190}
191
84fff0b3 192wxChar *
c801d85f
KB
193LongToString (long number)
194{
657a7545 195 static wxChar buf[20];
c801d85f 196
657a7545
WS
197 wxSprintf (buf, wxT("%ld"), number);
198 return buf;
c801d85f
KB
199}
200
e12c92c2
VZ
201#endif // WXWIN_COMPATIBILITY_2_4
202
c801d85f 203// Array used in DecToHex conversion routine.
223d09f6 204static wxChar hexArray[] = wxT("0123456789ABCDEF");
c801d85f
KB
205
206// Convert 2-digit hex number to decimal
fd71308f 207int wxHexToDec(const wxString& buf)
c801d85f 208{
657a7545 209 int firstDigit, secondDigit;
3f4a0c5b 210
657a7545
WS
211 if (buf.GetChar(0) >= wxT('A'))
212 firstDigit = buf.GetChar(0) - wxT('A') + 10;
213 else
214 firstDigit = buf.GetChar(0) - wxT('0');
c801d85f 215
657a7545
WS
216 if (buf.GetChar(1) >= wxT('A'))
217 secondDigit = buf.GetChar(1) - wxT('A') + 10;
218 else
219 secondDigit = buf.GetChar(1) - wxT('0');
3f4a0c5b 220
657a7545 221 return (firstDigit & 0xF) * 16 + (secondDigit & 0xF );
c801d85f
KB
222}
223
224// Convert decimal integer to 2-character hex string
84fff0b3 225void wxDecToHex(int dec, wxChar *buf)
c801d85f 226{
657a7545
WS
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];
231 buf[2] = 0;
c801d85f
KB
232}
233
fd71308f
JS
234// Convert decimal integer to 2-character hex string
235wxString wxDecToHex(int dec)
236{
84fff0b3 237 wxChar buf[3];
fd71308f
JS
238 wxDecToHex(dec, buf);
239 return wxString(buf);
240}
241
7c072018
VZ
242// ----------------------------------------------------------------------------
243// misc functions
244// ----------------------------------------------------------------------------
c801d85f
KB
245
246// Return the current date/time
e90c1d2a 247wxString wxNow()
c801d85f 248{
4676948b
JS
249#ifdef __WXWINCE__
250#if wxUSE_DATETIME
251 wxDateTime now = wxDateTime::Now();
252 return now.Format();
253#else
254 return wxEmptyString;
255#endif
256#else
2b5f62a0
VZ
257 time_t now = time((time_t *) NULL);
258 char *date = ctime(&now);
259 date[24] = '\0';
260 return wxString::FromAscii(date);
4676948b 261#endif
c801d85f
KB
262}
263
08873d36
VZ
264void wxUsleep(unsigned long milliseconds)
265{
266 wxMilliSleep(milliseconds);
267}
268
7c072018
VZ
269const wxChar *wxGetInstallPrefix()
270{
271 wxString prefix;
272
273 if ( wxGetEnv(wxT("WXPREFIX"), &prefix) )
274 return prefix.c_str();
275
276#ifdef wxINSTALL_PREFIX
277 return wxT(wxINSTALL_PREFIX);
278#else
525d8583 279 return wxEmptyString;
7c072018
VZ
280#endif
281}
282
283wxString wxGetDataDir()
284{
10f206ad
RL
285 wxString dir = wxGetInstallPrefix();
286 dir << wxFILE_SEP_PATH << wxT("share") << wxFILE_SEP_PATH << wxT("wx");
7c072018
VZ
287 return dir;
288}
e90c1d2a 289
8bb6b2c0 290bool wxIsPlatformLittleEndian()
2739d4f0 291{
8bb6b2c0
VZ
292 // Are we little or big endian? This method is from Harbison & Steele.
293 union
294 {
295 long l;
296 char c[sizeof(long)];
297 } u;
298 u.l = 1;
299
300 return u.c[0] == 1;
2739d4f0 301}
1e6feb95 302
8bb6b2c0 303
230c9077
JS
304/*
305 * Class to make it easier to specify platform-dependent values
306 */
307
308wxArrayInt* wxPlatform::sm_customPlatforms = NULL;
309
4bfec179 310void wxPlatform::Copy(const wxPlatform& platform)
230c9077 311{
4bfec179
JS
312 m_longValue = platform.m_longValue;
313 m_doubleValue = platform.m_doubleValue;
314 m_stringValue = platform.m_stringValue;
315}
316
317wxPlatform wxPlatform::If(int platform, long value)
318{
319 if (Is(platform))
320 return wxPlatform(value);
321 else
322 return wxPlatform();
323}
324
325wxPlatform wxPlatform::IfNot(int platform, long value)
326{
327 if (!Is(platform))
328 return wxPlatform(value);
329 else
330 return wxPlatform();
331}
332
333wxPlatform& wxPlatform::ElseIf(int platform, long value)
334{
335 if (Is(platform))
230c9077
JS
336 m_longValue = value;
337 return *this;
338}
339
4bfec179 340wxPlatform& wxPlatform::ElseIfNot(int platform, long value)
230c9077 341{
4bfec179 342 if (!Is(platform))
230c9077
JS
343 m_longValue = value;
344 return *this;
345}
346
4bfec179 347wxPlatform wxPlatform::If(int platform, double value)
230c9077 348{
4bfec179
JS
349 if (Is(platform))
350 return wxPlatform(value);
351 else
352 return wxPlatform();
353}
354
355wxPlatform wxPlatform::IfNot(int platform, double value)
356{
357 if (!Is(platform))
358 return wxPlatform(value);
359 else
360 return wxPlatform();
361}
362
363wxPlatform& wxPlatform::ElseIf(int platform, double value)
364{
365 if (Is(platform))
230c9077
JS
366 m_doubleValue = value;
367 return *this;
368}
369
4bfec179 370wxPlatform& wxPlatform::ElseIfNot(int platform, double value)
230c9077 371{
4bfec179 372 if (!Is(platform))
230c9077
JS
373 m_doubleValue = value;
374 return *this;
375}
376
4bfec179
JS
377wxPlatform wxPlatform::If(int platform, const wxString& value)
378{
379 if (Is(platform))
380 return wxPlatform(value);
381 else
382 return wxPlatform();
383}
384
385wxPlatform wxPlatform::IfNot(int platform, const wxString& value)
386{
387 if (!Is(platform))
388 return wxPlatform(value);
389 else
390 return wxPlatform();
391}
392
393wxPlatform& wxPlatform::ElseIf(int platform, const wxString& value)
230c9077 394{
4bfec179 395 if (Is(platform))
230c9077
JS
396 m_stringValue = value;
397 return *this;
398}
399
4bfec179 400wxPlatform& wxPlatform::ElseIfNot(int platform, const wxString& value)
230c9077 401{
4bfec179 402 if (!Is(platform))
230c9077
JS
403 m_stringValue = value;
404 return *this;
405}
406
4bfec179 407wxPlatform& wxPlatform::Else(long value)
230c9077
JS
408{
409 m_longValue = value;
410 return *this;
411}
412
4bfec179 413wxPlatform& wxPlatform::Else(double value)
230c9077
JS
414{
415 m_doubleValue = value;
416 return *this;
417}
418
4bfec179 419wxPlatform& wxPlatform::Else(const wxString& value)
230c9077
JS
420{
421 m_stringValue = value;
422 return *this;
423}
424
425void wxPlatform::AddPlatform(int platform)
426{
427 if (!sm_customPlatforms)
428 sm_customPlatforms = new wxArrayInt;
429 sm_customPlatforms->Add(platform);
430}
431
432void wxPlatform::ClearPlatforms()
433{
434 delete sm_customPlatforms;
435 sm_customPlatforms = NULL;
436}
437
438/// Function for testing current platform
439
4bfec179 440bool wxPlatform::Is(int platform)
230c9077
JS
441{
442#ifdef __WXMSW__
216c3543 443 if (platform == wxOS_WINDOWS)
230c9077
JS
444 return true;
445#endif
446#ifdef __WXWINCE__
216c3543 447 if (platform == wxOS_WINDOWS_CE)
230c9077
JS
448 return true;
449#endif
a6e8c584
WS
450
451#if 0
452
453// FIXME: wxWinPocketPC and wxWinSmartPhone are unknown symbols
454
230c9077
JS
455#if defined(__WXWINCE__) && defined(__POCKETPC__)
456 if (platform == wxWinPocketPC)
457 return true;
458#endif
459#if defined(__WXWINCE__) && defined(__SMARTPHONE__)
6aa68c25 460 if (platform == wxWinSmartPhone)
230c9077
JS
461 return true;
462#endif
a6e8c584
WS
463
464#endif
465
230c9077 466#ifdef __WXGTK__
216c3543 467 if (platform == wxPORT_GTK)
230c9077
JS
468 return true;
469#endif
470#ifdef __WXMAC__
216c3543 471 if (platform == wxPORT_MAC)
230c9077
JS
472 return true;
473#endif
474#ifdef __WXX11__
216c3543 475 if (platform == wxPORT_X11)
230c9077
JS
476 return true;
477#endif
478#ifdef __UNIX__
216c3543 479 if (platform == wxOS_UNIX)
230c9077
JS
480 return true;
481#endif
482#ifdef __WXMGL__
216c3543 483 if (platform == wxPORT_MGL)
230c9077
JS
484 return true;
485#endif
8ab09e65
SN
486#ifdef __OS2__
487 if (platform == wxOS_OS2)
488 return true;
489#endif
490#ifdef __WXPM__
491 if (platform == wxPORT_PM)
230c9077
JS
492 return true;
493#endif
55d452c6 494#ifdef __WXCOCOA__
216c3543 495 if (platform == wxPORT_MAC)
230c9077
JS
496 return true;
497#endif
498
499 if (sm_customPlatforms && sm_customPlatforms->Index(platform) != wxNOT_FOUND)
500 return true;
501
502 return false;
503}
504
e90c1d2a 505// ----------------------------------------------------------------------------
7c072018 506// network and user id functions
e90c1d2a 507// ----------------------------------------------------------------------------
c801d85f 508
7c072018
VZ
509// Get Full RFC822 style email address
510bool wxGetEmailAddress(wxChar *address, int maxSize)
c801d85f 511{
7c072018
VZ
512 wxString email = wxGetEmailAddress();
513 if ( !email )
cb719f2e 514 return false;
c801d85f 515
7c072018
VZ
516 wxStrncpy(address, email, maxSize - 1);
517 address[maxSize - 1] = wxT('\0');
518
cb719f2e 519 return true;
c801d85f
KB
520}
521
7c072018 522wxString wxGetEmailAddress()
47bc1060 523{
7c072018 524 wxString email;
974e8d94 525
7c072018 526 wxString host = wxGetFullHostName();
4055ed82 527 if ( !host.empty() )
1e6feb95 528 {
7c072018 529 wxString user = wxGetUserId();
4055ed82 530 if ( !user.empty() )
1e6feb95 531 {
7c072018 532 email << user << wxT('@') << host;
974e8d94 533 }
974e8d94
VZ
534 }
535
7c072018 536 return email;
974e8d94
VZ
537}
538
7c072018 539wxString wxGetUserId()
c801d85f 540{
7c072018 541 static const int maxLoginLen = 256; // FIXME arbitrary number
c801d85f 542
7c072018 543 wxString buf;
4c3ebca9 544 bool ok = wxGetUserId(wxStringBuffer(buf, maxLoginLen), maxLoginLen);
c801d85f 545
7c072018
VZ
546 if ( !ok )
547 buf.Empty();
c801d85f 548
7c072018 549 return buf;
c801d85f
KB
550}
551
7c072018 552wxString wxGetUserName()
c801d85f 553{
7c072018 554 static const int maxUserNameLen = 1024; // FIXME arbitrary number
1e6feb95 555
7c072018 556 wxString buf;
4c3ebca9 557 bool ok = wxGetUserName(wxStringBuffer(buf, maxUserNameLen), maxUserNameLen);
7c072018
VZ
558
559 if ( !ok )
560 buf.Empty();
561
562 return buf;
59a12e90
JS
563}
564
7c072018 565wxString wxGetHostName()
59a12e90 566{
7c072018 567 static const size_t hostnameSize = 257;
c67d6888 568
7c072018 569 wxString buf;
4c3ebca9 570 bool ok = wxGetHostName(wxStringBuffer(buf, hostnameSize), hostnameSize);
59a12e90 571
7c072018
VZ
572 if ( !ok )
573 buf.Empty();
59a12e90 574
7c072018 575 return buf;
59a12e90
JS
576}
577
7c072018 578wxString wxGetFullHostName()
59a12e90 579{
7c072018 580 static const size_t hostnameSize = 257;
c801d85f 581
7c072018 582 wxString buf;
4c3ebca9 583 bool ok = wxGetFullHostName(wxStringBuffer(buf, hostnameSize), hostnameSize);
7c072018
VZ
584
585 if ( !ok )
586 buf.Empty();
c801d85f 587
7c072018
VZ
588 return buf;
589}
c801d85f 590
7c072018
VZ
591wxString wxGetHomeDir()
592{
593 wxString home;
594 wxGetHomeDir(&home);
c801d85f 595
7c072018
VZ
596 return home;
597}
c801d85f 598
c801d85f
KB
599#if 0
600
7c072018 601wxString wxGetCurrentDir()
c801d85f 602{
7c072018
VZ
603 wxString dir;
604 size_t len = 1024;
605 bool ok;
606 do
607 {
608 ok = getcwd(dir.GetWriteBuf(len + 1), len) != NULL;
609 dir.UngetWriteBuf();
c801d85f 610
7c072018
VZ
611 if ( !ok )
612 {
613 if ( errno != ERANGE )
614 {
615 wxLogSysError(_T("Failed to get current directory"));
c801d85f 616
7c072018
VZ
617 return wxEmptyString;
618 }
3f4a0c5b 619 else
7c072018
VZ
620 {
621 // buffer was too small, retry with a larger one
622 len *= 2;
623 }
3f4a0c5b 624 }
7c072018
VZ
625 //else: ok
626 } while ( !ok );
c801d85f 627
7c072018 628 return dir;
c801d85f
KB
629}
630
7c072018 631#endif // 0
e90c1d2a
VZ
632
633// ----------------------------------------------------------------------------
7c072018 634// wxExecute
e90c1d2a 635// ----------------------------------------------------------------------------
ead7ce10 636
7c072018
VZ
637// wxDoExecuteWithCapture() helper: reads an entire stream into one array
638//
cb719f2e 639// returns true if ok, false if error
7c072018
VZ
640#if wxUSE_STREAMS
641static bool ReadAll(wxInputStream *is, wxArrayString& output)
dfad0599 642{
cb719f2e 643 wxCHECK_MSG( is, false, _T("NULL stream in wxExecute()?") );
dfad0599 644
7c072018
VZ
645 // the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state
646 is->Reset();
1e6feb95 647
7c072018 648 wxTextInputStream tis(*is);
1e6feb95 649
cb719f2e 650 bool cont = true;
7c072018 651 while ( cont )
d2f50933 652 {
7c072018
VZ
653 wxString line = tis.ReadLine();
654 if ( is->Eof() )
655 break;
656
657 if ( !*is )
658 {
cb719f2e 659 cont = false;
7c072018
VZ
660 }
661 else
662 {
663 output.Add(line);
664 }
d2f50933
VZ
665 }
666
7c072018 667 return cont;
dfad0599 668}
7c072018 669#endif // wxUSE_STREAMS
d2f50933 670
7c072018
VZ
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
674static long wxDoExecuteWithCapture(const wxString& command,
675 wxArrayString& output,
4d172154
VZ
676 wxArrayString* error,
677 int flags)
d2f50933 678{
7c072018
VZ
679 // create a wxProcess which will capture the output
680 wxProcess *process = new wxProcess;
681 process->Redirect();
dfad0599 682
4d172154 683 long rc = wxExecute(command, wxEXEC_SYNC | flags, process);
1e6feb95 684
7c072018
VZ
685#if wxUSE_STREAMS
686 if ( rc != -1 )
bf31fa26 687 {
7c072018
VZ
688 if ( !ReadAll(process->GetInputStream(), output) )
689 rc = -1;
91b4c08d 690
7c072018
VZ
691 if ( error )
692 {
693 if ( !ReadAll(process->GetErrorStream(), *error) )
694 rc = -1;
695 }
91b4c08d 696
7c072018 697 }
e70ba80d
WS
698#else
699 wxUnusedVar(output);
700 wxUnusedVar(error);
701#endif // wxUSE_STREAMS/!wxUSE_STREAMS
91b4c08d 702
7c072018 703 delete process;
1e6feb95 704
7c072018 705 return rc;
7c072018 706}
bf31fa26 707
4d172154 708long wxExecute(const wxString& command, wxArrayString& output, int flags)
bf31fa26 709{
4d172154 710 return wxDoExecuteWithCapture(command, output, NULL, flags);
7c072018 711}
bf31fa26 712
7c072018
VZ
713long wxExecute(const wxString& command,
714 wxArrayString& output,
4d172154
VZ
715 wxArrayString& error,
716 int flags)
7c072018 717{
4d172154 718 return wxDoExecuteWithCapture(command, output, &error, flags);
bf31fa26
VZ
719}
720
498a1eeb
RN
721// ----------------------------------------------------------------------------
722// Launch default browser
723// ----------------------------------------------------------------------------
724
42d0df00 725bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags)
498a1eeb 726{
42d0df00
VZ
727 wxUnusedVar(flags);
728
7999124f 729 // set the scheme of url to http if it does not have one
889fda0c 730 // RR: This doesn't work if the url is just a local path
7999124f 731 wxString url(urlOrig);
6f6dd276
VZ
732 wxURI uri(url);
733 if ( !uri.HasScheme() )
7999124f 734 url.Prepend(wxT("http://"));
889fda0c 735
532d575b 736
7999124f 737#if defined(__WXMSW__)
5ccb95f6
WS
738
739#if wxUSE_IPC
42d0df00
VZ
740 if ( flags & wxBROWSER_NEW_WINDOW )
741 {
742 // ShellExecuteEx() opens the URL in an existing window by default so
743 // we can't use it if we need a new window
6f6dd276
VZ
744 wxRegKey key(wxRegKey::HKCR, uri.GetScheme() + _T("\\shell\\open"));
745 if ( !key.Exists() )
746 {
747 // try default browser, it must be registered at least for http URLs
748 key.SetName(wxRegKey::HKCR, _T("http\\shell\\open"));
749 }
750
42d0df00
VZ
751 if ( key.Exists() )
752 {
753 wxRegKey keyDDE(key, wxT("DDEExec"));
754 if ( keyDDE.Exists() )
755 {
756 const wxString ddeTopic = wxRegKey(keyDDE, wxT("topic"));
757
758 // we only know the syntax of WWW_OpenURL DDE request for IE,
759 // optimistically assume that all other browsers are compatible
760 // with it
761 wxString ddeCmd;
762 bool ok = ddeTopic == wxT("WWW_OpenURL");
763 if ( ok )
764 {
588c80de 765 ddeCmd = keyDDE.QueryDefaultValue();
42d0df00
VZ
766 ok = !ddeCmd.empty();
767 }
768
769 if ( ok )
770 {
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;
776 }
777
778 if ( ok )
779 {
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;
783 }
784
785 if ( ok )
786 {
787 // try to send it the DDE request now but ignore the errors
788 wxLogNull noLog;
789
790 const wxString ddeServer = wxRegKey(keyDDE, wxT("application"));
791 if ( wxExecuteDDE(ddeServer, ddeTopic, ddeCmd) )
792 return true;
793
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
798 // browser anyhow
799 }
800 }
801 }
802 }
5ccb95f6 803#endif // wxUSE_IPC
42d0df00 804
7999124f
VZ
805 WinStruct<SHELLEXECUTEINFO> sei;
806 sei.lpFile = url.c_str();
807 sei.lpVerb = _T("open");
808 sei.nShow = SW_SHOWNORMAL;
498a1eeb 809
7999124f 810 ::ShellExecuteEx(&sei);
657a7545 811
7999124f 812 const int nResult = (int) sei.hInstApp;
498a1eeb 813
7999124f
VZ
814 // Firefox returns file not found for some reason, so make an exception
815 // for it
816 if ( nResult > 32 || nResult == SE_ERR_FNF )
498a1eeb 817 {
657a7545 818#ifdef __WXDEBUG__
498a1eeb 819 // Log something if SE_ERR_FNF happens
7999124f
VZ
820 if ( nResult == SE_ERR_FNF )
821 wxLogDebug(wxT("SE_ERR_FNF from ShellExecute -- maybe FireFox?"));
822#endif // __WXDEBUG__
823 return true;
657a7545 824 }
f14d6dd1
JS
825#elif defined(__WXMAC__)
826 OSStatus err;
827 ICInstance inst;
fb743cab
SC
828 long int startSel;
829 long int endSel;
f14d6dd1
JS
830
831 err = ICStart(&inst, 'STKA'); // put your app creator code here
13a1e96f
DS
832 if (err == noErr)
833 {
f14d6dd1 834#if !TARGET_CARBON
13a1e96f 835 err = ICFindConfigFile(inst, 0, NULL);
f14d6dd1
JS
836#endif
837 if (err == noErr)
838 {
839 ConstStr255Param hint = 0;
840 startSel = 0;
76b49cf4 841 endSel = url.length();
f14d6dd1
JS
842 err = ICLaunchURL(inst, hint, url.fn_str(), endSel, &startSel, &endSel);
843 if (err != noErr)
844 wxLogDebug(wxT("ICLaunchURL error %d"), (int) err);
845 }
846 ICStop(inst);
847 return true;
848 }
849 else
850 {
851 wxLogDebug(wxT("ICStart error %d"), (int) err);
852 return false;
853 }
889fda0c
RR
854#else
855 // (non-Mac, non-MSW)
856
857#ifdef __UNIX__
17ede0b1
RR
858
859 wxString desktop = wxTheApp->GetTraits()->GetDesktopEnvironment();
860
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"))
889fda0c
RR
864 {
865 wxArrayString errors;
866 wxArrayString output;
17ede0b1
RR
867
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 );
889fda0c
RR
871 if (res >= 0 && errors.GetCount() == 0)
872 {
873 wxString cmd = output[0];
874 cmd << _T(' ') << url;
875 if (wxExecute(cmd))
876 return true;
877 }
878 }
17ede0b1
RR
879 else if (desktop == wxT("KDE"))
880 {
881 // kfmclient directly opens the given URL
882 if (wxExecute(wxT("kfmclient openURL ") + url))
883 return true;
884 }
889fda0c
RR
885#endif
886
13a1e96f
DS
887 bool ok = false;
888 wxString cmd;
889
1b1b5318 890#if wxUSE_MIMETYPE
13a1e96f 891 wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(_T("html"));
7999124f 892 if ( ft )
657a7545 893 {
7999124f
VZ
894 wxString mt;
895 ft->GetMimeType(&mt);
498a1eeb 896
13a1e96f 897 ok = ft->GetOpenCommand(&cmd, wxFileType::MessageParameters(url));
7999124f 898 delete ft;
498a1eeb 899 }
1b1b5318 900#endif // wxUSE_MIMETYPE
13a1e96f
DS
901
902 if ( !ok || cmd.empty() )
2830b4a4 903 {
13a1e96f
DS
904 // fallback to checking for the BROWSER environment variable
905 cmd = wxGetenv(wxT("BROWSER"));
906 if ( !cmd.empty() )
907 cmd << _T(' ') << url;
2830b4a4 908 }
13a1e96f
DS
909
910 ok = ( !cmd.empty() && wxExecute(cmd) );
911 if (ok)
912 return ok;
913
914 // no file type for HTML extension
915 wxLogError(_T("No default application configured for HTML files."));
916
7999124f 917#endif // !wxUSE_MIMETYPE && !__WXMSW__
532d575b 918
7999124f
VZ
919 wxLogSysError(_T("Failed to open URL \"%s\" in default browser."),
920 url.c_str());
657a7545 921
7999124f 922 return false;
498a1eeb
RN
923}
924
91b4c08d 925// ----------------------------------------------------------------------------
7c072018 926// wxApp::Yield() wrappers for backwards compatibility
91b4c08d
VZ
927// ----------------------------------------------------------------------------
928
7c072018 929bool wxYield()
469e1e5c 930{
7c072018 931 return wxTheApp && wxTheApp->Yield();
469e1e5c 932}
7c072018
VZ
933
934bool wxYieldIfNeeded()
469e1e5c 935{
cb719f2e 936 return wxTheApp && wxTheApp->Yield(true);
469e1e5c 937}
7c072018 938
ec67cff1 939#endif // wxUSE_BASE
7c072018
VZ
940
941// ============================================================================
942// GUI-only functions from now on
943// ============================================================================
944
945#if wxUSE_GUI
946
4c3ebca9
MB
947// Id generation
948static long wxCurrentId = 100;
949
c838b68e 950long wxNewId()
4c3ebca9 951{
c838b68e
VS
952 // skip the part of IDs space that contains hard-coded values:
953 if (wxCurrentId == wxID_LOWEST)
954 wxCurrentId = wxID_HIGHEST + 1;
955
956 return wxCurrentId++;
4c3ebca9
MB
957}
958
959long
960wxGetCurrentId(void) { return wxCurrentId; }
961
962void
963wxRegisterId (long id)
964{
965 if (id >= wxCurrentId)
966 wxCurrentId = id + 1;
967}
968
e90c1d2a 969// ----------------------------------------------------------------------------
7c072018 970// Menu accelerators related functions
e90c1d2a
VZ
971// ----------------------------------------------------------------------------
972
7c072018 973wxChar *wxStripMenuCodes(const wxChar *in, wxChar *out)
e90c1d2a 974{
9a6384ca 975#if wxUSE_MENUS
7c072018 976 wxString s = wxMenuItem::GetLabelFromText(in);
9a6384ca
WS
977#else
978 wxString str(in);
979 wxString s = wxStripMenuCodes(str);
980#endif // wxUSE_MENUS
7c072018
VZ
981 if ( out )
982 {
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));
985 }
986 else
987 {
f526f752
MB
988 // MYcopystring - for easier search...
989 out = new wxChar[s.length() + 1];
990 wxStrcpy(out, s.c_str());
7c072018
VZ
991 }
992
993 return out;
e90c1d2a
VZ
994}
995
74639764 996wxString wxStripMenuCodes(const wxString& in, int flags)
e90c1d2a 997{
74639764
VZ
998 wxASSERT_MSG( flags, _T("this is useless to call without any flags") );
999
7c072018 1000 wxString out;
79f585d9 1001
7c072018
VZ
1002 size_t len = in.length();
1003 out.reserve(len);
79f585d9 1004
7c072018
VZ
1005 for ( size_t n = 0; n < len; n++ )
1006 {
1007 wxChar ch = in[n];
74639764 1008 if ( (flags & wxStrip_Mnemonics) && ch == _T('&') )
cd6ce4a9 1009 {
7c072018
VZ
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
1013 if ( ++n == len )
79f585d9 1014 {
7c072018
VZ
1015 wxLogDebug(_T("Invalid menu string '%s'"), in.c_str());
1016 }
1017 else
1018 {
1019 // use the next char instead
1020 ch = in[n];
79f585d9 1021 }
cd6ce4a9 1022 }
74639764 1023 else if ( (flags & wxStrip_Accel) && ch == _T('\t') )
79f585d9 1024 {
7c072018
VZ
1025 // everything after TAB is accel string, exit the loop
1026 break;
79f585d9 1027 }
7c072018
VZ
1028
1029 out += ch;
225fe9d6
VZ
1030 }
1031
7c072018 1032 return out;
cd6ce4a9
VZ
1033}
1034
cbc66a27 1035// ----------------------------------------------------------------------------
7c072018 1036// Window search functions
cbc66a27
VZ
1037// ----------------------------------------------------------------------------
1038
7c072018
VZ
1039/*
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.
1042 *
1043 */
e2a6f233 1044
7c072018
VZ
1045wxWindow *
1046wxFindWindowByLabel (const wxString& title, wxWindow * parent)
134677bd 1047{
7c072018
VZ
1048 return wxWindow::FindWindowByLabel( title, parent );
1049}
b829bf55 1050
b829bf55 1051
7c072018
VZ
1052/*
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.
1055 *
1056 */
134677bd 1057
7c072018
VZ
1058wxWindow *
1059wxFindWindowByName (const wxString& name, wxWindow * parent)
2c18f21d 1060{
7c072018 1061 return wxWindow::FindWindowByName( name, parent );
2c18f21d
VS
1062}
1063
cb719f2e 1064// Returns menu item id or wxNOT_FOUND if none.
7c072018
VZ
1065int
1066wxFindMenuItemId (wxFrame * frame, const wxString& menuString, const wxString& itemString)
e2a6f233 1067{
7c072018 1068#if wxUSE_MENUS
9a6384ca
WS
1069 wxMenuBar *menuBar = frame->GetMenuBar ();
1070 if ( menuBar )
1071 return menuBar->FindMenuItem (menuString, itemString);
7c072018 1072#endif // wxUSE_MENUS
0fb67cd1 1073
9a6384ca 1074 return wxNOT_FOUND;
e2a6f233
JS
1075}
1076
7c072018
VZ
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.
1082wxWindow* wxFindWindowAtPoint(wxWindow* win, const wxPoint& pt)
e2a6f233 1083{
7c072018
VZ
1084 if (!win->IsShown())
1085 return NULL;
0fb67cd1 1086
7c072018
VZ
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.
1089#if wxUSE_NOTEBOOK
1090 if (win->IsKindOf(CLASSINFO(wxNotebook)))
e2a6f233 1091 {
7c072018
VZ
1092 wxNotebook* nb = (wxNotebook*) win;
1093 int sel = nb->GetSelection();
1094 if (sel >= 0)
1095 {
1096 wxWindow* child = nb->GetPage(sel);
1097 wxWindow* foundWin = wxFindWindowAtPoint(child, pt);
1098 if (foundWin)
1099 return foundWin;
1100 }
e2a6f233 1101 }
7c072018 1102#endif
0fb67cd1 1103
df5168c4 1104 wxWindowList::compatibility_iterator node = win->GetChildren().GetLast();
7c072018
VZ
1105 while (node)
1106 {
1107 wxWindow* child = node->GetData();
1108 wxWindow* foundWin = wxFindWindowAtPoint(child, pt);
1109 if (foundWin)
1110 return foundWin;
1111 node = node->GetPrevious();
1112 }
1113
1114 wxPoint pos = win->GetPosition();
1115 wxSize sz = win->GetSize();
7aa7d2d4 1116 if ( !win->IsTopLevel() && win->GetParent() )
7c072018
VZ
1117 {
1118 pos = win->GetParent()->ClientToScreen(pos);
1119 }
1120
1121 wxRect rect(pos, sz);
22a35096 1122 if (rect.Contains(pt))
7c072018 1123 return win;
622eb786
VZ
1124
1125 return NULL;
0fb67cd1
VZ
1126}
1127
7c072018 1128wxWindow* wxGenericFindWindowAtPoint(const wxPoint& pt)
0fb67cd1 1129{
7c072018
VZ
1130 // Go backwards through the list since windows
1131 // on top are likely to have been appended most
1132 // recently.
df5168c4 1133 wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetLast();
7c072018
VZ
1134 while (node)
1135 {
1136 wxWindow* win = node->GetData();
1137 wxWindow* found = wxFindWindowAtPoint(win, pt);
1138 if (found)
1139 return found;
1140 node = node->GetPrevious();
1141 }
1142 return NULL;
1143}
0fb67cd1 1144
7c072018
VZ
1145// ----------------------------------------------------------------------------
1146// GUI helpers
1147// ----------------------------------------------------------------------------
0fb67cd1 1148
7c072018
VZ
1149/*
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.
1152 */
0fb67cd1 1153
7c072018 1154#if wxUSE_MSGDLG
0fb67cd1 1155
7c072018
VZ
1156int wxMessageBox(const wxString& message, const wxString& caption, long style,
1157 wxWindow *parent, int WXUNUSED(x), int WXUNUSED(y) )
0fb67cd1 1158{
53a6ac21
DS
1159 long decorated_style = style;
1160
1161 if ( ( style & ( wxICON_EXCLAMATION | wxICON_HAND | wxICON_INFORMATION | wxICON_QUESTION ) ) == 0 )
1162 {
1163 decorated_style |= ( style & wxYES ) ? wxICON_QUESTION : wxICON_INFORMATION ;
1164 }
1165
1166 wxMessageDialog dialog(parent, message, caption, decorated_style);
0fb67cd1 1167
7c072018
VZ
1168 int ans = dialog.ShowModal();
1169 switch ( ans )
1170 {
1171 case wxID_OK:
1172 return wxOK;
1173 case wxID_YES:
1174 return wxYES;
1175 case wxID_NO:
1176 return wxNO;
1177 case wxID_CANCEL:
1178 return wxCANCEL;
1179 }
0fb67cd1 1180
7c072018 1181 wxFAIL_MSG( _T("unexpected return code from wxMessageDialog") );
0fb67cd1 1182
7c072018 1183 return wxCANCEL;
e2a6f233
JS
1184}
1185
7c072018 1186#endif // wxUSE_MSGDLG
518b5d2f 1187
7c072018 1188#if wxUSE_TEXTDLG
518b5d2f 1189
7c072018
VZ
1190wxString wxGetTextFromUser(const wxString& message, const wxString& caption,
1191 const wxString& defaultValue, wxWindow *parent,
13d13a9e 1192 wxCoord x, wxCoord y, bool centre )
7c072018
VZ
1193{
1194 wxString str;
13d13a9e
WS
1195 long style = wxTextEntryDialogStyle;
1196
1197 if (centre)
1198 style |= wxCENTRE;
1199 else
1200 style &= ~wxCENTRE;
1201
1202 wxTextEntryDialog dialog(parent, message, caption, defaultValue, style, wxPoint(x, y));
1203
7c072018
VZ
1204 if (dialog.ShowModal() == wxID_OK)
1205 {
1206 str = dialog.GetValue();
1207 }
0fb67cd1 1208
7c072018 1209 return str;
518b5d2f
VZ
1210}
1211
7c072018
VZ
1212wxString wxGetPasswordFromUser(const wxString& message,
1213 const wxString& caption,
1214 const wxString& defaultValue,
b3bb2a74
KH
1215 wxWindow *parent,
1216 wxCoord x, wxCoord y, bool centre )
96c5bd7f 1217{
7c072018 1218 wxString str;
b3bb2a74
KH
1219 long style = wxTextEntryDialogStyle;
1220
1221 if (centre)
1222 style |= wxCENTRE;
1223 else
1224 style &= ~wxCENTRE;
1225
12cfa304
KH
1226 wxPasswordEntryDialog dialog(parent, message, caption, defaultValue,
1227 style, wxPoint(x, y));
7c072018
VZ
1228 if ( dialog.ShowModal() == wxID_OK )
1229 {
1230 str = dialog.GetValue();
1231 }
96c5bd7f 1232
7c072018
VZ
1233 return str;
1234}
96c5bd7f 1235
7c072018 1236#endif // wxUSE_TEXTDLG
96c5bd7f 1237
7c072018 1238#if wxUSE_COLOURDLG
96c5bd7f 1239
f14d6dd1 1240wxColour wxGetColourFromUser(wxWindow *parent, const wxColour& colInit, const wxString& caption)
c51deffc 1241{
7c072018 1242 wxColourData data;
cb719f2e 1243 data.SetChooseFull(true);
7c072018
VZ
1244 if ( colInit.Ok() )
1245 {
1246 data.SetColour((wxColour &)colInit); // const_cast
1247 }
c51deffc 1248
7c072018
VZ
1249 wxColour colRet;
1250 wxColourDialog dialog(parent, &data);
76b49cf4 1251 if (!caption.empty())
f14d6dd1 1252 dialog.SetTitle(caption);
7c072018
VZ
1253 if ( dialog.ShowModal() == wxID_OK )
1254 {
1255 colRet = dialog.GetColourData().GetColour();
1256 }
1257 //else: leave it invalid
1258
1259 return colRet;
c51deffc 1260}
bc385ba9 1261
7c072018 1262#endif // wxUSE_COLOURDLG
bc385ba9 1263
7c072018
VZ
1264#if wxUSE_FONTDLG
1265
f14d6dd1 1266wxFont wxGetFontFromUser(wxWindow *parent, const wxFont& fontInit, const wxString& caption)
bc385ba9 1267{
7c072018
VZ
1268 wxFontData data;
1269 if ( fontInit.Ok() )
bc385ba9 1270 {
7c072018
VZ
1271 data.SetInitialFont(fontInit);
1272 }
bc385ba9 1273
7c072018
VZ
1274 wxFont fontRet;
1275 wxFontDialog dialog(parent, data);
76b49cf4 1276 if (!caption.empty())
f14d6dd1 1277 dialog.SetTitle(caption);
7c072018
VZ
1278 if ( dialog.ShowModal() == wxID_OK )
1279 {
1280 fontRet = dialog.GetFontData().GetChosenFont();
1281 }
1282 //else: leave it invalid
bc385ba9 1283
7c072018 1284 return fontRet;
bc385ba9
VZ
1285}
1286
7c072018 1287#endif // wxUSE_FONTDLG
2b5f62a0 1288
7c072018
VZ
1289// ----------------------------------------------------------------------------
1290// wxSafeYield and supporting functions
1291// ----------------------------------------------------------------------------
2b5f62a0 1292
7c072018
VZ
1293void wxEnableTopLevelWindows(bool enable)
1294{
df5168c4 1295 wxWindowList::compatibility_iterator node;
7c072018
VZ
1296 for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
1297 node->GetData()->Enable(enable);
1298}
2b5f62a0 1299
7c072018
VZ
1300wxWindowDisabler::wxWindowDisabler(wxWindow *winToSkip)
1301{
1302 // remember the top level windows which were already disabled, so that we
1303 // don't reenable them later
1304 m_winDisabled = NULL;
1305
df5168c4 1306 wxWindowList::compatibility_iterator node;
7c072018 1307 for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
2b5f62a0 1308 {
7c072018
VZ
1309 wxWindow *winTop = node->GetData();
1310 if ( winTop == winToSkip )
1311 continue;
2b5f62a0 1312
7c072018
VZ
1313 // we don't need to disable the hidden or already disabled windows
1314 if ( winTop->IsEnabled() && winTop->IsShown() )
2b5f62a0 1315 {
7c072018 1316 winTop->Disable();
2b5f62a0
VZ
1317 }
1318 else
1319 {
7c072018
VZ
1320 if ( !m_winDisabled )
1321 {
1322 m_winDisabled = new wxWindowList;
1323 }
1324
1325 m_winDisabled->Append(winTop);
2b5f62a0
VZ
1326 }
1327 }
2b5f62a0
VZ
1328}
1329
7c072018 1330wxWindowDisabler::~wxWindowDisabler()
cd6ce4a9 1331{
df5168c4 1332 wxWindowList::compatibility_iterator node;
7c072018 1333 for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
cd6ce4a9 1334 {
7c072018
VZ
1335 wxWindow *winTop = node->GetData();
1336 if ( !m_winDisabled || !m_winDisabled->Find(winTop) )
cd6ce4a9 1337 {
7c072018 1338 winTop->Enable();
cd6ce4a9 1339 }
7c072018 1340 //else: had been already disabled, don't reenable
cd6ce4a9 1341 }
f6bcfd97 1342
7c072018 1343 delete m_winDisabled;
f6bcfd97
BP
1344}
1345
7c072018
VZ
1346// Yield to other apps/messages and disable user input to all windows except
1347// the given one
1348bool wxSafeYield(wxWindow *win, bool onlyIfNeeded)
f6bcfd97 1349{
7c072018 1350 wxWindowDisabler wd(win);
21709999 1351
7c072018
VZ
1352 bool rc;
1353 if (onlyIfNeeded)
1354 rc = wxYieldIfNeeded();
1355 else
1356 rc = wxYield();
8461e4c2 1357
7c072018 1358 return rc;
8461e4c2
VZ
1359}
1360
7c072018
VZ
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
1363// in utilsgtk.cpp.
1364#ifndef __WXGTK__
1365bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
8461e4c2 1366{
cb719f2e 1367 return true; // detectable auto-repeat is the only mode MSW supports
8461e4c2 1368}
7c072018
VZ
1369#endif // !wxGTK
1370
1371#endif // wxUSE_GUI