Mercurial > dwindows
comparison win/dw.c @ 1869:a2d556368be1
Fixed Windows issues with dw_tree_item_g/set_data()... and potentially
dw_tree_item_get_title() and simplified the delete and clear functionality.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 21 Mar 2013 22:10:43 +0000 |
parents | dc3260e1a915 |
children | 5a4d98cab9d3 |
comparison
equal
deleted
inserted
replaced
1868:dc3260e1a915 | 1869:a2d556368be1 |
---|---|
8776 * itemdata: User defined data to be associated with item. | 8776 * itemdata: User defined data to be associated with item. |
8777 */ | 8777 */ |
8778 void API dw_tree_item_set_data(HWND handle, HTREEITEM item, void *itemdata) | 8778 void API dw_tree_item_set_data(HWND handle, HTREEITEM item, void *itemdata) |
8779 { | 8779 { |
8780 TVITEM tvi; | 8780 TVITEM tvi; |
8781 void **ptrs; | 8781 |
8782 | 8782 tvi.mask = TVIF_HANDLE | TVIF_PARAM; |
8783 tvi.mask = TVIF_HANDLE; | |
8784 tvi.hItem = item; | 8783 tvi.hItem = item; |
8785 | 8784 tvi.lParam = (LPARAM)itemdata; |
8786 if(TreeView_GetItem(handle, &tvi)) | 8785 |
8787 { | 8786 TreeView_SetItem(handle, &tvi); |
8788 ptrs = (void **)tvi.lParam; | |
8789 ptrs[1] = itemdata; | |
8790 } | |
8791 } | 8787 } |
8792 | 8788 |
8793 /* | 8789 /* |
8794 * Gets the item data of a tree item. | 8790 * Gets the item data of a tree item. |
8795 * Parameters: | 8791 * Parameters: |
8797 * item: Handle of the item to be modified. | 8793 * item: Handle of the item to be modified. |
8798 */ | 8794 */ |
8799 void * API dw_tree_item_get_data(HWND handle, HTREEITEM item) | 8795 void * API dw_tree_item_get_data(HWND handle, HTREEITEM item) |
8800 { | 8796 { |
8801 TVITEM tvi; | 8797 TVITEM tvi; |
8802 void **ptrs; | |
8803 | 8798 |
8804 tvi.mask = TVIF_HANDLE | TVIF_PARAM; | 8799 tvi.mask = TVIF_HANDLE | TVIF_PARAM; |
8805 tvi.hItem = item; | 8800 tvi.hItem = item; |
8806 | 8801 |
8807 if(TreeView_GetItem(handle, &tvi)) | 8802 if(TreeView_GetItem(handle, &tvi)) |
8808 { | 8803 { |
8809 ptrs = (void **)tvi.lParam; | 8804 return (void *)tvi.lParam; |
8810 return ptrs[1]; | |
8811 } | 8805 } |
8812 return NULL; | 8806 return NULL; |
8813 } | 8807 } |
8814 | 8808 |
8815 /* | 8809 /* |
8819 * item: Handle of the item to be modified. | 8813 * item: Handle of the item to be modified. |
8820 */ | 8814 */ |
8821 char * API dw_tree_get_title(HWND handle, HTREEITEM item) | 8815 char * API dw_tree_get_title(HWND handle, HTREEITEM item) |
8822 { | 8816 { |
8823 TVITEM tvi; | 8817 TVITEM tvi; |
8824 | 8818 TCHAR textbuf[1025] = {0}, *textptr = textbuf; |
8825 tvi.mask = TVIF_HANDLE; | 8819 |
8820 tvi.mask = TVIF_HANDLE | TVIF_TEXT; | |
8826 tvi.hItem = item; | 8821 tvi.hItem = item; |
8827 | 8822 |
8828 if(TreeView_GetItem(handle, &tvi)) | 8823 if(TreeView_GetItem(handle, &tvi)) |
8829 return _strdup(WideToUTF8(tvi.pszText)); | 8824 return _strdup(WideToUTF8(textptr)); |
8830 return NULL; | 8825 return NULL; |
8831 } | 8826 } |
8832 | 8827 |
8833 /* | 8828 /* |
8834 * Gets the text an item in a tree window (widget). | 8829 * Gets the text an item in a tree window (widget). |
8850 void API dw_tree_item_select(HWND handle, HTREEITEM item) | 8845 void API dw_tree_item_select(HWND handle, HTREEITEM item) |
8851 { | 8846 { |
8852 TreeView_SelectItem(handle, item); | 8847 TreeView_SelectItem(handle, item); |
8853 } | 8848 } |
8854 | 8849 |
8855 /* Delete all tree subitems */ | |
8856 void _dw_tree_item_delete_recursive(HWND handle, HTREEITEM node) | |
8857 { | |
8858 HTREEITEM hti; | |
8859 | |
8860 hti = TreeView_GetChild(handle, node); | |
8861 | |
8862 while(hti) | |
8863 { | |
8864 HTREEITEM lastitem = hti; | |
8865 | |
8866 hti = TreeView_GetNextSibling(handle, hti); | |
8867 dw_tree_item_delete(handle, lastitem); | |
8868 } | |
8869 } | |
8870 | |
8871 /* | 8850 /* |
8872 * Removes all nodes from a tree. | 8851 * Removes all nodes from a tree. |
8873 * Parameters: | 8852 * Parameters: |
8874 * handle: Handle to the window (widget) to be cleared. | 8853 * handle: Handle to the window (widget) to be cleared. |
8875 */ | 8854 */ |
8876 void API dw_tree_clear(HWND handle) | 8855 void API dw_tree_clear(HWND handle) |
8877 { | 8856 { |
8878 HTREEITEM hti = TreeView_GetRoot(handle); | 8857 dw_window_set_data(handle, "_dw_select_item", DW_INT_TO_POINTER(1)); |
8879 | 8858 TreeView_DeleteAllItems(handle); |
8880 dw_window_set_data(handle, "_dw_select_item", (void *)1); | 8859 dw_window_set_data(handle, "_dw_select_item", NULL); |
8881 while(hti) | |
8882 { | |
8883 HTREEITEM lastitem = hti; | |
8884 | |
8885 _dw_tree_item_delete_recursive(handle, hti); | |
8886 hti = TreeView_GetNextSibling(handle, hti); | |
8887 dw_tree_item_delete(handle, lastitem); | |
8888 } | |
8889 dw_window_set_data(handle, "_dw_select_item", (void *)0); | |
8890 } | 8860 } |
8891 | 8861 |
8892 /* | 8862 /* |
8893 * Expands a node on a tree. | 8863 * Expands a node on a tree. |
8894 * Parameters: | 8864 * Parameters: |
8917 * handle: Handle to the window (widget) to be cleared. | 8887 * handle: Handle to the window (widget) to be cleared. |
8918 * item: Handle to node to be deleted. | 8888 * item: Handle to node to be deleted. |
8919 */ | 8889 */ |
8920 void API dw_tree_item_delete(HWND handle, HTREEITEM item) | 8890 void API dw_tree_item_delete(HWND handle, HTREEITEM item) |
8921 { | 8891 { |
8922 TVITEM tvi; | |
8923 void **ptrs=NULL; | |
8924 | |
8925 if(item == TVI_ROOT || !item) | |
8926 return; | |
8927 | |
8928 tvi.mask = TVIF_HANDLE; | |
8929 tvi.hItem = item; | |
8930 | |
8931 if(TreeView_GetItem(handle, &tvi)) | |
8932 ptrs = (void **)tvi.lParam; | |
8933 | |
8934 _dw_tree_item_delete_recursive(handle, item); | |
8935 TreeView_DeleteItem(handle, item); | 8892 TreeView_DeleteItem(handle, item); |
8936 if(ptrs) | |
8937 free(ptrs); | |
8938 } | 8893 } |
8939 | 8894 |
8940 /* | 8895 /* |
8941 * Sets up the container columns. | 8896 * Sets up the container columns. |
8942 * Parameters: | 8897 * Parameters: |
12512 return _myWideToUTF8(wstring, malloc(WideCharToMultiByte(CP_UTF8, 0, wstring, -1, NULL, 0, NULL, NULL))); | 12467 return _myWideToUTF8(wstring, malloc(WideCharToMultiByte(CP_UTF8, 0, wstring, -1, NULL, 0, NULL, NULL))); |
12513 #else | 12468 #else |
12514 return NULL; | 12469 return NULL; |
12515 #endif | 12470 #endif |
12516 } | 12471 } |
12517 |