home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Examples / AppKit / Draw / GraphicView.h < prev    next >
Text File  |  1996-04-18  |  11KB  |  317 lines

  1. #import <objc/Storage.h>
  2.  
  3. typedef enum { Normal, Resizing } DrawStatusType;
  4. typedef enum { LEFT = 1, RIGHT, BOTTOM, TOP, HORIZONTAL_CENTERS, VERTICAL_CENTERS, BASELINES } AlignmentType;
  5.  
  6. extern DrawStatusType DrawStatus;
  7. extern NSString *DrawPboardType;
  8. extern BOOL InMsgPrint;
  9.  
  10. typedef enum { ByRect, ByGraphic, ByList } DrawSelectionType;
  11.  
  12. /* Update modes for links. */
  13.  
  14. #define UPDATE_NEVER 0
  15. #define UPDATE_IMMEDIATELY - 1
  16. #define UPDATE_NORMALLY 1
  17.  
  18. @interface GraphicView : NSView
  19. {
  20.     NSMutableArray *glist;        /* the list of Graphics */
  21.     NSMutableArray *slist;        /* the list of selected Graphics. In 
  22.                            Draw with undo we are very careful
  23.                        to keep slist sorted, like glist */
  24.     NSImage *cacheImage;        /* the cache of drawn graphics */
  25.     struct {
  26. #ifdef __BIG_ENDIAN__
  27.     unsigned int groupInSlist:1;    /* whether a Group is in the slist */
  28.     unsigned int cacheing:1;    /* whether cacheing or drawing */
  29.     unsigned int suspendLinkUpdate:1; /* don't update links */
  30.     unsigned int grid:8;        /* grid size */
  31.     unsigned int showGrid:1;    /* whether grid is visible */
  32.     unsigned int locked:1;        /* some graphics are locked */
  33.     unsigned int gridDisabled:1;    /* whether grid is enabled */
  34.     unsigned int freeOriginalPaste:1;/* whether originalPaste needs free */
  35.     unsigned int serviceActsOnSelection:1;    /* whether service acts on selection */
  36. #else
  37.     unsigned int serviceActsOnSelection:1;    /* whether service acts on selection */
  38.     unsigned int freeOriginalPaste:1;/* whether originalPaste needs free */
  39.     unsigned int gridDisabled:1;    /* whether grid is enabled */
  40.     unsigned int locked:1;        /* some graphics are locked */
  41.     unsigned int showGrid:1;    /* whether grid is visible */
  42.     unsigned int grid:8;        /* grid size */
  43.     unsigned int suspendLinkUpdate:1; /* don't update links */
  44.     unsigned int cacheing:1;    /* whether cacheing or drawing */
  45.     unsigned int groupInSlist:1;    /* whether a Group is in the slist */
  46. #endif
  47. // These last 16 bits are NOT archived, so don't depend on them being permanent across a Save/Open
  48.     unsigned int selectAll:1;    /* select all was last select operation performed */
  49.     unsigned int dragCopyOk:1;    /* true if dragging with sourcMask == copy is ok */
  50.     unsigned int dragLinkOk:1;    /* true if dragging with sourcMask == link is ok */
  51.     unsigned int didPrintCustomDefs:1; /* true if wrote custom PostScript defs in printing */
  52.     unsigned int padding:12;
  53.     } gvFlags;
  54.     short *gupCoords;            /* points in the grid user path */
  55.     int gupLength;            /* number of points in gupCoords */
  56.     char *gupOps;            /* movetos and linetos in the gup */
  57.     short *gupBBox;            /* bounding box of the gup */
  58.     float gridGray;            /* grayness of the grid */
  59.     int consecutivePastes;        /* number of consecutive pastes */
  60.     int lastPastedChangeCount;        /* the change count of last paste */
  61.     int lastCopiedChangeCount;        /* the change count of last cut or copy */
  62.     int lastCutChangeCount;        /* the change count of last cut */
  63.     NSView *editView;            /* flipped subview for editing */
  64.     Graphic *originalPaste;        /* the first pasted graphic */
  65.     NSDataLinkManager *linkManager;    /* manager of data links */
  66.     NSRect *invalidRect;        /* invalid area which must be cleaned up */
  67.     NSRect *dragRect;            /* last rectangle we dragged out to select */
  68.     Storage *linkTrackingRects;        /* the rects of the links we are tracking */
  69.     int spellDocTag;
  70. }
  71.  
  72. /* Class initialization */
  73.  
  74. + (void)initClassVars;
  75.  
  76. /* Alignment methods */
  77.  
  78. + (SEL)actionFromAlignType:(AlignmentType)alignType;
  79.  
  80. /* Creation methods */
  81.  
  82. - (id)initWithFrame:(NSRect)frameRect;
  83.  
  84. /* Free method */
  85.  
  86. - (void)dealloc;
  87.  
  88. /* Public methods */
  89.  
  90. - (BOOL)isEmpty;
  91. - (BOOL)hasEmptySelection;
  92. - (void)dirty;
  93. - (void)getSelection;
  94. - (void)setGroupInSlist:(BOOL)setting;
  95. - (void)resetGroupInSlist;
  96. - (void)resetLockedFlag;
  97. - (NSRect)getBBoxOfArray:(NSArray *)array;
  98. - (NSRect)getBBoxOfArray:(NSArray *)array extended:(BOOL)flag;
  99.  
  100. - (void)redrawGraphics:graphicsList afterChangeAgent:changeAgent performs:(SEL)aSelector;
  101. - (void)graphicsPerform:(SEL)aSelector;
  102. - (void)graphicsPerform:(SEL)aSelector with:(void *)argument;
  103.  
  104. - (void)cache:(NSRect)rect;
  105. - (void)cache:(NSRect)rect andUpdateLinks:(BOOL)updateLinks;
  106. - (void)recacheSelection;
  107. - (NSImage *)selectionCache;
  108. - (void)cacheSelection;
  109. - (void)cacheList:(NSArray *)array into:(NSImage *)aCache withTransparentBackground:(BOOL)flag;
  110. - (void)cacheList:(NSArray *)array into:(NSImage *)aCache;
  111. - (void)cacheGraphic:(Graphic *)graphic;
  112.  
  113. - (void)removeGraphic:(Graphic *)graphic;
  114. - (void)insertGraphic:(Graphic *)graphic;
  115. - (Graphic *)selectedGraphic;
  116. - (NSMutableArray *)selectedGraphics;
  117. - (NSMutableArray *)graphics;
  118.  
  119. - (int)gridSpacing;
  120. - (BOOL)gridIsVisible;
  121. - (BOOL)gridIsEnabled;
  122. - (float)gridGray;
  123. - (void)setGridSpacing:(int)gridSpacing;
  124. - (void)setGridEnabled:(BOOL)flag;
  125. - (void)setGridVisible:(BOOL)flag;
  126. - (void)setGridGray:(float)gray;
  127. - (void)setGridSpacing:(int)gridSpacing andGray:(float)gray;
  128. - (NSPoint)grid:(NSPoint)point;
  129.  
  130. - (Graphic *)placeGraphic:(Graphic *)graphic at:(const NSPoint *)location;
  131.  
  132. /* Methods overridden from superclass */
  133.  
  134. - (void)setFrameSize:(NSSize)newSize;
  135. - (void)mouseDown:(NSEvent *)event;
  136. - (void)drawRect:(NSRect)rects;
  137. - (void)keyDown:(NSEvent *)event;
  138.  
  139. /* Getting/Setting the current Graphic */
  140.  
  141. - (Class)currentGraphic;
  142. - (void)setCurrentGraphic:sender;
  143.  
  144. /* Writing Draw forms and files */
  145.  
  146. - (BOOL)hasFormEntries;
  147. - (void)writeFormEntriesToFile:(NSString *)filename;
  148. - (BOOL)hasGraphicsWhichWriteFiles;
  149. - (void)allowGraphicsToWriteFilesIntoDirectory:(NSString *)directory;
  150.  
  151. /* Target/Action methods */
  152.  
  153. - (void)delete:(id)sender;
  154. - (void)selectAll:(id)sender;
  155. - (void)deselectAll:sender;
  156. - (void)lockGraphic:sender;
  157. - (void)unlockGraphic:sender;
  158. - (void)bringToFront:sender;
  159. - (void)sendToBack:sender;
  160. - (void)group:sender;
  161. - (void)ungroup:sender;
  162. - (void)align:sender;
  163. - (void)changeAspectRatio:sender;
  164. - (void)alignToGrid:sender;
  165. - (void)sizeToGrid:sender;
  166. - (void)enableGrid:sender;
  167. - (void)hideGrid:sender;
  168. - (void)addCoverSheetEntry:sender;
  169. - (void)addLocalizableCoverSheetEntry:sender;
  170.  
  171. /* Target/Action messages sent from Controls to set various parameters */
  172.  
  173. - (void)takeGridValueFrom:sender;
  174. - (void)takeGridGrayFrom:sender;
  175. - (void)takeGrayValueFrom:sender;
  176. - (void)takeLineWidthFrom:sender;
  177. - (void)takeLineJoinFrom:sender;
  178. - (void)takeLineCapFrom:sender;
  179. - (void)takeLineArrowFrom:sender;
  180. - (void)takeFillValueFrom:sender;
  181. - (void)takeFrameValueFrom:sender;
  182. - (void)takeLineColorFrom:sender;
  183. - (void)takeFillColorFrom:sender;
  184. - (void)takeFormEntryStatusFrom:sender;
  185.  
  186. - (void)changeFont:(id)sender;
  187.  
  188. /* Accepting becoming the First Responder */
  189.  
  190. - (BOOL)acceptsFirstResponder;
  191.  
  192. /* Printing-related methods */
  193.  
  194. - (void)endPrologue;
  195.  
  196. /* Archiving methods */
  197.  
  198. - (id)propertyList;
  199. - initWithFrame:(NSRect)frame fromPropertyList:(id)plist inDirectory:(NSString *)directory;
  200.  
  201. /* Useful scrolling methods */
  202.  
  203. - (void)scrollGraphicToVisible:(Graphic *)graphic;
  204. - (void)scrollPointToVisible:(NSPoint)point;
  205. - (void)scrollSelectionToVisible;
  206.  
  207.  
  208. - (void)checkSpelling:(id)sender;
  209. - (void)ignoreSpelling:(id)sender;
  210.  
  211. @end
  212.  
  213. /* Pasteboard */
  214.  
  215. typedef enum { LinkOnly = -1, DontLink = 0, Link = 1 } LinkType;
  216.  
  217. @interface GraphicView(NSPasteboard)
  218.  
  219. extern NSArray *TypesDrawExports(void);
  220. extern NSString *DrawPasteType(NSArray *types);
  221. extern NSString *ForeignPasteType(NSArray *types);
  222. extern NSString *TextPasteType(NSArray *types);
  223. extern BOOL IncludesType(NSArray *types, NSString *type);
  224. extern NSString *MatchTypes(NSArray *typesToMatch, NSArray *orderedTypes);
  225.  
  226. + (void)convert:(NSUnarchiver *)unarchiver to:(NSString *)type using:(SEL)writer toPasteboard:(NSPasteboard *)pb;
  227. + (void)pasteboard:(NSPasteboard *)sender provideDataForType:(NSString *)type;
  228.  
  229. - (NSData *)dataForEPS;
  230. - (NSData *)dataForEPSUsingList:(NSArray *)array;
  231. - (NSData *)dataForTIFF;
  232. - (NSData *)dataForTIFFUsingList:(NSArray *)array;
  233.  
  234. - (NSData *)copySelectionAsEPS;
  235. - (NSData *)copySelectionAsTIFF;
  236. - (NSData *)copySelection;
  237.  
  238. - copyToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types;
  239. - copyToPasteboard:(NSPasteboard *)pboard;
  240. - (BOOL)pasteForeignDataFromPasteboard:(NSPasteboard *)pboard andLink:(LinkType)doLink at:(NSPoint)point;
  241. - (NSArray *)pasteFromPasteboard:(NSPasteboard *)pboard andLink:(LinkType)doLink at:(const NSPoint *)point;
  242. - (void)paste:sender andLink:(LinkType)doLink;
  243. - (void)cut:(id)sender;
  244. - (void)copy:(id)sender;
  245. - (void)paste:(id)sender;
  246. - (void)pasteAndLink:sender;
  247.  
  248. @end
  249.  
  250. /* Data link methods */
  251.  
  252. @interface GraphicView(Links)
  253.  
  254. - (NSSelection *)currentSelection;
  255. - (Graphic *)findGraphicInSelection:(NSSelection *)selection;
  256. - (NSArray *)findGraphicsInSelection:(NSSelection *)selection;
  257.  
  258. - (void)writeLinkToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types;
  259. - (BOOL)addLink:(NSDataLink *)link toGraphic:(Graphic *)graphic at:(NSPoint)p update:(int)update;
  260.  
  261. - (BOOL)pasteFromPasteboard:(NSPasteboard *)pboard at:(NSSelection *)selection;
  262. - (BOOL)importFile:(NSString *)filename at:(NSSelection *)selection;
  263. - (void)pasteboard:(NSPasteboard *)sender provideDataForType:(NSString *)type;
  264. - copyToPasteboard:(NSPasteboard *)pboard at:(NSSelection *)selection cheapCopyAllowed:(BOOL)cheapCopyAllowed;
  265.  
  266. - (void)updateLinksPanel;
  267. - (NSDataLinkManager *)linkManager;
  268. - (void)setLinkManager:(NSDataLinkManager *)linkManager;
  269. - (BOOL)showSelection:(NSSelection *)selection;
  270. - (void)breakLinkAndRedrawOutlines:(NSDataLink *)aLink;
  271. - (void)updateTrackedLinks:(NSRect)rect;
  272. - (void)startTrackingLink:(NSDataLink *)link;
  273. - (void)stopTrackingLink:(NSDataLink *)link;
  274.  
  275. @end
  276.  
  277. /* Dragging */
  278.  
  279. @interface GraphicView(Drag)
  280.  
  281. - (void)registerForDragging;
  282. - (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender;
  283. - (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender;
  284. - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
  285.  
  286. @end
  287.  
  288. /* Services Menu */
  289.  
  290. @interface GraphicView(Services)
  291.  
  292. - (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType;
  293. - (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types;
  294. - readSelectionFromPasteboard:(NSPasteboard *)pboard;
  295.  
  296. @end
  297.  
  298. /*
  299.  * Since we can't be sure that we have an InspectorPanel, we use the
  300.  * objective-C respondsTo: mechanism to see if we can send the message
  301.  * initializeGraphic: to [NSApp inspectorPanel].  This dummy interface
  302.  * declaration declares those messages (so that even if they don't exists,
  303.  * we can at least use them to check with respondsTo:).  We don't want
  304.  * to import DrawApp.h or InspectorPanel.h since we might accidentally
  305.  * introduce a dependency on them which wouldn't be caught because we
  306.  * imported both of their interfaces.
  307.  */
  308.  
  309. @interface PossibleInspectorPanel : NSObject
  310.  
  311. - (NSPanel *)inspectorPanel;
  312. - (void)initializeGraphic:(Graphic *)graphic;
  313.  
  314. @end
  315.  
  316. extern NSEvent *periodicEventWithLocationSetToPoint(NSEvent *oldEvent, NSPoint point);
  317.