discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GSVBox or maybe NSSplitView - Resizing Problem


From: Jeremy Cowgar
Subject: GSVBox or maybe NSSplitView - Resizing Problem
Date: Fri, 28 Dec 2001 10:48:51 -0500

Greetings!

I have a very simple window:

[=============+==============]
[ TABLEVIEW     |  FORM             ]
[                       +--------------------]
[                       | TEXTVIEW ]
[=============+===============]

My main window content view is the NSSplitView, which has two views, my 
NSScrollView containing a NSTableView and then a GSVBox containing a 
NSForm and another NSScrollView which contains a NSTextView.

My problem is that the right pane (Form/TextView) does not resize. I set 
it up to that the form will always be the same height but would size 
horizontally and the textview would change both vertically and 
horizontally.

If I simply comment out the main SplitView and TableView, then simply make
my GSVBox the contentView of my window, it resizes perfectly and does 
exactly what I want it to, but as soon as I put the GSVBox into the 
SplitView and reassign the contentView of my window to be the splitview, 
the GSVBox no longer resizes at all.

Any ideas? I have included my code below:

  // Create my window
  NSRect rect = NSMakeRect(0,0,600,600);
  unsigned int styleMask = NSTitledWindowMask | 
        NSMiniaturizableWindowMask | NSClosableWindowMask | 
NSResizableWindowMask;

  myWindow = [NSWindow alloc];
  myWindow = [myWindow initWithContentRect: rect
                                           styleMask: styleMask
                                           backing: NSBackingStoreBuffered
                                           defer: NO];
  [myWindow setTitle: @"Rolodex v0.1"];

  // View and Control Vars
  NSTableColumn *nameCol;
  NSScrollView *scrollView;
  NSSplitView *splitView;
  NSBox *formBox;
  NSScrollView *textScrollView;
  NSTextView *textView;

  // Create my TableView
  nameCol = [[NSTableColumn alloc] initWithIdentifier: @"name"];
  AUTORELEASE(nameCol);
  [[nameCol headerCell] setStringValue: @"Name"];
  [nameCol setMinWidth: 100];

  tableView = [[NSTableView alloc]
                                initWithFrame: NSMakeRect(0,0,100,200)];
  [tableView addTableColumn: nameCol];

  [tableView setDataSource: self];
  [tableView setDelegate: self];

  // Create the scrollView in which the Table will be placed
  scrollView = [[NSScrollView alloc]
                                 initWithFrame: NSMakeRect(0,0,200,200)];
  [scrollView setDocumentView: tableView];
  RELEASE(tableView);
  [scrollView setHasHorizontalScroller: YES];
  [scrollView setHasVerticalScroller: YES];
  [scrollView setBorderType: NSBezelBorder];
  [scrollView setAutoresizingMask: (NSViewWidthSizable | 
NSViewHeightSizable)];

  [tableView sizeToFit];

  // Create my "details" form
  form = [NSForm new];
  [form addEntry: @"Name"];
  [form addEntry: @"Home Phone"];
  [form addEntry: @"Work Phone"];
  [form addEntry: @"Email Address 1"];
  [form addEntry: @"Email Address 2"];
  [form addEntry: @"Email Address 3"];
  [form addEntry: @"URL 1"];
  [form addEntry: @"URL 2"];
  [form addEntry: @"URL 3"];
  [form setAutoresizingMask: NSViewWidthSizable];
  [form setAutosizesCells: YES];
  [form sizeToFit];

  // Create the TextScrollView for the "Notes"
  textScrollView = [[NSScrollView alloc]
                                         initWithFrame: 
NSMakeRect(0,0,400,200)];
  [textScrollView setHasHorizontalScroller: YES];
  [textScrollView setHasVerticalScroller: YES];
  [textScrollView setBorderType: NSBezelBorder];
  [textScrollView setAutoresizingMask: (NSViewWidthSizable | 
NSViewHeightSizable)];

  // Create my TextView (actual control to edit for notes, etc...
  NSRect textRect = [[textScrollView contentView] frame];
  textView = [[NSTextView alloc] initWithFrame: textRect];
  [textView setDelegate: self];
  [textView setHorizontallyResizable: NO];
  [textView setVerticallyResizable: YES];
  [textView setMinSize: NSMakeSize(0,0)];
  [textView setMaxSize: NSMakeSize(1E7,1E7)];
  [textView setAutoresizingMask: (NSViewHeightSizable | 
NSViewWidthSizable)];
  [[textView textContainer] setContainerSize: 
NSMakeSize(textRect.size.width,
                                                                                
                                 1E7)];
  [[textView textContainer] setWidthTracksTextView: YES];

  [textScrollView setDocumentView: textView];
  RELEASE(textView);

  // Create a box to contain the form so that I have a nice border, title 
and also so it
  // resizes properly.
  formBox = [[NSBox new] autorelease];
  [formBox setTitlePosition: NSAtTop];
  [formBox setTitle: @"Entry"];
  [formBox setBorderType: NSGrooveBorder];
  [formBox addSubview: form];
  [formBox setContentViewMargins: NSMakeSize(10,10)];
  [formBox setAutoresizingMask: NSViewWidthSizable];
  [formBox sizeToFit];

  // A VBox to put the form and text views into
  GSVbox *formVBox = [[GSVbox new] autorelease];
  [formVBox setBorder: 1];
  [formVBox setDefaultMinYMargin: 1];
  [formVBox addView: textScrollView enablingYResizing: YES];
  [formVBox addView: formBox enablingYResizing: NO]; // Don't want this to
grow in height.
  [formVBox setAutoresizingMask: (NSViewHeightSizable | 
NSViewWidthSizable)];
  [formVBox sizeToFit];
  
  // Finally, my splitview that will contain my tableview and form/notes 
view
  splitView = [NSSplitView new];
  [splitView setVertical: YES];
  [splitView addSubview: scrollView];
  [splitView addSubview: formVBox];
  [splitView setAutoresizingMask: (NSViewWidthSizable | 
NSViewHeightSizable)];

  [scrollView release];

  // Make the splitView the content view of my window.
  [myWindow setContentView: splitView];
-- 
Jeremy Cowgar - jc@cowgar.com
http://cowgar.com





reply via email to

[Prev in Thread] Current Thread [Next in Thread]