comparison mac/dw.m @ 2186:25fc0f438c6d

Mac: Attempt to fix cell clipping/visibility issues by fully enabling autosizing on all cells, and only forcing cell layout changes on combination image/text cells. Also some general code cleanup.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 14 Oct 2020 23:44:25 +0000
parents 8f9a44279ff0
children 6740154cec68
comparison
equal deleted inserted replaced
2185:2a52d9fc2de4 2186:25fc0f438c6d
2366 NSTableCellView *browsercell = [[[NSTableCellView alloc] init] autorelease]; 2366 NSTableCellView *browsercell = [[[NSTableCellView alloc] init] autorelease];
2367 [browsercell setAutoresizesSubviews:YES]; 2367 [browsercell setAutoresizesSubviews:YES];
2368 if(icon) 2368 if(icon)
2369 { 2369 {
2370 NSImageView *iv = [[[NSImageView alloc] init] autorelease]; 2370 NSImageView *iv = [[[NSImageView alloc] init] autorelease];
2371 [iv setAutoresizingMask:NSViewHeightSizable]; 2371 [iv setAutoresizingMask:NSViewHeightSizable|(text ? 0 :NSViewWidthSizable)];
2372 [iv setImage:icon]; 2372 [iv setImage:icon];
2373 [browsercell setImageView:iv]; 2373 [browsercell setImageView:iv];
2374 [browsercell addSubview:iv]; 2374 [browsercell addSubview:iv];
2375 } 2375 }
2376 if(text) 2376 if(text)
2389 return browsercell; 2389 return browsercell;
2390 } 2390 }
2391 2391
2392 void _dw_table_cell_view_layout(NSTableCellView *result) 2392 void _dw_table_cell_view_layout(NSTableCellView *result)
2393 { 2393 {
2394 int width = 0; 2394 /* Adjust the frames of the textField and imageView when both are present */
2395 NSRect rect = result.frame; 2395 if([result imageView] && [result textField])
2396 {
2397 NSImageView *iv = [result imageView];
2398 NSImage *icon = [iv image];
2399 NSTextField *tf = [result textField];
2400 NSRect rect = result.frame;
2401 int width =[icon size].width;
2396 2402
2397 /* Adjust the frames of the textField and imageView */ 2403 [iv setFrame:NSMakeRect(0,0,width,rect.size.height)];
2398 if([result imageView])
2399 {
2400 NSImage *icon = [[result imageView] image];
2401 width = [icon size].width;
2402 [[result imageView] setFrame:NSMakeRect(0,0,width,rect.size.height)];
2403 }
2404 if([result textField])
2405 {
2406 2404
2407 /* Adjust the rect to allow space for the image */ 2405 /* Adjust the rect to allow space for the image */
2408 if([result imageView]) 2406 rect.origin.x += width;
2409 { 2407 rect.size.width -= width;
2410 rect.origin.x += width; 2408 [tf setFrame:rect];
2411 rect.size.width -= width;
2412 }
2413 [[result textField] setFrame:rect];
2414 } 2409 }
2415 } 2410 }
2416 #endif 2411 #endif
2417 2412
2418 /* Subclass for a Container/List type */ 2413 /* Subclass for a Container/List type */
2632 [rowView setBackgroundColor:oddcolor]; 2627 [rowView setBackgroundColor:oddcolor];
2633 } 2628 }
2634 } 2629 }
2635 -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; 2630 -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;
2636 { 2631 {
2637 /* Get an existing cell with the MyView identifier if it exists */ 2632 /* Not reusing cell views, so get the cell from our array */
2638 int index = (int)(row * [tvcols count]) + (int)[tvcols indexOfObject:tableColumn]; 2633 int index = (int)(row * [tvcols count]) + (int)[tvcols indexOfObject:tableColumn];
2639 id celldata = [data objectAtIndex:index]; 2634 id celldata = [data objectAtIndex:index];
2640 2635
2641 /* The data is already a NSTableCellView so just return that */ 2636 /* The data is already a NSTableCellView so just return that */
2642 if([celldata isMemberOfClass:[NSTableCellView class]]) 2637 if([celldata isMemberOfClass:[NSTableCellView class]])
4720 * Spinbutton: 50x(maxfontheight) 4715 * Spinbutton: 50x(maxfontheight)
4721 * Text/Status: (textwidth)x(textheight) 4716 * Text/Status: (textwidth)x(textheight)
4722 * Ranged: 100x14 or 14x100 for vertical. 4717 * Ranged: 100x14 or 14x100 for vertical.
4723 * Buttons/Bitmaps: Size of text or image and border. 4718 * Buttons/Bitmaps: Size of text or image and border.
4724 */ 4719 */
4725 void _control_size(id handle, int *width, int *height) 4720 void _dw_control_size(id handle, int *width, int *height)
4726 { 4721 {
4727 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0; 4722 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0;
4728 NSString *nsstr = nil; 4723 NSString *nsstr = nil;
4729 id object = _text_handle(handle); 4724 id object = _text_handle(handle);
4730 4725
5039 tmpitem[index].hsize = hsize ? SIZEEXPAND : SIZESTATIC; 5034 tmpitem[index].hsize = hsize ? SIZEEXPAND : SIZESTATIC;
5040 tmpitem[index].vsize = vsize ? SIZEEXPAND : SIZESTATIC; 5035 tmpitem[index].vsize = vsize ? SIZEEXPAND : SIZESTATIC;
5041 5036
5042 /* If either of the parameters are -1 ... calculate the size */ 5037 /* If either of the parameters are -1 ... calculate the size */
5043 if(width == -1 || height == -1) 5038 if(width == -1 || height == -1)
5044 _control_size(object, width == -1 ? &tmpitem[index].width : NULL, height == -1 ? &tmpitem[index].height : NULL); 5039 _dw_control_size(object, width == -1 ? &tmpitem[index].width : NULL, height == -1 ? &tmpitem[index].height : NULL);
5045 5040
5046 thisbox->items = tmpitem; 5041 thisbox->items = tmpitem;
5047 5042
5048 /* Update the item count */ 5043 /* Update the item count */
5049 thisbox->count++; 5044 thisbox->count++;
5274 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) 5269 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
5275 { 5270 {
5276 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()"); 5271 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()");
5277 } 5272 }
5278 5273
5279 HWND _button_new(const char *text, ULONG cid) 5274 /* Internal function to create a basic button, used by all button types */
5275 HWND _dw_button_new(const char *text, ULONG cid)
5280 { 5276 {
5281 DWButton *button = [[DWButton alloc] init]; 5277 DWButton *button = [[DWButton alloc] init];
5282 if(text) 5278 if(text)
5283 { 5279 {
5284 [button setTitle:[ NSString stringWithUTF8String:text ]]; 5280 [button setTitle:[ NSString stringWithUTF8String:text ]];
5303 * text: The text to be display by the static text widget. 5299 * text: The text to be display by the static text widget.
5304 * id: An ID to be used with dw_window_from_id() or 0L. 5300 * id: An ID to be used with dw_window_from_id() or 0L.
5305 */ 5301 */
5306 HWND API dw_button_new(const char *text, ULONG cid) 5302 HWND API dw_button_new(const char *text, ULONG cid)
5307 { 5303 {
5308 DWButton *button = _button_new(text, cid); 5304 DWButton *button = _dw_button_new(text, cid);
5309 [button setButtonType:DWButtonTypeMomentaryPushIn]; 5305 [button setButtonType:DWButtonTypeMomentaryPushIn];
5310 [button setBezelStyle:DWBezelStyleRounded]; 5306 [button setBezelStyle:DWBezelStyleRounded];
5311 [button setImagePosition:NSNoImage]; 5307 [button setImagePosition:NSNoImage];
5312 [button setAlignment:DWTextAlignmentCenter]; 5308 [button setAlignment:DWTextAlignmentCenter];
5313 [[button cell] setControlTint:NSBlueControlTint]; 5309 [[button cell] setControlTint:NSBlueControlTint];
5371 { 5367 {
5372 NSBundle *bundle = [NSBundle mainBundle]; 5368 NSBundle *bundle = [NSBundle mainBundle];
5373 NSString *respath = [bundle resourcePath]; 5369 NSString *respath = [bundle resourcePath];
5374 NSString *filepath = [respath stringByAppendingFormat:@"/%lu.png", resid]; 5370 NSString *filepath = [respath stringByAppendingFormat:@"/%lu.png", resid];
5375 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath]; 5371 NSImage *image = [[NSImage alloc] initWithContentsOfFile:filepath];
5376 DWButton *button = _button_new("", resid); 5372 DWButton *button = _dw_button_new("", resid);
5377 if(image) 5373 if(image)
5378 { 5374 {
5379 [button setImage:image]; 5375 [button setImage:image];
5380 } 5376 }
5381 if(text) 5377 if(text)
5403 if(!image && ext) 5399 if(!image && ext)
5404 { 5400 {
5405 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]]; 5401 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]];
5406 image = [[NSImage alloc] initWithContentsOfFile:nstr]; 5402 image = [[NSImage alloc] initWithContentsOfFile:nstr];
5407 } 5403 }
5408 DWButton *button = _button_new("", cid); 5404 DWButton *button = _dw_button_new("", cid);
5409 if(image) 5405 if(image)
5410 { 5406 {
5411 [button setImage:image]; 5407 [button setImage:image];
5412 } 5408 }
5413 if(text) 5409 if(text)
5427 */ 5423 */
5428 HWND API dw_bitmapbutton_new_from_data(const char *text, unsigned long cid, const char *data, int len) 5424 HWND API dw_bitmapbutton_new_from_data(const char *text, unsigned long cid, const char *data, int len)
5429 { 5425 {
5430 NSData *thisdata = [NSData dataWithBytes:data length:len]; 5426 NSData *thisdata = [NSData dataWithBytes:data length:len];
5431 NSImage *image = [[NSImage alloc] initWithData:thisdata]; 5427 NSImage *image = [[NSImage alloc] initWithData:thisdata];
5432 DWButton *button = _button_new("", cid); 5428 DWButton *button = _dw_button_new("", cid);
5433 if(image) 5429 if(image)
5434 { 5430 {
5435 [button setImage:image]; 5431 [button setImage:image];
5436 } 5432 }
5437 if(text) 5433 if(text)
5508 * text: The text to be display by the static text widget. 5504 * text: The text to be display by the static text widget.
5509 * id: An ID to be used with dw_window_from_id() or 0L. 5505 * id: An ID to be used with dw_window_from_id() or 0L.
5510 */ 5506 */
5511 HWND API dw_radiobutton_new(const char *text, ULONG cid) 5507 HWND API dw_radiobutton_new(const char *text, ULONG cid)
5512 { 5508 {
5513 DWButton *button = _button_new(text, cid); 5509 DWButton *button = _dw_button_new(text, cid);
5514 [button setButtonType:DWButtonTypeRadio]; 5510 [button setButtonType:DWButtonTypeRadio];
5515 return button; 5511 return button;
5516 } 5512 }
5517 5513
5518 /* 5514 /*
5690 * text: The text to be display by the static text widget. 5686 * text: The text to be display by the static text widget.
5691 * id: An ID to be used with dw_window_from_id() or 0L. 5687 * id: An ID to be used with dw_window_from_id() or 0L.
5692 */ 5688 */
5693 HWND API dw_checkbox_new(const char *text, ULONG cid) 5689 HWND API dw_checkbox_new(const char *text, ULONG cid)
5694 { 5690 {
5695 DWButton *button = _button_new(text, cid); 5691 DWButton *button = _dw_button_new(text, cid);
5696 [button setButtonType:DWButtonTypeSwitch]; 5692 [button setButtonType:DWButtonTypeSwitch];
5697 [button setBezelStyle:DWBezelStyleRegularSquare]; 5693 [button setBezelStyle:DWBezelStyleRegularSquare];
5698 return button; 5694 return button;
5699 } 5695 }
5700 5696
5731 [button setState:DWControlStateValueOff]; 5727 [button setState:DWControlStateValueOff];
5732 } 5728 }
5733 5729
5734 } 5730 }
5735 5731
5736 /* Common code for containers and listboxes */ 5732 /* Internal common function to create containers and listboxes */
5737 HWND _cont_new(ULONG cid, int multi) 5733 HWND _dw_cont_new(ULONG cid, int multi)
5738 { 5734 {
5739 NSScrollView *scrollview = [[NSScrollView alloc] init]; 5735 NSScrollView *scrollview = [[NSScrollView alloc] init];
5740 DWContainer *cont = [[DWContainer alloc] init]; 5736 DWContainer *cont = [[DWContainer alloc] init];
5741 5737
5742 [cont setScrollview:scrollview]; 5738 [cont setScrollview:scrollview];
5743 [scrollview setBorderType:NSBezelBorder]; 5739 [scrollview setBorderType:NSBezelBorder];
5744 [scrollview setHasVerticalScroller:YES]; 5740 [scrollview setHasVerticalScroller:YES];
5745 [scrollview setAutohidesScrollers:YES]; 5741 [scrollview setAutohidesScrollers:YES];
5746 5742 [cont setAllowsMultipleSelection:(multi ? YES : NO)];
5747 if(multi) 5743 [cont setAllowsColumnReordering:NO];
5748 {
5749 [cont setAllowsMultipleSelection:YES];
5750 }
5751 else
5752 {
5753 [cont setAllowsMultipleSelection:NO];
5754 }
5755 [cont setDataSource:cont]; 5744 [cont setDataSource:cont];
5756 [cont setDelegate:cont]; 5745 [cont setDelegate:cont];
5757 [scrollview setDocumentView:cont]; 5746 [scrollview setDocumentView:cont];
5758 [cont setTag:cid]; 5747 [cont setTag:cid];
5759 [cont autorelease]; 5748 [cont autorelease];
5771 DW_FUNCTION_ADD_PARAM2(cid, multi) 5760 DW_FUNCTION_ADD_PARAM2(cid, multi)
5772 DW_FUNCTION_RETURN(dw_listbox_new, HWND) 5761 DW_FUNCTION_RETURN(dw_listbox_new, HWND)
5773 DW_FUNCTION_RESTORE_PARAM2(cid, ULONG, multi, int) 5762 DW_FUNCTION_RESTORE_PARAM2(cid, ULONG, multi, int)
5774 { 5763 {
5775 DW_FUNCTION_INIT; 5764 DW_FUNCTION_INIT;
5776 DWContainer *cont = _cont_new(cid, multi); 5765 DWContainer *cont = _dw_cont_new(cid, multi);
5777 [cont setHeaderView:nil]; 5766 [cont setHeaderView:nil];
5778 int type = DW_CFA_STRING; 5767 int type = DW_CFA_STRING;
5779 [cont setup]; 5768 [cont setup];
5780 NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:@"_DWListboxColumn"] autorelease]; 5769 NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:@"_DWListboxColumn"] autorelease];
5781 [column setEditable:NO]; 5770 [column setEditable:NO];
7500 DW_FUNCTION_ADD_PARAM2(cid, multi) 7489 DW_FUNCTION_ADD_PARAM2(cid, multi)
7501 DW_FUNCTION_RETURN(dw_container_new, HWND) 7490 DW_FUNCTION_RETURN(dw_container_new, HWND)
7502 DW_FUNCTION_RESTORE_PARAM2(cid, ULONG, multi, int) 7491 DW_FUNCTION_RESTORE_PARAM2(cid, ULONG, multi, int)
7503 { 7492 {
7504 DW_FUNCTION_INIT; 7493 DW_FUNCTION_INIT;
7505 DWContainer *cont = _cont_new(cid, multi); 7494 DWContainer *cont = _dw_cont_new(cid, multi);
7506 NSScrollView *scrollview = [cont scrollview]; 7495 NSScrollView *scrollview = [cont scrollview];
7507 [scrollview setHasHorizontalScroller:YES]; 7496 [scrollview setHasHorizontalScroller:YES];
7508 NSTableHeaderView *header = [[[NSTableHeaderView alloc] init] autorelease]; 7497 NSTableHeaderView *header = [[[NSTableHeaderView alloc] init] autorelease];
7509 [cont setHeaderView:header]; 7498 [cont setHeaderView:header];
7510 [cont setTarget:cont]; 7499 [cont setTarget:cont];
10223 Item *item = _box_item(handle); 10212 Item *item = _box_item(handle);
10224 10213
10225 /* Check to see if any of the sizes need to be recalculated */ 10214 /* Check to see if any of the sizes need to be recalculated */
10226 if(item && (item->origwidth == -1 || item->origheight == -1)) 10215 if(item && (item->origwidth == -1 || item->origheight == -1))
10227 { 10216 {
10228 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); 10217 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
10229 /* Queue a redraw on the top-level window */ 10218 /* Queue a redraw on the top-level window */
10230 _dw_redraw([object window], TRUE); 10219 _dw_redraw([object window], TRUE);
10231 } 10220 }
10232 return DW_ERROR_NONE; 10221 return DW_ERROR_NONE;
10233 } 10222 }
10423 /* Check to see if any of the sizes need to be recalculated */ 10412 /* Check to see if any of the sizes need to be recalculated */
10424 if(item && (item->origwidth == -1 || item->origheight == -1)) 10413 if(item && (item->origwidth == -1 || item->origheight == -1))
10425 { 10414 {
10426 int newwidth, newheight; 10415 int newwidth, newheight;
10427 10416
10428 _control_size(handle, &newwidth, &newheight); 10417 _dw_control_size(handle, &newwidth, &newheight);
10429 10418
10430 /* Only update the item and redraw the window if it changed */ 10419 /* Only update the item and redraw the window if it changed */
10431 if((item->origwidth == -1 && item->width != newwidth) || 10420 if((item->origwidth == -1 && item->width != newwidth) ||
10432 (item->origheight == -1 && item->height != newheight)) 10421 (item->origheight == -1 && item->height != newheight))
10433 { 10422 {
10554 Item *item = _box_item(handle); 10543 Item *item = _box_item(handle);
10555 10544
10556 /* Check to see if any of the sizes need to be recalculated */ 10545 /* Check to see if any of the sizes need to be recalculated */
10557 if(item && (item->origwidth == -1 || item->origheight == -1)) 10546 if(item && (item->origwidth == -1 || item->origheight == -1))
10558 { 10547 {
10559 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); 10548 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
10560 /* Queue a redraw on the top-level window */ 10549 /* Queue a redraw on the top-level window */
10561 _dw_redraw([object window], TRUE); 10550 _dw_redraw([object window], TRUE);
10562 } 10551 }
10563 DW_LOCAL_POOL_OUT; 10552 DW_LOCAL_POOL_OUT;
10564 } 10553 }
10612 Item *item = _box_item(handle); 10601 Item *item = _box_item(handle);
10613 10602
10614 /* Check to see if any of the sizes need to be recalculated */ 10603 /* Check to see if any of the sizes need to be recalculated */
10615 if(item && (item->origwidth == -1 || item->origheight == -1)) 10604 if(item && (item->origwidth == -1 || item->origheight == -1))
10616 { 10605 {
10617 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); 10606 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
10618 /* Queue a redraw on the top-level window */ 10607 /* Queue a redraw on the top-level window */
10619 _dw_redraw([object window], TRUE); 10608 _dw_redraw([object window], TRUE);
10620 } 10609 }
10621 } 10610 }
10622 } 10611 }
10795 if(width) *width = thisbox->minwidth; 10784 if(width) *width = thisbox->minwidth;
10796 if(height) *height = thisbox->minheight; 10785 if(height) *height = thisbox->minheight;
10797 } 10786 }
10798 } 10787 }
10799 else 10788 else
10800 _control_size(handle, width, height); 10789 _dw_control_size(handle, width, height);
10801 } 10790 }
10802 10791
10803 /* 10792 /*
10804 * Sets the gravity of a given window (widget). 10793 * Sets the gravity of a given window (widget).
10805 * Gravity controls which corner of the screen and window the position is relative to. 10794 * Gravity controls which corner of the screen and window the position is relative to.