]> git.saurik.com Git - wxWidgets.git/blob - src/unix/apptraits.cpp
extracted GUI-specific part of utilsunx.cpp to a new unix/apptraits.cpp file and...
[wxWidgets.git] / src / unix / apptraits.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/unix/apptraits.cpp
3 // Purpose: implementation of wxGUIAppTraits for Unix systems
4 // Author: Vadim Zeitlin
5 // Created: 2008-03-22
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #ifndef WX_PRECOMP
27 #endif // WX_PRECOMP
28
29 #include "wx/apptrait.h"
30 #include "wx/unix/execute.h"
31
32 // ============================================================================
33 // implementation
34 // ============================================================================
35
36 int wxGUIAppTraits::WaitForChild(wxExecuteData& execData)
37 {
38 const int flags = execData.flags;
39 if ( !(flags & wxEXEC_SYNC) || (flags & wxEXEC_NOEVENTS) )
40 {
41 // async or blocking sync cases are already handled by the base class
42 // just fine, no need to duplicate its code here
43 return wxAppTraits::WaitForChild(execData);
44 }
45
46 // here we're dealing with the case of synchronous execution when we want
47 // to process the GUI events while waiting for the child termination
48
49 wxEndProcessData endProcData;
50
51 // we may have process for capturing the program output, but it's
52 // not used in wxEndProcessData in the case of sync execution
53 endProcData.process = NULL;
54
55 // sync execution: indicate it by negating the pid
56 endProcData.pid = -execData.pid;
57
58 endProcData.tag = AddProcessCallback
59 (
60 &endProcData,
61 execData.pipeEndProcDetect.Detach(wxPipe::Read)
62 );
63
64 execData.pipeEndProcDetect.Close();
65
66
67 // prepare to wait for the child termination: show to the user that we're
68 // busy and refuse all input unless explicitly told otherwise
69 wxBusyCursor bc;
70 wxWindowDisabler wd(!(flags & wxEXEC_NODISABLE));
71
72 // endProcData.pid will be set to 0 from wxHandleProcessTermination() when
73 // the process terminates
74 while ( endProcData.pid != 0 )
75 {
76 // don't consume 100% of the CPU while we're sitting in this
77 // loop
78 if ( !CheckForRedirectedIO(execData) )
79 wxMilliSleep(1);
80
81 // give the toolkit a chance to call wxHandleProcessTermination() here
82 // and also repaint the GUI and handle other accumulated events
83 wxYield();
84 }
85
86 return endProcData.exitcode;
87 }
88
89