1 /* -*-objc-*- 2 NSText.h 3 4 The text object 5 6 Copyright (C) 1996 Free Software Foundation, Inc. 7 8 Author: Scott Christley <scottc@net-community.com> 9 Date: 1996 10 Author: Felipe A. Rodriguez <far@ix.netcom.com> 11 Date: July 1998 12 Author: Daniel Böhringer <boehring@biomed.ruhr-uni-bochum.de> 13 Date: August 1998 14 Author: Nicola Pero <n.pero@mi.flashnet.it> 15 Date: December 2000 16 17 This file is part of the GNUstep GUI Library. 18 19 This library is free software; you can redistribute it and/or 20 modify it under the terms of the GNU Lesser General Public 21 License as published by the Free Software Foundation; either 22 version 2 of the License, or (at your option) any later version. 23 24 This library is distributed in the hope that it will be useful, 25 but WITHOUT ANY WARRANTY; without even the implied warranty of 26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 Lesser General Public License for more details. 28 29 You should have received a copy of the GNU Lesser General Public 30 License along with this library; see the file COPYING.LIB. 31 If not, see <http://www.gnu.org/licenses/> or write to the 32 Free Software Foundation, 51 Franklin Street, Fifth Floor, 33 Boston, MA 02110-1301, USA. 34 */ 35 36 #ifndef _GNUstep_H_NSText 37 #define _GNUstep_H_NSText 38 39 /* 40 * The NSText class is now an abstract class. When you allocate an 41 * instance of NSText, an instance of NSTextView is always allocated 42 * instead. 43 * 44 * But you can still subclass NSText to implement your own text 45 * editing class not derived from NSTextView. NSText declares general 46 * methods that a text editing object should have; it has some helper 47 * methods which are simple wrappers around the real basic editing 48 * methods. The real editing methods are not implemented in NSText, 49 * which is why it is abstract. To make a working subclass, you need to 50 * implement these methods, marked as "PRIMITIVE" below. 51 * 52 * The working subclass could potentially be implemented in absolutely 53 * *any* way you want. I have been told that some versions of Emacs can 54 * be embedded as an X subwindow inside alien widgets and windows - so 55 * yes, potentially if you are able to figure out how to embed Emacs 56 * inside the GNUstep NSView tree, you can write a subclass of NSText 57 * which just uses Emacs. */ 58 59 #import <Foundation/NSObject.h> 60 #import <Foundation/NSRange.h> 61 #import <AppKit/NSView.h> 62 #import <AppKit/NSSpellProtocol.h> 63 //#import <AppKit/NSStringDrawing.h> 64 65 @class NSAttributedString; 66 @class NSData; 67 @class NSNotification; 68 @class NSString; 69 @class NSColor; 70 @class NSFont; 71 72 typedef NSInteger NSTextAlignment; 73 enum { 74 NSLeftTextAlignment = 0, 75 NSRightTextAlignment, 76 NSCenterTextAlignment, 77 NSJustifiedTextAlignment, 78 NSNaturalTextAlignment 79 }; 80 81 #if OS_API_VERSION(MAC_OS_X_VERSION_10_11, GS_API_LATEST) 82 enum { 83 NSTextAlignmentLeft = NSLeftTextAlignment, 84 NSTextAlignmentRight = NSRightTextAlignment, 85 NSTextAlignmentCenter = NSCenterTextAlignment, 86 NSTextAlignmentJustified = NSJustifiedTextAlignment, 87 NSTextAlignmentNatural = NSNaturalTextAlignment 88 }; 89 #endif 90 91 enum { 92 NSTextWritingDirectionEmbedding = (0 << 1), 93 NSTextWritingDirectionOverride = (1 << 1) 94 }; 95 96 enum { 97 NSIllegalTextMovement = 0, 98 NSReturnTextMovement = 0x10, 99 NSTabTextMovement = 0x11, 100 NSBacktabTextMovement = 0x12, 101 NSLeftTextMovement = 0x13, 102 NSRightTextMovement = 0x14, 103 NSUpTextMovement = 0x15, 104 NSDownTextMovement = 0x16, 105 NSCancelTextMovement = 0x17, 106 NSOtherTextMovement = 0 107 }; 108 109 enum { 110 NSParagraphSeparatorCharacter = 0x2029, 111 NSLineSeparatorCharacter = 0x2028, 112 NSTabCharacter = 0x0009, 113 NSFormFeedCharacter = 0x000c, 114 NSNewlineCharacter = 0x000a, 115 NSCarriageReturnCharacter = 0x000d, 116 NSEnterCharacter = 0x0003, 117 NSBackspaceCharacter = 0x0008, 118 NSBackTabCharacter = 0x0019, 119 NSDeleteCharacter = 0x007f, 120 }; 121 122 123 /* The following are required by the original openstep doc. */ 124 enum { 125 NSBackspaceKey = 8, 126 NSCarriageReturnKey = 13, 127 NSDeleteKey = 0x7f, 128 NSBacktabKey = 25 129 }; 130 131 @interface NSText : NSView <NSChangeSpelling, NSIgnoreMisspelledWords> 132 { 133 } 134 135 /* 136 * Getting and Setting Contents 137 */ 138 /* these aren't in OPENSTEP */ 139 - (void) replaceCharactersInRange: (NSRange)aRange 140 withRTF: (NSData*)rtfData; 141 - (void) replaceCharactersInRange: (NSRange)aRange 142 withRTFD: (NSData*)rtfdData; 143 /* PRIMITIVE */ 144 - (void) replaceCharactersInRange: (NSRange)aRange 145 withString: (NSString*)aString; 146 /* PRIMITIVE */ 147 -(void) replaceCharactersInRange: (NSRange)aRange /* GNUstep extension */ 148 withAttributedString: (NSAttributedString *)attrString; 149 /* PRIMITIVE */ 150 - (void) setString: (NSString*)aString; 151 /* PRIMITIVE */ 152 - (NSString*) string; 153 154 /* 155 * Old fashioned OpenStep methods (wrappers for the previous ones) 156 */ 157 - (void) replaceRange: (NSRange)aRange withString: (NSString*)aString; /* not OPENSTEP */ 158 - (void) replaceRange: (NSRange)aRange withRTF: (NSData*)rtfData; 159 - (void) replaceRange: (NSRange)aRange withRTFD: (NSData*)rtfdData; 160 - (void) setText: (NSString*)aString; 161 - (void) setText: (NSString*)aString range: (NSRange)aRange; /* not OPENSTEP */ 162 - (NSString*) text; 163 164 /* 165 * Graphic attributes 166 */ 167 /* PRIMITIVE */ 168 - (NSColor*) backgroundColor; 169 /* PRIMITIVE */ 170 - (BOOL) drawsBackground; 171 /* PRIMITIVE */ 172 - (void) setBackgroundColor: (NSColor*)color; 173 /* PRIMITIVE */ 174 - (void) setDrawsBackground: (BOOL)flag; 175 176 /* 177 * Managing Global Characteristics 178 */ 179 - (BOOL) importsGraphics; /* PRIMITIVE */ 180 - (BOOL) isEditable; /* PRIMITIVE */ 181 - (BOOL) isFieldEditor; /* PRIMITIVE */ 182 - (BOOL) isRichText; /* PRIMITIVE */ 183 - (BOOL) isSelectable; /* PRIMITIVE */ 184 - (void) setEditable: (BOOL)flag; /* PRIMITIVE */ 185 - (void) setFieldEditor: (BOOL)flag; /* PRIMITIVE */ 186 - (void) setImportsGraphics: (BOOL)flag; /* PRIMITIVE */ 187 - (void) setRichText: (BOOL)flag; /* PRIMITIVE */ 188 - (void) setSelectable: (BOOL)flag; /* PRIMITIVE */ 189 190 /* 191 * Using the font panel 192 */ 193 - (void) setUsesFontPanel: (BOOL)flag; /* PRIMITIVE */ 194 - (BOOL) usesFontPanel; /* PRIMITIVE */ 195 196 /* 197 * Managing the Ruler 198 */ 199 - (BOOL) isRulerVisible; /* PRIMITIVE */ 200 - (void) toggleRuler: (id)sender; /* PRIMITIVE */ 201 202 /* 203 * Managing the Selection 204 */ 205 - (NSRange) selectedRange; 206 - (void) setSelectedRange: (NSRange)range; 207 208 /* 209 * Responding to Editing Commands 210 */ 211 - (void) copy: (id)sender; /* PRIMITIVE */ 212 - (void) copyFont: (id)sender; /* PRIMITIVE */ 213 - (void) copyRuler: (id)sender; /* PRIMITIVE */ 214 - (void) cut: (id)sender; 215 - (void) delete: (id)sender; /* PRIMITIVE */ 216 - (void) paste: (id)sender; /* PRIMITIVE */ 217 - (void) pasteFont: (id)sender; /* PRIMITIVE */ 218 - (void) pasteRuler: (id)sender; /* PRIMITIVE */ 219 - (void) selectAll: (id)sender; 220 221 /* 222 * Managing Font 223 */ 224 - (void) changeFont: (id)sender; /* PRIMITIVE */ 225 - (NSFont*) font; /* PRIMITIVE */ 226 - (void) setFont: (NSFont*)font; /* PRIMITIVE */ 227 - (void) setFont: (NSFont*)font range: (NSRange)aRange; /* PRIMITIVE */ 228 /* Old OpenStep name for the same method. */ 229 - (void) setFont: (NSFont*)font ofRange: (NSRange)aRange; 230 231 /* 232 * Managing Alignment 233 */ 234 - (NSTextAlignment) alignment; /* PRIMITIVE */ 235 - (void) setAlignment: (NSTextAlignment)mode; /* PRIMITIVE */ 236 - (void) alignCenter: (id)sender; /* PRIMITIVE */ 237 - (void) alignLeft: (id)sender; /* PRIMITIVE */ 238 - (void) alignRight: (id)sender; /* PRIMITIVE */ 239 240 /* 241 * Text colour 242 */ 243 - (void) setTextColor: (NSColor*)color range: (NSRange)aRange; /* PRIMITIVE */ /* not OPENSTEP */ 244 - (void) setColor: (NSColor*)color ofRange: (NSRange)aRange; /* PRIMITIVE */ 245 - (void) setTextColor: (NSColor*)color; /* PRIMITIVE */ 246 - (NSColor*) textColor; /* PRIMITIVE */ 247 248 /* 249 * Text attributes 250 */ 251 - (void) subscript: (id)sender; /* PRIMITIVE */ 252 - (void) superscript: (id)sender; /* PRIMITIVE */ 253 - (void) underline: (id)sender; /* PRIMITIVE */ 254 - (void) unscript: (id)sender; /* PRIMITIVE */ 255 256 /* 257 * Reading and Writing RTFD Files 258 */ 259 -(BOOL) readRTFDFromFile: (NSString*)path; /* PRIMITIVE */ 260 -(BOOL) writeRTFDToFile: (NSString*)path atomically: (BOOL)flag; /* PRIMITIVE */ 261 -(NSData*) RTFDFromRange: (NSRange)aRange; /* PRIMITIVE */ 262 -(NSData*) RTFFromRange: (NSRange)aRange; /* PRIMITIVE */ 263 264 /* 265 * Sizing the Frame Rectangle 266 */ 267 - (BOOL) isHorizontallyResizable; /* PRIMITIVE */ 268 - (BOOL) isVerticallyResizable; /* PRIMITIVE */ 269 - (NSSize) maxSize; /* PRIMITIVE */ 270 - (NSSize) minSize; /* PRIMITIVE */ 271 - (void) setHorizontallyResizable: (BOOL)flag; /* PRIMITIVE */ 272 - (void) setMaxSize: (NSSize)newMaxSize; /* PRIMITIVE */ 273 - (void) setMinSize: (NSSize)newMinSize; /* PRIMITIVE */ 274 - (void) setVerticallyResizable: (BOOL)flag; /* PRIMITIVE */ 275 - (void) sizeToFit; /* PRIMITIVE */ 276 277 /* 278 * Spelling 279 */ 280 - (void) checkSpelling: (id)sender; /* PRIMITIVE */ 281 - (void) showGuessPanel: (id)sender; 282 283 /* 284 * Scrolling 285 */ 286 - (void) scrollRangeToVisible: (NSRange)aRange; /* PRIMITIVE */ 287 288 /* 289 * Managing the Delegate 290 */ 291 - (id) delegate; /* PRIMITIVE */ 292 - (void) setDelegate: (id)anObject; /* PRIMITIVE */ 293 294 /* 295 * NSChangeSpelling protocol 296 */ 297 - (void) changeSpelling: (id)sender; /* PRIMITIVE */ 298 299 /* 300 * NSIgnoreMisspelledWords protocol 301 */ 302 - (void) ignoreSpelling: (id)sender; /* PRIMITIVE */ /* not OPENSTEP */ 303 @end 304 305 @interface NSText (GNUstepExtensions) 306 307 - (NSUInteger) textLength; /* PRIMITIVE */ 308 309 @end 310 311 /* Notifications */ 312 APPKIT_EXPORT NSString *NSTextDidBeginEditingNotification; 313 APPKIT_EXPORT NSString *NSTextDidEndEditingNotification; 314 APPKIT_EXPORT NSString *NSTextDidChangeNotification; 315 316 @interface NSObject (NSTextDelegate) 317 - (BOOL) textShouldBeginEditing: (NSText*)textObject; /* YES means do it */ 318 - (BOOL) textShouldEndEditing: (NSText*)textObject; /* YES means do it */ 319 - (void) textDidBeginEditing: (NSNotification*)notification; 320 - (void) textDidEndEditing: (NSNotification*)notification; 321 - (void) textDidChange: (NSNotification*)notification; /* Any keyDown or paste which changes the contents causes this */ 322 @end 323 324 #endif // _GNUstep_H_NSText 325 326