1 /******************************************************************************* 2 / 3 / File: TextView.h 4 / 5 / Description: BTextView displays and manages styled text. 6 / 7 / Copyright 1993-98, Be Incorporated, All Rights Reserved 8 / 9 *******************************************************************************/ 10 11 #ifndef _TEXTVIEW_H 12 #define _TEXTVIEW_H 13 14 #include <BeBuild.h> 15 #include <View.h> 16 17 /*----------------------------------------------------------------*/ 18 /*----- BTextView structures and definitions ---------------------*/ 19 20 struct text_run { 21 int32 offset; /* byte offset of first character of run*/ 22 BFont font; /* font of run*/ 23 rgb_color color; /* color of run*/ 24 }; 25 26 struct text_run_array { 27 int32 count; /* number of text runs*/ 28 text_run runs[1]; /* array of count number of runs*/ 29 }; 30 31 enum undo_state { 32 B_UNDO_UNAVAILABLE, 33 B_UNDO_TYPING, 34 B_UNDO_CUT, 35 B_UNDO_PASTE, 36 B_UNDO_CLEAR, 37 B_UNDO_DROP 38 }; 39 40 41 #if _PR2_COMPATIBLE_ 42 extern "C" void _ReservedTextView2__9BTextViewFv(BTextView *object, 43 BMessage *drag, 44 BBitmap **bitmap, 45 BPoint *point, 46 BHandler **handler); 47 #endif 48 49 50 class BBitmap; 51 class BClipboard; 52 class BFile; 53 class BList; 54 class _BTextGapBuffer_; 55 class _BLineBuffer_; 56 class _BStyleBuffer_; 57 class _BWidthBuffer_; 58 class _BUndoBuffer_; 59 class _BInlineInput_; 60 class _BTextTrackState_; 61 class _BTextChangeResult_; 62 63 extern "C" status_t _init_interface_kit_(); 64 65 /*----------------------------------------------------------------*/ 66 /*----- BTextView class ------------------------------------------*/ 67 68 class BTextView : public BView { 69 public: 70 BTextView(BRect frame, 71 const char *name, 72 BRect textRect, 73 uint32 resizeMask, 74 uint32 flags = B_WILL_DRAW | B_PULSE_NEEDED); 75 BTextView(BRect frame, 76 const char *name, 77 BRect textRect, 78 const BFont *initialFont, 79 const rgb_color *initialColor, 80 uint32 resizeMask, 81 uint32 flags); 82 BTextView(BMessage *data); 83 virtual ~BTextView(); 84 85 static BArchivable* Instantiate(BMessage *data); 86 virtual status_t Archive(BMessage *data, bool deep = true) const; 87 88 virtual void AttachedToWindow(); 89 virtual void DetachedFromWindow(); 90 virtual void Draw(BRect inRect); 91 virtual void MouseDown(BPoint where); 92 virtual void MouseUp(BPoint where); 93 virtual void MouseMoved(BPoint where, 94 uint32 code, 95 const BMessage *message); 96 virtual void WindowActivated(bool state); 97 virtual void KeyDown(const char *bytes, int32 numBytes); 98 virtual void Pulse(); 99 virtual void FrameResized(float width, float height); 100 virtual void MakeFocus(bool focusState = true); 101 virtual void MessageReceived(BMessage *message); 102 virtual BHandler* ResolveSpecifier(BMessage *message, 103 int32 index, 104 BMessage *specifier, 105 int32 form, 106 const char *property); 107 virtual status_t GetSupportedSuites(BMessage *data); 108 virtual status_t Perform(perform_code d, void *arg); 109 110 void SetText(const char *inText, 111 const text_run_array *inRuns = NULL); 112 void SetText(const char *inText, 113 int32 inLength, 114 const text_run_array *inRuns = NULL); 115 void SetText(BFile *inFile, 116 int32 startOffset, 117 int32 inLength, 118 const text_run_array *inRuns = NULL); 119 120 void Insert(const char *inText, 121 const text_run_array *inRuns = NULL); 122 void Insert(const char *inText, 123 int32 inLength, 124 const text_run_array *inRuns = NULL); 125 void Insert(int32 startOffset, 126 const char *inText, 127 int32 inLength, 128 const text_run_array *inRuns = NULL); 129 130 void Delete(); 131 void Delete(int32 startOffset, int32 endOffset); 132 133 const char* Text() const; 134 int32 TextLength() const; 135 void GetText(int32 offset, 136 int32 length, 137 char *buffer) const; 138 uchar ByteAt(int32 offset) const; 139 140 int32 CountLines() const; 141 int32 CurrentLine() const; 142 void GoToLine(int32 lineNum); 143 144 virtual void Cut(BClipboard *clipboard); 145 virtual void Copy(BClipboard *clipboard); 146 virtual void Paste(BClipboard *clipboard); 147 void Clear(); 148 149 virtual bool AcceptsPaste(BClipboard *clipboard); 150 virtual bool AcceptsDrop(const BMessage *inMessage); 151 152 virtual void Select(int32 startOffset, int32 endOffset); 153 void SelectAll(); 154 void GetSelection(int32 *outStart, int32 *outEnd) const; 155 156 void SetFontAndColor(const BFont *inFont, 157 uint32 inMode = B_FONT_ALL, 158 const rgb_color *inColor = NULL); 159 void SetFontAndColor(int32 startOffset, 160 int32 endOffset, 161 const BFont *inFont, 162 uint32 inMode = B_FONT_ALL, 163 const rgb_color *inColor = NULL); 164 165 void GetFontAndColor(int32 inOffset, 166 BFont *outFont, 167 rgb_color *outColor = NULL) const; 168 void GetFontAndColor(BFont *outFont, 169 uint32 *outMode, 170 rgb_color *outColor = NULL, 171 bool *outEqColor = NULL) const; 172 173 void SetRunArray(int32 startOffset, 174 int32 endOffset, 175 const text_run_array *inRuns); 176 text_run_array* RunArray(int32 startOffset, 177 int32 endOffset, 178 int32 *outSize = NULL) const; 179 180 int32 LineAt(int32 offset) const; 181 int32 LineAt(BPoint point) const; 182 BPoint PointAt(int32 inOffset, float *outHeight = NULL) const; 183 int32 OffsetAt(BPoint point) const; 184 int32 OffsetAt(int32 line) const; 185 186 virtual void FindWord(int32 inOffset, 187 int32 *outFromOffset, 188 int32 *outToOffset); 189 190 virtual bool CanEndLine(int32 offset); 191 192 float LineWidth(int32 lineNum = 0) const; 193 float LineHeight(int32 lineNum = 0) const; 194 float TextHeight(int32 startLine, int32 endLine) const; 195 196 void GetTextRegion(int32 startOffset, 197 int32 endOffset, 198 BRegion *outRegion) const; 199 200 virtual void ScrollToOffset(int32 inOffset); 201 void ScrollToSelection(); 202 203 void Highlight(int32 startOffset, int32 endOffset); 204 205 void SetTextRect(BRect rect); 206 BRect TextRect() const; 207 void SetStylable(bool stylable); 208 bool IsStylable() const; 209 void SetTabWidth(float width); 210 float TabWidth() const; 211 void MakeSelectable(bool selectable = true); 212 bool IsSelectable() const; 213 void MakeEditable(bool editable = true); 214 bool IsEditable() const; 215 void SetWordWrap(bool wrap); 216 bool DoesWordWrap() const; 217 void SetMaxBytes(int32 max); 218 int32 MaxBytes() const; 219 void DisallowChar(uint32 aChar); 220 void AllowChar(uint32 aChar); 221 void SetAlignment(alignment flag); 222 alignment Alignment() const; 223 void SetAutoindent(bool state); 224 bool DoesAutoindent() const; 225 void SetColorSpace(color_space colors); 226 color_space ColorSpace() const; 227 void MakeResizable(bool resize, BView *resizeView = NULL); 228 bool IsResizable() const; 229 void SetDoesUndo(bool undo); 230 bool DoesUndo() const; 231 void HideTyping(bool enabled); 232 bool IsTypingHidden(void) const; 233 234 virtual void ResizeToPreferred(); 235 virtual void GetPreferredSize(float *width, float *height); 236 virtual void AllAttached(); 237 virtual void AllDetached(); 238 239 static void* FlattenRunArray(const text_run_array *inArray, 240 int32 *outSize = NULL); 241 static text_run_array* UnflattenRunArray(const void *data, 242 int32 *outSize = NULL); 243 244 protected: 245 virtual void InsertText(const char *inText, 246 int32 inLength, 247 int32 inOffset, 248 const text_run_array *inRuns); 249 virtual void DeleteText(int32 fromOffset, int32 toOffset); 250 251 public: 252 virtual void Undo(BClipboard *clipboard); 253 undo_state UndoState(bool *isRedo) const; 254 255 protected: 256 virtual void GetDragParameters(BMessage *drag, 257 BBitmap **bitmap, 258 BPoint *point, 259 BHandler **handler); 260 261 /*----- Private or reserved -----------------------------------------*/ 262 private: 263 friend status_t _init_interface_kit_(); 264 friend class _BTextTrackState_; 265 266 #if _PR2_COMPATIBLE_ 267 friend void _ReservedTextView2__9BTextViewFv(BTextView *object, 268 BMessage *drag, 269 BBitmap **bitmap, 270 BPoint *point, 271 BHandler **handler); 272 #endif 273 274 virtual void _ReservedTextView3(); 275 virtual void _ReservedTextView4(); 276 virtual void _ReservedTextView5(); 277 virtual void _ReservedTextView6(); 278 virtual void _ReservedTextView7(); 279 virtual void _ReservedTextView8(); 280 281 #if !_PR3_COMPATIBLE_ 282 virtual void _ReservedTextView9(); 283 virtual void _ReservedTextView10(); 284 virtual void _ReservedTextView11(); 285 virtual void _ReservedTextView12(); 286 #endif 287 288 void InitObject(BRect textRect, 289 const BFont *initialFont, 290 const rgb_color *initialColor); 291 292 void HandleBackspace(); 293 void HandleArrowKey(uint32 inArrowKey); 294 void HandleDelete(); 295 void HandlePageKey(uint32 inPageKey); 296 void HandleAlphaKey(const char *bytes, int32 numBytes); 297 298 void Refresh(int32 fromOffset, 299 int32 toOffset, 300 bool erase, 301 bool scroll); 302 void RecalLineBreaks(int32 *startLine, int32 *endLine); 303 int32 FindLineBreak(int32 fromOffset, 304 float *outAscent, 305 float *outDescent, 306 float *ioWidth); 307 308 float StyledWidth(int32 fromOffset, 309 int32 length, 310 float *outAscent = NULL, 311 float *outDescent = NULL) const; 312 float ActualTabWidth(float location) const; 313 314 void DoInsertText(const char *inText, 315 int32 inLength, 316 int32 inOffset, 317 const text_run_array *inRuns, 318 _BTextChangeResult_ *outResult); 319 void DoDeleteText(int32 fromOffset, 320 int32 toOffset, 321 _BTextChangeResult_ *outResult); 322 323 void DrawLines(int32 startLine, 324 int32 endLine, 325 int32 startOffset = -1, 326 bool erase = false); 327 void DrawCaret(int32 offset); 328 void InvertCaret(); 329 void DragCaret(int32 offset); 330 331 void StopMouseTracking(); 332 bool PerformMouseUp(BPoint where); 333 bool PerformMouseMoved(BPoint where, 334 uint32 code); 335 336 void TrackMouse(BPoint where, const BMessage *message, 337 bool force = false); 338 339 void TrackDrag(BPoint where); 340 void InitiateDrag(); 341 bool MessageDropped(BMessage *inMessage, 342 BPoint where, 343 BPoint offset); 344 345 void UpdateScrollbars(); 346 void AutoResize(bool doredraw=true); 347 348 void NewOffscreen(float padding = 0.0F); 349 void DeleteOffscreen(); 350 351 void Activate(); 352 void Deactivate(); 353 354 void NormalizeFont(BFont *font); 355 356 uint32 CharClassification(int32 offset) const; 357 int32 NextInitialByte(int32 offset) const; 358 int32 PreviousInitialByte(int32 offset) const; 359 360 bool GetProperty(BMessage *specifier, 361 int32 form, 362 const char *property, 363 BMessage *reply); 364 bool SetProperty(BMessage *specifier, 365 int32 form, 366 const char *property, 367 BMessage *reply); 368 bool CountProperties(BMessage *specifier, 369 int32 form, 370 const char *property, 371 BMessage *reply); 372 373 void HandleInputMethodChanged(BMessage *message); 374 void HandleInputMethodLocationRequest(); 375 void CancelInputMethod(); 376 377 static void LockWidthBuffer(); 378 static void UnlockWidthBuffer(); 379 380 _BTextGapBuffer_* fText; 381 _BLineBuffer_* fLines; 382 _BStyleBuffer_* fStyles; 383 BRect fTextRect; 384 int32 fSelStart; 385 int32 fSelEnd; 386 bool fCaretVisible; 387 bigtime_t fCaretTime; 388 int32 fClickOffset; 389 int32 fClickCount; 390 bigtime_t fClickTime; 391 int32 fDragOffset; 392 uint8 fCursor; 393 bool fActive; 394 bool fStylable; 395 float fTabWidth; 396 bool fSelectable; 397 bool fEditable; 398 bool fWrap; 399 int32 fMaxBytes; 400 BList* fDisallowedChars; 401 alignment fAlignment; 402 bool fAutoindent; 403 BBitmap* fOffscreen; 404 color_space fColorSpace; 405 bool fResizable; 406 BView* fContainerView; 407 _BUndoBuffer_* fUndo; /* was _reserved[0] */ 408 _BInlineInput_* fInline; /* was _reserved[1] */ 409 BMessageRunner * fDragRunner; /* was _reserved[2] */ 410 BMessageRunner * fClickRunner; /* was _reserved[3] */ 411 BPoint fWhere; 412 _BTextTrackState_* fTrackingMouse; /* was _reserved[6] */ 413 _BTextChangeResult_* fTextChange; /* was _reserved[7] */ 414 uint32 _reserved[1]; /* was 8 */ 415 #if !_PR3_COMPATIBLE_ 416 uint32 _more_reserved[8]; 417 #endif 418 419 static _BWidthBuffer_* sWidths; 420 static sem_id sWidthSem; 421 static int32 sWidthAtom; 422 }; 423 424 /*-------------------------------------------------------------*/ 425 /*-------------------------------------------------------------*/ 426 427 #endif /* _TEXT_VIEW_H */ 428