xref: /haiku/src/apps/terminal/TermWindow.h (revision 1a3518cf757c2da8006753f83962da5935bbc82b)
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 
55 
56 class TermWindow : public BWindow, private SmartTabView::Listener,
57 	private TermView::Listener, private SetTitleDialog::Listener,
58 	private TerminalRoster::Listener {
59 public:
60 								TermWindow(const BString& title,
61 									Arguments* args);
62 	virtual						~TermWindow();
63 
64 			void				SessionChanged();
65 
66 	static	void				MakeEncodingMenu(BMenu*);
67 	static	void				MakeWindowSizeMenu(BMenu*);
68 
69 protected:
70 	virtual bool				QuitRequested();
71 	virtual void				MessageReceived(BMessage* message);
72 	virtual void				WindowActivated(bool activated);
73 	virtual void				MenusBeginning();
74 	virtual	void				Zoom(BPoint leftTop, float width, float height);
75 	virtual void				FrameResized(float newWidth, float newHeight);
76 	virtual void				WorkspacesChanged(uint32 oldWorkspaces,
77 									uint32 newWorkspaces);
78 	virtual void				WorkspaceActivated(int32 workspace,
79 									bool state);
80 	virtual void				Minimize(bool minimize);
81 
82 private:
83 	// SmartTabView::Listener
84 	virtual	void				TabSelected(SmartTabView* tabView, int32 index);
85 	virtual	void				TabDoubleClicked(SmartTabView* tabView,
86 									BPoint point, int32 index);
87 	virtual	void				TabMiddleClicked(SmartTabView* tabView,
88 									BPoint point, int32 index);
89 	virtual	void				TabRightClicked(SmartTabView* tabView,
90 									BPoint point, int32 index);
91 
92 	// TermView::Listener
93 	virtual	void				NotifyTermViewQuit(TermView* view,
94 									int32 reason);
95 	virtual	void				SetTermViewTitle(TermView* view,
96 									const char* title);
97 	virtual	void				PreviousTermView(TermView* view);
98 	virtual	void				NextTermView(TermView* view);
99 
100 	// SetTitleDialog::Listener
101 	virtual	void				TitleChanged(SetTitleDialog* dialog,
102 									const BString& title,
103 									bool titleUserDefined);
104 	virtual	void				SetTitleDialogDone(SetTitleDialog* dialog);
105 
106 	// TerminalRoster::Listener
107 	virtual	void				TerminalInfosUpdated(TerminalRoster* roster);
108 
109 private:
110 			struct Title {
111 				BString			title;
112 				BString			pattern;
113 				bool			patternUserDefined;
114 			};
115 
116 			struct SessionID {
117 								SessionID(int32 id = -1);
118 								SessionID(const BMessage& message,
119 									const char* field);
120 
121 				bool			IsValid() const		{ return fID >= 0; }
122 
123 				status_t		AddToMessage(BMessage& message,
124 									const char* field) const;
125 
126 				bool			operator==(const SessionID& other) const
127 									{ return fID == other.fID; }
128 				bool			operator!=(const SessionID& other) const
129 									{ return !(*this == other); }
130 
131 			private:
132 				int32			fID;
133 			};
134 
135 			struct Session;
136 
137 private:
138 			void				_SetTermColors(
139 									TermViewContainerView* containerView);
140 			void				_InitWindow();
141 			void				_SetupMenu();
142 	static	BMenu*				_MakeFontSizeMenu(uint32 command,
143 									uint8 defaultSize);
144 			void				_UpdateSwitchTerminalsMenuItem();
145 
146 			status_t			_GetWindowPositionFile(BFile* file,
147 									uint32 openMode);
148 			status_t			_LoadWindowPosition(BRect* frame,
149 									uint32* workspaces);
150 			status_t			_SaveWindowPosition();
151 
152 			void				_GetPreferredFont(BFont &font);
153 			status_t			_DoPageSetup();
154 			void				_DoPrint();
155 
156 			void				_NewTab();
157 			void				_AddTab(Arguments* args,
158 									const BString& currentDirectory
159 										= BString());
160 			void				_RemoveTab(int32 index);
161 			void				_NavigateTab(int32 index, int32 direction,
162 									bool move);
163 
164 			bool				_CanClose(int32 index);
165 
166 			TermViewContainerView* _ActiveTermViewContainerView() const;
167 			TermViewContainerView* _TermViewContainerViewAt(int32 index) const;
168 			TermView*			_ActiveTermView() const;
169 			TermView*			_TermViewAt(int32 index) const;
170 			int32				_IndexOfTermView(TermView* termView) const;
171 	inline	Session*			_SessionAt(int32 index) const;
172 			Session*			_SessionForID(const SessionID& sessionID) const;
173 	inline	int32				_IndexOfSession(Session* session) const;
174 
175 			void				_CheckChildren();
176 			void				_ResizeView(TermView* view);
177 
178 			void				_TitleSettingsChanged();
179 			void				_UpdateTitles();
180 			void				_UpdateSessionTitle(int32 index);
181 			void				_OpenSetTabTitleDialog(int32 index);
182 			void				_OpenSetWindowTitleDialog();
183 			void				_FinishTitleDialog();
184 
185 			void				_SwitchTerminal();
186 			team_id				_FindSwitchTerminalTarget();
187 
188 			SessionID			_NewSessionID();
189 			int32				_NewSessionIndex();
190 
191 			void				_MoveWindowInScreen(BWindow* window);
192 
193 			void				_UpdateKeymap();
194 
195 private:
196 			TerminalRoster		fTerminalRoster;
197 
198 			Title				fTitle;
199 			BString				fSessionTitlePattern;
200 			BMessageRunner		fTitleUpdateRunner;
201 
202 			BList				fSessions;
203 			int32				fNextSessionID;
204 
205 			SmartTabView*		fTabView;
206 
207 			BMenuBar*			fMenuBar;
208 			BMenuItem*			fSwitchTerminalsMenuItem;
209 			BMenu*				fEncodingMenu;
210 			BMenu*				fFontSizeMenu;
211 
212 			BMessage*			fPrintSettings;
213 			PrefWindow*			fPrefWindow;
214 			FindWindow*			fFindPanel;
215 			BRect				fSavedFrame;
216 			window_look			fSavedLook;
217 
218 			SetTitleDialog*		fSetWindowTitleDialog;
219 			SetTitleDialog*		fSetTabTitleDialog;
220 			SessionID			fSetTabTitleSession;
221 
222 			// Saved search parameters
223 			BString				fFindString;
224 			BMenuItem*			fFindNextMenuItem;
225 			BMenuItem*			fFindPreviousMenuItem;
226 			BMenuItem*			fIncreaseFontSizeMenuItem;
227 			BMenuItem*			fDecreaseFontSizeMenuItem;
228 
229 			bool				fFindSelection;
230 			bool				fForwardSearch;
231 			bool				fMatchCase;
232 			bool				fMatchWord;
233 
234 			bool				fFullScreen;
235 
236 			key_map*			fKeymap;
237 			char*				fKeymapChars;
238 };
239 
240 
241 #endif // TERM_WINDOW_H
242