comparison os2/dw.c @ 1766:47e503ecc812

Ported clang/Xcode fixes to Windows and OS/2 just in case.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 01 Jul 2012 07:51:25 +0000
parents 7b049aaca615
children 31edce4598d0
comparison
equal deleted inserted replaced
1765:15414cbe857f 1766:47e503ecc812
7708 Item *tmpitem, *thisitem = thisbox->items; 7708 Item *tmpitem, *thisitem = thisbox->items;
7709 char tmpbuf[100] = {0}; 7709 char tmpbuf[100] = {0};
7710 HWND frame = (HWND)dw_window_get_data(item, "_dw_combo_box"); 7710 HWND frame = (HWND)dw_window_get_data(item, "_dw_combo_box");
7711 7711
7712 /* Do some sanity bounds checking */ 7712 /* Do some sanity bounds checking */
7713 if(!thisitem)
7714 thisbox->count = 0;
7713 if(index < 0) 7715 if(index < 0)
7714 index = 0; 7716 index = 0;
7715 if(index > thisbox->count) 7717 if(index > thisbox->count)
7716 index = thisbox->count; 7718 index = thisbox->count;
7717 7719
7718 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); 7720 tmpitem = calloc(sizeof(Item), (thisbox->count+1));
7719 7721
7720 for(z=0;z<thisbox->count;z++) 7722 for(z=0;z<thisbox->count;z++)
7721 { 7723 {
7722 if(z == index) 7724 if(z == index)
7723 x++; 7725 x++;
7724 tmpitem[x] = thisitem[z]; 7726 tmpitem[x] = thisitem[z];
7725 x++; 7727 x++;
7726 } 7728 }
7727
7728 7729
7729 WinQueryClassName(item, 99, (PCH)tmpbuf); 7730 WinQueryClassName(item, 99, (PCH)tmpbuf);
7730 7731
7731 if(vsize && !height) 7732 if(vsize && !height)
7732 height = 1; 7733 height = 1;
7756 if(width == -1 || height == -1) 7757 if(width == -1 || height == -1)
7757 _control_size(item, width == -1 ? &tmpitem[index].width : NULL, height == -1 ? &tmpitem[index].height : NULL); 7758 _control_size(item, width == -1 ? &tmpitem[index].width : NULL, height == -1 ? &tmpitem[index].height : NULL);
7758 7759
7759 thisbox->items = tmpitem; 7760 thisbox->items = tmpitem;
7760 7761
7761 if(thisbox->count) 7762 if(thisitem)
7762 free(thisitem); 7763 free(thisitem);
7763 7764
7764 thisbox->count++; 7765 thisbox->count++;
7765 7766
7766 WinQueryClassName(item, 99, (PCH)tmpbuf); 7767 WinQueryClassName(item, 99, (PCH)tmpbuf);
7796 * try to remove it from the layout 7797 * try to remove it from the layout
7797 */ 7798 */
7798 if(thisbox && thisbox->count) 7799 if(thisbox && thisbox->count)
7799 { 7800 {
7800 int z, index = -1; 7801 int z, index = -1;
7801 Item *tmpitem, *thisitem = thisbox->items; 7802 Item *tmpitem = NULL, *thisitem = thisbox->items;
7802 7803
7804 if(!thisitem)
7805 thisbox->count = 0;
7806
7803 for(z=0;z<thisbox->count;z++) 7807 for(z=0;z<thisbox->count;z++)
7804 { 7808 {
7805 if(thisitem[z].hwnd == handle) 7809 if(thisitem[z].hwnd == handle)
7806 index = z; 7810 index = z;
7807 } 7811 }
7808 7812
7809 if(index == -1) 7813 if(index == -1)
7810 return DW_ERROR_GENERAL; 7814 return DW_ERROR_GENERAL;
7811 7815
7812 tmpitem = malloc(sizeof(Item)*(thisbox->count-1)); 7816 if(thisbox->count > 1)
7817 {
7818 tmpitem = calloc(sizeof(Item), (thisbox->count-1));
7819
7820 /* Copy all but the current entry to the new list */
7821 for(z=0;z<index;z++)
7822 {
7823 tmpitem[z] = thisitem[z];
7824 }
7825 for(z=index+1;z<thisbox->count;z++)
7826 {
7827 tmpitem[z-1] = thisitem[z];
7828 }
7829 }
7830
7831 thisbox->items = tmpitem;
7832 if(thisitem)
7833 free(thisitem);
7834 if(tmpitem)
7835 thisbox->count--;
7836 else
7837 thisbox->count = 0;
7838
7839 /* If it isn't padding, reset the parent */
7840 if(handle)
7841 WinSetParent(handle, HWND_OBJECT, FALSE);
7842 /* Queue a redraw on the top-level window */
7843 _dw_redraw(_toplevel_window(parent), TRUE);
7844 return DW_ERROR_NONE;
7845 }
7846 }
7847 return DW_ERROR_GENERAL;
7848 }
7849
7850 /*
7851 * Remove windows (widgets) from a box at an arbitrary location.
7852 * Parameters:
7853 * box: Window handle of the box to be removed from.
7854 * index: 0 based index of packed items.
7855 * Returns:
7856 * Handle to the removed item on success, 0 on failure or padding.
7857 */
7858 HWND API dw_box_remove_at_index(HWND box, int index)
7859 {
7860 Box *thisbox = WinQueryWindowPtr(box, QWP_USER);
7861
7862 /* Try to remove it from the layout */
7863 if(thisbox && index > -1 && index < thisbox->count)
7864 {
7865 int z;
7866 Item *tmpitem = NULL, *thisitem = thisbox->items;
7867 HWND handle = thisitem[index].hwnd;
7868
7869 if(thisbox->count > 1)
7870 {
7871 tmpitem = calloc(sizeof(Item), (thisbox->count-1));
7813 7872
7814 /* Copy all but the current entry to the new list */ 7873 /* Copy all but the current entry to the new list */
7815 for(z=0;z<index;z++) 7874 for(z=0;z<index;z++)
7816 { 7875 {
7817 tmpitem[z] = thisitem[z]; 7876 tmpitem[z] = thisitem[z];
7818 } 7877 }
7819 for(z=index+1;z<thisbox->count;z++) 7878 for(z=index+1;z<thisbox->count;z++)
7820 { 7879 {
7821 tmpitem[z-1] = thisitem[z]; 7880 tmpitem[z-1] = thisitem[z];
7822 } 7881 }
7823 7882 }
7824 thisbox->items = tmpitem; 7883
7884 thisbox->items = tmpitem;
7885 if(thisitem)
7825 free(thisitem); 7886 free(thisitem);
7887 if(tmpitem)
7826 thisbox->count--; 7888 thisbox->count--;
7827 /* If it isn't padding, reset the parent */ 7889 else
7828 if(handle) 7890 thisbox->count = 0;
7829 WinSetParent(handle, HWND_OBJECT, FALSE); 7891
7830 /* Queue a redraw on the top-level window */
7831 _dw_redraw(_toplevel_window(parent), TRUE);
7832 return DW_ERROR_NONE;
7833 }
7834 }
7835 return DW_ERROR_GENERAL;
7836 }
7837
7838 /*
7839 * Remove windows (widgets) from a box at an arbitrary location.
7840 * Parameters:
7841 * box: Window handle of the box to be removed from.
7842 * index: 0 based index of packed items.
7843 * Returns:
7844 * Handle to the removed item on success, 0 on failure or padding.
7845 */
7846 HWND API dw_box_remove_at_index(HWND box, int index)
7847 {
7848 Box *thisbox = WinQueryWindowPtr(box, QWP_USER);
7849
7850 /* Try to remove it from the layout */
7851 if(thisbox && index > -1 && index < thisbox->count)
7852 {
7853 int z;
7854 Item *tmpitem, *thisitem = thisbox->items;
7855 HWND handle = thisitem[index].hwnd;
7856
7857 tmpitem = malloc(sizeof(Item)*(thisbox->count-1));
7858
7859 /* Copy all but the current entry to the new list */
7860 for(z=0;z<index;z++)
7861 {
7862 tmpitem[z] = thisitem[z];
7863 }
7864 for(z=index+1;z<thisbox->count;z++)
7865 {
7866 tmpitem[z-1] = thisitem[z];
7867 }
7868
7869 thisbox->items = tmpitem;
7870 free(thisitem);
7871 thisbox->count--;
7872 /* If it isn't padding, reset the parent */ 7892 /* If it isn't padding, reset the parent */
7873 if(handle) 7893 if(handle)
7874 WinSetParent(handle, HWND_OBJECT, FALSE); 7894 WinSetParent(handle, HWND_OBJECT, FALSE);
7875 /* Queue a redraw on the top-level window */ 7895 /* Queue a redraw on the top-level window */
7876 _dw_redraw(_toplevel_window(box), TRUE); 7896 _dw_redraw(_toplevel_window(box), TRUE);