xref: /haiku/src/apps/terminal/TermWindow.h (revision ed24eb5ff12640d052171c6a7feba37fab8a75d1)
1 /*
2  * Copyright 2001-2010, Haiku.
3  * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
4  * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files or portions
8  * thereof (the "Software"), to deal in the Software without restriction,
9  * including without limitation the rights to use, copy, modify, merge,
10  * publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so, subject
12  * to the following conditions:
13  *
14  *  * Redistributions of source code must retain the above copyright notice,
15  *    this list of conditions and the following disclaimer.
16  *
17  *  * Redistributions in binary form must reproduce the above copyright notice
18  *    in the  binary, as well as this list of conditions and the following
19  *    disclaimer in the documentation and/or other materials provided with
20  *    the distribution.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28  * THE SOFTWARE.
29  *
30  */
31 #ifndef TERM_WINDOW_H
32 #define TERM_WINDOW_H
33 
34 
35 #include <InterfaceDefs.h>
36 #include <MessageRunner.h>
37 #include <String.h>
38 #include <Window.h>
39 
40 #include "SmartTabView.h"
41 #include "SetTitleDialog.h"
42 #include "TerminalRoster.h"
43 #include "TermView.h"
44 
45 
46 class Arguments;
47 class BFile;
48 class BFont;
49 class BMenu;
50 class BMenuBar;
51 class FindWindow;
52 class PrefWindow;
53 class TermViewContainerView;
54 class ThemeWindow;
55 
56 
57 class TermWindow : public BWindow, private SmartTabView::Listener,
58 	private TermView::Listener, private SetTitleDialog::Listener,
59 	private TerminalRoster::Listener {
60 public:
61 								TermWindow(const BString& title,
62 									Arguments* args);
63 	virtual						~TermWindow();
64 
65 			void				SessionChanged();
66 
67 	static	void				MakeEncodingMenu(BMenu*);
68 	static	void				MakeWindowSizeMenu(BMenu*);
69 
70 protected:
71 	virtual bool				QuitRequested();
72 	virtual void				MessageReceived(BMessage* message);
73 	virtual void				WindowActivated(bool activated);
74 	virtual void				MenusBeginning();
75 	virtual	void				Zoom(BPoint leftTop, float width, float height);
76 	virtual void				FrameResized(float newWidth, float newHeight);
77 	virtual void				WorkspacesChanged(uint32 oldWorkspaces,
78 									uint32 newWorkspaces);
79 	virtual void				WorkspaceActivated(int32 workspace,
80 									bool state);
81 	virtual void				Minimize(bool minimize);
82 
83 private:
84 	// SmartTabView::Listener
85 	virtual	void				TabSelected(SmartTabView* tabView, int32 index);
86 	virtual	void				TabDoubleClicked(SmartTabView* tabView,
87 									BPoint point, int32 index);
88 	virtual	void				TabMiddleClicked(SmartTabView* tabView,
89 									BPoint point, int32 index);
90 	virtual	void				TabRightClicked(SmartTabView* tabView,
91 									BPoint point, int32 index);
92 
93 	// TermView::Listener
94 	virtual	void				NotifyTermViewQuit(TermView* view,
95 									int32 reason);
96 	virtual	void				SetTermViewTitle(TermView* view,
97 									const char* title);
98 	virtual	void				PreviousTermView(TermView* view);
99 	virtual	void				NextTermView(TermView* view);
100 
101 	// SetTitleDialog::Listener
102 	virtual	void				TitleChanged(SetTitleDialog* dialog,
103 									const BString& title,
104 									bool titleUserDefined);
105 	virtual	void				SetTitleDialogDone(SetTitleDialog* dialog);
106 
107 	// TerminalRoster::Listener
108 	virtual	void				TerminalInfosUpdated(TerminalRoster* roster);
109 
110 private:
111 			struct Title {
112 				BString			title;
113 				BString			pattern;
114 				bool			patternUserDefined;
115 			};
116 
117 			struct SessionID {
118 								SessionID(int32 id = -1);
119 								SessionID(const BMessage& message,
120 									const char* field);
121 
122 				bool			IsValid() const		{ return fID >= 0; }
123 
124 				status_t		AddToMessage(BMessage& message,
125 									const char* field) const;
126 
127 				bool			operator==(const SessionID& other) const
128 									{ return fID == other.fID; }
129 				bool			operator!=(const SessionID& other) const
130 									{ return !(*this == other); }
131 
132 			private:
133 				int32			fID;
134 			};
135 
136 			struct Session;
137 
138 private:
139 			void				_SetTermColors(
140 									TermViewContainerView* containerView);
141 			void				_InitWindow();
142 			void				_SetupMenu();
143 	static	BMenu*				_MakeFontSizeMenu(uint32 command,
144 									uint8 defaultSize);
145 			void				_UpdateSwitchTerminalsMenuItem();
146 
147 			status_t			_GetWindowPositionFile(BFile* file,
148 									uint32 openMode);
149 			status_t			_LoadWindowPosition(BRect* frame,
150 									uint32* workspaces);
151 			status_t			_SaveWindowPosition();
152 
153 			void				_GetPreferredFont(BFont &font);
154 			status_t			_DoPageSetup();
155 			void				_DoPrint();
156 
157 			void				_NewTab();
158 			void				_AddTab(Arguments* args,
159 									const BString& currentDirectory
160 										= BString());
161 			void				_RemoveTab(int32 index);
162 			void				_NavigateTab(int32 index, int32 direction,
163 									bool move);
164 
165 			bool				_CanClose(int32 index);
166 
167 			TermViewContainerView* _ActiveTermViewContainerView() const;
168 			TermViewContainerView* _TermViewContainerViewAt(int32 index) const;
169 			TermView*			_ActiveTermView() const;
170 			TermView*			_TermViewAt(int32 index) const;
171 			int32				_IndexOfTermView(TermView* termView) const;
172 	inline	Session*			_SessionAt(int32 index) const;
173 			Session*			_SessionForID(const SessionID& sessionID) const;
174 	inline	int32				_IndexOfSession(Session* session) const;
175 
176 			void				_CheckChildren();
177 			void				_ResizeView(TermView* view);
178 
179 			void				_TitleSettingsChanged();
180 			void				_UpdateTitles();
181 			void				_UpdateSessionTitle(int32 index);
182 			void				_OpenSetTabTitleDialog(int32 index);
183 			void				_OpenSetWindowTitleDialog();
184 			void				_FinishTitleDialog();
185 
186 			void				_SwitchTerminal();
187 			team_id				_FindSwitchTerminalTarget();
188 
189 			SessionID			_NewSessionID();
190 			int32				_NewSessionIndex();
191 
192 			void				_MoveWindowInScreen(BWindow* window);
193 
194 			void				_UpdateKeymap();
195 
196 private:
197 			TerminalRoster		fTerminalRoster;
198 
199 			Title				fTitle;
200 			BString				fSessionTitlePattern;
201 			BMessageRunner		fTitleUpdateRunner;
202 
203 			BList				fSessions;
204 			int32				fNextSessionID;
205 
206 			SmartTabView*		fTabView;
207 
208 			BMenuBar*			fMenuBar;
209 			BMenuItem*			fSwitchTerminalsMenuItem;
210 			BMenu*				fEncodingMenu;
211 			BMenu*				fFontSizeMenu;
212 
213 			BMessage*			fPrintSettings;
214 			PrefWindow*			fPrefWindow;
215 			ThemeWindow*		fThemeWindow;
216 			FindWindow*			fFindPanel;
217 			BRect				fSavedFrame;
218 			window_look			fSavedLook;
219 
220 			SetTitleDialog*		fSetWindowTitleDialog;
221 			SetTitleDialog*		fSetTabTitleDialog;
222 			SessionID			fSetTabTitleSession;
223 
224 			// Saved search parameters
225 			BString				fFindString;
226 			BMenuItem*			fFindNextMenuItem;
227 			BMenuItem*			fFindPreviousMenuItem;
228 			BMenuItem*			fIncreaseFontSizeMenuItem;
229 			BMenuItem*			fDecreaseFontSizeMenuItem;
230 
231 			bool				fFindSelection;
232 			bool				fForwardSearch;
233 			bool				fMatchCase;
234 			bool				fMatchWord;
235 
236 			bool				fFullScreen;
237 
238 			key_map*			fKeymap;
239 			char*				fKeymapChars;
240 };
241 
242 
243 #endif // TERM_WINDOW_H
244