1 #ifndef WRITEWINDOW_H 2 #define WRITEWINDOW_H 3 4 #include "InputDialog.h" 5 6 7 class WriteWindow; 8 class XFileWrite; 9 10 // Undo record for text fragment 11 class FXTextCommand : public FXCommand 12 { 13 FXDECLARE_ABSTRACT(FXTextCommand) 14 protected: 15 FXText* text; // Text widget 16 char* buffer; // Character buffer 17 int pos; // Character position 18 int ndel; // Deleted characters 19 int nins; // Inserted characters 20 public: FXTextCommand(FXText * txt,int p,int nd,int ni)21 FXTextCommand(FXText* txt, int p, int nd, int ni) : text(txt), buffer(NULL), pos(p), ndel(nd), nins(ni) 22 {} 23 virtual FXuint size() const; 24 ~FXTextCommand()25 virtual ~FXTextCommand() 26 { 27 FXFREE(&buffer); 28 } 29 }; 30 31 32 // Insert command 33 class FXTextInsert : public FXTextCommand 34 { 35 FXDECLARE_ABSTRACT(FXTextInsert) 36 public: 37 FXTextInsert(FXText* txt, int p, int ni, const char* ins); undoName()38 virtual FXString undoName() const 39 { 40 return("Undo insert"); 41 } 42 redoName()43 virtual FXString redoName() const 44 { 45 return("Redo insert"); 46 } 47 48 virtual void undo(); 49 virtual void redo(); 50 }; 51 52 53 // Delete command 54 class FXTextDelete : public FXTextCommand 55 { 56 FXDECLARE_ABSTRACT(FXTextDelete) 57 public: 58 FXTextDelete(FXText* txt, int p, int nd, const char* del); undoName()59 virtual FXString undoName() const 60 { 61 return("Undo delete"); 62 } 63 redoName()64 virtual FXString redoName() const 65 { 66 return("Redo delete"); 67 } 68 69 virtual void undo(); 70 virtual void redo(); 71 }; 72 73 74 // Replace command 75 class FXTextReplace : public FXTextCommand 76 { 77 FXDECLARE_ABSTRACT(FXTextReplace) 78 public: 79 FXTextReplace(FXText* txt, int p, int nd, int ni, const char* del, const char* ins); undoName()80 virtual FXString undoName() const 81 { 82 return("Undo replace"); 83 } 84 redoName()85 virtual FXString redoName() const 86 { 87 return("Redo replace"); 88 } 89 90 virtual void undo(); 91 virtual void redo(); 92 }; 93 94 95 class Preferences : public DialogBox 96 { 97 FXDECLARE(Preferences) 98 protected: 99 FXTextField* wrapmargin; 100 FXString wrapmargin_prev; 101 FXTextField* tabsize; 102 FXString tabsize_prev; 103 FXCheckButton* stripcr; 104 FXbool stripcr_prev; 105 FXText* editor; 106 WriteWindow* editwin; 107 FXColor textcolor_prev; 108 FXColor backcolor_prev; 109 FXColor seltextcolor_prev; 110 FXColor selbackcolor_prev; 111 FXColor hilitetextcolor_prev; 112 FXColor hilitebackcolor_prev; 113 FXColor cursorcolor_prev; 114 FXColor barcolor_prev; 115 FXColor numbercolor_prev; 116 private: Preferences()117 Preferences() : wrapmargin(NULL), tabsize(NULL), stripcr(NULL), stripcr_prev(false), editor(NULL), editwin(NULL), 118 textcolor_prev(FXRGB(0, 0, 0)), backcolor_prev(FXRGB(0, 0, 0)), seltextcolor_prev(FXRGB(0, 0, 0)), selbackcolor_prev(FXRGB(0, 0, 0)), 119 hilitetextcolor_prev(FXRGB(0, 0, 0)), hilitebackcolor_prev(FXRGB(0, 0, 0)), cursorcolor_prev(FXRGB(0, 0, 0)), barcolor_prev(FXRGB(0, 0, 0)), 120 numbercolor_prev(FXRGB(0, 0, 0)) 121 {} 122 Preferences(const Preferences&); 123 Preferences& operator=(const Preferences&); 124 125 public: 126 enum 127 { 128 ID_ACCEPT=DialogBox::ID_LAST, 129 ID_CANCEL, 130 ID_TEXT_BACK, 131 ID_TEXT_FORE, 132 ID_TEXT_SELBACK, 133 ID_TEXT_SELFORE, 134 ID_TEXT_HILITEBACK, 135 ID_TEXT_HILITEFORE, 136 ID_TEXT_CURSOR, 137 ID_TEXT_NUMBACK, 138 ID_TEXT_NUMFORE, 139 ID_LAST 140 }; 141 public: 142 143 // Create preferences dialog 144 Preferences(WriteWindow* owner); 145 146 // Owner is text window getApp()147 XFileWrite* getApp() const 148 { 149 return((XFileWrite*)DialogBox::getApp()); 150 } 151 152 FXuint execute(FXuint); 153 long onCmdCancel(FXObject*, FXSelector, void*); 154 long onCmdAccept(FXObject*, FXSelector, void*); 155 long onCmdTextBackColor(FXObject*, FXSelector, void*); 156 long onUpdTextBackColor(FXObject*, FXSelector, void*); 157 long onCmdTextForeColor(FXObject*, FXSelector, void*); 158 long onUpdTextForeColor(FXObject*, FXSelector, void*); 159 long onCmdTextSelBackColor(FXObject*, FXSelector, void*); 160 long onUpdTextSelBackColor(FXObject*, FXSelector, void*); 161 long onCmdTextSelForeColor(FXObject*, FXSelector, void*); 162 long onUpdTextSelForeColor(FXObject*, FXSelector, void*); 163 long onCmdTextHiliteBackColor(FXObject*, FXSelector, void*); 164 long onUpdTextHiliteBackColor(FXObject*, FXSelector, void*); 165 long onCmdTextHiliteForeColor(FXObject*, FXSelector, void*); 166 long onUpdTextHiliteForeColor(FXObject*, FXSelector, void*); 167 long onCmdTextCursorColor(FXObject*, FXSelector, void*); 168 long onUpdTextCursorColor(FXObject*, FXSelector, void*); 169 long onCmdTextBarColor(FXObject*, FXSelector, void*); 170 long onUpdTextBarColor(FXObject*, FXSelector, void*); 171 long onCmdTextNumberColor(FXObject*, FXSelector, void*); 172 long onUpdTextNumberColor(FXObject*, FXSelector, void*); 173 }; 174 175 // Editor main window 176 class WriteWindow : public FXMainWindow 177 { 178 FXDECLARE(WriteWindow) 179 protected: 180 FXToolBarShell* dragshell; // Shell for floating toolbar 181 FXMenuPane* filemenu; // File menu 182 FXMenuPane* editmenu; // Edit menu 183 FXMenuPane* searchmenu; // Search menu 184 FXMenuPane* prefsmenu; // Preferences menu 185 FXMenuPane* viewmenu; // View menu 186 FXMenuPane* windowmenu; // Window menu 187 FXMenuPane* helpmenu; // Help menu 188 FXMenuPane* popupmenu; // Popup menu 189 FXHorizontalFrame* undoredoblock; // Undo/redo block on status line 190 FXText* editor; // Multiline text widget 191 FXMenuBar* menubar; // Menu bar 192 FXToolBar* toolbar; // Tool bar 193 FXStatusBar* statusbar; // Status bar 194 FXFont* font; // Text window font 195 FXUndoList undolist; // Undo list 196 FXRecentFiles mrufiles; // Recent files list 197 FXString filename; // File being edited 198 FXTime filetime; // Original modtime of file 199 FXbool filenameset; // Filename is set 200 FXString searchpath; // To search for files 201 FXbool stripcr; // Strip carriage returns 202 FXbool linesnum; // Lines numbering 203 FXbool readonly; // Text is read only 204 InputDialog* printdialog; 205 Preferences* prefsdialog; 206 FXSearchDialog* searchdialog; 207 FXReplaceDialog* replacedialog; 208 FXbool smoothscroll; 209 FXbool fromreg; // Read window size and position from the regsitry 210 FXuint ww; // Window width 211 FXuint hh; // Window height 212 FXuint xx; // Window x position 213 FXuint yy; // Window y position 214 FXButton* cut; // Cut button 215 FXButton* paste; // Paste button 216 FXMenuCommand* cutmc; // Cut menu item 217 FXMenuCommand* pastemc; // Paste menu item 218 219 protected: 220 void loadConfig(); 221 void saveConfig(); 222 FXString unique() const; 223 WriteWindow* findUnused() const; 224 WriteWindow* findWindow(const FXString& file) const; 225 int backwardByContext(int pos) const; 226 int forwardByContext(int pos) const; 227 228 protected: 229 enum 230 { 231 MAXUNDOSIZE = 1000000, // Don't let the undo buffer get out of hand 232 KEEPUNDOSIZE = 500000 // When MAXUNDOSIZE was exceeded, trim down to this size 233 }; 234 private: WriteWindow()235 WriteWindow() : dragshell(NULL), filemenu(NULL), editmenu(NULL), searchmenu(NULL), prefsmenu(NULL), viewmenu(NULL), windowmenu(NULL), helpmenu(NULL), 236 popupmenu(NULL), undoredoblock(NULL), editor(NULL), menubar(NULL), toolbar(NULL), statusbar(NULL), font(NULL), 237 filetime(0), filenameset(false), stripcr(false), linesnum(false), readonly(false), printdialog(NULL), 238 prefsdialog(NULL), searchdialog(NULL), replacedialog(NULL), smoothscroll(false), fromreg(false), 239 ww(0), hh(0), xx(0), yy(0), cut(NULL), paste(NULL), cutmc(NULL), pastemc(NULL) 240 {} 241 WriteWindow(const WriteWindow&); 242 WriteWindow& operator=(const WriteWindow&); 243 244 public: 245 long onUpdateTitle(FXObject*, FXSelector, void*); 246 long onFocusIn(FXObject*, FXSelector, void*); 247 long onCmdAbout(FXObject*, FXSelector, void*); 248 long onSigHarvest(FXObject*, FXSelector, void*); 249 250 // File management 251 long onCmdNew(FXObject*, FXSelector, void*); 252 long onCmdOpen(FXObject*, FXSelector, void*); 253 long onCmdOpenRecent(FXObject*, FXSelector, void*); 254 long onCmdOpenSelected(FXObject*, FXSelector, void*); 255 long onCmdSave(FXObject*, FXSelector, void*); 256 long onUpdSave(FXObject*, FXSelector, void*); 257 long onCmdSaveAs(FXObject*, FXSelector, void*); 258 long onCmdFont(FXObject*, FXSelector, void*); 259 long onCmdPrint(FXObject*, FXSelector, void*); 260 long onUpdReadOnly(FXObject*, FXSelector, void*); 261 262 // Text display 263 long onCmdLineNumbers(FXObject*, FXSelector, void*); 264 long onUpdLineNumbers(FXObject*, FXSelector, void*); 265 long onCmdWrap(FXObject*, FXSelector, void*); 266 long onUpdWrap(FXObject*, FXSelector, void*); 267 long onCmdLinesNum(FXObject*, FXSelector, void*); 268 long onUpdLinesNum(FXObject*, FXSelector, void*); 269 270 // Text changes 271 long onTextInserted(FXObject*, FXSelector, void*); 272 long onTextReplaced(FXObject*, FXSelector, void*); 273 long onTextDeleted(FXObject*, FXSelector, void*); 274 long onTextRightMouse(FXObject*, FXSelector, void*); 275 long onTextChanged(FXObject*, FXSelector, void*); 276 long onEditDNDMotion(FXObject*, FXSelector, void*); 277 long onEditDNDDrop(FXObject*, FXSelector, void*); 278 279 // Miscellaneous 280 long onUpdOverstrike(FXObject*, FXSelector, void*); 281 long onUpdNumRows(FXObject*, FXSelector, void*); 282 long onCmdMorePrefs(FXObject*, FXSelector, void*); 283 long onCmdWindow(FXObject*, FXSelector, void*); 284 long onUpdWindow(FXObject*, FXSelector, void*); 285 long onCmdSearch(FXObject*, FXSelector, void*); 286 long onCmdReplace(FXObject*, FXSelector, void*); 287 long onCmdSearchSel(FXObject*, FXSelector, void*); 288 long onCmdGotoLine(FXObject*, FXSelector, void*); 289 290 public: 291 enum 292 { 293 ID_ABOUT=FXMainWindow::ID_LAST, 294 ID_NEW, 295 ID_OPEN, 296 ID_OPEN_TREE, 297 ID_OPEN_SELECTED, 298 ID_OPEN_RECENT, 299 ID_HARVEST, 300 ID_SAVE, 301 ID_SAVEAS, 302 ID_FONT, 303 ID_WINDOW, 304 ID_PRINT, 305 ID_TEXT_LINENUMS, 306 ID_SEARCH, 307 ID_REPLACE, 308 ID_SEARCH_FORW_SEL, 309 ID_SEARCH_BACK_SEL, 310 ID_GOTO_LINE, 311 ID_TOGGLE_WRAP, 312 ID_TOGGLE_LINES_NUM, 313 ID_TEXT, 314 ID_INCLUDE_PATH, 315 ID_OVERSTRIKE, 316 ID_PREFERENCES, 317 ID_NUM_ROWS, 318 ID_WINDOW_1, 319 ID_WINDOW_2, 320 ID_WINDOW_3, 321 ID_WINDOW_4, 322 ID_WINDOW_5, 323 ID_WINDOW_6, 324 ID_WINDOW_7, 325 ID_WINDOW_8, 326 ID_WINDOW_9, 327 ID_WINDOW_10, 328 ID_WINDOW_11, 329 ID_WINDOW_12, 330 ID_WINDOW_13, 331 ID_WINDOW_14, 332 ID_WINDOW_15, 333 ID_WINDOW_16, 334 ID_WINDOW_17, 335 ID_WINDOW_18, 336 ID_WINDOW_19, 337 ID_WINDOW_20, 338 ID_WINDOW_21, 339 ID_WINDOW_22, 340 ID_WINDOW_23, 341 ID_WINDOW_24, 342 ID_WINDOW_25, 343 ID_WINDOW_26, 344 ID_WINDOW_27, 345 ID_WINDOW_28, 346 ID_WINDOW_29, 347 ID_WINDOW_30, 348 ID_WINDOW_31, 349 ID_WINDOW_32, 350 ID_WINDOW_33, 351 ID_WINDOW_34, 352 ID_WINDOW_35, 353 ID_WINDOW_36, 354 ID_WINDOW_37, 355 ID_WINDOW_38, 356 ID_WINDOW_39, 357 ID_WINDOW_40, 358 ID_WINDOW_41, 359 ID_WINDOW_42, 360 ID_WINDOW_43, 361 ID_WINDOW_44, 362 ID_WINDOW_45, 363 ID_WINDOW_46, 364 ID_WINDOW_47, 365 ID_WINDOW_48, 366 ID_WINDOW_49, 367 ID_WINDOW_50, 368 ID_LAST 369 }; 370 public: 371 372 // Create new text window 373 WriteWindow(XFileWrite* a, const FXString& file, const FXbool readonly); 374 375 // Create window 376 virtual void create(); 377 378 // Detach window 379 virtual void detach(); 380 381 // Close the window, return true if actually closed 382 virtual FXbool close(FXbool notify = false); 383 384 // Return XFileWrite application getApp()385 XFileWrite* getApp() const 386 { 387 return((XFileWrite*)FXMainWindow::getApp()); 388 } 389 390 // Return this window's filename getFilename()391 const FXString& getFilename() const 392 { 393 return(filename); 394 } 395 396 // Change this window's filename setFilename(const FXString & file)397 void setFilename(const FXString& file) 398 { 399 filename = file; 400 } 401 402 // Has a filename been set or is it a new window isFilenameSet()403 FXbool isFilenameSet() const 404 { 405 return(filenameset); 406 } 407 408 // Obtain a pointer on the text widget getEditor()409 FXText* getEditor() const 410 { 411 return(editor); 412 } 413 414 // Get the value of the stripcr flag getStripcr()415 FXbool getStripcr() const 416 { 417 return(stripcr); 418 } 419 420 // Set the value of the stripcr flag setStripcr(FXbool val)421 void setStripcr(FXbool val) 422 { 423 stripcr = val; 424 } 425 setSmoothScroll(FXbool smooth)426 void setSmoothScroll(FXbool smooth) 427 { 428 smoothscroll = smooth; 429 } 430 431 // Is it modified 432 FXbool isModified() const; 433 434 // Load text from file 435 FXbool loadFile(const FXString& file); 436 437 // Save text to file 438 FXbool saveFile(const FXString& file); 439 440 // Return true if changes have been saved 441 FXbool saveChanges(); 442 443 // Visit given line 444 void visitLine(int line); 445 446 // Delete text window 447 virtual ~WriteWindow(); 448 }; 449 450 451 typedef FXObjectListOf<WriteWindow> WriteWindowList; 452 453 #endif 454