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