1 /* 2 FXiTe - The Free eXtensIble Text Editor 3 Copyright (c) 2009-2013 Jeffrey Pohlmeyer <yetanothergeek@gmail.com> 4 5 This program is free software; you can redistribute it and/or modify it 6 under the terms of the GNU General Public License version 3 as 7 published by the Free Software Foundation. 8 9 This software is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 #ifndef SCIDOC_H 20 #define SCIDOC_H 21 22 #include <Scintilla.h> 23 #include <FXScintilla.h> 24 25 typedef struct _StyleDef StyleDef; 26 typedef struct _LangStyle LangStyle; 27 28 29 class SciSearch; 30 31 32 class SciDoc : public FXScintilla { 33 FXDECLARE(SciDoc) 34 friend class SciSearch; 35 private: 36 LangStyle *_lang; 37 FXString _filename; 38 FXchar bom[4]; 39 const char*_openers; 40 const char*_closers; 41 FXString _lasterror; 42 char _caretlinealpha[16]; 43 char _caretlinebg[16]; 44 char _whitespacebg[16]; 45 char _whitespacefg[16]; 46 char _rightmarginbg[16]; 47 char _caretfg[16]; 48 char _selectionbg[16]; 49 50 FXTime _filetime; 51 FXint splitter_style; 52 unsigned char user_undo_level; 53 54 unsigned char _loading:1; 55 unsigned char _dirty:1; 56 unsigned char check_stale:1; 57 unsigned char need_backup:1; 58 unsigned char need_styled:1; 59 unsigned char _utf8:1; 60 unsigned char smart_home:1; 61 unsigned char recording:1; 62 protected: SciDoc()63 SciDoc(){} 64 inline bool IsInsideBrace(long &pos); 65 inline bool IsOutsideBrace(long &pos); 66 inline bool IsAfterBrace(long &pos); 67 inline bool IsBrace(long &pos, int mode); 68 void GetSelection(CharacterRange &crange); 69 bool DoLoadFromFile(const char*filename,bool insert=false); 70 void AdjustHScroll(); 71 void SetCaseOfSelection(int msg); 72 public: Master()73 SciDoc*Master() { return (SciDoc*)getPrev(); } Slave()74 SciDoc*Slave() { return (SciDoc*)getNext(); } 75 SciSearch *search; 76 long onKeyPress(FXObject *o, FXSelector sel, void *p); 77 long onRightBtnPress(FXObject *o, FXSelector sel, void *p); 78 long onRecordReplace(FXObject *o, FXSelector sel, void *p); 79 virtual void moveContents(FXint x,FXint y); 80 SciDoc(FXComposite*p, FXObject*tgt=NULL, FXSelector sel=0); 81 ~SciDoc(); 82 83 bool GtLtIsBrace(); /* Whether to consider <> for brace matching */ 84 void GtLtIsBrace(bool gtlt); 85 void MatchBrace(); 86 void setFont(const FXString &font, int size); 87 88 bool setLanguage(const char*name); 89 bool setLanguage(LangStyle*ls); 90 bool setLanguageFromFileName(const char*ext); 91 bool setLanguageFromContent(); 92 bool SetLanguageForHeader(const FXString &filename); getLanguage()93 LangStyle* getLanguage() { return _lang; } 94 static void DefaultStyles(StyleDef*styles); 95 static StyleDef* DefaultStyles(); 96 Loading()97 bool Loading() { return Master()?Master()->Loading():_loading; } Dirty()98 bool Dirty() { return Master()?Master()->Dirty():_dirty; } Dirty(bool dirty)99 void Dirty(bool dirty) { _dirty=dirty; if (Master()) { Master()->Dirty(dirty); } } NeedBackup()100 bool NeedBackup() { return Master()?Master()->NeedBackup():need_backup; } NeedBackup(bool need)101 void NeedBackup(bool need) { need_backup=need; if (Master()) { Master()->NeedBackup(need); } } 102 NeedStyled(bool need)103 void NeedStyled(bool need) { need_styled=need; } NeedStyled()104 bool NeedStyled() { return need_styled; } 105 106 int Stale(); /* 0=ok; 1=modified; 2=deleted; */ DoStaleTest(bool doit)107 void DoStaleTest(bool doit) { check_stale=doit; if (Master()) { Master()->DoStaleTest(doit); } } DoStaleTest()108 bool DoStaleTest() { return Master()?Master()->DoStaleTest():check_stale; } Filename()109 const FXString Filename() { return Master()?Master()->Filename():_filename; } GetLastError()110 const FXString GetLastError() { return Master()?Master()->GetLastError():_lasterror; } 111 InsertFile(const char * filename)112 bool InsertFile(const char*filename) { return DoLoadFromFile(filename, true); } LoadFromFile(const char * filename)113 bool LoadFromFile(const char*filename) { return DoLoadFromFile(filename, false); } 114 bool SaveToFile(const char*filename, bool as_itself=true); 115 116 long GetSelLength(); 117 long GetSelText(FXString&txt); 118 void SetSelText(const FXString&source); 119 long WordAtPos(FXString&s, long pos=-1); 120 long PrefixAtPos(FXString&s, long pos=-1); CharAt(long pos)121 long CharAt(long pos) { return sendMessage(SCI_GETCHARAT,pos,0); } GetTextLength()122 long GetTextLength() { return sendMessage(SCI_GETLENGTH,0,0); } 123 long GetText(FXString&txt); 124 void SetText(const char *source); 125 bool GoToStringCoords(const char*coords); 126 void GoToPos(long pos); 127 void GoToCoords(long row, long col); 128 void ScrollCaret(long pos=-1); 129 void ScrollWrappedInsert(); 130 int GetLineLength(int line); 131 long GetLineText(long linenum, FXString &text); GetLineCount()132 long GetLineCount() { return sendMessage(SCI_GETLINECOUNT,0,0); } 133 void SetLineIndentation(int line, int indent); GetCaretPos()134 long GetCaretPos() { return sendMessage(SCI_GETCURRENTPOS,0,0); } GetLineNumber()135 long GetLineNumber() { return sendMessage(SCI_LINEFROMPOSITION, GetCaretPos(), 0); } GetColumnNumber()136 long GetColumnNumber() { return sendMessage(SCI_GETCOLUMN, GetCaretPos(), 0); } 137 void ZoomStep(int direction); 138 void SetZoom(int zoom); 139 int GetZoom(); 140 void CaretLineBG(const char*bgcolor); 141 void CaretLineAlpha(const char*alpha); // <= This really screws up CaretLineBG() CaretLineBG()142 const char* CaretLineBG() {return _caretlinebg[0]?_caretlinebg:NULL; } 143 144 void RightMarginBG(const char*bgcolor); RightMarginBG()145 const char* RightMarginBG() {return _rightmarginbg[0]?_rightmarginbg:NULL; } 146 147 void WhiteSpaceBG(const char*bgcolor); 148 void WhiteSpaceFG(const char*fgcolor); 149 150 void CaretFG(const char*fgcolor); 151 void SelectionBG(const char*bgcolor); 152 WhiteSpaceBG()153 const char* WhiteSpaceBG() {return _whitespacebg[0]?_whitespacebg:NULL; } 154 155 void UpdateStyle(); 156 GetReadOnly()157 bool GetReadOnly() { return sendMessage(SCI_GETREADONLY,0,0); } 158 ShowWhiteSpace()159 bool ShowWhiteSpace() { return sendMessage(SCI_GETVIEWWS,0,0)!=SCWS_INVISIBLE; } 160 void ShowWhiteSpace(bool showit); 161 TabWidth()162 int TabWidth() { return sendMessage(SCI_GETTABWIDTH,0,0); } 163 void TabWidth(int w); 164 void ShowLineNumbers(bool showit); ShowLineNumbers()165 bool ShowLineNumbers() { return sendMessage(SCI_GETMARGINWIDTHN, 0, 0)?true:false; } 166 SetEdgeColumn(int edge)167 void SetEdgeColumn(int edge) { sendMessage(SCI_SETEDGECOLUMN,edge,0); } GetEdgeColumn()168 int GetEdgeColumn() { return sendMessage(SCI_GETEDGECOLUMN,0,0); } GetShowEdge()169 bool GetShowEdge() { return sendMessage(SCI_GETEDGEMODE,0,0)!=EDGE_NONE; } SetShowEdge(bool showit)170 void SetShowEdge(bool showit) {sendMessage(SCI_SETEDGEMODE, showit?EDGE_LINE:EDGE_NONE,0); } GetShowIndent()171 bool GetShowIndent() { return sendMessage(SCI_GETINDENTATIONGUIDES,0,0)!=SC_IV_NONE; } SetShowIndent(bool showit)172 void SetShowIndent(bool showit) { sendMessage(SCI_SETINDENTATIONGUIDES,showit?SC_IV_LOOKBOTH:SC_IV_NONE,0); } 173 174 void SmartHome(bool smart); 175 UseTabs()176 bool UseTabs() { return sendMessage(SCI_GETUSETABS, 0, 0)?true:false; } UseTabs(bool use)177 void UseTabs(bool use) {sendMessage(SCI_SETUSETABS, use, 0); } CaretWidth(int w)178 void CaretWidth(int w) { sendMessage(SCI_SETCARETWIDTH, w<1?1:w>3?3:w, 0); } CaretWidth()179 int CaretWidth() { return sendMessage(SCI_GETCARETWIDTH, 0, 0); } 180 SmoothScroll()181 bool SmoothScroll() { return (getScrollStyle()&SCROLLERS_DONT_TRACK)==0; } SmoothScroll(bool smooth)182 void SmoothScroll(bool smooth) { 183 setScrollStyle(smooth?(getScrollStyle()&~SCROLLERS_DONT_TRACK):(getScrollStyle()|SCROLLERS_DONT_TRACK)); 184 } 185 void SetSplit(FXint style); GetSplit()186 FXint GetSplit() { return splitter_style; } 187 static const char* BinaryFileMessage(); 188 void SetEolModeFromContent(); 189 void SetUTF8(bool utf8); GetUTF8()190 bool GetUTF8() { return _utf8; } 191 const char*GetEncoding(); 192 void SetUserUndoLevel(FXint action); // 1:push level; -1: pop level; 0:reset level 193 void SetProperty(const char*key, const char*value); 194 bool GetProperty(const FXString &key, FXString &value, bool expanded=false); 195 int GetPropertyInt(const char*key, int default_value); 196 void SetWordWrap(bool on); 197 bool GetWordWrap(); 198 void SetWrapAware(bool aware); 199 void SelectionToUpper(); 200 void SelectionToLower(); 201 void ShowPopupMenu(int x, int y); 202 void EnableRecorder(bool enable_recorder); RecorderEnabled()203 bool RecorderEnabled() { return recording; } 204 enum { 205 ID_RECORD_REPLACE=FXScintilla::ID_LAST, 206 ID_LAST 207 }; 208 }; 209 210 #define sendString(iMessage, wParam, lParam) sendMessage(iMessage, wParam, reinterpret_cast<long>(lParam)) 211 212 #endif 213 214