xref: /haiku/src/apps/stylededit/StyledEditWindow.h (revision 83b1a68c52ba3e0e8796282759f694b7fdddf06d)
1 /*
2  * Copyright 2002-2012, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Mattias Sundblad
7  *		Andrew Bachmann
8  *		Jonas Sundström
9  */
10 #ifndef STYLED_EDIT_WINDOW_H
11 #define STYLED_EDIT_WINDOW_H
12 
13 
14 #include <Alert.h>
15 #include <Node.h>
16 #include <Window.h>
17 
18 struct entry_ref;
19 
20 class BFilePanel;
21 class BMenu;
22 class BMenuBar;
23 class BMenuItem;
24 class BMessage;
25 class BScrollView;
26 class StatusView;
27 class StyledEditView;
28 
29 
30 class StyledEditWindow : public BWindow {
31 public:
32 								StyledEditWindow(BRect frame, int32 id,
33 									uint32 encoding = 0);
34 								StyledEditWindow(BRect frame, entry_ref* ref,
35 									uint32 encoding = 0);
36 	virtual						~StyledEditWindow();
37 
38 	virtual void				Quit();
39 	virtual bool				QuitRequested();
40 	virtual void				MessageReceived(BMessage* message);
41 	virtual void				MenusBeginning();
42 
43 			status_t			Save(BMessage* message = NULL);
44 			status_t			SaveAs(BMessage* message = NULL);
45 			void				OpenFile(entry_ref* ref);
46 			status_t			PageSetup(const char* documentName);
47 			void				Print(const char* documentName);
48 			void				SearchAllWindows(BString find, BString replace,
49 									bool caseSensitive);
50 			bool				IsDocumentEntryRef(const entry_ref* ref);
51 
52 private:
53 			void				_InitWindow(uint32 encoding = 0);
54 			void				_LoadAttrs();
55 			void				_SaveAttrs();
56 			status_t			_LoadFile(entry_ref* ref,
57 									const char* forceEncoding = NULL);
58 			void				_ReloadDocument(BMessage *message);
59 			status_t			_UnlockFile();
60 			bool				_Search(BString searchFor, bool caseSensitive,
61 									bool wrap, bool backSearch,
62 									bool scrollToOccurence = true);
63 			void				_FindSelection();
64 			bool				_Replace(BString findThis, BString replaceWith,
65 									bool caseSensitive, bool wrap,
66 									bool backSearch);
67 			void				_ReplaceAll(BString find, BString replace,
68 									bool caseSensitive);
69 			void				_SetFontSize(float fontSize);
70 			void				_SetFontColor(const rgb_color* color);
71 			void				_SetFontStyle(const char* fontFamily,
72 									const char* fontStyle);
73 			int32				_ShowStatistics();
74 			void				_SetReadOnly(bool editable);
75 			void				_UpdateCleanUndoRedoSaveRevert();
76 			int32				_ShowAlert(const BString& text,
77 									const BString& label, const BString& label2,
78 									const BString& label3,
79 									alert_type type) const;
80 			BMenu*				_PopulateEncodingMenu(BMenu* menu,
81 									const char* encoding);
82 
83 				// node monitoring helper
84 			class _NodeMonitorSuspender {
85 				StyledEditWindow *fWindow;
86 			public:
87 				_NodeMonitorSuspender(StyledEditWindow *w) : fWindow(w) {
88 					fWindow->_SwitchNodeMonitor(false);
89 				}
90 
91 				~_NodeMonitorSuspender() {
92 					fWindow->_SwitchNodeMonitor(true);
93 				}
94 			};
95 
96 			friend class		_NodeMonitorSuspender;
97 
98 			void				_HandleNodeMonitorEvent(BMessage *message);
99 			void				_ShowNodeChangeAlert(const char* name,
100 									bool removed);
101 			void				_SwitchNodeMonitor(bool on,
102 									entry_ref* ref = NULL);
103 
104 private:
105 			BMenuBar*			fMenuBar;
106 			BMessage*			fPrintSettings;
107 			BMessage*			fSaveMessage;
108 
109 			BMenu*				fFontMenu;
110 			BMenu*				fFontSizeMenu;
111 			BMenu*				fFontColorMenu;
112 			BMenuItem*			fCurrentFontItem;
113 			BMenuItem*			fCurrentStyleItem;
114 
115 			BMenuItem*			fSaveItem;
116 			BMenuItem*			fReloadItem;
117 
118 			BMenuItem*			fUndoItem;
119 			BMenuItem*			fCutItem;
120 			BMenuItem*			fCopyItem;
121 
122 			BMenuItem*			fFindAgainItem;
123 			BMenuItem*			fReplaceItem;
124 			BMenuItem*			fReplaceSameItem;
125 
126 			BMenuItem*			fBlackItem;
127 			BMenuItem*			fRedItem;
128 			BMenuItem*			fGreenItem;
129 			BMenuItem*			fBlueItem;
130 			BMenuItem*			fCyanItem;
131 			BMenuItem*			fMagentaItem;
132 			BMenuItem*			fYellowItem;
133 
134 			BMenuItem*			fBoldItem;
135 			BMenuItem*			fItalicItem;
136 
137 			BMenuItem*			fWrapItem;
138 			BMenuItem*			fAlignLeft;
139 			BMenuItem*			fAlignCenter;
140 			BMenuItem*			fAlignRight;
141 			BMenuItem*			fEncodingItem;
142 			BMenuItem*			fRecentMenuItem;
143 
144 			BString				fStringToFind;
145 			BString				fReplaceString;
146 
147 			// undo modes
148 			bool				fUndoFlag;	// we just did an undo action
149 			bool				fCanUndo;	// we can do an undo action next
150 			bool 				fRedoFlag;	// we just did a redo action
151 			bool				fCanRedo;	// we can do a redo action next
152 
153 			// clean modes
154 			bool				fUndoCleans;
155 				// an undo action will put us in a clean state
156 			bool				fRedoCleans;
157 				// a redo action will put us in a clean state
158 			bool				fClean;		// we are in a clean state
159 
160 			bool				fCaseSensitive;
161 			bool				fWrapAround;
162 			bool				fBackSearch;
163 
164 			StyledEditView*		fTextView;
165 			BScrollView*		fScrollView;
166 			StatusView*			fStatusView;
167 
168 			BFilePanel*			fSavePanel;
169 			BMenu*				fSavePanelEncodingMenu;
170 				// node monitoring
171 			node_ref			fNodeRef;
172 			node_ref			fFolderNodeRef;
173 			bool				fNagOnNodeChange;
174 
175 			BWindow*			fFindWindow;
176 			BWindow*			fReplaceWindow;
177 };
178 
179 
180 #endif	// STYLED_EDIT_WINDOW_H
181