next up previous contents
Next: browser delegate methods Up: RECView.m program listing Previous: declarations

copying and printing Views

There is a mechanism for printing selected views, which is more selective than the printing options which can be connected by mouse dragging in the Interface Builder. Likewise Views can be copied to a pasteboard, where they are available for use by other programs, such as Draw. The problem is to know which Window, or which View to draw, although in principle a separate button for every one of them could be placed on the program's menu.

By making RECView a delegate of a Window which could be printed, it has an opportunity to respond to the announcement that the Window has become the key Window -- in other words, the focus of attention of keyboard strokes and mouse movements and has been displayed in front of everything else. The response takes the form of connecting the one single copy button and the single print button to the View which is to be copied or printed.

To avoid the uncertainty of knowing what to print when some other window has taken priority, the ``key resigned'' can be used to deactivate the menu buttons. Of course, the substituting window can delegate RECView the responsibility of printing it, but otherwise the buttons in the menu remain disconnected.

/* - - - - - - -   c o p y   a n d   p r i n t   v i e w s   - - - - - - */

- printREC:sender {[keyWindow smartPrintPSCode: sender]; return self;}

- windowDidBecomeKey:sender {
	keyWindow=sender;
	[menuCopy setTarget: self];
	[menuCopy setAction: @selector(copyREC:)];
	[menuCopy setEnabled: YES];
	[menuPrint setTarget: self];
	[menuPrint setAction: @selector(printREC:)];
	[menuPrint setEnabled: YES];
return self;
}

- windowDidResignKey:sender {
	[menuCopy setEnabled: NO];
	[menuPrint setEnabled: NO];
return self;
}

- copyREC:sender {
    drawBack=NO;

    if (keyWindow==planeWindow)
	[self copySomeView: planeView];
    if (keyWindow==infoPanel)
	[self copySomeView: [infoPanel contentView]];
    if (keyWindow==execWin)
	[self copySomeView: [execWin contentView]];
    if (keyWindow==parPanel)
	[self copySomeView: [parPanel contentView]];

    drawBack=YES;
return self;
}

- copySomeView:theView {
NXRect zbounds;
id     pBoard;
//  drawView=viewnum;
//  *draw=YES;
  pBoard = [Pasteboard new];
  [pBoard declareTypes: &NXPostScriptPboardType num: 1 owner: self];
  [theView getBounds: &zbounds];
  [theView writePSCodeInside: &zbounds to: pBoard]; 
//  *draw=NO;
return self;
}


next up previous contents
Next: browser delegate methods Up: RECView.m program listing Previous: declarations
Microcomputadoras
2001-02-12