Mercurial > dwindows
comparison mac/dw.m @ 1671:d5f39d32c4da
Initial implementation of dw_box_remove() and dw_box_remove_at_index() for Mac.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 26 Apr 2012 21:57:18 +0000 |
parents | 4ec0bce77f70 |
children | 42890a2b8d3e |
comparison
equal
deleted
inserted
replaced
1670:86d7bce8f4c6 | 1671:d5f39d32c4da |
---|---|
3900 free(thisitem); | 3900 free(thisitem); |
3901 DW_MUTEX_UNLOCK; | 3901 DW_MUTEX_UNLOCK; |
3902 } | 3902 } |
3903 | 3903 |
3904 /* | 3904 /* |
3905 * Remove windows (widgets) from the box they are packed into. | |
3906 * Parameters: | |
3907 * handle: Window handle of the item to be back. | |
3908 * Returns: | |
3909 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. | |
3910 */ | |
3911 int API dw_box_remove(HWND handle) | |
3912 { | |
3913 int _locked_by_me = FALSE; | |
3914 DW_LOCAL_POOL_IN; | |
3915 DW_MUTEX_LOCK; | |
3916 id object = handle; | |
3917 | |
3918 if([object isKindOfClass:[NSView class]] || [object isKindOfClass:[NSControl class]]) | |
3919 { | |
3920 DWBox *parent = (DWBox *)[object superview]; | |
3921 | |
3922 /* Some controls are embedded in scrollviews... | |
3923 * so get the parent of the scrollview in that case. | |
3924 */ | |
3925 if(([object isKindOfClass:[NSTableView class]] || [object isMemberOfClass:[DWMLE class]]) | |
3926 && [parent isMemberOfClass:[NSClipView class]]) | |
3927 { | |
3928 object = [parent superview]; | |
3929 parent = (DWBox *)[object superview]; | |
3930 } | |
3931 | |
3932 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) | |
3933 { | |
3934 id window = [object window]; | |
3935 Box *thisbox = [parent box]; | |
3936 int z, index = -1; | |
3937 Item *tmpitem, *thisitem = thisbox->items; | |
3938 | |
3939 for(z=0;z<thisbox->count;z++) | |
3940 { | |
3941 if(thisitem[z].hwnd == object) | |
3942 index = z; | |
3943 } | |
3944 | |
3945 if(index == -1) | |
3946 { | |
3947 DW_MUTEX_UNLOCK; | |
3948 DW_LOCAL_POOL_OUT; | |
3949 return DW_ERROR_GENERAL; | |
3950 } | |
3951 | |
3952 [object retain]; | |
3953 [object removeFromSuperview]; | |
3954 | |
3955 tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); | |
3956 | |
3957 /* Copy all but the current entry to the new list */ | |
3958 for(z=0;z<index;z++) | |
3959 { | |
3960 tmpitem[z] = thisitem[z]; | |
3961 } | |
3962 for(z=index+1;z<thisbox->count;z++) | |
3963 { | |
3964 tmpitem[z-1] = thisitem[z]; | |
3965 } | |
3966 | |
3967 thisbox->items = tmpitem; | |
3968 free(thisitem); | |
3969 thisbox->count--; | |
3970 /* Queue a redraw on the top-level window */ | |
3971 _dw_redraw(window, TRUE); | |
3972 } | |
3973 } | |
3974 DW_MUTEX_UNLOCK; | |
3975 DW_LOCAL_POOL_OUT; | |
3976 return DW_ERROR_NONE; | |
3977 } | |
3978 | |
3979 /* | |
3980 * Remove windows (widgets) from a box at an arbitrary location. | |
3981 * Parameters: | |
3982 * box: Window handle of the box to be removed from. | |
3983 * index: 0 based index of packed items. | |
3984 * Returns: | |
3985 * Handle to the removed item on success, 0 on failure. | |
3986 */ | |
3987 HWND API dw_box_remove_at_index(HWND box, int index) | |
3988 { | |
3989 int _locked_by_me = FALSE; | |
3990 DW_LOCAL_POOL_IN; | |
3991 DW_MUTEX_LOCK; | |
3992 DWBox *parent = (DWBox *)box; | |
3993 id object = nil; | |
3994 | |
3995 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) | |
3996 { | |
3997 id window = [parent window]; | |
3998 Box *thisbox = [parent box]; | |
3999 | |
4000 if(thisbox && index > -1 && index < thisbox->count) | |
4001 { | |
4002 int z; | |
4003 Item *tmpitem, *thisitem = thisbox->items; | |
4004 | |
4005 object = thisitem[index].hwnd; | |
4006 | |
4007 [object retain]; | |
4008 [object removeFromSuperview]; | |
4009 | |
4010 tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); | |
4011 | |
4012 /* Copy all but the current entry to the new list */ | |
4013 for(z=0;z<index;z++) | |
4014 { | |
4015 tmpitem[z] = thisitem[z]; | |
4016 } | |
4017 for(z=index+1;z<thisbox->count;z++) | |
4018 { | |
4019 tmpitem[z-1] = thisitem[z]; | |
4020 } | |
4021 | |
4022 thisbox->items = tmpitem; | |
4023 free(thisitem); | |
4024 thisbox->count--; | |
4025 /* Queue a redraw on the top-level window */ | |
4026 _dw_redraw(window, TRUE); | |
4027 } | |
4028 } | |
4029 DW_MUTEX_UNLOCK; | |
4030 DW_LOCAL_POOL_OUT; | |
4031 return 0; | |
4032 } | |
4033 | |
4034 /* | |
3905 * Pack windows (widgets) into a box at an arbitrary location. | 4035 * Pack windows (widgets) into a box at an arbitrary location. |
3906 * Parameters: | 4036 * Parameters: |
3907 * box: Window handle of the box to be packed into. | 4037 * box: Window handle of the box to be packed into. |
3908 * item: Window handle of the item to be back. | 4038 * item: Window handle of the item to be back. |
3909 * index: 0 based index of packed items. | 4039 * index: 0 based index of packed items. |
8491 parent = (DWBox *)[object superview]; | 8621 parent = (DWBox *)[object superview]; |
8492 } | 8622 } |
8493 | 8623 |
8494 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) | 8624 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) |
8495 { | 8625 { |
8626 id window = [object window]; | |
8496 Box *thisbox = [parent box]; | 8627 Box *thisbox = [parent box]; |
8497 int z, index = -1; | 8628 int z, index = -1; |
8498 Item *tmpitem, *thisitem = thisbox->items; | 8629 Item *tmpitem, *thisitem = thisbox->items; |
8499 id window = [object window]; | |
8500 | 8630 |
8501 for(z=0;z<thisbox->count;z++) | 8631 for(z=0;z<thisbox->count;z++) |
8502 { | 8632 { |
8503 if(thisitem[z].hwnd == object) | 8633 if(thisitem[z].hwnd == object) |
8504 index = z; | 8634 index = z; |