FILE COMPARISON
Produced: 2/18/2011 1:26:20 PM
   
Mode:  All Lines  
   
Left file: C:\Documents and Settings\krollins\My Documents\Admin\OpenSource\eRCP\eSWT\current\source\modified\original\Shell.c  
Right file: C:\Documents and Settings\krollins\My Documents\Admin\OpenSource\eRCP\eSWT\current\source\modified\Shell.c  
1 /******************************************************************************* = 1 /*******************************************************************************
2 * Copyright (c) 2000, 2005 IBM Corporation and others.   2 * Copyright (c) 2000, 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials   3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0   4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at   5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html   6 * http://www.eclipse.org/legal/epl-v10.html
7 *   7 *
8 * Contributors:   8 * Contributors:
9 *     IBM Corporation - initial API and implementation   9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/   10 *******************************************************************************/
    <> 11 /*******************************************************************************
      12 * Additions/modifications to this source file by Oracle America, Inc. 2011
      13 *******************************************************************************/
11   = 14  
12 #include "ugl_win32.h"   15 #include "ugl_win32.h"
13     16  
14 #if _WIN32_WCE   17 #if _WIN32_WCE
15     18  
16 #if (_WIN32_WCE >= 420)   19 #if (_WIN32_WCE >= 420)
17 #include <aygshell.h>   20 #include <aygshell.h>
18 #endif /* _WIN32_WCE >= 420 */   21 #endif /* _WIN32_WCE >= 420 */
19     22  
20 #if !(WIN32_PLATFORM_PSPC) && !(WIN32_PLATFORM_WFSP)    23 #if !(WIN32_PLATFORM_PSPC) && !(WIN32_PLATFORM_WFSP) 
21 #include "Commctrl.h"   24 #include "Commctrl.h"
22 #endif /* !(WIN32_PLATFORM_PSPC) && !(WIN32_PLATFORM_WFSP) */   25 #endif /* !(WIN32_PLATFORM_PSPC) && !(WIN32_PLATFORM_WFSP) */
23     26  
24 #endif /* _WIN32_WCE */   27 #endif /* _WIN32_WCE */
25     28  
26 #include "Image.h"   29 #include "Image.h"
27 #include "Ugl_Win32_DC.h"   30 #include "Ugl_Win32_DC.h"
28 #include "UGL_Win32_Menu.h"   31 #include "UGL_Win32_Menu.h"
29 #include "Graphics.h"   32 #include "Graphics.h"
30 #include "Widget.h"   33 #include "Widget.h"
31 #include "UGL_Win32_Widget.h"   34 #include "UGL_Win32_Widget.h"
32     35  
33 #include "Control.h"   36 #include "Control.h"
34 #include "Shell.h"   37 #include "Shell.h"
35 #include "Menu.h"   38 #include "Menu.h"
36     39  
37 #ifdef _WIN32_WCE   40 #ifdef _WIN32_WCE
38 #define SHELL_WINDOW_CLASS _T("Dialog")   41 #define SHELL_WINDOW_CLASS _T("Dialog")
39 #else   42 #else
40 #define SHELL_WINDOW_CLASS _T("#32770")   43 #define SHELL_WINDOW_CLASS _T("#32770")
41 #endif   44 #endif
42     45  
43 static UGL_Int _Shell_ExStyle(UGL_Int ugl_style, BOOL isChild);   46 static UGL_Int _Shell_ExStyle(UGL_Int ugl_style, BOOL isChild);
44 static UGL_Int _Shell_Style(UGL_Int ugl_style, BOOL isChild);   47 static UGL_Int _Shell_Style(UGL_Int ugl_style, BOOL isChild);
45 static UGL_Int _Shell_New(UGL_Int parentHandle, UGL_Int displayHandle, UGL_Int ugl_style, UGL_Error uglError);   48 static UGL_Int _Shell_New(UGL_Int parentHandle, UGL_Int displayHandle, UGL_Int ugl_style, UGL_Error uglError);
46 static void _Shell_MoveAbove(PUGL_Control control, PUGL_Control sibling, UGL_Error error);   49 static void _Shell_MoveAbove(PUGL_Control control, PUGL_Control sibling, UGL_Error error);
47 static UGL_Boolean _Shell_GetMaximized(PUGL_Shell shell);   50 static UGL_Boolean _Shell_GetMaximized(PUGL_Shell shell);
48     51  
49 void _Shell_GetMinimumSize(UGL_Int handle, POINT *point, UGL_Error uglError);   52 void _Shell_GetMinimumSize(UGL_Int handle, POINT *point, UGL_Error uglError);
50 void _Dispose_Shell(UGL_Int handle, UGL_Error uglError);   53 void _Dispose_Shell(UGL_Int handle, UGL_Error uglError);
51 static LRESULT CALLBACK _Shell_Proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);   54 static LRESULT CALLBACK _Shell_Proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
52 //========================================================================================   55 //========================================================================================
53     56  
54 UGL_Int Shell_New(UGL_Int displayHandle, UGL_Int ugl_style, UGL_Error uglError) {   57 UGL_Int Shell_New(UGL_Int displayHandle, UGL_Int ugl_style, UGL_Error uglError) {
55     return _Shell_New(0, displayHandle, ugl_style, uglError);   58     return _Shell_New(0, displayHandle, ugl_style, uglError);
56 }   59 }
57     60  
58 //========================================================================================   61 //========================================================================================
59     62  
60 #if defined(WIN32_PLATFORM_PSPC)   63 #if defined(WIN32_PLATFORM_PSPC)
61 /**   64 /**
62 * Ensures that the menubar associated with the specified shell   65 * Ensures that the menubar associated with the specified shell
63 * is visible to the user.   66 * is visible to the user.
64 *   67 *
65 * PocketPC menubars are floating top-level windows which   68 * PocketPC menubars are floating top-level windows which
66 * need to be shown and hidden in conjuntion with showing   69 * need to be shown and hidden in conjuntion with showing
67 * and hiding their owning window.    70 * and hiding their owning window. 
68 */   71 */
69 void _Shell_EnsureMenuBarIsVisible(UGL_Shell* shell, UGL_Control* parent) {   72 void _Shell_EnsureMenuBarIsVisible(UGL_Shell* shell, UGL_Control* parent) {
70     73  
71     int i;   74     int i;
72     BOOL hasSubMenu, useSoftkey;   75     BOOL hasSubMenu, useSoftkey;
73     PUGL_Display display = UGL_WIDGET(shell)->display;   76     PUGL_Display display = UGL_WIDGET(shell)->display;
74     hasSubMenu = FALSE;   77     hasSubMenu = FALSE;
75     useSoftkey = FALSE;   78     useSoftkey = FALSE;
76     79  
77 #if defined (WIN32_PLATFORM_PSPC)   80 #if defined (WIN32_PLATFORM_PSPC)
78     useSoftkey = TRUE;   81     useSoftkey = TRUE;
79 #endif   82 #endif
80     83  
81     for(i = 0; i<display->menuItemsLength; i++){   84     for(i = 0; i<display->menuItemsLength; i++){
82         if(display->menuItems[i] != NULL && display->menuItems[i]->parent_menu->hwndCB != 0){   85         if(display->menuItems[i] != NULL && display->menuItems[i]->parent_menu->hwndCB != 0){
83             if(display->menuItems[i]->hasSubMenu){   86             if(display->menuItems[i]->hasSubMenu){
84                 hasSubMenu = TRUE;   87                 hasSubMenu = TRUE;
85             }   88             }
86         }   89         }
87     }   90     }
88     if(parent == NULL){   91     if(parent == NULL){
89         UGL_Menu* menubar = shell->ugl_menu == NULL ? shell->emptyMenu : shell->ugl_menu;   92         UGL_Menu* menubar = shell->ugl_menu == NULL ? shell->emptyMenu : shell->ugl_menu;
90         // Show the new menubar   93         // Show the new menubar
91         // new for softkey, check device Major version   94         // new for softkey, check device Major version
92         if(Platform_GetMajorVersion() >= 5 && useSoftkey){   95         if(Platform_GetMajorVersion() >= 5 && useSoftkey){
93             if(UGL_WIDGET(shell)->display->menuItemCount>2 || hasSubMenu){   96             if(UGL_WIDGET(shell)->display->menuItemCount>2 || hasSubMenu){
94                 ShowWindow(menubar->hwndMB, SW_SHOW);   97                 ShowWindow(menubar->hwndMB, SW_SHOW);
95             } else {      98             } else {   
96                 ShowWindow(menubar->hwndCB, SW_SHOW);   99                 ShowWindow(menubar->hwndCB, SW_SHOW);
97             }   100             }
98         } else {   101         } else {
99             ShowWindow(menubar->hwndCB, SW_SHOW);   102             ShowWindow(menubar->hwndCB, SW_SHOW);
100         }   103         }
101     104  
102         if (_Shell_GetMaximized(shell)) Shell_SetMaximized((UGL_Int)shell, TRUE, NULL);   105         if (_Shell_GetMaximized(shell)) Shell_SetMaximized((UGL_Int)shell, TRUE, NULL);
103     } else {   106     } else {
104     107  
105         if(shell->ugl_menu != NULL)   108         if(shell->ugl_menu != NULL)
106         {   109         {
107             UGL_Menu* menubar = shell->ugl_menu;   110             UGL_Menu* menubar = shell->ugl_menu;
108         // new for softkey, check device Major version   111         // new for softkey, check device Major version
109         if(Platform_GetMajorVersion() >= 5 && useSoftkey){   112         if(Platform_GetMajorVersion() >= 5 && useSoftkey){
110             if(UGL_WIDGET(shell)->display->menuItemCount>2 || hasSubMenu){   113             if(UGL_WIDGET(shell)->display->menuItemCount>2 || hasSubMenu){
111                 ShowWindow(menubar->hwndMB, SW_SHOW);   114                 ShowWindow(menubar->hwndMB, SW_SHOW);
112             } else {      115             } else {   
113                 ShowWindow(menubar->hwndCB, SW_SHOW);   116                 ShowWindow(menubar->hwndCB, SW_SHOW);
114             }   117             }
115         } else {   118         } else {
116             ShowWindow(menubar->hwndCB, SW_SHOW);   119             ShowWindow(menubar->hwndCB, SW_SHOW);
117         }   120         }
118               121            
119     122  
120         if (_Shell_GetMaximized(shell)) Shell_SetMaximized((UGL_Int)shell, TRUE, NULL);   123         if (_Shell_GetMaximized(shell)) Shell_SetMaximized((UGL_Int)shell, TRUE, NULL);
121         }   124         }
122     }   125     }
123       126    
124 }   127 }
125 #endif /* WIN32_PLATFORM_PSPC */   128 #endif /* WIN32_PLATFORM_PSPC */
126     129  
127 //========================================================================================   130 //========================================================================================
128     131  
129 void Shell_SetText(UGL_Int handle, UGL_String text, UGL_Error uglError) {   132 void Shell_SetText(UGL_Int handle, UGL_String text, UGL_Error uglError) {
130     PUGL_Control shell = (PUGL_Control)handle;   133     PUGL_Control shell = (PUGL_Control)handle;
131     HWND hWnd = shell->hWnd;   134     HWND hWnd = shell->hWnd;
132     135  
133     // assumes text is correctly formed   136     // assumes text is correctly formed
134     SetWindowText(hWnd, text);   137     SetWindowText(hWnd, text);
135 }   138 }
136 //========================================================================================   139 //========================================================================================
137     140  
138 void Shell_SetMaximized(UGL_Int handle, UGL_Boolean maximized, UGL_Error uglError) {   141 void Shell_SetMaximized(UGL_Int handle, UGL_Boolean maximized, UGL_Error uglError) {
139     PUGL_Control control = (PUGL_Control)handle;   142     PUGL_Control control = (PUGL_Control)handle;
140     HWND hWnd = control->hWnd;   143     HWND hWnd = control->hWnd;
141     RECT rect;   144     RECT rect;
142     int width, height;   145     int width, height;
143     int flags;   146     int flags;
144     147  
145     148  
146 #ifdef _WIN32_WCE   149 #ifdef _WIN32_WCE
147     /*   150     /*
148     * Note: WinCE does not support SW_SHOWMAXIMIZED and SW_RESTORE. The   151     * Note: WinCE does not support SW_SHOWMAXIMIZED and SW_RESTORE. The
149     * workaround is to resize the window to fit the parent client area.   152     * workaround is to resize the window to fit the parent client area.
150     */   153     */
151     PUGL_Shell shell = UGL_SHELL(handle);   154     PUGL_Shell shell = UGL_SHELL(handle);
152     if (maximized) {   155     if (maximized) {
153         if(shell->state == MINIMIZED){   156         if(shell->state == MINIMIZED){
154             ShowWindow(hWnd, SW_RESTORE);   157             ShowWindow(hWnd, SW_RESTORE);
155         }   158         }
156         ShowWindow(hWnd, SW_MAXIMIZE);   159         ShowWindow(hWnd, SW_MAXIMIZE);
157         shell->state = MAXIMIZED;         160         shell->state = MAXIMIZED;      
158     161  
159 #if defined(WIN32_PLATFORM_PSPC)   162 #if defined(WIN32_PLATFORM_PSPC)
160         SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);   163         SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
161         width = rect.right - rect.left;   164         width = rect.right - rect.left;
162         height = rect.bottom - rect.top;   165         height = rect.bottom - rect.top;
163         {   166         {
164         UGL_Shell* shell = UGL_SHELL(control);   167         UGL_Shell* shell = UGL_SHELL(control);
165         /* Leave space for the menu bar */   168         /* Leave space for the menu bar */
166         if ((shell->ugl_menu != NULL) || (shell->emptyMenu != NULL)) {   169         if ((shell->ugl_menu != NULL) || (shell->emptyMenu != NULL)) {
167             HWND hwndCB = shell->ugl_menu != NULL ? shell->ugl_menu->hwndCB : shell->emptyMenu->hwndCB;   170             HWND hwndCB = shell->ugl_menu != NULL ? shell->ugl_menu->hwndCB : shell->emptyMenu->hwndCB;
168             RECT rectCB;   171             RECT rectCB;
169     172  
170             GetWindowRect(hwndCB, &rectCB);   173             GetWindowRect(hwndCB, &rectCB);
171             height -= rectCB.bottom - rectCB.top;   174             height -= rectCB.bottom - rectCB.top;
172         }   175         }
173         }   176         }
174     177  
    <> 178         {
      179         /* Leave space for SIP */
      180         SIPINFO si;
      181         memset(&si, 0, sizeof(SIPINFO));
      182         si.cbSize = sizeof(SIPINFO);
      183         if (SipGetInfo(&si)) {
      184             flags = SIPF_ON | SIPF_DOCKED;
      185             if ((si.fdwFlags & flags) == flags)
      186             {
      187                 height -= si.rcSipRect.bottom - si.rcSipRect.top;
      188             }
      189         }
      190         }
175   = 191  
176         if ((control->widget.ugl_style & (UGL_STYLE_BORDER)) == UGL_STYLE_BORDER) {   192         if ((control->widget.ugl_style & (UGL_STYLE_BORDER)) == UGL_STYLE_BORDER) {
177             LONG styleBits = GetWindowLong(hWnd, GWL_STYLE) & ~WS_BORDER;   193             LONG styleBits = GetWindowLong(hWnd, GWL_STYLE) & ~WS_BORDER;
178             SetWindowLong(hWnd, GWL_STYLE, styleBits);   194             SetWindowLong(hWnd, GWL_STYLE, styleBits);
179     195  
180             styleBits = GetWindowLong(hWnd, GWL_EXSTYLE) & ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_STATICEDGE | WS_EX_CLIENTEDGE);   196             styleBits = GetWindowLong(hWnd, GWL_EXSTYLE) & ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_STATICEDGE | WS_EX_CLIENTEDGE);
181             SetWindowLong(hWnd, GWL_EXSTYLE, styleBits);   197             SetWindowLong(hWnd, GWL_EXSTYLE, styleBits);
182         }   198         }
183     199  
184         flags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;   200         flags = SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE;
185         _SetWindowPos(hWnd, NULL, rect.left, rect.top, width, height, flags);     201         _SetWindowPos(hWnd, NULL, rect.left, rect.top, width, height, flags);  
186 #endif // is PPC   202 #endif // is PPC
187     }   203     }
188     // else if normal   204     // else if normal
189     else{   205     else{
190         shell->state = NORMAL;   206         shell->state = NORMAL;
191         ShowWindow(hWnd, SW_RESTORE);   207         ShowWindow(hWnd, SW_RESTORE);
192     }   208     }
193     209  
194 #else   210 #else
195     int swFlags = maximized ? SW_SHOWMAXIMIZED : SW_RESTORE;   211     int swFlags = maximized ? SW_SHOWMAXIMIZED : SW_RESTORE;
196     212  
197     UGL_SHELL(handle)->state = maximized ? MAXIMIZED : NORMAL;   213     UGL_SHELL(handle)->state = maximized ? MAXIMIZED : NORMAL;
198     214  
199     if (!IsWindowVisible(hWnd)) return;   215     if (!IsWindowVisible(hWnd)) return;
200     if (maximized == IsZoomed(hWnd)) return;   216     if (maximized == IsZoomed(hWnd)) return;
201           217        
202     ShowWindow (hWnd, swFlags);   218     ShowWindow (hWnd, swFlags);
203     UpdateWindow(hWnd);   219     UpdateWindow(hWnd);
204     220  
205 #endif   221 #endif
206 }   222 }
207 //========================================================================================   223 //========================================================================================
208     224  
209 void Shell_Close(UGL_Int shellHandle, UGL_Error uglError) {   225 void Shell_Close(UGL_Int shellHandle, UGL_Error uglError) {
210     // TODO: remove this method when api is gone   226     // TODO: remove this method when api is gone
211 //  PUGL_Control ugl_widget = (PUGL_Control)shellHandle;   227 //  PUGL_Control ugl_widget = (PUGL_Control)shellHandle;
212     228  
213 //  PostMessage(ugl_widget->hWnd, WM_CLOSE, 0, 0);   229 //  PostMessage(ugl_widget->hWnd, WM_CLOSE, 0, 0);
214 }   230 }
215 //========================================================================================   231 //========================================================================================
216     232  
217     233  
218 //========================================================================================   234 //========================================================================================
219     235  
220 UGL_Int _Shell_ExStyle(UGL_Int ugl_style, BOOL isChild) {   236 UGL_Int _Shell_ExStyle(UGL_Int ugl_style, BOOL isChild) {
221     int style = 0;   237     int style = 0;
222     238  
223 #ifndef _WIN32_WCE    239 #ifndef _WIN32_WCE 
224       240    
225     //if (IS_FLAG_SET(ugl_style, UGL_STYLE_BORDER)) SET_FLAG(style, WS_EX_CLIENTEDGE);   241     //if (IS_FLAG_SET(ugl_style, UGL_STYLE_BORDER)) SET_FLAG(style, WS_EX_CLIENTEDGE);
226           242        
227     /*   243     /*
228     * Feature in Windows NT.  When CreateWindowEx() is called with   244     * Feature in Windows NT.  When CreateWindowEx() is called with
229     * WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT, CreateWindowEx()   245     * WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT, CreateWindowEx()
230     * fails to create the HWND. The fix is to not use these bits.   246     * fails to create the HWND. The fix is to not use these bits.
231     */   247     */
232     OSVERSIONINFO os_version;   248     OSVERSIONINFO os_version;
233     os_version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);   249     os_version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
234     GetVersionEx((LPOSVERSIONINFO)&os_version);   250     GetVersionEx((LPOSVERSIONINFO)&os_version);
235     // if it is NOT Windows NT   251     // if it is NOT Windows NT
236     if ((os_version.dwMajorVersion << 16 | os_version.dwMinorVersion) >= (4 << 16 | 10))  {   252     if ((os_version.dwMajorVersion << 16 | os_version.dwMinorVersion) >= (4 << 16 | 10))  {
237         SET_FLAG(style, WS_EX_NOINHERITLAYOUT);   253         SET_FLAG(style, WS_EX_NOINHERITLAYOUT);
238         if (IS_FLAG_SET(ugl_style, UGL_STYLE_RIGHT_TO_LEFT)) SET_FLAG(style, WS_EX_LAYOUTRTL);   254         if (IS_FLAG_SET(ugl_style, UGL_STYLE_RIGHT_TO_LEFT)) SET_FLAG(style, WS_EX_LAYOUTRTL);
239     }   255     }
240 #endif   256 #endif
241     257  
242     if (IS_FLAG_SET(ugl_style, UGL_STYLE_BORDER)) SET_FLAG(style, WS_EX_DLGMODALFRAME);   258     if (IS_FLAG_SET(ugl_style, UGL_STYLE_BORDER)) SET_FLAG(style, WS_EX_DLGMODALFRAME);
243     259  
244 #ifndef _WIN32_WCE   260 #ifndef _WIN32_WCE
245     /*   261     /*
246     * Feature in Windows.  When a window that does not have a parent   262     * Feature in Windows.  When a window that does not have a parent
247     * is created, it is automatically added to the Windows Task Bar,   263     * is created, it is automatically added to the Windows Task Bar,
248     * even when it has no title.  The fix is to use WS_EX_TOOLWINDOW   264     * even when it has no title.  The fix is to use WS_EX_TOOLWINDOW
249     * which does not cause the window to appear in the Task Bar.   265     * which does not cause the window to appear in the Task Bar.
250     */   266     */
251       267    
252     if (!isChild) {   268     if (!isChild) {
253         //if (IS_FLAG_SET(ugl_style, UGL_STYLE_APPLICATION_MODAL)) SET_FLAG(style, WS_EX_TOOLWINDOW);   269         //if (IS_FLAG_SET(ugl_style, UGL_STYLE_APPLICATION_MODAL)) SET_FLAG(style, WS_EX_TOOLWINDOW);
254     }   270     }
255     271  
256     /*   272     /*
257     * Bug in Windows 98 and NT.  Creating a window with the   273     * Bug in Windows 98 and NT.  Creating a window with the
258     * WS_EX_TOPMOST extended style can result in a dialog shell   274     * WS_EX_TOPMOST extended style can result in a dialog shell
259     * being moved behind its parent.  The exact case where this   275     * being moved behind its parent.  The exact case where this
260     * happens is a shell with two dialog shell children where   276     * happens is a shell with two dialog shell children where
261     * each dialog child has another hidden dialog child with   277     * each dialog child has another hidden dialog child with
262     * the WS_EX_TOPMOST extended style.  Clicking on either of   278     * the WS_EX_TOPMOST extended style.  Clicking on either of
263     * the visible dialogs causes them to become active but move   279     * the visible dialogs causes them to become active but move
264     * to the back, behind the parent shell.  The fix is to   280     * to the back, behind the parent shell.  The fix is to
265     * disallow the WS_EX_TOPMOST extended style on Windows 98   281     * disallow the WS_EX_TOPMOST extended style on Windows 98
266     * and NT.   282     * and NT.
267     */   283     */
268     if (isChild) {   284     if (isChild) {
269         // if Windows 95   285         // if Windows 95
270         if (os_version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) return style;   286         if (os_version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) return style;
271         if ((os_version.dwMajorVersion << 16 | os_version.dwMinorVersion) < (4 << 16 | 10)) return style;   287         if ((os_version.dwMajorVersion << 16 | os_version.dwMinorVersion) < (4 << 16 | 10)) return style;
272     }   288     }
273     //if (parent != null) {   289     //if (parent != null) {
274     //  if (OS.IsWin95) return bits;   290     //  if (OS.IsWin95) return bits;
275     //  if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) {   291     //  if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) {
276     //      return bits;   292     //      return bits;
277     //  }   293     //  }
278     //}   294     //}
279     295  
280 #endif   296 #endif
281 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)   297 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
282     //if (IS_FLAG_SET(ugl_style, UGL_STYLE_CLOSE) && isChild) SET_FLAG(style, WS_EX_CAPTIONOKBTN);   298     //if (IS_FLAG_SET(ugl_style, UGL_STYLE_CLOSE) && isChild) SET_FLAG(style, WS_EX_CAPTIONOKBTN);
283     if IS_FLAG_SET(ugl_style, UGL_STYLE_CLOSE) SET_FLAG(style, WS_EX_CAPTIONOKBTN); //fix to bug#120258, replace OK button with 'X'   299     if IS_FLAG_SET(ugl_style, UGL_STYLE_CLOSE) SET_FLAG(style, WS_EX_CAPTIONOKBTN); //fix to bug#120258, replace OK button with 'X'
284 #endif   300 #endif
285     //if (IS_FLAG_SET(ugl_style, UGL_STYLE_APPLICATION_MODAL)) SET_FLAG(style, WS_EX_TOPMOST);   301     //if (IS_FLAG_SET(ugl_style, UGL_STYLE_APPLICATION_MODAL)) SET_FLAG(style, WS_EX_TOPMOST);
286     return style;   302     return style;
287 }   303 }
288 //========================================================================================   304 //========================================================================================
289     305  
290 UGL_Int _Shell_Style(UGL_Int ugl_style, BOOL isChild) {   306 UGL_Int _Shell_Style(UGL_Int ugl_style, BOOL isChild) {
291     int style = _Scrollable_Style(ugl_style) & ~(WS_TABSTOP | WS_CHILD);   307     int style = _Scrollable_Style(ugl_style) & ~(WS_TABSTOP | WS_CHILD);
292       308    
293     /* Set the title bits and no-trim bits */   309     /* Set the title bits and no-trim bits */
294     //if ((style & SWT.NO_TRIM) != 0) return bits;   310     //if ((style & SWT.NO_TRIM) != 0) return bits;
295     //if (ugl_style == 0) return style;   311     //if (ugl_style == 0) return style;
296       312    
297     if (ugl_style != 0) {   313     if (ugl_style != 0) {
298     314  
299         /* Set the min and max button bits */   315         /* Set the min and max button bits */
300 #ifndef _WIN32_WCE  /* Minimize and maximize buttons don't make sense for WinCE devices */   316 #ifndef _WIN32_WCE  /* Minimize and maximize buttons don't make sense for WinCE devices */
301         if (IS_FLAG_SET(ugl_style, UGL_STYLE_MIN)) SET_FLAG(style, WS_MINIMIZEBOX);   317         if (IS_FLAG_SET(ugl_style, UGL_STYLE_MIN)) SET_FLAG(style, WS_MINIMIZEBOX);
302         if (IS_FLAG_SET(ugl_style, UGL_STYLE_MAX)) SET_FLAG(style, WS_MAXIMIZEBOX);   318         if (IS_FLAG_SET(ugl_style, UGL_STYLE_MAX)) SET_FLAG(style, WS_MAXIMIZEBOX);
303 #endif        319 #endif     
304     320  
305         /* On PPC use the WS_EX_CAPTIONOKBTN style instead of the WS_SYSMENU style. */   321         /* On PPC use the WS_EX_CAPTIONOKBTN style instead of the WS_SYSMENU style. */
306 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)   322 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
307         if (IS_FLAG_SET(ugl_style, UGL_STYLE_CLOSE) && !isChild) SET_FLAG(style, WS_SYSMENU);   323         if (IS_FLAG_SET(ugl_style, UGL_STYLE_CLOSE) && !isChild) SET_FLAG(style, WS_SYSMENU);
308 #else   324 #else
309         if (IS_FLAG_SET(ugl_style, UGL_STYLE_CLOSE)) SET_FLAG(style, WS_SYSMENU);   325         if (IS_FLAG_SET(ugl_style, UGL_STYLE_CLOSE)) SET_FLAG(style, WS_SYSMENU);
310 #endif   326 #endif
311     327  
312         /* Set the resize, dialog border or border bits */   328         /* Set the resize, dialog border or border bits */
313         //if ((style & SWT.RESIZE) != 0) {   329         //if ((style & SWT.RESIZE) != 0) {
314             /*   330             /*
315             * Note on WinCE PPC.  SWT.RESIZE is used to resize   331             * Note on WinCE PPC.  SWT.RESIZE is used to resize
316             * the Shell according to the state of the IME.   332             * the Shell according to the state of the IME.
317             * It does not set the WS_THICKFRAME style.   333             * It does not set the WS_THICKFRAME style.
318             */   334             */
319             //if (!OS.IsPPC) bits |= OS.WS_THICKFRAME;   335             //if (!OS.IsPPC) bits |= OS.WS_THICKFRAME;
320 //#ifndef _WIN32_WCE   336 //#ifndef _WIN32_WCE
321 //          SET_FLAG(style, WS_THICKFRAME); // makes window resizeable   337 //          SET_FLAG(style, WS_THICKFRAME); // makes window resizeable
322 //#endif   338 //#endif
323         //} else {   339         //} else {
324             //if (IS_FLAG_SET(ugl_style, UGL_STYLE_BORDER)) SET_FLAG(style, WS_BORDER);   340             //if (IS_FLAG_SET(ugl_style, UGL_STYLE_BORDER)) SET_FLAG(style, WS_BORDER);
325         //}   341         //}
326     342  
327     }   343     }
328       344    
329     345  
330     /*   346     /*
331     * Feature in WinCE.  Calling CreateWindowEx () with WS_OVERLAPPED   347     * Feature in WinCE.  Calling CreateWindowEx () with WS_OVERLAPPED
332     * and a parent window causes the new window to become a WS_CHILD of   348     * and a parent window causes the new window to become a WS_CHILD of
333     * the parent instead of a dialog child.  The fix is to use WS_POPUP   349     * the parent instead of a dialog child.  The fix is to use WS_POPUP
334     * for a window with a parent.    350     * for a window with a parent. 
335     *   351     *
336     * Feature in WinCE PPC.  A window without a parent with WS_POPUP   352     * Feature in WinCE PPC.  A window without a parent with WS_POPUP
337     * always shows on top of the Pocket PC 'Today Screen'. The fix   353     * always shows on top of the Pocket PC 'Today Screen'. The fix
338     * is to not set WS_POPUP for a window without a parent on WinCE   354     * is to not set WS_POPUP for a window without a parent on WinCE
339     * devices.   355     * devices.
340     *   356     *
341     * NOTE: WS_POPUP causes CreateWindowEx () to ignore CW_USEDEFAULT   357     * NOTE: WS_POPUP causes CreateWindowEx () to ignore CW_USEDEFAULT
342     * and causes the default window location and size to be zero.   358     * and causes the default window location and size to be zero.
343     */   359     */
344 #if defined(_WIN32_WCE) || defined(WIN32_PLATFORM_WFSP)   360 #if defined(_WIN32_WCE) || defined(WIN32_PLATFORM_WFSP)
345     //if (OS.IsWinCE) {   361     //if (OS.IsWinCE) {
346         //if (OS.IsSP) return bits | OS.WS_POPUP;   362         //if (OS.IsSP) return bits | OS.WS_POPUP;
347     363  
348         if (isChild) SET_FLAG(style, WS_POPUP);   364         if (isChild) SET_FLAG(style, WS_POPUP);
349     365  
350         return style;   366         return style;
351     //}   367     //}
352 #else   368 #else
353       369    
354     /*   370     /*
355     * Use WS_OVERLAPPED for all windows, either dialog or top level   371     * Use WS_OVERLAPPED for all windows, either dialog or top level
356     * so that CreateWindowEx () will respect CW_USEDEFAULT and set   372     * so that CreateWindowEx () will respect CW_USEDEFAULT and set
357     * the default window location and size.   373     * the default window location and size.
358     *   374     *
359     * NOTE:  When a WS_OVERLAPPED window is created, Windows gives   375     * NOTE:  When a WS_OVERLAPPED window is created, Windows gives
360     * the new window WS_CAPTION style bits.  These two constants are   376     * the new window WS_CAPTION style bits.  These two constants are
361     * as follows:   377     * as follows:
362     *   378     *
363     *   WS_OVERLAPPED = 0   379     *   WS_OVERLAPPED = 0
364     *   WS_CAPTION = WS_BORDER | WS_DLGFRAME   380     *   WS_CAPTION = WS_BORDER | WS_DLGFRAME
365     *   381     *
366     */   382     */
367     SET_FLAG(style, WS_OVERLAPPED);   383     SET_FLAG(style, WS_OVERLAPPED);
368     SET_FLAG(style, WS_CAPTION);   384     SET_FLAG(style, WS_CAPTION);
369     //style |= WS_EX_DLGMODALFRAME;   385     //style |= WS_EX_DLGMODALFRAME;
370     return style;   386     return style;
371 #endif   387 #endif
372 }   388 }
373 //========================================================================================   389 //========================================================================================
374     390  
375 UGL_Int _Shell_New(UGL_Int parentHandle, UGL_Int displayHandle, UGL_Int ugl_style, UGL_Error uglError) {   391 UGL_Int _Shell_New(UGL_Int parentHandle, UGL_Int displayHandle, UGL_Int ugl_style, UGL_Error uglError) {
376     PUGL_Control shell = NULL;   392     PUGL_Control shell = NULL;
377     PUGL_Display ugl_display = NULL;   393     PUGL_Display ugl_display = NULL;
378     PUGL_Control ugl_parent = NULL;   394     PUGL_Control ugl_parent = NULL;
379     HWND hWnd, hWndParent = NULL;   395     HWND hWnd, hWndParent = NULL;
380     WNDCLASS lpWndClass;   396     WNDCLASS lpWndClass;
381       397    
382     BOOL is_child = (parentHandle != 0);   398     BOOL is_child = (parentHandle != 0);
383     int extended_style = 0;   399     int extended_style = 0;
384     int style = 0;   400     int style = 0;
385     int bits = 0;   401     int bits = 0;
386     int flags = 0;   402     int flags = 0;
387       403    
388     HINSTANCE hInstance;   404     HINSTANCE hInstance;
389       405    
390     if (is_child) {   406     if (is_child) {
391         ugl_parent = UGL_CONTROL(parentHandle);   407         ugl_parent = UGL_CONTROL(parentHandle);
392         hWndParent = ugl_parent->hWnd;   408         hWndParent = ugl_parent->hWnd;
393         ugl_display = UGL_DISPLAY(Widget_GetDisplay(parentHandle));   409         ugl_display = UGL_DISPLAY(Widget_GetDisplay(parentHandle));
394     } else {   410     } else {
395         ugl_display = UGL_DISPLAY(displayHandle);   411         ugl_display = UGL_DISPLAY(displayHandle);
396     }   412     }
397     413  
398     hInstance = ugl_display->hInstance;   414     hInstance = ugl_display->hInstance;
399     415  
400     // if the current thread is different than the display's thread   416     // if the current thread is different than the display's thread
401     if (GetCurrentThreadId() != (unsigned long)ugl_display->threadID) {   417     if (GetCurrentThreadId() != (unsigned long)ugl_display->threadID) {
402         // block this thread and let the display thread call this function   418         // block this thread and let the display thread call this function
403         UGL_Int args[2] = {parentHandle, (UGL_Int)uglError};   419         UGL_Int args[2] = {parentHandle, (UGL_Int)uglError};
404         // initiate creating the shell using our own message id (ie. above WM_USER).   420         // initiate creating the shell using our own message id (ie. above WM_USER).
405         shell = (PUGL_Control)SendMessage(ugl_display->creation_hWnd, UI_CREATE_SHELL, (WPARAM)ugl_style, (LPARAM)&args);   421         shell = (PUGL_Control)SendMessage(ugl_display->creation_hWnd, UI_CREATE_SHELL, (WPARAM)ugl_style, (LPARAM)&args);
406         return (UGL_Int)shell;   422         return (UGL_Int)shell;
407     }   423     }
408       424    
409     // you can't get down here unless you have come from creationProc in Display   425     // you can't get down here unless you have come from creationProc in Display
410     shell = UGL_CONTROL(calloc(sizeof(UGL_Shell), 1));   426     shell = UGL_CONTROL(calloc(sizeof(UGL_Shell), 1));
411     if (shell == NULL) return 0;   427     if (shell == NULL) return 0;
412     extended_style = _Shell_ExStyle(ugl_style, is_child);   428     extended_style = _Shell_ExStyle(ugl_style, is_child);
413     style = _Shell_Style(ugl_style, is_child);   429     style = _Shell_Style(ugl_style, is_child);
414     430  
415     hWnd = CreateWindowEx(extended_style, SHELL_WINDOW_CLASS, NULL, style,   431     hWnd = CreateWindowEx(extended_style, SHELL_WINDOW_CLASS, NULL, style,
416       CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWndParent, NULL, hInstance, NULL);   432       CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWndParent, NULL, hInstance, NULL);
417     433  
418    if (!hWnd) {   434    if (!hWnd) {
419         Win32Error_SetError(uglError, GetLastError(), _T("Unable to create window"));   435         Win32Error_SetError(uglError, GetLastError(), _T("Unable to create window"));
420         return NULL_HANDLE;   436         return NULL_HANDLE;
421    }   437    }
422     438  
423 // post processing?   439 // post processing?
424     bits = GetWindowLong(hWnd, GWL_STYLE);    440     bits = GetWindowLong(hWnd, GWL_STYLE); 
425     bits &= ~(WS_OVERLAPPED | WS_CAPTION);   441     bits &= ~(WS_OVERLAPPED | WS_CAPTION);
426     442  
427 #ifndef _WIN32_WCE   443 #ifndef _WIN32_WCE
428     bits |= WS_POPUP;   444     bits |= WS_POPUP;
429 #endif   445 #endif
430     446  
431 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)   447 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
432     if (is_child && IS_FLAG_SET(ugl_style, UGL_STYLE_TITLE)) bits |= WS_CAPTION;   448     if (is_child && IS_FLAG_SET(ugl_style, UGL_STYLE_TITLE)) bits |= WS_CAPTION;
433 #else   449 #else
434     if (IS_FLAG_SET(ugl_style, UGL_STYLE_TITLE)) bits |= WS_CAPTION;   450     if (IS_FLAG_SET(ugl_style, UGL_STYLE_TITLE)) bits |= WS_CAPTION;
435 #endif   451 #endif
436     452  
437     // Add the border back to the window it was specified because   453     // Add the border back to the window it was specified because
438     // then the WS_CAPTION style was removed avoid the WS_BORDER style gets   454     // then the WS_CAPTION style was removed avoid the WS_BORDER style gets
439     // removed as well   455     // removed as well
440     if ((ugl_style & (UGL_STYLE_BORDER)) == UGL_STYLE_BORDER) bits |= WS_BORDER;   456     if ((ugl_style & (UGL_STYLE_BORDER)) == UGL_STYLE_BORDER) bits |= WS_BORDER;
441     457  
442     /*   458     /*
443     * Bug in Windows.  When the WS_CAPTION bits are cleared using   459     * Bug in Windows.  When the WS_CAPTION bits are cleared using
444     * SetWindowLong(), Windows does not resize the client area of   460     * SetWindowLong(), Windows does not resize the client area of
445     * the window to get rid of the caption until the first resize.   461     * the window to get rid of the caption until the first resize.
446     * The fix is to use SetWindowPos() with SWP_DRAWFRAME to force   462     * The fix is to use SetWindowPos() with SWP_DRAWFRAME to force
447     * the frame to be redrawn and resized.   463     * the frame to be redrawn and resized.
448     */   464     */
449     SetWindowLong(hWnd, GWL_STYLE, bits);   465     SetWindowLong(hWnd, GWL_STYLE, bits);
450     flags = SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE;   466     flags = SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE;
451     _SetWindowPos(hWnd, 0, 0, 0, 0, 0, flags);   467     _SetWindowPos(hWnd, 0, 0, 0, 0, 0, flags);
452     468  
453     UGL_WIDGET(shell)->display = ugl_display;   469     UGL_WIDGET(shell)->display = ugl_display;
454     UGL_WIDGET(shell)->callback_target = NULL;   470     UGL_WIDGET(shell)->callback_target = NULL;
455     UGL_WIDGET(shell)->ugl_style = ugl_style;   471     UGL_WIDGET(shell)->ugl_style = ugl_style;
456     UGL_WIDGET(shell)->widget_dispose = _Dispose_Shell;   472     UGL_WIDGET(shell)->widget_dispose = _Dispose_Shell;
457       473    
458     shell->parent = ugl_parent;   474     shell->parent = ugl_parent;
459     shell->hWnd = hWnd;   475     shell->hWnd = hWnd;
460     shell->widgetProc = NULL;   476     shell->widgetProc = NULL;
461     shell->redraw_enabled = TRUE;   477     shell->redraw_enabled = TRUE;
462     shell->background_color = 0;   478     shell->background_color = 0;
463     shell->foreground_color = 0;   479     shell->foreground_color = 0;
464     shell->cursor = NULL;   480     shell->cursor = NULL;
465     shell->inheritsBackground = TRUE;   481     shell->inheritsBackground = TRUE;
466     shell->sendKeyEvent = _Control_SendKeyEvent;   482     shell->sendKeyEvent = _Control_SendKeyEvent;
467     483  
468 #ifndef _WIN32_WCE   484 #ifndef _WIN32_WCE
469     UGL_SHELL(shell)->state = NORMAL;   485     UGL_SHELL(shell)->state = NORMAL;
470 #endif   486 #endif
471       487    
472 #if (_WIN32_WCE >= 420)   488 #if (_WIN32_WCE >= 420)
473     {   489     {
474         SHACTIVATEINFO *shActivateInfo = &(UGL_SHELL(shell)->shActivateInfo);   490         SHACTIVATEINFO *shActivateInfo = &(UGL_SHELL(shell)->shActivateInfo);
475         memset(shActivateInfo, 0, sizeof(*shActivateInfo));   491         memset(shActivateInfo, 0, sizeof(*shActivateInfo));
476         shActivateInfo->cbSize = sizeof(*shActivateInfo);   492         shActivateInfo->cbSize = sizeof(*shActivateInfo);
477     }   493     }
478 #endif   494 #endif
479       495    
480     SetWindowLong(hWnd, GWL_USERDATA, (LONG)shell);   496     SetWindowLong(hWnd, GWL_USERDATA, (LONG)shell);
481     497  
482     lpWndClass.lpfnWndProc = 0;   498     lpWndClass.lpfnWndProc = 0;
483     GetClassInfo(hInstance, SHELL_WINDOW_CLASS, &lpWndClass);   499     GetClassInfo(hInstance, SHELL_WINDOW_CLASS, &lpWndClass);
484     shell->widgetProc = lpWndClass.lpfnWndProc;   500     shell->widgetProc = lpWndClass.lpfnWndProc;
485     501  
486     // let original display handler create shell first, then set new handler   502     // let original display handler create shell first, then set new handler
487     SetWindowLong(hWnd, GWL_WNDPROC, (LONG)_Shell_Proc);   503     SetWindowLong(hWnd, GWL_WNDPROC, (LONG)_Shell_Proc);
488     504  
489 #ifdef _WIN32_WCE   505 #ifdef _WIN32_WCE
490 #if defined(WIN32_PLATFORM_PSPC)   506 #if defined(WIN32_PLATFORM_PSPC)
491     // All PocketPC shells should have an empty menu by default   507     // All PocketPC shells should have an empty menu by default
492     UGL_SHELL(shell)->emptyMenu = (UGL_Menu*)_MenuBar_New(shell, NULL);   508     UGL_SHELL(shell)->emptyMenu = (UGL_Menu*)_MenuBar_New(shell, NULL);
493 #endif   509 #endif
494     510  
495     if (shell->parent == NULL) {   511     if (shell->parent == NULL) {
496         // only Toplevel shells on WinCE should always be maximized   512         // only Toplevel shells on WinCE should always be maximized
497         Shell_SetMaximized((UGL_Int)shell, TRUE, uglError);   513         Shell_SetMaximized((UGL_Int)shell, TRUE, uglError);
498     }   514     }
499 #endif   515 #endif
500     516  
501     Display_AddShell(ugl_display, shell, uglError);   517     Display_AddShell(ugl_display, shell, uglError);
502     return (UGL_Int)shell;   518     return (UGL_Int)shell;
503     519  
504 }   520 }
505     521  
506 void _Shell_GetInsets(PUGL_Control control, LPRECT rect) {   522 void _Shell_GetInsets(PUGL_Control control, LPRECT rect) {
507     _Scrollable_GetInsets(control, rect);   523     _Scrollable_GetInsets(control, rect);
508     524  
509 #if _WIN32_WCE && !(WIN32_PLATFORM_PSPC) && !(WIN32_PLATFORM_WFSP)   525 #if _WIN32_WCE && !(WIN32_PLATFORM_PSPC) && !(WIN32_PLATFORM_WFSP)
510     {   526     {
511         PUGL_Shell shell = UGL_SHELL(control);   527         PUGL_Shell shell = UGL_SHELL(control);
512         if (shell->ugl_menu != NULL) {   528         if (shell->ugl_menu != NULL) {
513             rect->top += CommandBar_Height(shell->ugl_menu->hwndCB);   529             rect->top += CommandBar_Height(shell->ugl_menu->hwndCB);
514         }   530         }
515     }   531     }
516 #endif   532 #endif
517     533  
518 #ifndef _WIN32_WCE   534 #ifndef _WIN32_WCE
519     // The logic in _Scrollable_GetInsets does not correctly   535     // The logic in _Scrollable_GetInsets does not correctly
520     // calculate the size of the insets when the shell   536     // calculate the size of the insets when the shell
521     // has a menubar and that menubar is wraped across two   537     // has a menubar and that menubar is wraped across two
522     // lines.  This code is a fix for that problem (bug 108315)   538     // lines.  This code is a fix for that problem (bug 108315)
523     if (GetMenu(control->hWnd) != NULL) {   539     if (GetMenu(control->hWnd) != NULL) {
524         RECT windowRect;   540         RECT windowRect;
525         int oldTop, calculatedTopInset;   541         int oldTop, calculatedTopInset;
526         GetWindowRect(control->hWnd, &windowRect);   542         GetWindowRect(control->hWnd, &windowRect);
527         oldTop = windowRect.top;   543         oldTop = windowRect.top;
528         SendMessage(control->hWnd, WM_NCCALCSIZE, 0, (LPARAM)&windowRect);   544         SendMessage(control->hWnd, WM_NCCALCSIZE, 0, (LPARAM)&windowRect);
529         calculatedTopInset = windowRect.top - oldTop;   545         calculatedTopInset = windowRect.top - oldTop;
530         if (rect->top < (calculatedTopInset)) {   546         if (rect->top < (calculatedTopInset)) {
531             rect->top = calculatedTopInset;   547             rect->top = calculatedTopInset;
532         }   548         }
533     }   549     }
534 #endif   550 #endif
535 }   551 }
536     552  
537 #ifdef _WIN32_WCE   553 #ifdef _WIN32_WCE
538 void _Shell_AdjustChildBounds(PUGL_Control control, LPRECT childBounds) {   554 void _Shell_AdjustChildBounds(PUGL_Control control, LPRECT childBounds) {
539     555  
540 #if !(WIN32_PLATFORM_PSPC) && !(WIN32_PLATFORM_WFSP)   556 #if !(WIN32_PLATFORM_PSPC) && !(WIN32_PLATFORM_WFSP)
541     PUGL_Shell shell = UGL_SHELL(control);   557     PUGL_Shell shell = UGL_SHELL(control);
542     if (shell->ugl_menu != NULL) {   558     if (shell->ugl_menu != NULL) {
543         int menubarHeight = CommandBar_Height(shell->ugl_menu->hwndCB);   559         int menubarHeight = CommandBar_Height(shell->ugl_menu->hwndCB);
544         childBounds->top += menubarHeight;   560         childBounds->top += menubarHeight;
545         childBounds->bottom += menubarHeight;   561         childBounds->bottom += menubarHeight;
546     }   562     }
547 #endif    563 #endif 
548     564  
549 }   565 }
550 #endif   566 #endif
551     567  
552 void _Shell_HandleResize(PUGL_Control shell, ShellState newState) {   568 void _Shell_HandleResize(PUGL_Control shell, ShellState newState) {
553     RECT rect;   569     RECT rect;
554     int nWidth;   570     int nWidth;
555     int nHeight;   571     int nHeight;
556 #ifndef _WIN32_WCE   572 #ifndef _WIN32_WCE
557     ShellState state = UGL_SHELL(shell)->state;   573     ShellState state = UGL_SHELL(shell)->state;
558 #endif   574 #endif
559     575  
560     GetWindowRect(shell->hWnd, &rect);   576     GetWindowRect(shell->hWnd, &rect);
561     nWidth = rect.right - rect.left;   577     nWidth = rect.right - rect.left;
562     nHeight = rect.bottom - rect.top;   578     nHeight = rect.bottom - rect.top;
563     579  
564 #ifndef _WIN32_WCE   580 #ifndef _WIN32_WCE
565     if (state != newState) {   581     if (state != newState) {
566         if (state == MINIMIZED) {   582         if (state == MINIMIZED) {
567             ShellCallback(shell->widget.callback_target, UGL_EVENT_SHELL_DEICONIFIED);   583             ShellCallback(shell->widget.callback_target, UGL_EVENT_SHELL_DEICONIFIED);
568         }   584         }
569         UGL_SHELL(shell)->state = newState;   585         UGL_SHELL(shell)->state = newState;
570     }   586     }
571 #endif   587 #endif
572     588  
573     ShellResizeCallback(shell->widget.callback_target, nWidth, nHeight);   589     ShellResizeCallback(shell->widget.callback_target, nWidth, nHeight);
574 }   590 }
575     591  
576 //========================================================================================   592 //========================================================================================
577     593  
578 LRESULT CALLBACK _Shell_Proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {   594 LRESULT CALLBACK _Shell_Proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
579     PUGL_Control ugl_shell = (PUGL_Control)GetWindowLong(hWnd, GWL_USERDATA);   595     PUGL_Control ugl_shell = (PUGL_Control)GetWindowLong(hWnd, GWL_USERDATA);
580     PUGL_Display ugl_display = UGL_DISPLAY(Widget_GetDisplay((UGL_Int)ugl_shell));   596     PUGL_Display ugl_display = UGL_DISPLAY(Widget_GetDisplay((UGL_Int)ugl_shell));
581     LRESULT result = 0;   597     LRESULT result = 0;
582     int i;   598     int i;
583     599  
584     switch (message) {   600     switch (message) {
585     601  
586         case WM_ACTIVATE: {   602         case WM_ACTIVATE: {
587             if (LOWORD(wParam) == WA_INACTIVE) {   603             if (LOWORD(wParam) == WA_INACTIVE) {
588                 //SWT saves the focus here. We seem to get away without it.   604                 //SWT saves the focus here. We seem to get away without it.
589                 ShellCallback(UGL_WIDGET(ugl_shell)->callback_target, UGL_EVENT_SHELL_DEACTIVATED);   605                 ShellCallback(UGL_WIDGET(ugl_shell)->callback_target, UGL_EVENT_SHELL_DEACTIVATED);
590             } else {   606             } else {
591 #if (_WIN32_WCE >= 420)   607 #if (_WIN32_WCE >= 420)
592                 SHACTIVATEINFO *shActivateInfo;   608                 SHACTIVATEINFO *shActivateInfo;
593 #endif   609 #endif
594     610  
595                 if (HIWORD(wParam) != 0) return 0; //if the Shell is not minimized...   611                 if (HIWORD(wParam) != 0) return 0; //if the Shell is not minimized...
596                 ugl_display->activeShell = ugl_shell;   612                 ugl_display->activeShell = ugl_shell;
597                 for(i=0; i<ugl_display->menuItemsLength; i++){   613                 for(i=0; i<ugl_display->menuItemsLength; i++){
598                     if(ugl_display->menuItems[i] != NULL){   614                     if(ugl_display->menuItems[i] != NULL){
599                         if (ugl_display->menuItems[i]->parent_menu->parent == ugl_shell) {   615                         if (ugl_display->menuItems[i]->parent_menu->parent == ugl_shell) {
600                             ugl_display->activeMenuBar = ugl_display->menuItems[i]->parent_menu;   616                             ugl_display->activeMenuBar = ugl_display->menuItems[i]->parent_menu;
601                             break;   617                             break;
602                         }   618                         }
603                     }   619                     }
604                 }   620                 }
605                 ShellCallback(UGL_WIDGET(ugl_shell)->callback_target, UGL_EVENT_SHELL_ACTIVATED);   621                 ShellCallback(UGL_WIDGET(ugl_shell)->callback_target, UGL_EVENT_SHELL_ACTIVATED);
606     622  
607     623  
608 #if (_WIN32_WCE >= 420)   624 #if (_WIN32_WCE >= 420)
609                 {   625                 {
610                     /**   626                     /**
611                      * On WinCE, SHHandleWMActivate is used to manage the state   627                      * On WinCE, SHHandleWMActivate is used to manage the state
612                      * of the input window.    628                      * of the input window. 
613                      * One side effect of SHHandleWMActivate, which is not documented   629                      * One side effect of SHHandleWMActivate, which is not documented
614                      * in MSDN, is that if the window is activated by a mouse click   630                      * in MSDN, is that if the window is activated by a mouse click
615                      * then the window will be resized to fill the entire client area   631                      * then the window will be resized to fill the entire client area
616                      * of the screen.  This is not the behavior that the Java toolkits   632                      * of the screen.  This is not the behavior that the Java toolkits
617                      * expect so the old window size is saved before and restored after   633                      * expect so the old window size is saved before and restored after
618                      * the call to SHHandleWMActivate.   634                      * the call to SHHandleWMActivate.
619                      */   635                      */
620                     RECT old;   636                     RECT old;
621                     GetWindowRect(hWnd, &old);   637                     GetWindowRect(hWnd, &old);
622                     shActivateInfo = &(UGL_SHELL(ugl_shell)->shActivateInfo);   638                     shActivateInfo = &(UGL_SHELL(ugl_shell)->shActivateInfo);
623                     // restore input panel to previous state   639                     // restore input panel to previous state
624                     SHHandleWMActivate(hWnd, wParam, lParam, shActivateInfo, 0);   640                     SHHandleWMActivate(hWnd, wParam, lParam, shActivateInfo, 0);
625                     SetWindowPos(hWnd, NULL, old.left, old.top, (old.right - old.left), (old.bottom - old.top), SWP_NOZORDER | SWP_NOACTIVATE);   641                     SetWindowPos(hWnd, NULL, old.left, old.top, (old.right - old.left), (old.bottom - old.top), SWP_NOZORDER | SWP_NOACTIVATE);
626                 }   642                 }
627 #endif   643 #endif
628 #if defined(WIN32_PLATFORM_PSPC)   644 #if defined(WIN32_PLATFORM_PSPC)
629                 _Shell_EnsureMenuBarIsVisible(UGL_SHELL(ugl_shell), ugl_shell->parent);   645                 _Shell_EnsureMenuBarIsVisible(UGL_SHELL(ugl_shell), ugl_shell->parent);
630 #endif   646 #endif
631             }   647             }
632             break;   648             break;
633         }   649         }
634     650  
635         case WM_SIZE: {   651         case WM_SIZE: {
636             switch (wParam) {   652             switch (wParam) {
637                 case SIZE_MAXIMIZED: {   653                 case SIZE_MAXIMIZED: {
638                     _Shell_HandleResize(ugl_shell, MAXIMIZED);   654                     _Shell_HandleResize(ugl_shell, MAXIMIZED);
639                     break;   655                     break;
640                 }   656                 }
641                 case SIZE_RESTORED: {   657                 case SIZE_RESTORED: {
642                     _Shell_HandleResize(ugl_shell, NORMAL);   658                     _Shell_HandleResize(ugl_shell, NORMAL);
643                     break;   659                     break;
644                 }   660                 }
645                 case SIZE_MINIMIZED: {   661                 case SIZE_MINIMIZED: {
646                     // Don't use _Sehll_HandleResize() because a new size   662                     // Don't use _Sehll_HandleResize() because a new size
647                     // does not need to be sent back to Java   663                     // does not need to be sent back to Java
648                     ShellCallback(ugl_shell->widget.callback_target, UGL_EVENT_SHELL_ICONIFIED);   664                     ShellCallback(ugl_shell->widget.callback_target, UGL_EVENT_SHELL_ICONIFIED);
649 #ifndef _WIN32_WCE   665 #ifndef _WIN32_WCE
650                     UGL_SHELL(ugl_shell)->state = MINIMIZED;   666                     UGL_SHELL(ugl_shell)->state = MINIMIZED;
651 #endif   667 #endif
652                     break;   668                     break;
653                 }   669                 }
654             }   670             }
655             break;   671             break;
656         }   672         }
657     673  
658         case WM_MOVE: {   674         case WM_MOVE: {
659             /*   675             /*
660              * PPro expects us to return the x and y coordinate of the whole window, not   676              * PPro expects us to return the x and y coordinate of the whole window, not
661              * the client area.   677              * the client area.
662              */   678              */
663             RECT rect;   679             RECT rect;
664             int xPos;   680             int xPos;
665             int yPos;   681             int yPos;
666             GetWindowRect(hWnd, &rect);   682             GetWindowRect(hWnd, &rect);
667             xPos = rect.left;   683             xPos = rect.left;
668             yPos = rect.top;   684             yPos = rect.top;
669             ShellMoveCallback(ugl_shell->widget.callback_target, xPos, yPos);   685             ShellMoveCallback(ugl_shell->widget.callback_target, xPos, yPos);
670             break;   686             break;
671         }   687         }
672     688  
673         case WM_DRAWITEM: {   689         case WM_DRAWITEM: {
674             LPDRAWITEMSTRUCT draw_struct = (LPDRAWITEMSTRUCT)lParam;   690             LPDRAWITEMSTRUCT draw_struct = (LPDRAWITEMSTRUCT)lParam;
675             if (draw_struct->CtlType == ODT_MENU) {   691             if (draw_struct->CtlType == ODT_MENU) {
676                 PUGL_MenuItem ugl_menuItem = Display_GetMenuItem(ugl_shell->widget.display, draw_struct->itemData);   692                 PUGL_MenuItem ugl_menuItem = Display_GetMenuItem(ugl_shell->widget.display, draw_struct->itemData);
677                 if ((ugl_menuItem != NULL) && (ugl_menuItem->wmDrawChild != NULL))   693                 if ((ugl_menuItem != NULL) && (ugl_menuItem->wmDrawChild != NULL))
678                     result = ugl_menuItem->wmDrawChild((UGL_Int)ugl_menuItem, wParam, lParam);   694                     result = ugl_menuItem->wmDrawChild((UGL_Int)ugl_menuItem, wParam, lParam);
679             }   695             }
680             break;   696             break;
681         }   697         }
682     698  
683         case WM_MEASUREITEM: {   699         case WM_MEASUREITEM: {
684             LPMEASUREITEMSTRUCT measure_struct = (LPMEASUREITEMSTRUCT)lParam;   700             LPMEASUREITEMSTRUCT measure_struct = (LPMEASUREITEMSTRUCT)lParam;
685             if (measure_struct->CtlType == ODT_MENU) {   701             if (measure_struct->CtlType == ODT_MENU) {
686                 PUGL_MenuItem ugl_menuItem = Display_GetMenuItem(ugl_shell->widget.display, measure_struct->itemData);   702                 PUGL_MenuItem ugl_menuItem = Display_GetMenuItem(ugl_shell->widget.display, measure_struct->itemData);
687                 if ((ugl_menuItem != NULL) && (ugl_menuItem->wmMeasureChild != NULL)) {   703                 if ((ugl_menuItem != NULL) && (ugl_menuItem->wmMeasureChild != NULL)) {
688                     result = ugl_menuItem->wmMeasureChild((UGL_Int)ugl_menuItem, wParam, lParam);   704                     result = ugl_menuItem->wmMeasureChild((UGL_Int)ugl_menuItem, wParam, lParam);
689                     return TRUE;   705                     return TRUE;
690                 }   706                 }
691             }   707             }
692             break;   708             break;
693         }   709         }
694     710  
695 #if (_WIN32_WCE >= 420)   711 #if (_WIN32_WCE >= 420)
696         case WM_SETTINGCHANGE:   712         case WM_SETTINGCHANGE:
697             if (wParam == SPI_SETSIPINFO) {   713             if (wParam == SPI_SETSIPINFO) {
698                 RECT old;   714                 RECT old;
699                 PUGL_Shell shell = UGL_SHELL(ugl_shell);   715                 PUGL_Shell shell = UGL_SHELL(ugl_shell);
700                 SHACTIVATEINFO *shActivateInfo = &(shell->shActivateInfo);   716                 SHACTIVATEINFO *shActivateInfo = &(shell->shActivateInfo);
701     717  
702                 // resize shell and store state when input panel is shown/hidden   718                 // resize shell and store state when input panel is shown/hidden
703                 // The shell should not be resized if it is not fullscreen.  This covers   719                 // The shell should not be resized if it is not fullscreen.  This covers
704                 // both child windows and if we ever support non-fullscreen top-level windows   720                 // both child windows and if we ever support non-fullscreen top-level windows
705                 if (_Shell_GetMaximized(shell) == FALSE) GetWindowRect(hWnd, &old);   721                 if (_Shell_GetMaximized(shell) == FALSE) GetWindowRect(hWnd, &old);
706                 SHHandleWMSettingChange(hWnd, wParam, lParam, shActivateInfo);   722                 SHHandleWMSettingChange(hWnd, wParam, lParam, shActivateInfo);
707                 if (_Shell_GetMaximized(shell) == FALSE)  SetWindowPos(hWnd, NULL, old.left, old.top, (old.right - old.left), (old.bottom - old.top), SWP_NOZORDER | SWP_NOACTIVATE);   723                 if (_Shell_GetMaximized(shell) == FALSE)  SetWindowPos(hWnd, NULL, old.left, old.top, (old.right - old.left), (old.bottom - old.top), SWP_NOZORDER | SWP_NOACTIVATE);
708 #if defined(WIN32_PLATFORM_PSPC)   724 #if defined(WIN32_PLATFORM_PSPC)
709                 if( GetForegroundWindow() == hWnd) _Shell_EnsureMenuBarIsVisible(shell, ugl_shell->parent);   725                 if( GetForegroundWindow() == hWnd) _Shell_EnsureMenuBarIsVisible(shell, ugl_shell->parent);
710 #endif   726 #endif
711                 return 0;   727                 return 0;
712             }   728             }
713             break;   729             break;
714 #endif   730 #endif
715 #if defined(_WIN32_WCE)   731 #if defined(_WIN32_WCE)
716         case WM_COMMAND: {   732         case WM_COMMAND: {
717             PUGL_Shell shell = UGL_SHELL(ugl_shell);   733             PUGL_Shell shell = UGL_SHELL(ugl_shell);
718 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)   734 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
719             /*   735             /*
720             * Note in WinCE PPC:  Close the Shell when the "Done Button" has   736             * Note in WinCE PPC:  Close the Shell when the "Done Button" has
721             * been pressed. lParam is either 0 (PocketPC 2002) or the handle   737             * been pressed. lParam is either 0 (PocketPC 2002) or the handle
722             * to the Shell (PocketPC).   738             * to the Shell (PocketPC).
723             */   739             */
724             int loWord = wParam & 0xFFFF;   740             int loWord = wParam & 0xFFFF;
725             if (loWord == IDOK && (lParam == 0 || lParam == hWnd)) {   741             if (loWord == IDOK && (lParam == 0 || lParam == hWnd)) {
726                 PostMessage (hWnd, WM_CLOSE, 0, 0);   742                 PostMessage (hWnd, WM_CLOSE, 0, 0);
727                 return 0;             743                 return 0;          
728             }   744             }
729 #endif   745 #endif
730     746  
731             if (shell->ugl_menu != NULL) {   747             if (shell->ugl_menu != NULL) {
732                 // For menu items that are placed directly on the   748                 // For menu items that are placed directly on the
733                 // menubar, the window that is supplied in the   749                 // menubar, the window that is supplied in the
734                 // lParam is NOT the menu hwnd as would be expected, but   750                 // lParam is NOT the menu hwnd as would be expected, but
735                 // actually the one of the child widgets of the menubar.   751                 // actually the one of the child widgets of the menubar.
736                 HWND menubarHWND = shell->ugl_menu->hwndCB;   752                 HWND menubarHWND = shell->ugl_menu->hwndCB;
737                 if ((menubarHWND == (HWND)lParam) || (IsChild(menubarHWND, (HWND)lParam))) {   753                 if ((menubarHWND == (HWND)lParam) || (IsChild(menubarHWND, (HWND)lParam))) {
738                     WORD menuId = wParam & 0xFFFF;   754                     WORD menuId = wParam & 0xFFFF;
739                     _Control_ProcessMenuItemCommand(ugl_display, menuId, wParam, lParam);   755                     _Control_ProcessMenuItemCommand(ugl_display, menuId, wParam, lParam);
740                 }   756                 }
741                   757                
742             }   758             }
743             break;   759             break;
744         }   760         }
745 #endif   761 #endif
746     762  
747         case UI_MOVE_ABOVE:{   763         case UI_MOVE_ABOVE:{
748             PUGL_Control sibling = (PUGL_Control)wParam;   764             PUGL_Control sibling = (PUGL_Control)wParam;
749             _Shell_MoveAbove(ugl_shell, sibling, (UGL_Error)lParam);   765             _Shell_MoveAbove(ugl_shell, sibling, (UGL_Error)lParam);
750             return 0;   766             return 0;
751         } break;   767         } break;
752     768  
753         case UI_SCROLLABLE_GETINSETS: {   769         case UI_SCROLLABLE_GETINSETS: {
754             _Shell_GetInsets(ugl_shell, (LPRECT)wParam);              770             _Shell_GetInsets(ugl_shell, (LPRECT)wParam);           
755             return 0;   771             return 0;
756         }   772         }
757     773  
758         case UI_SET_ENABLED: {   774         case UI_SET_ENABLED: {
759             BOOL enable = (BOOL)wParam;   775             BOOL enable = (BOOL)wParam;
760             PUGL_Display display = Control_GetDisplay(ugl_shell);   776             PUGL_Display display = Control_GetDisplay(ugl_shell);
761             if (!Display_EnableShell(display, ugl_shell, enable)) {   777             if (!Display_EnableShell(display, ugl_shell, enable)) {
762                 // the display does not want the enabled status of this   778                 // the display does not want the enabled status of this
763                 // control to change so it is important that no further processing   779                 // control to change so it is important that no further processing
764                 // happen on this message   780                 // happen on this message
765                 return 0;   781                 return 0;
766             }   782             }
767             break;   783             break;
768         }   784         }
769     785  
770         case UI_SET_VISIBLE: {   786         case UI_SET_VISIBLE: {
771             // It is important that the enabled status of the shells be updated   787             // It is important that the enabled status of the shells be updated
772             // before this shell becomes visible/invisible because if no other   788             // before this shell becomes visible/invisible because if no other
773             // shell is enabled when the modal dialog is made invisble then no   789             // shell is enabled when the modal dialog is made invisble then no
774             // windows are brought to the front.   790             // windows are brought to the front.
775             BOOL visible = (BOOL)wParam;   791             BOOL visible = (BOOL)wParam;
776             UGL_Error* error = (UGL_Error*)lParam;   792             UGL_Error* error = (UGL_Error*)lParam;
777             if (IS_FLAG_SET(ugl_shell->widget.ugl_style, UGL_STYLE_APPLICATION_MODAL)) {   793             if (IS_FLAG_SET(ugl_shell->widget.ugl_style, UGL_STYLE_APPLICATION_MODAL)) {
778                 PUGL_Display display = Control_GetDisplay(ugl_shell);   794                 PUGL_Display display = Control_GetDisplay(ugl_shell);
779                 Display_UpdateModalShellVisibility(display, ugl_shell, visible, *error);   795                 Display_UpdateModalShellVisibility(display, ugl_shell, visible, *error);
780             }   796             }
781     797  
782 #ifndef _WIN32_WCE   798 #ifndef _WIN32_WCE
783             if (visible) {   799             if (visible) {
784                 if ((UGL_SHELL(ugl_shell)->state != MINIMIZED) && (IsIconic(hWnd))) {   800                 if ((UGL_SHELL(ugl_shell)->state != MINIMIZED) && (IsIconic(hWnd))) {
785                     ShellCallback(ugl_shell->widget.callback_target, UGL_EVENT_SHELL_DEICONIFIED);   801                     ShellCallback(ugl_shell->widget.callback_target, UGL_EVENT_SHELL_DEICONIFIED);
786                 }   802                 }
787     803  
788                 if (UGL_SHELL(ugl_shell)->state != NORMAL) {   804                 if (UGL_SHELL(ugl_shell)->state != NORMAL) {
789                     if (UGL_SHELL(ugl_shell)->state == MAXIMIZED) {   805                     if (UGL_SHELL(ugl_shell)->state == MAXIMIZED) {
790                         ShowWindow(hWnd, SW_MAXIMIZE);   806                         ShowWindow(hWnd, SW_MAXIMIZE);
791                     } else {   807                     } else {
792                         ShowWindow(hWnd, SW_SHOWMINNOACTIVE);   808                         ShowWindow(hWnd, SW_SHOWMINNOACTIVE);
793                     }   809                     }
794                     return 0;   810                     return 0;
795                 }   811                 }
796             }   812             }
797 #endif   813 #endif
798     814  
799             break;   815             break;
800         }   816         }
801     817  
802 #ifdef _WIN32_WCE   818 #ifdef _WIN32_WCE
803         case UI_SET_BOUNDS: {   819         case UI_SET_BOUNDS: {
804             LPRECT bounds = (LPRECT)wParam;   820             LPRECT bounds = (LPRECT)wParam;
805             UGL_Error error = (UGL_Error)lParam;   821             UGL_Error error = (UGL_Error)lParam;
806             int x = bounds->left;   822             int x = bounds->left;
807             int y = bounds->top;   823             int y = bounds->top;
808             int width = bounds->right - bounds->left;   824             int width = bounds->right - bounds->left;
809             int height = bounds->bottom - bounds->top;   825             int height = bounds->bottom - bounds->top;
810     826  
811             if (ugl_shell->parent != NULL) {   827             if (ugl_shell->parent != NULL) {
812                 if (!SetWindowPos(hWnd, NULL, x, y, width, height, SWP_NOZORDER)) {   828                 if (!SetWindowPos(hWnd, NULL, x, y, width, height, SWP_NOZORDER)) {
813                     Win32Error_SetError(error, GetLastError(), _T("Could not change the size of the shell"));   829                     Win32Error_SetError(error, GetLastError(), _T("Could not change the size of the shell"));
814                 }   830                 }
815             } else {   831             } else {
816                 // Do nothing since top-level windows are always fullscreen on WinCE   832                 // Do nothing since top-level windows are always fullscreen on WinCE
817                 // Even though the size is not changing the real size needs to   833                 // Even though the size is not changing the real size needs to
818                 // be reported back to Java.  If this does not happen Java will think   834                 // be reported back to Java.  If this does not happen Java will think
819                 // that the frame has taken the new size and layouts will not   835                 // that the frame has taken the new size and layouts will not
820                 // work correctly.   836                 // work correctly.
821             }   837             }
822     838  
823             Control_GetBounds((UGL_Int) ugl_shell, &x, &y, &width, &height, error);   839             Control_GetBounds((UGL_Int) ugl_shell, &x, &y, &width, &height, error);
824 //          ShellResizeCallback(ugl_shell->widget.callback_target, width, height);   840 //          ShellResizeCallback(ugl_shell->widget.callback_target, width, height);
825 //          ShellMoveCallback(ugl_shell->widget.callback_target, x, y);   841 //          ShellMoveCallback(ugl_shell->widget.callback_target, x, y);
826             return 0;   842             return 0;
827         }   843         }
828 #endif   844 #endif
829         case UI_GET_MINIMUM_SIZE: {   845         case UI_GET_MINIMUM_SIZE: {
830             POINT* point = (POINT*)wParam;   846             POINT* point = (POINT*)wParam;
831             _Shell_GetMinimumSize((UGL_Int)ugl_shell, point, (UGL_Error)lParam);   847             _Shell_GetMinimumSize((UGL_Int)ugl_shell, point, (UGL_Error)lParam);
832             return 0;   848             return 0;
833         }   849         }
834     850  
835 #ifdef _WIN32_WCE   851 #ifdef _WIN32_WCE
836         case UI_ADJUST_CHILD_BOUNDS: {   852         case UI_ADJUST_CHILD_BOUNDS: {
837             // Child controls need to have their bounds adjusted before they are set   853             // Child controls need to have their bounds adjusted before they are set
838             // depending on whether the shell has a menu or not.  The menubar is considered   854             // depending on whether the shell has a menu or not.  The menubar is considered
839             // part of the client area but from a Java perspective it should not be   855             // part of the client area but from a Java perspective it should not be
840             _Shell_AdjustChildBounds(ugl_shell, (LPRECT)wParam);   856             _Shell_AdjustChildBounds(ugl_shell, (LPRECT)wParam);
841             return 0;   857             return 0;
842         }   858         }
843 #endif   859 #endif
844     }   860     }
845     861  
846     862  
847     // the ugl_display->windowProc will call the DefWindowProc if the message   863     // the ugl_display->windowProc will call the DefWindowProc if the message
848     // cannot be handled so it is possible to return the value without checking   864     // cannot be handled so it is possible to return the value without checking
849     // it's value   865     // it's value
850     return _Composite_Proc(hWnd, message, wParam, lParam);   866     return _Composite_Proc(hWnd, message, wParam, lParam);
851 }   867 }
852 //========================================================================================   868 //========================================================================================
853     869  
854 void _Dispose_Shell(UGL_Int handle, UGL_Error uglError) {   870 void _Dispose_Shell(UGL_Int handle, UGL_Error uglError) {
855     PUGL_Shell shell = UGL_SHELL(handle);   871     PUGL_Shell shell = UGL_SHELL(handle);
856     PUGL_Control ugl_control = UGL_CONTROL(handle);   872     PUGL_Control ugl_control = UGL_CONTROL(handle);
857     Display_RemoveShell(Control_GetDisplay(ugl_control), ugl_control);   873     Display_RemoveShell(Control_GetDisplay(ugl_control), ugl_control);
858     874  
859     if (shell->accel_entries != NULL) {   875     if (shell->accel_entries != NULL) {
860         free(shell->accel_entries);   876         free(shell->accel_entries);
861     }   877     }
862     878  
863     if (shell->accelerator_table != 0) {   879     if (shell->accelerator_table != 0) {
864         DestroyAcceleratorTable(shell->accelerator_table);   880         DestroyAcceleratorTable(shell->accelerator_table);
865     }   881     }
866     882  
867 #if defined(WIN32_PLATFORM_PSPC)   883 #if defined(WIN32_PLATFORM_PSPC)
868     _Dispose_Menu((UGL_Int)shell->emptyMenu, uglError);   884     _Dispose_Menu((UGL_Int)shell->emptyMenu, uglError);
869 #endif   885 #endif
870     886  
871     _Dispose_Scrollable(handle, uglError);   887     _Dispose_Scrollable(handle, uglError);
872 }   888 }
873 //========================================================================================   889 //========================================================================================
874     890  
875     891  
876 //========================================================================================   892 //========================================================================================
877     893  
878 UGL_Int Shell_NewChild(UGL_Int parent, UGL_Int ugl_style, UGL_Error uglError) {   894 UGL_Int Shell_NewChild(UGL_Int parent, UGL_Int ugl_style, UGL_Error uglError) {
879     return _Shell_New(parent, 0, ugl_style, uglError);   895     return _Shell_New(parent, 0, ugl_style, uglError);
880 }   896 }
881 ////========================================================================================   897 ////========================================================================================
882 UGL_Boolean Shell_GetMinimized(UGL_Int handle, UGL_Error uglError) {   898 UGL_Boolean Shell_GetMinimized(UGL_Int handle, UGL_Error uglError) {
883     PUGL_Control shell = (PUGL_Control)handle;   899     PUGL_Control shell = (PUGL_Control)handle;
884     HWND hWnd = shell->hWnd;   900     HWND hWnd = shell->hWnd;
885     901  
886     902  
887 #ifdef _WIN32_WCE   903 #ifdef _WIN32_WCE
888     return UGL_SHELL(handle)->state == MINIMIZED;   904     return UGL_SHELL(handle)->state == MINIMIZED;
889 #else   905 #else
890     if (IsWindowVisible (hWnd)) {   906     if (IsWindowVisible (hWnd)) {
891         return IsIconic(hWnd);   907         return IsIconic(hWnd);
892     } else {   908     } else {
893         return UGL_SHELL(handle)->state == MINIMIZED;   909         return UGL_SHELL(handle)->state == MINIMIZED;
894     }   910     }
895 #endif   911 #endif
896     //return swFlags == OS.SW_SHOWMINNOACTIVE;   912     //return swFlags == OS.SW_SHOWMINNOACTIVE;
897 }   913 }
898 //========================================================================================   914 //========================================================================================
899     915  
900 UGL_Boolean _Shell_GetMaximized(PUGL_Shell shell) {   916 UGL_Boolean _Shell_GetMaximized(PUGL_Shell shell) {
901     HWND hWnd = shell->scrollable.control.hWnd;   917     HWND hWnd = shell->scrollable.control.hWnd;
902     918  
903     919  
904 #ifdef _WIN32_WCE   920 #ifdef _WIN32_WCE
905     return shell->state == MAXIMIZED;   921     return shell->state == MAXIMIZED;
906 #else   922 #else
907     if (IsWindowVisible (hWnd)) {   923     if (IsWindowVisible (hWnd)) {
908         return IsZoomed(hWnd);   924         return IsZoomed(hWnd);
909     } else {   925     } else {
910         return shell->state == MAXIMIZED;   926         return shell->state == MAXIMIZED;
911     }   927     }
912 #endif   928 #endif
913     929  
914 }   930 }
915 void _Shell_GetMinimumSize(UGL_Int handle, POINT *point, UGL_Error uglError) {   931 void _Shell_GetMinimumSize(UGL_Int handle, POINT *point, UGL_Error uglError) {
916     PUGL_Shell shell = (PUGL_Shell)handle;   932     PUGL_Shell shell = (PUGL_Shell)handle;
917     PUGL_Widget shellWidget = (PUGL_Widget)handle;   933     PUGL_Widget shellWidget = (PUGL_Widget)handle;
918     PUGL_Control shellControl = (PUGL_Control)handle;   934     PUGL_Control shellControl = (PUGL_Control)handle;
919     int ugl_style = shellWidget->ugl_style;   935     int ugl_style = shellWidget->ugl_style;
920            936         
921 #ifndef _WIN32_WCE   937 #ifndef _WIN32_WCE
922     int widthLimit, heightLimit;   938     int widthLimit, heightLimit;
923     BOOL trim;   939     BOOL trim;
924     940  
925     trim = (IS_FLAG_SET(ugl_style, UGL_STYLE_TITLE)) ||   941     trim = (IS_FLAG_SET(ugl_style, UGL_STYLE_TITLE)) ||
926         (IS_FLAG_SET(ugl_style, UGL_STYLE_CLOSE)) ||   942         (IS_FLAG_SET(ugl_style, UGL_STYLE_CLOSE)) ||
927         (IS_FLAG_SET(ugl_style, UGL_STYLE_MIN)) ||   943         (IS_FLAG_SET(ugl_style, UGL_STYLE_MIN)) ||
928         (IS_FLAG_SET(ugl_style, UGL_STYLE_MAX));   944         (IS_FLAG_SET(ugl_style, UGL_STYLE_MAX));
929     if (!IS_FLAG_SET(ugl_style, UGL_STYLE_NO_TRIM) && trim) {   945     if (!IS_FLAG_SET(ugl_style, UGL_STYLE_NO_TRIM) && trim) {
930         int bits1 = GetWindowLong (shellControl->hWnd, GWL_STYLE);   946         int bits1 = GetWindowLong (shellControl->hWnd, GWL_STYLE);
931         widthLimit = GetSystemMetrics (SM_CXMINTRACK);   947         widthLimit = GetSystemMetrics (SM_CXMINTRACK);
932         if ((bits1 & WS_THICKFRAME) != 0) {   948         if ((bits1 & WS_THICKFRAME) != 0) {
933             heightLimit = GetSystemMetrics (SM_CYMINTRACK);   949             heightLimit = GetSystemMetrics (SM_CYMINTRACK);
934         } else {   950         } else {
935             RECT rect;   951             RECT rect;
936             int bits2 = GetWindowLong (shellControl->hWnd, GWL_EXSTYLE);   952             int bits2 = GetWindowLong (shellControl->hWnd, GWL_EXSTYLE);
937             AdjustWindowRectEx ((LPRECT)&rect, bits1, FALSE, bits2);   953             AdjustWindowRectEx ((LPRECT)&rect, bits1, FALSE, bits2);
938             heightLimit = rect.bottom - rect.top;   954             heightLimit = rect.bottom - rect.top;
939         }   955         }
940         point->x = widthLimit;   956         point->x = widthLimit;
941         point->y = heightLimit;   957         point->y = heightLimit;
942     } else {   958     } else {
943         point->x = 0;   959         point->x = 0;
944         point->y = 0;   960         point->y = 0;
945     }   961     }
946 #else   962 #else
947         point->x = 0;   963         point->x = 0;
948         point->y = 0;   964         point->y = 0;
949 #endif   965 #endif
950 }   966 }
951 //========================================================================================   967 //========================================================================================
952 void Shell_SetMinimized(UGL_Int handle, UGL_Boolean minimized, UGL_Error uglError) {   968 void Shell_SetMinimized(UGL_Int handle, UGL_Boolean minimized, UGL_Error uglError) {
953     PUGL_Control shell = (PUGL_Control)handle;   969     PUGL_Control shell = (PUGL_Control)handle;
954     HWND hWnd = shell->hWnd;   970     HWND hWnd = shell->hWnd;
955     971  
956     972  
957 #ifndef _WIN32_WCE   973 #ifndef _WIN32_WCE
958     974  
959     int swFlags = minimized ? SW_SHOWMINNOACTIVE : SW_RESTORE;   975     int swFlags = minimized ? SW_SHOWMINNOACTIVE : SW_RESTORE;
960     976  
961     UGL_SHELL(handle)->state = minimized ? MINIMIZED : NORMAL;   977     UGL_SHELL(handle)->state = minimized ? MINIMIZED : NORMAL;
962       978    
963     if (!IsWindowVisible(hWnd)) return;   979     if (!IsWindowVisible(hWnd)) return;
964     if (minimized == IsIconic(hWnd)) return;   980     if (minimized == IsIconic(hWnd)) return;
965     981  
966     // The following line has been slightly changed from SWT.  In SWT   982     // The following line has been slightly changed from SWT.  In SWT
967     // GetActiveWindow is used but GetActiveWindow only works if the   983     // GetActiveWindow is used but GetActiveWindow only works if the
968     // current thread is the thread that owns the active window.  Changing   984     // current thread is the thread that owns the active window.  Changing
969     // the call to GetForegroundWindow keeps the same logic, but works from any   985     // the call to GetForegroundWindow keeps the same logic, but works from any
970     // thread.   986     // thread.
971     if (swFlags == SW_SHOWMINNOACTIVE && hWnd == GetForegroundWindow()) {   987     if (swFlags == SW_SHOWMINNOACTIVE && hWnd == GetForegroundWindow()) {
972         swFlags = SW_MINIMIZE;   988         swFlags = SW_MINIMIZE;
973     }   989     }
974     990  
975     if (!minimized) {   991     if (!minimized) {
976         // Since the state has already been updated to reflect the minimized state   992         // Since the state has already been updated to reflect the minimized state
977         // the event from the OS will not generate a deiconified event.  A deiconified   993         // the event from the OS will not generate a deiconified event.  A deiconified
978         // event is still desired so we'll force one here   994         // event is still desired so we'll force one here
979         ShellCallback(shell->widget.callback_target, UGL_EVENT_SHELL_DEICONIFIED);   995         ShellCallback(shell->widget.callback_target, UGL_EVENT_SHELL_DEICONIFIED);
980     }   996     }
981     997  
982     ShowWindow(hWnd, swFlags);   998     ShowWindow(hWnd, swFlags);
983     UpdateWindow(hWnd);   999     UpdateWindow(hWnd);
984 #else   1000 #else
985         PUGL_Shell shellmin = UGL_SHELL(handle);   1001         PUGL_Shell shellmin = UGL_SHELL(handle);
986         if (minimized) {          1002         if (minimized) {       
987             shellmin->state = MINIMIZED;              1003             shellmin->state = MINIMIZED;           
988             ShowWindow(hWnd,SW_MINIMIZE);   1004             ShowWindow(hWnd,SW_MINIMIZE);
989         } else {   1005         } else {
990             if(shellmin->state == MINIMIZED){   1006             if(shellmin->state == MINIMIZED){
991                 shellmin->state = NORMAL;   1007                 shellmin->state = NORMAL;
992                 ShowWindow(hWnd, SW_RESTORE);     1008                 ShowWindow(hWnd, SW_RESTORE);  
993             }   1009             }
994         }   1010         }
995 #endif   1011 #endif
996       1012    
997 }   1013 }
998 //========================================================================================   1014 //========================================================================================
999     1015  
1000 void Shell_SetImage(UGL_Int shellHandle, UGL_Int imageHandle, UGL_Error uglError) {   1016 void Shell_SetImage(UGL_Int shellHandle, UGL_Int imageHandle, UGL_Error uglError) {
1001     /*   1017     /*
1002     * Feature in WinCE.  WM_SETICON and WM_GETICON set the icon   1018     * Feature in WinCE.  WM_SETICON and WM_GETICON set the icon
1003     * for the window class, not the window instance.  This means   1019     * for the window class, not the window instance.  This means
1004     * that it is possible to set an icon into a window and then   1020     * that it is possible to set an icon into a window and then
1005     * later free the icon, thus freeing the icon for every window.   1021     * later free the icon, thus freeing the icon for every window.
1006     * The fix is to avoid the API.   1022     * The fix is to avoid the API.
1007     *   1023     *
1008     * On WinCE PPC, icons in windows are not displayed.   1024     * On WinCE PPC, icons in windows are not displayed.
1009     */   1025     */
1010 #ifdef _WIN32_WCE   1026 #ifdef _WIN32_WCE
1011     return;   1027     return;
1012 #else   1028 #else
1013     1029  
1014     PUGL_Control ugl_shell = UGL_CONTROL(shellHandle);   1030     PUGL_Control ugl_shell = UGL_CONTROL(shellHandle);
1015     PUGL_Image ugl_image = UGL_IMAGE(imageHandle);   1031     PUGL_Image ugl_image = UGL_IMAGE(imageHandle);
1016     1032  
1017     ICONINFO icon_info;   1033     ICONINFO icon_info;
1018     HICON hIcon;   1034     HICON hIcon;
1019     1035  
1020     if (imageHandle == 0) {   1036     if (imageHandle == 0) {
1021         // remove icon from shell   1037         // remove icon from shell
1022         hIcon = NULL;   1038         hIcon = NULL;
1023     } else {   1039     } else {
1024         memset(&icon_info, 0, sizeof(ICONINFO));   1040         memset(&icon_info, 0, sizeof(ICONINFO));
1025         icon_info.fIcon = TRUE;   1041         icon_info.fIcon = TRUE;
1026         icon_info.hbmColor = ugl_image->image_handle;   1042         icon_info.hbmColor = ugl_image->image_handle;
1027         icon_info.hbmMask = ugl_image->image_handle;   1043         icon_info.hbmMask = ugl_image->image_handle;
1028     1044  
1029         hIcon = CreateIconIndirect(&icon_info);   1045         hIcon = CreateIconIndirect(&icon_info);
1030         if (hIcon == NULL) {   1046         if (hIcon == NULL) {
1031             Win32Error_SetError(uglError, GetLastError(), _T("Unable to create icon from image!"));   1047             Win32Error_SetError(uglError, GetLastError(), _T("Unable to create icon from image!"));
1032             return;   1048             return;
1033         }   1049         }
1034     }   1050     }
1035     1051  
1036     SendMessage(ugl_shell->hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);   1052     SendMessage(ugl_shell->hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
1037     SendMessage(ugl_shell->hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);   1053     SendMessage(ugl_shell->hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
1038     1054  
1039     /*   1055     /*
1040     * Bug in Windows.  When WM_SETICON is used to remove an   1056     * Bug in Windows.  When WM_SETICON is used to remove an
1041     * icon from the window trimmings for a window with the   1057     * icon from the window trimmings for a window with the
1042     * extended style bits WS_EX_DLGMODALFRAME, the window   1058     * extended style bits WS_EX_DLGMODALFRAME, the window
1043     * trimmings do not redraw to hide the previous icon.   1059     * trimmings do not redraw to hide the previous icon.
1044     * The fix is to force a redraw.   1060     * The fix is to force a redraw.
1045     */   1061     */
1046     1062  
1047     RedrawWindow(ugl_shell->hWnd, NULL, 0, RDW_FRAME | RDW_INVALIDATE);   1063     RedrawWindow(ugl_shell->hWnd, NULL, 0, RDW_FRAME | RDW_INVALIDATE);
1048     1064  
1049 #endif // defined _WIN32_WCE   1065 #endif // defined _WIN32_WCE
1050 }   1066 }
1051 //========================================================================================   1067 //========================================================================================
1052     1068  
1053 void Shell_SetResizable(UGL_Int shellHandle, UGL_Boolean resizeable, UGL_Error uglError)  {   1069 void Shell_SetResizable(UGL_Int shellHandle, UGL_Boolean resizeable, UGL_Error uglError)  {
1054     PUGL_Shell ugl_shell = UGL_SHELL(shellHandle);   1070     PUGL_Shell ugl_shell = UGL_SHELL(shellHandle);
1055     int style_bits = 0;   1071     int style_bits = 0;
1056     HWND hwnd = UGL_CONTROL(ugl_shell)->hWnd;   1072     HWND hwnd = UGL_CONTROL(ugl_shell)->hWnd;
1057     1073  
1058     1074  
1059 #ifdef _WIN32_WCE   1075 #ifdef _WIN32_WCE
1060     if (GetParent(hwnd) != NULL) {   1076     if (GetParent(hwnd) != NULL) {
1061 #endif   1077 #endif
1062     style_bits = GetWindowLong(hwnd, GWL_STYLE);   1078     style_bits = GetWindowLong(hwnd, GWL_STYLE);
1063       1079    
1064     if (resizeable) SET_FLAG(style_bits, WS_THICKFRAME);   1080     if (resizeable) SET_FLAG(style_bits, WS_THICKFRAME);
1065     else UNSET_FLAG(style_bits, WS_THICKFRAME);   1081     else UNSET_FLAG(style_bits, WS_THICKFRAME);
1066     1082  
1067     SetWindowLong(hwnd, GWL_STYLE, style_bits);   1083     SetWindowLong(hwnd, GWL_STYLE, style_bits);
1068     SetWindowPos(hwnd, NULL, 0,0,0,0, SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE);   1084     SetWindowPos(hwnd, NULL, 0,0,0,0, SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE);
1069 #ifdef _WIN32_WCE   1085 #ifdef _WIN32_WCE
1070     }   1086     }
1071 #endif   1087 #endif
1072 }   1088 }
1073 //========================================================================================   1089 //========================================================================================
1074     1090  
1075     1091  
1076 void _Shell_MoveAbove(PUGL_Control control, PUGL_Control sibling, UGL_Error error) {   1092 void _Shell_MoveAbove(PUGL_Control control, PUGL_Control sibling, UGL_Error error) {
1077     _Control_MoveAbove(control, sibling, error);   1093     _Control_MoveAbove(control, sibling, error);
1078     if (sibling == NULL) {   1094     if (sibling == NULL) {
1079         SetForegroundWindow(control->hWnd);   1095         SetForegroundWindow(control->hWnd);
1080     }   1096     }
1081 }   1097 }
1082     1098  
1083     1099  
1084 //========================================================================================   1100 //========================================================================================
1085     1101  
1086 void Shell_SetMenuBar(UGL_Int shellHandle, UGL_Int menuBarHandle, UGL_Error uglError)  {   1102 void Shell_SetMenuBar(UGL_Int shellHandle, UGL_Int menuBarHandle, UGL_Error uglError)  {
1087     PUGL_Shell ugl_shell = UGL_SHELL(shellHandle);   1103     PUGL_Shell ugl_shell = UGL_SHELL(shellHandle);
1088     PUGL_Menu ugl_menu = UGL_MENU(menuBarHandle);   1104     PUGL_Menu ugl_menu = UGL_MENU(menuBarHandle);
1089     PUGL_Control ugl_control = UGL_CONTROL(shellHandle);   1105     PUGL_Control ugl_control = UGL_CONTROL(shellHandle);
1090     1106  
1091 #if defined(WIN32_PLATFORM_PSPC)   1107 #if defined(WIN32_PLATFORM_PSPC)
1092     /*   1108     /*
1093     * Note in WinCE PPC.  The menu bar is a separate popup window.   1109     * Note in WinCE PPC.  The menu bar is a separate popup window.
1094     * If the shell is full screen, resize its window to leave   1110     * If the shell is full screen, resize its window to leave
1095     * space for the menu bar.   1111     * space for the menu bar.
1096     */   1112     */
1097     PUGL_Menu old_menu = ugl_shell->ugl_menu != NULL ? ugl_shell->ugl_menu : ugl_shell->emptyMenu;   1113     PUGL_Menu old_menu = ugl_shell->ugl_menu != NULL ? ugl_shell->ugl_menu : ugl_shell->emptyMenu;
1098     if (old_menu != NULL) ShowWindow(old_menu->hwndCB, SW_HIDE);   1114     if (old_menu != NULL) ShowWindow(old_menu->hwndCB, SW_HIDE);
1099       1115    
1100     ugl_shell->ugl_menu = ugl_menu;   1116     ugl_shell->ugl_menu = ugl_menu;
1101     1117  
1102     _Shell_EnsureMenuBarIsVisible(ugl_shell, ugl_control->parent);   1118     _Shell_EnsureMenuBarIsVisible(ugl_shell, ugl_control->parent);
1103 #endif // if PPC   1119 #endif // if PPC
1104     1120  
1105 #ifdef WIN32_PLATFORM_WFSP   1121 #ifdef WIN32_PLATFORM_WFSP
1106     1122  
1107     PUGL_Menu old_menu = ugl_shell->ugl_menu;   1123     PUGL_Menu old_menu = ugl_shell->ugl_menu;
1108     if (old_menu != NULL) ShowWindow(old_menu->hwndCB, SW_HIDE);   1124     if (old_menu != NULL) ShowWindow(old_menu->hwndCB, SW_HIDE);
1109     ugl_shell->ugl_menu = ugl_menu;   1125     ugl_shell->ugl_menu = ugl_menu;
1110     if (ugl_menu != NULL) ShowWindow(ugl_menu->hwndCB, SW_SHOW);   1126     if (ugl_menu != NULL) ShowWindow(ugl_menu->hwndCB, SW_SHOW);
1111           1127        
1112 #endif // if SP   1128 #endif // if SP
1113     1129  
1114 #if _WIN32_WCE && !(WIN32_PLATFORM_PSPC) && !(WIN32_PLATFORM_WFSP)   1130 #if _WIN32_WCE && !(WIN32_PLATFORM_PSPC) && !(WIN32_PLATFORM_WFSP)
1115     HWND shellHwnd = ugl_shell->scrollable.control.hWnd;   1131     HWND shellHwnd = ugl_shell->scrollable.control.hWnd;
1116     PUGL_Menu old_menu = ugl_shell->ugl_menu;   1132     PUGL_Menu old_menu = ugl_shell->ugl_menu;
1117     if (old_menu != NULL) {   1133     if (old_menu != NULL) {
1118         CommandBar_Show(old_menu->hwndCB, FALSE);   1134         CommandBar_Show(old_menu->hwndCB, FALSE);
1119     1135  
1120         // Shift the child widgets up to take into consideration the height of the commandbar which has been   1136         // Shift the child widgets up to take into consideration the height of the commandbar which has been
1121         // removed   1137         // removed
1122         ScrollWindowEx(shellHwnd, 0, -CommandBar_Height(old_menu->hwndCB), NULL, NULL, 0, NULL, SW_SCROLLCHILDREN);   1138         ScrollWindowEx(shellHwnd, 0, -CommandBar_Height(old_menu->hwndCB), NULL, NULL, 0, NULL, SW_SCROLLCHILDREN);
1123     }   1139     }
1124     ugl_shell->ugl_menu = ugl_menu;   1140     ugl_shell->ugl_menu = ugl_menu;
1125     if (ugl_menu != NULL) {   1141     if (ugl_menu != NULL) {
1126         // Shift the child widgets down to take make room for the new CommandBar.  For some reason   1142         // Shift the child widgets down to take make room for the new CommandBar.  For some reason
1127         // the CommandBar will return the wrong location if it is not at (0,0).  The CommandBar may not   1143         // the CommandBar will return the wrong location if it is not at (0,0).  The CommandBar may not
1128         // be at (0,0) if a second menubar has been created on the frame and is being made visible.  Moving   1144         // be at (0,0) if a second menubar has been created on the frame and is being made visible.  Moving
1129         // the CommandBar back to (0,0) before getting the height will fix this problem.   1145         // the CommandBar back to (0,0) before getting the height will fix this problem.
1130         SetWindowPos(ugl_menu->hwndCB, HWND_TOPMOST, 0,0,0,0, SWP_NOSIZE);   1146         SetWindowPos(ugl_menu->hwndCB, HWND_TOPMOST, 0,0,0,0, SWP_NOSIZE);
1131         ScrollWindowEx(shellHwnd, 0, CommandBar_Height(ugl_menu->hwndCB), NULL, NULL, 0, NULL, SW_SCROLLCHILDREN);   1147         ScrollWindowEx(shellHwnd, 0, CommandBar_Height(ugl_menu->hwndCB), NULL, NULL, 0, NULL, SW_SCROLLCHILDREN);
1132       1148    
1133         // Bring the CommandBar to the front and make sure that it is at the top of the window.  This second   1149         // Bring the CommandBar to the front and make sure that it is at the top of the window.  This second
1134         // call is needed because the ScrollWindowEx call above will move the CommandBar in addition to the other   1150         // call is needed because the ScrollWindowEx call above will move the CommandBar in addition to the other
1135         // widgets.   1151         // widgets.
1136         SetWindowPos(ugl_menu->hwndCB, HWND_TOPMOST, 0,0,0,0, SWP_NOSIZE);   1152         SetWindowPos(ugl_menu->hwndCB, HWND_TOPMOST, 0,0,0,0, SWP_NOSIZE);
1137     1153  
1138         CommandBar_Show(ugl_menu->hwndCB, TRUE);   1154         CommandBar_Show(ugl_menu->hwndCB, TRUE);
1139     }   1155     }
1140     1156  
1141     // On WinCE the application should only have a title bar, or a menu bar.  Both at the same   1157     // On WinCE the application should only have a title bar, or a menu bar.  Both at the same
1142     // time wastes space and should be avoided.  This is only true for maximized though shells since   1158     // time wastes space and should be avoided.  This is only true for maximized though shells since
1143     // shells that don't fill the entire screen look weird without a titlebar   1159     // shells that don't fill the entire screen look weird without a titlebar
1144     if (_Shell_GetMaximized(ugl_shell) == TRUE) {   1160     if (_Shell_GetMaximized(ugl_shell) == TRUE) {
1145         LONG styleBits = GetWindowLong(shellHwnd, GWL_STYLE);   1161         LONG styleBits = GetWindowLong(shellHwnd, GWL_STYLE);
1146           1162        
1147         if (menuBarHandle == 0) {   1163         if (menuBarHandle == 0) {
1148             styleBits |= WS_CAPTION;   1164             styleBits |= WS_CAPTION;
1149         } else {   1165         } else {
1150             styleBits &= ~WS_CAPTION;   1166             styleBits &= ~WS_CAPTION;
1151     1167  
1152             CommandBar_AddAdornments(ugl_menu->hwndCB, 0,0);   1168             CommandBar_AddAdornments(ugl_menu->hwndCB, 0,0);
1153         }   1169         }
1154     1170  
1155         SetWindowLong(shellHwnd, GWL_STYLE, styleBits);   1171         SetWindowLong(shellHwnd, GWL_STYLE, styleBits);
1156     1172  
1157         // Force the update of the frame   1173         // Force the update of the frame
1158         _SetWindowPos(shellHwnd, 0, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);   1174         _SetWindowPos(shellHwnd, 0, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1159     }   1175     }
1160 #endif   1176 #endif
1161     1177  
1162 #ifndef _WIN32_WCE   1178 #ifndef _WIN32_WCE
1163     SetMenu(ugl_shell->scrollable.control.hWnd, (ugl_menu != NULL ? ugl_menu->hMenu : 0));   1179     SetMenu(ugl_shell->scrollable.control.hWnd, (ugl_menu != NULL ? ugl_menu->hMenu : 0));
1164 #endif // if WINCE   1180 #endif // if WINCE
1165 }   1181 }
1166 //========================================================================================   1182 //========================================================================================
1167     1183  
1168 #define ACCEL_TABLE_INIT_SIZE 10   1184 #define ACCEL_TABLE_INIT_SIZE 10
1169 #define ACCEL_TABLE_INCREMENT 5   1185 #define ACCEL_TABLE_INCREMENT 5
1170     1186  
1171 void _Shell_SetAccelerator(PUGL_Shell shell, LPACCEL accel, UGL_Error error) {   1187 void _Shell_SetAccelerator(PUGL_Shell shell, LPACCEL accel, UGL_Error error) {
1172     // Try to update the entry in place, or signal that a new   1188     // Try to update the entry in place, or signal that a new
1173     // entry needs to be created to hold this accel   1189     // entry needs to be created to hold this accel
1174     BOOL needsAdd = TRUE;   1190     BOOL needsAdd = TRUE;
1175     if (shell->accel_entries != 0) {   1191     if (shell->accel_entries != 0) {
1176         int i;   1192         int i;
1177         for (i=0;i<shell->accel_entries_used;i++) {   1193         for (i=0;i<shell->accel_entries_used;i++) {
1178             if (shell->accel_entries[i].cmd == accel->cmd) {   1194             if (shell->accel_entries[i].cmd == accel->cmd) {
1179                 shell->accel_entries[i].fVirt = accel->fVirt;   1195                 shell->accel_entries[i].fVirt = accel->fVirt;
1180                 shell->accel_entries[i].key = accel->key;   1196                 shell->accel_entries[i].key = accel->key;
1181                 needsAdd = FALSE;   1197                 needsAdd = FALSE;
1182                 break;   1198                 break;
1183             }   1199             }
1184         }   1200         }
1185     }   1201     }
1186     1202  
1187     // If the accelerator does not have any entry then a new one must   1203     // If the accelerator does not have any entry then a new one must
1188     // be created   1204     // be created
1189     if (needsAdd) {   1205     if (needsAdd) {
1190         int i;   1206         int i;
1191     1207  
1192         // Either a new table needs to be created or we just need   1208         // Either a new table needs to be created or we just need
1193         // to make sure that there is enough space at the end of the table   1209         // to make sure that there is enough space at the end of the table
1194         if (shell->accel_entries == NULL) {   1210         if (shell->accel_entries == NULL) {
1195             shell->accel_entries = (LPACCEL)calloc(sizeof(ACCEL), ACCEL_TABLE_INIT_SIZE);   1211             shell->accel_entries = (LPACCEL)calloc(sizeof(ACCEL), ACCEL_TABLE_INIT_SIZE);
1196             if (shell->accel_entries == NULL) {   1212             if (shell->accel_entries == NULL) {
1197                 Win32Error_SetError(error, UGL_ERROR_OUT_OF_MEMORY, _T("Not enough space to create accelerator table"));   1213                 Win32Error_SetError(error, UGL_ERROR_OUT_OF_MEMORY, _T("Not enough space to create accelerator table"));
1198                 return;   1214                 return;
1199             }   1215             }
1200     1216  
1201             shell->accel_entries_space = ACCEL_TABLE_INIT_SIZE;   1217             shell->accel_entries_space = ACCEL_TABLE_INIT_SIZE;
1202             shell->accel_entries_used = 0;   1218             shell->accel_entries_used = 0;
1203         } else {   1219         } else {
1204             if (shell->accel_entries_used == shell->accel_entries_space) {   1220             if (shell->accel_entries_used == shell->accel_entries_space) {
1205                 // The table is maxed out and is must be resized to fit the new entry   1221                 // The table is maxed out and is must be resized to fit the new entry
1206                 int newSize = shell->accel_entries_space + ACCEL_TABLE_INCREMENT;   1222                 int newSize = shell->accel_entries_space + ACCEL_TABLE_INCREMENT;
1207                 LPACCEL newTable = (LPACCEL)calloc(sizeof(ACCEL), newSize);   1223                 LPACCEL newTable = (LPACCEL)calloc(sizeof(ACCEL), newSize);
1208                 LPACCEL oldTable = NULL;   1224                 LPACCEL oldTable = NULL;
1209                 if (newTable == NULL) {   1225                 if (newTable == NULL) {
1210                     Win32Error_SetError(error, UGL_ERROR_OUT_OF_MEMORY, _T("Not enough space to grow accelerator table"));   1226                     Win32Error_SetError(error, UGL_ERROR_OUT_OF_MEMORY, _T("Not enough space to grow accelerator table"));
1211                     return;   1227                     return;
1212                 }   1228                 }
1213                 memcpy(newTable, shell->accel_entries, shell->accel_entries_used * sizeof(ACCEL));   1229                 memcpy(newTable, shell->accel_entries, shell->accel_entries_used * sizeof(ACCEL));
1214                 oldTable = shell->accel_entries;   1230                 oldTable = shell->accel_entries;
1215                 shell->accel_entries = newTable;   1231                 shell->accel_entries = newTable;
1216                 shell->accel_entries_space = newSize;   1232                 shell->accel_entries_space = newSize;
1217     1233  
1218                 // The old table is not needed anymore   1234                 // The old table is not needed anymore
1219                 free(oldTable);               1235                 free(oldTable);            
1220             }   1236             }
1221         }   1237         }
1222     1238  
1223         // By now we've either created a new table, or ensured there is enough space   1239         // By now we've either created a new table, or ensured there is enough space
1224         // at the end of the current table to add a entry   1240         // at the end of the current table to add a entry
1225         i = shell->accel_entries_used;   1241         i = shell->accel_entries_used;
1226         shell->accel_entries[i].cmd = accel->cmd;   1242         shell->accel_entries[i].cmd = accel->cmd;
1227         shell->accel_entries[i].fVirt = accel->fVirt;   1243         shell->accel_entries[i].fVirt = accel->fVirt;
1228         shell->accel_entries[i].key = accel->key;   1244         shell->accel_entries[i].key = accel->key;
1229         shell->accel_entries_used++;   1245         shell->accel_entries_used++;
1230     }   1246     }
1231     1247  
1232     // Destory the cached accelerator table because of the change   1248     // Destory the cached accelerator table because of the change
1233     if (shell->accelerator_table != 0) DestroyAcceleratorTable(shell->accelerator_table);   1249     if (shell->accelerator_table != 0) DestroyAcceleratorTable(shell->accelerator_table);
1234     shell->accelerator_table = 0;   1250     shell->accelerator_table = 0;
1235 }   1251 }
1236     1252  
1237 void _Shell_RemoveAccelerator(PUGL_Shell shell, WORD cmd) {   1253 void _Shell_RemoveAccelerator(PUGL_Shell shell, WORD cmd) {
1238     int i;   1254     int i;
1239     for (i=0;i<shell->accel_entries_used;i++) {   1255     for (i=0;i<shell->accel_entries_used;i++) {
1240         if (shell->accel_entries[i].cmd == cmd) {   1256         if (shell->accel_entries[i].cmd == cmd) {
1241             // The command was in the list, so all entries   1257             // The command was in the list, so all entries
1242             // after the comment should be shifted down one   1258             // after the comment should be shifted down one
1243             // spot and the size shrunk by 1   1259             // spot and the size shrunk by 1
1244             int nextEntry = i+1;   1260             int nextEntry = i+1;
1245             memmove(shell->accel_entries + i, shell->accel_entries + nextEntry, (shell->accel_entries_used - nextEntry) * sizeof(ACCEL));   1261             memmove(shell->accel_entries + i, shell->accel_entries + nextEntry, (shell->accel_entries_used - nextEntry) * sizeof(ACCEL));
1246             shell->accel_entries_used--;   1262             shell->accel_entries_used--;
1247     1263  
1248             // Since the list has been modifed, the cached table   1264             // Since the list has been modifed, the cached table
1249             // should be removed   1265             // should be removed
1250             if (shell->accelerator_table != 0) {   1266             if (shell->accelerator_table != 0) {
1251                 DestroyAcceleratorTable(shell->accelerator_table);   1267                 DestroyAcceleratorTable(shell->accelerator_table);
1252             }   1268             }
1253         }   1269         }
1254     }   1270     }
1255 }   1271 }
1256     1272  
1257 HACCEL _Shell_GetAcceleratorTable(PUGL_Shell shell) {   1273 HACCEL _Shell_GetAcceleratorTable(PUGL_Shell shell) {
1258     if (shell->accelerator_table == 0) {   1274     if (shell->accelerator_table == 0) {
1259         if (shell->accel_entries_used == 0) {   1275         if (shell->accel_entries_used == 0) {
1260             return 0;   1276             return 0;
1261         } else {   1277         } else {
1262             shell->accelerator_table = CreateAcceleratorTable(shell->accel_entries, shell->accel_entries_used);   1278             shell->accelerator_table = CreateAcceleratorTable(shell->accel_entries, shell->accel_entries_used);
1263         }   1279         }
1264     }   1280     }
1265     return shell->accelerator_table;   1281     return shell->accelerator_table;
1266 }   1282 }
1267     1283  
1268     1284  
1269     1285  
1270     1286  
1271 //========================================================================================   1287 //========================================================================================
1272     1288  
1273 UGL_Boolean Shell_GetMaximized(UGL_Int handle, UGL_Error uglError) {   1289 UGL_Boolean Shell_GetMaximized(UGL_Int handle, UGL_Error uglError) {
1274     PUGL_Shell shell = (PUGL_Shell)handle;   1290     PUGL_Shell shell = (PUGL_Shell)handle;
1275     return _Shell_GetMaximized(shell);   1291     return _Shell_GetMaximized(shell);
1276 }   1292 }
1277     1293  
1278 //========================================================================================   1294 //========================================================================================
1279     1295  
1280 /**   1296 /**
1281 * Makes a button the default for this shell.  Default buttons may   1297 * Makes a button the default for this shell.  Default buttons may
1282 * have a special appearance, or they may take the initial focus   1298 * have a special appearance, or they may take the initial focus
1283 * from the shell.   1299 * from the shell.
1284 *   1300 *
1285 * @param buttonHandle the button to be made default, or 0 if no default   1301 * @param buttonHandle the button to be made default, or 0 if no default
1286 *                     button should be used.  This handle will only   1302 *                     button should be used.  This handle will only
1287 *                     be buttons created with PushButton_New()   1303 *                     be buttons created with PushButton_New()
1288 */   1304 */
1289 void Shell_SetDefaultButton(UGL_Int shellhandle, UGL_Int buttonHandle, UGL_Error uglError) {   1305 void Shell_SetDefaultButton(UGL_Int shellhandle, UGL_Int buttonHandle, UGL_Error uglError) {
1290     PUGL_Control shell = UGL_CONTROL(shellhandle);   1306     PUGL_Control shell = UGL_CONTROL(shellhandle);
1291       1307    
1292     // Unset the old button   1308     // Unset the old button
1293     HWND oldButton = (HWND)SendMessage(shell->hWnd, DM_GETDEFID, 0, 0);   1309     HWND oldButton = (HWND)SendMessage(shell->hWnd, DM_GETDEFID, 0, 0);
1294     if (oldButton != NULL) {   1310     if (oldButton != NULL) {
1295         int oldbits = GetWindowLong(oldButton, GWL_STYLE);   1311         int oldbits = GetWindowLong(oldButton, GWL_STYLE);
1296         oldbits &= ~BS_DEFPUSHBUTTON;   1312         oldbits &= ~BS_DEFPUSHBUTTON;
1297         SendMessage(oldButton, BM_SETSTYLE, oldbits, 1);   1313         SendMessage(oldButton, BM_SETSTYLE, oldbits, 1);
1298     }   1314     }
1299     1315  
1300     // Update the new button   1316     // Update the new button
1301     if (buttonHandle != 0) {   1317     if (buttonHandle != 0) {
1302         PUGL_Control button = UGL_CONTROL(buttonHandle);   1318         PUGL_Control button = UGL_CONTROL(buttonHandle);
1303         int bits = GetWindowLong(button->hWnd, GWL_STYLE);   1319         int bits = GetWindowLong(button->hWnd, GWL_STYLE);
1304         bits |= BS_DEFPUSHBUTTON;   1320         bits |= BS_DEFPUSHBUTTON;
1305         SendMessage(button->hWnd, BM_SETSTYLE, bits, 1);   1321         SendMessage(button->hWnd, BM_SETSTYLE, bits, 1);
1306     1322  
1307         SendMessage(shell->hWnd, DM_SETDEFID, (WPARAM)button->hWnd, 0);   1323         SendMessage(shell->hWnd, DM_SETDEFID, (WPARAM)button->hWnd, 0);
1308     } else {   1324     } else {
1309         SendMessage(shell->hWnd, DM_SETDEFID, 0, 0);   1325         SendMessage(shell->hWnd, DM_SETDEFID, 0, 0);
1310     }   1326     }
1311 }   1327 }
1312     1328