• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: question about frame and bounds
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about frame and bounds


  • Subject: Re: question about frame and bounds
  • From: j o a r <email@hidden>
  • Date: Sun, 19 Oct 2003 23:43:20 +0200

On 2003-10-19, at 23.01, Ivan S. Kourtev wrote:

I am confused. Isn't that exactly what the code above is doing (except for the perhaps inappropriate choice of variable name for NSView *containing_view)? This did seem to work.

Sorry, I didn't read your code closely enough...

At any rate, what I am trying to do is dynamically change the size and appearance of the main application window based on the program state. For example, when the user selects a certain action, a file must be read in. At this point, I would like to:
(a) resize the window a little larger (already know how to do that with setFrame:display:animate),
(b) show a progress bar and a bunch of NSTextField's in the new window area
(c) read the file, indicating progress with progress bar, fill out NSTextFields
(d) when user is done, resize window back to normal (get rid of progress bar, NSTextFields, etc.)

So, according to an example I have seen, I create the entire interface in PB. In awakeFromNib I want to hide this portion of the main window interface which is not needed yet. So I wanted to get the dimensions and positions of interface objects (in the portion to be hidden) in order to calculate how much does the main window need to shrink (and hide the objects that are not needed for display).

You're definitively on the right track. If I were you I would write a subclass of NSBox called "CollapsableBox" that looked something like this:

@interface CollapsableBox : NSBox
{
@private

BOOL _isCollapsed;
NSView *_contentView;
NSView *_swapView;
}

- (void) toggleCollapsed:(id) sender;

- (BOOL) isCollapsed;
- (void) setCollapsed:(BOOL) collapse;

@end

To make it easier to implement, make a couple of assumptions:
* That it spans the window width
* That it is always a direct subview of the window content view

To collaps, do something like this:

* Tell the window content view to not resize subviews automatically, via setAutoresizesSubviews: NO.
* Make sure that the original content view (_contentView) is retained and replace it with an empty view (_swapView).
* Resize the box to 0 height.
* Reposition all other top level views and resize the window appropriately.
* Tell the window content view to not resize subviews automatically, via setAutoresizesSubviews: YES.

...and the other way around

* Tell the window content view to not resize subviews automatically, via setAutoresizesSubviews: NO.
* Resize the box to the height of the original content view.
* Make sure that the swap view is retained and replace it with the original content view
* Reposition all other top level views and resize the window appropriately.
* Tell the window content view to not resize subviews automatically, via setAutoresizesSubviews: YES.

A full implementation of a CollapsableBox is often more complex than the bare bones example above, but it's an incredible useful control that you'd use over and over again. A more full fledged implementation would have fewer restrictions, like being able to be contained within an arbitrary view hierarchy. It could have settings for if it should resize the window at all, and if it should do it vertically, horizontally, or both. We have such a one where I work, but I'm not allowed to share the source unfortunately.
If you look around, I'm sure you can find working code examples of collapsable boxes on the Cocoa web sites on the net. You could for example search for "disclosure" in the mailing list archives:

<http://cocoa.mamasam.com/>

Like this one:

<http://cocoa.mamasam.com/COCOADEV/2002/08/1/42537.php>

Perhaps you can find one in the frameworks that Omni provides? Look around!

An alternative to a collapsable box that you might consider is to use a NSDrawer that open and close as needed to display the progress bar.

j o a r
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: question about frame and bounds (mostly FIXED with a little problem)
      • From: Ivan Kourtev <email@hidden>
    • Re: question about frame and bounds
      • From: Ambroise Confetti <email@hidden>
References: 
 >Re: question about frame and bounds (From: Ivan Kourtev <email@hidden>)
 >Re: question about frame and bounds (From: "Ivan S. Kourtev" <email@hidden>)

  • Prev by Date: Re: question about frame and bounds
  • Next by Date: Re: question about frame and bounds
  • Previous by thread: Re: question about frame and bounds
  • Next by thread: Re: question about frame and bounds
  • Index(es):
    • Date
    • Thread