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 static BMenu* _MakeFontSizeMenu(uint32 command, 140 uint8 defaultSize); 141 void _UpdateSwitchTerminalsMenuItem(); 142 143 status_t _GetWindowPositionFile(BFile* file, 144 uint32 openMode); 145 status_t _LoadWindowPosition(BRect* frame, 146 uint32* workspaces); 147 status_t _SaveWindowPosition(); 148 149 void _GetPreferredFont(BFont &font); 150 status_t _DoPageSetup(); 151 void _DoPrint(); 152 153 void _NewTab(); 154 void _AddTab(Arguments* args, 155 const BString& currentDirectory 156 = BString()); 157 void _RemoveTab(int32 index); 158 void _NavigateTab(int32 index, int32 direction, 159 bool move); 160 161 bool _CanClose(int32 index); 162 163 TermViewContainerView* _ActiveTermViewContainerView() const; 164 TermViewContainerView* _TermViewContainerViewAt(int32 index) const; 165 TermView* _ActiveTermView() const; 166 TermView* _TermViewAt(int32 index) const; 167 int32 _IndexOfTermView(TermView* termView) const; 168 inline Session* _SessionAt(int32 index) const; 169 Session* _SessionForID(const SessionID& sessionID) const; 170 inline int32 _IndexOfSession(Session* session) const; 171 172 void _CheckChildren(); 173 void _ResizeView(TermView* view); 174 175 void _TitleSettingsChanged(); 176 void _UpdateTitles(); 177 void _UpdateSessionTitle(int32 index); 178 void _OpenSetTabTitleDialog(int32 index); 179 void _OpenSetWindowTitleDialog(); 180 void _FinishTitleDialog(); 181 182 void _SwitchTerminal(); 183 team_id _FindSwitchTerminalTarget(); 184 185 SessionID _NewSessionID(); 186 int32 _NewSessionIndex(); 187 188 void _MoveWindowInScreen(BWindow* window); 189 190 private: 191 TerminalRoster fTerminalRoster; 192 193 Title fTitle; 194 BString fSessionTitlePattern; 195 BMessageRunner fTitleUpdateRunner; 196 197 BList fSessions; 198 int32 fNextSessionID; 199 200 SmartTabView* fTabView; 201 202 BMenuBar* fMenuBar; 203 BMenuItem* fSwitchTerminalsMenuItem; 204 BMenu* fEncodingMenu; 205 BMenu* fFontSizeMenu; 206 207 BMessage* fPrintSettings; 208 PrefWindow* fPrefWindow; 209 FindWindow* fFindPanel; 210 BRect fSavedFrame; 211 window_look fSavedLook; 212 213 SetTitleDialog* fSetWindowTitleDialog; 214 SetTitleDialog* fSetTabTitleDialog; 215 SessionID fSetTabTitleSession; 216 217 // Saved search parameters 218 BString fFindString; 219 BMenuItem* fFindNextMenuItem; 220 BMenuItem* fFindPreviousMenuItem; 221 BMenuItem* fIncreaseFontSizeMenuItem; 222 BMenuItem* fDecreaseFontSizeMenuItem; 223 224 bool fFindSelection; 225 bool fForwardSearch; 226 bool fMatchCase; 227 bool fMatchWord; 228 229 bool fFullScreen; 230 }; 231 232 233 #endif // TERM_WINDOW_H 234