home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / PostScript / Pencil / Source / MultipleSelection.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  5.1 KB  |  145 lines

  1. /*
  2. Pencil V1.0, Copyright 1994, 95 by Florian Marquardt.
  3. This program may be distributed under the terms of the GNU general
  4. public license (Start Pencil and select "Info>COPYING..." for a copy of the
  5. license).
  6. */
  7. #import "MultipleSelection.h"
  8.  
  9. @implementation MultipleSelection
  10. - (BOOL)selected:(NXEvent *)te:(int *)cp:(id)view
  11. {    int i=[slist count]; while(i--) if([[slist objectAt:i] selected:te:cp:view]) return YES; return NO; }
  12. - (BOOL)move:(NXEvent *)te:(int *)cp:(id)view:(float)bsize
  13. { return NO;  }
  14. - create:(NXEvent *)te:(int *)cp:(id)view:(float)bsize { return self; }
  15. - createPolyFreehand:(NXEvent *)te:(int *)cp:(id)view:(float)bsize { return self; }
  16. - (void)draw:(NXRect *)re
  17. {    int i, c=[slist count]; for(i=0;i<c;i++) [[slist objectAt:i] draw:re]; }
  18. - (void)drawControl:(NXRect *)re:(int)cp:(float)bsize
  19. {    int i, c=[slist count]; for(i=0;i<c;i++) [[slist objectAt:i] drawControl:re:-1:bsize]; }
  20. - initWithSettings:(char *)name:(NXColor)co1:(NXColor)co2:(float)lw:(char *)dm:(char *)fm:(char *)sm:(char *)ud
  21. { return self; }
  22. - giveSettings:(char **)name:(NXColor *)co1:(NXColor *)co2:(float *)lw:(char **)dmeth:(char **)fillmeth:(char **)strokemeth:(char **)ud { [[slist objectAt:0] giveSettings:name:co1:co2:lw:dmeth:fillmeth:strokemeth:ud]; return self; }
  23. - setMethodname:(char*)name
  24. { int i=[slist count]; while(i--) [[slist objectAt:i] setMethodname:name]; return self; }
  25. - setDrawingMethod:(char *)name
  26. { int i=[slist count]; while(i--) [[slist objectAt:i] setDrawingMethod:name]; return self; }
  27. - setStrokeMethod:(char *)name
  28. { int i=[slist count]; while(i--) [[slist objectAt:i] setStrokeMethod:name]; return self; }
  29. - setFillMethod:(char *)name
  30. { int i=[slist count]; while(i--) [[slist objectAt:i] setFillMethod:name]; return self; }
  31. - setSpecialAttributes:(char *)name
  32. { int i=[slist count]; while(i--) [[slist objectAt:i] setSpecialAttributes:name]; return self; }
  33. - setColor1:(NXColor)col
  34. { int i=[slist count]; while(i--) [[slist objectAt:i] setColor1:col]; return self; }
  35. - setColor2:(NXColor)col
  36. { int i=[slist count]; while(i--) [[slist objectAt:i] setColor2:col]; return self; }
  37. - setLineWidth:(float)lw
  38. { int i=[slist count]; while(i--) [[slist objectAt:i] setLineWidth:lw]; return self; }
  39. - addTranslation:(float)dtx:(float)dty
  40. { int i=[slist count]; while(i--) [[slist objectAt:i] addTranslation:dtx:dty]; return self; }
  41. - (void)rotateAroundCenter:(float)x:(float)y fromPoint:(NXPoint *)pt1 toPoint:(NXPoint *)pt2
  42. { int i=[slist count]; while(i--) [[slist objectAt:i] rotateAroundCenter:x:y fromPoint:pt1 toPoint:pt2]; }
  43. - insertNextPoint:(int *)cp { return self; }
  44. - insertPoint:(int *)cp { return self; }
  45. - deletePoint:(int *)cp { return self; }
  46. - calculateBoundingBox:(id)view
  47. {
  48. NXRect thebounds; int i=[slist count]-1;
  49. [[slist objectAt:i] calculateBoundingBox:view]; [[slist objectAt:i] giveBounds:&bounds];
  50. while(i--) { [[slist objectAt:i] calculateBoundingBox:view]; [[slist objectAt:i] giveBounds:&thebounds]; NXUnionRect( &thebounds, &bounds); } return self;
  51. }
  52. - giveBounds:(NXRect *)bnd
  53. {  *bnd=bounds; return self; }
  54. - initWithGraphic:(id)graphic
  55. {    [super init]; slist=[[[List alloc] init] addObject:graphic]; return self; }
  56. - initEmpty
  57. {    [super init]; slist=[[List alloc] init]; return self; }
  58. - addToSelection:(id)graphic posFromEnd:(int)pos
  59. {    [slist insertObject:graphic at:[slist count]-pos]; return self; }
  60. - free
  61. {
  62.     int i;
  63.     if(slist)
  64.     {
  65.     i=[slist count];
  66.     while(i--) [[slist objectAt:i] select:NO];
  67.     [slist free];
  68.     }
  69.     return [super free];
  70. }
  71. - freeOrig
  72. {
  73.     return [super free];
  74. }
  75. - select:(BOOL)yesno { if(yesno==NO) { [self free]; } return self; }
  76. - toFrontIn:(id)list
  77. {
  78.     int i, c=[list count]; id g;
  79.     for(i=0;c--;++i) if([g=[list objectAt:i] selected]) { [list removeObjectAt:i];  [list addObject:g]; --i; }
  80.     return self;
  81. }
  82. - toBackIn:(id)list
  83. {
  84.     int i,c=[list count]; id g;
  85.     for(i=c-1;c--;--i) if([g=[list objectAt:i] selected]) { [list removeObjectAt:i];  [list insertObject:g at:0]; ++i; }
  86.     return self;
  87. }
  88. - deleteThemIn:(id)list
  89. {
  90.     int i=[slist count]; id g;
  91.     while(i--) { [list removeObject:g=[slist objectAt:i]]; [g free]; }
  92.     [slist free];
  93.     slist=nil;
  94.     return [self free];
  95. }
  96. - (BOOL)partOfSelection:(id)graphic
  97. {
  98.     if([slist indexOf:graphic]==NX_NOT_IN_LIST) return(NO); else return(YES);
  99. }
  100. - addElementsTo:(id)list
  101. {
  102.     int i, c=[slist count];
  103.     for(i=0;i<c;i++)    [list addObject:[[slist objectAt:i] select:YES]];
  104.     return self;
  105. }
  106.  
  107. - moveElementsFrom:(id)list1 to:(id)list2
  108. {
  109.     int i, c=[slist count];
  110.     for(i=0;i<c;i++)    { [list1 removeObject:[slist objectAt:i]]; [list2 addObject:[[slist objectAt:i] select:YES]]; }
  111.     return self;
  112. }
  113.  
  114. - (void)scaleCenter:(float)cx:(float)cy by:(float)scx:(float)scy
  115. { int i=[slist count]; while(i--) [[slist objectAt:i] scaleCenter:cx:cy by:scx:scy];
  116. }
  117.  
  118. - slist { return slist; }
  119.  
  120. - write:(NXTypedStream *)stream
  121. {
  122.     int i,n;
  123.  
  124.     [super write:stream];
  125.     n=[slist count];
  126.     NXWriteType(stream, "i", &n);
  127.     for(i=0;i<n;i++)
  128.         NXWriteObject(stream, [slist objectAt:i]);
  129.     return self;
  130. }
  131.  
  132. - read:(NXTypedStream *)stream
  133. {
  134.     int i,n;
  135.  
  136.     [super read:stream];
  137.     n=[slist count];
  138.     NXReadType(stream, "i", &n);
  139.     if(slist)    [slist free];
  140.     [slist=[List alloc] setAvailableCapacity:n];
  141.     for(i=0;i<n;i++)
  142.         [slist addObject:NXReadObject(stream)];
  143.     return self;
  144. }
  145. @end