comparison os2/dw.c @ 478:ea099ba917c6

Added two new tree functions, get_title and get_parent and finished the OS/2 folder browser. Will be porting to Unix soon. Windows tree functions need to be completed. Will do that tomorrow.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 15 Oct 2003 09:55:28 +0000
parents 923b46b0716c
children 469ff8133ed3
comparison
equal deleted inserted replaced
477:923b46b0716c 478:ea099ba917c6
97 char name[30]; 97 char name[30];
98 98
99 } SignalList; 99 } SignalList;
100 100
101 /* List of signals and their equivilent OS/2 message */ 101 /* List of signals and their equivilent OS/2 message */
102 #define SIGNALMAX 15 102 #define SIGNALMAX 16
103 103
104 SignalList SignalTranslate[SIGNALMAX] = { 104 SignalList SignalTranslate[SIGNALMAX] = {
105 { WM_SIZE, DW_SIGNAL_CONFIGURE }, 105 { WM_SIZE, DW_SIGNAL_CONFIGURE },
106 { WM_CHAR, DW_SIGNAL_KEY_PRESS }, 106 { WM_CHAR, DW_SIGNAL_KEY_PRESS },
107 { WM_BUTTON1DOWN, DW_SIGNAL_BUTTON_PRESS }, 107 { WM_BUTTON1DOWN, DW_SIGNAL_BUTTON_PRESS },
114 { CN_CONTEXTMENU, DW_SIGNAL_ITEM_CONTEXT }, 114 { CN_CONTEXTMENU, DW_SIGNAL_ITEM_CONTEXT },
115 { LN_SELECT, DW_SIGNAL_LIST_SELECT }, 115 { LN_SELECT, DW_SIGNAL_LIST_SELECT },
116 { CN_EMPHASIS, DW_SIGNAL_ITEM_SELECT }, 116 { CN_EMPHASIS, DW_SIGNAL_ITEM_SELECT },
117 { WM_SETFOCUS, DW_SIGNAL_SET_FOCUS }, 117 { WM_SETFOCUS, DW_SIGNAL_SET_FOCUS },
118 { SLN_SLIDERTRACK, DW_SIGNAL_VALUE_CHANGED }, 118 { SLN_SLIDERTRACK, DW_SIGNAL_VALUE_CHANGED },
119 { BKN_PAGESELECTED,DW_SIGNAL_SWITCH_PAGE } 119 { BKN_PAGESELECTED,DW_SIGNAL_SWITCH_PAGE },
120 { CN_EXPANDTREE, DW_SIGNAL_TREE_EXPAND }
120 }; 121 };
121 122
122 /* This function adds a signal handler callback into the linked list. 123 /* This function adds a signal handler callback into the linked list.
123 */ 124 */
124 void _new_signal(ULONG message, HWND window, int id, void *signalfunction, void *data) 125 void _new_signal(ULONG message, HWND window, int id, void *signalfunction, void *data)
174 typedef struct _CNRITEM 175 typedef struct _CNRITEM
175 { 176 {
176 MINIRECORDCORE rc; 177 MINIRECORDCORE rc;
177 HPOINTER hptrIcon; 178 HPOINTER hptrIcon;
178 PVOID user; 179 PVOID user;
180 HTREEITEM parent;
179 181
180 } CNRITEM, *PCNRITEM; 182 } CNRITEM, *PCNRITEM;
181 183
182 184
183 int _null_key(HWND window, int key, void *data) 185 int _null_key(HWND window, int key, void *data)
2245 } 2247 }
2246 2248
2247 if(tmp->window == conthwnd) 2249 if(tmp->window == conthwnd)
2248 { 2250 {
2249 result = containerselectfunc(tmp->window, text, tmp->data); 2251 result = containerselectfunc(tmp->window, text, tmp->data);
2252 tmp = NULL;
2253 }
2254 }
2255 break;
2256 case CN_EXPANDTREE:
2257 {
2258 int (* API treeexpandfunc)(HWND, HTREEITEM, void *) = (int (* API)(HWND, HTREEITEM, void *))tmp->signalfunction;
2259 int id = SHORT1FROMMP(mp1);
2260 HWND conthwnd = dw_window_from_id(hWnd, id);
2261
2262 if(tmp->window == conthwnd)
2263 {
2264 result = treeexpandfunc(tmp->window, (HTREEITEM)mp2, tmp->data);
2250 tmp = NULL; 2265 tmp = NULL;
2251 } 2266 }
2252 } 2267 }
2253 break; 2268 break;
2254 case CN_CONTEXTMENU: 2269 case CN_CONTEXTMENU:
5980 pci->rc.pszIcon = strdup(title); 5995 pci->rc.pszIcon = strdup(title);
5981 pci->rc.hptrIcon = icon; 5996 pci->rc.hptrIcon = icon;
5982 5997
5983 pci->hptrIcon = icon; 5998 pci->hptrIcon = icon;
5984 pci->user = itemdata; 5999 pci->user = itemdata;
6000 pci->parent = parent;
5985 6001
5986 memset(&ri, 0, sizeof(RECORDINSERT)); 6002 memset(&ri, 0, sizeof(RECORDINSERT));
5987 6003
5988 ri.cb = sizeof(RECORDINSERT); 6004 ri.cb = sizeof(RECORDINSERT);
5989 ri.pRecordOrder = (PRECORDCORE)item; 6005 ri.pRecordOrder = (PRECORDCORE)item;
5990 ri.pRecordParent = (PRECORDCORE)NULL;
5991 ri.zOrder = (USHORT)CMA_TOP; 6006 ri.zOrder = (USHORT)CMA_TOP;
5992 ri.cRecordsInsert = 1; 6007 ri.cRecordsInsert = 1;
5993 ri.fInvalidateRecord = TRUE; 6008 ri.fInvalidateRecord = TRUE;
5994 6009
5995 /* We are about to insert the child records. Set the parent record to be 6010 /* We are about to insert the child records. Set the parent record to be
6039 pci->rc.hptrIcon = icon; 6054 pci->rc.hptrIcon = icon;
6040 6055
6041 pci->hptrIcon = icon; 6056 pci->hptrIcon = icon;
6042 6057
6043 WinSendMsg(handle, CM_INVALIDATERECORD, (MPARAM)&pci, MPFROM2SHORT(1, CMA_TEXTCHANGED)); 6058 WinSendMsg(handle, CM_INVALIDATERECORD, (MPARAM)&pci, MPFROM2SHORT(1, CMA_TEXTCHANGED));
6059 }
6060
6061 /*
6062 * Gets the text an item in a tree window (widget).
6063 * Parameters:
6064 * handle: Handle to the tree containing the item.
6065 * item: Handle of the item to be modified.
6066 */
6067 char * API dw_tree_get_title(HWND handle, HTREEITEM item)
6068 {
6069 PCNRITEM pci = (PCNRITEM)item;
6070
6071 handle = handle; /* keep compiler happy */
6072 if(pci)
6073 return pci->rc.pszIcon;
6074 return NULL;
6075 }
6076
6077 /*
6078 * Gets the text an item in a tree window (widget).
6079 * Parameters:
6080 * handle: Handle to the tree containing the item.
6081 * item: Handle of the item to be modified.
6082 */
6083 HTREEITEM API dw_tree_get_parent(HWND handle, HTREEITEM item)
6084 {
6085 PCNRITEM pci = (PCNRITEM)item;
6086
6087 handle = handle; /* keep compiler happy */
6088 if(pci)
6089 return pci->parent;
6090 return (HTREEITEM)0;
6044 } 6091 }
6045 6092
6046 /* 6093 /*
6047 * Sets the item data of a tree item. 6094 * Sets the item data of a tree item.
6048 * Parameters: 6095 * Parameters:
6678 { 6725 {
6679 free(pCore->rc.pszIcon); 6726 free(pCore->rc.pszIcon);
6680 pCore->rc.pszIcon = 0; 6727 pCore->rc.pszIcon = 0;
6681 } 6728 }
6682 } 6729 }
6683 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); 6730 pCore = (PCNRITEM)pCore->rc.preccNextRecord;/*WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));*/
6684 } 6731 }
6685 _dw_send_msg(handle, CM_REMOVERECORD, (MPARAM)0L, MPFROM2SHORT(0, (redraw ? CMA_INVALIDATE : 0) | CMA_FREE), -1); 6732 _dw_send_msg(handle, CM_REMOVERECORD, (MPARAM)0L, MPFROM2SHORT(0, (redraw ? CMA_INVALIDATE : 0) | CMA_FREE), -1);
6686 } 6733 }
6687 6734
6688 /* 6735 /*
8031 /* The next few functions are support functions for the OS/2 folder browser */ 8078 /* The next few functions are support functions for the OS/2 folder browser */
8032 void _populate_directory(HMTX mtx, HWND *tree, HTREEITEM parent, char *path) 8079 void _populate_directory(HMTX mtx, HWND *tree, HTREEITEM parent, char *path)
8033 { 8080 {
8034 FILEFINDBUF3 ffbuf; 8081 FILEFINDBUF3 ffbuf;
8035 HTREEITEM item; 8082 HTREEITEM item;
8036 ULONG count; 8083 ULONG count = 1;
8037 HDIR hdir = HDIR_CREATE; 8084 HDIR hdir = HDIR_CREATE;
8038 APIRET rc;
8039 8085
8040 dw_mutex_lock(mtx); 8086 dw_mutex_lock(mtx);
8041 if(*tree) 8087 if(*tree)
8042 { 8088 {
8043 if((rc = DosFindFirst(path, &hdir, MUST_HAVE_DIRECTORY | FILE_NORMAL, 8089 if(DosFindFirst(path, &hdir, FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_ARCHIVED | MUST_HAVE_DIRECTORY,
8044 &ffbuf, sizeof(FILEFINDBUF3), &count, FIL_STANDARD)) == NO_ERROR) 8090 &ffbuf, sizeof(FILEFINDBUF3), &count, FIL_STANDARD) == NO_ERROR)
8045 { 8091 {
8046 while(DosFindNext(hdir, &ffbuf, sizeof(FILEFINDBUF3), &count) == NO_ERROR) 8092 while(DosFindNext(hdir, &ffbuf, sizeof(FILEFINDBUF3), &count) == NO_ERROR)
8047 { 8093 {
8048 int len = strlen(path); 8094 if(strcmp(ffbuf.achName, ".") && strcmp(ffbuf.achName, ".."))
8049 char *folder = malloc(len + ffbuf.cchName + 2);
8050 strcpy(folder, path);
8051 strcpy(&folder[len-1], ffbuf.achName);
8052
8053 item = dw_tree_insert(*tree, ffbuf.achName, WinLoadFileIcon(folder, TRUE), parent, 0);
8054
8055 dw_mutex_unlock(mtx);
8056 strcat(folder, "\\*");
8057
8058 _populate_directory(mtx, tree, item, folder);
8059
8060 free(folder);
8061 dw_mutex_lock(mtx);
8062 if(!*tree)
8063 { 8095 {
8096 int len = strlen(path);
8097 char *folder = malloc(len + ffbuf.cchName + 2);
8098 HTREEITEM tempitem;
8099
8100 strcpy(folder, path);
8101 strcpy(&folder[len-1], ffbuf.achName);
8102
8103 item = dw_tree_insert(*tree, ffbuf.achName, WinLoadFileIcon(folder, TRUE), parent, (void *)parent);
8104 tempitem = dw_tree_insert(*tree, "", 0, item, 0);
8105 dw_tree_set_data(*tree, item, (void *)tempitem);
8106
8064 dw_mutex_unlock(mtx); 8107 dw_mutex_unlock(mtx);
8065 DosFindClose(hdir); 8108 strcat(folder, "\\*");
8066 return; 8109
8110 free(folder);
8111 dw_mutex_lock(mtx);
8112 if(!*tree)
8113 {
8114 dw_mutex_unlock(mtx);
8115 DosFindClose(hdir);
8116 return;
8117 }
8067 } 8118 }
8068 } 8119 }
8069 DosFindClose(hdir); 8120 DosFindClose(hdir);
8070 } 8121 }
8071 } 8122 }
8085 for(drive=0;drive<26;drive++) 8136 for(drive=0;drive<26;drive++)
8086 { 8137 {
8087 if(DosQueryFSInfo(drive+1, FSIL_VOLSER,(PVOID)&volinfo, sizeof(FSINFO)) == NO_ERROR) 8138 if(DosQueryFSInfo(drive+1, FSIL_VOLSER,(PVOID)&volinfo, sizeof(FSINFO)) == NO_ERROR)
8088 { 8139 {
8089 char folder[5] = "C:\\", name[9] = "Drive C:"; 8140 char folder[5] = "C:\\", name[9] = "Drive C:";
8141 HTREEITEM tempitem;
8090 8142
8091 folder[0] = name[6] = 'A' + drive; 8143 folder[0] = name[6] = 'A' + drive;
8092 8144
8093 dw_mutex_lock(mtx); 8145 dw_mutex_lock(mtx);
8094 if(!*tree) 8146 if(!*tree)
8097 dw_mutex_close(mtx); 8149 dw_mutex_close(mtx);
8098 return; 8150 return;
8099 } 8151 }
8100 8152
8101 items[drive] = dw_tree_insert(*tree, name, WinLoadFileIcon(folder, TRUE), NULL, 0); 8153 items[drive] = dw_tree_insert(*tree, name, WinLoadFileIcon(folder, TRUE), NULL, 0);
8154 tempitem = dw_tree_insert(*tree, "", 0, items[drive], 0);
8155 dw_tree_set_data(*tree, items[drive], (void *)tempitem);
8102 8156
8103 dw_mutex_unlock(mtx); 8157 dw_mutex_unlock(mtx);
8104 } 8158 }
8105 else 8159 else
8106 items[drive] = 0; 8160 items[drive] = 0;
8107 } 8161 }
8108 DosError(FERR_ENABLEHARDERR); 8162 DosError(FERR_ENABLEHARDERR);
8109
8110 for(drive=0;drive<26;drive++)
8111 {
8112 if(items[drive])
8113 {
8114 char folder[5] = "C:\\";
8115
8116 folder[0] = 'A' + drive;
8117
8118 strcat(folder, "*");
8119
8120 _populate_directory(mtx, tree, items[drive], folder);
8121 }
8122 }
8123 8163
8124 dw_mutex_lock(mtx); 8164 dw_mutex_lock(mtx);
8125 if(!*tree) 8165 if(!*tree)
8126 { 8166 {
8127 free(tree); 8167 free(tree);
8165 dw_window_destroy((HWND)dwwait->data); 8205 dw_window_destroy((HWND)dwwait->data);
8166 dw_dialog_dismiss((DWDialog *)data, NULL); 8206 dw_dialog_dismiss((DWDialog *)data, NULL);
8167 return FALSE; 8207 return FALSE;
8168 } 8208 }
8169 8209
8210 char *_tree_folder(HWND tree, HTREEITEM item)
8211 {
8212 char *folder=strdup("");
8213 HTREEITEM parent = item;
8214
8215 while(parent)
8216 {
8217 char *temp, *text = dw_tree_get_title(tree, parent);
8218
8219 if(text)
8220 {
8221 if(strncmp(text, "Drive ", 6) == 0)
8222 text = &text[6];
8223
8224 temp = malloc(strlen(text) + strlen(folder) + 3);
8225 strcpy(temp, text);
8226 strcat(temp, "\\");
8227 strcat(temp, folder);
8228 free(folder);
8229 folder = temp;
8230 }
8231 parent = dw_tree_get_parent(tree, parent);
8232 }
8233 return folder;
8234 }
8235
8170 int DWSIGNAL _item_select(HWND window, HTREEITEM item, char *text, void *data, void *itemdata) 8236 int DWSIGNAL _item_select(HWND window, HTREEITEM item, char *text, void *data, void *itemdata)
8171 { 8237 {
8172 DWDialog *dwwait = (DWDialog *)data; 8238 DWDialog *dwwait = (DWDialog *)data;
8173 char *treedata = (char *)dw_window_get_data((HWND)dwwait->data, "_dw_tree_selected"); 8239 char *treedata = (char *)dw_window_get_data((HWND)dwwait->data, "_dw_tree_selected");
8174 8240
8241 text = text; itemdata = itemdata;
8175 if(treedata) 8242 if(treedata)
8176 free(treedata); 8243 free(treedata);
8177 8244
8178 treedata = strdup(text); 8245 treedata = _tree_folder(window, item);
8179 dw_window_set_data((HWND)dwwait->data, "_dw_tree_selected", (void *)treedata); 8246 dw_window_set_data((HWND)dwwait->data, "_dw_tree_selected", (void *)treedata);
8247
8248 return FALSE;
8249 }
8250
8251 int DWSIGNAL _tree_expand(HWND window, HTREEITEM item, void *data)
8252 {
8253 DWDialog *dwwait = (DWDialog *)data;
8254 HMTX mtx = (HMTX)dw_window_get_data(window, "_dw_mutex");
8255 HWND *tree = (HWND *)dw_window_get_data((HWND)dwwait->data, "_dw_tree");
8256 HTREEITEM tempitem = (HTREEITEM)dw_tree_get_data(*tree, item);
8257
8258 if(tempitem)
8259 {
8260 char *folder = _tree_folder(*tree, item);
8261
8262 dw_tree_set_data(*tree, item, 0);
8263 dw_tree_delete(*tree, tempitem);
8264
8265 if(*folder)
8266 {
8267 strcat(folder, "*");
8268 _populate_directory(mtx, tree, item, folder);
8269 }
8270 free(folder);
8271 }
8180 8272
8181 return FALSE; 8273 return FALSE;
8182 } 8274 }
8183 8275
8184 /* 8276 /*
8220 dw_box_pack_start(vbox, hbox, 0, 0, TRUE, FALSE, 0); 8312 dw_box_pack_start(vbox, hbox, 0, 0, TRUE, FALSE, 0);
8221 8313
8222 dwwait = dw_dialog_new((void *)window); 8314 dwwait = dw_dialog_new((void *)window);
8223 8315
8224 dw_signal_connect(tree, DW_SIGNAL_ITEM_SELECT, DW_SIGNAL_FUNC(_item_select), (void *)dwwait); 8316 dw_signal_connect(tree, DW_SIGNAL_ITEM_SELECT, DW_SIGNAL_FUNC(_item_select), (void *)dwwait);
8317 dw_signal_connect(tree, DW_SIGNAL_TREE_EXPAND, DW_SIGNAL_FUNC(_tree_expand), (void *)dwwait);
8225 8318
8226 button = dw_button_new("Ok", 1001L); 8319 button = dw_button_new("Ok", 1001L);
8227 dw_box_pack_start(hbox, button, 50, 30, TRUE, FALSE, 3); 8320 dw_box_pack_start(hbox, button, 50, 30, TRUE, FALSE, 3);
8228 dw_signal_connect(button, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_ok_func), (void *)dwwait); 8321 dw_signal_connect(button, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_ok_func), (void *)dwwait);
8229 8322
8232 dw_signal_connect(button, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_cancel_func), (void *)dwwait); 8325 dw_signal_connect(button, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_cancel_func), (void *)dwwait);
8233 8326
8234 dw_window_set_usize(window, 225, 300); 8327 dw_window_set_usize(window, 225, 300);
8235 dw_window_show(window); 8328 dw_window_show(window);
8236 8329
8237 dw_thread_new((void *)_populate_tree_thread, (void *)window, 0xfff); 8330 dw_thread_new((void *)_populate_tree_thread, (void *)window, 0xff);
8238 return (char *)dw_dialog_wait(dwwait); 8331 return (char *)dw_dialog_wait(dwwait);
8239 } 8332 }
8240 else 8333 else
8241 { 8334 {
8242 FILEDLG fild; 8335 FILEDLG fild;