xref: /haiku/src/apps/stylededit/StyledEditWindow.h (revision 822e8462075a234cd2bd4fc82d353a584346692d)
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 			BMenuItem*			_MakeEncodingMenuItem();
55 			void				_LoadAttrs();
56 			void				_SaveAttrs();
57 			status_t			_LoadFile(entry_ref* ref,
58 									const char* forceEncoding = NULL);
59 			void				_ReloadDocument(BMessage *message);
60 			status_t			_UnlockFile();
61 			bool				_Search(BString searchFor, bool caseSensitive,
62 									bool wrap, bool backSearch,
63 									bool scrollToOccurence = true);
64 			void				_FindSelection();
65 			bool				_Replace(BString findThis, BString replaceWith,
66 									bool caseSensitive, bool wrap,
67 									bool backSearch);
68 			void				_ReplaceAll(BString find, BString replace,
69 									bool caseSensitive);
70 			void				_SetFontSize(float fontSize);
71 			void				_SetFontColor(const rgb_color* color);
72 			void				_SetFontStyle(const char* fontFamily,
73 									const char* fontStyle);
74 			int32				_ShowStatistics();
75 			void				_SetReadOnly(bool editable);
76 			void				_UpdateCleanUndoRedoSaveRevert();
77 			int32				_ShowAlert(const BString& text,
78 									const BString& label, const BString& label2,
79 									const BString& label3,
80 									alert_type type) const;
81 
82 				// node monitoring helper
83 			class _NodeMonitorSuspender {
84 				StyledEditWindow *fWindow;
85 			public:
86 				_NodeMonitorSuspender(StyledEditWindow *w) : fWindow(w) {
87 					fWindow->_SwitchNodeMonitor(false);
88 				}
89 
90 				~_NodeMonitorSuspender() {
91 					fWindow->_SwitchNodeMonitor(true);
92 				}
93 			};
94 
95 			friend class		_NodeMonitorSuspender;
96 
97 			void				_HandleNodeMonitorEvent(BMessage *message);
98 			void				_ShowNodeChangeAlert(const char* name,
99 									bool removed);
100 			void				_SwitchNodeMonitor(bool on,
101 									entry_ref* ref = NULL);
102 
103 private:
104 			BMenuBar*			fMenuBar;
105 			BMessage*			fPrintSettings;
106 			BMessage*			fSaveMessage;
107 			BMenu*				fRecentMenu;
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 
143 			BString				fStringToFind;
144 			BString				fReplaceString;
145 
146 			// undo modes
147 			bool				fUndoFlag;	// we just did an undo action
148 			bool				fCanUndo;	// we can do an undo action next
149 			bool 				fRedoFlag;	// we just did a redo action
150 			bool				fCanRedo;	// we can do a redo action next
151 
152 			// clean modes
153 			bool				fUndoCleans;
154 				// an undo action will put us in a clean state
155 			bool				fRedoCleans;
156 				// a redo action will put us in a clean state
157 			bool				fClean;		// we are in a clean state
158 
159 			bool				fCaseSensitive;
160 			bool				fWrapAround;
161 			bool				fBackSearch;
162 
163 			StyledEditView*		fTextView;
164 			BScrollView*		fScrollView;
165 			StatusView*			fStatusView;
166 
167 			BFilePanel*			fSavePanel;
168 			BMenu*				fSavePanelEncodingMenu;
169 				// node monitoring
170 			node_ref			fNodeRef;
171 			node_ref			fFolderNodeRef;
172 			bool				fNagOnNodeChange;
173 };
174 
175 
176 #endif	// STYLED_EDIT_WINDOW_H
177