comparison os2/dw.c @ 159:9c0f1f04f4c7

Replacement window disable code... looks much nicer.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 14 Nov 2002 11:09:34 +0000
parents a07dd2e819f3
children 76bc6b4e8b79
comparison
equal deleted inserted replaced
158:a4ae65d5b301 159:9c0f1f04f4c7
149 PVOID user; 149 PVOID user;
150 150
151 } CNRITEM, *PCNRITEM; 151 } CNRITEM, *PCNRITEM;
152 152
153 153
154 int _null_key(HWND window, int key, void *data)
155 {
156 return TRUE;
157 }
158
154 /* Find the desktop window handle */ 159 /* Find the desktop window handle */
155 HWND _toplevel_window(HWND handle) 160 HWND _toplevel_window(HWND handle)
156 { 161 {
157 HWND box, lastbox = WinQueryWindow(handle, QW_PARENT); 162 HWND box, lastbox = WinQueryWindow(handle, QW_PARENT);
158 163
263 char tmpbuf[100]; 268 char tmpbuf[100];
264 269
265 if(!handle) 270 if(!handle)
266 return 0; 271 return 0;
267 272
268 if(!WinIsWindowEnabled(handle)) 273 if(!WinIsWindowEnabled(handle) || dw_window_get_data(handle, "_dw_disabled"))
269 return 0; 274 return 0;
270 275
271 WinQueryClassName(handle, 99, tmpbuf); 276 WinQueryClassName(handle, 99, tmpbuf);
272 277
273 /* These are the window classes which can 278 /* These are the window classes which can
1442 { 1447 {
1443 menuitem = dw_menu_append_item(hwndMenu, "Undo", ENTRY_UNDO, 0L, TRUE, FALSE, 0L); 1448 menuitem = dw_menu_append_item(hwndMenu, "Undo", ENTRY_UNDO, 0L, TRUE, FALSE, 0L);
1444 dw_menu_append_item(hwndMenu, "", 0L, 0L, TRUE, FALSE, 0L); 1449 dw_menu_append_item(hwndMenu, "", 0L, 0L, TRUE, FALSE, 0L);
1445 } 1450 }
1446 menuitem = dw_menu_append_item(hwndMenu, "Copy", ENTRY_COPY, 0L, TRUE, FALSE, 0L); 1451 menuitem = dw_menu_append_item(hwndMenu, "Copy", ENTRY_COPY, 0L, TRUE, FALSE, 0L);
1447 if(strncmp(tmpbuf, "#10", 4)!=0 || (strncmp(tmpbuf, "#10", 4)==0 && !WinSendMsg(hWnd, MLM_QUERYREADONLY, 0, 0))) 1452 if((strncmp(tmpbuf, "#10", 4)!=0 && !dw_window_get_data(hWnd, "_dw_disabled")) || (strncmp(tmpbuf, "#10", 4)==0 && !WinSendMsg(hWnd, MLM_QUERYREADONLY, 0, 0)))
1448 { 1453 {
1449 menuitem = dw_menu_append_item(hwndMenu, "Cut", ENTRY_CUT, 0L, TRUE, FALSE, 0L); 1454 menuitem = dw_menu_append_item(hwndMenu, "Cut", ENTRY_CUT, 0L, TRUE, FALSE, 0L);
1450 menuitem = dw_menu_append_item(hwndMenu, "Paste", ENTRY_PASTE, 0L, TRUE, FALSE, 0L); 1455 menuitem = dw_menu_append_item(hwndMenu, "Paste", ENTRY_PASTE, 0L, TRUE, FALSE, 0L);
1451 } 1456 }
1452 dw_menu_append_item(hwndMenu, "", 0L, 0L, TRUE, FALSE, 0L); 1457 dw_menu_append_item(hwndMenu, "", 0L, 0L, TRUE, FALSE, 0L);
1530 break; 1535 break;
1531 case WM_SETFOCUS: 1536 case WM_SETFOCUS:
1532 _run_event(hWnd, msg, mp1, mp2); 1537 _run_event(hWnd, msg, mp1, mp2);
1533 break; 1538 break;
1534 case WM_CHAR: 1539 case WM_CHAR:
1540 if(_run_event(hWnd, msg, mp1, mp2) == TRUE)
1541 return (MRESULT)TRUE;
1535 if(SHORT1FROMMP(mp2) == '\t') 1542 if(SHORT1FROMMP(mp2) == '\t')
1536 { 1543 {
1537 if(CHARMSG(&msg)->fs & KC_SHIFT) 1544 if(CHARMSG(&msg)->fs & KC_SHIFT)
1538 _shift_focus_back(hWnd); 1545 _shift_focus_back(hWnd);
1539 else 1546 else
1582 return _entryproc(hWnd, msg, mp1, mp2); 1589 return _entryproc(hWnd, msg, mp1, mp2);
1583 case WM_SETFOCUS: 1590 case WM_SETFOCUS:
1584 _run_event(hWnd, msg, mp1, mp2); 1591 _run_event(hWnd, msg, mp1, mp2);
1585 break; 1592 break;
1586 case WM_CHAR: 1593 case WM_CHAR:
1594 if(_run_event(hWnd, msg, mp1, mp2) == TRUE)
1595 return (MRESULT)TRUE;
1587 /* A Similar problem to the MLE, if ESC just return */ 1596 /* A Similar problem to the MLE, if ESC just return */
1588 if(SHORT1FROMMP(mp2) == 283) 1597 if(SHORT1FROMMP(mp2) == 283)
1589 return (MRESULT)TRUE; 1598 return (MRESULT)TRUE;
1590 break; 1599 break;
1591 } 1600 }
2612 if(mp2) 2621 if(mp2)
2613 _run_event(hwnd, msg, mp1, mp2); 2622 _run_event(hwnd, msg, mp1, mp2);
2614 else 2623 else
2615 WinSendMsg(hwnd, BM_SETDEFAULT, 0, 0); 2624 WinSendMsg(hwnd, BM_SETDEFAULT, 0, 0);
2616 break; 2625 break;
2626 case WM_BUTTON1DOWN:
2627 case WM_BUTTON2DOWN:
2628 case WM_BUTTON3DOWN:
2629 case WM_BUTTON1DBLCLK:
2630 case WM_BUTTON2DBLCLK:
2631 case WM_BUTTON3DBLCLK:
2632 if(dw_window_get_data(hwnd, "_dw_disabled"))
2633 return (MRESULT)FALSE;
2634 break;
2617 case WM_BUTTON1UP: 2635 case WM_BUTTON1UP:
2618 { 2636 {
2619 SignalHandler *tmp = Root; 2637 SignalHandler *tmp = Root;
2620 2638
2621 if(WinIsWindowEnabled(hwnd)) 2639 if(WinIsWindowEnabled(hwnd) && !dw_window_get_data(hwnd, "_dw_disabled"))
2622 { 2640 {
2623 /* Find any callbacks for this function */ 2641 /* Find any callbacks for this function */
2624 while(tmp) 2642 while(tmp)
2625 { 2643 {
2626 if(tmp->message == WM_COMMAND) 2644 if(tmp->message == WM_COMMAND)
3246 int dw_window_set_font(HWND handle, char *fontname) 3264 int dw_window_set_font(HWND handle, char *fontname)
3247 { 3265 {
3248 return WinSetPresParam(handle, PP_FONTNAMESIZE, strlen(fontname)+1, fontname); 3266 return WinSetPresParam(handle, PP_FONTNAMESIZE, strlen(fontname)+1, fontname);
3249 } 3267 }
3250 3268
3251 /* 3269 /* Internal version */
3252 * Sets the colors used by a specified window (widget) handle. 3270 int _dw_window_set_color(HWND handle, ULONG fore, ULONG back)
3253 * Parameters:
3254 * handle: The window (widget) handle.
3255 * fore: Foreground color in DW_RGB format or a default color index.
3256 * back: Background color in DW_RGB format or a default color index.
3257 */
3258 int dw_window_set_color(HWND handle, ULONG fore, ULONG back)
3259 { 3271 {
3260 if((fore & DW_RGB_COLOR) == DW_RGB_COLOR) 3272 if((fore & DW_RGB_COLOR) == DW_RGB_COLOR)
3261 { 3273 {
3262 RGB2 rgb2; 3274 RGB2 rgb2;
3263 3275
3298 back = CLR_WHITE; 3310 back = CLR_WHITE;
3299 3311
3300 WinSetPresParam(handle, PP_BACKGROUNDCOLORINDEX, sizeof(ULONG), &back); 3312 WinSetPresParam(handle, PP_BACKGROUNDCOLORINDEX, sizeof(ULONG), &back);
3301 } 3313 }
3302 return 0; 3314 return 0;
3315 }
3316 /*
3317 * Sets the colors used by a specified window (widget) handle.
3318 * Parameters:
3319 * handle: The window (widget) handle.
3320 * fore: Foreground color in DW_RGB format or a default color index.
3321 * back: Background color in DW_RGB format or a default color index.
3322 */
3323 int dw_window_set_color(HWND handle, ULONG fore, ULONG back)
3324 {
3325 dw_window_set_data(handle, "_dw_fore", (void *)fore);
3326 dw_window_set_data(handle, "_dw_back", (void *)back);
3327
3328 return _dw_window_set_color(handle, fore, back);
3303 } 3329 }
3304 3330
3305 /* 3331 /*
3306 * Sets the font used by a specified window (widget) handle. 3332 * Sets the font used by a specified window (widget) handle.
3307 * Parameters: 3333 * Parameters:
3903 NULL, 3929 NULL,
3904 NULL); 3930 NULL);
3905 dw_window_set_font(tmp, DefaultFont); 3931 dw_window_set_font(tmp, DefaultFont);
3906 blah->oldproc = WinSubclassWindow(tmp, _entryproc); 3932 blah->oldproc = WinSubclassWindow(tmp, _entryproc);
3907 WinSetWindowPtr(tmp, QWP_USER, blah); 3933 WinSetWindowPtr(tmp, QWP_USER, blah);
3934 dw_window_set_color(tmp, DW_CLR_BLACK, DW_CLR_WHITE);
3908 return tmp; 3935 return tmp;
3909 } 3936 }
3910 3937
3911 /* 3938 /*
3912 * Create a new Entryfield (password) window (widget) to be packed. 3939 * Create a new Entryfield (password) window (widget) to be packed.
3929 NULL, 3956 NULL,
3930 NULL); 3957 NULL);
3931 dw_window_set_font(tmp, DefaultFont); 3958 dw_window_set_font(tmp, DefaultFont);
3932 blah->oldproc = WinSubclassWindow(tmp, _entryproc); 3959 blah->oldproc = WinSubclassWindow(tmp, _entryproc);
3933 WinSetWindowPtr(tmp, QWP_USER, blah); 3960 WinSetWindowPtr(tmp, QWP_USER, blah);
3961 dw_window_set_color(tmp, DW_CLR_BLACK, DW_CLR_WHITE);
3934 return tmp; 3962 return tmp;
3935 } 3963 }
3936 3964
3937 /* 3965 /*
3938 * Create a new Combobox window (widget) to be packed. 3966 * Create a new Combobox window (widget) to be packed.
3958 3986
3959 while((child = WinGetNextWindow(henum)) != NULLHANDLE) 3987 while((child = WinGetNextWindow(henum)) != NULLHANDLE)
3960 { 3988 {
3961 WindowData *moreblah = calloc(1, sizeof(WindowData)); 3989 WindowData *moreblah = calloc(1, sizeof(WindowData));
3962 moreblah->oldproc = WinSubclassWindow(child, _comboentryproc); 3990 moreblah->oldproc = WinSubclassWindow(child, _comboentryproc);
3991 dw_window_set_color(child, DW_CLR_BLACK, DW_CLR_WHITE);
3963 WinSetWindowPtr(child, QWP_USER, moreblah); 3992 WinSetWindowPtr(child, QWP_USER, moreblah);
3964 } 3993 }
3965 WinEndEnumWindows(henum); 3994 WinEndEnumWindows(henum);
3966 dw_window_set_font(tmp, DefaultFont); 3995 dw_window_set_font(tmp, DefaultFont);
3967 dw_window_set_color(tmp, DW_CLR_BLACK, DW_CLR_WHITE);
3968 blah->oldproc = WinSubclassWindow(tmp, _comboproc); 3996 blah->oldproc = WinSubclassWindow(tmp, _comboproc);
3969 WinSetWindowPtr(tmp, QWP_USER, blah); 3997 WinSetWindowPtr(tmp, QWP_USER, blah);
3998 dw_window_set_color(tmp, DW_CLR_BLACK, DW_CLR_WHITE);
3970 return tmp; 3999 return tmp;
3971 } 4000 }
3972 4001
3973 /* 4002 /*
3974 * Create a new button window (widget) to be packed. 4003 * Create a new button window (widget) to be packed.
3995 bubble->bubbletext[0] = '\0'; 4024 bubble->bubbletext[0] = '\0';
3996 bubble->pOldProc = WinSubclassWindow(tmp, _BtProc); 4025 bubble->pOldProc = WinSubclassWindow(tmp, _BtProc);
3997 4026
3998 WinSetWindowPtr(tmp, QWP_USER, bubble); 4027 WinSetWindowPtr(tmp, QWP_USER, bubble);
3999 dw_window_set_font(tmp, DefaultFont); 4028 dw_window_set_font(tmp, DefaultFont);
4029 dw_window_set_color(tmp, DW_CLR_BLACK, DW_CLR_PALEGRAY);
4000 return tmp; 4030 return tmp;
4001 } 4031 }
4002 4032
4003 /* Function: GenResIDStr 4033 /* Function: GenResIDStr
4004 ** Abstract: Generate string '#nnnn' for a given ID for using with Button 4034 ** Abstract: Generate string '#nnnn' for a given ID for using with Button
4093 blah->oldproc = WinSubclassWindow(tmp, _entryproc); 4123 blah->oldproc = WinSubclassWindow(tmp, _entryproc);
4094 WinSetWindowPtr(tmp, QWP_USER, blah); 4124 WinSetWindowPtr(tmp, QWP_USER, blah);
4095 blah = calloc(sizeof(WindowData), 1); 4125 blah = calloc(sizeof(WindowData), 1);
4096 blah->oldproc = WinSubclassWindow(entry, _spinentryproc); 4126 blah->oldproc = WinSubclassWindow(entry, _spinentryproc);
4097 WinSetWindowPtr(entry, QWP_USER, blah); 4127 WinSetWindowPtr(entry, QWP_USER, blah);
4128 dw_window_set_color(entry, DW_CLR_BLACK, DW_CLR_WHITE);
4098 return tmp; 4129 return tmp;
4099 } 4130 }
4100 4131
4101 /* 4132 /*
4102 * Create a new radiobutton window (widget) to be packed. 4133 * Create a new radiobutton window (widget) to be packed.
4227 HWND_TOP, 4258 HWND_TOP,
4228 id, 4259 id,
4229 NULL, 4260 NULL,
4230 NULL); 4261 NULL);
4231 dw_window_set_font(tmp, DefaultFont); 4262 dw_window_set_font(tmp, DefaultFont);
4263 dw_window_set_color(tmp, DW_CLR_BLACK, DW_CLR_WHITE);
4232 blah->oldproc = WinSubclassWindow(tmp, _entryproc); 4264 blah->oldproc = WinSubclassWindow(tmp, _entryproc);
4233 WinSetWindowPtr(tmp, QWP_USER, blah); 4265 WinSetWindowPtr(tmp, QWP_USER, blah);
4234 return tmp; 4266 return tmp;
4235 } 4267 }
4236 4268
4299 * Parameters: 4331 * Parameters:
4300 * handle: Handle to the window. 4332 * handle: Handle to the window.
4301 */ 4333 */
4302 void dw_window_disable(HWND handle) 4334 void dw_window_disable(HWND handle)
4303 { 4335 {
4336 char tmpbuf[100];
4337
4338 WinQueryClassName(handle, 99, tmpbuf);
4339
4340 if(tmpbuf[0] == '#')
4341 {
4342 int val = atoi(&tmpbuf[1]);
4343 HWND hwnd;
4344
4345 switch(val)
4346 {
4347 case 2:
4348 case 6:
4349 case 10:
4350 case 32:
4351 case 7:
4352 hwnd = _find_entryfield(handle);
4353 _dw_window_set_color(hwnd ? hwnd : handle, DW_CLR_BLACK, DW_CLR_PALEGRAY);
4354 dw_signal_connect(hwnd ? hwnd : handle, "key_press_event", DW_SIGNAL_FUNC(_null_key), (void *)100);
4355 dw_window_set_data(handle, "_dw_disabled", (void *)1);
4356 if(hwnd)
4357 dw_window_set_data(hwnd, "_dw_disabled", (void *)1);
4358 return;
4359 case 3:
4360 _dw_window_set_color(handle, DW_CLR_DARKGRAY, DW_CLR_PALEGRAY);
4361 dw_signal_connect(handle, "key_press_event", DW_SIGNAL_FUNC(_null_key), (void *)100);
4362 dw_signal_connect(handle, "button_press_event", DW_SIGNAL_FUNC(_null_key), (void *)100);
4363 dw_window_set_data(handle, "_dw_disabled", (void *)1);
4364 return;
4365 }
4366 }
4304 WinEnableWindow(handle, FALSE); 4367 WinEnableWindow(handle, FALSE);
4305 } 4368 }
4306 4369
4307 /* 4370 /*
4308 * Enables given window (widget). 4371 * Enables given window (widget).
4309 * Parameters: 4372 * Parameters:
4310 * handle: Handle to the window. 4373 * handle: Handle to the window.
4311 */ 4374 */
4312 void dw_window_enable(HWND handle) 4375 void dw_window_enable(HWND handle)
4313 { 4376 {
4377 ULONG fore = (ULONG)dw_window_get_data(handle, "_dw_fore");
4378 ULONG back = (ULONG)dw_window_get_data(handle, "_dw_back");
4379 HWND hwnd = _find_entryfield(handle);
4380
4381 dw_window_set_data(handle, "_dw_disabled", 0);
4382 if(hwnd)
4383 dw_window_set_data(hwnd, "_dw_disabled", 0);
4384 if(fore && back)
4385 _dw_window_set_color(hwnd ? hwnd : handle, fore, back);
4386 dw_signal_disconnect_by_data(handle, (void *)100);
4314 WinEnableWindow(handle, TRUE); 4387 WinEnableWindow(handle, TRUE);
4315 } 4388 }
4316 4389
4317 /* 4390 /*
4318 * Gets the child window handle with specified ID. 4391 * Gets the child window handle with specified ID.
6490 * handle: Module handle returned by dw_module_load() 6563 * handle: Module handle returned by dw_module_load()
6491 */ 6564 */
6492 int dw_module_close(HMOD handle) 6565 int dw_module_close(HMOD handle)
6493 { 6566 {
6494 DosFreeModule(handle); 6567 DosFreeModule(handle);
6568 return 0;
6495 } 6569 }
6496 6570
6497 /* 6571 /*
6498 * Returns the handle to an unnamed mutex semaphore. 6572 * Returns the handle to an unnamed mutex semaphore.
6499 */ 6573 */
7173 7247
7174 /* Functions for managing the user data lists that are associated with 7248 /* Functions for managing the user data lists that are associated with
7175 * a given window handle. Used in dw_window_set_data() and 7249 * a given window handle. Used in dw_window_set_data() and
7176 * dw_window_get_data(). 7250 * dw_window_get_data().
7177 */ 7251 */
7178 UserData *find_userdata(UserData **root, char *varname) 7252 UserData *_find_userdata(UserData **root, char *varname)
7179 { 7253 {
7180 UserData *tmp = *root; 7254 UserData *tmp = *root;
7181 7255
7182 while(tmp) 7256 while(tmp)
7183 { 7257 {
7186 tmp = tmp->next; 7260 tmp = tmp->next;
7187 } 7261 }
7188 return NULL; 7262 return NULL;
7189 } 7263 }
7190 7264
7191 int new_userdata(UserData **root, char *varname, void *data) 7265 int _new_userdata(UserData **root, char *varname, void *data)
7192 { 7266 {
7193 UserData *new = find_userdata(root, varname); 7267 UserData *new = _find_userdata(root, varname);
7194 7268
7195 if(new) 7269 if(new)
7196 { 7270 {
7197 new->data = data; 7271 new->data = data;
7198 return TRUE; 7272 return TRUE;
7226 } 7300 }
7227 } 7301 }
7228 return FALSE; 7302 return FALSE;
7229 } 7303 }
7230 7304
7231 int remove_userdata(UserData **root, char *varname, int all) 7305 int _remove_userdata(UserData **root, char *varname, int all)
7232 { 7306 {
7233 UserData *prev = NULL, *tmp = *root; 7307 UserData *prev = NULL, *tmp = *root;
7234 7308
7235 while(tmp) 7309 while(tmp)
7236 { 7310 {
7273 blah = calloc(1, sizeof(WindowData)); 7347 blah = calloc(1, sizeof(WindowData));
7274 WinSetWindowPtr(window, QWP_USER, blah); 7348 WinSetWindowPtr(window, QWP_USER, blah);
7275 } 7349 }
7276 7350
7277 if(data) 7351 if(data)
7278 new_userdata(&(blah->root), dataname, data); 7352 _new_userdata(&(blah->root), dataname, data);
7279 else 7353 else
7280 { 7354 {
7281 if(dataname) 7355 if(dataname)
7282 remove_userdata(&(blah->root), dataname, FALSE); 7356 _remove_userdata(&(blah->root), dataname, FALSE);
7283 else 7357 else
7284 remove_userdata(&(blah->root), NULL, TRUE); 7358 _remove_userdata(&(blah->root), NULL, TRUE);
7285 } 7359 }
7286 } 7360 }
7287 7361
7288 /* 7362 /*
7289 * Gets a named user data item to a window handle. 7363 * Gets a named user data item to a window handle.
7296 { 7370 {
7297 WindowData *blah = (WindowData *)WinQueryWindowPtr(window, QWP_USER); 7371 WindowData *blah = (WindowData *)WinQueryWindowPtr(window, QWP_USER);
7298 7372
7299 if(blah && blah->root && dataname) 7373 if(blah && blah->root && dataname)
7300 { 7374 {
7301 UserData *ud = find_userdata(&(blah->root), dataname); 7375 UserData *ud = _find_userdata(&(blah->root), dataname);
7302 if(ud) 7376 if(ud)
7303 return ud->data; 7377 return ud->data;
7304 } 7378 }
7305 return NULL; 7379 return NULL;
7306 } 7380 }