comparison ios/dw.m @ 2540:1c17472a175a

iOS: Implement scrollbars as sliders... implement vertical with a transform. Also add a gray border on status text.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 12 May 2021 09:19:41 +0000
parents 457c91634881
children 2ee4df2c50bf
comparison
equal deleted inserted replaced
2539:822f814a54f4 2540:1c17472a175a
1963 1963
1964 /* Subclass for a slider type */ 1964 /* Subclass for a slider type */
1965 @interface DWSlider : UISlider 1965 @interface DWSlider : UISlider
1966 { 1966 {
1967 void *userdata; 1967 void *userdata;
1968 } 1968 BOOL vertical;
1969 }
1970 -(void)setVertical:(BOOL)vert;
1971 -(BOOL)vertical;
1969 -(void *)userdata; 1972 -(void *)userdata;
1970 -(void)setUserdata:(void *)input; 1973 -(void)setUserdata:(void *)input;
1971 -(void)sliderChanged:(id)sender; 1974 -(void)sliderChanged:(id)sender;
1972 @end 1975 @end
1973 1976
1974 @implementation DWSlider 1977 @implementation DWSlider
1978 -(void)setVertical:(BOOL)vert
1979 {
1980 if(vert)
1981 {
1982 CGAffineTransform trans = CGAffineTransformMakeRotation(M_PI * 0.5);
1983 self.transform = trans;
1984 }
1985 vertical = vert;
1986 }
1987 -(BOOL)vertical { return vertical; }
1975 -(void *)userdata { return userdata; } 1988 -(void *)userdata { return userdata; }
1976 -(void)setUserdata:(void *)input { userdata = input; } 1989 -(void)setUserdata:(void *)input { userdata = input; }
1977 -(void)sliderChanged:(id)sender { int intVal = (int)[self value]; _dw_event_handler(self, DW_INT_TO_POINTER(intVal), 14); } 1990 -(void)sliderChanged:(id)sender { int intVal = (int)[self value]; _dw_event_handler(self, DW_INT_TO_POINTER(intVal), 14); }
1978 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1991 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1979 @end 1992 @end
4344 * Parameters: 4357 * Parameters:
4345 * vertical: TRUE or FALSE if slider is vertical. 4358 * vertical: TRUE or FALSE if slider is vertical.
4346 * increments: Number of increments available. 4359 * increments: Number of increments available.
4347 * id: An ID to be used with dw_window_from_id() or 0L. 4360 * id: An ID to be used with dw_window_from_id() or 0L.
4348 */ 4361 */
4349 DW_FUNCTION_DEFINITION(dw_slider_new, HWND, int DW_UNUSED(vertical), int increments, ULONG cid) 4362 DW_FUNCTION_DEFINITION(dw_slider_new, HWND, int vertical, int increments, ULONG cid)
4350 DW_FUNCTION_ADD_PARAM3(vertical, increments, cid) 4363 DW_FUNCTION_ADD_PARAM3(vertical, increments, cid)
4351 DW_FUNCTION_RETURN(dw_slider_new, HWND) 4364 DW_FUNCTION_RETURN(dw_slider_new, HWND)
4352 DW_FUNCTION_RESTORE_PARAM3(DW_UNUSED(vertical), int, increments, int, cid, ULONG) 4365 DW_FUNCTION_RESTORE_PARAM3(vertical, int, increments, int, cid, ULONG)
4353 { 4366 {
4354 DWSlider *slider = [[[DWSlider alloc] init] retain]; 4367 DWSlider *slider = [[[DWSlider alloc] init] retain];
4355 [slider setMaximumValue:(double)increments]; 4368 [slider setMaximumValue:(double)increments];
4356 [slider setMinimumValue:0]; 4369 [slider setMinimumValue:0];
4357 [slider setContinuous:YES]; 4370 [slider setContinuous:YES];
4358 [slider addTarget:slider 4371 [slider addTarget:slider
4359 action:@selector(sliderChanged:) 4372 action:@selector(sliderChanged:)
4360 forControlEvents:UIControlEventValueChanged]; 4373 forControlEvents:UIControlEventValueChanged];
4361 [slider setTag:cid]; 4374 [slider setTag:cid];
4375 [slider setVertical:(vertical ? YES : NO)];
4362 DW_FUNCTION_RETURN_THIS(slider); 4376 DW_FUNCTION_RETURN_THIS(slider);
4363 } 4377 }
4364 4378
4365 /* 4379 /*
4366 * Returns the position of the slider. 4380 * Returns the position of the slider.
4393 * increments: Number of increments available. 4407 * increments: Number of increments available.
4394 * id: An ID to be used with dw_window_from_id() or 0L. 4408 * id: An ID to be used with dw_window_from_id() or 0L.
4395 */ 4409 */
4396 HWND API dw_scrollbar_new(int vertical, ULONG cid) 4410 HWND API dw_scrollbar_new(int vertical, ULONG cid)
4397 { 4411 {
4398 /*TODO: Implement scrollbars if possible */ 4412 return dw_slider_new(vertical, 1, cid);
4399 return 0;
4400 } 4413 }
4401 4414
4402 /* 4415 /*
4403 * Returns the position of the scrollbar. 4416 * Returns the position of the scrollbar.
4404 * Parameters: 4417 * Parameters:
4405 * handle: Handle to the scrollbar to be queried. 4418 * handle: Handle to the scrollbar to be queried.
4406 */ 4419 */
4407 unsigned int API dw_scrollbar_get_pos(HWND handle) 4420 unsigned int API dw_scrollbar_get_pos(HWND handle)
4408 { 4421 {
4409 /*TODO: Implement scrollbars if possible */ 4422 return dw_slider_get_pos(handle);
4410 return 0;
4411 } 4423 }
4412 4424
4413 /* 4425 /*
4414 * Sets the scrollbar position. 4426 * Sets the scrollbar position.
4415 * Parameters: 4427 * Parameters:
4416 * handle: Handle to the scrollbar to be set. 4428 * handle: Handle to the scrollbar to be set.
4417 * position: Position of the scrollbar withing the range. 4429 * position: Position of the scrollbar withing the range.
4418 */ 4430 */
4419 void API dw_scrollbar_set_pos(HWND handle, unsigned int position) 4431 void API dw_scrollbar_set_pos(HWND handle, unsigned int position)
4420 { 4432 {
4421 /*TODO: Implement scrollbars if possible */ 4433 dw_slider_set_pos(handle, position);
4422 } 4434 }
4423 4435
4424 /* 4436 /*
4425 * Sets the scrollbar range. 4437 * Sets the scrollbar range.
4426 * Parameters: 4438 * Parameters:
4428 * range: Maximum range value. 4440 * range: Maximum range value.
4429 * visible: Visible area relative to the range. 4441 * visible: Visible area relative to the range.
4430 */ 4442 */
4431 void API dw_scrollbar_set_range(HWND handle, unsigned int range, unsigned int visible) 4443 void API dw_scrollbar_set_range(HWND handle, unsigned int range, unsigned int visible)
4432 { 4444 {
4433 /*TODO: Implement scrollbars if possible */ 4445 DWSlider *slider = handle;
4446 [slider setMaximumValue:(double)range];
4434 } 4447 }
4435 4448
4436 /* 4449 /*
4437 * Create a new percent bar window (widget) to be packed. 4450 * Create a new percent bar window (widget) to be packed.
4438 * Parameters: 4451 * Parameters:
5276 * Create a new status text window (widget) to be packed. 5289 * Create a new status text window (widget) to be packed.
5277 * Parameters: 5290 * Parameters:
5278 * text: The text to be display by the static text widget. 5291 * text: The text to be display by the static text widget.
5279 * id: An ID to be used with dw_window_from_id() or 0L. 5292 * id: An ID to be used with dw_window_from_id() or 0L.
5280 */ 5293 */
5281 HWND API dw_status_text_new(const char *text, ULONG cid) 5294 DW_FUNCTION_DEFINITION(dw_status_text_new, HWND, const char *text, ULONG cid)
5282 { 5295 DW_FUNCTION_ADD_PARAM2(text, cid)
5283 return dw_text_new(text, cid); 5296 DW_FUNCTION_RETURN(dw_status_text_new, HWND)
5297 DW_FUNCTION_RESTORE_PARAM2(text, const char *, cid, ULONG)
5298 {
5299 DWText *textfield = [[[DWText alloc] init] retain];
5300 [textfield setText:[NSString stringWithUTF8String:text]];
5301 [textfield setTag:cid];
5302 if(DWDefaultFont)
5303 {
5304 [textfield setFont:DWDefaultFont];
5305 }
5306 [textfield layer].borderWidth = 2.0;
5307 [textfield layer].borderColor = [[UIColor darkGrayColor] CGColor];
5308 DW_FUNCTION_RETURN_THIS(textfield);
5284 } 5309 }
5285 5310
5286 /* 5311 /*
5287 * Create a new static text window (widget) to be packed. 5312 * Create a new static text window (widget) to be packed.
5288 * Parameters: 5313 * Parameters: