comparison mac/dw.m @ 656:6c8b95ca877b

Comboboxes implemented.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 23 Feb 2011 20:45:50 +0000
parents 27eb39d2577b
children f31a47b055f8
comparison
equal deleted inserted replaced
655:27eb39d2577b 656:6c8b95ca877b
447 @implementation DWContainer 447 @implementation DWContainer
448 -(void *)userdata { return userdata; } 448 -(void *)userdata { return userdata; }
449 -(void)setUserdata:(void *)input { userdata = input; } 449 -(void)setUserdata:(void *)input { userdata = input; }
450 @end 450 @end
451 451
452 /* Subclass for a Container/List type */ 452 /* Subclass for a Calendar type */
453 @interface DWCalendar : NSDatePicker 453 @interface DWCalendar : NSDatePicker
454 { 454 {
455 void *userdata; 455 void *userdata;
456 } 456 }
457 -(void *)userdata; 457 -(void *)userdata;
458 -(void)setUserdata:(void *)input; 458 -(void)setUserdata:(void *)input;
459 @end 459 @end
460 460
461 @implementation DWCalendar 461 @implementation DWCalendar
462 -(void *)userdata { return userdata; }
463 -(void)setUserdata:(void *)input { userdata = input; }
464 @end
465
466 /* Subclass for a Combobox type */
467 @interface DWComboBox : NSComboBox
468 {
469 void *userdata;
470 }
471 -(void *)userdata;
472 -(void)setUserdata:(void *)input;
473 @end
474
475 @implementation DWComboBox
462 -(void *)userdata { return userdata; } 476 -(void *)userdata { return userdata; }
463 -(void)setUserdata:(void *)input { userdata = input; } 477 -(void)setUserdata:(void *)input { userdata = input; }
464 @end 478 @end
465 479
466 typedef struct 480 typedef struct
1881 * Parameters: 1895 * Parameters:
1882 * handle: Handle to the checkbox to be queried. 1896 * handle: Handle to the checkbox to be queried.
1883 */ 1897 */
1884 int API dw_checkbox_get(HWND handle) 1898 int API dw_checkbox_get(HWND handle)
1885 { 1899 {
1886 NSLog(@"dw_checkbox_set() unimplemented\n"); 1900 DWButton *button = handle;
1887 return 0; 1901 if([button state])
1902 {
1903 return TRUE;
1904 }
1905 return FALSE;
1888 } 1906 }
1889 1907
1890 /* 1908 /*
1891 * Sets the state of the checkbox. 1909 * Sets the state of the checkbox.
1892 * Parameters: 1910 * Parameters:
1893 * handle: Handle to the checkbox to be queried. 1911 * handle: Handle to the checkbox to be queried.
1894 * value: TRUE for checked, FALSE for unchecked. 1912 * value: TRUE for checked, FALSE for unchecked.
1895 */ 1913 */
1896 void API dw_checkbox_set(HWND handle, int value) 1914 void API dw_checkbox_set(HWND handle, int value)
1897 { 1915 {
1898 NSLog(@"dw_checkbox_set() unimplemented\n"); 1916 DWButton *button = handle;
1917 if(value)
1918 {
1919 [button setState:NSOnState];
1920 }
1921 else
1922 {
1923 [button setState:NSOffState];
1924 }
1925
1899 } 1926 }
1900 1927
1901 /* 1928 /*
1902 * Create a new listbox window (widget) to be packed. 1929 * Create a new listbox window (widget) to be packed.
1903 * Parameters: 1930 * Parameters:
1916 * handle: Handle to the listbox to be appended to. 1943 * handle: Handle to the listbox to be appended to.
1917 * text: Text to append into listbox. 1944 * text: Text to append into listbox.
1918 */ 1945 */
1919 void API dw_listbox_append(HWND handle, char *text) 1946 void API dw_listbox_append(HWND handle, char *text)
1920 { 1947 {
1921 NSLog(@"dw_listbox_append() unimplemented\n"); 1948 id object = handle;
1949
1950 if([object isMemberOfClass:[DWComboBox class]])
1951 {
1952 DWComboBox *combo = handle;
1953
1954 [combo addItemWithObjectValue:[ NSString stringWithUTF8String:text ]];
1955 }
1922 } 1956 }
1923 1957
1924 /* 1958 /*
1925 * Inserts the specified text into the listbox's (or combobox) entry list. 1959 * Inserts the specified text into the listbox's (or combobox) entry list.
1926 * Parameters: 1960 * Parameters:
1928 * text: Text to insert into listbox. 1962 * text: Text to insert into listbox.
1929 * pos: 0-based position to insert text 1963 * pos: 0-based position to insert text
1930 */ 1964 */
1931 void API dw_listbox_insert(HWND handle, char *text, int pos) 1965 void API dw_listbox_insert(HWND handle, char *text, int pos)
1932 { 1966 {
1933 NSLog(@"dw_listbox_insert() unimplemented\n"); 1967 id object = handle;
1968
1969 if([object isMemberOfClass:[DWComboBox class]])
1970 {
1971 DWComboBox *combo = handle;
1972
1973 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:text ] atIndex:pos];
1974 }
1934 } 1975 }
1935 1976
1936 /* 1977 /*
1937 * Appends the specified text items to the listbox's (or combobox) entry list. 1978 * Appends the specified text items to the listbox's (or combobox) entry list.
1938 * Parameters: 1979 * Parameters:
1940 * text: Text strings to append into listbox. 1981 * text: Text strings to append into listbox.
1941 * count: Number of text strings to append 1982 * count: Number of text strings to append
1942 */ 1983 */
1943 void API dw_listbox_list_append(HWND handle, char **text, int count) 1984 void API dw_listbox_list_append(HWND handle, char **text, int count)
1944 { 1985 {
1945 NSLog(@"dw_listbox_list_append() unimplemented\n"); 1986 id object = handle;
1987
1988 if([object isMemberOfClass:[DWComboBox class]])
1989 {
1990 DWComboBox *combo = handle;
1991 int z;
1992
1993 for(z=0;z<count;z++)
1994 {
1995 [combo addItemWithObjectValue:[ NSString stringWithUTF8String:text[z] ]];
1996 }
1997 }
1946 } 1998 }
1947 1999
1948 /* 2000 /*
1949 * Clears the listbox's (or combobox) list of all entries. 2001 * Clears the listbox's (or combobox) list of all entries.
1950 * Parameters: 2002 * Parameters:
1951 * handle: Handle to the listbox to be cleared. 2003 * handle: Handle to the listbox to be cleared.
1952 */ 2004 */
1953 void API dw_listbox_clear(HWND handle) 2005 void API dw_listbox_clear(HWND handle)
1954 { 2006 {
1955 NSLog(@"dw_listbox_clear() unimplemented\n"); 2007 id object = handle;
2008
2009 if([object isMemberOfClass:[DWComboBox class]])
2010 {
2011 DWComboBox *combo = handle;
2012
2013 [combo removeAllItems];
2014 }
1956 } 2015 }
1957 2016
1958 /* 2017 /*
1959 * Returns the listbox's item count. 2018 * Returns the listbox's item count.
1960 * Parameters: 2019 * Parameters:
1961 * handle: Handle to the listbox to be cleared. 2020 * handle: Handle to the listbox to be cleared.
1962 */ 2021 */
1963 int API dw_listbox_count(HWND handle) 2022 int API dw_listbox_count(HWND handle)
1964 { 2023 {
1965 NSLog(@"dw_listbox_count() unimplemented\n"); 2024 id object = handle;
2025
2026 if([object isMemberOfClass:[DWComboBox class]])
2027 {
2028 DWComboBox *combo = handle;
2029
2030 return [combo numberOfItems];
2031 }
1966 return 0; 2032 return 0;
1967 } 2033 }
1968 2034
1969 /* 2035 /*
1970 * Sets the topmost item in the viewport. 2036 * Sets the topmost item in the viewport.
1972 * handle: Handle to the listbox to be cleared. 2038 * handle: Handle to the listbox to be cleared.
1973 * top: Index to the top item. 2039 * top: Index to the top item.
1974 */ 2040 */
1975 void API dw_listbox_set_top(HWND handle, int top) 2041 void API dw_listbox_set_top(HWND handle, int top)
1976 { 2042 {
1977 NSLog(@"dw_listbox_set_top() unimplemented\n"); 2043 id object = handle;
2044
2045 if([object isMemberOfClass:[DWComboBox class]])
2046 {
2047 DWComboBox *combo = handle;
2048
2049 [combo scrollItemAtIndexToTop:top];
2050 }
1978 } 2051 }
1979 2052
1980 /* 2053 /*
1981 * Copies the given index item's text into buffer. 2054 * Copies the given index item's text into buffer.
1982 * Parameters: 2055 * Parameters:
1985 * buffer: Buffer where text will be copied. 2058 * buffer: Buffer where text will be copied.
1986 * length: Length of the buffer (including NULL). 2059 * length: Length of the buffer (including NULL).
1987 */ 2060 */
1988 void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length) 2061 void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length)
1989 { 2062 {
1990 NSLog(@"dw_listbox_get_text() unimplemented\n"); 2063 id object = handle;
2064
2065 if([object isMemberOfClass:[DWComboBox class]])
2066 {
2067 DWComboBox *combo = handle;
2068 NSString *nstr = [combo itemObjectValueAtIndex:index];
2069 strncpy(buffer, [ nstr UTF8String ], length - 1);
2070 }
1991 } 2071 }
1992 2072
1993 /* 2073 /*
1994 * Sets the text of a given listbox entry. 2074 * Sets the text of a given listbox entry.
1995 * Parameters: 2075 * Parameters:
1997 * index: Index into the list to be queried. 2077 * index: Index into the list to be queried.
1998 * buffer: Buffer where text will be copied. 2078 * buffer: Buffer where text will be copied.
1999 */ 2079 */
2000 void API dw_listbox_set_text(HWND handle, unsigned int index, char *buffer) 2080 void API dw_listbox_set_text(HWND handle, unsigned int index, char *buffer)
2001 { 2081 {
2002 NSLog(@"dw_listbox_set_text() unimplemented\n"); 2082 id object = handle;
2083
2084 if([object isMemberOfClass:[DWComboBox class]])
2085 {
2086 DWComboBox *combo = handle;
2087
2088 [combo removeItemAtIndex:pos];
2089 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:bufer ] atIndex:pos];
2090 }
2003 } 2091 }
2004 2092
2005 /* 2093 /*
2006 * Returns the index to the item in the list currently selected. 2094 * Returns the index to the item in the list currently selected.
2007 * Parameters: 2095 * Parameters:
2008 * handle: Handle to the listbox to be queried. 2096 * handle: Handle to the listbox to be queried.
2009 */ 2097 */
2010 unsigned int API dw_listbox_selected(HWND handle) 2098 unsigned int API dw_listbox_selected(HWND handle)
2011 { 2099 {
2012 NSLog(@"dw_listbox_selected() unimplemented\n"); 2100 id object = handle;
2013 return 0; 2101
2102 if([object isMemberOfClass:[DWComboBox class]])
2103 {
2104 DWComboBox *combo = handle;
2105 return [combo indexOfSelectedItem];
2106 }
2107 return -1;
2014 } 2108 }
2015 2109
2016 /* 2110 /*
2017 * Returns the index to the current selected item or -1 when done. 2111 * Returns the index to the current selected item or -1 when done.
2018 * Parameters: 2112 * Parameters:
2032 * index: Item index. 2126 * index: Item index.
2033 * state: TRUE if selected FALSE if unselected. 2127 * state: TRUE if selected FALSE if unselected.
2034 */ 2128 */
2035 void API dw_listbox_select(HWND handle, int index, int state) 2129 void API dw_listbox_select(HWND handle, int index, int state)
2036 { 2130 {
2037 NSLog(@"dw_listbox_select() unimplemented\n"); 2131 id object = handle;
2132
2133 if([object isMemberOfClass:[DWComboBox class]])
2134 {
2135 DWComboBox *combo = handle;
2136 if(state)
2137 [combo selectItemAtIndex:index];
2138 else
2139 [combo deselectItemAtIndex:index];
2140 }
2038 } 2141 }
2039 2142
2040 /* 2143 /*
2041 * Deletes the item with given index from the list. 2144 * Deletes the item with given index from the list.
2042 * Parameters: 2145 * Parameters:
2043 * handle: Handle to the listbox to be set. 2146 * handle: Handle to the listbox to be set.
2044 * index: Item index. 2147 * index: Item index.
2045 */ 2148 */
2046 void API dw_listbox_delete(HWND handle, int index) 2149 void API dw_listbox_delete(HWND handle, int index)
2047 { 2150 {
2048 NSLog(@"dw_listbox_delete() unimplemented\n"); 2151 id object = handle;
2152
2153 if([object isMemberOfClass:[DWComboBox class]])
2154 {
2155 DWComboBox *combo = handle;
2156
2157 [combo removeItemAtIndex:index];
2158 }
2049 } 2159 }
2050 2160
2051 /* 2161 /*
2052 * Create a new Combobox window (widget) to be packed. 2162 * Create a new Combobox window (widget) to be packed.
2053 * Parameters: 2163 * Parameters:
2054 * text: The default text to be in the combpbox widget. 2164 * text: The default text to be in the combpbox widget.
2055 * id: An ID to be used with dw_window_from_id() or 0L. 2165 * id: An ID to be used with dw_window_from_id() or 0L.
2056 */ 2166 */
2057 HWND API dw_combobox_new(char *text, ULONG id) 2167 HWND API dw_combobox_new(char *text, ULONG id)
2058 { 2168 {
2059 NSLog(@"dw_combobox_new() unimplemented\n"); 2169 DWComboBox *combo = [[DWComboBox alloc] init];
2060 return HWND_DESKTOP; 2170 return combo;
2061 } 2171 }
2062 2172
2063 /* 2173 /*
2064 * Create a new Multiline Editbox window (widget) to be packed. 2174 * Create a new Multiline Editbox window (widget) to be packed.
2065 * Parameters: 2175 * Parameters: