xref: /haiku/src/apps/stylededit/StyledEditWindow.h (revision 7a74a5df454197933bc6e80a542102362ee98703)
1 /*
2  * Copyright 2002-2010, 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 <Window.h>
16 #include <String.h>
17 #include <Message.h>
18 
19 
20 struct entry_ref;
21 
22 class BMenu;
23 class BMessage;
24 class BMenuBar;
25 class BMenuItem;
26 class BFilePanel;
27 class BScrollView;
28 class StyledEditView;
29 
30 
31 class StyledEditWindow : public BWindow {
32 public:
33 								StyledEditWindow(BRect frame, int32 id,
34 									uint32 encoding = 0);
35 								StyledEditWindow(BRect frame, entry_ref* ref,
36 									uint32 encoding = 0);
37 	virtual						~StyledEditWindow();
38 
39 	virtual void				Quit();
40 	virtual bool				QuitRequested();
41 	virtual void				MessageReceived(BMessage* message);
42 	virtual void				MenusBeginning();
43 
44 			status_t			Save(BMessage* message = NULL);
45 			status_t			SaveAs(BMessage* message = NULL);
46 			void				OpenFile(entry_ref* ref);
47 			status_t			PageSetup(const char* documentName);
48 			void				Print(const char* documentName);
49 			void				SearchAllWindows(BString find, BString replace,
50 									bool caseSensitive);
51 			bool				IsDocumentEntryRef(const entry_ref* ref);
52 
53 private:
54 			void				_InitWindow(uint32 encoding = 0);
55 			void				_LoadAttrs();
56 			void				_SaveAttrs();
57 			status_t			_LoadFile(entry_ref* ref);
58 			void				_RevertToSaved();
59 			bool				_Search(BString searchFor, bool caseSensitive,
60 									bool wrap, bool backSearch,
61 									bool scrollToOccurence = true);
62 			void				_FindSelection();
63 			bool				_Replace(BString findThis, BString replaceWith,
64 									bool caseSensitive, bool wrap,
65 									bool backSearch);
66 			void				_ReplaceAll(BString find, BString replace,
67 									bool caseSensitive);
68 			void				_SetFontSize(float fontSize);
69 			void				_SetFontColor(const rgb_color* color);
70 			void				_SetFontStyle(const char* fontFamily,
71 									const char* fontStyle);
72 			int32				_ShowStatistics();
73 			void				_UpdateCleanUndoRedoSaveRevert();
74 			int32				_ShowAlert(const BString& text,
75 									const BString& label, const BString& label2,
76 									const BString& label3,
77 									alert_type type) const;
78 
79 private:
80 			BMenuBar*			fMenuBar;
81 			BMessage*			fPrintSettings;
82 			BMessage*			fSaveMessage;
83 			BMenu*				fRecentMenu;
84 
85 			BMenu*				fFontMenu;
86 			BMenu*				fFontSizeMenu;
87 			BMenu*				fFontColorMenu;
88 			BMenuItem*			fCurrentFontItem;
89 			BMenuItem*			fCurrentStyleItem;
90 
91 			BMenuItem*			fSaveItem;
92 			BMenuItem*			fRevertItem;
93 
94 			BMenuItem*			fUndoItem;
95 			BMenuItem*			fCutItem;
96 			BMenuItem*			fCopyItem;
97 
98 			BMenuItem*			fFindAgainItem;
99 			BMenuItem*			fReplaceSameItem;
100 
101 			BMenuItem*			fBlackItem;
102 			BMenuItem*			fRedItem;
103 			BMenuItem*			fGreenItem;
104 			BMenuItem*			fBlueItem;
105 			BMenuItem*			fCyanItem;
106 			BMenuItem*			fMagentaItem;
107 			BMenuItem*			fYellowItem;
108 
109 			BMenuItem*			fBoldItem;
110 			BMenuItem*			fItalicItem;
111 
112 			BMenuItem*			fWrapItem;
113 			BMenuItem*			fAlignLeft;
114 			BMenuItem*			fAlignCenter;
115 			BMenuItem*			fAlignRight;
116 
117 			BString				fStringToFind;
118 			BString				fReplaceString;
119 
120 			// undo modes
121 			bool				fUndoFlag;	// we just did an undo action
122 			bool				fCanUndo;	// we can do an undo action next
123 			bool 				fRedoFlag;	// we just did a redo action
124 			bool				fCanRedo;	// we can do a redo action next
125 
126 			// clean modes
127 			bool				fUndoCleans;
128 				// an undo action will put us in a clean state
129 			bool				fRedoCleans;
130 				// a redo action will put us in a clean state
131 			bool				fClean;		// we are in a clean state
132 
133 			bool				fCaseSensitive;
134 			bool				fWrapAround;
135 			bool				fBackSearch;
136 
137 			StyledEditView*		fTextView;
138 			BScrollView*		fScrollView;
139 
140 			BFilePanel*			fSavePanel;
141 			BMenu*				fSavePanelEncodingMenu;
142 };
143 
144 
145 #endif	// STYLED_EDIT_WINDOW_H
146