Mercurial > dwindows
comparison win/dw.c @ 60:61869769c050
Sync with the latest DW code.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 29 Nov 2001 15:10:39 +0000 |
parents | 286ffd8e8ed8 |
children | 4a02842f8074 |
comparison
equal
deleted
inserted
replaced
59:286ffd8e8ed8 | 60:61869769c050 |
---|---|
95 { | 95 { |
96 ULONG message; | 96 ULONG message; |
97 char name[30]; | 97 char name[30]; |
98 | 98 |
99 } SignalList; | 99 } SignalList; |
100 | |
101 static int in_checkbox_handler = 0; | |
100 | 102 |
101 /* List of signals and their equivilent Win32 message */ | 103 /* List of signals and their equivilent Win32 message */ |
102 #define SIGNALMAX 14 | 104 #define SIGNALMAX 14 |
103 | 105 |
104 SignalList SignalTranslate[SIGNALMAX] = { | 106 SignalList SignalTranslate[SIGNALMAX] = { |
709 } | 711 } |
710 | 712 |
711 if(pass > 1 && *depth > 0) | 713 if(pass > 1 && *depth > 0) |
712 { | 714 { |
713 if(thisbox->type == BOXVERT) | 715 if(thisbox->type == BOXVERT) |
714 thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))))/((float)(thisbox->minwidth-((thisbox->items[z].pad*2)+(thisbox->parentpad*2)))); | 716 { |
717 if((thisbox->minwidth-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))) == 0) | |
718 thisbox->items[z].xratio = 1.0; | |
719 else | |
720 thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))))/((float)(thisbox->minwidth-((thisbox->items[z].pad*2)+(thisbox->parentpad*2)))); | |
721 } | |
715 else | 722 else |
716 thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-thisbox->upx))/((float)(thisbox->minwidth-thisbox->upx)); | 723 { |
724 if(thisbox->minwidth-thisbox->upx == 0) | |
725 thisbox->items[z].xratio = 1.0; | |
726 else | |
727 thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-thisbox->upx))/((float)(thisbox->minwidth-thisbox->upx)); | |
728 } | |
717 | 729 |
718 if(thisbox->type == BOXHORZ) | 730 if(thisbox->type == BOXHORZ) |
719 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))))/((float)(thisbox->minheight-((thisbox->items[z].pad*2)+(thisbox->parentpad*2)))); | 731 { |
732 if((thisbox->minheight-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))) == 0) | |
733 thisbox->items[z].yratio = 1.0; | |
734 else | |
735 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))))/((float)(thisbox->minheight-((thisbox->items[z].pad*2)+(thisbox->parentpad*2)))); | |
736 } | |
720 else | 737 else |
721 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-thisbox->upy))/((float)(thisbox->minheight-thisbox->upy)); | 738 { |
739 if(thisbox->minheight-thisbox->upy == 0) | |
740 thisbox->items[z].yratio = 1.0; | |
741 else | |
742 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-thisbox->upy))/((float)(thisbox->minheight-thisbox->upy)); | |
743 } | |
722 | 744 |
723 if(thisbox->items[z].type == TYPEBOX) | 745 if(thisbox->items[z].type == TYPEBOX) |
724 { | 746 { |
725 Box *tmp = (Box *)GetWindowLong(thisbox->items[z].hwnd, GWL_USERDATA); | 747 Box *tmp = (Box *)GetWindowLong(thisbox->items[z].hwnd, GWL_USERDATA); |
726 | 748 |
2190 int (*clickfunc)(HWND, void *) = tmp->signalfunction; | 2212 int (*clickfunc)(HWND, void *) = tmp->signalfunction; |
2191 | 2213 |
2192 /* Make sure it's the right window, and the right ID */ | 2214 /* Make sure it's the right window, and the right ID */ |
2193 if(tmp->window == hwnd) | 2215 if(tmp->window == hwnd) |
2194 { | 2216 { |
2217 if(bubble->checkbox) | |
2218 in_checkbox_handler = 1; | |
2219 | |
2195 clickfunc(tmp->window, tmp->data); | 2220 clickfunc(tmp->window, tmp->data); |
2221 | |
2222 if(bubble->checkbox) | |
2223 in_checkbox_handler = 0; | |
2196 tmp = NULL; | 2224 tmp = NULL; |
2197 } | 2225 } |
2198 } | 2226 } |
2199 if(tmp) | 2227 if(tmp) |
2200 tmp= tmp->next; | 2228 tmp= tmp->next; |
3545 * text: The text to be display by the static text widget. | 3573 * text: The text to be display by the static text widget. |
3546 * id: An ID to be used with WinWindowFromID() or 0L. | 3574 * id: An ID to be used with WinWindowFromID() or 0L. |
3547 */ | 3575 */ |
3548 HWND dw_button_new(char *text, ULONG id) | 3576 HWND dw_button_new(char *text, ULONG id) |
3549 { | 3577 { |
3550 BubbleButton *bubble = malloc(sizeof(BubbleButton)); | 3578 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); |
3551 | 3579 |
3552 HWND tmp = CreateWindow(BUTTONCLASSNAME, | 3580 HWND tmp = CreateWindow(BUTTONCLASSNAME, |
3553 text, | 3581 text, |
3554 WS_CHILD | BS_PUSHBUTTON | WS_CLIPCHILDREN, | 3582 WS_CHILD | BS_PUSHBUTTON | WS_CLIPCHILDREN, |
3555 0,0,2000,1000, | 3583 0,0,2000,1000, |
3574 * id: An ID of a bitmap in the resource file. | 3602 * id: An ID of a bitmap in the resource file. |
3575 */ | 3603 */ |
3576 HWND dw_bitmapbutton_new(char *text, ULONG id) | 3604 HWND dw_bitmapbutton_new(char *text, ULONG id) |
3577 { | 3605 { |
3578 HWND tmp; | 3606 HWND tmp; |
3579 BubbleButton *bubble = malloc(sizeof(BubbleButton)); | 3607 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); |
3580 HBITMAP hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); | 3608 HBITMAP hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); |
3581 | 3609 |
3582 tmp = CreateWindow(BUTTONCLASSNAME, | 3610 tmp = CreateWindow(BUTTONCLASSNAME, |
3583 "", | 3611 "", |
3584 WS_CHILD | BS_PUSHBUTTON | | 3612 WS_CHILD | BS_PUSHBUTTON | |
3706 * text: The text to be display by the static text widget. | 3734 * text: The text to be display by the static text widget. |
3707 * id: An ID to be used with WinWindowFromID() or 0L. | 3735 * id: An ID to be used with WinWindowFromID() or 0L. |
3708 */ | 3736 */ |
3709 HWND dw_checkbox_new(char *text, ULONG id) | 3737 HWND dw_checkbox_new(char *text, ULONG id) |
3710 { | 3738 { |
3739 BubbleButton *bubble = calloc(1, sizeof(BubbleButton)); | |
3711 HWND tmp = CreateWindow(BUTTONCLASSNAME, | 3740 HWND tmp = CreateWindow(BUTTONCLASSNAME, |
3712 text, | 3741 text, |
3713 WS_CHILD | BS_AUTOCHECKBOX | | 3742 WS_CHILD | BS_AUTOCHECKBOX | |
3714 BS_TEXT | WS_CLIPCHILDREN, | 3743 BS_TEXT | WS_CLIPCHILDREN, |
3715 0,0,2000,1000, | 3744 0,0,2000,1000, |
3716 DW_HWND_OBJECT, | 3745 DW_HWND_OBJECT, |
3717 NULL, | 3746 NULL, |
3718 NULL, | 3747 NULL, |
3719 NULL); | 3748 NULL); |
3720 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); | 3749 bubble->id = id; |
3721 | 3750 bubble->checkbox = 1; |
3722 cinfo->back = cinfo->fore = -1; | 3751 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); |
3723 cinfo->buddy = 0; | 3752 bubble->cinfo.fore = -1; |
3724 cinfo->user = 1; | 3753 bubble->cinfo.back = -1; |
3725 | 3754 SetWindowLong(tmp, GWL_USERDATA, (ULONG)bubble); |
3726 cinfo->pOldProc = SubclassWindow(tmp, _colorwndproc); | |
3727 SetWindowLong(tmp, GWL_USERDATA, (ULONG)cinfo); | |
3728 dw_window_set_font(tmp, DefaultFont); | 3755 dw_window_set_font(tmp, DefaultFont); |
3729 return tmp; | 3756 return tmp; |
3730 } | 3757 } |
3731 | 3758 |
3732 /* | 3759 /* |
4792 * handle: Handle to the checkbox to be queried. | 4819 * handle: Handle to the checkbox to be queried. |
4793 */ | 4820 */ |
4794 int dw_checkbox_query(HWND handle) | 4821 int dw_checkbox_query(HWND handle) |
4795 { | 4822 { |
4796 if(SendMessage(handle, BM_GETCHECK, 0, 0) == BST_CHECKED) | 4823 if(SendMessage(handle, BM_GETCHECK, 0, 0) == BST_CHECKED) |
4797 return TRUE; | 4824 return (in_checkbox_handler ? FALSE : TRUE); |
4798 return FALSE; | 4825 return (in_checkbox_handler ? TRUE : FALSE); |
4799 } | 4826 } |
4800 | 4827 |
4801 /* | 4828 /* |
4802 * Sets the state of the checkbox. | 4829 * Sets the state of the checkbox. |
4803 * Parameters: | 4830 * Parameters: |
4809 ColorInfo *cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA); | 4836 ColorInfo *cinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA); |
4810 | 4837 |
4811 if(cinfo && !cinfo->user) | 4838 if(cinfo && !cinfo->user) |
4812 SendMessage(handle, BM_CLICK, 0, 0); | 4839 SendMessage(handle, BM_CLICK, 0, 0); |
4813 SendMessage(handle, BM_SETCHECK, (WPARAM)value, 0); | 4840 SendMessage(handle, BM_SETCHECK, (WPARAM)value, 0); |
4841 } | |
4842 | |
4843 /* | |
4844 * Inserts an item into a tree window (widget) after another item. | |
4845 * Parameters: | |
4846 * handle: Handle to the tree to be inserted. | |
4847 * item: Handle to the item to be positioned after. | |
4848 * title: The text title of the entry. | |
4849 * icon: Handle to coresponding icon. | |
4850 * parent: Parent handle or 0 if root. | |
4851 * itemdata: Item specific data. | |
4852 */ | |
4853 HWND dw_tree_insert_after(HWND handle, HWND item, char *title, unsigned long icon, HWND parent, void *itemdata) | |
4854 { | |
4855 TVITEM tvi; | |
4856 TVINSERTSTRUCT tvins; | |
4857 HTREEITEM hti; | |
4858 void **ptrs= malloc(sizeof(void *) * 2); | |
4859 | |
4860 ptrs[0] = title; | |
4861 ptrs[1] = itemdata; | |
4862 | |
4863 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; | |
4864 tvi.pszText = title; | |
4865 tvi.lParam = (LONG)ptrs; | |
4866 tvi.cchTextMax = strlen(title); | |
4867 tvi.iSelectedImage = tvi.iImage = _lookup_icon(handle, (HICON)icon, 1); | |
4868 | |
4869 tvins.item = tvi; | |
4870 tvins.hParent = (HTREEITEM)parent; | |
4871 tvins.hInsertAfter = item ? (HTREEITEM)item : TVI_FIRST; | |
4872 | |
4873 hti = TreeView_InsertItem(handle, &tvins); | |
4874 | |
4875 return (HWND)hti; | |
4814 } | 4876 } |
4815 | 4877 |
4816 /* | 4878 /* |
4817 * Inserts an item into a tree window (widget). | 4879 * Inserts an item into a tree window (widget). |
4818 * Parameters: | 4880 * Parameters: |
4861 void **ptrs; | 4923 void **ptrs; |
4862 | 4924 |
4863 tvi.mask = TVIF_HANDLE; | 4925 tvi.mask = TVIF_HANDLE; |
4864 tvi.hItem = (HTREEITEM)item; | 4926 tvi.hItem = (HTREEITEM)item; |
4865 | 4927 |
4866 TreeView_GetItem(handle, &tvi); | 4928 if(TreeView_GetItem(handle, &tvi)) |
4867 | 4929 { |
4868 ptrs = (void **)tvi.lParam; | 4930 |
4869 ptrs[0] = title; | 4931 ptrs = (void **)tvi.lParam; |
4870 | 4932 ptrs[0] = title; |
4871 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; | 4933 |
4872 tvi.pszText = title; | 4934 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; |
4873 tvi.cchTextMax = strlen(title); | 4935 tvi.pszText = title; |
4874 tvi.iSelectedImage = tvi.iImage = _lookup_icon(handle, (HICON)icon, 1); | 4936 tvi.cchTextMax = strlen(title); |
4875 tvi.hItem = (HTREEITEM)item; | 4937 tvi.iSelectedImage = tvi.iImage = _lookup_icon(handle, (HICON)icon, 1); |
4876 | 4938 tvi.hItem = (HTREEITEM)item; |
4877 TreeView_SetItem(handle, &tvi); | 4939 |
4940 TreeView_SetItem(handle, &tvi); | |
4941 } | |
4878 } | 4942 } |
4879 | 4943 |
4880 /* | 4944 /* |
4881 * Sets the item data of a tree item. | 4945 * Sets the item data of a tree item. |
4882 * Parameters: | 4946 * Parameters: |
4890 void **ptrs; | 4954 void **ptrs; |
4891 | 4955 |
4892 tvi.mask = TVIF_HANDLE; | 4956 tvi.mask = TVIF_HANDLE; |
4893 tvi.hItem = (HTREEITEM)item; | 4957 tvi.hItem = (HTREEITEM)item; |
4894 | 4958 |
4895 TreeView_GetItem(handle, &tvi); | 4959 if(TreeView_GetItem(handle, &tvi)) |
4896 | 4960 { |
4897 ptrs = (void **)tvi.lParam; | 4961 ptrs = (void **)tvi.lParam; |
4898 ptrs[1] = itemdata; | 4962 ptrs[1] = itemdata; |
4963 } | |
4899 } | 4964 } |
4900 | 4965 |
4901 /* | 4966 /* |
4902 * Sets this item as the active selection. | 4967 * Sets this item as the active selection. |
4903 * Parameters: | 4968 * Parameters: |
4948 * handle: Handle to the window (widget) to be cleared. | 5013 * handle: Handle to the window (widget) to be cleared. |
4949 * item: Handle to node to be deleted. | 5014 * item: Handle to node to be deleted. |
4950 */ | 5015 */ |
4951 void dw_tree_delete(HWND handle, HWND item) | 5016 void dw_tree_delete(HWND handle, HWND item) |
4952 { | 5017 { |
5018 if((HTREEITEM)item == TVI_ROOT) | |
5019 return; | |
5020 | |
4953 TreeView_DeleteItem(handle, (HTREEITEM)item); | 5021 TreeView_DeleteItem(handle, (HTREEITEM)item); |
4954 } | 5022 } |
4955 | 5023 |
4956 /* | 5024 /* |
4957 * Sets up the container columns. | 5025 * Sets up the container columns. |