Mercurial > dwindows
changeset 69:9510897c0b03
Added new container functions, and implemented some missing functionality.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 04 Feb 2002 16:04:43 +0000 |
parents | 8d6100960adf |
children | 5e7a4d93d8d7 |
files | dw.def dw.h dww.def gtk/dw.c os2/dw.c win/dw.c |
diffstat | 6 files changed, 338 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/dw.def Tue Jan 22 23:45:01 2002 +0000 +++ b/dw.def Mon Feb 04 16:04:43 2002 +0000 @@ -133,6 +133,8 @@ dw_container_delete @230 dw_container_scroll @231 dw_container_set_column_width @232 + dw_container_cursor @233 + dw_container_optimize @234 dw_filesystem_setup @240 dw_filesystem_set_item @241
--- a/dw.h Tue Jan 22 23:45:01 2002 +0000 +++ b/dw.h Mon Feb 04 16:04:43 2002 +0000 @@ -97,6 +97,9 @@ #define DW_CV_MINI CV_MINI #define DW_CV_DETAIL CV_DETAIL +#define DW_CRA_SELECTED CRA_SELECTED +#define DW_CRA_CURSORED CRA_CURSORED + #define DW_SLS_READONLY SLS_READONLY #define DW_SLS_RIBBONSTRIP SLS_RIBBONSTRIP @@ -214,13 +217,13 @@ #define DW_FCF_AUTOICON 0 #define DW_CFA_BITMAPORICON 1 -#define DW_CFA_STRING 1 << 2 -#define DW_CFA_ULONG 1 << 3 -#define DW_CFA_TIME 1 << 4 -#define DW_CFA_DATE 1 << 5 -#define DW_CFA_CENTER 1 << 6 -#define DW_CFA_LEFT 1 << 7 -#define DW_CFA_RIGHT 1 << 8 +#define DW_CFA_STRING (1 << 1) +#define DW_CFA_ULONG (1 << 2) +#define DW_CFA_TIME (1 << 3) +#define DW_CFA_DATE (1 << 4) +#define DW_CFA_CENTER (1 << 5) +#define DW_CFA_LEFT (1 << 6) +#define DW_CFA_RIGHT (1 << 7) #define DW_CFA_HORZSEPARATOR 0 #define DW_CFA_SEPARATOR 0 @@ -228,6 +231,9 @@ #define DW_CV_MINI 0 #define DW_CV_DETAIL 0 +#define DW_CRA_SELECTED LVNI_SELECTED +#define DW_CRA_CURSORED LVNI_FOCUSED + #define DW_SLS_READONLY 0 #define DW_SLS_RIBBONSTRIP 0 @@ -439,6 +445,9 @@ #define DW_CCS_SINGLESEL 1 #define DW_CCS_EXTENDSEL (1 << 1) +#define DW_CRA_SELECTED 1 +#define DW_CRA_CURSORED (1 << 1) + #define DW_LS_MULTIPLESEL 1 #define DW_LIT_NONE -1 @@ -691,6 +700,8 @@ char *dw_container_query_start(HWND handle, unsigned long flags); char *dw_container_query_next(HWND handle, unsigned long flags); void dw_container_scroll(HWND handle, int direction, long rows); +void dw_container_cursor(HWND handle, char *text); +void dw_container_optimize(HWND handle); int dw_filesystem_setup(HWND handle, unsigned long *flags, char **titles, int count); void dw_filesystem_set_item(HWND handle, void *pointer, int column, int row, void *data); void dw_filesystem_set_file(HWND handle, void *pointer, int row, char *filename, unsigned long icon);
--- a/dww.def Tue Jan 22 23:45:01 2002 +0000 +++ b/dww.def Mon Feb 04 16:04:43 2002 +0000 @@ -130,6 +130,8 @@ dw_container_delete @230 dw_container_scroll @231 dw_container_set_column_width @232 + dw_container_cursor @233 + dw_container_optimize @234 dw_filesystem_setup @240 dw_filesystem_set_item @241
--- a/gtk/dw.c Tue Jan 22 23:45:01 2002 +0000 +++ b/gtk/dw.c Mon Feb 04 16:04:43 2002 +0000 @@ -446,9 +446,16 @@ { GList *tmp = (GList *)gtk_object_get_data(GTK_OBJECT(widget), "selectlist"); char *rowdata = gtk_clist_get_row_data(GTK_CLIST(widget), row); + int multi = (int)gtk_object_get_data(GTK_OBJECT(widget), "multi"); if(rowdata) { + if(!multi) + { + g_list_free(tmp); + tmp = NULL; + } + tmp = g_list_append(tmp, rowdata); gtk_object_set_data(GTK_OBJECT(widget), "selectlist", tmp); } @@ -3683,26 +3690,35 @@ return NULL; } - /* If there is an old query list, free it */ - list = (GList *)gtk_object_get_data(GTK_OBJECT(clist), "querylist"); - if(list) - g_list_free(list); - - /* Move the current selection list to the query list, and remove the - * current selection list. - */ - list = (GList *)gtk_object_get_data(GTK_OBJECT(clist), "selectlist"); - gtk_object_set_data(GTK_OBJECT(clist), "selectlist", NULL); - gtk_object_set_data(GTK_OBJECT(clist), "querylist", (gpointer)list); - gtk_clist_unselect_all(GTK_CLIST(clist)); - - if(list) + /* These should be separate but right now this will work */ + if(flags & DW_CRA_SELECTED || flags & DW_CRA_CURSORED) { + /* If there is an old query list, free it */ + list = (GList *)gtk_object_get_data(GTK_OBJECT(clist), "querylist"); + if(list) + g_list_free(list); + + /* Move the current selection list to the query list, and remove the + * current selection list. + */ + list = (GList *)gtk_object_get_data(GTK_OBJECT(clist), "selectlist"); + gtk_object_set_data(GTK_OBJECT(clist), "selectlist", NULL); + gtk_object_set_data(GTK_OBJECT(clist), "querylist", (gpointer)list); + gtk_clist_unselect_all(GTK_CLIST(clist)); + + if(list) + { + gtk_object_set_data(GTK_OBJECT(clist), "querypos", (gpointer)1); + if(list->data) + retval = list->data; + else + retval = ""; + } + } + else + { + retval = (char *)gtk_clist_get_row_data(GTK_CLIST(clist), 0); gtk_object_set_data(GTK_OBJECT(clist), "querypos", (gpointer)1); - if(list->data) - retval = list->data; - else - retval = ""; } DW_MUTEX_UNLOCK; return retval; @@ -3732,29 +3748,110 @@ return NULL; } - list = (GList *)gtk_object_get_data(GTK_OBJECT(clist), "querylist"); - - if(list) + /* These should be separate but right now this will work */ + if(flags & DW_CRA_SELECTED || flags & DW_CRA_CURSORED) { - int counter = 0, pos = (int)gtk_object_get_data(GTK_OBJECT(clist), "querypos"); - gtk_object_set_data(GTK_OBJECT(clist), "querypos", (gpointer)pos+1); - - while(list && counter < pos) + list = (GList *)gtk_object_get_data(GTK_OBJECT(clist), "querylist"); + + if(list) { - list = list->next; - counter++; + int counter = 0, pos = (int)gtk_object_get_data(GTK_OBJECT(clist), "querypos"); + gtk_object_set_data(GTK_OBJECT(clist), "querypos", (gpointer)pos+1); + + while(list && counter < pos) + { + list = list->next; + counter++; + } + + if(list && list->data) + retval = list->data; + else if(list && !list->data) + retval = ""; } - - if(list && list->data) - retval = list->data; - else if(list && !list->data) - retval = ""; + } + else + { + int pos = (int)gtk_object_get_data(GTK_OBJECT(clist), "querypos"); + + retval = (char *)gtk_clist_get_row_data(GTK_CLIST(clist), pos); + gtk_object_set_data(GTK_OBJECT(clist), "querypos", (gpointer)pos+1); } DW_MUTEX_UNLOCK; return retval; } /* + * Cursors the item with the text speficied, and scrolls to that item. + * Parameters: + * handle: Handle to the window (widget) to be queried. + * text: Text usually returned by dw_container_query(). + */ +void dw_container_cursor(HWND handle, char *text) +{ + int _locked_by_me = FALSE; + GtkWidget *clist; + int rowcount, z; + char *rowdata; + + DW_MUTEX_LOCK; + clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle)); + + if(!clist) + { + DW_MUTEX_UNLOCK; + return; + } + rowcount = (int)gtk_object_get_data(GTK_OBJECT(clist), "rowcount"); + + for(z=0;z<rowcount;z++) + { + rowdata = gtk_clist_get_row_data(GTK_CLIST(clist), z); + if(rowdata == text) + { + gfloat pos; + GtkAdjustment *adj = gtk_clist_get_vadjustment(GTK_CLIST(clist)); + gtk_clist_select_row(GTK_CLIST(clist), z, 0); + + pos = ((adj->upper - adj->lower) * ((gfloat)z/(gfloat)rowcount)) + adj->lower; + gtk_adjustment_set_value(adj, pos); + DW_MUTEX_UNLOCK; + return; + } + } + + DW_MUTEX_UNLOCK; +} + +/* + * Optimizes the column widths so that all data is visible. + * Parameters: + * handle: Handle to the window (widget) to be optimized. + */ +void dw_container_optimize(HWND handle) +{ + int _locked_by_me = FALSE; + GtkWidget *clist; + int colcount, z; + + DW_MUTEX_LOCK; + clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle)); + + if(!clist) + { + DW_MUTEX_UNLOCK; + return; + } + colcount = (int)gtk_object_get_data(GTK_OBJECT(clist), "colcount"); + for(z=0;z<colcount;z++) + { + int width = gtk_clist_optimal_column_width(GTK_CLIST(clist), z); + gtk_clist_set_column_width(GTK_CLIST(clist), z, width); + } + DW_MUTEX_UNLOCK; +} + +/* * Creates a rendering context widget (window) to be packed. * Parameters: * id: An id to be used with dw_window_from_id. @@ -4645,9 +4742,15 @@ if(GTK_IS_CLIST(handle2)) { if(style & DW_CCS_EXTENDSEL) + { gtk_clist_set_selection_mode(GTK_CLIST(handle2), GTK_SELECTION_MULTIPLE); + gtk_object_set_data(GTK_OBJECT(handle2), "multi", (gpointer)1); + } if(style & DW_CCS_SINGLESEL) + { gtk_clist_set_selection_mode(GTK_CLIST(handle2), GTK_SELECTION_SINGLE); + gtk_object_set_data(GTK_OBJECT(handle2), "multi", (gpointer)0); + } } if(GTK_IS_LABEL(handle2)) {
--- a/os2/dw.c Tue Jan 22 23:45:01 2002 +0000 +++ b/os2/dw.c Mon Feb 04 16:04:43 2002 +0000 @@ -5473,7 +5473,9 @@ temp = (PRECORDCORE)ci->data; - WinSendMsg(handle, CM_QUERYCNRINFO, (MPARAM)&cnr, MPFROMSHORT(sizeof(CNRINFO))); + if(!WinSendMsg(handle, CM_QUERYCNRINFO, (MPARAM)&cnr, MPFROMSHORT(sizeof(CNRINFO)))) + return; + currentcount = cnr.cRecords; /* Figure out the offsets to the items in the struct */ @@ -5612,6 +5614,8 @@ break; DosSleep(1); } + + free(ci); } /* @@ -5719,7 +5723,7 @@ { while(pCore) { - if(pCore->flRecordAttr & CRA_SELECTED) + if(pCore->flRecordAttr & flags) return pCore->pszIcon; pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); } @@ -5747,7 +5751,7 @@ { while(pCore) { - if(pCore->flRecordAttr & CRA_SELECTED) + if(pCore->flRecordAttr & flags) return pCore->pszIcon; pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); @@ -5760,6 +5764,53 @@ } /* + * Cursors the item with the text speficied, and scrolls to that item. + * Parameters: + * handle: Handle to the window (widget) to be queried. + * text: Text usually returned by dw_container_query(). + */ +void dw_container_cursor(HWND handle, char *text) +{ + RECTL viewport, item; + + pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)0L, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER)); + while(pCore) + { + if(pCore->pszIcon == text) + { + QUERYRECORDRECT qrr; + int scrollpixels = 0, midway; + + qrr.cb = sizeof(QUERYRECORDRECT); + qrr.pRecord = pCore; + qrr.fRightSplitWindow = 0; + qrr.fsExtent = CMA_TEXT; + + WinSendMsg(handle, CM_SETRECORDEMPHASIS, (MPARAM)pCore, MPFROM2SHORT(TRUE, CRA_CURSORED)); + WinSendMsg(handle, CM_QUERYVIEWPORTRECT, (MPARAM)&viewport, MPFROM2SHORT(CMA_WORKSPACE, FALSE)); + WinSendMsg(handle, CM_QUERYRECORDRECT, (MPARAM)&item, (MPARAM)&qrr); + + midway = (viewport.yTop - viewport.yBottom)/2; + scrollpixels = viewport.yTop - (item.yTop + midway); + + WinSendMsg(handle, CM_SCROLLWINDOW, MPFROMSHORT(CMA_VERTICAL), MPFROMLONG(scrollpixels)); + return; + } + + pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); + } +} + +/* + * Optimizes the column widths so that all data is visible. + * Parameters: + * handle: Handle to the window (widget) to be optimized. + */ +void dw_container_optimize(HWND handle) +{ +} + +/* * Creates a rendering context widget (window) to be packed. * Parameters: * id: An id to be used with dw_window_from_id.
--- a/win/dw.c Tue Jan 22 23:45:01 2002 +0000 +++ b/win/dw.c Mon Feb 04 16:04:43 2002 +0000 @@ -1985,6 +1985,8 @@ iItem = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED); + memset(&lvi, 0, sizeof(LV_ITEM)); + if(iItem > -1) { lvi.iItem = iItem; @@ -1992,8 +1994,6 @@ ListView_GetItem(hWnd, &lvi); } - else - lvi.lParam = (LPARAM)NULL; { SignalHandler *tmp = Root; @@ -2040,6 +2040,8 @@ iItem = ListView_HitTest(tmp->window, &lhi); + memset(&lvi, 0, sizeof(LV_ITEM)); + if(iItem > -1) { lvi.iItem = iItem; @@ -2048,8 +2050,6 @@ ListView_GetItem(tmp->window, &lvi); ListView_SetSelectionMark(tmp->window, iItem); } - else - lvi.lParam = (LPARAM)NULL; /* Seems to be having lParam as 1 which really sucks */ if(lvi.lParam < 100) @@ -3559,7 +3559,7 @@ { HWND tmp = CreateWindow(WC_LISTVIEW, "", - WS_CHILD | LVS_REPORT | + WS_CHILD | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SHAREIMAGELISTS | WS_BORDER | WS_CLIPCHILDREN, 0,0,2000,1000, @@ -3593,7 +3593,7 @@ { HWND tmp = CreateWindow(WC_TREEVIEW, "", - WS_CHILD | TVS_HASLINES | + WS_CHILD | TVS_HASLINES | TVS_SHOWSELALWAYS | TVS_HASBUTTONS | TVS_LINESATROOT | WS_BORDER | WS_CLIPCHILDREN, 0,0,2000,1000, @@ -5387,6 +5387,7 @@ memcpy(&tempflags[l], flags, sizeof(unsigned long) * count); tempflags[count + l] = 0; cinfo->flags = tempflags; + cinfo->columns = count; for(z=0;z<count;z++) @@ -5766,11 +5767,12 @@ { LV_ITEM lvi; - if(flags) - _index = ListView_GetNextItem(handle, -1, LVNI_SELECTED); - else - _index = ListView_GetNextItem(handle, -1, LVNI_ALL); - + _index = ListView_GetNextItem(handle, -1, flags); + + if(_index == -1) + return NULL; + + memset(&lvi, 0, sizeof(LV_ITEM)); lvi.iItem = _index; lvi.mask = LVIF_PARAM; @@ -5792,14 +5794,13 @@ { LV_ITEM lvi; - if(flags) - _index = ListView_GetNextItem(handle, _index, LVNI_SELECTED); - else - _index = ListView_GetNextItem(handle, _index, LVNI_ALL); + _index = ListView_GetNextItem(handle, _index, flags); if(_index == -1) return NULL; + memset(&lvi, 0, sizeof(LV_ITEM)); + lvi.iItem = _index; lvi.mask = LVIF_PARAM; @@ -5809,6 +5810,117 @@ } /* + * Cursors the item with the text speficied, and scrolls to that item. + * Parameters: + * handle: Handle to the window (widget) to be queried. + * text: Text usually returned by dw_container_query(). + */ +void dw_container_cursor(HWND handle, char *text) +{ + int index = ListView_GetNextItem(handle, -1, LVNI_ALL); + + while(index != -1) + { + LV_ITEM lvi; + + memset(&lvi, 0, sizeof(LV_ITEM)); + + lvi.iItem = index; + lvi.mask = LVIF_PARAM; + + ListView_GetItem(handle, &lvi); + + if((char *)lvi.lParam == text) + { + RECT viewport, item; + + ListView_SetItemState(handle, index, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); + ListView_EnsureVisible(handle, index, TRUE); + return; + } + + index = ListView_GetNextItem(handle, index, LVNI_ALL); + } +} + +/* + * Optimizes the column widths so that all data is visible. + * Parameters: + * handle: Handle to the window (widget) to be optimized. + */ +void dw_container_optimize(HWND handle) +{ + ContainerInfo *cinfo = (ContainerInfo *)GetWindowLong(handle, GWL_USERDATA); + ULONG *flags; + LV_ITEM lvi; + + if(cinfo && cinfo->columns > 0) + { + int z, index; + ULONG *flags = cinfo->flags, *columns = calloc(sizeof(ULONG), cinfo->columns); + char *text = malloc(1024); + + /* Initialize with sizes of column labels */ + for(z=0;z<cinfo->columns;z++) + { + if(flags[z] & DW_CFA_BITMAPORICON) + columns[z] = 5; + else + { + LVCOLUMN lvc; + + lvc.mask = LVCF_TEXT; + lvc.cchTextMax = 1023; + lvc.pszText = text; + + if(ListView_GetColumn(handle, z, &lvc)) + columns[z] = ListView_GetStringWidth(handle, lvc.pszText); + } + } + + index = ListView_GetNextItem(handle, -1, LVNI_ALL); + + /* Query all the item texts */ + while(index != -1) + { + for(z=0;z<cinfo->columns;z++) + { + LV_ITEM lvi; + + memset(&lvi, 0, sizeof(LV_ITEM)); + + lvi.iItem = index; + lvi.iSubItem = z; + lvi.mask = LVIF_TEXT; + lvi.cchTextMax = 1023; + lvi.pszText = text; + + if(ListView_GetItem(handle, &lvi)) + { + int width = ListView_GetStringWidth(handle, lvi.pszText); + if(width > columns[z]) + { + if(z == 0) + columns[z] = width + 20; + else + columns[z] = width; + } + } + } + + index = ListView_GetNextItem(handle, index, LVNI_ALL); + } + + /* Set the new sizes */ + for(z=0;z<cinfo->columns;z++) + ListView_SetColumnWidth(handle, z, columns[z] + 15); + + free(columns); + free(text); + } +} + +/* * Creates a rendering context widget (window) to be packed. * Parameters: * id: An id to be used with dw_window_from_id.