Changeset 12556


Ignore:
Timestamp:
Jul 18, 2011, 12:48:00 AM (10 years ago)
Author:
livings124
Message:

#4365 enforce window size for auto-resizing by setting min/max size

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r12118 r12556  
    238238- (void) setWindowSizeToFit;
    239239- (NSRect) sizedWindowFrame;
     240- (void) updateForAutoSize;
     241- (void) setWindowMinMaxToCurrent;
     242- (CGFloat) minWindowContentSizeAllowed;
    240243
    241244- (void) updateForExpandCollape;
  • trunk/macosx/Controller.m

    r12538 r12556  
    394394    [fTableView setUsesAlternatingRowBackgroundColors: !small];
    395395   
    396     //window min height
    397     NSSize contentMinSize = [fWindow contentMinSize];
    398     contentMinSize.height = [[fWindow contentView] frame].size.height - [[fTableView enclosingScrollView] frame].size.height
    399                                 + [fTableView rowHeight] + [fTableView intercellSpacing].height;
    400     [fWindow setContentMinSize: contentMinSize];
    401396    [fWindow setContentBorderThickness: NSMinY([[fTableView enclosingScrollView] frame]) forEdge: NSMinYEdge];
    402397    [fWindow setMovableByWindowBackground: YES];
     
    420415    [fWindow registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, NSURLPboardType, nil]];
    421416   
    422     //you would think this would be called later in this method from updateUI, but it's not
     417    //you would think this would be called later in this method from updateUI, but it's not reached in awakeFromNib
     418    //this must be called after showStatusBar:
    423419    [fStatusBar updateWithDownload: 0.0 upload: 0.0];
    424420
     421    //this should also be after the rest of the setup
     422    [self updateForAutoSize];
     423   
    425424    //register for sleep notifications
    426425    IONotificationPortRef notify;
     
    478477                    name: @"AutoImportSettingChange" object: nil];
    479478   
    480     [nc addObserver: self selector: @selector(setWindowSizeToFit)
     479    [nc addObserver: self selector: @selector(updateForAutoSize)
    481480                    name: @"AutoSizeSettingChange" object: nil];
    482481   
     
    27882787    [fTableView noteHeightOfRowsWithIndexesChanged: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fTableView numberOfRows])]];
    27892788   
    2790     //window min height
    2791     NSSize contentMinSize = [fWindow contentMinSize],
    2792             contentSize = [[fWindow contentView] frame].size;
    2793     contentMinSize.height = contentSize.height - [[fTableView enclosingScrollView] frame].size.height
    2794                             + [fTableView rowHeight] + [fTableView intercellSpacing].height;
    2795     [fWindow setContentMinSize: contentMinSize];
    2796    
    27972789    //resize for larger min height if not set to auto size
    27982790    if (![fDefaults boolForKey: @"AutoSize"])
    27992791    {
     2792        const NSSize contentSize = [[fWindow contentView] frame].size;
     2793       
     2794        NSSize contentMinSize = [fWindow contentMinSize];
     2795        contentMinSize.height = [self minWindowContentSizeAllowed];
     2796        [fWindow setContentMinSize: contentMinSize];
     2797       
     2798        //make sure the window already isn't too small
    28002799        if (!makeSmall && contentSize.height < contentMinSize.height)
    28012800        {
     
    28452844    if (check)
    28462845    {
    2847         NSSize minSize = [scrollView convertSize: [fWindow minSize] fromView: nil];
    2848        
    2849         if (windowSize.height < minSize.height)
    2850             windowSize.height = minSize.height;
     2846        //we can't call minSize, since it might be set to the current size (auto size)
     2847        const CGFloat minHeight = [self minWindowContentSizeAllowed]
     2848                                    + (NSHeight([fWindow frame]) - NSHeight([[fWindow contentView] frame])); //contentView to window
     2849       
     2850        if (windowSize.height < minHeight)
     2851            windowSize.height =minHeight;
    28512852        else
    28522853        {
     
    29422943    [scrollView setAutoresizingMask: scrollMask];
    29432944   
    2944     //change min size
    2945     NSSize minSize = [fWindow contentMinSize];
    2946     minSize.height += heightChange;
    2947     [fWindow setContentMinSize: minSize];
    2948    
    29492945    if (!show)
    29502946    {
     
    29522948        [fStatusBar release];
    29532949        fStatusBar = nil;
     2950    }
     2951   
     2952    if ([fDefaults boolForKey: @"AutoSize"])
     2953        [self setWindowMinMaxToCurrent];
     2954    else
     2955    {
     2956        //change min size
     2957        NSSize minSize = [fWindow contentMinSize];
     2958        minSize.height += heightChange;
     2959        [fWindow setContentMinSize: minSize];
    29542960    }
    29552961}
     
    30353041    [scrollView setAutoresizingMask: scrollMask];
    30363042   
    3037     //change min size
    3038     NSSize minSize = [fWindow contentMinSize];
    3039     minSize.height += heightChange;
    3040     [fWindow setContentMinSize: minSize];
    3041    
    30423043    if (!show)
    30433044    {
     
    30453046        [fFilterBar release];
    30463047        fFilterBar = nil;
     3048    }
     3049   
     3050    if ([fDefaults boolForKey: @"AutoSize"])
     3051        [self setWindowMinMaxToCurrent];
     3052    else
     3053    {
     3054        //change min size
     3055        NSSize minSize = [fWindow contentMinSize];
     3056        minSize.height += heightChange;
     3057        [fWindow setContentMinSize: minSize];
    30473058    }
    30483059}
     
    39643975            [scrollView setAutohidesScrollers: YES];
    39653976        }
     3977       
     3978        [self setWindowMinMaxToCurrent];
    39663979    }
    39673980}
     
    39743987    CGFloat heightChange = (GROUP_SEPARATOR_HEIGHT + [fTableView intercellSpacing].height) * groups
    39753988                        + ([fTableView rowHeight] + [fTableView intercellSpacing].height) * ([fTableView numberOfRows] - groups)
    3976                         - [[fTableView enclosingScrollView] frame].size.height;
     3989                        - NSHeight([[fTableView enclosingScrollView] frame]);
    39773990   
    39783991    return [self windowFrameByAddingHeight: heightChange checkLimits: YES];
     3992}
     3993
     3994- (void) updateForAutoSize
     3995{
     3996    if ([fDefaults boolForKey: @"AutoSize"])
     3997        [self setWindowSizeToFit];
     3998    else
     3999    {
     4000        NSSize contentMinSize = [fWindow contentMinSize];
     4001        contentMinSize.height = [self minWindowContentSizeAllowed];
     4002       
     4003        [fWindow setContentMinSize: contentMinSize];
     4004       
     4005        NSSize contentMaxSize = [fWindow contentMaxSize];
     4006        contentMaxSize.height = FLT_MAX;
     4007        [fWindow setContentMaxSize: contentMaxSize];
     4008    }
     4009}
     4010
     4011- (void) setWindowMinMaxToCurrent
     4012{
     4013    const CGFloat height = NSHeight([[fWindow contentView] frame]);
     4014   
     4015    NSSize minSize = [fWindow contentMinSize],
     4016            maxSize = [fWindow contentMaxSize];
     4017    minSize.height = height;
     4018    maxSize.height = height;
     4019   
     4020    [fWindow setContentMinSize: minSize];
     4021    [fWindow setContentMaxSize: maxSize];
     4022}
     4023
     4024- (CGFloat) minWindowContentSizeAllowed
     4025{
     4026    CGFloat contentMinHeight = NSHeight([[fWindow contentView] frame]) - NSHeight([[fTableView enclosingScrollView] frame])
     4027                                + [fTableView rowHeight] + [fTableView intercellSpacing].height;
     4028    return contentMinHeight;
    39794029}
    39804030
     
    39944044    [fBadger clearCompleted];
    39954045    [self updateUI];
    3996 }
    3997 
    3998 - (NSSize) windowWillResize: (NSWindow *) sender toSize: (NSSize) proposedFrameSize
    3999 {
    4000     //only resize horizontally if autosize is enabled
    4001     if ([fDefaults boolForKey: @"AutoSize"])
    4002         proposedFrameSize.height = [fWindow frame].size.height;
    4003     return proposedFrameSize;
    40044046}
    40054047
Note: See TracChangeset for help on using the changeset viewer.