FILE COMPARISON
Produced: 2/18/2011 4:22:12 PM
   
Mode:  All Lines  
   
Left file: C:\Documents and Settings\krollins\My Documents\Admin\OpenSource\eRCP\eSWT\current\source\modified\original\MenuItem.c  
Right file: C:\Documents and Settings\krollins\My Documents\Admin\OpenSource\eRCP\eSWT\current\source\modified\MenuItem.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     11  
    <> 12 /*******************************************************************************
      13 * Additions/modifications to this source file by Oracle America, Inc. 2011
      14 *******************************************************************************/
      15  
12 #include "ugl_win32.h" = 16 #include "ugl_win32.h"
13 #include "UGL_Win32_Widget.h"   17 #include "UGL_Win32_Widget.h"
14 #include "UGL_win32_display.h"   18 #include "UGL_win32_display.h"
15 #include "UGL_Win32_Menu.h"   19 #include "UGL_Win32_Menu.h"
16 #include "UGL_Win32_DC.h"   20 #include "UGL_Win32_DC.h"
17 #include "KeyUtils.h"   21 #include "KeyUtils.h"
18 #include "Platform.h"   22 #include "Platform.h"
19     23  
20 #ifdef _WIN32_WCE   24 #ifdef _WIN32_WCE
21 #include <commctrl.h>   25 #include <commctrl.h>
22 #include <sipapi.h>   26 #include <sipapi.h>
23     27  
24 #if (_WIN32_WCE >= 420)   28 #if (_WIN32_WCE >= 420)
25 #include <aygshell.h>   29 #include <aygshell.h>
26 #endif   30 #endif
27 #endif /* _WIN32_WCE */   31 #endif /* _WIN32_WCE */
28     32  
29 // for softkey   33 // for softkey
30 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)   34 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
31 #include "i18n.h"   35 #include "i18n.h"
32 #include "Resource.h"   36 #include "Resource.h"
33     37  
34 #define MENU_MSG_BUFF_SIZE  100   38 #define MENU_MSG_BUFF_SIZE  100
35 #endif   39 #endif
36     40  
37 #include <assert.h>   41 #include <assert.h>
38     42  
39 #include "Widget.h"   43 #include "Widget.h"
40 #include "Control.h"   44 #include "Control.h"
41 #include "Image.h"   45 #include "Image.h"
42 #include "MenuItem.h"   46 #include "MenuItem.h"
43 #include "Menu.h"   47 #include "Menu.h"
44 #include "Display.h"   48 #include "Display.h"
45     49  
46     50  
47 #define MENU_ITEM_TEXT_LENGTH 128   51 #define MENU_ITEM_TEXT_LENGTH 128
48     52  
49 //========================================================================================   53 //========================================================================================
50 static void _CascadeMenuItem_SetMenu(PUGL_MenuItem ugl_cascade, PUGL_Menu ugl_dropdown, UGL_Error uglError);   54 static void _CascadeMenuItem_SetMenu(PUGL_MenuItem ugl_cascade, PUGL_Menu ugl_dropdown, UGL_Error uglError);
51 static void _LabeledMenuItem_SetText(PUGL_MenuItem ugl_menuItem, UGL_String text, UGL_String accelText, UGL_Error uglError);   55 static void _LabeledMenuItem_SetText(PUGL_MenuItem ugl_menuItem, UGL_String text, UGL_String accelText, UGL_Error uglError);
52 static void _AbstractMenuItem_SetEnabled(PUGL_MenuItem ugl_menuItem, UGL_Boolean enabled, UGL_Error uglError);   56 static void _AbstractMenuItem_SetEnabled(PUGL_MenuItem ugl_menuItem, UGL_Boolean enabled, UGL_Error uglError);
53 static PUGL_MenuItem _MenuItem_New_WinCe(PUGL_Menu ugl_Menu, PUGL_MenuItem ugl_menuItem, int index, int type);   57 static PUGL_MenuItem _MenuItem_New_WinCe(PUGL_Menu ugl_Menu, PUGL_MenuItem ugl_menuItem, int index, int type);
54 static PUGL_MenuItem _MenuItem_New(UGL_Int menuHandle, int type, BOOLEAN isCascade, int index, UGL_Error uglError);   58 static PUGL_MenuItem _MenuItem_New(UGL_Int menuHandle, int type, BOOLEAN isCascade, int index, UGL_Error uglError);
55 static LRESULT _wmDrawChild(UGL_Int handle, WPARAM wParam, LPARAM lParam);   59 static LRESULT _wmDrawChild(UGL_Int handle, WPARAM wParam, LPARAM lParam);
56 static LRESULT _wmMeasureChild(UGL_Int handle, WPARAM wParam, LPARAM lParam);   60 static LRESULT _wmMeasureChild(UGL_Int handle, WPARAM wParam, LPARAM lParam);
57 static LRESULT _wmCommandChild(UGL_Int handle, WPARAM wParam, LPARAM lParam);   61 static LRESULT _wmCommandChild(UGL_Int handle, WPARAM wParam, LPARAM lParam);
58 static void _Dispose(PUGL_Menu ugl_menu, int id, UGL_Error uglError);   62 static void _Dispose(PUGL_Menu ugl_menu, int id, UGL_Error uglError);
59 void _Dispose_MenuItem(UGL_Int handle, UGL_Error uglError);   63 void _Dispose_MenuItem(UGL_Int handle, UGL_Error uglError);
60 void _Update_Enabled(PUGL_Display display, HWND hwndCB);   64 void _Update_Enabled(PUGL_Display display, HWND hwndCB);
61 //========================================================================================   65 //========================================================================================
    <> 66 #ifdef _WIN32_WCE
      67 static HMENU getMenuForCheck(HMENU parent_menu);
      68 #endif // #ifdef _WIN32_WCE
      69  
      70 #ifdef _WIN32_WCE
      71 static HMENU getMenuForCheck(PUGL_Menu parent_menu)
      72 {
      73     HMENU hMenu = parent_menu->hMenu;
      74     // if the parent menu is the menubar, we need to find the submenu
      75     // of the popup so that the check will actually work
      76     if (parent_menu->hwndCB != 0)
      77     {
      78         HMENU hMenuNew = SendMessage (parent_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);
      79         if (hMenuNew != 0)
      80         {
      81             hMenu = hMenuNew;
      82         }
      83     }
      84  
      85     return hMenu;
      86 }
      87 #endif // #ifdef _WIN32_WCE
62   = 88  
63 void Menu_Redraw(PUGL_Menu menu) {   89 void Menu_Redraw(PUGL_Menu menu) {
64 #if _WIN32_WCE && !WIN32_PLATFORM_PSPC && !WIN32_PLATFORM_WFSP   90 #if _WIN32_WCE && !WIN32_PLATFORM_PSPC && !WIN32_PLATFORM_WFSP
65       91    
66     if (menu->hwndCB != NULL) {   92     if (menu->hwndCB != NULL) {
67         if (!CommandBar_DrawMenuBar(menu->hwndCB, 1)) {   93         if (!CommandBar_DrawMenuBar(menu->hwndCB, 1)) {
68             return; // Something went wrong   94             return; // Something went wrong
69         }   95         }
70     } else {   96     } else {
71         if (menu->cascadeItem != NULL) {   97         if (menu->cascadeItem != NULL) {
72             Menu_Redraw(menu->cascadeItem->parent_menu);   98             Menu_Redraw(menu->cascadeItem->parent_menu);
73         }   99         }
74     }   100     }
75       101    
76 #endif   102 #endif
77     103  
78 #ifndef _WIN32_WCE   104 #ifndef _WIN32_WCE
79     DrawMenuBar(menu->parent->hWnd);   105     DrawMenuBar(menu->parent->hWnd);
80 #endif   106 #endif
81 }   107 }
82     108  
83 /**   109 /**
84 * Returns the position of the menu item with the   110 * Returns the position of the menu item with the
85 * specified id in the parent menu.   111 * specified id in the parent menu.
86 */   112 */
87 UINT FindMenu(HMENU parent, UINT id) {   113 UINT FindMenu(HMENU parent, UINT id) {
88     UINT pos;   114     UINT pos;
89     MENUITEMINFO info;   115     MENUITEMINFO info;
90     info.cbSize = sizeof(MENUITEMINFO);   116     info.cbSize = sizeof(MENUITEMINFO);
91     info.fMask = MIIM_DATA;   117     info.fMask = MIIM_DATA;
92     118  
93     for (pos=0;;pos++) {   119     for (pos=0;;pos++) {
94         if (!GetMenuItemInfo(parent, pos, TRUE, &info)) {   120         if (!GetMenuItemInfo(parent, pos, TRUE, &info)) {
95             return -1;   121             return -1;
96         }   122         }
97     123  
98     124  
99         // When a submenu is inserted the id of the cascade menu item is   125         // When a submenu is inserted the id of the cascade menu item is
100         // set to the address of the submenu. Therefore we cannot use the   126         // set to the address of the submenu. Therefore we cannot use the
101         // wId field.   127         // wId field.
102         if (info.dwItemData == id) return pos;   128         if (info.dwItemData == id) return pos;
103     }   129     }
104 }   130 }
105     131  
106 /**   132 /**
107 * Updates the cascade item to have the new menu item specified.    133 * Updates the cascade item to have the new menu item specified. 
108 * This method is used instead of SetMenuItemInfo because SetMenuItemInfo   134 * This method is used instead of SetMenuItemInfo because SetMenuItemInfo
109 * will delete the previous menu automaticly.  This behavior is not desired   135 * will delete the previous menu automaticly.  This behavior is not desired
110 * and this method provides the behavior we want without the previous menu   136 * and this method provides the behavior we want without the previous menu
111 * being deleted.   137 * being deleted.
112 */   138 */
113 void _CascadeMenuItem_SetMenu(PUGL_MenuItem ugl_cascade, PUGL_Menu ugl_dropdown, UGL_Error uglError) {   139 void _CascadeMenuItem_SetMenu(PUGL_MenuItem ugl_cascade, PUGL_Menu ugl_dropdown, UGL_Error uglError) {
114     HMENU parentMenu = ugl_cascade->parent_menu->hMenu;   140     HMENU parentMenu = ugl_cascade->parent_menu->hMenu;
115     int id = ugl_cascade->id;   141     int id = ugl_cascade->id;
116     MENUITEMINFO info;   142     MENUITEMINFO info;
117     int flags;   143     int flags;
118     HMENU dropdown;   144     HMENU dropdown;
119     TCHAR oldText[MENU_ITEM_TEXT_LENGTH];   145     TCHAR oldText[MENU_ITEM_TEXT_LENGTH];
120       146    
121     147  
122     // Calculate the position of the menu item with the   148     // Calculate the position of the menu item with the
123     // id that we are looking for by walking through the   149     // id that we are looking for by walking through the
124     // list untill we get a match or and error.  This code is not very   150     // list untill we get a match or and error.  This code is not very
125     // pretty but it is required that we use the position instead of the id   151     // pretty but it is required that we use the position instead of the id
126     // when accessing the menu item below.  See the comments below for more   152     // when accessing the menu item below.  See the comments below for more
127     // details.   153     // details.
128     int pos = FindMenu(parentMenu, id);   154     int pos = FindMenu(parentMenu, id);
129     if (pos == -1) {   155     if (pos == -1) {
130         Win32Error_SetError(uglError, GetLastError(), _T("Unable to find the item"));   156         Win32Error_SetError(uglError, GetLastError(), _T("Unable to find the item"));
131         return;   157         return;
132     }   158     }
133     159  
134     // The text from the old menu item needs be retrieved so that it can be used in the new item   160     // The text from the old menu item needs be retrieved so that it can be used in the new item
135     memset(&info, 0, sizeof(MENUITEMINFO));   161     memset(&info, 0, sizeof(MENUITEMINFO));
136     info.cbSize = sizeof(MENUITEMINFO);   162     info.cbSize = sizeof(MENUITEMINFO);
137 #ifndef _WIN32_WCE   163 #ifndef _WIN32_WCE
138     info.fMask = MIIM_STRING; // MSDN says that the dwTypeData is only used when MIIM_STRING is used   164     info.fMask = MIIM_STRING; // MSDN says that the dwTypeData is only used when MIIM_STRING is used
139 #else   165 #else
140     info.fMask = MIIM_TYPE;   166     info.fMask = MIIM_TYPE;
141 #endif   167 #endif
142     info.dwTypeData = oldText;   168     info.dwTypeData = oldText;
143     info.cch = MENU_ITEM_TEXT_LENGTH;   169     info.cch = MENU_ITEM_TEXT_LENGTH;
144     if (!GetMenuItemInfo(parentMenu, pos, TRUE, &info)) {   170     if (!GetMenuItemInfo(parentMenu, pos, TRUE, &info)) {
145         Win32Error_SetError(uglError, GetLastError(), _T("Unable to get the menu item text"));   171         Win32Error_SetError(uglError, GetLastError(), _T("Unable to get the menu item text"));
146         return;       172         return;    
147     }   173     }
148     174  
149     // Insert the new menu item at the same location as the old item.    175     // Insert the new menu item at the same location as the old item. 
150     // NOTE:  The insert call must use MF_BYPOSITION since windows will   176     // NOTE:  The insert call must use MF_BYPOSITION since windows will
151     // not properly find menu items by id if they have a submenu set.    177     // not properly find menu items by id if they have a submenu set. 
152     flags = MF_BYPOSITION;   178     flags = MF_BYPOSITION;
153     if (ugl_dropdown != 0) {   179     if (ugl_dropdown != 0) {
154         flags |= MF_POPUP;   180         flags |= MF_POPUP;
155         dropdown = ugl_dropdown->hMenu;   181         dropdown = ugl_dropdown->hMenu;
156     } else {   182     } else {
157         dropdown = 0;   183         dropdown = 0;
158     }   184     }
159     if (!InsertMenu(parentMenu, pos, flags, (UINT)dropdown, oldText)) {   185     if (!InsertMenu(parentMenu, pos, flags, (UINT)dropdown, oldText)) {
160         Win32Error_SetError(uglError, GetLastError(), _T("Unable to insert new cascade menu item"));   186         Win32Error_SetError(uglError, GetLastError(), _T("Unable to insert new cascade menu item"));
161         return;   187         return;
162     }   188     }
163     189  
164     // When a submenu is inserted the id of the cascade menu item is   190     // When a submenu is inserted the id of the cascade menu item is
165     // set to the address of the submenu. Set our internal item id   191     // set to the address of the submenu. Set our internal item id
166     // (global item index) in the data field.   192     // (global item index) in the data field.
167     memset(&info, 0, sizeof(MENUITEMINFO));   193     memset(&info, 0, sizeof(MENUITEMINFO));
168     info.cbSize = sizeof(MENUITEMINFO);   194     info.cbSize = sizeof(MENUITEMINFO);
169     info.fMask = MIIM_DATA;   195     info.fMask = MIIM_DATA;
170     info.dwItemData = id;   196     info.dwItemData = id;
171     197  
172 //fix for Bug#:107883 make sure the image retains when menuitem cascades   198 //fix for Bug#:107883 make sure the image retains when menuitem cascades
173 #if (_WIN32_WCE < 500)   199 #if (_WIN32_WCE < 500)
174     #if !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP))   200     #if !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP))
175         info.fMask |= MIIM_BITMAP;   201         info.fMask |= MIIM_BITMAP;
176         info.hbmpItem = HBMMENU_CALLBACK;   202         info.hbmpItem = HBMMENU_CALLBACK;
177     #endif   203     #endif
178 #endif   204 #endif
179     205  
180       206    
181     SetMenuItemInfo(parentMenu, pos, TRUE, &info);   207     SetMenuItemInfo(parentMenu, pos, TRUE, &info);
182     208  
183     // If the new item was inserted correctly the old item can be removed   209     // If the new item was inserted correctly the old item can be removed
184     // NOTE:  The delete call must use MF_BYPOSITION since windows will   210     // NOTE:  The delete call must use MF_BYPOSITION since windows will
185     // not properly find menu items by id if they have a submenu set.    211     // not properly find menu items by id if they have a submenu set. 
186     212  
187     // NOTE:  Remove menu should be used because DeleteMenu will destroy   213     // NOTE:  Remove menu should be used because DeleteMenu will destroy
188     // the submenu which is not what we want.   214     // the submenu which is not what we want.
189     if (!RemoveMenu(parentMenu, pos+1, MF_BYPOSITION)) {   215     if (!RemoveMenu(parentMenu, pos+1, MF_BYPOSITION)) {
190         Win32Error_SetError(uglError, GetLastError(), _T("Unable to delete old menu item"));   216         Win32Error_SetError(uglError, GetLastError(), _T("Unable to delete old menu item"));
191     }   217     }
192 }   218 }
193     219  
194 void CascadeMenuItem_SetMenu(UGL_Int cascadeMenuItemHandle, UGL_Int dropDownMenuHandle, UGL_Error uglError) {   220 void CascadeMenuItem_SetMenu(UGL_Int cascadeMenuItemHandle, UGL_Int dropDownMenuHandle, UGL_Error uglError) {
195     221  
196     PUGL_MenuItem ugl_cascade = UGL_MENUITEM(cascadeMenuItemHandle);   222     PUGL_MenuItem ugl_cascade = UGL_MENUITEM(cascadeMenuItemHandle);
197     PUGL_Menu ugl_dropdown = UGL_MENU(dropDownMenuHandle);   223     PUGL_Menu ugl_dropdown = UGL_MENU(dropDownMenuHandle);
198     UGL_Display *display = display = UGL_WIDGET(ugl_cascade)->display;   224     UGL_Display *display = display = UGL_WIDGET(ugl_cascade)->display;
199     225  
200     226  
201     #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)   227     #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
202     {   228     {
203         TBBUTTONINFO info;   229         TBBUTTONINFO info;
204         PUGL_MenuItem tempItem;   230         PUGL_MenuItem tempItem;
205         BOOL found;   231         BOOL found;
206         int i;   232         int i;
207         found = FALSE;   233         found = FALSE;
208         memset(&info, 0, sizeof(TBBUTTONINFO));   234         memset(&info, 0, sizeof(TBBUTTONINFO));
209         // check for softkey support   235         // check for softkey support
210         if (Platform_GetMajorVersion() < 5) {   236         if (Platform_GetMajorVersion() < 5) {
211             HWND hwndCB = ugl_cascade->parent_menu->hwndCB;   237             HWND hwndCB = ugl_cascade->parent_menu->hwndCB;
212             int id = ugl_cascade->id;   238             int id = ugl_cascade->id;
213             if (hwndCB != 0) {   239             if (hwndCB != 0) {
214                 HWND oldMenu = (HWND)SendMessage(hwndCB, SHCMBM_SETSUBMENU, id, (LPARAM) ugl_dropdown->hMenu);   240                 HWND oldMenu = (HWND)SendMessage(hwndCB, SHCMBM_SETSUBMENU, id, (LPARAM) ugl_dropdown->hMenu);
215             } else {   241             } else {
216                 _CascadeMenuItem_SetMenu(ugl_cascade, ugl_dropdown, uglError);   242                 _CascadeMenuItem_SetMenu(ugl_cascade, ugl_dropdown, uglError);
217             }   243             }
218         } else {   244         } else {
219             HWND hwndCB = ugl_cascade->parent_menu->hwndMB;   245             HWND hwndCB = ugl_cascade->parent_menu->hwndMB;
220             HWND realhwndCB = ugl_cascade->parent_menu->hwndCB;   246             HWND realhwndCB = ugl_cascade->parent_menu->hwndCB;
221             HMENU hMenu = (HMENU) SendMessage (ugl_cascade->parent_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);   247             HMENU hMenu = (HMENU) SendMessage (ugl_cascade->parent_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);
222             _TCHAR msgBuff[MENU_MSG_BUFF_SIZE];   248             _TCHAR msgBuff[MENU_MSG_BUFF_SIZE];
223             // if main menu   249             // if main menu
224             if (hwndCB != 0) {   250             if (hwndCB != 0) {
225                 // if the first item on the button is being set a  submenu, find a item that doesn't have a submenu to replace it   251                 // if the first item on the button is being set a  submenu, find a item that doesn't have a submenu to replace it
226                 if(ugl_cascade->index == 0) {   252                 if(ugl_cascade->index == 0) {
227                     // if found, set the item's index to 0 and increment every other items by 1.   253                     // if found, set the item's index to 0 and increment every other items by 1.
228                     for(i = 1; i < display->menuItemsLength; i++){   254                     for(i = 1; i < display->menuItemsLength; i++){
229                         tempItem = Display_FindMenuItem(display, realhwndCB, i);   255                         tempItem = Display_FindMenuItem(display, realhwndCB, i);
230                         if(tempItem != NULL && !tempItem->hasSubMenu){   256                         if(tempItem != NULL && !tempItem->hasSubMenu){
231                             // move the first item that doesn't have submenu into the first spot   257                             // move the first item that doesn't have submenu into the first spot
232                             RemoveMenu (hMenu, tempItem->index-1, MF_BYPOSITION);   258                             RemoveMenu (hMenu, tempItem->index-1, MF_BYPOSITION);
233                             InsertMenu (hMenu, 0, MF_BYPOSITION | MF_POPUP, (UINT) ugl_dropdown->hMenu, ugl_cascade->text);   259                             InsertMenu (hMenu, 0, MF_BYPOSITION | MF_POPUP, (UINT) ugl_dropdown->hMenu, ugl_cascade->text);
234                             Display_DecMenuItemIndex(display, realhwndCB, tempItem->index);   260                             Display_DecMenuItemIndex(display, realhwndCB, tempItem->index);
235                             Display_IncMenuItemIndex(display, realhwndCB, 0);   261                             Display_IncMenuItemIndex(display, realhwndCB, 0);
236                             tempItem->index = 0;   262                             tempItem->index = 0;
237                             info.cbSize = sizeof(TBBUTTONINFO);   263                             info.cbSize = sizeof(TBBUTTONINFO);
238                             info.dwMask = TBIF_TEXT;   264                             info.dwMask = TBIF_TEXT;
239                             info.pszText = (LPWSTR) tempItem->text;   265                             info.pszText = (LPWSTR) tempItem->text;
240                             if(!SendMessage (ugl_cascade->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){   266                             if(!SendMessage (ugl_cascade->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){
241                                 Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));   267                                 Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));
242                             }   268                             }
243                             LoadResourceString(display->hInstance, IDS_U_MENU, msgBuff, MENU_MSG_BUFF_SIZE);   269                             LoadResourceString(display->hInstance, IDS_U_MENU, msgBuff, MENU_MSG_BUFF_SIZE);
244                             info.pszText = msgBuff;   270                             info.pszText = msgBuff;
245                             SendMessage (ugl_cascade->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);   271                             SendMessage (ugl_cascade->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);
246                             found = TRUE;   272                             found = TRUE;
247     273  
248                             //ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);   274                             //ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);
249                             //ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);   275                             //ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);
250     276  
251                             if (display->activeShell == ugl_cascade->parent_menu->parent) {   277                             if (display->activeShell == ugl_cascade->parent_menu->parent) {
252                                 ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);   278                                 ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);
253                                 ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);   279                                 ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);
254                             } /*else {   280                             } /*else {
255                                 ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_HIDE);   281                                 ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_HIDE);
256                                 ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);   282                                 ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);
257                             }*/   283                             }*/
258     284  
259     285  
260                             break;   286                             break;
261                         }   287                         }
262                     }   288                     }
263                     // if not found, simply set the left softkey to be blank and add one item with submenu on the right menu.   289                     // if not found, simply set the left softkey to be blank and add one item with submenu on the right menu.
264                     if(!found){   290                     if(!found){
265                         info.cbSize = sizeof(TBBUTTONINFO);   291                         info.cbSize = sizeof(TBBUTTONINFO);
266                         info.dwMask = TBIF_TEXT;   292                         info.dwMask = TBIF_TEXT;
267                         info.pszText = (LPWSTR) _T("");   293                         info.pszText = (LPWSTR) _T("");
268                         if(!SendMessage (ugl_cascade->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){   294                         if(!SendMessage (ugl_cascade->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){
269                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));   295                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));
270                         }   296                         }
271                         Display_IncMenuItemIndex(display, realhwndCB, 0);   297                         Display_IncMenuItemIndex(display, realhwndCB, 0);
272                         InsertMenu (hMenu, 0, MF_BYPOSITION | MF_POPUP, (UINT) ugl_dropdown->hMenu, ugl_cascade->text);   298                         InsertMenu (hMenu, 0, MF_BYPOSITION | MF_POPUP, (UINT) ugl_dropdown->hMenu, ugl_cascade->text);
273                         LoadResourceString(display->hInstance, IDS_U_MENU, msgBuff, MENU_MSG_BUFF_SIZE);   299                         LoadResourceString(display->hInstance, IDS_U_MENU, msgBuff, MENU_MSG_BUFF_SIZE);
274                         info.pszText = msgBuff;   300                         info.pszText = msgBuff;
275                         SendMessage (ugl_cascade->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);   301                         SendMessage (ugl_cascade->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);
276     302  
277                         if (display->activeShell == ugl_cascade->parent_menu->parent) {   303                         if (display->activeShell == ugl_cascade->parent_menu->parent) {
278                             ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);   304                             ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);
279                             ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);   305                             ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);
280                         } /*else {   306                         } /*else {
281                             ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_HIDE);   307                             ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_HIDE);
282                             ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);   308                             ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);
283                         }*/   309                         }*/
284                         //ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);   310                         //ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);
285                         //ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);   311                         //ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);
286                     }   312                     }
287                     ugl_cascade->hasSubMenu=TRUE;   313                     ugl_cascade->hasSubMenu=TRUE;
288                 } else {   314                 } else {
289                     // if adding submenu to menuitem, directly add it.   315                     // if adding submenu to menuitem, directly add it.
290                     ugl_cascade->hasSubMenu=TRUE;   316                     ugl_cascade->hasSubMenu=TRUE;
291                     RemoveMenu (hMenu, ugl_cascade->index-1, MF_BYPOSITION);   317                     RemoveMenu (hMenu, ugl_cascade->index-1, MF_BYPOSITION);
292                     InsertMenu (hMenu, ugl_cascade->index-1, MF_BYPOSITION | MF_POPUP, (UINT) ugl_dropdown->hMenu, ugl_cascade->text);   318                     InsertMenu (hMenu, ugl_cascade->index-1, MF_BYPOSITION | MF_POPUP, (UINT) ugl_dropdown->hMenu, ugl_cascade->text);
293     319  
294                     // if index = 1, it's likely the right softkey is not set to IDS_U_MENU, load the resource and set it //Uriel   320                     // if index = 1, it's likely the right softkey is not set to IDS_U_MENU, load the resource and set it //Uriel
295                     if(ugl_cascade->index == 1) {   321                     if(ugl_cascade->index == 1) {
296                         info.cbSize = sizeof(TBBUTTONINFO);   322                         info.cbSize = sizeof(TBBUTTONINFO);
297                         info.dwMask = TBIF_TEXT;   323                         info.dwMask = TBIF_TEXT;
298                         LoadResourceString(display->hInstance, IDS_U_MENU, msgBuff, MENU_MSG_BUFF_SIZE);   324                         LoadResourceString(display->hInstance, IDS_U_MENU, msgBuff, MENU_MSG_BUFF_SIZE);
299                         info.pszText = msgBuff;   325                         info.pszText = msgBuff;
300                         SendMessage (ugl_cascade->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);   326                         SendMessage (ugl_cascade->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);
301                     }   327                     }
302     328  
303                 }   329                 }
304                 // when adding submenu to main menu, always show MB menu bar   330                 // when adding submenu to main menu, always show MB menu bar
305                 //ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);   331                 //ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);
306                 //ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);   332                 //ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);
307                 if (display->activeShell == ugl_cascade->parent_menu->parent) {   333                 if (display->activeShell == ugl_cascade->parent_menu->parent) {
308                     ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);   334                     ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);
309                     ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);   335                     ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);
310                 } /*else {   336                 } /*else {
311                     ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_HIDE);   337                     ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_HIDE);
312                     ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);   338                     ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);
313                 }*/   339                 }*/
314     340  
315     341  
316             } else {   342             } else {
317                 // submenu   343                 // submenu
318                 _CascadeMenuItem_SetMenu(ugl_cascade, ugl_dropdown, uglError);   344                 _CascadeMenuItem_SetMenu(ugl_cascade, ugl_dropdown, uglError);
319                 if (display->activeShell == ugl_cascade->parent_menu->parent) {   345                 if (display->activeShell == ugl_cascade->parent_menu->parent) {
320                     ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);   346                     ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);
321                     ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);   347                     ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);
322                 }/* else {   348                 }/* else {
323                     ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_HIDE);   349                     ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_HIDE);
324                     ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);   350                     ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);
325                 }*/   351                 }*/
326     352  
327                 //ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);   353                 //ShowWindow(ugl_cascade->parent_menu->hwndMB, SW_SHOW);
328                 //ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);   354                 //ShowWindow(ugl_cascade->parent_menu->hwndCB, SW_HIDE);
329     355  
330             }   356             }
331         }   357         }
332     }   358     }
333 #else   359 #else
334     _CascadeMenuItem_SetMenu(ugl_cascade, ugl_dropdown, uglError);   360     _CascadeMenuItem_SetMenu(ugl_cascade, ugl_dropdown, uglError);
335 #endif   361 #endif
336     362  
337     {   363     {
338         if (ugl_cascade->dropDownMenu != NULL) {   364         if (ugl_cascade->dropDownMenu != NULL) {
339 #if defined(DEBUG) && !defined(_WIN32_WCE)   365 #if defined(DEBUG) && !defined(_WIN32_WCE)
340             if (IsMenu(ugl_cascade->dropDownMenu->hMenu) == FALSE) {   366             if (IsMenu(ugl_cascade->dropDownMenu->hMenu) == FALSE) {
341                 Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Previous menu was diposed when removing it from menuitem"));   367                 Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Previous menu was diposed when removing it from menuitem"));
342             }   368             }
343 #endif   369 #endif
344             ugl_cascade->dropDownMenu->cascadeItem = NULL;   370             ugl_cascade->dropDownMenu->cascadeItem = NULL;
345         }   371         }
346         if (ugl_dropdown != NULL) ugl_dropdown->cascadeItem = ugl_cascade;   372         if (ugl_dropdown != NULL) ugl_dropdown->cascadeItem = ugl_cascade;
347         ugl_cascade->dropDownMenu = ugl_dropdown;   373         ugl_cascade->dropDownMenu = ugl_dropdown;
348     }   374     }
349     375  
350     Menu_Redraw(ugl_cascade->parent_menu);   376     Menu_Redraw(ugl_cascade->parent_menu);
351 }   377 }
352 //========================================================================================   378 //========================================================================================
353     379  
354 UGL_Int StateMenuItem_New(UGL_Int menuHandle, UGL_Int index, UGL_Int style, UGL_Error uglError) {   380 UGL_Int StateMenuItem_New(UGL_Int menuHandle, UGL_Int index, UGL_Int style, UGL_Error uglError) {
355     int type = (IS_FLAG_SET(style, UGL_STYLE_RADIO) ? MFT_RADIOCHECK : MFT_STRING);   381     int type = (IS_FLAG_SET(style, UGL_STYLE_RADIO) ? MFT_RADIOCHECK : MFT_STRING);
356       382    
357     PUGL_MenuItem ugl_menuItem = _MenuItem_New(menuHandle, type, FALSE, index, uglError);   383     PUGL_MenuItem ugl_menuItem = _MenuItem_New(menuHandle, type, FALSE, index, uglError);
358     UGL_WIDGET(ugl_menuItem)->ugl_style = style | UGL_STYLE_CHECK;   384     UGL_WIDGET(ugl_menuItem)->ugl_style = style | UGL_STYLE_CHECK;
359     return (UGL_Int)ugl_menuItem;   385     return (UGL_Int)ugl_menuItem;
360 }   386 }
361 //========================================================================================   387 //========================================================================================
362     388  
363 void LabeledMenuItem_SetFont(UGL_Int menuItemHandle, UGL_Int fontHandle, UGL_Error uglError) {   389 void LabeledMenuItem_SetFont(UGL_Int menuItemHandle, UGL_Int fontHandle, UGL_Error uglError) {
364     //NO OP   390     //NO OP
365 }   391 }
366 //========================================================================================   392 //========================================================================================
367     393  
368 UGL_Int CascadeMenuItem_New(UGL_Int menuHandle, UGL_Int index, UGL_Error uglError) {   394 UGL_Int CascadeMenuItem_New(UGL_Int menuHandle, UGL_Int index, UGL_Error uglError) {
369     int type = MFT_STRING;   395     int type = MFT_STRING;
370     PUGL_MenuItem ugl_menuItem = NULL;   396     PUGL_MenuItem ugl_menuItem = NULL;
371     PUGL_Menu ugl_menu = UGL_MENU(menuHandle);   397     PUGL_Menu ugl_menu = UGL_MENU(menuHandle);
372     398  
373     399  
374     ugl_menuItem = _MenuItem_New(menuHandle, type, TRUE, index, uglError);   400     ugl_menuItem = _MenuItem_New(menuHandle, type, TRUE, index, uglError);
375     401  
376     Menu_Redraw(ugl_menu);   402     Menu_Redraw(ugl_menu);
377     403  
378     return (UGL_Int)ugl_menuItem;   404     return (UGL_Int)ugl_menuItem;
379 }   405 }
380 //========================================================================================   406 //========================================================================================
381     407  
382 void StateMenuItem_SetSelection(UGL_Int statefulMenuItemHandle, UGL_Boolean selected, UGL_Error uglError) {   408 void StateMenuItem_SetSelection(UGL_Int statefulMenuItemHandle, UGL_Boolean selected, UGL_Error uglError) {
383     PUGL_MenuItem ugl_item = UGL_MENUITEM(statefulMenuItemHandle);   409     PUGL_MenuItem ugl_item = UGL_MENUITEM(statefulMenuItemHandle);
384     410  
385     HMENU hMenu = ugl_item->parent_menu->hMenu;   411     HMENU hMenu = ugl_item->parent_menu->hMenu;
386     int item_id = ugl_item->id; //ugl_item->menu_item_info.wID;   412     int item_id = ugl_item->id; //ugl_item->menu_item_info.wID;
387     413  
388 #ifdef _WIN32_WCE   414 #ifdef _WIN32_WCE
    <> 415     int flags;
      416     int count;
      417 #else
      418     MENUITEMINFO info;
      419     BOOL success;
      420 #endif // #ifdef _WIN32_WCE
      421  
      422     // cache this so we are in sync with the java side
      423     // the java side sets the selected state before setting
      424     // it natively
      425     ugl_item->isSelected = selected;
      426  
      427 #ifdef _WIN32_WCE
      428     count = Display_MenuItemCount(UGL_WIDGET(ugl_item)->display, ugl_item->parent_menu->hwndCB);
      429     if (count <= 2)
      430     {
      431         // there aren't more than 2 menu items, so don't set the checked state yet
      432         // because both of the menu items are on the menu bar
      433         return;
      434     }
      435  
      436     hMenu = getMenuForCheck(ugl_item->parent_menu);
      437  
389     int flags = MF_BYCOMMAND | (selected ? MF_CHECKED : MF_UNCHECKED);   438     flags = MF_BYCOMMAND | (selected ? MF_CHECKED : MF_UNCHECKED);
390     if (CheckMenuItem(hMenu, item_id, flags) == -1) { = 439     if (CheckMenuItem(hMenu, item_id, flags) == -1) {
391         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Menu item doesn't exist"));   440         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Menu item doesn't exist"));
392         return;   441         return;
393     }   442     }
394 #else   443 #else
395     MENUITEMINFO info; <>    
396     BOOL success;      
397          
398        
399     info.cbSize = sizeof(MENUITEMINFO); = 444     info.cbSize = sizeof(MENUITEMINFO);
400     info.fMask = MIIM_STATE;   445     info.fMask = MIIM_STATE;
401     success = GetMenuItemInfo(hMenu, item_id, FALSE, (LPMENUITEMINFO)&info);   446     success = GetMenuItemInfo(hMenu, item_id, FALSE, (LPMENUITEMINFO)&info);
402     if (!success) {   447     if (!success) {
403         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to get current state menu selection"));   448         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to get current state menu selection"));
404         return;   449         return;
405     }   450     }
406     451  
407     info.fState &= ~MFS_CHECKED;   452     info.fState &= ~MFS_CHECKED;
408     if (selected) info.fState |= MFS_CHECKED;   453     if (selected) info.fState |= MFS_CHECKED;
409     success = SetMenuItemInfo (hMenu, item_id, FALSE, (LPMENUITEMINFO)&info);   454     success = SetMenuItemInfo (hMenu, item_id, FALSE, (LPMENUITEMINFO)&info);
410       455    
411     if (!success) {   456     if (!success) {
412         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to get current state menu selection"));   457         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to get current state menu selection"));
413         return;   458         return;
414     }   459     }
415 #endif // defined _WIN32_WCE   460 #endif // defined _WIN32_WCE
416     461  
417     Menu_Redraw(ugl_item->parent_menu);   462     Menu_Redraw(ugl_item->parent_menu);
418 }   463 }
    <> 464  
      465 void StateMenuItem_DisableAutoSelection(UGL_Int statefulMenuItemHandle, UGL_Boolean disableAutoSelection)
      466 {
      467     PUGL_MenuItem ugl_item = UGL_MENUITEM(statefulMenuItemHandle);
      468     ugl_item->disableAutoSelection = disableAutoSelection;
      469 }
      470  
419 //======================================================================================== = 471 //========================================================================================
420     472  
421 UGL_Int SeparatorItem_New(UGL_Int menuHandle, UGL_Int index, UGL_Error uglError) {   473 UGL_Int SeparatorItem_New(UGL_Int menuHandle, UGL_Int index, UGL_Error uglError) {
422     int type = MFT_SEPARATOR;   474     int type = MFT_SEPARATOR;
423       475    
424     return (UGL_Int)_MenuItem_New(menuHandle, type, FALSE, index, uglError);   476     return (UGL_Int)_MenuItem_New(menuHandle, type, FALSE, index, uglError);
425 }   477 }
426 //========================================================================================   478 //========================================================================================
427     479  
428 UGL_Int PushMenuItem_New(UGL_Int menuHandle, UGL_Int index, UGL_Error uglError) {   480 UGL_Int PushMenuItem_New(UGL_Int menuHandle, UGL_Int index, UGL_Error uglError) {
429     int type = MFT_STRING;   481     int type = MFT_STRING;
430       482    
431     return (UGL_Int)_MenuItem_New(menuHandle, type, FALSE, index, uglError);   483     return (UGL_Int)_MenuItem_New(menuHandle, type, FALSE, index, uglError);
432       484    
433 }   485 }
434 //========================================================================================   486 //========================================================================================
435     487  
436 void _LabeledMenuItem_SetText(PUGL_MenuItem ugl_menuItem, UGL_String text, UGL_String accelText, UGL_Error uglError) {   488 void _LabeledMenuItem_SetText(PUGL_MenuItem ugl_menuItem, UGL_String text, UGL_String accelText, UGL_Error uglError) {
437     MENUITEMINFO info;    489     MENUITEMINFO info; 
438     LPTSTR combined = NULL;   490     LPTSTR combined = NULL;
439     491  
440     492  
441         int accelLength;   493         int accelLength;
442       494    
443         int pos = FindMenu(ugl_menuItem->parent_menu->hMenu, ugl_menuItem->id);   495         int pos = FindMenu(ugl_menuItem->parent_menu->hMenu, ugl_menuItem->id);
444         if (pos == -1) {   496         if (pos == -1) {
445             Win32Error_SetError(uglError, GetLastError(), _T("Unable to find the item"));   497             Win32Error_SetError(uglError, GetLastError(), _T("Unable to find the item"));
446             return;   498             return;
447         }   499         }
448     500  
449         accelLength = lstrlen(accelText);   501         accelLength = lstrlen(accelText);
450         if (accelLength > 0) {   502         if (accelLength > 0) {
451             combined = (LPTSTR)calloc(sizeof(TCHAR), accelLength + lstrlen(text) + 2);   503             combined = (LPTSTR)calloc(sizeof(TCHAR), accelLength + lstrlen(text) + 2);
452             if (combined == NULL) {   504             if (combined == NULL) {
453                 Win32Error_SetError(uglError, UGL_ERROR_OUT_OF_MEMORY, _T(""));   505                 Win32Error_SetError(uglError, UGL_ERROR_OUT_OF_MEMORY, _T(""));
454                 return;   506                 return;
455             } else {   507             } else {
456                 lstrcat(combined, text);   508                 lstrcat(combined, text);
457                 lstrcat(combined, _T("\t"));   509                 lstrcat(combined, _T("\t"));
458                 lstrcat(combined, accelText);   510                 lstrcat(combined, accelText);
459             }   511             }
460         }   512         }
461       513    
462       514    
463         /*   515         /*
464         * Bug in Windows 2000.  For some reason, when MIIM_TYPE is set   516         * Bug in Windows 2000.  For some reason, when MIIM_TYPE is set
465         * on a menu item that also has MIIM_BITMAP, the MIIM_TYPE clears   517         * on a menu item that also has MIIM_BITMAP, the MIIM_TYPE clears
466         * the MIIM_BITMAP style.  The fix is to reset both MIIM_BITMAP.   518         * the MIIM_BITMAP style.  The fix is to reset both MIIM_BITMAP.
467         * Note, this does not happen on Windows 98.   519         * Note, this does not happen on Windows 98.
468         */   520         */
469         //boolean hasBitmap = false;   521         //boolean hasBitmap = false;
470         //if (!OS.IsWinCE && (OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) >= (4 << 16 | 10)) {   522         //if (!OS.IsWinCE && (OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) >= (4 << 16 | 10)) {
471         //  info.fMask = OS.MIIM_BITMAP;   523         //  info.fMask = OS.MIIM_BITMAP;
472         //  OS.GetMenuItemInfo (hMenu, id, false, info);   524         //  OS.GetMenuItemInfo (hMenu, id, false, info);
473         //  hasBitmap = info.hbmpItem != 0;   525         //  hasBitmap = info.hbmpItem != 0;
474         //}   526         //}
475           527        
476         /* Use the character encoding for the default locale */   528         /* Use the character encoding for the default locale */
477           529        
478         info.cbSize = sizeof(MENUITEMINFO);   530         info.cbSize = sizeof(MENUITEMINFO);
479     #ifndef _WIN32_WCE   531     #ifndef _WIN32_WCE
480         info.fMask = MIIM_STRING;   532         info.fMask = MIIM_STRING;
481     #else   533     #else
482         info.fMask = MIIM_TYPE; // This would be nicer as MIIM_STRING but that doesn't exist on WinCE   534         info.fMask = MIIM_TYPE; // This would be nicer as MIIM_STRING but that doesn't exist on WinCE
483         info.fType = MFT_STRING;   535         info.fType = MFT_STRING;
484     #endif   536     #endif
485         info.dwTypeData = combined == NULL ? text : combined;   537         info.dwTypeData = combined == NULL ? text : combined;
486     538  
487         // NOTE:  The SetMenuItemInfo call must use MF_BYPOSITION since windows will   539         // NOTE:  The SetMenuItemInfo call must use MF_BYPOSITION since windows will
488         // not properly find menu items by id if they have a submenu set.   540         // not properly find menu items by id if they have a submenu set.
489         if (!SetMenuItemInfo(ugl_menuItem->parent_menu->hMenu, pos, TRUE, &info)) {   541         if (!SetMenuItemInfo(ugl_menuItem->parent_menu->hMenu, pos, TRUE, &info)) {
490             Win32Error_SetError(uglError, GetLastError(), _T("Unable to update the menu item's label"));   542             Win32Error_SetError(uglError, GetLastError(), _T("Unable to update the menu item's label"));
491         } else {   543         } else {
492             Menu_Redraw(ugl_menuItem->parent_menu);   544             Menu_Redraw(ugl_menuItem->parent_menu);
493         }   545         }
494     546  
495         if (combined != NULL) free(combined);   547         if (combined != NULL) free(combined);
496     548  
497         /*   549         /*
498         * Restore the bitmap that was removed to work around a problem   550         * Restore the bitmap that was removed to work around a problem
499         * in GetMenuItemInfo() and menu items that have bitmaps set with   551         * in GetMenuItemInfo() and menu items that have bitmaps set with
500         * MIIM_BITMAP.   552         * MIIM_BITMAP.
501         */   553         */
502         //if (!OS.IsWinCE && (OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) >= (4 << 16 | 10)) {   554         //if (!OS.IsWinCE && (OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) >= (4 << 16 | 10)) {
503         //  if (hasBitmap) {   555         //  if (hasBitmap) {
504         //      info.fMask = OS.MIIM_BITMAP;   556         //      info.fMask = OS.MIIM_BITMAP;
505         //      info.hbmpItem = OS.HBMMENU_CALLBACK;   557         //      info.hbmpItem = OS.HBMMENU_CALLBACK;
506         //      success = OS.SetMenuItemInfo (hMenu, id, false, info);   558         //      success = OS.SetMenuItemInfo (hMenu, id, false, info);
507         //  }   559         //  }
508         //}   560         //}
509 }   561 }
510     562  
511 //========================================================================================   563 //========================================================================================
512     564  
513 void LabeledMenuItem_SetText(UGL_Int menuItemHandle, UGL_String text, UGL_String accelText, UGL_Error uglError) {   565 void LabeledMenuItem_SetText(UGL_Int menuItemHandle, UGL_String text, UGL_String accelText, UGL_Error uglError) {
514     PUGL_MenuItem ugl_menuItem = UGL_MENUITEM(menuItemHandle);   566     PUGL_MenuItem ugl_menuItem = UGL_MENUITEM(menuItemHandle);
515     567  
516 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)   568 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
517     {   569     {
518         UGL_Display *display = display = UGL_WIDGET(ugl_menuItem)->display;   570         UGL_Display *display = display = UGL_WIDGET(ugl_menuItem)->display;
519         HWND hwndCB = ugl_menuItem->parent_menu->hwndCB;   571         HWND hwndCB = ugl_menuItem->parent_menu->hwndCB;
520         UGL_String revise;   572         UGL_String revise;
521         UGL_Boolean isRevise = UGL_FALSE;   573         UGL_Boolean isRevise = UGL_FALSE;
522         UGL_Int i, j, len;   574         UGL_Int i, j, len;
523         for(i=0, len=0; *(text+i)!=0; i++) {   575         for(i=0, len=0; *(text+i)!=0; i++) {
524             if(*(text+i) != '&')   576             if(*(text+i) != '&')
525                 len++;   577                 len++;
526             else   578             else
527                 isRevise = UGL_TRUE;   579                 isRevise = UGL_TRUE;
528         }   580         }
529         if(isRevise) {   581         if(isRevise) {
530             revise = (UGL_String)calloc(len+1, sizeof(UGL_String));   582             revise = (UGL_String)calloc(len+1, sizeof(UGL_String));
531             for(i=0, j=0; *(text+i)!=0; i++) {   583             for(i=0, j=0; *(text+i)!=0; i++) {
532                 if(*(text+i) != '&') {   584                 if(*(text+i) != '&') {
533                     *(revise+j) = *(text+i);   585                     *(revise+j) = *(text+i);
534                     j++;   586                     j++;
535                 }   587                 }
536             }   588             }
537         } else {   589         } else {
538             revise = text;   590             revise = text;
539         }   591         }
540     592  
541         if (hwndCB != 0) {   593         if (hwndCB != 0) {
542             // top level "menu"bar   594             // top level "menu"bar
543             TBBUTTONINFO buttonInfo;   595             TBBUTTONINFO buttonInfo;
544     596  
545             memset(&buttonInfo, 0, sizeof(TBBUTTONINFO));   597             memset(&buttonInfo, 0, sizeof(TBBUTTONINFO));
546             buttonInfo.cbSize = sizeof(TBBUTTONINFO);   598             buttonInfo.cbSize = sizeof(TBBUTTONINFO);
547             buttonInfo.dwMask = TBIF_TEXT | TBIF_STATE;   599             buttonInfo.dwMask = TBIF_TEXT | TBIF_STATE;
548             buttonInfo.pszText = (LPWSTR) revise;   600             buttonInfo.pszText = (LPWSTR) revise;
549             buttonInfo.fsState &= ~TBSTATE_ENABLED;   601             buttonInfo.fsState &= ~TBSTATE_ENABLED;
550             if (ugl_menuItem->enabled){   602             if (ugl_menuItem->enabled){
551                 buttonInfo.fsState |= TBSTATE_ENABLED;   603                 buttonInfo.fsState |= TBSTATE_ENABLED;
552             }   604             }
553     605  
554             // check for softkey support   606             // check for softkey support
555             if (Platform_GetMajorVersion() >= 5) {   607             if (Platform_GetMajorVersion() >= 5) {
556     608  
557                 ugl_menuItem->text = (UGL_String)calloc(lstrlen(revise), sizeof(UGL_String));             609                 ugl_menuItem->text = (UGL_String)calloc(lstrlen(revise), sizeof(UGL_String));          
558                 lstrcpy(ugl_menuItem->text, revise);              610                 lstrcpy(ugl_menuItem->text, revise);           
559     611  
560                 //if first item, set left softkey text   612                 //if first item, set left softkey text
561                 if(ugl_menuItem->index == 0){   613                 if(ugl_menuItem->index == 0){
562                       614                    
563                         if (!SendMessage(hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (LPARAM) &buttonInfo)) {   615                         if (!SendMessage(hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (LPARAM) &buttonInfo)) {
564                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item text"));   616                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item text"));
565                         }   617                         }
566                           618                        
567                         if (!SendMessage(ugl_menuItem->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (LPARAM) &buttonInfo)) {   619                         if (!SendMessage(ugl_menuItem->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (LPARAM) &buttonInfo)) {
568                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item text"));   620                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item text"));
569                         }   621                         }
570                           622                        
571     623  
572                 } else if (ugl_menuItem->index == 1){   624                 } else if (ugl_menuItem->index == 1){
573                       625                    
574                     //if second item and only two items, set to right softkey   626                     //if second item and only two items, set to right softkey
575                     if(display->menuItemCount == 2 && !ugl_menuItem->hasSubMenu){   627                     if(display->menuItemCount == 2 && !ugl_menuItem->hasSubMenu){
576                         if (!SendMessage(hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (LPARAM) &buttonInfo)) {   628                         if (!SendMessage(hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (LPARAM) &buttonInfo)) {
577                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item text"));   629                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item text"));
578                         }   630                         }
579                         if (!SendMessage(ugl_menuItem->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (LPARAM) &buttonInfo)) {   631                         if (!SendMessage(ugl_menuItem->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (LPARAM) &buttonInfo)) {
580                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item text"));   632                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item text"));
581                         }   633                         }
582                     } else {   634                     } else {
583                         // else we need to set the text of the softkey's menu Item.                   635                         // else we need to set the text of the softkey's menu Item.                
584                         MENUITEMINFO info;   636                         MENUITEMINFO info;
585                         HMENU hMenu = (HMENU) SendMessage (ugl_menuItem->parent_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);   637                         HMENU hMenu = (HMENU) SendMessage (ugl_menuItem->parent_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);
586                         memset(&info, 0, sizeof(MENUITEMINFO));   638                         memset(&info, 0, sizeof(MENUITEMINFO));
587                         info.cbSize = sizeof(MENUITEMINFO);   639                         info.cbSize = sizeof(MENUITEMINFO);
588                         info.fMask = MIIM_TYPE;   640                         info.fMask = MIIM_TYPE;
589                         info.dwTypeData = revise;   641                         info.dwTypeData = revise;
590     642  
591                         if(!SetMenuItemInfo(hMenu, ugl_menuItem->index-1, TRUE, &info)){   643                         if(!SetMenuItemInfo(hMenu, ugl_menuItem->index-1, TRUE, &info)){
592                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item text"));   644                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item text"));
593                         }   645                         }
594                           646                        
595                     }   647                     }
596                 } else {   648                 } else {
597                     // else simply set the text for the menuitem   649                     // else simply set the text for the menuitem
598                         MENUITEMINFO info;   650                         MENUITEMINFO info;
599                         HMENU hMenu = (HMENU) SendMessage (ugl_menuItem->parent_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);   651                         HMENU hMenu = (HMENU) SendMessage (ugl_menuItem->parent_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);
600                         memset(&info, 0, sizeof(MENUITEMINFO));   652                         memset(&info, 0, sizeof(MENUITEMINFO));
601                         info.cbSize = sizeof(MENUITEMINFO);   653                         info.cbSize = sizeof(MENUITEMINFO);
602                         info.fMask = MIIM_TYPE;   654                         info.fMask = MIIM_TYPE;
603                         info.dwTypeData = revise;   655                         info.dwTypeData = revise;
604     656  
605                         if(!SetMenuItemInfo(hMenu, ugl_menuItem->index-1, TRUE, &info)){   657                         if(!SetMenuItemInfo(hMenu, ugl_menuItem->index-1, TRUE, &info)){
606                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item text"));   658                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item text"));
607                         }   659                         }
608                 }   660                 }
609             } else {      661             } else {   
610                 if (!SendMessage(hwndCB, TB_SETBUTTONINFO, ugl_menuItem->id, (LPARAM) &buttonInfo)) {   662                 if (!SendMessage(hwndCB, TB_SETBUTTONINFO, ugl_menuItem->id, (LPARAM) &buttonInfo)) {
611                     Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item text"));   663                     Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item text"));
612                 }   664                 }
613             }   665             }
614         } else {   666         } else {
615             // submenu   667             // submenu
616             _LabeledMenuItem_SetText(ugl_menuItem, revise, accelText, uglError);   668             _LabeledMenuItem_SetText(ugl_menuItem, revise, accelText, uglError);
617         }   669         }
618         if(isRevise)   670         if(isRevise)
619             free(revise);   671             free(revise);
620     }   672     }
621     673  
622 #else   674 #else
623     _LabeledMenuItem_SetText(ugl_menuItem, text, accelText, uglError);   675     _LabeledMenuItem_SetText(ugl_menuItem, text, accelText, uglError);
624 #endif   676 #endif
625 }   677 }
626 //========================================================================================   678 //========================================================================================
627     679  
628 void LabeledMenuItem_SetAccelerator(UGL_Int menuItemHandle, UGL_Int accelerator, UGL_Error uglError) {   680 void LabeledMenuItem_SetAccelerator(UGL_Int menuItemHandle, UGL_Int accelerator, UGL_Error uglError) {
629     PUGL_MenuItem menuItem = UGL_MENUITEM(menuItemHandle);   681     PUGL_MenuItem menuItem = UGL_MENUITEM(menuItemHandle);
630     PUGL_Shell parent= UGL_SHELL(menuItem->parent_menu->parent);   682     PUGL_Shell parent= UGL_SHELL(menuItem->parent_menu->parent);
631     WORD cmd = (short)menuItem->id;   683     WORD cmd = (short)menuItem->id;
632     684  
633     if (accelerator != 0) {   685     if (accelerator != 0) {
634         ACCEL entry;   686         ACCEL entry;
635         int modifiers = (accelerator >> 16) & 0x0000FFFF;   687         int modifiers = (accelerator >> 16) & 0x0000FFFF;
636     688  
637         entry.cmd = cmd;   689         entry.cmd = cmd;
638     690  
639         // Although not documented in MSDN, it appears that TranslateAccelerator will   691         // Although not documented in MSDN, it appears that TranslateAccelerator will
640         // only honor the FALT and FCONTROL constants if FVIRTKEY is used as well.   692         // only honor the FALT and FCONTROL constants if FVIRTKEY is used as well.
641         entry.fVirt = FVIRTKEY;   693         entry.fVirt = FVIRTKEY;
642         if (IS_FLAG_SET(modifiers, UGL_MODIFIER_MASK_ALT))      entry.fVirt |= FALT;   694         if (IS_FLAG_SET(modifiers, UGL_MODIFIER_MASK_ALT))      entry.fVirt |= FALT;
643         if (IS_FLAG_SET(modifiers, UGL_MODIFIER_MASK_CONTROL))  entry.fVirt |= FCONTROL;   695         if (IS_FLAG_SET(modifiers, UGL_MODIFIER_MASK_CONTROL))  entry.fVirt |= FCONTROL;
644         if (IS_FLAG_SET(modifiers, UGL_MODIFIER_MASK_SHIFT))    entry.fVirt |= FSHIFT;   696         if (IS_FLAG_SET(modifiers, UGL_MODIFIER_MASK_SHIFT))    entry.fVirt |= FSHIFT;
645     697  
646         entry.key = KeyUtils_ConvertToNativeKeycode(accelerator & 0x0000FFFF);   698         entry.key = KeyUtils_ConvertToNativeKeycode(accelerator & 0x0000FFFF);
647     699  
648         _Shell_SetAccelerator(parent, &entry, uglError);   700         _Shell_SetAccelerator(parent, &entry, uglError);
649     } else {   701     } else {
650         _Shell_RemoveAccelerator(parent, cmd);   702         _Shell_RemoveAccelerator(parent, cmd);
651     }   703     }
652 }   704 }
653 //========================================================================================   705 //========================================================================================
654     706  
655 void _AbstractMenuItem_SetEnabled(PUGL_MenuItem ugl_menuItem, UGL_Boolean enabled, UGL_Error uglError) {   707 void _AbstractMenuItem_SetEnabled(PUGL_MenuItem ugl_menuItem, UGL_Boolean enabled, UGL_Error uglError) {
656     int bits;   708     int bits;
657     HMENU hMenu = ugl_menuItem->parent_menu->hMenu;   709     HMENU hMenu = ugl_menuItem->parent_menu->hMenu;
658     710  
659     int pos = FindMenu(hMenu, ugl_menuItem->id);   711     int pos = FindMenu(hMenu, ugl_menuItem->id);
660     if (pos == -1) {   712     if (pos == -1) {
661         Win32Error_SetError(uglError, GetLastError(), _T("Unable to find the item"));   713         Win32Error_SetError(uglError, GetLastError(), _T("Unable to find the item"));
662         return;   714         return;
663     }   715     }
664     716  
665     bits = MF_BYPOSITION | (enabled ? MF_ENABLED : MF_GRAYED);   717     bits = MF_BYPOSITION | (enabled ? MF_ENABLED : MF_GRAYED);
666     718  
667     if (EnableMenuItem(hMenu, pos, bits) == -1) {   719     if (EnableMenuItem(hMenu, pos, bits) == -1) {
668         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("The menu item does not exist"));   720         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("The menu item does not exist"));
669         return;   721         return;
670     }   722     }
671     723  
672     Menu_Redraw(ugl_menuItem->parent_menu);   724     Menu_Redraw(ugl_menuItem->parent_menu);
673 }   725 }
674 //========================================================================================   726 //========================================================================================
675     727  
676 void AbstractMenuItem_SetEnabled(UGL_Int menuItemHandle, UGL_Boolean enabled, UGL_Error uglError) {   728 void AbstractMenuItem_SetEnabled(UGL_Int menuItemHandle, UGL_Boolean enabled, UGL_Error uglError) {
677     PUGL_MenuItem ugl_menuItem = UGL_MENUITEM(menuItemHandle);   729     PUGL_MenuItem ugl_menuItem = UGL_MENUITEM(menuItemHandle);
678     730  
679 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)   731 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
680     {   732     {
681         HWND hwndCB = ugl_menuItem->parent_menu->hwndCB;   733         HWND hwndCB = ugl_menuItem->parent_menu->hwndCB;
682     734  
683         if (hwndCB != NULL) {   735         if (hwndCB != NULL) {
684             TBBUTTONINFO buttonInfo;   736             TBBUTTONINFO buttonInfo;
685             memset(&buttonInfo, 0, sizeof(TBBUTTONINFO));   737             memset(&buttonInfo, 0, sizeof(TBBUTTONINFO));
686             buttonInfo.cbSize = sizeof(TBBUTTONINFO);   738             buttonInfo.cbSize = sizeof(TBBUTTONINFO);
687             buttonInfo.dwMask = TBIF_STATE;   739             buttonInfo.dwMask = TBIF_STATE;
688               740            
689               741            
690             // if has softkey support   742             // if has softkey support
691             if (Platform_GetMajorVersion() >= 5) {   743             if (Platform_GetMajorVersion() >= 5) {
692                   744                
693                 UGL_Display *display = display = UGL_WIDGET(ugl_menuItem)->display;   745                 UGL_Display *display = display = UGL_WIDGET(ugl_menuItem)->display;
694                 ugl_menuItem->enabled = enabled;   746                 ugl_menuItem->enabled = enabled;
695                 buttonInfo.fsState &= ~TBSTATE_ENABLED;   747                 buttonInfo.fsState &= ~TBSTATE_ENABLED;
696                 if (enabled){   748                 if (enabled){
697                     buttonInfo.fsState |= TBSTATE_ENABLED;   749                     buttonInfo.fsState |= TBSTATE_ENABLED;
698                 }   750                 }
699                 if(ugl_menuItem->index == 0){   751                 if(ugl_menuItem->index == 0){
700                       752                    
701                         if (!SendMessage(hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (LPARAM) &buttonInfo)) {   753                         if (!SendMessage(hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (LPARAM) &buttonInfo)) {
702                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item enabled state"));   754                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item enabled state"));
703                         }   755                         }
704                           756                        
705                         if (!SendMessage(ugl_menuItem->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (LPARAM) &buttonInfo)) {   757                         if (!SendMessage(ugl_menuItem->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (LPARAM) &buttonInfo)) {
706                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item enabled state"));   758                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item enabled state"));
707                         }   759                         }
708                           760                        
709     761  
710                 } else if (ugl_menuItem->index == 1){   762                 } else if (ugl_menuItem->index == 1){
711                       763                    
712                     //if second item and only two items, set to right softkey   764                     //if second item and only two items, set to right softkey
713                     if(display->menuItemCount == 2 && !ugl_menuItem->hasSubMenu){   765                     if(display->menuItemCount == 2 && !ugl_menuItem->hasSubMenu){
714                         if (!SendMessage(hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (LPARAM) &buttonInfo)) {   766                         if (!SendMessage(hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (LPARAM) &buttonInfo)) {
715                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item enabled state"));   767                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item enabled state"));
716                         }   768                         }
717                     } else {   769                     } else {
718                         // else we need to set the state of the softkey's menu Item.   770                         // else we need to set the state of the softkey's menu Item.
719                         int bits;   771                         int bits;
720                         HMENU hMenu = (HMENU) SendMessage (ugl_menuItem->parent_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);   772                         HMENU hMenu = (HMENU) SendMessage (ugl_menuItem->parent_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);
721                         bits = MF_BYPOSITION | (enabled ? MF_ENABLED : MF_GRAYED);   773                         bits = MF_BYPOSITION | (enabled ? MF_ENABLED : MF_GRAYED);
722     774  
723                         if (EnableMenuItem(hMenu,  ugl_menuItem->index-1, bits) == -1) {   775                         if (EnableMenuItem(hMenu,  ugl_menuItem->index-1, bits) == -1) {
724                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("The menu item does not exist"));   776                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("The menu item does not exist"));
725                             return;   777                             return;
726                         }   778                         }
727                     }   779                     }
728                 } else {   780                 } else {
729                     // else simply set the state for the menuitem   781                     // else simply set the state for the menuitem
730                         int bits;   782                         int bits;
731                         HMENU hMenu = (HMENU) SendMessage (ugl_menuItem->parent_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);   783                         HMENU hMenu = (HMENU) SendMessage (ugl_menuItem->parent_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);
732                         bits = MF_BYPOSITION | (enabled ? MF_ENABLED : MF_GRAYED);   784                         bits = MF_BYPOSITION | (enabled ? MF_ENABLED : MF_GRAYED);
733     785  
734                         if (EnableMenuItem(hMenu,  ugl_menuItem->index-1, bits) == -1) {   786                         if (EnableMenuItem(hMenu,  ugl_menuItem->index-1, bits) == -1) {
735                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("The menu item does not exist"));   787                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("The menu item does not exist"));
736                             return;   788                             return;
737                         }   789                         }
738                 }   790                 }
739     791  
740             } else {   792             } else {
741                 // else no softkey support   793                 // else no softkey support
742                 if (!SendMessage(hwndCB, TB_GETBUTTONINFO, ugl_menuItem->id, (LPARAM) &buttonInfo)) {   794                 if (!SendMessage(hwndCB, TB_GETBUTTONINFO, ugl_menuItem->id, (LPARAM) &buttonInfo)) {
743                     Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item enabled state"));   795                     Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item enabled state"));
744                 }   796                 }
745                 buttonInfo.fsState &= ~TBSTATE_ENABLED;   797                 buttonInfo.fsState &= ~TBSTATE_ENABLED;
746                 if (enabled) buttonInfo.fsState |= TBSTATE_ENABLED;   798                 if (enabled) buttonInfo.fsState |= TBSTATE_ENABLED;
747                 if (!SendMessage(hwndCB, TB_SETBUTTONINFO, ugl_menuItem->id, (LPARAM) &buttonInfo)) {   799                 if (!SendMessage(hwndCB, TB_SETBUTTONINFO, ugl_menuItem->id, (LPARAM) &buttonInfo)) {
748                     Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item enabled state"));   800                     Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set menu item enabled state"));
749                 }   801                 }
750             }   802             }
751         } else {   803         } else {
752             _AbstractMenuItem_SetEnabled(ugl_menuItem, enabled, uglError);   804             _AbstractMenuItem_SetEnabled(ugl_menuItem, enabled, uglError);
753         }   805         }
754           806        
755     }   807     }
756 #else   808 #else
757     _AbstractMenuItem_SetEnabled(ugl_menuItem, enabled, uglError);   809     _AbstractMenuItem_SetEnabled(ugl_menuItem, enabled, uglError);
758 #endif   810 #endif
759 }   811 }
760 //========================================================================================   812 //========================================================================================
761     813  
762 void LabeledMenuItem_SetImage(UGL_Int menuItemHandle, UGL_Int imageHandle, UGL_Error uglError) {   814 void LabeledMenuItem_SetImage(UGL_Int menuItemHandle, UGL_Int imageHandle, UGL_Error uglError) {
763     //if ((style & SWT.SEPARATOR) != 0) return;   815     //if ((style & SWT.SEPARATOR) != 0) return;
764     PUGL_MenuItem ugl_menuItem = UGL_MENUITEM(menuItemHandle);   816     PUGL_MenuItem ugl_menuItem = UGL_MENUITEM(menuItemHandle);
765     HMENU hMenu = ugl_menuItem->parent_menu->hMenu;   817     HMENU hMenu = ugl_menuItem->parent_menu->hMenu;
766     int id = ugl_menuItem->id;   818     int id = ugl_menuItem->id;
767     819  
768 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)   820 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
769     TBBUTTONINFO buttonInfo;   821     TBBUTTONINFO buttonInfo;
770     HIMAGELIST imagelist;             822     HIMAGELIST imagelist;          
771     int imageWidth, imageHeight, index;   823     int imageWidth, imageHeight, index;
772     BITMAP bitmap;   824     BITMAP bitmap;
773     HANDLE hBitmap;   825     HANDLE hBitmap;
774     HBITMAP himg, hmask, hOldBitmap;   826     HBITMAP himg, hmask, hOldBitmap;
775     HDC hdc, hdc1, hdc2;   827     HDC hdc, hdc1, hdc2;
776     828  
777     HWND hwndCB = ugl_menuItem->parent_menu->hwndCB;   829     HWND hwndCB = ugl_menuItem->parent_menu->hwndCB;
778       830    
779     ugl_menuItem->ugl_image = UGL_IMAGE(imageHandle);   831     ugl_menuItem->ugl_image = UGL_IMAGE(imageHandle);
780     GetObject(ugl_menuItem->ugl_image->image_handle, sizeof(BITMAP), &bitmap);   832     GetObject(ugl_menuItem->ugl_image->image_handle, sizeof(BITMAP), &bitmap);
781       833    
782     imageWidth = bitmap.bmWidth;   834     imageWidth = bitmap.bmWidth;
783     imageHeight = bitmap.bmHeight;   835     imageHeight = bitmap.bmHeight;
784     836  
785     if(hwndCB != 0)   837     if(hwndCB != 0)
786     {   838     {
787         (long) imagelist = SendMessage(hwndCB, TB_GETIMAGELIST, 0, 0);   839         (long) imagelist = SendMessage(hwndCB, TB_GETIMAGELIST, 0, 0);
788         if(imagelist == NULL){   840         if(imagelist == NULL){
789             // create imagelist if it's not previously created   841             // create imagelist if it's not previously created
790             imagelist = ImageList_Create(imageWidth, 20, ILC_COLOR | ILC_MASK, 16, 16);   842             imagelist = ImageList_Create(imageWidth, 20, ILC_COLOR | ILC_MASK, 16, 16);
791             SendMessage (hwndCB, TB_SETIMAGELIST, 0, (LPARAM) imagelist);   843             SendMessage (hwndCB, TB_SETIMAGELIST, 0, (LPARAM) imagelist);
792         }   844         }
793         // add image to the imagelist   845         // add image to the imagelist
794           846        
795           847        
796         ImageList_SetIconSize(imagelist, imageWidth, imageHeight);   848         ImageList_SetIconSize(imagelist, imageWidth, imageHeight);
797         hBitmap = ugl_menuItem->ugl_image != NULL ? ugl_menuItem->ugl_image->image_handle : NULL;   849         hBitmap = ugl_menuItem->ugl_image != NULL ? ugl_menuItem->ugl_image->image_handle : NULL;
798           850        
799         // prepare HBATMAP handle's for image and the mask   851         // prepare HBATMAP handle's for image and the mask
800         GetObject(hBitmap, sizeof(BITMAP), &bitmap);   852         GetObject(hBitmap, sizeof(BITMAP), &bitmap);
801         hdc = GetDC(0);   853         hdc = GetDC(0);
802         hdc1 = CreateCompatibleDC(hdc);   854         hdc1 = CreateCompatibleDC(hdc);
803         SelectObject(hdc1, hBitmap);   855         SelectObject(hdc1, hBitmap);
804         hdc2 = CreateCompatibleDC(hdc);   856         hdc2 = CreateCompatibleDC(hdc);
805         himg = CreateCompatibleBitmap(hdc, bitmap.bmWidth, bitmap.bmHeight);   857         himg = CreateCompatibleBitmap(hdc, bitmap.bmWidth, bitmap.bmHeight);
806         SelectObject(hdc2, himg);   858         SelectObject(hdc2, himg);
807         BitBlt(hdc2, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdc1, 0, 0, SRCCOPY);   859         BitBlt(hdc2, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdc1, 0, 0, SRCCOPY);
808     860  
809         DeleteDC(hdc1);   861         DeleteDC(hdc1);
810         DeleteDC(hdc2);   862         DeleteDC(hdc2);
811         ReleaseDC(0, hdc);   863         ReleaseDC(0, hdc);
812         // now we have Hbitmap for image   864         // now we have Hbitmap for image
813     865  
814         GetObject(hBitmap, sizeof(BITMAP), &bitmap);   866         GetObject(hBitmap, sizeof(BITMAP), &bitmap);
815         hmask = CreateBitmap(bitmap.bmWidth, bitmap.bmHeight, 1, 1, NULL);   867         hmask = CreateBitmap(bitmap.bmWidth, bitmap.bmHeight, 1, 1, NULL);
816         hdc = GetDC(0);   868         hdc = GetDC(0);
817         hdc1 = CreateCompatibleDC(hdc);   869         hdc1 = CreateCompatibleDC(hdc);
818     870  
819         hOldBitmap = SelectObject(hdc1, hmask);   871         hOldBitmap = SelectObject(hdc1, hmask);
820         PatBlt(hdc1, 0, 0, bitmap.bmWidth, bitmap.bmHeight, BLACKNESS);   872         PatBlt(hdc1, 0, 0, bitmap.bmWidth, bitmap.bmHeight, BLACKNESS);
821 //      SelectObject(hdc1, hOldBitmap);   873 //      SelectObject(hdc1, hOldBitmap);
822           874        
823         ReleaseDC(0, hdc);   875         ReleaseDC(0, hdc);
824         DeleteDC(hdc1);   876         DeleteDC(hdc1);
825         // now we have the mask   877         // now we have the mask
826     878  
827         index = ImageList_Add(imagelist, himg, hmask);            879         index = ImageList_Add(imagelist, himg, hmask);         
828         DeleteObject(hmask);   880         DeleteObject(hmask);
829         DeleteObject(himg);   881         DeleteObject(himg);
830     882  
831         memset(&buttonInfo, 0, sizeof(TBBUTTONINFO));   883         memset(&buttonInfo, 0, sizeof(TBBUTTONINFO));
832         buttonInfo.cbSize = sizeof(TBBUTTONINFO);   884         buttonInfo.cbSize = sizeof(TBBUTTONINFO);
833         buttonInfo.dwMask = TBIF_TEXT;   885         buttonInfo.dwMask = TBIF_TEXT;
834         buttonInfo.dwMask |= TBIF_IMAGE;     886         buttonInfo.dwMask |= TBIF_IMAGE;  
835         if(index != -1){   887         if(index != -1){
836             buttonInfo.iImage = index;   888             buttonInfo.iImage = index;
837         }   889         }
838         SendMessage(hwndCB, TB_SETBUTTONINFO, ugl_menuItem->id, (LPARAM) &buttonInfo);   890         SendMessage(hwndCB, TB_SETBUTTONINFO, ugl_menuItem->id, (LPARAM) &buttonInfo);
839     }   891     }
840     else   892     else
841     {   893     {
842         // the menuItem in PPC doesn't receive the drawchild and messurechild event   894         // the menuItem in PPC doesn't receive the drawchild and messurechild event
843             MENUITEMINFO info;   895             MENUITEMINFO info;
844             info.cbSize = sizeof(MENUITEMINFO);   896             info.cbSize = sizeof(MENUITEMINFO);
845             info.fMask = MIIM_TYPE;   897             info.fMask = MIIM_TYPE;
846             info.fType = MFT_OWNERDRAW;   898             info.fType = MFT_OWNERDRAW;
847             SetMenuItemInfo(hMenu, id, TRUE, &info);   899             SetMenuItemInfo(hMenu, id, TRUE, &info);
848     }   900     }
849       901    
850 #endif   902 #endif
851     903  
852 #ifndef _WIN32_WCE   904 #ifndef _WIN32_WCE
853     ugl_menuItem->ugl_image = UGL_IMAGE(imageHandle);   905     ugl_menuItem->ugl_image = UGL_IMAGE(imageHandle);
854       906    
855     if (ugl_menuItem->parent_menu->isMenuBar == FALSE) {   907     if (ugl_menuItem->parent_menu->isMenuBar == FALSE) {
856     908  
857         // Touch all items in the menu when the image changes on one of them so   909         // Touch all items in the menu when the image changes on one of them so
858         // that they will all layout correctly.  See the _wmMeasureChild method   910         // that they will all layout correctly.  See the _wmMeasureChild method
859         // for more information about why each item should be redrawn   911         // for more information about why each item should be redrawn
860     912  
861         int itemCount = GetMenuItemCount(hMenu);   913         int itemCount = GetMenuItemCount(hMenu);
862         int i;   914         int i;
863     915  
864         for (i=0;i<itemCount;i++) {   916         for (i=0;i<itemCount;i++) {
865             MENUITEMINFO info;   917             MENUITEMINFO info;
866     918  
867             info.cbSize = sizeof(MENUITEMINFO);   919             info.cbSize = sizeof(MENUITEMINFO);
868             info.fMask = MIIM_BITMAP;   920             info.fMask = MIIM_BITMAP;
869             info.hbmpItem = HBMMENU_CALLBACK;   921             info.hbmpItem = HBMMENU_CALLBACK;
870             SetMenuItemInfo(hMenu, i, TRUE, &info);   922             SetMenuItemInfo(hMenu, i, TRUE, &info);
871         }   923         }
872     } else {   924     } else {
873         MENUITEMINFO info;   925         MENUITEMINFO info;
874         int pos = FindMenu(hMenu, ugl_menuItem->id);   926         int pos = FindMenu(hMenu, ugl_menuItem->id);
875         if (pos == -1) {   927         if (pos == -1) {
876             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Failed to find menu item"));   928             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Failed to find menu item"));
877             return;   929             return;
878         }   930         }
879     931  
880         info.cbSize = sizeof(MENUITEMINFO);   932         info.cbSize = sizeof(MENUITEMINFO);
881         info.fMask = MIIM_BITMAP;   933         info.fMask = MIIM_BITMAP;
882         info.hbmpItem = imageHandle == 0 ? NULL : HBMMENU_CALLBACK;   934         info.hbmpItem = imageHandle == 0 ? NULL : HBMMENU_CALLBACK;
883         if (!SetMenuItemInfo(hMenu, pos, TRUE, &info)) {   935         if (!SetMenuItemInfo(hMenu, pos, TRUE, &info)) {
884             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Failed to set image on menu item"));   936             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Failed to set image on menu item"));
885             return;   937             return;
886         }   938         }
887     }   939     }
888     940  
889     Menu_Redraw(ugl_menuItem->parent_menu);   941     Menu_Redraw(ugl_menuItem->parent_menu);
890 #endif // ifndef _WIN32_WCE   942 #endif // ifndef _WIN32_WCE
891 }   943 }
892 //========================================================================================   944 //========================================================================================
893 PUGL_MenuItem _MenuItem_New_WinCe(PUGL_Menu ugl_menu, PUGL_MenuItem ugl_menuItem, int index, int type) {   945 PUGL_MenuItem _MenuItem_New_WinCe(PUGL_Menu ugl_menu, PUGL_MenuItem ugl_menuItem, int index, int type) {
894     int bits = 0;   946     int bits = 0;
895     MENUITEMINFO info;   947     MENUITEMINFO info;
896     948  
897     if (IS_FLAG_SET(type, MFT_SEPARATOR)) bits |= MF_SEPARATOR;   949     if (IS_FLAG_SET(type, MFT_SEPARATOR)) bits |= MF_SEPARATOR;
898     else if (IS_FLAG_SET(type, MFT_STRING)) bits |= MF_STRING;   950     else if (IS_FLAG_SET(type, MFT_STRING)) bits |= MF_STRING;
899     if (!InsertMenu(ugl_menu->hMenu, index, MF_BYPOSITION | bits, (UINT)ugl_menuItem->id, _T(""))) {   951     if (!InsertMenu(ugl_menu->hMenu, index, MF_BYPOSITION | bits, (UINT)ugl_menuItem->id, _T(""))) {
900         return UGL_MENUITEM(NULL_HANDLE);   952         return UGL_MENUITEM(NULL_HANDLE);
901     }   953     }
902       954    
903     memset(&info, 0, sizeof(MENUITEMINFO));   955     memset(&info, 0, sizeof(MENUITEMINFO));
904     info.cbSize = sizeof(MENUITEMINFO);   956     info.cbSize = sizeof(MENUITEMINFO);
905     info.fMask = MIIM_DATA;   957     info.fMask = MIIM_DATA;
906     info.dwItemData = ugl_menuItem->id;   958     info.dwItemData = ugl_menuItem->id;
907       959    
908     SetMenuItemInfo(ugl_menu->hMenu, ugl_menuItem->id, FALSE, &info);   960     SetMenuItemInfo(ugl_menu->hMenu, ugl_menuItem->id, FALSE, &info);
909     961  
910     return ugl_menuItem;   962     return ugl_menuItem;
911 }   963 }
912     964  
913 //========================================================================================   965 //========================================================================================
914     966  
915 PUGL_MenuItem _MenuItem_New(UGL_Int menuHandle, int type, BOOLEAN isCascade, int index, UGL_Error uglError) {   967 PUGL_MenuItem _MenuItem_New(UGL_Int menuHandle, int type, BOOLEAN isCascade, int index, UGL_Error uglError) {
916     PUGL_MenuItem ugl_menuItem = NULL;   968     PUGL_MenuItem ugl_menuItem = NULL;
917     PUGL_Menu ugl_menu = UGL_MENU(menuHandle);   969     PUGL_Menu ugl_menu = UGL_MENU(menuHandle);
918     970  
919     ugl_menuItem = UGL_MENUITEM(calloc(sizeof(UGL_MenuItem), 1));   971     ugl_menuItem = UGL_MENUITEM(calloc(sizeof(UGL_MenuItem), 1));
920     UGL_WIDGET(ugl_menuItem)->display = Control_GetDisplay(ugl_menu->parent);   972     UGL_WIDGET(ugl_menuItem)->display = Control_GetDisplay(ugl_menu->parent);
921     ugl_menuItem->parent_menu = ugl_menu;   973     ugl_menuItem->parent_menu = ugl_menu;
922     ugl_menuItem->wmDrawChild = _wmDrawChild;   974     ugl_menuItem->wmDrawChild = _wmDrawChild;
923     ugl_menuItem->wmMeasureChild = _wmMeasureChild;   975     ugl_menuItem->wmMeasureChild = _wmMeasureChild;
924     ugl_menuItem->wmCommandChild = _wmCommandChild;   976     ugl_menuItem->wmCommandChild = _wmCommandChild;
925     ugl_menuItem->enabled = TRUE;   977     ugl_menuItem->enabled = TRUE;
    -+ 978     ugl_menuItem->disableAutoSelection = FALSE;
      979     ugl_menuItem->isSelected = FALSE;
926     UGL_WIDGET(ugl_menuItem)->widget_dispose = _Dispose_MenuItem; = 980     UGL_WIDGET(ugl_menuItem)->widget_dispose = _Dispose_MenuItem;
927     981  
928       982    
929       983    
930 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)   984 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
931 {   985 {
932     // if major version > 5, use softkey support code.   986     // if major version > 5, use softkey support code.
933     if (Platform_GetMajorVersion() >= 5)   987     if (Platform_GetMajorVersion() >= 5)
934     {   988     {
935     989  
936         TBBUTTONINFO info;   990         TBBUTTONINFO info;
937         HMENU hMenu;   991         HMENU hMenu;
938         PUGL_MenuItem tempItem;   992         PUGL_MenuItem tempItem;
939         _TCHAR msgBuff[MENU_MSG_BUFF_SIZE];   993         _TCHAR msgBuff[MENU_MSG_BUFF_SIZE];
940           994        
941         UGL_Display *display;   995         UGL_Display *display;
942         int i,j;   996         int i,j;
943         //int count = UGL_WIDGET(ugl_menu)->display->menuItemCount;   997         //int count = UGL_WIDGET(ugl_menu)->display->menuItemCount;
944         int count;   998         int count;
945         int bits = 0;   999         int bits = 0;
946         int enable = 0;   1000         int enable = 0;
947         FILE * pFile;   1001         FILE * pFile;
948     1002  
949         if (IS_FLAG_SET(type, MFT_SEPARATOR)) ugl_menuItem->isSeparator = TRUE;   1003         if (IS_FLAG_SET(type, MFT_SEPARATOR)) ugl_menuItem->isSeparator = TRUE;
950         else ugl_menuItem->isSeparator = FALSE;   1004         else ugl_menuItem->isSeparator = FALSE;
951         ugl_menuItem->index = index;   1005         ugl_menuItem->index = index;
952         ugl_menuItem->text = _T("");   1006         ugl_menuItem->text = _T("");
953         ugl_menuItem->hasSubMenu = FALSE;   1007         ugl_menuItem->hasSubMenu = FALSE;
954     1008  
955     1009  
956         memset(&info, 0, sizeof(TBBUTTONINFO));   1010         memset(&info, 0, sizeof(TBBUTTONINFO));
957         display = UGL_WIDGET(ugl_menuItem)->display;      1011         display = UGL_WIDGET(ugl_menuItem)->display;   
958         count = Display_MenuItemCount(display, ugl_menu->hwndCB);   1012         count = Display_MenuItemCount(display, ugl_menu->hwndCB);
959     1013  
960     1014  
961         /*   1015         /*
962         pFile = fopen ("\\myfile.txt","a");   1016         pFile = fopen ("\\myfile.txt","a");
963         fprintf(pFile, "display->activeShell = %d, ugl_menu->parent = %d;\n", display->activeShell, ugl_menu->parent);   1017         fprintf(pFile, "display->activeShell = %d, ugl_menu->parent = %d;\n", display->activeShell, ugl_menu->parent);
964         fclose(pFile);   1018         fclose(pFile);
965         */   1019         */
966         if (display->activeShell == ugl_menu->parent) {   1020         if (display->activeShell == ugl_menu->parent) {
967             display->activeMenuBar = ugl_menu;   1021             display->activeMenuBar = ugl_menu;
968         }   1022         }
969     1023  
970           1024        
971         // if main menu (on menu Bar)   1025         // if main menu (on menu Bar)
972         if(ugl_menu->hwndCB !=0){   1026         if(ugl_menu->hwndCB !=0){
973             // if left softkey position is empty put the newly created item directly in it   1027             // if left softkey position is empty put the newly created item directly in it
974               1028            
975     1029  
976             if(Display_FindMenuItem(display, ugl_menu->hwndCB, 0) == NULL && count > 0) {   1030             if(Display_FindMenuItem(display, ugl_menu->hwndCB, 0) == NULL && count > 0) {
977                 info.cbSize = sizeof(info);   1031                 info.cbSize = sizeof(info);
978                 info.dwMask = TBIF_TEXT;   1032                 info.dwMask = TBIF_TEXT;
979                 info.pszText = _T("");   1033                 info.pszText = _T("");
980                 SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info);    1034                 SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info); 
981     1035  
982                 ugl_menuItem->index = 0;   1036                 ugl_menuItem->index = 0;
983                 Display_AddMenuItem(ugl_menuItem);   1037                 Display_AddMenuItem(ugl_menuItem);
984                 count = UGL_WIDGET(ugl_menu)->display->menuItemCount;   1038                 count = UGL_WIDGET(ugl_menu)->display->menuItemCount;
985                 //ShowWindow(ugl_menu->hwndMB, SW_SHOW);   1039                 //ShowWindow(ugl_menu->hwndMB, SW_SHOW);
986                 //ShowWindow(ugl_menu->hwndCB, SW_HIDE);   1040                 //ShowWindow(ugl_menu->hwndCB, SW_HIDE);
987                 if (display->activeShell == ugl_menu->parent) {   1041                 if (display->activeShell == ugl_menu->parent) {
988                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);   1042                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);
989                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);   1043                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);
990                 }   1044                 }
991     1045  
992                 /*   1046                 /*
993                 pFile = fopen ("\\myfile.txt","a");   1047                 pFile = fopen ("\\myfile.txt","a");
994                 fprintf(pFile, "=============== _MenuItem_New 1 ========================\n", count);   1048                 fprintf(pFile, "=============== _MenuItem_New 1 ========================\n", count);
995                 fprintf(pFile, "menuItemCount = %d\n", count);   1049                 fprintf(pFile, "menuItemCount = %d\n", count);
996                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   1050                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
997                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   1051                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
998                 for(i=0; i<display->menuItemsLength; i++){    1052                 for(i=0; i<display->menuItemsLength; i++){ 
999                     if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   1053                     if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
1000                     if(display->menuItems[i] != NULL){   1054                     if(display->menuItems[i] != NULL){
1001                         // setting the left softkey text   1055                         // setting the left softkey text
1002                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   1056                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
1003                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   1057                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1004                         }   1058                         }
1005                     }   1059                     }
1006                 }   1060                 }
1007                   1061                
1008                 fprintf(pFile, "========================================================\n");   1062                 fprintf(pFile, "========================================================\n");
1009                 fclose(pFile);   1063                 fclose(pFile);
1010                 */   1064                 */
1011     1065  
1012             } else {   1066             } else {
1013                 Display_AddMenuItem(ugl_menuItem);   1067                 Display_AddMenuItem(ugl_menuItem);
1014                 Display_IncMenuItemIndex(display, ugl_menu->hwndCB, ugl_menuItem->index);   1068                 Display_IncMenuItemIndex(display, ugl_menu->hwndCB, ugl_menuItem->index);
1015                 count = Display_MenuItemCount(display, ugl_menu->hwndCB);   1069                 count = Display_MenuItemCount(display, ugl_menu->hwndCB);
1016                 ugl_menuItem->index--;   1070                 ugl_menuItem->index--;
1017     1071  
1018                 switch(Display_MenuItemCount(display, ugl_menu->hwndCB)){   1072                 switch(Display_MenuItemCount(display, ugl_menu->hwndCB)){
1019                     case 1:   1073                     case 1:
1020                         // if it's the first item, add to the left softkey   1074                         // if it's the first item, add to the left softkey
1021                         info.cbSize = sizeof(info);   1075                         info.cbSize = sizeof(info);
1022                         info.dwMask = TBIF_TEXT;   1076                         info.dwMask = TBIF_TEXT;
1023                         info.pszText = _T("");   1077                         info.pszText = _T("");
1024                         SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info);    1078                         SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info); 
1025                         //ShowWindow(ugl_menu->hwndCB, SW_SHOW);   1079                         //ShowWindow(ugl_menu->hwndCB, SW_SHOW);
1026                         //ShowWindow(ugl_menu->hwndMB, SW_HIDE);   1080                         //ShowWindow(ugl_menu->hwndMB, SW_HIDE);
1027     1081  
1028                         if (display->activeShell == ugl_menu->parent) {   1082                         if (display->activeShell == ugl_menu->parent) {
1029                             ShowWindow(ugl_menu->hwndCB, SW_SHOW);   1083                             ShowWindow(ugl_menu->hwndCB, SW_SHOW);
1030                             ShowWindow(ugl_menu->hwndMB, SW_HIDE);   1084                             ShowWindow(ugl_menu->hwndMB, SW_HIDE);
1031                         }   1085                         }
1032       1086    
1033                         /*   1087                         /*
1034                         pFile = fopen ("\\myfile.txt","a");   1088                         pFile = fopen ("\\myfile.txt","a");
1035                         fprintf(pFile, "=============== _MenuItem_New 2 ========================\n", count);   1089                         fprintf(pFile, "=============== _MenuItem_New 2 ========================\n", count);
1036                         fprintf(pFile, "menuItemCount = %d\n", count);   1090                         fprintf(pFile, "menuItemCount = %d\n", count);
1037                         fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   1091                         fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
1038                         fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   1092                         fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
1039                         for(i=0; i<display->menuItemsLength; i++){                        1093                         for(i=0; i<display->menuItemsLength; i++){                     
1040                             if(display->menuItems[i] != NULL){   1094                             if(display->menuItems[i] != NULL){
1041                                 // setting the left softkey text   1095                                 // setting the left softkey text
1042                                 if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   1096                                 if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
1043                                 if(display->menuItems[i]->parent_menu->hwndCB != 0){   1097                                 if(display->menuItems[i]->parent_menu->hwndCB != 0){
1044                                     fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   1098                                     fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1045                                 }   1099                                 }
1046                             }   1100                             }
1047                         }   1101                         }
1048                           1102                        
1049                         fprintf(pFile, "========================================================\n", count);   1103                         fprintf(pFile, "========================================================\n", count);
1050                         fclose(pFile);   1104                         fclose(pFile);
1051                         */   1105                         */
1052     1106  
1053                         break;   1107                         break;
1054                     case 2:   1108                     case 2:
1055                         // if it's the second, index == 0, add to left, may need to move the left text to right   1109                         // if it's the second, index == 0, add to left, may need to move the left text to right
1056                         if(ugl_menuItem->index == 0){   1110                         if(ugl_menuItem->index == 0){
1057                             info.cbSize = sizeof(info);   1111                             info.cbSize = sizeof(info);
1058                             info.dwMask = TBIF_TEXT;   1112                             info.dwMask = TBIF_TEXT;
1059                             info.pszText = _T("");   1113                             info.pszText = _T("");
1060                             SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info);    1114                             SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info); 
1061                           1115                        
1062                             // if left key originally have text, move to right   1116                             // if left key originally have text, move to right
1063                             tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 1);   1117                             tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 1);
1064                             if(tempItem != NULL && tempItem->text != NULL){                                               1118                             if(tempItem != NULL && tempItem->text != NULL){                                            
1065                                 info.cbSize = sizeof(TBBUTTONINFO);   1119                                 info.cbSize = sizeof(TBBUTTONINFO);
1066                                 info.dwMask = TBIF_TEXT;   1120                                 info.dwMask = TBIF_TEXT;
1067                                 info.pszText = (LPWSTR) tempItem->text;   1121                                 info.pszText = (LPWSTR) tempItem->text;
1068                                 if(!SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info)){   1122                                 if(!SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info)){
1069                                     MessageBox(0, _T("unable to set button info"), _T("new"), 0);   1123                                     MessageBox(0, _T("unable to set button info"), _T("new"), 0);
1070                                 }                                 1124                                 }                              
1071                             }   1125                             }
1072                             //_Update_Enabled(display, ugl_menu->hwndCB);   1126                             //_Update_Enabled(display, ugl_menu->hwndCB);
1073                             /*if (display->activeShell == ugl_menu->parent) {   1127                             /*if (display->activeShell == ugl_menu->parent) {
1074                                 ShowWindow(ugl_menu->hwndMB, SW_HIDE);   1128                                 ShowWindow(ugl_menu->hwndMB, SW_HIDE);
1075                                 ShowWindow(ugl_menu->hwndCB, SW_SHOW);   1129                                 ShowWindow(ugl_menu->hwndCB, SW_SHOW);
1076                                 _Update_Enabled(display, ugl_menu->hwndCB);   1130                                 _Update_Enabled(display, ugl_menu->hwndCB);
1077                             } else {   1131                             } else {
1078                                 ShowWindow(ugl_menu->hwndMB, SW_HIDE);   1132                                 ShowWindow(ugl_menu->hwndMB, SW_HIDE);
1079                                 ShowWindow(ugl_menu->hwndCB, SW_HIDE);   1133                                 ShowWindow(ugl_menu->hwndCB, SW_HIDE);
1080                             }*/   1134                             }*/
1081     1135  
1082     1136  
1083                             // else if it's the right item   1137                             // else if it's the right item
1084                         } else {   1138                         } else {
1085                             // do nothing   1139                             // do nothing
1086                         }   1140                         }
1087     1141  
1088                         if (display->activeShell == ugl_menu->parent) {   1142                         if (display->activeShell == ugl_menu->parent) {
1089                             ShowWindow(ugl_menu->hwndCB, SW_SHOW);   1143                             ShowWindow(ugl_menu->hwndCB, SW_SHOW);
1090                             ShowWindow(ugl_menu->hwndMB, SW_HIDE);   1144                             ShowWindow(ugl_menu->hwndMB, SW_HIDE);
1091                             _Update_Enabled(display, ugl_menu->hwndCB);   1145                             _Update_Enabled(display, ugl_menu->hwndCB);
1092                         }   1146                         }
1093     1147  
1094                         //ShowWindow(ugl_menu->hwndCB, SW_SHOW);   1148                         //ShowWindow(ugl_menu->hwndCB, SW_SHOW);
1095                         //ShowWindow(ugl_menu->hwndMB, SW_HIDE);   1149                         //ShowWindow(ugl_menu->hwndMB, SW_HIDE);
1096     1150  
1097                         /*   1151                         /*
1098                         pFile = fopen ("\\myfile.txt","a");   1152                         pFile = fopen ("\\myfile.txt","a");
1099                         fprintf(pFile, "=============== _MenuItem_New 3 ========================\n", count);   1153                         fprintf(pFile, "=============== _MenuItem_New 3 ========================\n", count);
1100                         fprintf(pFile, "menuItemCount = %d\n", count);   1154                         fprintf(pFile, "menuItemCount = %d\n", count);
1101                         fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   1155                         fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
1102                         fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   1156                         fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
1103                         for(i=0; i<display->menuItemsLength; i++){                        1157                         for(i=0; i<display->menuItemsLength; i++){                     
1104                             if(display->menuItems[i] != NULL){   1158                             if(display->menuItems[i] != NULL){
1105                                 // setting the left softkey text   1159                                 // setting the left softkey text
1106                                 if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   1160                                 if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
1107                                 if(display->menuItems[i]->parent_menu->hwndCB != 0){   1161                                 if(display->menuItems[i]->parent_menu->hwndCB != 0){
1108                                     fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   1162                                     fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1109                                 }   1163                                 }
1110                             }   1164                             }
1111                         }   1165                         }
1112                           1166                        
1113                         fprintf(pFile, "========================================================\n", count);   1167                         fprintf(pFile, "========================================================\n", count);
1114                         fclose(pFile);   1168                         fclose(pFile);
1115                         */   1169                         */
1116     1170  
1117     1171  
1118                         break;   1172                         break;
1119                     case 3:   1173                     case 3:
1120                             // setting text for Menu   1174                             // setting text for Menu
1121                             hMenu = (HMENU) SendMessage (ugl_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);   1175                             hMenu = (HMENU) SendMessage (ugl_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);
1122                             info.cbSize = sizeof(info);   1176                             info.cbSize = sizeof(info);
1123                             info.dwMask = TBIF_TEXT;   1177                             info.dwMask = TBIF_TEXT;
1124                             LoadResourceString(display->hInstance, IDS_U_MENU, msgBuff, MENU_MSG_BUFF_SIZE);   1178                             LoadResourceString(display->hInstance, IDS_U_MENU, msgBuff, MENU_MSG_BUFF_SIZE);
1125                             info.pszText = msgBuff;   1179                             info.pszText = msgBuff;
1126                             SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);   1180                             SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);
1127     1181  
1128                             // insert menu   1182                             // insert menu
1129                             bits = 0;   1183                             bits = 0;
1130                             enable = 0;   1184                             enable = 0;
1131                             tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 0);   1185                             tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 0);
1132                             if(tempItem != NULL){   1186                             if(tempItem != NULL){
1133                                 // setting the left softkey text   1187                                 // setting the left softkey text
1134                                 if(tempItem->text != NULL){   1188                                 if(tempItem->text != NULL){
1135                                     info.pszText = tempItem->text;   1189                                     info.pszText = tempItem->text;
1136                                     SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info);    1190                                     SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info); 
1137                                 }   1191                                 }
1138                                 // setting menuitem text   1192                                 // setting menuitem text
1139                                 tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 1);   1193                                 tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 1);
1140                                 if(tempItem != NULL){   1194                                 if(tempItem != NULL){
1141                                     if(!tempItem->hasSubMenu) { //no submenu                                              1195                                     if(!tempItem->hasSubMenu) { //no submenu                                           
1142                                         if(tempItem->isSeparator){   1196                                         if(tempItem->isSeparator){
1143                                             bits |= MF_SEPARATOR;   1197                                             bits |= MF_SEPARATOR;
1144                                         }                                             1198                                         }                                          
1145                                         InsertMenu(hMenu, 0, MF_BYPOSITION | bits, tempItem->id, tempItem->text);                                                                                                                 1199                                         InsertMenu(hMenu, 0, MF_BYPOSITION | bits, tempItem->id, tempItem->text);                                                                                                              
1146                                           1200                                        
1147                                         enable = MF_BYPOSITION | (tempItem->enabled ? MF_ENABLED : MF_GRAYED);   1201                                         enable = MF_BYPOSITION | (tempItem->enabled ? MF_ENABLED : MF_GRAYED);
1148                                         if (EnableMenuItem(hMenu,  0, enable) == -1) {   1202                                         if (EnableMenuItem(hMenu,  0, enable) == -1) {
1149                                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("The menu item does not exist, enable failed"));   1203                                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("The menu item does not exist, enable failed"));
1150                                         }   1204                                         }
    <> 1205                                         if (IS_FLAG_SET(UGL_WIDGET(tempItem)->ugl_style, UGL_STYLE_CHECK)) {
      1206                                                 if (tempItem->isSelected) {
      1207                                                     if (CheckMenuItem(hMenu, tempItem->id, MF_BYCOMMAND | MF_CHECKED) == -1) {
      1208                                                         // disregard the error
      1209                                                         // Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Menu item doesn't exist"));
      1210                                                         return;
1151                                           1211                                                     }
      1212                                                 }
      1213                                         }
1152                                     } = 1214                                     }
1153                                 }   1215                                 }
1154     1216  
1155                                 bits = 0;   1217                                 bits = 0;
1156                                 enable = 0;   1218                                 enable = 0;
1157     1219  
1158                                 tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 2);   1220                                 tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 2);
1159                                 if(tempItem != NULL){   1221                                 if(tempItem != NULL){
1160                                     if(!tempItem->hasSubMenu){                                        1222                                     if(!tempItem->hasSubMenu){                                     
1161                                         if(tempItem->isSeparator){   1223                                         if(tempItem->isSeparator){
1162                                             bits |= MF_SEPARATOR;   1224                                             bits |= MF_SEPARATOR;
1163                                         }                                             1225                                         }                                          
1164     1226  
1165                                         InsertMenu(hMenu, 1, MF_BYPOSITION | bits, tempItem->id, tempItem->text);                                                     1227                                         InsertMenu(hMenu, 1, MF_BYPOSITION | bits, tempItem->id, tempItem->text);                                                  
1166                                           1228                                        
1167                                         enable = MF_BYPOSITION | (tempItem->enabled ? MF_ENABLED : MF_GRAYED);   1229                                         enable = MF_BYPOSITION | (tempItem->enabled ? MF_ENABLED : MF_GRAYED);
1168                                         if (EnableMenuItem(hMenu, 1, enable) == -1) {   1230                                         if (EnableMenuItem(hMenu, 1, enable) == -1) {
1169                                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("The menu item does not exist, enable failed"));   1231                                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("The menu item does not exist, enable failed"));
1170                                         }   1232                                         }
1171                                           1233                                        
1172                                     }   1234                                     }
1173                                 }   1235                                 }
1174                                   1236                                
1175                             }   1237                             }
1176                               1238                            
1177     1239  
1178                         if (display->activeShell == ugl_menu->parent) {   1240                         if (display->activeShell == ugl_menu->parent) {
1179                             ShowWindow(ugl_menu->hwndMB, SW_SHOW);   1241                             ShowWindow(ugl_menu->hwndMB, SW_SHOW);
1180                             ShowWindow(ugl_menu->hwndCB, SW_HIDE);   1242                             ShowWindow(ugl_menu->hwndCB, SW_HIDE);
1181                             _Update_Enabled(display, ugl_menu->hwndCB);   1243                             _Update_Enabled(display, ugl_menu->hwndCB);
1182                         }   1244                         }
1183     1245  
1184                             //ShowWindow(ugl_menu->hwndMB, SW_SHOW);   1246                             //ShowWindow(ugl_menu->hwndMB, SW_SHOW);
1185                             //ShowWindow(ugl_menu->hwndCB, SW_HIDE);   1247                             //ShowWindow(ugl_menu->hwndCB, SW_HIDE);
1186                         /*   1248                         /*
1187                         pFile = fopen ("\\myfile.txt","a");   1249                         pFile = fopen ("\\myfile.txt","a");
1188                         fprintf(pFile, "=============== _MenuItem_New 4 ========================\n", count);   1250                         fprintf(pFile, "=============== _MenuItem_New 4 ========================\n", count);
1189                         fprintf(pFile, "menuItemCount = %d\n", count);   1251                         fprintf(pFile, "menuItemCount = %d\n", count);
1190                         fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   1252                         fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
1191                         fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   1253                         fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
1192                         for(i=0; i<display->menuItemsLength; i++){                        1254                         for(i=0; i<display->menuItemsLength; i++){                     
1193                             if(display->menuItems[i] != NULL){   1255                             if(display->menuItems[i] != NULL){
1194                                 // setting the left softkey text   1256                                 // setting the left softkey text
1195                                 if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   1257                                 if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
1196                                 if(display->menuItems[i]->parent_menu->hwndCB != 0){   1258                                 if(display->menuItems[i]->parent_menu->hwndCB != 0){
1197                                     fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   1259                                     fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1198                                 }   1260                                 }
1199                             }   1261                             }
1200                         }   1262                         }
1201                           1263                        
1202                         fprintf(pFile, "========================================================\n", count);   1264                         fprintf(pFile, "========================================================\n", count);
1203                         fclose(pFile);   1265                         fclose(pFile);
1204                         */   1266                         */
1205     1267  
1206     1268  
1207                         break;   1269                         break;
1208     1270  
1209                     default:   1271                     default:
1210                         // any item more than 3   1272                         // any item more than 3
1211     1273  
1212                             hMenu = (HMENU) SendMessage (ugl_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);   1274                             hMenu = (HMENU) SendMessage (ugl_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);
1213                             if (IS_FLAG_SET(type, MFT_SEPARATOR)) {   1275                             if (IS_FLAG_SET(type, MFT_SEPARATOR)) {
1214                                 bits |= MF_SEPARATOR;   1276                                 bits |= MF_SEPARATOR;
1215                             }   1277                             }
1216                             else if (IS_FLAG_SET(type, MFT_STRING)) bits |= MF_STRING;   1278                             else if (IS_FLAG_SET(type, MFT_STRING)) bits |= MF_STRING;
1217     1279  
1218                             if(ugl_menuItem->index != 0){   1280                             if(ugl_menuItem->index != 0){
1219                                 // not to the left softkey, simply add it to the menu on the right   1281                                 // not to the left softkey, simply add it to the menu on the right
1220                                 InsertMenu(hMenu, ugl_menuItem->index-1, MF_BYPOSITION | bits, ugl_menuItem->id, _T(""));   1282                                 InsertMenu(hMenu, ugl_menuItem->index-1, MF_BYPOSITION | bits, ugl_menuItem->id, _T(""));
1221     1283  
1222                                 if (display->activeShell == ugl_menu->parent) {   1284                                 if (display->activeShell == ugl_menu->parent) {
1223                                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);   1285                                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);
1224                                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);   1286                                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);
1225                                 }   1287                                 }
1226     1288  
1227     1289  
1228                                 //ShowWindow(ugl_menu->hwndMB, SW_SHOW);   1290                                 //ShowWindow(ugl_menu->hwndMB, SW_SHOW);
1229                                 //ShowWindow(ugl_menu->hwndCB, SW_HIDE);   1291                                 //ShowWindow(ugl_menu->hwndCB, SW_HIDE);
1230     1292  
1231                                 /*   1293                                 /*
1232                                 pFile = fopen ("\\myfile.txt","a");   1294                                 pFile = fopen ("\\myfile.txt","a");
1233                                 fprintf(pFile, "=============== _MenuItem_New 6 ========================\n", count);   1295                                 fprintf(pFile, "=============== _MenuItem_New 6 ========================\n", count);
1234                                 fprintf(pFile, "menuItemCount = %d\n", count);   1296                                 fprintf(pFile, "menuItemCount = %d\n", count);
1235                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   1297                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
1236                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   1298                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
1237                                 for(i=0; i<display->menuItemsLength; i++){                        1299                                 for(i=0; i<display->menuItemsLength; i++){                     
1238                                     if(display->menuItems[i] != NULL){   1300                                     if(display->menuItems[i] != NULL){
1239                                         // setting the left softkey text   1301                                         // setting the left softkey text
1240                                         if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   1302                                         if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
1241                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   1303                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
1242                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   1304                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1243                                         }   1305                                         }
1244                                     }   1306                                     }
1245                                 }   1307                                 }
1246                                 fclose(pFile);   1308                                 fclose(pFile);
1247                                 fprintf(pFile, "========================================================\n", count);   1309                                 fprintf(pFile, "========================================================\n", count);
1248     1310  
1249                                 */   1311                                 */
1250     1312  
1251                             } else {   1313                             } else {
1252     1314  
1253                                 for(i=0; i<display->menuItemsLength; i++){   1315                                 for(i=0; i<display->menuItemsLength; i++){
1254                                     if(display->menuItems[i] != NULL){                                    1316                                     if(display->menuItems[i] != NULL){                                 
1255                                         if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   1317                                         if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
1256                                       1318                                    
1257                                         // insert it to the left softkey text   1319                                         // insert it to the left softkey text
1258                                         if(display->menuItems[i]->index == 0 && display->menuItems[i]->parent_menu->hwndCB != 0){   1320                                         if(display->menuItems[i]->index == 0 && display->menuItems[i]->parent_menu->hwndCB != 0){
1259                                             info.cbSize = sizeof(info);   1321                                             info.cbSize = sizeof(info);
1260                                             info.dwMask = TBIF_TEXT;   1322                                             info.dwMask = TBIF_TEXT;
1261                                             info.pszText = _T("");   1323                                             info.pszText = _T("");
1262                                             SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info);    1324                                             SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info); 
1263                                         }   1325                                         }
1264                                         // insert the original left softkey item to the right   1326                                         // insert the original left softkey item to the right
1265                                           1327                                        
1266                                           1328                                        
1267                                         if(display->menuItems[i]->index == 1 && display->menuItems[i]->parent_menu->hwndCB != 0){   1329                                         if(display->menuItems[i]->index == 1 && display->menuItems[i]->parent_menu->hwndCB != 0){
1268                                             if(display->menuItems[i]->text != NULL){   1330                                             if(display->menuItems[i]->text != NULL){
1269                                                 InsertMenu(hMenu, 0, MF_BYPOSITION, display->menuItems[i]->id, display->menuItems[i]->text);                              1331                                                 InsertMenu(hMenu, 0, MF_BYPOSITION, display->menuItems[i]->id, display->menuItems[i]->text);                           
1270                                             } else {   1332                                             } else {
1271                                                 InsertMenu(hMenu, 0, MF_BYPOSITION, display->menuItems[i]->id, _T(""));                           1333                                                 InsertMenu(hMenu, 0, MF_BYPOSITION, display->menuItems[i]->id, _T(""));                        
1272                                             }   1334                                             }
1273                                         }   1335                                         }
1274                                     }   1336                                     }
1275                                 }     1337                                 }  
1276     1338  
1277                                 if (display->activeShell == ugl_menu->parent) {   1339                                 if (display->activeShell == ugl_menu->parent) {
1278                                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);   1340                                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);
1279                                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);   1341                                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);
1280                                     _Update_Enabled(display, ugl_menu->hwndCB);   1342                                     _Update_Enabled(display, ugl_menu->hwndCB);
1281                                 }   1343                                 }
1282     1344  
1283                                 //ShowWindow(ugl_menu->hwndMB, SW_SHOW);   1345                                 //ShowWindow(ugl_menu->hwndMB, SW_SHOW);
1284                                 //ShowWindow(ugl_menu->hwndCB, SW_HIDE);   1346                                 //ShowWindow(ugl_menu->hwndCB, SW_HIDE);
1285                                   1347                                
1286                         /*   1348                         /*
1287                         pFile = fopen ("\\myfile.txt","a");   1349                         pFile = fopen ("\\myfile.txt","a");
1288                         fprintf(pFile, "=============== _MenuItem_New 7 ========================\n", count);   1350                         fprintf(pFile, "=============== _MenuItem_New 7 ========================\n", count);
1289                         fprintf(pFile, "menuItemCount = %d\n", count);   1351                         fprintf(pFile, "menuItemCount = %d\n", count);
1290                         fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   1352                         fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
1291                         fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   1353                         fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
1292                         for(i=0; i<display->menuItemsLength; i++){                        1354                         for(i=0; i<display->menuItemsLength; i++){                     
1293                             if(display->menuItems[i] != NULL){   1355                             if(display->menuItems[i] != NULL){
1294                                 // setting the left softkey text   1356                                 // setting the left softkey text
1295                                 if(display->menuItems[i]->parent_menu->hwndCB != 0){   1357                                 if(display->menuItems[i]->parent_menu->hwndCB != 0){
1296                                     fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   1358                                     fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1297                                 }   1359                                 }
1298                             }   1360                             }
1299                         }   1361                         }
1300                         fclose(pFile);   1362                         fclose(pFile);
1301                         fprintf(pFile, "========================================================\n", count);   1363                         fprintf(pFile, "========================================================\n", count);
1302                         */   1364                         */
1303                         }   1365                         }
1304     1366  
1305     1367  
1306                         break;   1368                         break;
1307                     }   1369                     }
1308     1370  
1309                 }   1371                 }
1310             // else if hWndCB == 0, sub menu   1372             // else if hWndCB == 0, sub menu
1311     1373  
1312             } else {   1374             } else {
1313                 // sub menu   1375                 // sub menu
1314                 Display_AddMenuItem(ugl_menuItem);   1376                 Display_AddMenuItem(ugl_menuItem);
1315                 //Display_IncMenuItemIndex(display, ugl_menuItem->index);   1377                 //Display_IncMenuItemIndex(display, ugl_menuItem->index);
1316                 if (!_MenuItem_New_WinCe(ugl_menu, ugl_menuItem, index, type)) {   1378                 if (!_MenuItem_New_WinCe(ugl_menu, ugl_menuItem, index, type)) {
1317                     Display_RemoveMenuItem(ugl_menuItem);   1379                     Display_RemoveMenuItem(ugl_menuItem);
1318                     free(ugl_menuItem);   1380                     free(ugl_menuItem);
1319                     Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to create new menu item"));   1381                     Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to create new menu item"));
1320                     return UGL_MENUITEM(NULL_HANDLE);   1382                     return UGL_MENUITEM(NULL_HANDLE);
1321                 }   1383                 }
1322             }   1384             }
1323     1385  
1324     1386  
1325     }   1387     }
1326     1388  
1327     // else no softkey support   1389     // else no softkey support
1328     else   1390     else
1329     {   1391     {
1330         HWND hwndCB = ugl_menu->hwndCB;   1392         HWND hwndCB = ugl_menu->hwndCB;
1331         Display_AddMenuItem(ugl_menuItem);   1393         Display_AddMenuItem(ugl_menuItem);
1332           1394        
1333     1395  
1334         if (hwndCB != 0) {   1396         if (hwndCB != 0) {
1335             // top level "menu"bar   1397             // top level "menu"bar
1336             TBBUTTON lpButton;   1398             TBBUTTON lpButton;
1337             memset(&lpButton, 0, sizeof(TBBUTTON));   1399             memset(&lpButton, 0, sizeof(TBBUTTON));
1338             lpButton.idCommand = ugl_menuItem->id;   1400             lpButton.idCommand = ugl_menuItem->id;
1339             lpButton.fsStyle = (BYTE)TBSTYLE_AUTOSIZE;   1401             lpButton.fsStyle = (BYTE)TBSTYLE_AUTOSIZE;
1340     1402  
1341     1403  
1342             if (IS_FLAG_SET(type, MFT_SEPARATOR)) lpButton.fsStyle = TBSTYLE_SEP;//(BYTE)BTNS_SEP;   1404             if (IS_FLAG_SET(type, MFT_SEPARATOR)) lpButton.fsStyle = TBSTYLE_SEP;//(BYTE)BTNS_SEP;
1343             else if (isCascade) lpButton.fsStyle |= TBSTYLE_DROPDOWN | 0x80;   1405             else if (isCascade) lpButton.fsStyle |= TBSTYLE_DROPDOWN | 0x80;
1344               1406            
1345             lpButton.fsState = (BYTE)TBSTATE_ENABLED;   1407             lpButton.fsState = (BYTE)TBSTATE_ENABLED;
1346             lpButton.iBitmap = I_IMAGENONE;   1408             lpButton.iBitmap = I_IMAGENONE;
1347             if (SendMessage (hwndCB, TB_INSERTBUTTON, index, (LPARAM) &lpButton) == FALSE) {   1409             if (SendMessage (hwndCB, TB_INSERTBUTTON, index, (LPARAM) &lpButton) == FALSE) {
1348                 Display_RemoveMenuItem(ugl_menuItem);   1410                 Display_RemoveMenuItem(ugl_menuItem);
1349                 free(ugl_menuItem);   1411                 free(ugl_menuItem);
1350                 Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to create new menu item"));   1412                 Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to create new menu item"));
1351                 return UGL_MENUITEM(NULL_HANDLE);   1413                 return UGL_MENUITEM(NULL_HANDLE);
1352             }   1414             }
1353         } else {   1415         } else {
1354             // sub menu   1416             // sub menu
1355             if (!_MenuItem_New_WinCe(ugl_menu, ugl_menuItem, index, type)) {   1417             if (!_MenuItem_New_WinCe(ugl_menu, ugl_menuItem, index, type)) {
1356                 Display_RemoveMenuItem(ugl_menuItem);   1418                 Display_RemoveMenuItem(ugl_menuItem);
1357                 free(ugl_menuItem);   1419                 free(ugl_menuItem);
1358                 Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to create new menu item"));   1420                 Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to create new menu item"));
1359                 return UGL_MENUITEM(NULL_HANDLE);   1421                 return UGL_MENUITEM(NULL_HANDLE);
1360             }   1422             }
1361         }   1423         }
1362     }   1424     }
1363     1425  
1364 }   1426 }
1365 #endif   1427 #endif
1366     1428  
1367 #if _WIN32_WCE && !(WIN32_PLATFORM_PSPC) && !(WIN32_PLATFORM_WFSP)   1429 #if _WIN32_WCE && !(WIN32_PLATFORM_PSPC) && !(WIN32_PLATFORM_WFSP)
1368     {   1430     {
1369         Display_AddMenuItem(ugl_menuItem);   1431         Display_AddMenuItem(ugl_menuItem);
1370         if (!_MenuItem_New_WinCe(ugl_menu, ugl_menuItem, index, type)) {   1432         if (!_MenuItem_New_WinCe(ugl_menu, ugl_menuItem, index, type)) {
1371             Display_RemoveMenuItem(ugl_menuItem);   1433             Display_RemoveMenuItem(ugl_menuItem);
1372             free(ugl_menuItem);   1434             free(ugl_menuItem);
1373             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to create new menu item"));   1435             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to create new menu item"));
1374             return UGL_MENUITEM(NULL_HANDLE);   1436             return UGL_MENUITEM(NULL_HANDLE);
1375         }   1437         }
1376     }   1438     }
1377 #endif   1439 #endif
1378     1440  
1379 #ifndef _WIN32_WCE   1441 #ifndef _WIN32_WCE
1380     Display_AddMenuItem(ugl_menuItem);   1442     Display_AddMenuItem(ugl_menuItem);
1381     /*   1443     /*
1382     * Bug in Windows.  For some reason, when InsertMenuItem()   1444     * Bug in Windows.  For some reason, when InsertMenuItem()
1383     * is used to insert an item without text, it is not possible   1445     * is used to insert an item without text, it is not possible
1384     * to use SetMenuItemInfo() to set the text at a later time.   1446     * to use SetMenuItemInfo() to set the text at a later time.
1385     * The fix is to insert the item with some text.   1447     * The fix is to insert the item with some text.
1386     *   1448     *
1387     * Feature in Windows.  When an empty string is used instead   1449     * Feature in Windows.  When an empty string is used instead
1388     * of a space and InsertMenuItem() is used to set a submenu   1450     * of a space and InsertMenuItem() is used to set a submenu
1389     * before setting text to a non-empty string, the menu item   1451     * before setting text to a non-empty string, the menu item
1390     * becomes unexpectedly disabled.  The fix is to insert a   1452     * becomes unexpectedly disabled.  The fix is to insert a
1391     * space.   1453     * space.
1392     */   1454     */
1393     {   1455     {
1394     MENUITEMINFO info;   1456     MENUITEMINFO info;
1395     info.cbSize = sizeof(MENUITEMINFO);   1457     info.cbSize = sizeof(MENUITEMINFO);
1396     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_DATA | MIIM_ID;   1458     info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_DATA | MIIM_ID;
1397     info.dwItemData = (UINT)ugl_menuItem->id;   1459     info.dwItemData = (UINT)ugl_menuItem->id;
1398     info.wID = (UINT)ugl_menuItem->id;   1460     info.wID = (UINT)ugl_menuItem->id;
1399     info.fType = type;   1461     info.fType = type;
1400     info.dwTypeData = _T(" ");   1462     info.dwTypeData = _T(" ");
1401     1463  
1402     if (ugl_menu->isMenuBar == FALSE) {   1464     if (ugl_menu->isMenuBar == FALSE) {
1403         // Windows has problems with menus which contain items with and without images   1465         // Windows has problems with menus which contain items with and without images
1404         // the fix is to mark every item has having an image.  See the _wmMeasureChild method   1466         // the fix is to mark every item has having an image.  See the _wmMeasureChild method
1405         // for more information.   1467         // for more information.
1406         info.fMask |= MIIM_BITMAP;   1468         info.fMask |= MIIM_BITMAP;
1407         info.hbmpItem = HBMMENU_CALLBACK;   1469         info.hbmpItem = HBMMENU_CALLBACK;
1408     }   1470     }
1409     1471  
1410     if (!InsertMenuItem(ugl_menu->hMenu, index, TRUE, &info)) {   1472     if (!InsertMenuItem(ugl_menu->hMenu, index, TRUE, &info)) {
1411         Display_RemoveMenuItem(ugl_menuItem);   1473         Display_RemoveMenuItem(ugl_menuItem);
1412         free(ugl_menuItem);   1474         free(ugl_menuItem);
1413         Win32Error_SetError(uglError, GetLastError(), _T("Unable to create new menu item"));   1475         Win32Error_SetError(uglError, GetLastError(), _T("Unable to create new menu item"));
1414         return UGL_MENUITEM(NULL_HANDLE);   1476         return UGL_MENUITEM(NULL_HANDLE);
1415     }   1477     }
1416     }   1478     }
1417 #endif   1479 #endif
1418       1480    
1419     return ugl_menuItem;   1481     return ugl_menuItem;
1420 }   1482 }
1421 //========================================================================================   1483 //========================================================================================
1422     1484  
1423 LRESULT _wmDrawChild(UGL_Int handle, WPARAM wParam, LPARAM lParam) {   1485 LRESULT _wmDrawChild(UGL_Int handle, WPARAM wParam, LPARAM lParam) {
1424     PUGL_MenuItem ugl_menuItem = UGL_MENUITEM(handle);   1486     PUGL_MenuItem ugl_menuItem = UGL_MENUITEM(handle);
1425     LPDRAWITEMSTRUCT draw_struct = (LPDRAWITEMSTRUCT)lParam;   1487     LPDRAWITEMSTRUCT draw_struct = (LPDRAWITEMSTRUCT)lParam;
1426     PUGL_Image image = ugl_menuItem->ugl_image;   1488     PUGL_Image image = ugl_menuItem->ugl_image;
1427     1489  
1428     if (image != NULL) {   1490     if (image != NULL) {
1429         HRGN clip = CreateRectRgn(0, 0, 0, 0);   1491         HRGN clip = CreateRectRgn(0, 0, 0, 0);
1430         PUGL_DC ugl_dc;   1492         PUGL_DC ugl_dc;
1431         RECT shiftedClip;   1493         RECT shiftedClip;
1432         int x;   1494         int x;
1433     1495  
1434         int res = GetClipRgn(draw_struct->hDC, clip);   1496         int res = GetClipRgn(draw_struct->hDC, clip);
1435           1497        
1436 #ifndef _WIN32_WCE   1498 #ifndef _WIN32_WCE
1437         POINT viewportOrg;   1499         POINT viewportOrg;
1438         // The incomming clip rect is in logical co-ordinates, but   1500         // The incomming clip rect is in logical co-ordinates, but
1439         // the clip going to new_DC is expected to be in device   1501         // the clip going to new_DC is expected to be in device
1440         // co-ords.  These next lines will shift it into the correct   1502         // co-ords.  These next lines will shift it into the correct
1441         // position   1503         // position
1442         GetViewportOrgEx(draw_struct->hDC, &viewportOrg);   1504         GetViewportOrgEx(draw_struct->hDC, &viewportOrg);
1443         shiftedClip.top = draw_struct->rcItem.top + viewportOrg.y;   1505         shiftedClip.top = draw_struct->rcItem.top + viewportOrg.y;
1444         shiftedClip.bottom = draw_struct->rcItem.bottom + viewportOrg.y;   1506         shiftedClip.bottom = draw_struct->rcItem.bottom + viewportOrg.y;
1445         shiftedClip.left = draw_struct->rcItem.left + viewportOrg.x;   1507         shiftedClip.left = draw_struct->rcItem.left + viewportOrg.x;
1446         shiftedClip.right = draw_struct->rcItem.right + viewportOrg.x;   1508         shiftedClip.right = draw_struct->rcItem.right + viewportOrg.x;
1447 #endif   1509 #endif
1448     1510  
1449         ugl_dc = _internal_new_DC(draw_struct->hDC, NULL,&(shiftedClip), NULL);   1511         ugl_dc = _internal_new_DC(draw_struct->hDC, NULL,&(shiftedClip), NULL);
1450         /*   1512         /*
1451         * Bug in Windows.  When a bitmap is included in the   1513         * Bug in Windows.  When a bitmap is included in the
1452         * menu bar, the HDC seems to already include the left   1514         * menu bar, the HDC seems to already include the left
1453         * coordinate.  The fix is to ignore this value when   1515         * coordinate.  The fix is to ignore this value when
1454         * the item is in a menu bar.   1516         * the item is in a menu bar.
1455         */   1517         */
1456         x = draw_struct->rcItem.left;   1518         x = draw_struct->rcItem.left;
1457     1519  
1458         Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_menuItem->ugl_image, x, draw_struct->rcItem.top, NULL);   1520         Graphics_DrawImage((UGL_Int)ugl_dc, (UGL_Int)ugl_menuItem->ugl_image, x, draw_struct->rcItem.top, NULL);
1459     1521  
1460         SelectClipRgn(draw_struct->hDC, res == 1 ? clip : NULL );   1522         SelectClipRgn(draw_struct->hDC, res == 1 ? clip : NULL );
1461         DeleteObject(clip);   1523         DeleteObject(clip);
1462     }   1524     }
1463     1525  
1464     return TRUE;   1526     return TRUE;
1465 }   1527 }
1466 //========================================================================================   1528 //========================================================================================
1467     1529  
1468 LRESULT _wmMeasureChild(UGL_Int handle, WPARAM wParam, LPARAM lParam) {   1530 LRESULT _wmMeasureChild(UGL_Int handle, WPARAM wParam, LPARAM lParam) {
1469     1531  
1470 #ifndef _WIN32_WCE   1532 #ifndef _WIN32_WCE
1471     LPMEASUREITEMSTRUCT measure_struct = (LPMEASUREITEMSTRUCT)lParam;   1533     LPMEASUREITEMSTRUCT measure_struct = (LPMEASUREITEMSTRUCT)lParam;
1472     PUGL_MenuItem ugl_menuItem = UGL_MENUITEM(handle);   1534     PUGL_MenuItem ugl_menuItem = UGL_MENUITEM(handle);
1473     PUGL_Image image = ugl_menuItem->ugl_image;   1535     PUGL_Image image = ugl_menuItem->ugl_image;
1474     int width = 0, height = 0;   1536     int width = 0, height = 0;
1475     1537  
1476     if (image != NULL) {   1538     if (image != NULL) {
1477         _Image_GetSize(image, &width, &height, NULL);   1539         _Image_GetSize(image, &width, &height, NULL);
1478     } else {   1540     } else {
1479         /*   1541         /*
1480         * Bug in Windows.  If a menu contains items that have   1542         * Bug in Windows.  If a menu contains items that have
1481         * images and can be checked, Windows does not include   1543         * images and can be checked, Windows does not include
1482         * the width of the image and the width of the check when   1544         * the width of the image and the width of the check when
1483         * computing the width of the menu.  When the longest item   1545         * computing the width of the menu.  When the longest item
1484         * does not have an image, the label and the accelerator   1546         * does not have an image, the label and the accelerator
1485         * text can overlap.  The fix is to use SetMenuItemInfo()   1547         * text can overlap.  The fix is to use SetMenuItemInfo()
1486         * to indicate that all items have a bitmap and then include   1548         * to indicate that all items have a bitmap and then include
1487         * the width of the widest bitmap in WM_MEASURECHILD.   1549         * the width of the widest bitmap in WM_MEASURECHILD.
1488         */   1550         */
1489         HMENU hMenu = ugl_menuItem->parent_menu->hMenu;   1551         HMENU hMenu = ugl_menuItem->parent_menu->hMenu;
1490     1552  
1491         MENUITEMINFO info;   1553         MENUITEMINFO info;
1492         int i;   1554         int i;
1493         int maxWidth = 0;   1555         int maxWidth = 0;
1494         int itemCount = GetMenuItemCount(hMenu);   1556         int itemCount = GetMenuItemCount(hMenu);
1495         info.cbSize = sizeof(MENUITEMINFO);   1557         info.cbSize = sizeof(MENUITEMINFO);
1496         info.fMask = MIIM_DATA;   1558         info.fMask = MIIM_DATA;
1497     1559  
1498         for (i=0;i<itemCount;i++) {   1560         for (i=0;i<itemCount;i++) {
1499             PUGL_MenuItem item;   1561             PUGL_MenuItem item;
1500             GetMenuItemInfo(hMenu, i, TRUE, &info);   1562             GetMenuItemInfo(hMenu, i, TRUE, &info);
1501     1563  
1502             item = Display_GetMenuItem(ugl_menuItem->widget.display, info.dwItemData);   1564             item = Display_GetMenuItem(ugl_menuItem->widget.display, info.dwItemData);
1503             if (item->ugl_image != NULL) {   1565             if (item->ugl_image != NULL) {
1504                 _Image_GetSize(item->ugl_image, &width, &height, NULL);   1566                 _Image_GetSize(item->ugl_image, &width, &height, NULL);
1505                 if (width > maxWidth) maxWidth = width;   1567                 if (width > maxWidth) maxWidth = width;
1506             }   1568             }
1507         }   1569         }
1508     1570  
1509         width = maxWidth;   1571         width = maxWidth;
1510         height = 0;   1572         height = 0;
1511     }   1573     }
1512     1574  
1513     if (width != 0 || height != 0) {   1575     if (width != 0 || height != 0) {
1514         /*   1576         /*
1515         * Feature in Windows.  On Windows 98, it is necessary   1577         * Feature in Windows.  On Windows 98, it is necessary
1516         * to add 4 pixels to the width of the image or the image   1578         * to add 4 pixels to the width of the image or the image
1517         * and text are too close.  On other Windows platforms,   1579         * and text are too close.  On other Windows platforms,
1518         * this causes the text of the longest item to touch the   1580         * this causes the text of the longest item to touch the
1519         * accelerator text.  The fix is to add only 2 pixels in   1581         * accelerator text.  The fix is to add only 2 pixels in
1520         * this case.   1582         * this case.
1521         */   1583         */
1522         measure_struct->itemWidth = width + (/*OS.IsWin95 ? 4 :*/ 2);   1584         measure_struct->itemWidth = width + (/*OS.IsWin95 ? 4 :*/ 2);
1523         measure_struct->itemHeight = height + 4;   1585         measure_struct->itemHeight = height + 4;
1524     } else {   1586     } else {
1525         measure_struct->itemWidth = width;   1587         measure_struct->itemWidth = width;
1526         measure_struct->itemHeight = height;   1588         measure_struct->itemHeight = height;
1527     }   1589     }
1528     1590  
1529 #endif // if defined _WIN32_WCE   1591 #endif // if defined _WIN32_WCE
1530     1592  
1531     return 0;   1593     return 0;
1532 }   1594 }
1533 //========================================================================================   1595 //========================================================================================
1534     1596  
1535 LRESULT _wmCommandChild(UGL_Int handle, WPARAM wParam, LPARAM lParam) {   1597 LRESULT _wmCommandChild(UGL_Int handle, WPARAM wParam, LPARAM lParam) {
1536     PUGL_MenuItem ugl_menuItem = UGL_MENUITEM(handle);   1598     PUGL_MenuItem ugl_menuItem = UGL_MENUITEM(handle);
1537     1599  
1538     //FILE * pFile;   1600     //FILE * pFile;
1539     UGL_Display *display = display = UGL_WIDGET(ugl_menuItem)->display;   1601     UGL_Display *display = display = UGL_WIDGET(ugl_menuItem)->display;
1540     int count = display->menuItemCount;   1602     int count = display->menuItemCount;
1541     int i;   1603     int i;
1542     /*   1604     /*
1543     pFile = fopen ("\\myfile.txt","a");   1605     pFile = fopen ("\\myfile.txt","a");
1544     fprintf(pFile, "=============== wmCommandChild ========================\n", count);   1606     fprintf(pFile, "=============== wmCommandChild ========================\n", count);
1545     fprintf(pFile, "menuItemCount = %d\n", count);   1607     fprintf(pFile, "menuItemCount = %d\n", count);
1546     fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   1608     fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
1547     for(i=0; i<display->menuItemsLength; i++){                        1609     for(i=0; i<display->menuItemsLength; i++){                     
1548         if(display->menuItems[i] != NULL){   1610         if(display->menuItems[i] != NULL){
1549             // setting the left softkey text   1611             // setting the left softkey text
1550             if(display->menuItems[i]->parent_menu->hwndCB != 0){   1612             if(display->menuItems[i]->parent_menu->hwndCB != 0){
1551                 fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   1613                 fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1552             }   1614             }
1553         }   1615         }
1554     }   1616     }
1555     fclose(pFile);   1617     fclose(pFile);
1556     fprintf(pFile, "========================================================\n", count);   1618     fprintf(pFile, "========================================================\n", count);
1557     */   1619     */
1558     1620  
1559     if (IS_FLAG_SET(UGL_WIDGET(ugl_menuItem)->ugl_style, UGL_STYLE_CHECK)) {   1621     if (IS_FLAG_SET(UGL_WIDGET(ugl_menuItem)->ugl_style, UGL_STYLE_CHECK)) {
    <> 1622         if (ugl_menuItem->disableAutoSelection == FALSE) {
1560         MENUITEMINFO info;   1623             MENUITEMINFO info;
1561         int id = ugl_menuItem->id;   1624             int id = ugl_menuItem->id;
      1625 #ifdef _WIN32_WCE
      1626             HMENU hMenu = getMenuForCheck(ugl_menuItem->parent_menu);
      1627 #else
1562         HMENU hMenu = ugl_menuItem->parent_menu->hMenu;   1628             HMENU hMenu = ugl_menuItem->parent_menu->hMenu;
      1629 #endif // #ifdef _WIN32_WCE
1563         BOOL selected = FALSE;   1630             BOOL selected = FALSE;
1564   = 1631  
1565         info.cbSize = sizeof(MENUITEMINFO); <> 1632             info.cbSize = sizeof(MENUITEMINFO);
1566         info.fMask = MIIM_STATE;   1633             info.fMask = MIIM_STATE;
1567         GetMenuItemInfo(hMenu, id, FALSE, (LPMENUITEMINFO)&info);   1634             GetMenuItemInfo(hMenu, id, FALSE, (LPMENUITEMINFO)&info);
1568         selected = IS_FLAG_SET(info.fState, MFS_CHECKED);   1635             selected = IS_FLAG_SET(info.fState, MFS_CHECKED);
1569   = 1636  
1570         StateMenuItem_SetSelection((UGL_Int)ugl_menuItem, !selected, NULL); <> 1637             StateMenuItem_SetSelection((UGL_Int)ugl_menuItem, !selected, NULL);
      1638         }
1571     } = 1639     }
1572     1640  
1573     MenuSelectionCallback(UGL_WIDGET(ugl_menuItem)->callback_target, 0);   1641     MenuSelectionCallback(UGL_WIDGET(ugl_menuItem)->callback_target, 0);
1574       1642    
1575     return 0;   1643     return 0;
1576 }   1644 }
1577 //========================================================================================   1645 //========================================================================================
1578     1646  
1579 void _Dispose(PUGL_Menu ugl_menu, int id, UGL_Error uglError) {   1647 void _Dispose(PUGL_Menu ugl_menu, int id, UGL_Error uglError) {
1580     HMENU hMenu = ugl_menu->hMenu;   1648     HMENU hMenu = ugl_menu->hMenu;
1581     int pos;   1649     int pos;
1582       1650    
1583 #if defined(DEBUG) && !defined(_WIN32_WCE)   1651 #if defined(DEBUG) && !defined(_WIN32_WCE)
1584     if (IsMenu(hMenu) == FALSE) {   1652     if (IsMenu(hMenu) == FALSE) {
1585         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Removing menu item from previously disposed menu"));   1653         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Removing menu item from previously disposed menu"));
1586         return;   1654         return;
1587     }   1655     }
1588 #endif   1656 #endif
1589     pos = FindMenu(hMenu, id);   1657     pos = FindMenu(hMenu, id);
1590     1658  
1591     if (pos == -1) {   1659     if (pos == -1) {
1592         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to find menu item"));   1660         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to find menu item"));
1593         return;   1661         return;
1594     }   1662     }
1595     1663  
1596     if (!DeleteMenu(hMenu, pos, MF_BYPOSITION)) {   1664     if (!DeleteMenu(hMenu, pos, MF_BYPOSITION)) {
1597         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to delete menu item"));   1665         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to delete menu item"));
1598     } else {   1666     } else {
1599         PUGL_Display ugl_display = UGL_WIDGET(ugl_menu)->display;   1667         PUGL_Display ugl_display = UGL_WIDGET(ugl_menu)->display;
1600         PUGL_MenuItem ugl_menuItem = Display_GetMenuItem(ugl_display, id);   1668         PUGL_MenuItem ugl_menuItem = Display_GetMenuItem(ugl_display, id);
1601     1669  
1602         if (ugl_menuItem != NULL) {   1670         if (ugl_menuItem != NULL) {
1603             Display_RemoveMenuItem(ugl_menuItem);   1671             Display_RemoveMenuItem(ugl_menuItem);
1604         }         1672         }      
1605         Menu_Redraw(ugl_menu);   1673         Menu_Redraw(ugl_menu);
1606     }   1674     }
1607 }   1675 }
1608 //========================================================================================   1676 //========================================================================================
1609     1677  
1610 // this helper updates the enabled state of the left and right softkey   1678 // this helper updates the enabled state of the left and right softkey
1611 void _Update_Enabled(PUGL_Display display, HWND hwndCB) {   1679 void _Update_Enabled(PUGL_Display display, HWND hwndCB) {
1612 #ifdef _WIN32_WCE   1680 #ifdef _WIN32_WCE
1613     PUGL_MenuItem tempItem;   1681     PUGL_MenuItem tempItem;
1614     TBBUTTONINFO buttonInfo;   1682     TBBUTTONINFO buttonInfo;
1615     memset(&buttonInfo, 0, sizeof(TBBUTTONINFO));   1683     memset(&buttonInfo, 0, sizeof(TBBUTTONINFO));
1616     buttonInfo.cbSize = sizeof(TBBUTTONINFO);   1684     buttonInfo.cbSize = sizeof(TBBUTTONINFO);
1617     buttonInfo.dwMask = TBIF_STATE;   1685     buttonInfo.dwMask = TBIF_STATE;
1618     1686  
1619 // left softkey   1687 // left softkey
1620     tempItem = Display_FindMenuItem(display, hwndCB, 0);   1688     tempItem = Display_FindMenuItem(display, hwndCB, 0);
1621     if(tempItem != NULL){   1689     if(tempItem != NULL){
1622         buttonInfo.fsState &= ~TBSTATE_ENABLED;   1690         buttonInfo.fsState &= ~TBSTATE_ENABLED;
1623         if (tempItem->enabled){   1691         if (tempItem->enabled){
1624                 buttonInfo.fsState |= TBSTATE_ENABLED;   1692                 buttonInfo.fsState |= TBSTATE_ENABLED;
1625             }   1693             }
1626         SendMessage(tempItem->parent_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (LPARAM) &buttonInfo);   1694         SendMessage(tempItem->parent_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (LPARAM) &buttonInfo);
1627         SendMessage(tempItem->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (LPARAM) &buttonInfo);   1695         SendMessage(tempItem->parent_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (LPARAM) &buttonInfo);
1628               1696            
1629           1697        
1630     }   1698     }
1631     1699  
1632 // right softkey   1700 // right softkey
1633     tempItem = Display_FindMenuItem(display, hwndCB, 1);   1701     tempItem = Display_FindMenuItem(display, hwndCB, 1);
1634     if(tempItem != NULL){   1702     if(tempItem != NULL){
1635           1703        
1636         buttonInfo.fsState &= ~TBSTATE_ENABLED;   1704         buttonInfo.fsState &= ~TBSTATE_ENABLED;
1637         if (tempItem->enabled){   1705         if (tempItem->enabled){
1638                 buttonInfo.fsState |= TBSTATE_ENABLED;   1706                 buttonInfo.fsState |= TBSTATE_ENABLED;
1639             }   1707             }
1640         SendMessage(tempItem->parent_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (LPARAM) &buttonInfo);   1708         SendMessage(tempItem->parent_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (LPARAM) &buttonInfo);
1641     }   1709     }
1642 #endif   1710 #endif
1643     1711  
1644 }   1712 }
1645 //========================================================================================   1713 //========================================================================================
1646 void _Dispose_MenuItem(UGL_Int handle, UGL_Error uglError) {   1714 void _Dispose_MenuItem(UGL_Int handle, UGL_Error uglError) {
1647     // new code, softkey   1715     // new code, softkey
1648     1716  
1649     PUGL_MenuItem ugl_menuItem = UGL_MENUITEM(handle);   1717     PUGL_MenuItem ugl_menuItem = UGL_MENUITEM(handle);
1650     PUGL_Menu ugl_menu = ugl_menuItem->parent_menu;   1718     PUGL_Menu ugl_menu = ugl_menuItem->parent_menu;
1651     int id = ugl_menuItem->id;   1719     int id = ugl_menuItem->id;
1652     PUGL_Shell parentShell = UGL_SHELL(ugl_menuItem->parent_menu->parent);   1720     PUGL_Shell parentShell = UGL_SHELL(ugl_menuItem->parent_menu->parent);
1653     _Shell_RemoveAccelerator(parentShell, ugl_menuItem->id);   1721     _Shell_RemoveAccelerator(parentShell, ugl_menuItem->id);
1654       1722    
1655       1723    
1656       1724    
1657     #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)   1725     #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
1658     {   1726     {
1659     HIMAGELIST imagelist;   1727     HIMAGELIST imagelist;
1660     HWND hwndCB = ugl_menu->hwndCB;   1728     HWND hwndCB = ugl_menu->hwndCB;
1661     TBBUTTONINFO info;   1729     TBBUTTONINFO info;
1662     HMENU hMenu;   1730     HMENU hMenu;
1663     UGL_String buffer;   1731     UGL_String buffer;
1664     UGL_Display *display;   1732     UGL_Display *display;
1665     PUGL_MenuItem tempItem, tempItem2, tempItem3, tempItem4;   1733     PUGL_MenuItem tempItem, tempItem2, tempItem3, tempItem4;
1666     BOOL switchCBMB, found, foundfirst, foundfirstsub;   1734     BOOL switchCBMB, found, foundfirst, foundfirstsub;
1667     BOOL isSubMenu[2];   1735     BOOL isSubMenu[2];
1668     int i,j;   1736     int i,j;
1669     FILE * pFile;   1737     FILE * pFile;
1670       1738    
1671     display = UGL_WIDGET(ugl_menuItem)->display;   1739     display = UGL_WIDGET(ugl_menuItem)->display;
1672     memset(&info, 0, sizeof(TBBUTTONINFO));   1740     memset(&info, 0, sizeof(TBBUTTONINFO));
1673     buffer = (UGL_String)calloc(1, sizeof(UGL_String));   1741     buffer = (UGL_String)calloc(1, sizeof(UGL_String));
1674     1742  
1675     1743  
1676     /*   1744     /*
1677     pFile = fopen ("\\myfile.txt","a");   1745     pFile = fopen ("\\myfile.txt","a");
1678     fprintf(pFile, "display->activeShell = %d, ugl_menu->parent = %d;\n", display->activeShell, ugl_menu->parent);   1746     fprintf(pFile, "display->activeShell = %d, ugl_menu->parent = %d;\n", display->activeShell, ugl_menu->parent);
1679     fclose(pFile);   1747     fclose(pFile);
1680     */   1748     */
1681     1749  
1682     if (display->activeShell == ugl_menu->parent) {   1750     if (display->activeShell == ugl_menu->parent) {
1683         display->activeMenuBar = ugl_menu;   1751         display->activeMenuBar = ugl_menu;
1684     }   1752     }
1685     1753  
1686     1754  
1687     // if menuitems of menu bar   1755     // if menuitems of menu bar
1688     if (hwndCB != 0) {   1756     if (hwndCB != 0) {
1689         // if support softkey   1757         // if support softkey
1690         if (Platform_GetMajorVersion() >= 5) {   1758         if (Platform_GetMajorVersion() >= 5) {
1691             int pos = id - 108;   1759             int pos = id - 108;
1692             int index = ugl_menuItem->index;   1760             int index = ugl_menuItem->index;
1693             int count = Display_MenuItemCount(display, ugl_menu->hwndCB);   1761             int count = Display_MenuItemCount(display, ugl_menu->hwndCB);
1694     1762  
1695     1763  
1696             if (pos == -1) {   1764             if (pos == -1) {
1697                 Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to find menu item"));   1765                 Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to find menu item"));
1698                 return;   1766                 return;
1699             }   1767             }
1700     1768  
1701               1769            
1702             (long) imagelist = SendMessage (hwndCB, TB_GETIMAGELIST, 0, 0);   1770             (long) imagelist = SendMessage (hwndCB, TB_GETIMAGELIST, 0, 0);
1703             if (imagelist != NULL) {   1771             if (imagelist != NULL) {
1704                 ImageList_Destroy(imagelist);   1772                 ImageList_Destroy(imagelist);
1705             }   1773             }
1706     1774  
1707             // if there's sub menus but not normal menuitem   1775             // if there's sub menus but not normal menuitem
1708     1776  
1709 /*            1777 /*         
1710                 pFile = fopen ("\\myfile.txt","a");   1778                 pFile = fopen ("\\myfile.txt","a");
1711                 fprintf(pFile, "=============== _Dispose_MenuItem 0 ========================\n", count);   1779                 fprintf(pFile, "=============== _Dispose_MenuItem 0 ========================\n", count);
1712                 fprintf(pFile, "menuItemCount = %d\n", count);   1780                 fprintf(pFile, "menuItemCount = %d\n", count);
1713                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   1781                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
1714                 for(i=0; i<display->menuItemsLength; i++){                        1782                 for(i=0; i<display->menuItemsLength; i++){                     
1715                     if(display->menuItems[i] != NULL){   1783                     if(display->menuItems[i] != NULL){
1716                         // setting the left softkey text   1784                         // setting the left softkey text
1717                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   1785                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
1718                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   1786                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1719                         }   1787                         }
1720                     }   1788                     }
1721                 }   1789                 }
1722                 fclose(pFile);   1790                 fclose(pFile);
1723                 fprintf(pFile, "========================================================\n", count);   1791                 fprintf(pFile, "========================================================\n", count);
1724                 */   1792                 */
1725                   1793                
1726     1794  
1727     1795  
1728             if(Display_FindMenuItem(display, ugl_menu->hwndCB, 0) == NULL && count > 0){   1796             if(Display_FindMenuItem(display, ugl_menu->hwndCB, 0) == NULL && count > 0){
1729                 // directly remove from the submenu   1797                 // directly remove from the submenu
1730                 /*   1798                 /*
1731                 pFile = fopen ("\\myfile.txt","a");   1799                 pFile = fopen ("\\myfile.txt","a");
1732                 fprintf(pFile, "=============== _Dispose_MenuItem 1 ========================\n", count);   1800                 fprintf(pFile, "=============== _Dispose_MenuItem 1 ========================\n", count);
1733                 fclose(pFile);   1801                 fclose(pFile);
1734                 */   1802                 */
1735     1803  
1736     1804  
1737                 hMenu = (HMENU) SendMessage (ugl_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);   1805                 hMenu = (HMENU) SendMessage (ugl_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);
1738                 RemoveMenu ((HMENU) hMenu, index-1, MF_BYPOSITION);   1806                 RemoveMenu ((HMENU) hMenu, index-1, MF_BYPOSITION);
1739                 Display_RemoveMenuItem(ugl_menuItem);   1807                 Display_RemoveMenuItem(ugl_menuItem);
1740                 Display_DecMenuItemIndex(display, ugl_menu->hwndCB, ugl_menuItem->index);   1808                 Display_DecMenuItemIndex(display, ugl_menu->hwndCB, ugl_menuItem->index);
1741     1809  
1742                 /*   1810                 /*
1743                 pFile = fopen ("\\myfile.txt","a");   1811                 pFile = fopen ("\\myfile.txt","a");
1744                 fprintf(pFile, "menuItemCount = %d\n", count);   1812                 fprintf(pFile, "menuItemCount = %d\n", count);
1745                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   1813                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
1746                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   1814                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
1747                 for(i=0; i<display->menuItemsLength; i++){                        1815                 for(i=0; i<display->menuItemsLength; i++){                     
1748                     if(display->menuItems[i] != NULL){   1816                     if(display->menuItems[i] != NULL){
1749                         // setting the left softkey text   1817                         // setting the left softkey text
1750                         if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   1818                         if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
1751                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   1819                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
1752                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   1820                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1753                         }   1821                         }
1754                     }   1822                     }
1755                 }   1823                 }
1756                 fprintf(pFile, "========================================================\n", count);   1824                 fprintf(pFile, "========================================================\n", count);
1757                 fclose(pFile);   1825                 fclose(pFile);
1758     1826  
1759                 */   1827                 */
1760     1828  
1761                 if(count == 1){   1829                 if(count == 1){
1762                     info.cbSize = sizeof(info);   1830                     info.cbSize = sizeof(info);
1763                     info.dwMask = TBIF_TEXT;   1831                     info.dwMask = TBIF_TEXT;
1764                     info.pszText = _T("");   1832                     info.pszText = _T("");
1765                     SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info);    1833                     SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info); 
1766                     SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);    1834                     SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info); 
1767                     if (display->activeShell == ugl_menu->parent) {   1835                     if (display->activeShell == ugl_menu->parent) {
1768                         ShowWindow(ugl_menu->hwndCB, SW_SHOW);   1836                         ShowWindow(ugl_menu->hwndCB, SW_SHOW);
1769                         ShowWindow(ugl_menu->hwndMB, SW_HIDE);   1837                         ShowWindow(ugl_menu->hwndMB, SW_HIDE);
1770                     }   1838                     }
1771     1839  
1772                     /*   1840                     /*
1773                     pFile = fopen ("\\myfile.txt","a");   1841                     pFile = fopen ("\\myfile.txt","a");
1774                     fprintf(pFile, "=============== _Dispose_MenuItem 2 ========================\n", count);   1842                     fprintf(pFile, "=============== _Dispose_MenuItem 2 ========================\n", count);
1775                     fprintf(pFile, "menuItemCount = %d\n", count);   1843                     fprintf(pFile, "menuItemCount = %d\n", count);
1776                     fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   1844                     fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
1777                     fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   1845                     fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
1778                     for(i=0; i<display->menuItemsLength; i++){                        1846                     for(i=0; i<display->menuItemsLength; i++){                     
1779                         if(display->menuItems[i] != NULL){   1847                         if(display->menuItems[i] != NULL){
1780                             // setting the left softkey text   1848                             // setting the left softkey text
1781                             if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   1849                             if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
1782                             if(display->menuItems[i]->parent_menu->hwndCB != 0){   1850                             if(display->menuItems[i]->parent_menu->hwndCB != 0){
1783                                 fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   1851                                 fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1784                             }   1852                             }
1785                         }   1853                         }
1786                     }   1854                     }
1787                     fprintf(pFile, "========================================================\n", count);   1855                     fprintf(pFile, "========================================================\n", count);
1788                     fclose(pFile);   1856                     fclose(pFile);
1789                     */   1857                     */
1790                 }   1858                 }
1791             } else {   1859             } else {
1792                 switch(count){   1860                 switch(count){
1793                     case 1: // item at left softkey   1861                     case 1: // item at left softkey
1794                         info.cbSize = sizeof(info);   1862                         info.cbSize = sizeof(info);
1795                         info.dwMask = TBIF_TEXT;   1863                         info.dwMask = TBIF_TEXT;
1796                         info.pszText = _T("");   1864                         info.pszText = _T("");
1797                         SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info);    1865                         SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info); 
1798     1866  
1799                         /*   1867                         /*
1800                         pFile = fopen ("\\myfile.txt","a");   1868                         pFile = fopen ("\\myfile.txt","a");
1801                         fprintf(pFile, "=============== _Dispose_MenuItem 3 ========================\n", count);   1869                         fprintf(pFile, "=============== _Dispose_MenuItem 3 ========================\n", count);
1802                         fprintf(pFile, "menuItemCount = %d\n", count);   1870                         fprintf(pFile, "menuItemCount = %d\n", count);
1803                         fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   1871                         fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
1804                         fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   1872                         fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
1805                         for(i=0; i<display->menuItemsLength; i++){                        1873                         for(i=0; i<display->menuItemsLength; i++){                     
1806                             if(display->menuItems[i] != NULL){   1874                             if(display->menuItems[i] != NULL){
1807                                 // setting the left softkey text   1875                                 // setting the left softkey text
1808                                 if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   1876                                 if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
1809                                 if(display->menuItems[i]->parent_menu->hwndCB != 0){   1877                                 if(display->menuItems[i]->parent_menu->hwndCB != 0){
1810                                     fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   1878                                     fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1811                                 }   1879                                 }
1812                             }   1880                             }
1813                         }   1881                         }
1814                         fprintf(pFile, "========================================================\n", count);   1882                         fprintf(pFile, "========================================================\n", count);
1815                         fclose(pFile);   1883                         fclose(pFile);
1816                         */   1884                         */
1817     1885  
1818     1886  
1819                         if (display->activeShell == ugl_menu->parent) {   1887                         if (display->activeShell == ugl_menu->parent) {
1820                             ShowWindow(ugl_menu->hwndCB, SW_SHOW);   1888                             ShowWindow(ugl_menu->hwndCB, SW_SHOW);
1821                             ShowWindow(ugl_menu->hwndMB, SW_HIDE);   1889                             ShowWindow(ugl_menu->hwndMB, SW_HIDE);
1822                         }   1890                         }
1823     1891  
1824                         break;   1892                         break;
1825     1893  
1826                     case 2:       1894                     case 2:    
1827                         // this is the softkey with Button/Menu (one of the item has submenu)   1895                         // this is the softkey with Button/Menu (one of the item has submenu)
1828                         tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 1);   1896                         tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 1);
1829                         if((tempItem != NULL && tempItem->hasSubMenu)){                       1897                         if((tempItem != NULL && tempItem->hasSubMenu)){                    
1830                             // if removing button, simply remove it.                          1898                             // if removing button, simply remove it.                       
1831                             if(index == 0){   1899                             if(index == 0){
1832                                 info.cbSize = sizeof(info);   1900                                 info.cbSize = sizeof(info);
1833                                 info.dwMask = TBIF_TEXT;   1901                                 info.dwMask = TBIF_TEXT;
1834                                 info.pszText = _T("");   1902                                 info.pszText = _T("");
1835                                 SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info);   1903                                 SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info);
1836     1904  
1837                                 /*   1905                                 /*
1838                                 pFile = fopen ("\\myfile.txt","a");   1906                                 pFile = fopen ("\\myfile.txt","a");
1839                                 fprintf(pFile, "=============== _Dispose_MenuItem 4 ========================\n", count);   1907                                 fprintf(pFile, "=============== _Dispose_MenuItem 4 ========================\n", count);
1840                                 fprintf(pFile, "menuItemCount = %d\n", count);   1908                                 fprintf(pFile, "menuItemCount = %d\n", count);
1841                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   1909                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
1842                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   1910                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
1843                                 for(i=0; i<display->menuItemsLength; i++){                        1911                                 for(i=0; i<display->menuItemsLength; i++){                     
1844                                     if(display->menuItems[i] != NULL){   1912                                     if(display->menuItems[i] != NULL){
1845                                         // setting the left softkey text   1913                                         // setting the left softkey text
1846                                         if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   1914                                         if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
1847                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   1915                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
1848                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   1916                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1849                                         }   1917                                         }
1850                                     }   1918                                     }
1851                                 }   1919                                 }
1852                                 fprintf(pFile, "========================================================\n", count);   1920                                 fprintf(pFile, "========================================================\n", count);
1853                                 fclose(pFile);   1921                                 fclose(pFile);
1854                                 */   1922                                 */
1855     1923  
1856     1924  
1857                                 if (display->activeShell == ugl_menu->parent) {   1925                                 if (display->activeShell == ugl_menu->parent) {
1858                                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);   1926                                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);
1859                                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);   1927                                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);
1860                                 }   1928                                 }
1861     1929  
1862                                 break;   1930                                 break;
1863     1931  
1864     1932  
1865     1933  
1866                             } else {   1934                             } else {
1867                                 // else remove menu and swtich back to Button/Button menu   1935                                 // else remove menu and swtich back to Button/Button menu
1868                                 /*   1936                                 /*
1869                                 pFile = fopen ("\\myfile.txt","a");   1937                                 pFile = fopen ("\\myfile.txt","a");
1870                                 fprintf(pFile, "=============== _Dispose_MenuItem 5 ========================\n", count);   1938                                 fprintf(pFile, "=============== _Dispose_MenuItem 5 ========================\n", count);
1871                                 fclose(pFile);   1939                                 fclose(pFile);
1872                                 */   1940                                 */
1873     1941  
1874                                 hMenu = (HMENU) SendMessage (ugl_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);   1942                                 hMenu = (HMENU) SendMessage (ugl_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);
1875                                 RemoveMenu ((HMENU) hMenu, index-1, MF_BYPOSITION);   1943                                 RemoveMenu ((HMENU) hMenu, index-1, MF_BYPOSITION);
1876     1944  
1877                                 tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 0);   1945                                 tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 0);
1878                                           1946                                        
1879                                 if(tempItem != NULL && tempItem->text != NULL){                               1947                                 if(tempItem != NULL && tempItem->text != NULL){                            
1880                                     info.cbSize = sizeof(TBBUTTONINFO);   1948                                     info.cbSize = sizeof(TBBUTTONINFO);
1881                                     info.dwMask = TBIF_TEXT;   1949                                     info.dwMask = TBIF_TEXT;
1882                                     info.pszText = (LPWSTR) tempItem->text;   1950                                     info.pszText = (LPWSTR) tempItem->text;
1883                                     if(!SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){   1951                                     if(!SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){
1884                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));   1952                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));
1885                                     }   1953                                     }
1886                                 }   1954                                 }
1887     1955  
1888                                 info.cbSize = sizeof(info);   1956                                 info.cbSize = sizeof(info);
1889                                 info.dwMask = TBIF_TEXT;   1957                                 info.dwMask = TBIF_TEXT;
1890                                 info.pszText = _T("");   1958                                 info.pszText = _T("");
1891                                 SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);   1959                                 SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);
1892                                 if (display->activeShell == ugl_menu->parent) {   1960                                 if (display->activeShell == ugl_menu->parent) {
1893                                     ShowWindow(ugl_menu->hwndCB, SW_SHOW);   1961                                     ShowWindow(ugl_menu->hwndCB, SW_SHOW);
1894                                     ShowWindow(ugl_menu->hwndMB, SW_HIDE);   1962                                     ShowWindow(ugl_menu->hwndMB, SW_HIDE);
1895                                 }   1963                                 }
1896     1964  
1897     1965  
1898                                 /*   1966                                 /*
1899                                 pFile = fopen ("\\myfile.txt","a");   1967                                 pFile = fopen ("\\myfile.txt","a");
1900                                 fprintf(pFile, "menuItemCount = %d\n", count);   1968                                 fprintf(pFile, "menuItemCount = %d\n", count);
1901                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   1969                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
1902                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   1970                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
1903                                 for(i=0; i<display->menuItemsLength; i++){                        1971                                 for(i=0; i<display->menuItemsLength; i++){                     
1904                                     if(display->menuItems[i] != NULL){   1972                                     if(display->menuItems[i] != NULL){
1905                                         // setting the left softkey text   1973                                         // setting the left softkey text
1906                                         if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   1974                                         if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
1907                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   1975                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
1908                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   1976                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1909                                         }   1977                                         }
1910                                     }   1978                                     }
1911                                 }   1979                                 }
1912                                 fprintf(pFile, "========================================================\n", count);   1980                                 fprintf(pFile, "========================================================\n", count);
1913                                 fclose(pFile);   1981                                 fclose(pFile);
1914                                 */   1982                                 */
1915     1983  
1916                                 break;   1984                                 break;
1917     1985  
1918     1986  
1919                             }   1987                             }
1920                   1988                
1921                         } else {   1989                         } else {
1922                             // softkey button/button case                         1990                             // softkey button/button case                      
1923                             // find the item on the rightsoftkey and set its text to the left                                                         1991                             // find the item on the rightsoftkey and set its text to the left                                                      
1924                             if(index == 0){   1992                             if(index == 0){
1925                                 if(tempItem != NULL && tempItem->text != NULL){                               1993                                 if(tempItem != NULL && tempItem->text != NULL){                            
1926                                         info.cbSize = sizeof(TBBUTTONINFO);   1994                                         info.cbSize = sizeof(TBBUTTONINFO);
1927                                         info.dwMask = TBIF_TEXT;   1995                                         info.dwMask = TBIF_TEXT;
1928                                         info.pszText = (LPWSTR) tempItem->text;   1996                                         info.pszText = (LPWSTR) tempItem->text;
1929                                         tempItem->index = 0;   1997                                         tempItem->index = 0;
1930                                         //Set right button to left button   1998                                         //Set right button to left button
1931                                         if(!SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){   1999                                         if(!SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){
1932                                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));   2000                                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));
1933                                         }   2001                                         }
1934                                     }   2002                                     }
1935                                 info.cbSize = sizeof(info);   2003                                 info.cbSize = sizeof(info);
1936                                 info.dwMask = TBIF_TEXT;   2004                                 info.dwMask = TBIF_TEXT;
1937                                 info.pszText = _T("");   2005                                 info.pszText = _T("");
1938                                 //Set empty menuitem to right button   2006                                 //Set empty menuitem to right button
1939                                 SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);   2007                                 SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);
1940     2008  
1941     2009  
1942                                 /*   2010                                 /*
1943                                 pFile = fopen ("\\myfile.txt","a");   2011                                 pFile = fopen ("\\myfile.txt","a");
1944                                 fprintf(pFile, "=============== _Dispose_MenuItem 6 ========================\n", count);   2012                                 fprintf(pFile, "=============== _Dispose_MenuItem 6 ========================\n", count);
1945                                 fprintf(pFile, "menuItemCount = %d\n", count);   2013                                 fprintf(pFile, "menuItemCount = %d\n", count);
1946                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   2014                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
1947                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   2015                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
1948                                 for(i=0; i<display->menuItemsLength; i++){                        2016                                 for(i=0; i<display->menuItemsLength; i++){                     
1949                                     if(display->menuItems[i] != NULL){   2017                                     if(display->menuItems[i] != NULL){
1950                                         // setting the left softkey text   2018                                         // setting the left softkey text
1951                                         if (display->menuItems[index] == NULL) continue;   2019                                         if (display->menuItems[index] == NULL) continue;
1952                                         if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   2020                                         if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
1953                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   2021                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
1954                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   2022                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1955                                         }   2023                                         }
1956                                     }   2024                                     }
1957                                 }   2025                                 }
1958                                 fprintf(pFile, "========================================================\n", count);   2026                                 fprintf(pFile, "========================================================\n", count);
1959                                 fclose(pFile);   2027                                 fclose(pFile);
1960                                 */   2028                                 */
1961                                 //ShowWindow(ugl_menu->hwndCB, SW_SHOW);   2029                                 //ShowWindow(ugl_menu->hwndCB, SW_SHOW);
1962                                 //ShowWindow(ugl_menu->hwndMB, SW_HIDE);   2030                                 //ShowWindow(ugl_menu->hwndMB, SW_HIDE);
1963     2031  
1964                                 if (display->activeShell == ugl_menu->parent) {   2032                                 if (display->activeShell == ugl_menu->parent) {
1965                                     ShowWindow(ugl_menu->hwndCB, SW_SHOW);   2033                                     ShowWindow(ugl_menu->hwndCB, SW_SHOW);
1966                                     ShowWindow(ugl_menu->hwndMB, SW_HIDE);   2034                                     ShowWindow(ugl_menu->hwndMB, SW_HIDE);
1967                                 }   2035                                 }
1968     2036  
1969                                 break;   2037                                 break;
1970     2038  
1971                             } else {   2039                             } else {
1972                                 // else simply set the right softkey to ""                    2040                                 // else simply set the right softkey to ""                 
1973                                 info.cbSize = sizeof(info);   2041                                 info.cbSize = sizeof(info);
1974                                 info.dwMask = TBIF_TEXT;   2042                                 info.dwMask = TBIF_TEXT;
1975                                 info.pszText = _T("");   2043                                 info.pszText = _T("");
1976                                 SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);   2044                                 SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);
1977                                 //ShowWindow(ugl_menu->hwndCB, SW_SHOW);   2045                                 //ShowWindow(ugl_menu->hwndCB, SW_SHOW);
1978                                 //ShowWindow(ugl_menu->hwndMB, SW_HIDE);   2046                                 //ShowWindow(ugl_menu->hwndMB, SW_HIDE);
1979     2047  
1980                                 if (display->activeShell == ugl_menu->parent) {   2048                                 if (display->activeShell == ugl_menu->parent) {
1981                                     ShowWindow(ugl_menu->hwndCB, SW_SHOW);   2049                                     ShowWindow(ugl_menu->hwndCB, SW_SHOW);
1982                                     ShowWindow(ugl_menu->hwndMB, SW_HIDE);   2050                                     ShowWindow(ugl_menu->hwndMB, SW_HIDE);
1983                                 }   2051                                 }
1984     2052  
1985                                 /*   2053                                 /*
1986                                 pFile = fopen ("\\myfile.txt","a");   2054                                 pFile = fopen ("\\myfile.txt","a");
1987                                 fprintf(pFile, "=============== _Dispose_MenuItem 7 ========================\n", count);   2055                                 fprintf(pFile, "=============== _Dispose_MenuItem 7 ========================\n", count);
1988                                 fprintf(pFile, "menuItemCount = %d\n", count);   2056                                 fprintf(pFile, "menuItemCount = %d\n", count);
1989                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   2057                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
1990                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   2058                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
1991                                 for(i=0; i<display->menuItemsLength; i++){                        2059                                 for(i=0; i<display->menuItemsLength; i++){                     
1992                                     if(display->menuItems[i] != NULL){   2060                                     if(display->menuItems[i] != NULL){
1993                                         // setting the left softkey text   2061                                         // setting the left softkey text
1994                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   2062                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
1995                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   2063                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
1996                                         }   2064                                         }
1997                                     }   2065                                     }
1998                                 }   2066                                 }
1999                                   2067                                
2000                                 fprintf(pFile, "========================================================\n", count);   2068                                 fprintf(pFile, "========================================================\n", count);
2001                                 fclose(pFile);   2069                                 fclose(pFile);
2002                                 break;   2070                                 break;
2003                                 */   2071                                 */
2004     2072  
2005                             }   2073                             }
2006                         }   2074                         }
2007                         break;   2075                         break;
2008     2076  
2009                     case 3:   2077                     case 3:
2010                         /*                  <SUB>   2078                         /*                  <SUB>
2011                                             <SUB>   2079                                             <SUB>
2012                             <NULL>          <SUB>   2080                             <NULL>          <SUB>
2013                         */   2081                         */
2014                         hMenu = (HMENU) SendMessage (ugl_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);   2082                         hMenu = (HMENU) SendMessage (ugl_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);
2015                         tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 0);   2083                         tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 0);
2016                         if (tempItem == NULL) { // remove SUB directly   2084                         if (tempItem == NULL) { // remove SUB directly
2017                             /*   2085                             /*
2018                             pFile = fopen ("\\myfile.txt","a");   2086                             pFile = fopen ("\\myfile.txt","a");
2019                             fprintf(pFile, "=============== _Dispose_MenuItem 8 ========================\n", count);   2087                             fprintf(pFile, "=============== _Dispose_MenuItem 8 ========================\n", count);
2020                             fclose(pFile);   2088                             fclose(pFile);
2021                             */   2089                             */
2022     2090  
2023                             RemoveMenu (hMenu, ugl_menuItem->index-1, MF_BYPOSITION);   2091                             RemoveMenu (hMenu, ugl_menuItem->index-1, MF_BYPOSITION);
2024                             Display_DecMenuItemIndex(display, ugl_menu->hwndCB, index);       2092                             Display_DecMenuItemIndex(display, ugl_menu->hwndCB, index);    
2025     2093  
2026                             /*    2094                             /* 
2027                             pFile = fopen ("\\myfile.txt","a");   2095                             pFile = fopen ("\\myfile.txt","a");
2028                                 fprintf(pFile, "menuItemCount = %d\n", count);   2096                                 fprintf(pFile, "menuItemCount = %d\n", count);
2029                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   2097                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
2030                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   2098                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
2031                                 for(i=0; i<display->menuItemsLength; i++){                        2099                                 for(i=0; i<display->menuItemsLength; i++){                     
2032                                     if(display->menuItems[i] != NULL){   2100                                     if(display->menuItems[i] != NULL){
2033                                         // setting the left softkey text   2101                                         // setting the left softkey text
2034                                         if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   2102                                         if(display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
2035                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   2103                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
2036                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   2104                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
2037                                         }   2105                                         }
2038                                     }   2106                                     }
2039                                 }   2107                                 }
2040                                   2108                                
2041                                 fprintf(pFile, "========================================================\n", count);   2109                                 fprintf(pFile, "========================================================\n", count);
2042                                 fclose(pFile);   2110                                 fclose(pFile);
2043                                 */   2111                                 */
2044     2112  
2045                             if (display->activeShell == ugl_menu->parent) {   2113                             if (display->activeShell == ugl_menu->parent) {
2046                                 ShowWindow(ugl_menu->hwndCB, SW_HIDE);   2114                                 ShowWindow(ugl_menu->hwndCB, SW_HIDE);
2047                                 ShowWindow(ugl_menu->hwndMB, SW_SHOW);   2115                                 ShowWindow(ugl_menu->hwndMB, SW_SHOW);
2048                             }   2116                             }
2049                             break;   2117                             break;
2050     2118  
2051     2119  
2052                         } else if (index == 0) {   2120                         } else if (index == 0) {
2053                             /* check if the other two menuitems has submenus */   2121                             /* check if the other two menuitems has submenus */
2054                             /* case 1:   2122                             /* case 1:
2055                                                 <SUB>   2123                                                 <SUB>
2056                                 <item1>         <SUB>   2124                                 <item1>         <SUB>
2057                                 if <item1> is to be deleted, set the left softkey to ""   2125                                 if <item1> is to be deleted, set the left softkey to ""
2058                             */   2126                             */
2059                             /* case 2:   2127                             /* case 2:
2060                                                 <SUB>   2128                                                 <SUB>
2061                                 <item1>         <item2>   2129                                 <item1>         <item2>
2062                               2130                            
2063                                 or   2131                                 or
2064                                                 <item2>   2132                                                 <item2>
2065                                 <item1>         <SUB>   2133                                 <item1>         <SUB>
2066                                 if <item1> is to be deleted, move <item2> to left and change to <button/button>   2134                                 if <item1> is to be deleted, move <item2> to left and change to <button/button>
2067                             */   2135                             */
2068                             /* case 3:   2136                             /* case 3:
2069                                                 <item3>   2137                                                 <item3>
2070                                 <item1>         <item2>   2138                                 <item1>         <item2>
2071                                 if <item1> is to be deleted, move <item2> to left and change to <button/button>   2139                                 if <item1> is to be deleted, move <item2> to left and change to <button/button>
2072                             */   2140                             */
2073                             found = FALSE;   2141                             found = FALSE;
2074                             foundfirst = FALSE;   2142                             foundfirst = FALSE;
2075                             tempItem = tempItem2 = tempItem3 = NULL;   2143                             tempItem = tempItem2 = tempItem3 = NULL;
2076                             for(i=0; i<display->menuItemsLength; i++){   2144                             for(i=0; i<display->menuItemsLength; i++){
2077                                 if(display->menuItems[i] != NULL){   2145                                 if(display->menuItems[i] != NULL){
2078                                     if(display->menuItems[i]->parent_menu->hwndCB != 0) {   2146                                     if(display->menuItems[i]->parent_menu->hwndCB != 0) {
2079                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   2147                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
2080                                         if (display->menuItems[i]->index == index) continue;   2148                                         if (display->menuItems[i]->index == index) continue;
2081                                         if (!display->menuItems[i]->hasSubMenu) {   2149                                         if (!display->menuItems[i]->hasSubMenu) {
2082                                             found = TRUE; //found item2, doesn't have submenu   2150                                             found = TRUE; //found item2, doesn't have submenu
2083                                             if(!foundfirst) {   2151                                             if(!foundfirst) {
2084                                                 foundfirst = TRUE;   2152                                                 foundfirst = TRUE;
2085                                                 tempItem = display->menuItems[i]; // this is item2   2153                                                 tempItem = display->menuItems[i]; // this is item2
2086                                             } else {   2154                                             } else {
2087                                                 tempItem3 = display->menuItems[i]; // this is item3   2155                                                 tempItem3 = display->menuItems[i]; // this is item3
2088                                             }   2156                                             }
2089                                         } else {   2157                                         } else {
2090                                             tempItem2 = display->menuItems[i]; // this is SUB   2158                                             tempItem2 = display->menuItems[i]; // this is SUB
2091                                         }   2159                                         }
2092     2160  
2093                                     }   2161                                     }
2094                                 }   2162                                 }
2095                             }   2163                             }
2096                             if (!found) { // case 1   2164                             if (!found) { // case 1
2097                                 info.cbSize = sizeof(TBBUTTONINFO);   2165                                 info.cbSize = sizeof(TBBUTTONINFO);
2098                                 info.dwMask = TBIF_TEXT;   2166                                 info.dwMask = TBIF_TEXT;
2099                                 info.pszText = (LPWSTR) _T("");   2167                                 info.pszText = (LPWSTR) _T("");
2100                                 if(!SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){   2168                                 if(!SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){
2101                                     Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));   2169                                     Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));
2102                                 }   2170                                 }
2103     2171  
2104                                 /*   2172                                 /*
2105                                 pFile = fopen ("\\myfile.txt","a");   2173                                 pFile = fopen ("\\myfile.txt","a");
2106                                 fprintf(pFile, "=============== _Dispose_MenuItem 9 ========================\n", count);   2174                                 fprintf(pFile, "=============== _Dispose_MenuItem 9 ========================\n", count);
2107                                 fprintf(pFile, "menuItemCount = %d\n", count);   2175                                 fprintf(pFile, "menuItemCount = %d\n", count);
2108                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   2176                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
2109                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   2177                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
2110                                 for(i=0; i<display->menuItemsLength; i++){                        2178                                 for(i=0; i<display->menuItemsLength; i++){                     
2111                                     if(display->menuItems[i] != NULL){   2179                                     if(display->menuItems[i] != NULL){
2112                                         // setting the left softkey text   2180                                         // setting the left softkey text
2113                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   2181                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
2114                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   2182                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
2115                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   2183                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
2116                                         }   2184                                         }
2117                                     }   2185                                     }
2118                                 }   2186                                 }
2119                                   2187                                
2120                                 fprintf(pFile, "========================================================\n", count);   2188                                 fprintf(pFile, "========================================================\n", count);
2121                                 fclose(pFile);   2189                                 fclose(pFile);
2122                                 */   2190                                 */
2123     2191  
2124                                 if (display->activeShell == ugl_menu->parent) {   2192                                 if (display->activeShell == ugl_menu->parent) {
2125                                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);   2193                                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);
2126                                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);   2194                                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);
2127                                 }   2195                                 }
2128     2196  
2129                                 break;   2197                                 break;
2130     2198  
2131     2199  
2132                             } else if (tempItem2 != NULL) { //case 2   2200                             } else if (tempItem2 != NULL) { //case 2
2133                             /*                  <SUB>   2201                             /*                  <SUB>
2134                                 <item1>         <item2>   2202                                 <item1>         <item2>
2135     2203  
2136                                 or                2204                                 or             
2137                                                 <item2>   2205                                                 <item2>
2138                                 <item1>         <SUB>   2206                                 <item1>         <SUB>
2139     2207  
2140                                 if the <item1> is to be deleted, need to move the <item2> to left softkey   2208                                 if the <item1> is to be deleted, need to move the <item2> to left softkey
2141                             */   2209                             */
2142                                 /*   2210                                 /*
2143                                 pFile = fopen ("\\myfile.txt","a");   2211                                 pFile = fopen ("\\myfile.txt","a");
2144                                 fprintf(pFile, "=============== _Dispose_MenuItem 10 ========================\n", count);   2212                                 fprintf(pFile, "=============== _Dispose_MenuItem 10 ========================\n", count);
2145                                 fclose(pFile);   2213                                 fclose(pFile);
2146                                 */   2214                                 */
2147                                   2215                                
2148                                 RemoveMenu ((HMENU) hMenu, tempItem->index-1, MF_BYPOSITION);   2216                                 RemoveMenu ((HMENU) hMenu, tempItem->index-1, MF_BYPOSITION);
2149                                 Display_DecMenuItemIndex(display, ugl_menu->hwndCB, tempItem->index);   2217                                 Display_DecMenuItemIndex(display, ugl_menu->hwndCB, tempItem->index);
2150                                 tempItem->index = 0;   2218                                 tempItem->index = 0;
2151                                 info.cbSize = sizeof(TBBUTTONINFO);   2219                                 info.cbSize = sizeof(TBBUTTONINFO);
2152                                 info.dwMask = TBIF_TEXT;   2220                                 info.dwMask = TBIF_TEXT;
2153                                 info.pszText = (LPWSTR) tempItem->text;   2221                                 info.pszText = (LPWSTR) tempItem->text;
2154                                 if(!SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){   2222                                 if(!SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){
2155                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));   2223                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));
2156                                 }   2224                                 }
2157     2225  
2158                                 /*   2226                                 /*
2159                                 pFile = fopen ("\\myfile.txt","a");   2227                                 pFile = fopen ("\\myfile.txt","a");
2160                                 fprintf(pFile, "menuItemCount = %d\n", count);   2228                                 fprintf(pFile, "menuItemCount = %d\n", count);
2161                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   2229                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
2162                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   2230                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
2163                                 for(i=0; i<display->menuItemsLength; i++){                        2231                                 for(i=0; i<display->menuItemsLength; i++){                     
2164                                     if(display->menuItems[i] != NULL){   2232                                     if(display->menuItems[i] != NULL){
2165                                         // setting the left softkey text   2233                                         // setting the left softkey text
2166                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   2234                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
2167                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   2235                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
2168                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   2236                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
2169                                         }   2237                                         }
2170                                     }   2238                                     }
2171                                 }   2239                                 }
2172                                   2240                                
2173                                 fprintf(pFile, "========================================================\n", count);   2241                                 fprintf(pFile, "========================================================\n", count);
2174                                 fclose(pFile);   2242                                 fclose(pFile);
2175                                 */   2243                                 */
2176     2244  
2177                                 if (display->activeShell == ugl_menu->parent) {   2245                                 if (display->activeShell == ugl_menu->parent) {
2178                                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);   2246                                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);
2179                                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);   2247                                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);
2180                                 }   2248                                 }
2181     2249  
2182     2250  
2183                                 break;   2251                                 break;
2184     2252  
2185     2253  
2186                             } else { // case 3   2254                             } else { // case 3
2187                             /*                  <item3>   2255                             /*                  <item3>
2188                                 <item1>         <item2>   2256                                 <item1>         <item2>
2189                                 if <item1> is to be deleted, move <item2> to left and change to <button/button>   2257                                 if <item1> is to be deleted, move <item2> to left and change to <button/button>
2190                             */   2258                             */
2191     2259  
2192                             /*   2260                             /*
2193                             pFile = fopen ("\\myfile.txt","a");   2261                             pFile = fopen ("\\myfile.txt","a");
2194                             fprintf(pFile, "=============== _Dispose_MenuItem 11 ========================\n", count);   2262                             fprintf(pFile, "=============== _Dispose_MenuItem 11 ========================\n", count);
2195                             fclose(pFile);   2263                             fclose(pFile);
2196                             */   2264                             */
2197     2265  
2198                                 hMenu = (HMENU) SendMessage (ugl_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);   2266                                 hMenu = (HMENU) SendMessage (ugl_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);
2199                                 Display_DecMenuItemIndex(display, ugl_menu->hwndCB, tempItem->index);   2267                                 Display_DecMenuItemIndex(display, ugl_menu->hwndCB, tempItem->index);
2200                                 tempItem->index = 0;   2268                                 tempItem->index = 0;
2201                                 info.cbSize = sizeof(TBBUTTONINFO);   2269                                 info.cbSize = sizeof(TBBUTTONINFO);
2202                                 info.dwMask = TBIF_TEXT;   2270                                 info.dwMask = TBIF_TEXT;
2203                                 info.pszText = (LPWSTR) tempItem->text;   2271                                 info.pszText = (LPWSTR) tempItem->text;
2204                                 if(!SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){   2272                                 if(!SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){
2205                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));   2273                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));
2206                                 }   2274                                 }
2207                                 info.pszText = (LPWSTR) tempItem3->text;   2275                                 info.pszText = (LPWSTR) tempItem3->text;
2208                                 if(!SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info)){   2276                                 if(!SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info)){
2209                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));   2277                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));
2210                                 }   2278                                 }
2211                                 RemoveMenu ((HMENU) hMenu, 1, MF_BYPOSITION);   2279                                 RemoveMenu ((HMENU) hMenu, 1, MF_BYPOSITION);
2212                                 RemoveMenu ((HMENU) hMenu, 0, MF_BYPOSITION);   2280                                 RemoveMenu ((HMENU) hMenu, 0, MF_BYPOSITION);
2213     2281  
2214                                 info.cbSize = sizeof(info);   2282                                 info.cbSize = sizeof(info);
2215                                 info.dwMask = TBIF_TEXT;   2283                                 info.dwMask = TBIF_TEXT;
2216                                 info.pszText = _T("");   2284                                 info.pszText = _T("");
2217                                 SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info);    2285                                 SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info); 
2218                                 SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);    2286                                 SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info); 
2219     2287  
2220                                 if (display->activeShell == ugl_menu->parent) {   2288                                 if (display->activeShell == ugl_menu->parent) {
2221                                     ShowWindow(ugl_menu->hwndCB, SW_SHOW);   2289                                     ShowWindow(ugl_menu->hwndCB, SW_SHOW);
2222                                     ShowWindow(ugl_menu->hwndMB, SW_HIDE);   2290                                     ShowWindow(ugl_menu->hwndMB, SW_HIDE);
2223                                 }   2291                                 }
2224     2292  
2225     2293  
2226                                 //ShowWindow(ugl_menu->hwndCB, SW_SHOW);   2294                                 //ShowWindow(ugl_menu->hwndCB, SW_SHOW);
2227                                 //ShowWindow(ugl_menu->hwndMB, SW_HIDE);   2295                                 //ShowWindow(ugl_menu->hwndMB, SW_HIDE);
2228     2296  
2229                                 /*   2297                                 /*
2230                                 pFile = fopen ("\\myfile.txt","a");   2298                                 pFile = fopen ("\\myfile.txt","a");
2231                                 fprintf(pFile, "menuItemCount = %d\n", count);   2299                                 fprintf(pFile, "menuItemCount = %d\n", count);
2232                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   2300                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
2233                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   2301                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
2234                                 for(i=0; i<display->menuItemsLength; i++){                        2302                                 for(i=0; i<display->menuItemsLength; i++){                     
2235                                     if(display->menuItems[i] != NULL){   2303                                     if(display->menuItems[i] != NULL){
2236                                         // setting the left softkey text   2304                                         // setting the left softkey text
2237                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   2305                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
2238                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   2306                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
2239                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   2307                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
2240                                         }   2308                                         }
2241                                     }   2309                                     }
2242                                 }   2310                                 }
2243                                   2311                                
2244                                 fprintf(pFile, "========================================================\n", count);   2312                                 fprintf(pFile, "========================================================\n", count);
2245                                 fclose(pFile);   2313                                 fclose(pFile);
2246                                 */   2314                                 */
2247     2315  
2248                                 break;   2316                                 break;
2249     2317  
2250     2318  
2251     2319  
2252                             }   2320                             }
2253                         } else { //if item1 is not to be deleted   2321                         } else { //if item1 is not to be deleted
2254                             /* case 1:   2322                             /* case 1:
2255                                                 <SUB2>   2323                                                 <SUB2>
2256                                 <item1>         <SUB1>   2324                                 <item1>         <SUB1>
2257                                   2325                                
2258                             */   2326                             */
2259                             /* case 2:   2327                             /* case 2:
2260                                                 <SUB>   2328                                                 <SUB>
2261                                 <item1>         <item2>   2329                                 <item1>         <item2>
2262                               2330                            
2263                                 or   2331                                 or
2264                                                 <item2>   2332                                                 <item2>
2265                                 <item1>         <SUB>   2333                                 <item1>         <SUB>
2266                                   2334                                
2267                             */   2335                             */
2268                             /* case 3:   2336                             /* case 3:
2269                                                 <item3>   2337                                                 <item3>
2270                                 <item1>         <item2>   2338                                 <item1>         <item2>
2271                                   2339                                
2272                             */   2340                             */
2273     2341  
2274                             /*   2342                             /*
2275                             pFile = fopen ("\\myfile.txt","a");   2343                             pFile = fopen ("\\myfile.txt","a");
2276                             fprintf(pFile, "=============== _Dispose_MenuItem 12 ========================\n", count);   2344                             fprintf(pFile, "=============== _Dispose_MenuItem 12 ========================\n", count);
2277                             fclose(pFile);   2345                             fclose(pFile);
2278                             */   2346                             */
2279     2347  
2280                             found = FALSE;   2348                             found = FALSE;
2281                             foundfirst = FALSE;   2349                             foundfirst = FALSE;
2282                             foundfirstsub = FALSE;   2350                             foundfirstsub = FALSE;
2283                             tempItem = tempItem2 = tempItem3 = NULL;   2351                             tempItem = tempItem2 = tempItem3 = NULL;
2284                             for(i=0; i<display->menuItemsLength; i++){   2352                             for(i=0; i<display->menuItemsLength; i++){
2285                                 if(display->menuItems[i] != NULL){   2353                                 if(display->menuItems[i] != NULL){
2286                                     if(display->menuItems[i]->parent_menu->hwndCB != 0) {   2354                                     if(display->menuItems[i]->parent_menu->hwndCB != 0) {
2287                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   2355                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
2288                                         if (display->menuItems[i]->index == index) continue;   2356                                         if (display->menuItems[i]->index == index) continue;
2289                                         if (display->menuItems[i]->index == 0) continue; // keep index 0 as left softkey regardlessly   2357                                         if (display->menuItems[i]->index == 0) continue; // keep index 0 as left softkey regardlessly
2290                                         tempItem = display->menuItems[i]; // the remaining one, might be item or SUB.   2358                                         tempItem = display->menuItems[i]; // the remaining one, might be item or SUB.
2291                                     }   2359                                     }
2292                                 }   2360                                 }
2293                             }   2361                             }
2294     2362  
2295                             if (tempItem->hasSubMenu) { //the remaining one is SUB   2363                             if (tempItem->hasSubMenu) { //the remaining one is SUB
2296                                 RemoveMenu (hMenu, ugl_menuItem->index-1, MF_BYPOSITION);   2364                                 RemoveMenu (hMenu, ugl_menuItem->index-1, MF_BYPOSITION);
2297                                 Display_DecMenuItemIndex(display, ugl_menu->hwndCB, index);       2365                                 Display_DecMenuItemIndex(display, ugl_menu->hwndCB, index);    
2298     2366  
2299                                 /*   2367                                 /*
2300                                 pFile = fopen ("\\myfile.txt","a");   2368                                 pFile = fopen ("\\myfile.txt","a");
2301                                 fprintf(pFile, "menuItemCount = %d\n", count);   2369                                 fprintf(pFile, "menuItemCount = %d\n", count);
2302                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   2370                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
2303                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   2371                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
2304                                 for(i=0; i<display->menuItemsLength; i++){                        2372                                 for(i=0; i<display->menuItemsLength; i++){                     
2305                                     if(display->menuItems[i] != NULL){   2373                                     if(display->menuItems[i] != NULL){
2306                                         // setting the left softkey text   2374                                         // setting the left softkey text
2307                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   2375                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
2308                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   2376                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
2309                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   2377                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
2310                                         }   2378                                         }
2311                                     }   2379                                     }
2312                                 }   2380                                 }
2313                                   2381                                
2314                                 fprintf(pFile, "========================================================\n", count);   2382                                 fprintf(pFile, "========================================================\n", count);
2315                                 fclose(pFile);   2383                                 fclose(pFile);
2316                                 */   2384                                 */
2317     2385  
2318                                 if (display->activeShell == ugl_menu->parent) {   2386                                 if (display->activeShell == ugl_menu->parent) {
2319                                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);   2387                                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);
2320                                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);   2388                                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);
2321                                 }   2389                                 }
2322     2390  
2323                                 break;   2391                                 break;
2324     2392  
2325     2393  
2326                             } else { // the remaining one is <item>, need to change to <button/button>   2394                             } else { // the remaining one is <item>, need to change to <button/button>
2327                                 /*   2395                                 /*
2328                                 pFile = fopen ("\\myfile.txt","a");   2396                                 pFile = fopen ("\\myfile.txt","a");
2329                                 fprintf(pFile, "=============== _Dispose_MenuItem 13 ========================\n", count);   2397                                 fprintf(pFile, "=============== _Dispose_MenuItem 13 ========================\n", count);
2330                                 fclose(pFile);   2398                                 fclose(pFile);
2331                                 */   2399                                 */
2332     2400  
2333                                 tempItem2 = Display_FindMenuItem(display, ugl_menu->hwndCB, 0);   2401                                 tempItem2 = Display_FindMenuItem(display, ugl_menu->hwndCB, 0);
2334                                 Display_DecMenuItemIndex(display, ugl_menu->hwndCB, index);   2402                                 Display_DecMenuItemIndex(display, ugl_menu->hwndCB, index);
2335                                 info.cbSize = sizeof(TBBUTTONINFO);   2403                                 info.cbSize = sizeof(TBBUTTONINFO);
2336                                 info.dwMask = TBIF_TEXT;   2404                                 info.dwMask = TBIF_TEXT;
2337                                 info.pszText = (LPWSTR) tempItem2->text;   2405                                 info.pszText = (LPWSTR) tempItem2->text;
2338                                 if(!SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){   2406                                 if(!SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){
2339                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));   2407                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));
2340                                 }   2408                                 }
2341                                 info.pszText = (LPWSTR) tempItem->text;   2409                                 info.pszText = (LPWSTR) tempItem->text;
2342                                 if(!SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info)){   2410                                 if(!SendMessage (ugl_menu->hwndCB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info)){
2343                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));   2411                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));
2344                                 }   2412                                 }
2345                                 RemoveMenu ((HMENU) hMenu, 1, MF_BYPOSITION);   2413                                 RemoveMenu ((HMENU) hMenu, 1, MF_BYPOSITION);
2346                                 RemoveMenu ((HMENU) hMenu, 0, MF_BYPOSITION);   2414                                 RemoveMenu ((HMENU) hMenu, 0, MF_BYPOSITION);
2347                                 info.cbSize = sizeof(info);   2415                                 info.cbSize = sizeof(info);
2348                                 info.dwMask = TBIF_TEXT;   2416                                 info.dwMask = TBIF_TEXT;
2349                                 info.pszText = _T("");   2417                                 info.pszText = _T("");
2350                                 SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info);    2418                                 SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info); 
2351                                 SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info);    2419                                 SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY1, (long) &info); 
2352     2420  
2353                                 //ShowWindow(ugl_menu->hwndCB, SW_SHOW);   2421                                 //ShowWindow(ugl_menu->hwndCB, SW_SHOW);
2354                                 //ShowWindow(ugl_menu->hwndMB, SW_HIDE);   2422                                 //ShowWindow(ugl_menu->hwndMB, SW_HIDE);
2355     2423  
2356                                 if (display->activeShell == ugl_menu->parent) {   2424                                 if (display->activeShell == ugl_menu->parent) {
2357                                     ShowWindow(ugl_menu->hwndCB, SW_SHOW);   2425                                     ShowWindow(ugl_menu->hwndCB, SW_SHOW);
2358                                     ShowWindow(ugl_menu->hwndMB, SW_HIDE);   2426                                     ShowWindow(ugl_menu->hwndMB, SW_HIDE);
2359                                 }   2427                                 }
2360     2428  
2361     2429  
2362                                 /*   2430                                 /*
2363                                 pFile = fopen ("\\myfile.txt","a");   2431                                 pFile = fopen ("\\myfile.txt","a");
2364                                 fprintf(pFile, "menuItemCount = %d\n", count);   2432                                 fprintf(pFile, "menuItemCount = %d\n", count);
2365                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   2433                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
2366                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   2434                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
2367                                 for(i=0; i<display->menuItemsLength; i++){                        2435                                 for(i=0; i<display->menuItemsLength; i++){                     
2368                                     if(display->menuItems[i] != NULL){   2436                                     if(display->menuItems[i] != NULL){
2369                                         // setting the left softkey text   2437                                         // setting the left softkey text
2370                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   2438                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
2371                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   2439                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
2372                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   2440                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
2373                                         }   2441                                         }
2374                                     }   2442                                     }
2375                                 }   2443                                 }
2376                                   2444                                
2377                                 fprintf(pFile, "========================================================\n", count);   2445                                 fprintf(pFile, "========================================================\n", count);
2378                                 fclose(pFile);   2446                                 fclose(pFile);
2379                                 */   2447                                 */
2380     2448  
2381                                 break;   2449                                 break;
2382     2450  
2383                             }   2451                             }
2384                               2452                            
2385                         }   2453                         }
2386     2454  
2387                         break;   2455                         break;
2388     2456  
2389                     default:   2457                     default:
2390                         //MessageBox(0, ugl_menuItem->text, _T("new"), 0);   2458                         //MessageBox(0, ugl_menuItem->text, _T("new"), 0);
2391                         found = FALSE;   2459                         found = FALSE;
2392                         hMenu = (HMENU) SendMessage (ugl_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);   2460                         hMenu = (HMENU) SendMessage (ugl_menu->hwndMB, SHCMBM_GETSUBMENU, 0, ID_SPSOFTKEY1);
2393                           2461                        
2394                         //if removing items in a menu, just remove it.   2462                         //if removing items in a menu, just remove it.
2395                         if (index != 0){   2463                         if (index != 0){
2396                             /*   2464                             /*
2397                             pFile = fopen ("\\myfile.txt","a");   2465                             pFile = fopen ("\\myfile.txt","a");
2398                             fprintf(pFile, "=============== _Dispose_MenuItem 14 ========================\n", count);   2466                             fprintf(pFile, "=============== _Dispose_MenuItem 14 ========================\n", count);
2399                             fclose(pFile);   2467                             fclose(pFile);
2400                             */   2468                             */
2401     2469  
2402                             RemoveMenu (hMenu, ugl_menuItem->index-1, MF_BYPOSITION);   2470                             RemoveMenu (hMenu, ugl_menuItem->index-1, MF_BYPOSITION);
2403                             Display_DecMenuItemIndex(display, ugl_menu->hwndCB, index);   2471                             Display_DecMenuItemIndex(display, ugl_menu->hwndCB, index);
2404     2472  
2405                             /*    2473                             /* 
2406                             pFile = fopen ("\\myfile.txt","a");   2474                             pFile = fopen ("\\myfile.txt","a");
2407                                 fprintf(pFile, "menuItemCount = %d\n", count);   2475                                 fprintf(pFile, "menuItemCount = %d\n", count);
2408                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   2476                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
2409                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   2477                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
2410                                 for(i=0; i<display->menuItemsLength; i++){                        2478                                 for(i=0; i<display->menuItemsLength; i++){                     
2411                                     if(display->menuItems[i] != NULL){   2479                                     if(display->menuItems[i] != NULL){
2412                                         // setting the left softkey text   2480                                         // setting the left softkey text
2413                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   2481                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
2414                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   2482                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
2415                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   2483                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
2416                                         }   2484                                         }
2417                                     }   2485                                     }
2418                                 }   2486                                 }
2419                                   2487                                
2420                                 fprintf(pFile, "========================================================\n", count);   2488                                 fprintf(pFile, "========================================================\n", count);
2421                                 fclose(pFile);   2489                                 fclose(pFile);
2422                                 */   2490                                 */
2423     2491  
2424                                 break;   2492                                 break;
2425     2493  
2426     2494  
2427                         } else { //index == 0, it's the first item   2495                         } else { //index == 0, it's the first item
2428     2496  
2429                             // removing the first item, check if the next item has submenu   2497                             // removing the first item, check if the next item has submenu
2430                             tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 1);   2498                             tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 1);
2431                             /*   2499                             /*
2432                             pFile = fopen ("\\myfile.txt","a");   2500                             pFile = fopen ("\\myfile.txt","a");
2433                             fprintf(pFile, "=============== _Dispose_MenuItem 15 ========================\n", count);   2501                             fprintf(pFile, "=============== _Dispose_MenuItem 15 ========================\n", count);
2434                             fclose(pFile);   2502                             fclose(pFile);
2435                             */   2503                             */
2436     2504  
2437     2505  
2438                             if(tempItem != NULL && tempItem->hasSubMenu){   2506                             if(tempItem != NULL && tempItem->hasSubMenu){
2439                                 for(i = 2; i < display->menuItemsLength; i++){   2507                                 for(i = 2; i < display->menuItemsLength; i++){
2440                                     tempItem2 = Display_FindMenuItem(display, ugl_menu->hwndCB, i);   2508                                     tempItem2 = Display_FindMenuItem(display, ugl_menu->hwndCB, i);
2441                                     if(tempItem2!= NULL && !tempItem2->hasSubMenu){   2509                                     if(tempItem2!= NULL && !tempItem2->hasSubMenu){
2442                                         // move the first item that doesn't have submenu into the first spot   2510                                         // move the first item that doesn't have submenu into the first spot
2443                                         RemoveMenu (hMenu, tempItem2->index-1, MF_BYPOSITION);   2511                                         RemoveMenu (hMenu, tempItem2->index-1, MF_BYPOSITION);
2444                                         Display_DecMenuItemIndex(display, ugl_menu->hwndCB, tempItem2->index);   2512                                         Display_DecMenuItemIndex(display, ugl_menu->hwndCB, tempItem2->index);
2445                                         tempItem2->index = 0;   2513                                         tempItem2->index = 0;
2446                                         info.cbSize = sizeof(TBBUTTONINFO);   2514                                         info.cbSize = sizeof(TBBUTTONINFO);
2447                                         info.dwMask = TBIF_TEXT;   2515                                         info.dwMask = TBIF_TEXT;
2448                                         info.pszText = (LPWSTR) tempItem2->text;   2516                                         info.pszText = (LPWSTR) tempItem2->text;
2449                                         if(!SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){   2517                                         if(!SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){
2450                                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));   2518                                             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));
2451                                         }   2519                                         }
2452                                         found = TRUE;   2520                                         found = TRUE;
2453                                         break;   2521                                         break;
2454                                     }   2522                                     }
2455                                 }   2523                                 }
2456                                 if(!found){   2524                                 if(!found){
2457                                     info.cbSize = sizeof(TBBUTTONINFO);   2525                                     info.cbSize = sizeof(TBBUTTONINFO);
2458                                     info.dwMask = TBIF_TEXT;   2526                                     info.dwMask = TBIF_TEXT;
2459                                     info.pszText = (LPWSTR) _T("");   2527                                     info.pszText = (LPWSTR) _T("");
2460                                     if(!SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){   2528                                     if(!SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){
2461                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));   2529                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));
2462                                     }   2530                                     }
2463                                 }   2531                                 }
2464     2532  
2465                                 /*   2533                                 /*
2466                                 pFile = fopen ("\\myfile.txt","a");   2534                                 pFile = fopen ("\\myfile.txt","a");
2467                                 fprintf(pFile, "menuItemCount = %d\n", count);   2535                                 fprintf(pFile, "menuItemCount = %d\n", count);
2468                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   2536                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
2469                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   2537                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
2470                                 for(i=0; i<display->menuItemsLength; i++){                        2538                                 for(i=0; i<display->menuItemsLength; i++){                     
2471                                     if(display->menuItems[i] != NULL){   2539                                     if(display->menuItems[i] != NULL){
2472                                         // setting the left softkey text   2540                                         // setting the left softkey text
2473                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   2541                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
2474                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   2542                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
2475                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   2543                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
2476                                         }   2544                                         }
2477                                     }   2545                                     }
2478                                 }   2546                                 }
2479                                   2547                                
2480                                 fprintf(pFile, "========================================================\n", count);   2548                                 fprintf(pFile, "========================================================\n", count);
2481                                 fclose(pFile);   2549                                 fclose(pFile);
2482                                 */   2550                                 */
2483     2551  
2484                                 break;   2552                                 break;
2485     2553  
2486     2554  
2487                             } else { //the first menuitem on the right softkey has no submenu   2555                             } else { //the first menuitem on the right softkey has no submenu
2488                                 // else remove text on the left softkey and pop the first menuitem's text onto the left softkey   2556                                 // else remove text on the left softkey and pop the first menuitem's text onto the left softkey
2489                                 /*   2557                                 /*
2490                             pFile = fopen ("\\myfile.txt","a");   2558                             pFile = fopen ("\\myfile.txt","a");
2491                             fprintf(pFile, "=============== _Dispose_MenuItem 16 ========================\n", count);   2559                             fprintf(pFile, "=============== _Dispose_MenuItem 16 ========================\n", count);
2492                             fclose(pFile);   2560                             fclose(pFile);
2493                             */   2561                             */
2494     2562  
2495                                 tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 1);                                2563                                 tempItem = Display_FindMenuItem(display, ugl_menu->hwndCB, 1);                             
2496                                 RemoveMenu (hMenu, 0, MF_BYPOSITION);   2564                                 RemoveMenu (hMenu, 0, MF_BYPOSITION);
2497                                 Display_DecMenuItemIndex(display, ugl_menu->hwndCB, 1);   2565                                 Display_DecMenuItemIndex(display, ugl_menu->hwndCB, 1);
2498                                 tempItem->index = 0;   2566                                 tempItem->index = 0;
2499                                   2567                                
2500                                 if(tempItem != NULL && tempItem->text != NULL){                               2568                                 if(tempItem != NULL && tempItem->text != NULL){                            
2501                                     info.cbSize = sizeof(TBBUTTONINFO);   2569                                     info.cbSize = sizeof(TBBUTTONINFO);
2502                                     info.dwMask = TBIF_TEXT;   2570                                     info.dwMask = TBIF_TEXT;
2503                                     info.pszText = (LPWSTR) tempItem->text;   2571                                     info.pszText = (LPWSTR) tempItem->text;
2504                                     if(!SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){   2572                                     if(!SendMessage (ugl_menu->hwndMB, TB_SETBUTTONINFO, ID_SPSOFTKEY0, (long) &info)){
2505                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));   2573                                         Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to set buttoninfo"));
2506                                     }   2574                                     }
2507                                 }   2575                                 }
2508     2576  
2509     2577  
2510                                 /*   2578                                 /*
2511                                 pFile = fopen ("\\myfile.txt","a");   2579                                 pFile = fopen ("\\myfile.txt","a");
2512                                 fprintf(pFile, "menuItemCount = %d\n", count);   2580                                 fprintf(pFile, "menuItemCount = %d\n", count);
2513                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);   2581                                 fprintf(pFile, "ugl_menuItem->index = %d, id = %d \n", ugl_menuItem->index, ugl_menuItem->id);
2514                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);   2582                                 fprintf(pFile, "ugl_menu->hwndMB = %d, ugl_menu->hwndCB = %d \n", ugl_menu->hwndMB, ugl_menu->hwndCB);
2515                                 for(i=0; i<display->menuItemsLength; i++){                        2583                                 for(i=0; i<display->menuItemsLength; i++){                     
2516                                     if(display->menuItems[i] != NULL){   2584                                     if(display->menuItems[i] != NULL){
2517                                         // setting the left softkey text   2585                                         // setting the left softkey text
2518                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;   2586                                         if (display->menuItems[i]->parent_menu->hwndCB != ugl_menu->hwndCB) continue;
2519                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){   2587                                         if(display->menuItems[i]->parent_menu->hwndCB != 0){
2520                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);   2588                                             fprintf(pFile, "menuItem[%d] index=%d, id=%d\n", i, display->menuItems[i]->index, display->menuItems[i]->id);
2521                                         }   2589                                         }
2522                                     }   2590                                     }
2523                                 }   2591                                 }
2524                                   2592                                
2525                                 fprintf(pFile, "========================================================\n", count);   2593                                 fprintf(pFile, "========================================================\n", count);
2526                                 fclose(pFile);   2594                                 fclose(pFile);
2527                                 */   2595                                 */
2528     2596  
2529                                   2597                                
2530                             }   2598                             }
2531                                 if (display->activeShell == ugl_menu->parent) {   2599                                 if (display->activeShell == ugl_menu->parent) {
2532                                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);   2600                                     ShowWindow(ugl_menu->hwndCB, SW_HIDE);
2533                                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);   2601                                     ShowWindow(ugl_menu->hwndMB, SW_SHOW);
2534                                 }   2602                                 }
2535     2603  
2536                                 break;   2604                                 break;
2537     2605  
2538     2606  
2539                               2607                            
2540                         }   2608                         }
2541                   2609                
2542                     break;   2610                     break;
2543     2611  
2544         }   2612         }
2545                 Display_RemoveMenuItem(ugl_menuItem);   2613                 Display_RemoveMenuItem(ugl_menuItem);
2546                 //_Update_Enabled(display);   2614                 //_Update_Enabled(display);
2547                 free(buffer);   2615                 free(buffer);
2548               2616            
2549             }     2617             }  
2550         } else {   2618         } else {
2551             // not supporting softkey   2619             // not supporting softkey
2552             int pos = SendMessage(hwndCB, TB_COMMANDTOINDEX, id, 0);          2620             int pos = SendMessage(hwndCB, TB_COMMANDTOINDEX, id, 0);       
2553               2621            
2554             if (pos == -1) {   2622             if (pos == -1) {
2555                 Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to find menu item"));   2623                 Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to find menu item"));
2556                 return;   2624                 return;
2557             }   2625             }
2558             if (!SendMessage(hwndCB, TB_DELETEBUTTON, pos, 0)) {   2626             if (!SendMessage(hwndCB, TB_DELETEBUTTON, pos, 0)) {
2559                 Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to delete menu item"));   2627                 Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to delete menu item"));
2560                 return;   2628                 return;
2561             }   2629             }
2562             Display_RemoveMenuItem(ugl_menuItem);   2630             Display_RemoveMenuItem(ugl_menuItem);
2563             (long) imagelist = SendMessage (hwndCB, TB_GETIMAGELIST, 0, 0);   2631             (long) imagelist = SendMessage (hwndCB, TB_GETIMAGELIST, 0, 0);
2564             if (imagelist != NULL) {   2632             if (imagelist != NULL) {
2565                 ImageList_Destroy(imagelist);   2633                 ImageList_Destroy(imagelist);
2566             }   2634             }
2567     2635  
2568         }   2636         }
2569     // if sub menu   2637     // if sub menu
2570     } else {   2638     } else {
2571         _Dispose(ugl_menu, id, uglError);   2639         _Dispose(ugl_menu, id, uglError);
2572     }   2640     }
2573     }   2641     }
2574     2642  
2575 #else   2643 #else
2576     _Dispose(ugl_menu, id, uglError);   2644     _Dispose(ugl_menu, id, uglError);
2577 #endif   2645 #endif
2578     2646  
2579     2647  
2580     /*  old code   2648     /*  old code
2581 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)   2649 #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
2582     {   2650     {
2583     HIMAGELIST imagelist;   2651     HIMAGELIST imagelist;
2584     HWND hwndCB = ugl_menu->hwndCB;   2652     HWND hwndCB = ugl_menu->hwndCB;
2585     2653  
2586     if (hwndCB != 0) {   2654     if (hwndCB != 0) {
2587         int pos = SendMessage(hwndCB, TB_COMMANDTOINDEX, id, 0);          2655         int pos = SendMessage(hwndCB, TB_COMMANDTOINDEX, id, 0);       
2588           2656        
2589         if (pos == -1) {   2657         if (pos == -1) {
2590             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to find menu item"));   2658             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to find menu item"));
2591             return;   2659             return;
2592         }   2660         }
2593         if (!SendMessage(hwndCB, TB_DELETEBUTTON, pos, 0)) {   2661         if (!SendMessage(hwndCB, TB_DELETEBUTTON, pos, 0)) {
2594             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to delete menu item"));   2662             Win32Error_SetError(uglError, UGL_ERROR_OTHER, _T("Unable to delete menu item"));
2595             return;   2663             return;
2596         }   2664         }
2597         Display_RemoveMenuItem(ugl_menuItem);   2665         Display_RemoveMenuItem(ugl_menuItem);
2598         (long) imagelist = SendMessage (hwndCB, TB_GETIMAGELIST, 0, 0);   2666         (long) imagelist = SendMessage (hwndCB, TB_GETIMAGELIST, 0, 0);
2599         if (imagelist != NULL) {   2667         if (imagelist != NULL) {
2600             ImageList_Destroy(imagelist);   2668             ImageList_Destroy(imagelist);
2601         }   2669         }
2602     } else {   2670     } else {
2603         _Dispose(ugl_menu, id, uglError);   2671         _Dispose(ugl_menu, id, uglError);
2604     }   2672     }
2605     }   2673     }
2606 #else   2674 #else
2607     _Dispose(ugl_menu, id, uglError);   2675     _Dispose(ugl_menu, id, uglError);
2608 #endif   2676 #endif
2609     */   2677     */
2610     2678  
2611     2679  
2612 }   2680 }
2613 //========================================================================================   2681 //========================================================================================