1 /* 2 * dxtext.h 3 * 4 * Copyright (C) 1998,2006 by Jeroen van der Zijp. All Rights Reserved. 5 * Copyright 2010 David Vachulka <arch_dvx@users.sourceforge.net> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 20 * MA 02110-1301, USA. 21 */ 22 23 #ifndef DXTEXT_H 24 #define DXTEXT_H 25 26 #ifndef FXSCROLLAREA_H 27 #include "FXScrollArea.h" 28 #endif 29 30 #ifndef FXARRAY_H 31 #include "FXArray.h" 32 #endif 33 34 /// Highlight style entry 35 struct dxHiliteStyle { 36 FXColor normalForeColor; /// Normal text foreground color 37 FXColor normalBackColor; /// Normal text background color 38 FXColor selectForeColor; /// Selected text foreground color 39 FXColor selectBackColor; /// Selected text background color 40 FXuint style; /// Highlight text style 41 FXbool link; /// Link text for launch 42 }; 43 44 // Smiley entry 45 struct dxSmiley { 46 FXString text; //smiley text, e.g. :) etc. 47 FXString path; //path to smiley image, needed for resize 48 FXIcon *icon; //smiley icon 49 }; 50 51 enum { 52 SEL_TEXTLINK = SEL_LAST ///Link text clicked 53 }; 54 55 typedef FXArray<FXString> FXStringBuffer; 56 typedef FXArray<dxSmiley> dxSmileyArray; 57 typedef FXArray<FXint> dxFXintArray; 58 59 class dxText : public FXScrollArea 60 { 61 FXDECLARE(dxText) 62 public: 63 dxText(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=3,FXint pr=3,FXint pt=2,FXint pb=2); 64 virtual ~dxText(); 65 enum { 66 STYLE_UNDERLINE = 0x0001, /// Underline text 67 STYLE_STRIKEOUT = 0x0002, /// Strike out text 68 STYLE_BOLD = 0x0004 /// Bold text 69 }; 70 enum { 71 ID_COPY_SEL = FXScrollArea::ID_LAST, 72 ID_SELECT_ALL, 73 ID_DESELECT_ALL, 74 ID_SEARCH, 75 ID_CLEAR, 76 ID_LAST 77 }; 78 79 virtual void create(); 80 virtual void detach(); 81 virtual void layout(); 82 virtual void recalc(); 83 virtual bool canFocus() const; 84 void setTextColor(FXColor clr); getTextColor()85 FXColor getTextColor() const { return textColor; } 86 void setSelBackColor(FXColor clr); getSelBackColor()87 FXColor getSelBackColor() const { return selbackColor; } 88 void setSelTextColor(FXColor clr); getSelTextColor()89 FXColor getSelTextColor() const { return seltextColor; } 90 void setHiliteStyles(const dxHiliteStyle* styles); getHiliteStyles()91 const dxHiliteStyle* getHiliteStyles() const { return hilitestyles; } 92 void setFont(FXFont* fnt); getFont()93 FXFont* getFont() const { return font; } getUseSmiley()94 FXbool getUseSmiley() const { return usesmiley; } 95 void setSmileys(FXbool smiley, dxSmileyArray nsmileys); 96 void removeSmileys(); 97 virtual void appendText(const FXString &text); 98 virtual void appendStyledText(FXString text, FXint style=0); 99 virtual void removeLine(FXint line); 100 virtual void removeLastLine(); 101 virtual void clearText(); 102 virtual FXint getDefaultWidth(); 103 virtual FXint getDefaultHeight(); 104 virtual FXint getContentWidth(); 105 virtual FXint getContentHeight(); 106 void makeLastRowVisible(FXbool force=FALSE); 107 void extractText(FXString& text,FXint startindex,FXint startpos, FXint endindex, FXint endpos); hasSomeText()108 FXbool hasSomeText() const { return contents.no() && !contents[0].empty(); } 109 FXbool hasSelectedText() const; 110 void copySelectedText(); 111 FXbool isXYLink(FXint x, FXint y) const; 112 FXString getLinkTextXY(FXint x, FXint y); 113 void clearSelection(); 114 void setSelection(FXint startindex, FXint startpos, FXint endindex, FXint endpos); 115 FXbool findText(const FXString& string, FXint* index, FXint* beg, FXint* end, FXint startindex=0, FXint startpos=0, FXuint flags=SEARCH_FORWARD|SEARCH_WRAP|SEARCH_EXACT, FXint npar=1); 116 void makePositionVisible(FXint index, FXint pos); 117 void findStart(FXuint flags, FXint &start, FXint &pos); 118 119 long onPaint(FXObject*, FXSelector, void*); 120 long onMotion(FXObject*, FXSelector, void*); 121 long onLeftBtnPress(FXObject*,FXSelector,void*); 122 long onLeftBtnRelease(FXObject*,FXSelector,void*); 123 long onFocusIn(FXObject*,FXSelector,void*); 124 long onFocusOut(FXObject*,FXSelector,void*); 125 long onUngrabbed(FXObject*,FXSelector,void*); 126 long onSelectionLost(FXObject*,FXSelector,void*); 127 long onSelectionGained(FXObject*,FXSelector,void*); 128 long onSelectionRequest(FXObject*,FXSelector,void*); 129 long onClipboardLost(FXObject*,FXSelector,void*); 130 long onClipboardGained(FXObject*,FXSelector,void*); 131 long onClipboardRequest(FXObject*,FXSelector,void*); 132 long onKeyPress(FXObject*,FXSelector,void*); 133 long onKeyRelease(FXObject*,FXSelector,void*); 134 long onCmdCopySel(FXObject*,FXSelector,void*); 135 long onCmdSelectAll(FXObject*,FXSelector,void*); 136 long onCmdDeselectAll(FXObject*,FXSelector,void*); 137 long onCmdSearch(FXObject*,FXSelector,void*); 138 long onCmdClear(FXObject*,FXSelector,void*); 139 protected: 140 dxText(); 141 142 enum { 143 STYLE_MASK = 0x00FF, // Mask color table 144 STYLE_TEXT = 0x0100, // Draw some content 145 STYLE_SELECTED = 0x0200, // Selected 146 STYLE_CONTROL = 0x0400, // Control character 147 STYLE_SMILEY = 0x0800, // Smiley icon 148 }; 149 150 enum { 151 MOUSE_NONE, // No mouse operation 152 MOUSE_CHARS, // Selecting characters 153 MOUSE_WORDS, // Selecting words 154 MOUSE_LINES // Selecting lines 155 }; 156 157 FXStringBuffer contents; //Text data 158 FXStringBuffer styles; //Text style 159 dxFXintArray lines; //Real wraped lines for contents; index same as in contents 160 const dxHiliteStyle *hilitestyles; // Style definitions 161 FXFont *font; //Text font 162 FXint margintop; // Margins top 163 FXint marginbottom; // Margin bottom 164 FXint marginleft; // Margin left 165 FXint marginright; // Margin right 166 FXColor textColor; // Normal text color 167 FXColor selbackColor; // Select background color 168 FXColor seltextColor; // Select text color 169 FXint wrapwidth; // Wrap width in pixels 170 FXint nlines; // Real number lines 171 FXint topline; // Where first line is in contents 172 FXint vrows; // Default visible rows 173 FXint vcols; // Default visible columns 174 dxSmileyArray smileys; // smileys 175 FXbool usesmiley; // dxText use smiley 176 FXint cursorindex; // Cursor index in contents 177 FXint cursorpos; // Cursor position 178 FXint selstartindex; // Start selection index in contents 179 FXint selstartpos; // Start selection position 180 FXint selendindex; // End selection index in contents 181 FXint selendpos; // End selection position 182 FXuchar mode; // Mode widget is in 183 FXString clipped; // Clipped text 184 FXString searchstring; // String of last search 185 FXuint searchflags; // Flags of last search 186 187 virtual void fillBufferRect(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h,FXuint style) const; 188 virtual void drawTextFragment(FXDCWindow& dc, FXint x, FXint y, FXint w, FXint h, const FXchar *text, FXint n, FXuint style) const; 189 virtual void drawTextLine(FXDCWindow& dc, FXint line, FXint left, FXint right) const; 190 virtual void drawContents(FXDCWindow& dc, FXint x, FXint y, FXint w, FXint h) const; 191 virtual void drawIcon(FXDCWindow& dc, FXint x, FXint y, FXint index) const; 192 FXint charWidth(FXwchar ch, FXint col) const; 193 FXint smileyWidth(FXuint style) const; 194 FXuint styleOf(FXint line, FXint pos) const; 195 FXuint styleOfXY(FXint x, FXint y) const; 196 virtual void moveContents(FXint x,FXint y); 197 FXint getIndexOfY(FXint y) const; 198 FXint getIndexOfLine(FXint line) const; 199 FXint getPosOfXY(FXint x, FXint y) const; 200 FXint getYOfPos(FXint index, FXint pos) const; 201 void recompute(); 202 FXint lineCount(FXint line, FXint pos=0) const; 203 void createSmiley(FXString *text, FXString *style); 204 void removeSmiley(FXString *text, FXString *style); 205 FXString clearSmiley(FXint index, FXint pos, FXint len); 206 void wrapIndex(FXint index, FXint wrap, FXint &wrapstart, FXint &wrapend) const; 207 void setSelection(FXint index, FXint pos); 208 void killSelection(); 209 FXbool isSelection(FXint index, FXint pos) const; 210 void updateRange(FXint beg,FXint end) const; 211 void setCursorType(FXuint index); 212 FXint wordStart(FXint index, FXint pos); 213 FXint wordEnd(FXint index, FXint pos); 214 private: 215 dxText(const dxText&); 216 dxText& operator=(const dxText&); 217 }; 218 219 #endif /* DXTEXT_H */ 220 221