~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/widget/src/os2/nsAppShell.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Mozilla Public License
 
6
 * Version 1.1 (the "License"); you may not use this file except in
 
7
 * compliance with the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/MPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
17
 * The Initial Developer of the Original Code is 
 
18
 * IBM Corporation.
 
19
 * Portions created by the Initial Developer are Copyright (C) 2003
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *  Michael Lowe <michael.lowe@bigfoot.com>
 
24
 *  John Fairhurst <john_fairhurst@iname.com>
 
25
 *
 
26
 * Alternatively, the contents of this file may be used under the terms of
 
27
 * either the GNU General Public License Version 2 or later (the "GPL"), or 
 
28
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
29
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
30
 * of those above. If you wish to allow use of your version of this file only
 
31
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
32
 * use your version of this file under the terms of the NPL, indicate your
 
33
 * decision by deleting the provisions above and replace them with the notice
 
34
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
35
 * the provisions above, a recipient may use your version of this file under
 
36
 * the terms of any one of the NPL, the GPL or the LGPL.
 
37
 *
 
38
 * ***** END LICENSE BLOCK ***** */
 
39
 
 
40
#include "nsAppShell.h"
 
41
#include "nsToolkit.h"
 
42
#include "nsIWidget.h"
 
43
#include "nsIEventQueueService.h"
 
44
#include "nsIServiceManager.h"
 
45
 
 
46
#include "nsWidgetsCID.h"
 
47
 
 
48
NS_IMPL_ISUPPORTS1(nsAppShell, nsIAppShell) 
 
49
 
 
50
static int gKeepGoing = 1;
 
51
//-------------------------------------------------------------------------
 
52
//
 
53
// nsAppShell constructor
 
54
//
 
55
//-------------------------------------------------------------------------
 
56
nsAppShell::nsAppShell()  
 
57
 
58
}
 
59
 
 
60
 
 
61
 
 
62
//-------------------------------------------------------------------------
 
63
//
 
64
// Create the application shell
 
65
//
 
66
//-------------------------------------------------------------------------
 
67
 
 
68
NS_METHOD nsAppShell::Create(int* argc, char ** argv)
 
69
{
 
70
  return NS_OK;
 
71
}
 
72
 
 
73
//-------------------------------------------------------------------------
 
74
//
 
75
// Enter a message handler loop
 
76
//
 
77
//-------------------------------------------------------------------------
 
78
 
 
79
#include "nsITimerManager.h"
 
80
 
 
81
NS_METHOD nsAppShell::Run(void)
 
82
{
 
83
  NS_ADDREF_THIS();
 
84
  QMSG  qmsg;
 
85
  int  keepGoing = 1;
 
86
 
 
87
  nsresult rv;
 
88
  nsCOMPtr<nsITimerManager> timerManager(do_GetService("@mozilla.org/timer/manager;1", &rv));
 
89
  if (NS_FAILED(rv)) return rv;
 
90
 
 
91
  // Using idle timers breaks drag drop, so turn it off for now
 
92
  timerManager->SetUseIdleTimers(PR_FALSE);
 
93
 
 
94
  gKeepGoing = 1;
 
95
  // Process messages
 
96
  do {
 
97
    // Give priority to system messages (in particular keyboard, mouse,
 
98
    // timer, and paint messages).
 
99
    if (WinPeekMsg((HAB)0, &qmsg, NULL, WM_CHAR, WM_VIOCHAR, PM_REMOVE) ||
 
100
        WinPeekMsg((HAB)0, &qmsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE) ||
 
101
        WinPeekMsg((HAB)0, &qmsg, NULL, 0, WM_USER-1, PM_REMOVE) ||
 
102
        WinPeekMsg((HAB)0, &qmsg, NULL, 0, 0, PM_REMOVE)) {
 
103
      keepGoing = (qmsg.msg != WM_QUIT);
 
104
 
 
105
      if (keepGoing != 0) {
 
106
        WinDispatchMsg((HAB)0, &qmsg);
 
107
      } else {
 
108
        if ((qmsg.hwnd) && (qmsg.mp1 || qmsg.mp2)) {
 
109
          // If close is selected from the task list, only close
 
110
          // that window, not the entire application
 
111
          WinSendMsg(qmsg.hwnd, WM_SYSCOMMAND, MPFROMSHORT(SC_CLOSE), 0);
 
112
          keepGoing = 1;
 
113
        }
 
114
      }
 
115
    } else {
 
116
 
 
117
      PRBool hasTimers;
 
118
      timerManager->HasIdleTimers(&hasTimers);
 
119
      if (hasTimers) {
 
120
        do {
 
121
          timerManager->FireNextIdleTimer();
 
122
          timerManager->HasIdleTimers(&hasTimers);
 
123
        } while (hasTimers && WinPeekMsg((HAB)0, &qmsg, NULL, 0, 0, PM_NOREMOVE));
 
124
      } else {
 
125
 
 
126
        if (!gKeepGoing) {
 
127
          // In this situation, PostQuitMessage() was called, but the WM_QUIT
 
128
          // message was removed from the event queue by someone else -
 
129
          // (see bug #54725).  So, just exit the loop as if WM_QUIT had been
 
130
          // reeceived...
 
131
          keepGoing = 0;
 
132
          printf("here\n");
 
133
        } else {
 
134
          // Block and wait for any posted application message
 
135
          ::WinWaitMsg((HAB)0, 0, 0);
 
136
        }
 
137
      }
 
138
    }
 
139
 
 
140
  } while (keepGoing != 0);
 
141
  Release();
 
142
  return NS_OK;
 
143
}
 
144
 
 
145
inline NS_METHOD nsAppShell::Spinup(void)
 
146
{ return NS_OK; }
 
147
 
 
148
inline NS_METHOD nsAppShell::Spindown(void)
 
149
{ return NS_OK; }
 
150
 
 
151
inline NS_METHOD nsAppShell::ListenToEventQueue(nsIEventQueue * aQueue, PRBool aListen)
 
152
{ return NS_OK; }
 
153
 
 
154
NS_METHOD
 
155
nsAppShell::GetNativeEvent(PRBool &aRealEvent, void *&aEvent)
 
156
{
 
157
  static QMSG qmsg;
 
158
 
 
159
  PRBool gotMessage = PR_FALSE;
 
160
 
 
161
  nsresult rv;
 
162
  nsCOMPtr<nsITimerManager> timerManager(do_GetService("@mozilla.org/timer/manager;1", &rv));
 
163
  if (NS_FAILED(rv)) return rv;
 
164
 
 
165
  do {
 
166
    // Give priority to system messages (in particular keyboard, mouse,
 
167
    // timer, and paint messages).
 
168
    if (WinPeekMsg((HAB)0, &qmsg, NULL, WM_CHAR, WM_VIOCHAR, PM_REMOVE) ||
 
169
        WinPeekMsg((HAB)0, &qmsg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE) || 
 
170
        WinPeekMsg((HAB)0, &qmsg, NULL, 0, WM_USER-1, PM_REMOVE) || 
 
171
        WinPeekMsg((HAB)0, &qmsg, NULL, 0, 0, PM_REMOVE)) {
 
172
      gotMessage = PR_TRUE;
 
173
    } else {
 
174
      PRBool hasTimers;
 
175
      timerManager->HasIdleTimers(&hasTimers);
 
176
      if (hasTimers) {
 
177
        do {
 
178
          timerManager->FireNextIdleTimer();
 
179
          timerManager->HasIdleTimers(&hasTimers);
 
180
        } while (hasTimers && WinPeekMsg((HAB)0, &qmsg, NULL, 0, 0, PM_NOREMOVE));
 
181
      } else {
 
182
        // Block and wait for any posted application message
 
183
        ::WinWaitMsg((HAB)0, 0, 0);
 
184
      }
 
185
    }
 
186
 
 
187
  } while (gotMessage == PR_FALSE);
 
188
 
 
189
#ifdef DEBUG_danm
 
190
  if (qmsg.msg != WM_TIMER)
 
191
    printf("-> %d", qmsg.msg);
 
192
#endif
 
193
 
 
194
  aEvent = &qmsg;
 
195
  aRealEvent = PR_TRUE;
 
196
  return NS_OK;
 
197
}
 
198
 
 
199
nsresult nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void *aEvent)
 
200
{
 
201
  WinDispatchMsg((HAB)0, (QMSG *)aEvent);
 
202
  return NS_OK;
 
203
}
 
204
 
 
205
//-------------------------------------------------------------------------
 
206
//
 
207
// Exit a message handler loop
 
208
//
 
209
//-------------------------------------------------------------------------
 
210
 
 
211
NS_METHOD nsAppShell::Exit(void)
 
212
{
 
213
  WinPostQueueMsg(HMQ_CURRENT, WM_QUIT, 0, 0);
 
214
  //
 
215
  // Also, set a global flag, just in case someone eats the WM_QUIT message.
 
216
  // see bug #54725.
 
217
  //
 
218
  gKeepGoing = 0;
 
219
  return NS_OK;
 
220
}
 
221
 
 
222
//-------------------------------------------------------------------------
 
223
//
 
224
// nsAppShell destructor
 
225
//
 
226
//-------------------------------------------------------------------------
 
227
nsAppShell::~nsAppShell()
 
228
{
 
229
}
 
230