Mercurial > dwindows
changeset 34:b03b24bb95f8
Added dw_window_default() to set the default focus widget in a dialog.
Also some fixes for containers on OS/2.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 03 Sep 2001 23:30:43 +0000 |
parents | 72675de7d229 |
children | 432c39a4ff86 |
files | dw.def dw.h dww.def gtk/dw.c os2/dw.c win/dw.c |
diffstat | 6 files changed, 202 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/dw.def Thu Aug 30 06:07:19 2001 +0000 +++ b/dw.def Mon Sep 03 23:30:43 2001 +0000 @@ -55,6 +55,7 @@ dw_window_set_border @72 dw_window_minimize @73 dw_window_pointer @74 + dw_window_default @75 dw_bitmap_new @80
--- a/dw.h Thu Aug 30 06:07:19 2001 +0000 +++ b/dw.h Mon Sep 03 23:30:43 2001 +0000 @@ -322,7 +322,9 @@ /* Padding */ int pad, parentpad; /* Groupbox */ - HWND grouphwnd; + HWND grouphwnd; + /* Default item */ + HWND defaultitem; /* Used as temporary storage in the calculation stage */ int upx, upy, minheight, minwidth; /* Ratio in this box */ @@ -629,6 +631,7 @@ void dw_window_release(void); void dw_window_reparent(HWND handle, HWND newparent); void dw_window_pointer(HWND handle, int pointertype); +void dw_window_default(HWND window, HWND defaultitem); unsigned int dw_mle_import(HWND handle, char *buffer, int startpoint); void dw_mle_export(HWND handle, char *buffer, int startpoint, int length); void dw_mle_query(HWND handle, unsigned long *bytes, unsigned long *lines);
--- a/dww.def Thu Aug 30 06:07:19 2001 +0000 +++ b/dww.def Mon Sep 03 23:30:43 2001 +0000 @@ -52,6 +52,7 @@ dw_window_set_border @72 dw_window_minimize @73 dw_window_pointer @74 + dw_window_default @75 dw_bitmap_new @80
--- a/gtk/dw.c Thu Aug 30 06:07:19 2001 +0000 +++ b/gtk/dw.c Mon Sep 03 23:30:43 2001 +0000 @@ -723,6 +723,7 @@ int dw_window_show(HWND handle) { int _locked_by_me = FALSE; + GtkWidget *defaultitem; if(!handle) return 0; @@ -733,6 +734,9 @@ gdk_flush(); gdk_window_show(GTK_WIDGET(handle)->window); gdk_flush(); + defaultitem = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "defaultitem"); + if(defaultitem) + gtk_widget_grab_focus(defaultitem); DW_MUTEX_UNLOCK; return 0; } @@ -4413,6 +4417,24 @@ } /* + * Sets the default focus item for a window/dialog. + * Parameters: + * window: Toplevel window or dialog. + * defaultitem: Handle to the dialog item to be default. + */ +void dw_window_default(HWND window, HWND defaultitem) +{ + int _locked_by_me = FALSE; + + if(!window) + return; + + DW_MUTEX_LOCK; + gtk_object_set_data(GTK_OBJECT(window), "defaultitem", (gpointer)defaultitem); + DW_MUTEX_UNLOCK; +} + +/* * Returns some information about the current operating environment. * Parameters: * env: Pointer to a DWEnv struct.
--- a/os2/dw.c Thu Aug 30 06:07:19 2001 +0000 +++ b/os2/dw.c Mon Sep 03 23:30:43 2001 +0000 @@ -150,6 +150,32 @@ } #endif +/* This function changes the owner of buttons in to the + * dynamicwindows handle to fix a problem in notebooks. + */ +void _fix_button_owner(HWND handle, HWND dw) +{ + HENUM henum; + HWND child; + + henum = WinBeginEnumWindows(handle); + while((child = WinGetNextWindow(henum)) != NULLHANDLE) + { + char tmpbuf[100]; + + WinQueryClassName(child, 99, tmpbuf); + + if(strncmp(tmpbuf, "#3", 3)==0 && dw) /* Button */ + WinSetOwner(child, dw); + else if(strncmp(tmpbuf, "dynamicwindows", 14) == 0) + dw = child; + + _fix_button_owner(child, dw); + } + WinEndEnumWindows(henum); + return; +} + /* This function removes and handlers on windows and frees * the user memory allocated to it. */ @@ -194,10 +220,10 @@ /* These are the window classes which can * obtain input focus. */ - if(strncmp(tmpbuf, "#2", 2)==0 || /* Entryfield */ - strncmp(tmpbuf, "#3", 2)==0 || /* Button */ - strncmp(tmpbuf, "#6", 2)==0 || /* Combobox */ - strncmp(tmpbuf, "#7", 2)==0 || /* List box */ + if(strncmp(tmpbuf, "#2", 3)==0 || /* Entryfield */ + strncmp(tmpbuf, "#3", 3)==0 || /* Button */ + strncmp(tmpbuf, "#6", 3)==0 || /* Combobox */ + strncmp(tmpbuf, "#7", 3)==0 || /* List box */ strncmp(tmpbuf, "#10", 3)==0 || /* MLE */ strncmp(tmpbuf, "#32", 3)==0 || /* Spinbutton */ strncmp(tmpbuf, "#37", 3)== 0) /* Container */ @@ -205,7 +231,7 @@ return 0; } -int _focus_check_box(Box *box, HWND handle, int start) +int _focus_check_box(Box *box, HWND handle, int start, HWND defaultitem) { int z; static HWND lasthwnd, firsthwnd; @@ -242,7 +268,7 @@ { Box *thisbox = WinQueryWindowPtr(box->items[z].hwnd, QWP_USER); - if(thisbox && _focus_check_box(thisbox, handle, start == 3 ? 3 : 0)) + if(thisbox && _focus_check_box(thisbox, handle, start == 3 ? 3 : 0, defaultitem)) return 1; } else @@ -269,8 +295,11 @@ */ if(start == 3) { - WinSetFocus(HWND_DESKTOP, box->items[z].hwnd); - return 1; + if(!defaultitem || (defaultitem && defaultitem == box->items[z].hwnd)) + { + WinSetFocus(HWND_DESKTOP, box->items[z].hwnd); + return 1; + } } if(!firsthwnd) @@ -293,7 +322,7 @@ { notebox = (Box *)WinQueryWindowPtr(page, QWP_USER); - if(notebox && _focus_check_box(notebox, handle, start == 3 ? 3 : 0)) + if(notebox && _focus_check_box(notebox, handle, start == 3 ? 3 : 0, defaultitem)) return 1; } } @@ -309,7 +338,7 @@ { Box *thisbox = WinQueryWindowPtr(box->items[z].hwnd, QWP_USER); - if(thisbox && _focus_check_box(thisbox, handle, start == 3 ? 3 : 0)) + if(thisbox && _focus_check_box(thisbox, handle, start == 3 ? 3 : 0, defaultitem)) return 1; } else @@ -336,8 +365,11 @@ */ if(start == 3) { - WinSetFocus(HWND_DESKTOP, box->items[z].hwnd); - return 1; + if(!defaultitem || (defaultitem && defaultitem == box->items[z].hwnd)) + { + WinSetFocus(HWND_DESKTOP, box->items[z].hwnd); + return 1; + } } if(!firsthwnd) @@ -360,7 +392,7 @@ { notebox = (Box *)WinQueryWindowPtr(page, QWP_USER); - if(notebox && _focus_check_box(notebox, handle, start == 3 ? 3 : 0)) + if(notebox && _focus_check_box(notebox, handle, start == 3 ? 3 : 0, defaultitem)) return 1; } } @@ -385,7 +417,7 @@ if(thisbox) { - _focus_check_box(thisbox, handle, 3); + _focus_check_box(thisbox, handle, 3, thisbox->defaultitem); } } @@ -411,8 +443,8 @@ if(thisbox) { - if(_focus_check_box(thisbox, handle, 1) == 0) - _focus_check_box(thisbox, handle, 2); + if(_focus_check_box(thisbox, handle, 1, 0) == 0) + _focus_check_box(thisbox, handle, 2, 0); } } @@ -869,13 +901,13 @@ WinQueryClassName(handle, 99, tmpbuf); - if(strncmp(tmpbuf, "#2", 2)==0) + if(strncmp(tmpbuf, "#2", 3)==0) { /* Make the combobox big enough to drop down. :) */ WinSetWindowPos(handle, HWND_TOP, currentx + pad, (currenty + pad) - 100, width + vectorx, (height + vectory) + 100, SWP_MOVE | SWP_SIZE | SWP_ZORDER); } - else if(strncmp(tmpbuf, "#6", 2)==0) + else if(strncmp(tmpbuf, "#6", 3)==0) { /* Entryfields on OS/2 have a thick border that isn't on Windows and GTK */ WinSetWindowPos(handle, HWND_TOP, (currentx + pad) + 3, (currenty + pad) + 3, @@ -915,7 +947,8 @@ void _do_resize(Box *thisbox, int x, int y) { - if(x != 0 && y != 0) { + if(x != 0 && y != 0) + { if(thisbox) { int usedx = 0, usedy = 0, usedpadx = 0, usedpady = 0, depth = 0; @@ -1524,7 +1557,7 @@ WinQueryClassName(tmp->window, 99, classbuf); - if(id && strncmp(classbuf, "#2", 2)==0) + if(id && strncmp(classbuf, "#2", 3)==0) { char *buf2; @@ -1685,6 +1718,12 @@ if(mybox && (swp->fl & SWP_MAXIMIZE)) { int z; + SWP swp2; + + WinQueryWindowPos(swp->hwnd, &swp2); + + if(swp2.cx == swp->cx && swp2.cy == swp->cy) + return FALSE; mybox->flags = 0; @@ -2507,6 +2546,7 @@ HSWITCH hswitch; SWCNTRL swcntrl; + _fix_button_owner(handle, 0); WinSetFocus(HWND_DESKTOP, handle); _initial_focus(handle); @@ -3596,7 +3636,7 @@ WinQueryClassName(child, 99, tmpbuf); /* If the child is a box (frame) then recurse into it */ - if(strncmp(tmpbuf, "#1", 2)==0) + if(strncmp(tmpbuf, "#1", 3)==0) if((found = dw_window_from_id(child, id)) != NULLHANDLE) return found; @@ -3680,7 +3720,7 @@ WinQueryClassName(item, 99, tmpbuf); - if(strncmp(tmpbuf, "#1", 2)==0) + if(strncmp(tmpbuf, "#1", 3)==0) tmpitem[thisbox->count].type = TYPEBOX; else tmpitem[thisbox->count].type = TYPEITEM; @@ -3708,7 +3748,7 @@ /* Don't set the ownership if it's an entryfield or combobox */ WinQueryClassName(item, 99, tmpbuf); - if(strncmp(tmpbuf, "#6", 2)!=0 /*&& strncmp(tmpbuf, "#2", 2)!=0*/) + if(strncmp(tmpbuf, "#6", 3)!=0 /*&& strncmp(tmpbuf, "#2", 2)!=0*/) { if((boxowner = WinQueryWindow(box, QW_OWNER)) != 0) WinSetOwner(item, boxowner); @@ -4034,8 +4074,15 @@ */ void dw_listbox_select(HWND handle, int index, int state) { + char tmpbuf[100]; + WinSendMsg(handle, LM_SELECTITEM, MPFROMSHORT(index), (MPARAM)state); - _run_event(handle, WM_CONTROL, MPFROM2SHORT(0, LN_SELECT), (MPARAM)handle); + + WinQueryClassName(handle, 99, tmpbuf); + + /* If we are setting a combobox call the event handler manually */ + if(strncmp(tmpbuf, "#6", 3)==0) + _run_event(handle, WM_CONTROL, MPFROM2SHORT(0, LN_SELECT), (MPARAM)handle); } /* @@ -4627,9 +4674,9 @@ int z, size = 0, totalsize, count = 0; PRECORDCORE temp; ContainerInfo *ci; - void *blah; - - if(!flags) + void *blah = NULL; + + if(!flags || rowcount < 1) return NULL; while(flags[count]) @@ -4652,7 +4699,15 @@ totalsize = size + sizeof(RECORDCORE); - blah = (void *)WinSendMsg(handle, CM_ALLOCRECORD, MPFROMLONG(size), MPFROMLONG(rowcount)); + z = 0; + + while((blah = (void *)WinSendMsg(handle, CM_ALLOCRECORD, MPFROMLONG(size), MPFROMLONG(rowcount))) == NULL) + { + z++; + if(z > 5000000) + break; + DosSleep(1); + } if(!blah) return NULL; @@ -4787,13 +4842,15 @@ void dw_container_set_row_title(void *pointer, int row, char *title) { ContainerInfo *ci = (ContainerInfo *)pointer; - PRECORDCORE temp = (PRECORDCORE)ci->data; + PRECORDCORE temp; int z, currentcount; CNRINFO cnr; if(!ci) return; + temp = (PRECORDCORE)ci->data; + WinSendMsg(ci->handle, CM_QUERYCNRINFO, (MPARAM)&cnr, MPFROMSHORT(sizeof(CNRINFO))); currentcount = cnr.cRecords; @@ -4816,6 +4873,7 @@ { RECORDINSERT recin; ContainerInfo *ci = (ContainerInfo *)pointer; + int z; if(!ci) return; @@ -4827,7 +4885,15 @@ recin.fInvalidateRecord = TRUE; recin.cRecordsInsert = rowcount; - WinSendMsg(handle, CM_INSERTRECORD, MPFROMP(ci->data), MPFROMP(&recin)); + z = 0; + + while(WinSendMsg(handle, CM_INSERTRECORD, MPFROMP(ci->data), MPFROMP(&recin)) == 0) + { + z++; + if(z > 5000000) + break; + DosSleep(1); + } } /* @@ -4837,7 +4903,15 @@ */ void dw_container_clear(HWND handle) { - WinSendMsg(handle, CM_REMOVERECORD, (MPARAM)0L, MPFROM2SHORT(0, CMA_INVALIDATE | CMA_FREE)); + int z = 0; + + while((int)WinSendMsg(handle, CM_REMOVERECORD, (MPARAM)0L, MPFROM2SHORT(0, CMA_INVALIDATE | CMA_FREE)) == -1) + { + z++; + if(z > 5000000) + break; + DosSleep(1); + } } /* @@ -4849,7 +4923,7 @@ void dw_container_delete(HWND handle, int rowcount) { RECORDCORE *last, **prc = malloc(sizeof(RECORDCORE *) * rowcount); - int current = 1; + int current = 1, z; prc[0] = last = (RECORDCORE *)WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)0L, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER)); @@ -4858,7 +4932,17 @@ prc[current] = last = (RECORDCORE *)WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)last, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); current++; } - WinSendMsg(handle, CM_REMOVERECORD, (MPARAM)prc, MPFROM2SHORT(current, CMA_INVALIDATE | CMA_FREE)); + + z = 0; + + while((int)WinSendMsg(handle, CM_REMOVERECORD, (MPARAM)prc, MPFROM2SHORT(current, CMA_INVALIDATE | CMA_FREE)) == -1) + { + z++; + if(z > 5000000) + break; + DosSleep(1); + } + free(prc); } @@ -5736,7 +5820,7 @@ WinQueryClassName(item, 99, tmpbuf); - if(strncmp(tmpbuf, "#1", 2)==0) + if(strncmp(tmpbuf, "#1", 3)==0) tmpitem[0].type = TYPEBOX; else tmpitem[0].type = TYPEITEM; @@ -5764,7 +5848,7 @@ WinQueryClassName(item, 99, tmpbuf); /* Don't set the ownership if it's an entryfield or combobox */ - if(strncmp(tmpbuf, "#6", 2)!=0 /*&& strncmp(tmpbuf, "#2", 2)!=0*/) + if(strncmp(tmpbuf, "#6", 3)!=0 /*&& strncmp(tmpbuf, "#2", 2)!=0*/) { if((boxowner = WinQueryWindow(box, QW_OWNER)) != 0) WinSetOwner(item, boxowner); @@ -5858,6 +5942,24 @@ return (ulBuild); } +/* + * Sets the default focus item for a window/dialog. + * Parameters: + * window: Toplevel window or dialog. + * defaultitem: Handle to the dialog item to be default. + */ +void dw_window_default(HWND window, HWND defaultitem) +{ + Box *thisbox = NULL; + HWND box; + + box = WinWindowFromID(window, FID_CLIENT); + if(box) + thisbox = WinQueryWindowPtr(box, QWP_USER); + + if(thisbox) + thisbox->defaultitem = defaultitem; +} /* * Returns some information about the current operating environment.
--- a/win/dw.c Thu Aug 30 06:07:19 2001 +0000 +++ b/win/dw.c Mon Sep 03 23:30:43 2001 +0000 @@ -322,7 +322,7 @@ return handle; } -int _focus_check_box(Box *box, HWND handle, int start) +int _focus_check_box(Box *box, HWND handle, int start, HWND defaultitem) { int z; static HWND lasthwnd, firsthwnd; @@ -356,7 +356,7 @@ { Box *thisbox = (Box *)GetWindowLong(box->items[z].hwnd, GWL_USERDATA); - if(thisbox && _focus_check_box(thisbox, handle, start == 3 ? 3 : 0)) + if(thisbox && _focus_check_box(thisbox, handle, start == 3 ? 3 : 0, defaultitem)) return 1; } else @@ -383,8 +383,11 @@ */ if(start == 3) { - SetFocus(_normalize_handle(box->items[z].hwnd)); - return 1; + if(!defaultitem || (defaultitem && box->items[z].hwnd == defaultitem)) + { + SetFocus(_normalize_handle(box->items[z].hwnd)); + return 1; + } } if(!firsthwnd) @@ -411,7 +414,7 @@ { notebox = (Box *)GetWindowLong(array[pageid]->hwnd, GWL_USERDATA); - if(notebox && _focus_check_box(notebox, handle, start == 3 ? 3 : 0)) + if(notebox && _focus_check_box(notebox, handle, start == 3 ? 3 : 0, defaultitem)) return 1; } } @@ -434,7 +437,7 @@ if(thisbox) { - _focus_check_box(thisbox, handle, 3); + _focus_check_box(thisbox, handle, 3, thisbox->defaultitem); } } @@ -456,8 +459,8 @@ thisbox = (Box *)GetWindowLong(lastbox, GWL_USERDATA); if(thisbox) { - if(_focus_check_box(thisbox, handle, 1) == 0) - _focus_check_box(thisbox, handle, 2); + if(_focus_check_box(thisbox, handle, 1, 0) == 0) + _focus_check_box(thisbox, handle, 2, 0); } } @@ -4561,13 +4564,16 @@ for(z=0;z<count;z++) { - lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM /*| LVCF_FORMAT*/; - lvc.pszText = titles[z]; - lvc.cchTextMax = strlen(titles[z]); - lvc.fmt = flags[z]; - lvc.cx = 75; - lvc.iSubItem = count; - SendMessage(handle, LVM_INSERTCOLUMN, (WPARAM)z + l, (LPARAM)&lvc); + if(titles[z]) + { + lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM /*| LVCF_FORMAT*/; + lvc.pszText = titles[z]; + lvc.cchTextMax = strlen(titles[z]); + lvc.fmt = flags[z]; + lvc.cx = 75; + lvc.iSubItem = count; + SendMessage(handle, LVM_INSERTCOLUMN, (WPARAM)z + l, (LPARAM)&lvc); + } } ListView_SetExtendedListViewStyle(handle, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); return TRUE; @@ -4656,8 +4662,8 @@ if(!hSmall || !hLarge) { - hSmall = ImageList_Create(16, 16, FALSE, ICON_INDEX_LIMIT, 0); - hLarge = ImageList_Create(32, 32, FALSE, ICON_INDEX_LIMIT, 0); + hSmall = ImageList_Create(16, 16, ILC_COLOR16, ICON_INDEX_LIMIT, 0); + hLarge = ImageList_Create(32, 32, ILC_COLOR16, ICON_INDEX_LIMIT, 0); } for(z=0;z<ICON_INDEX_LIMIT;z++) { @@ -5601,6 +5607,20 @@ } /* + * Sets the default focus item for a window/dialog. + * Parameters: + * window: Toplevel window or dialog. + * defaultitem: Handle to the dialog item to be default. + */ +void dw_window_default(HWND window, HWND defaultitem) +{ + Box *thisbox = (Box *)GetWindowLong(window, GWL_USERDATA); + + if(thisbox) + thisbox->defaultitem = defaultitem; +} + +/* * Returns some information about the current operating environment. * Parameters: * env: Pointer to a DWEnv struct.