Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > columnDidResize: and NSTableViewColumnDidResizeNotification

columnDidResize: and NSTableViewColumnDidResizeNotification
Thread Tools
Fresh-Faced Recruit
Join Date: Jul 2004
Status: Offline
Reply With Quote
Aug 21, 2004, 05:04 AM
 
Hello,

I am currently trying to make some alterations to a subclass of NSTableView that provides the ability for rows to resize to show wrapped text. Almost everything is working fine, but there is one minor ugliness I would like to correct, but cannot find any way of doing it. At the moment, if you resize a column, the row will not resize itself until after you have stopped resizing the column. This doesn't look brilliant. However, if you resize the whole window, the rows resize themselves accordingly.

After experimenting, I found that this is because during a live resize of a window, NSTableViewColumnDidResizeNotification is sent constantly. I have columnDidResize: set up to recalculate the heights of the rows, so this all works fine during window resizing. However, if you resize a column directly by dragging its edge, NSTableViewColumnDidResizeNotification is only sent after the operation has finished.

I was hoping that there would be something equivalent for "column is resizing", but there doesn't seem to be anything. I tried checking if a column was resizing from the overridden tile method by using the resizedColumn method from NSTableHeaderView, which returns the index of a column if one is being resized or -1 otherwise, like this:

if ([[self headerView] resizedColumn] != -1)
// recalculate grid and heights etc

However, this causes all sorts of drawing problems, presumably because it is being called to often.

Does anybody have any suggestions of how I can work around this? Basically I just need to be told when a column is resizing, and recalculate the heights and grid accordingly, but it has to be efficient to avoid drawing problems.

Many thanks for any suggestions, apologies if I've missed something obvious,
KB
     
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status: Offline
Reply With Quote
Aug 21, 2004, 01:47 PM
 
How about if you monitor mouseDown, mouseUp and mouseMoved if mouseDown occurs in the table column header view. Then whenever mouseMoved happens between a mouseDown and a mouseUp, you call your method explicitly
     
Ambit  (op)
Fresh-Faced Recruit
Join Date: Jul 2004
Status: Offline
Reply With Quote
Aug 21, 2004, 03:15 PM
 
Many thanks for the reply, and for the suggestion. I just tried this, bu unfortunately, it doesn't work...

I subclassed NSTableHeaderView, created override methods for mouseDown and mouseDragged, and set my new subclass as the new header view my table view using setHeaderView: I used an NSLog call in both the mouseDown and mouseDragged methods and then sent the messages on to super, and this is what I found:

mouseDown registered every time, and printed out the NSLog text.
The NSLog text for mouseDragged - which is what I need - would only print out if I didn't send any mouseDown messages to super. But of course, if I don't send any mouseDown messages to the superclass, the columns don't get resized...! Very Catch 22...

Any other suggestions would be much welcomed.

Many thanks,
KB

P.S. Here is the code I tried. First the subclass:

Header file:
Code:
#import <Foundation/Foundation.h> @interface NewTableHeaderView : NSTableHeaderView @end
Implementation file:
Code:
#import "NewTableHeaderView.h" @implementation NewTableHeaderView -(void) mouseDown: (NSEvent *) theEvent { NSLog (@"Mouse down!"); [super mouseDown: theEvent]; } -(void) mouseDragged: (NSEvent *) theEvent { NSLog(@"Mouse dragged!"); [super mouseDragged: theEvent]; } @end
And then I set the header view like this in my NSTableView designated initializer (note that headerView is an instance variable of type NewTableHeaderView*):

Code:
headerView = [[NewTableHeaderView alloc] initWithFrame: [[self headerView] frame]]; [self setHeaderView: headerView];
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:10 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2