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
18struct entry_ref;
19
20class BFilePanel;
21class BMenu;
22class BMenuBar;
23class BMenuItem;
24class BMessage;
25class BScrollView;
26class StatusView;
27class StyledEditView;
28
29
30class StyledEditWindow : public BWindow {
31public:
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	static	BMenu*				PopulateEncodingMenu(BMenu* menu,
53									const char* encoding);
54private:
55			void				_InitWindow(uint32 encoding = 0);
56			void				_LoadAttrs();
57			void				_SaveAttrs();
58			status_t			_LoadFile(entry_ref* ref,
59									const char* forceEncoding = NULL);
60			void				_ReloadDocument(BMessage *message);
61			status_t			_UnlockFile();
62			bool				_Search(BString searchFor, bool caseSensitive,
63									bool wrap, bool backSearch,
64									bool scrollToOccurence = true);
65			void				_FindSelection();
66			bool				_Replace(BString findThis, BString replaceWith,
67									bool caseSensitive, bool wrap,
68									bool backSearch);
69			void				_ReplaceAll(BString find, BString replace,
70									bool caseSensitive);
71			void				_SetFontSize(float fontSize);
72			void				_SetFontColor(const rgb_color* color);
73			void				_SetFontStyle(const char* fontFamily,
74									const char* fontStyle);
75			int32				_ShowStatistics();
76			void				_SetReadOnly(bool editable);
77			void				_UpdateCleanUndoRedoSaveRevert();
78			int32				_ShowAlert(const BString& text,
79									const BString& label, const BString& label2,
80									const BString& label3,
81									alert_type type) const;
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
104private:
105			BMenuBar*			fMenuBar;
106			BMessage*			fPrintSettings;
107			BMessage*			fSaveMessage;
108			BMenu*				fRecentMenu;
109
110			BMenu*				fFontMenu;
111			BMenu*				fFontSizeMenu;
112			BMenu*				fFontColorMenu;
113			BMenuItem*			fCurrentFontItem;
114			BMenuItem*			fCurrentStyleItem;
115
116			BMenuItem*			fSaveItem;
117			BMenuItem*			fReloadItem;
118
119			BMenuItem*			fUndoItem;
120			BMenuItem*			fCutItem;
121			BMenuItem*			fCopyItem;
122
123			BMenuItem*			fFindAgainItem;
124			BMenuItem*			fReplaceItem;
125			BMenuItem*			fReplaceSameItem;
126
127			BMenuItem*			fBlackItem;
128			BMenuItem*			fRedItem;
129			BMenuItem*			fGreenItem;
130			BMenuItem*			fBlueItem;
131			BMenuItem*			fCyanItem;
132			BMenuItem*			fMagentaItem;
133			BMenuItem*			fYellowItem;
134
135			BMenuItem*			fBoldItem;
136			BMenuItem*			fItalicItem;
137
138			BMenuItem*			fWrapItem;
139			BMenuItem*			fAlignLeft;
140			BMenuItem*			fAlignCenter;
141			BMenuItem*			fAlignRight;
142			BMenuItem*			fEncodingItem;
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
176
177#endif	// STYLED_EDIT_WINDOW_H
178