Mercurial > dwindows
comparison template/dw.c @ 1089:b58032a619b9
Added new functions for 2.1 to the template, and updated the box packing examples to use the new unified method to reduce redundancy.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 28 Jun 2011 20:30:29 +0000 |
parents | 9af693aafa93 |
children | 03cd2f3e929d |
comparison
equal
deleted
inserted
replaced
1088:97c221691665 | 1089:b58032a619b9 |
---|---|
668 int API dw_scrollbox_get_range(HWND handle, int orient) | 668 int API dw_scrollbox_get_range(HWND handle, int orient) |
669 { | 669 { |
670 return 0; | 670 return 0; |
671 } | 671 } |
672 | 672 |
673 /* | 673 /* Internal box packing function called by the other 3 functions */ |
674 * Pack windows (widgets) into a box from the end (or bottom). | 674 void _dw_box_pack(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad, char *funcname) |
675 { | |
676 Box *thisbox; | |
677 int z, x = 0; | |
678 Item *tmpitem, *thisitem; | |
679 | |
680 thisbox = _dw_get_window_pointer(box); | |
681 thisitem = thisbox->items; | |
682 | |
683 /* Do some sanity bounds checking */ | |
684 if(index < 0) | |
685 index = 0; | |
686 if(index > thisbox->count) | |
687 index = thisbox->count; | |
688 | |
689 /* Duplicate the existing data */ | |
690 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | |
691 | |
692 for(z=0;z<thisbox->count;z++) | |
693 { | |
694 if(z == index) | |
695 x++; | |
696 tmpitem[x] = thisitem[z]; | |
697 x++; | |
698 } | |
699 | |
700 /* Sanity checks */ | |
701 if(vsize && !height) | |
702 height = 1; | |
703 if(hsize && !width) | |
704 width = 1; | |
705 | |
706 /* Fill in the item data appropriately */ | |
707 if(0 /* Test to see if "item" is a box */) | |
708 tmpitem[index].type = TYPEBOX; | |
709 else | |
710 tmpitem[index].type = TYPEITEM; | |
711 | |
712 tmpitem[index].hwnd = item; | |
713 tmpitem[index].origwidth = tmpitem[index].width = width; | |
714 tmpitem[index].origheight = tmpitem[index].height = height; | |
715 tmpitem[index].pad = pad; | |
716 if(hsize) | |
717 tmpitem[index].hsize = SIZEEXPAND; | |
718 else | |
719 tmpitem[index].hsize = SIZESTATIC; | |
720 | |
721 if(vsize) | |
722 tmpitem[index].vsize = SIZEEXPAND; | |
723 else | |
724 tmpitem[index].vsize = SIZESTATIC; | |
725 | |
726 thisbox->items = tmpitem; | |
727 | |
728 /* Update the item count */ | |
729 thisbox->count++; | |
730 | |
731 /* Add the item to the box */ | |
732 #if 0 | |
733 /* Platform specific code to add item to box */ | |
734 BoxAdd(box, item); | |
735 #endif | |
736 | |
737 /* Free the old data */ | |
738 if(thisbox->count) | |
739 free(thisitem); | |
740 } | |
741 | |
742 /* | |
743 * Pack windows (widgets) into a box at an arbitrary location. | |
744 * Parameters: | |
745 * box: Window handle of the box to be packed into. | |
746 * item: Window handle of the item to be back. | |
747 * index: 0 based index of packed items. | |
748 * width: Width in pixels of the item or -1 to be self determined. | |
749 * height: Height in pixels of the item or -1 to be self determined. | |
750 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. | |
751 * vsize: TRUE if the window (widget) should expand vertically to fill space given. | |
752 * pad: Number of pixels of padding around the item. | |
753 */ | |
754 void API dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad) | |
755 { | |
756 _dw_box_pack(box, item, index, width, height, hsize, vsize, pad, "dw_box_pack_at_index()"); | |
757 } | |
758 | |
759 /* | |
760 * Pack windows (widgets) into a box from the start (or top). | |
675 * Parameters: | 761 * Parameters: |
676 * box: Window handle of the box to be packed into. | 762 * box: Window handle of the box to be packed into. |
677 * item: Window handle of the item to be back. | 763 * item: Window handle of the item to be back. |
678 * width: Width in pixels of the item or -1 to be self determined. | 764 * width: Width in pixels of the item or -1 to be self determined. |
679 * height: Height in pixels of the item or -1 to be self determined. | 765 * height: Height in pixels of the item or -1 to be self determined. |
680 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. | 766 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. |
681 * vsize: TRUE if the window (widget) should expand vertically to fill space given. | 767 * vsize: TRUE if the window (widget) should expand vertically to fill space given. |
682 * pad: Number of pixels of padding around the item. | 768 * pad: Number of pixels of padding around the item. |
683 */ | 769 */ |
684 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | 770 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) |
685 { | 771 { |
686 Box *thisbox; | 772 /* 65536 is the table limit on GTK... |
687 int z; | 773 * seems like a high enough value we will never hit it here either. |
688 Item *tmpitem, *thisitem; | 774 */ |
689 | 775 _dw_box_pack(box, item, 65536, width, height, hsize, vsize, pad, "dw_box_pack_start()"); |
690 thisbox = _dw_get_window_pointer(box); | 776 } |
691 thisitem = thisbox->items; | 777 |
692 | 778 /* |
693 /* Duplicate the existing data */ | 779 * Pack windows (widgets) into a box from the end (or bottom). |
694 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | |
695 | |
696 for(z=0;z<thisbox->count;z++) | |
697 { | |
698 tmpitem[z+1] = thisitem[z]; | |
699 } | |
700 | |
701 /* Sanity checks */ | |
702 if(vsize && !height) | |
703 height = 1; | |
704 if(hsize && !width) | |
705 width = 1; | |
706 | |
707 /* Fill in the item data appropriately */ | |
708 if(0 /* Test to see if "item" is a box */) | |
709 tmpitem[0].type = TYPEBOX; | |
710 else | |
711 tmpitem[0].type = TYPEITEM; | |
712 | |
713 tmpitem[0].hwnd = item; | |
714 tmpitem[0].origwidth = tmpitem[0].width = width; | |
715 tmpitem[0].origheight = tmpitem[0].height = height; | |
716 tmpitem[0].pad = pad; | |
717 if(hsize) | |
718 tmpitem[0].hsize = SIZEEXPAND; | |
719 else | |
720 tmpitem[0].hsize = SIZESTATIC; | |
721 | |
722 if(vsize) | |
723 tmpitem[0].vsize = SIZEEXPAND; | |
724 else | |
725 tmpitem[0].vsize = SIZESTATIC; | |
726 | |
727 thisbox->items = tmpitem; | |
728 | |
729 /* Update the item count */ | |
730 thisbox->count++; | |
731 | |
732 /* Add the item to the box */ | |
733 #if 0 | |
734 /* Platform specific code to add item to box */ | |
735 BoxAdd(box, item); | |
736 #endif | |
737 | |
738 /* Free the old data */ | |
739 if(thisbox->count) | |
740 free(thisitem); | |
741 } | |
742 | |
743 /* | |
744 * Pack windows (widgets) into a box from the start (or top). | |
745 * Parameters: | 780 * Parameters: |
746 * box: Window handle of the box to be packed into. | 781 * box: Window handle of the box to be packed into. |
747 * item: Window handle of the item to be back. | 782 * item: Window handle of the item to be back. |
748 * width: Width in pixels of the item or -1 to be self determined. | 783 * width: Width in pixels of the item or -1 to be self determined. |
749 * height: Height in pixels of the item or -1 to be self determined. | 784 * height: Height in pixels of the item or -1 to be self determined. |
750 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. | 785 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. |
751 * vsize: TRUE if the window (widget) should expand vertically to fill space given. | 786 * vsize: TRUE if the window (widget) should expand vertically to fill space given. |
752 * pad: Number of pixels of padding around the item. | 787 * pad: Number of pixels of padding around the item. |
753 */ | 788 */ |
754 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) | 789 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) |
755 { | 790 { |
756 Box *thisbox; | 791 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()"); |
757 int z; | |
758 Item *tmpitem, *thisitem; | |
759 | |
760 thisbox = _dw_get_window_pointer(box); | |
761 thisitem = thisbox->items; | |
762 | |
763 /* Duplicate the existing data */ | |
764 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | |
765 | |
766 for(z=0;z<thisbox->count;z++) | |
767 { | |
768 tmpitem[z] = thisitem[z]; | |
769 } | |
770 | |
771 /* Sanity checks */ | |
772 if(vsize && !height) | |
773 height = 1; | |
774 if(hsize && !width) | |
775 width = 1; | |
776 | |
777 /* Fill in the item data appropriately */ | |
778 if(0 /* Test to see if "item" is a box */) | |
779 tmpitem[thisbox->count].type = TYPEBOX; | |
780 else | |
781 tmpitem[thisbox->count].type = TYPEITEM; | |
782 | |
783 tmpitem[thisbox->count].hwnd = item; | |
784 tmpitem[thisbox->count].origwidth = tmpitem[thisbox->count].width = width; | |
785 tmpitem[thisbox->count].origheight = tmpitem[thisbox->count].height = height; | |
786 tmpitem[thisbox->count].pad = pad; | |
787 if(hsize) | |
788 tmpitem[thisbox->count].hsize = SIZEEXPAND; | |
789 else | |
790 tmpitem[thisbox->count].hsize = SIZESTATIC; | |
791 | |
792 if(vsize) | |
793 tmpitem[thisbox->count].vsize = SIZEEXPAND; | |
794 else | |
795 tmpitem[thisbox->count].vsize = SIZESTATIC; | |
796 | |
797 thisbox->items = tmpitem; | |
798 | |
799 /* Update the item count */ | |
800 thisbox->count++; | |
801 | |
802 /* Add the item to the box */ | |
803 #if 0 | |
804 /* Platform specific code to add item to box */ | |
805 BoxAdd(box, item); | |
806 #endif | |
807 | |
808 /* Free the old data */ | |
809 if(thisbox->count) | |
810 free(thisitem); | |
811 } | 792 } |
812 | 793 |
813 /* | 794 /* |
814 * Create a new button window (widget) to be packed. | 795 * Create a new button window (widget) to be packed. |
815 * Parameters: | 796 * Parameters: |
2679 * A malloc()ed font name string to be dw_free()ed or NULL on error. | 2660 * A malloc()ed font name string to be dw_free()ed or NULL on error. |
2680 */ | 2661 */ |
2681 char * API dw_window_get_font(HWND handle) | 2662 char * API dw_window_get_font(HWND handle) |
2682 { | 2663 { |
2683 return NULL; | 2664 return NULL; |
2665 } | |
2666 | |
2667 /* Allows the user to choose a font using the system's font chooser dialog. | |
2668 * Parameters: | |
2669 * currfont: current font | |
2670 * Returns: | |
2671 * A malloced buffer with the selected font or NULL on error. | |
2672 */ | |
2673 char * API dw_font_choose(char *currfont) | |
2674 { | |
2675 return NULL; | |
2676 } | |
2677 | |
2678 /* | |
2679 * Sets the default font used on text based widgets. | |
2680 * Parameters: | |
2681 * fontname: Font name in Dynamic Windows format. | |
2682 */ | |
2683 void API dw_font_set_default(char *fontname) | |
2684 { | |
2684 } | 2685 } |
2685 | 2686 |
2686 /* | 2687 /* |
2687 * Destroys a window and all of it's children. | 2688 * Destroys a window and all of it's children. |
2688 * Parameters: | 2689 * Parameters: |