| 1 | /* Copyright (c) 2006 by Arkkra Enterprises */ |
| 2 | /* All rights reserved */ |
| 3 | |
| 4 | #ifndef _EDIT_H_ |
| 5 | #define _EDIT_H_ |
| 6 | |
| 7 | // Classes for Edit menu item off of main toolbar |
| 8 | |
| 9 | #include <FL/Fl_Widget.H> |
| 10 | #include <FL/Fl_Text_Editor.H> |
| 11 | #include <FL/Fl_Text_Buffer.H> |
| 12 | #include <FL/Fl_Double_Window.H> |
| 13 | #include <FL/Fl_Input.H> |
| 14 | #include <FL/Fl_Int_Input.H> |
| 15 | #include <FL/Fl_Box.H> |
| 16 | #include <FL/Fl_Button.H> |
| 17 | #include <FL/Fl_Round_Button.H> |
| 18 | #include <FL/Fl_Check_Button.H> |
| 19 | #include <FL/Fl_Return_Button.H> |
| 20 | |
| 21 | |
| 22 | |
| 23 | // Class for window that pops up for "Find" or "Replace" |
| 24 | |
| 25 | class Find_dialog : public Fl_Double_Window { |
| 26 | |
| 27 | friend class Edit; // so it can call FindNext() |
| 28 | |
| 29 | public: |
| 30 | Find_dialog(void); |
| 31 | ~Find_dialog(); |
| 32 | |
| 33 | // Callbacks |
| 34 | static void FindNext_cb(Fl_Widget *, void * data); |
| 35 | static void Replace_cb(Fl_Widget *, void * data); |
| 36 | static void ReplaceAll_cb(Fl_Widget *, void * data); |
| 37 | static void Cancel_cb(Fl_Widget *, void * data); |
| 38 | static void Pattern_cb(Fl_Widget *, void * data); |
| 39 | static void change_cb(Fl_Widget *, void * data); |
| 40 | static void cursor_change_check(void * data); |
| 41 | |
| 42 | // Returns current search pattern |
| 43 | const char * get_pattern(void); |
| 44 | |
| 45 | // Tells class which edit buffer to search in |
| 46 | void set_editor(Fl_Text_Editor *); |
| 47 | |
| 48 | // Class instance can be either a Find or a Replace. |
| 49 | // These change the personality. |
| 50 | void as_Find(void); |
| 51 | void as_Replace(void); |
| 52 | |
| 53 | // when not allowed to search/replace |
| 54 | void gray_out(void); |
| 55 | |
| 56 | private: |
| 57 | // Callbacks |
| 58 | void FindNext(void); |
| 59 | void Replace(void); |
| 60 | void ReplaceAll(void); |
| 61 | void Cancel(void); |
| 62 | void Pattern(void); |
| 63 | void change(void); |
| 64 | |
| 65 | // Widgets |
| 66 | Fl_Input * pattern_p; |
| 67 | Fl_Input * replace_with_p; |
| 68 | Fl_Button * replace_p; |
| 69 | Fl_Button * replace_all_p; |
| 70 | Fl_Check_Button * casematch_p; |
| 71 | Fl_Box * direction_p; |
| 72 | Fl_Round_Button * up_p; |
| 73 | Fl_Round_Button * down_p; |
| 74 | Fl_Return_Button * next_p; |
| 75 | Fl_Button * cancel_p; |
| 76 | |
| 77 | // The text editor widget we are editing |
| 78 | Fl_Text_Editor * editor_p; |
| 79 | |
| 80 | // true if current personality is "Replace," false if "Find." |
| 81 | bool is_replace; |
| 82 | |
| 83 | // Where cursor was at last check |
| 84 | int last_cursor_position; |
| 85 | }; |
| 86 | |
| 87 | |
| 88 | // Class for window that pops up for Go To |
| 89 | |
| 90 | class GoTo_dialog : Fl_Double_Window { |
| 91 | |
| 92 | friend class Edit; |
| 93 | |
| 94 | public: |
| 95 | GoTo_dialog(void); |
| 96 | ~GoTo_dialog(); |
| 97 | |
| 98 | // Callbacks |
| 99 | static void OK_cb(Fl_Widget *, void * data); |
| 100 | static void Cancel_cb(Fl_Widget *, void * data); |
| 101 | |
| 102 | // Tells us which editor instance to use |
| 103 | void set_editor(Fl_Text_Editor * ed); |
| 104 | |
| 105 | // Initialize contents on GoTo field to the current line number |
| 106 | void set_current_line(); |
| 107 | |
| 108 | private: |
| 109 | // Callbacks |
| 110 | void OK(void); |
| 111 | void Cancel(void); |
| 112 | |
| 113 | // Widgets |
| 114 | Fl_Int_Input * linenum_p; |
| 115 | Fl_Return_Button * ok_p; |
| 116 | Fl_Button * cancel_p; |
| 117 | Fl_Text_Editor * editor_p; |
| 118 | }; |
| 119 | |
| 120 | |
| 121 | // Class for Edit Menu from main toolbar |
| 122 | |
| 123 | class Edit { |
| 124 | public: |
| 125 | Edit(); |
| 126 | ~Edit(); |
| 127 | |
| 128 | // Callbacks |
| 129 | static void Undo_cb(Fl_Widget *, void * data); |
| 130 | static void Cut_cb(Fl_Widget *, void * data); |
| 131 | static void Copy_cb(Fl_Widget *, void * data); |
| 132 | static void Paste_cb(Fl_Widget *, void * data); |
| 133 | static void Delete_cb(Fl_Widget *, void * data); |
| 134 | static void Find_cb(Fl_Widget *, void * data); |
| 135 | static void FindNext_cb(Fl_Widget *, void * data); |
| 136 | static void Replace_cb(Fl_Widget *, void * data); |
| 137 | static void GoTo_cb(Fl_Widget *, void * data); |
| 138 | static void SelectAll_cb(Fl_Widget *, void * data); |
| 139 | static void modify_cb(int, int, int, int, const char *, void * data); |
| 140 | |
| 141 | // Tells us which editor instance to use |
| 142 | void set_editor(Fl_Text_Editor * ed); |
| 143 | |
| 144 | // true if there is something in the clipboard that can be pasted |
| 145 | bool can_paste() { return wrote_to_clipboard; } |
| 146 | void set_can_paste(); |
| 147 | |
| 148 | private: |
| 149 | // Callbacks |
| 150 | void Undo(void); |
| 151 | void Cut(void); |
| 152 | void Copy(void); |
| 153 | void Paste(void); |
| 154 | void Delete(void); |
| 155 | void Find(void); |
| 156 | void FindNext(void); |
| 157 | void Replace(void); |
| 158 | void GoTo(void); |
| 159 | void SelectAll(void); |
| 160 | |
| 161 | // Widgets |
| 162 | Fl_Text_Editor * editor_p; |
| 163 | Fl_Text_Buffer * buffer_p; |
| 164 | Find_dialog * find_p; |
| 165 | GoTo_dialog * goto_p; |
| 166 | |
| 167 | // if wrote something to the cut/copy buffer |
| 168 | bool wrote_to_clipboard; |
| 169 | }; |
| 170 | |
| 171 | #endif |