[comp.sys.next] need advice on scrolling text fields

dz@plum.ucsb.edu (Daniel James Zerkle) (08/23/89)

This is a shameless request for advice.

As some of you may know, I am working on a project that will behave
similarly to the Digital Librarian.  As such, I would like to use a
feature similar to the DL, both because it will be less confusing to
have a similar interface, and because it is a nice idea.

I want to have a scrolling text field that will display file names,
one per line, very much like the file names are displayed by DL after
a search.  When the user clicks on one of these lines, I want it to
be highlighted and for the program to tell which line was hit.  I need
to be able to clear the whole field, also.

Am I going to need a custom view to do this, or is there already some-
thing available?  I remember reading in the past here that some people
have had a lot of trouble with something like this.  (I would go back
& read it, but our news gets flushed every couple of days)  Are there
any pitfalls I should watch out for?  Which bits of documentation
should I read?  Are there some features I should add that I haven't
mentioned yet?  Is there anything special I need to do to put this into
an application with the Interface Builder?  Is there anything else I
should know?

Just so you know where to aim, I'm very familiar with UNIX and C,
but only have a basic understanding of Objective-C and Interface
Builder.  (Outlet?  What's an outlet?)

Many thanks in advance (and probably after, too).

| Dan Zerkle home:(805) 968-4683 morning:961-2434 afternoon:687-0110  |
| dz@cornu.ucsb.edu dz%cornu@ucsbuxa.bitnet ...ucbvax!hub!cornu!dz    |
| Snailmail: 6681 Berkshire Terrace #5, Isla Vista, CA  93117         |
| Disclaimer: If it's wrong or stupid, pretend I didn't do it.        |

tsui@silver.bacs.indiana.edu (Yufeng Tsui) (08/24/89)

In article <2240@hub.UUCP> dz@cornu.ucsb.edu (Daniel James Zerkle) writes:
>This is a shameless request for advice.
>
>As some of you may know, I am working on a project that will behave
>similarly to the Digital Librarian.  As such, I would like to use a
>feature similar to the DL, both because it will be less confusing to
>have a similar interface, and because it is a nice idea.
>
>I want to have a scrolling text field that will display file names,
>one per line, very much like the file names are displayed by DL after
>a search.  When the user clicks on one of these lines, I want it to
>be highlighted and for the program to tell which line was hit.  I need
>to be able to clear the whole field, also.
>

  I just did that.  I think what you need is a scrollView whose contentView
is a matrix.(use buttonCell maybe? That way you can also use icons for
the cell)  Then you set the target for this matrix so that it send the
message to the target when it is hit.   Here is a piece of code from
my program.  It records user's commands and put them in the history window.
The user then can run the command just by clicking... The code has not
been cleard up yet, but it runs.


- setUpHistoryWindow
{
  NXRect aRect;
  id theScrollView,windowText;
  NXSize cSize;

  NXSetRect(&aRect,400,400,500,300);
  historyWindow = [Window newContent:&aRect
	 	style:NX_TITLEDSTYLE
		backing:NX_BUFFERED
		buttonMask:NX_ALLBUTTONS
		defer:NO];
  [historyWindow setTitle:"history"];
  [historyWindow setFreeWhenClosed:NO];
  [historyWindow setBackgroundGray:NX_LTGRAY];
  NXSetRect(&aRect, 0.0, 0.0,cSize.width,cSize.height);
  theScrollView = [ScrollView newFrame:&aRect];
  [theScrollView setHorizScrollerRequired:YES];
  [theScrollView setVertScrollerRequired:YES];
  [theScrollView setBorderType:NX_BEZEL];
  [theScrollView setAutoresizeSubviews:YES];
  [theScrollView setDynamicScrolling:YES];
  windowText = [Matrix newFrame:&aRect
                       mode:NX_RADIOMODE
                       cellClass:SelectionCell // ButtonCell will be better
                       numRows:0
                       numCols:0];
  [windowText setTarget:self];
  [windowText setDoubleAction:@selector(IamHit:)]; // double click
  [windowText setEnabled:YES];
  [historyWindow setContentView:theScrollView];
  [theScrollView setDocView:windowText];
  [theScrollView setBackgroundGray:NX_WHITE];
  [theScrollView setDisplayOnScroll:YES];
  [windowText sizeToFit];
  return self;
}

- IamHit:sender
{
  // get the sender's stringValue and pass it to my shellCmdView
  ...
  [shellCmdView setStringValue:[[sender selectedCell] stringValue] at:0];
  return self;
}

- run:sender // after run the command, put it in to the history window.
{
  char *aStr,*totalStr;
  int aLength;
  id theCell,theMatrix;

  aStr = [shellCmdView stringValueAt:0];
  if (empty(aStr)) return self;
  if (history) {
     theMatrix=[[historyWindow contentView] docView];
     theCell = [SelectionCell newTextCell:aStr];
     [theMatrix setPrototype:theCell];
     [theMatrix addRow];
     [theMatrix selectCellAt:[theMatrix cellCount]-1:0];
     [theMatrix sizeToCells];
     [theMatrix sizeToFit];
     [theMatrix display];
  }
  [self clear:self];
  [myMainWindow makeFirstResponder:shellCmdView];
  return self;
}