1 /* 2 * Copyright 2001-2013, Haiku, Inc. 3 * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net> 4 * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. 5 * 6 * Distributed under the terms of the MIT license. 7 * Authors: 8 * Stefano Ceccherini, stefano.ceccherini@gmail.com 9 * Kian Duffy, myob@users.sourceforge.net 10 * Ingo Weinhold, ingo_weinhold@gmx.de 11 * Siarzhuk Zharski, zharik@gmx.li 12 */ 13 #ifndef TERMVIEW_STATES_H 14 #define TERMVIEW_STATES_H 15 16 17 #include "HyperLink.h" 18 #include "TerminalCharClassifier.h" 19 #include "TermView.h" 20 21 22 class TermView::State { 23 public: 24 State(TermView* view); 25 virtual ~State(); 26 27 virtual void Entered(); 28 virtual void Exited(); 29 30 virtual bool MessageReceived(BMessage* message); 31 // returns true, if handled 32 33 virtual void ModifiersChanged(int32 oldModifiers, 34 int32 modifiers); 35 virtual void KeyDown(const char* bytes, int32 numBytes); 36 37 virtual void MouseDown(BPoint where, int32 buttons, 38 int32 modifiers); 39 virtual void MouseMoved(BPoint where, uint32 transit, 40 const BMessage* dragMessage, int32 modifiers); 41 virtual void MouseUp(BPoint where, int32 buttons); 42 43 virtual void WindowActivated(bool active); 44 45 virtual void VisibleTextBufferChanged(); 46 47 protected: 48 TermView* fView; 49 }; 50 51 52 class TermView::StandardBaseState : public TermView::State { 53 public: 54 StandardBaseState(TermView* view); 55 56 protected: 57 bool _StandardMouseMoved(BPoint where, 58 int32 modifiers); 59 }; 60 61 62 class TermView::DefaultState : public TermView::StandardBaseState { 63 public: 64 DefaultState(TermView* view); 65 66 virtual void ModifiersChanged(int32 oldModifiers, 67 int32 modifiers); 68 69 virtual void KeyDown(const char* bytes, int32 numBytes); 70 71 virtual void MouseDown(BPoint where, int32 buttons, 72 int32 modifiers); 73 virtual void MouseMoved(BPoint where, uint32 transit, 74 const BMessage* dragMessage, int32 modifiers); 75 76 virtual void WindowActivated(bool active); 77 78 private: 79 bool _CheckEnterHyperLinkState(int32 modifiers); 80 }; 81 82 83 class TermView::SelectState : public TermView::StandardBaseState { 84 public: 85 SelectState(TermView* view); 86 87 void Prepare(BPoint where, int32 modifiers); 88 89 virtual bool MessageReceived(BMessage* message); 90 91 virtual void MouseMoved(BPoint where, uint32 transit, 92 const BMessage* dragMessage, int32 modifiers); 93 virtual void MouseUp(BPoint where, int32 buttons); 94 95 private: 96 void _AutoScrollUpdate(); 97 98 private: 99 int32 fSelectGranularity; 100 bool fCheckMouseTracking; 101 bool fMouseTracking; 102 }; 103 104 105 class TermView::HyperLinkState : public TermView::State, 106 private TermViewHighlighter { 107 public: 108 HyperLinkState(TermView* view); 109 110 virtual void Entered(); 111 virtual void Exited(); 112 113 virtual void ModifiersChanged(int32 oldModifiers, 114 int32 modifiers); 115 116 virtual void MouseDown(BPoint where, int32 buttons, 117 int32 modifiers); 118 virtual void MouseMoved(BPoint where, uint32 transit, 119 const BMessage* dragMessage, int32 modifiers); 120 121 virtual void WindowActivated(bool active); 122 123 virtual void VisibleTextBufferChanged(); 124 125 private: 126 // TermViewHighlighter 127 virtual rgb_color ForegroundColor(); 128 virtual rgb_color BackgroundColor(); 129 virtual uint32 AdjustTextAttributes(uint32 attributes); 130 131 private: 132 struct CharPosition { 133 int32 index; 134 TermPos position; 135 }; 136 137 private: 138 bool _GetHyperLinkAt(BPoint where, 139 bool pathPrefixOnly, HyperLink& _link, 140 TermPos& _start, TermPos& _end); 141 bool _EntryExists(const BString& path, 142 BString& _actualPath) const; 143 144 void _UpdateHighlight(); 145 void _UpdateHighlight(BPoint where, int32 modifiers); 146 void _ActivateHighlight(const TermPos& start, 147 const TermPos& end); 148 void _DeactivateHighlight(); 149 150 private: 151 DefaultCharClassifier fURLCharClassifier; 152 DefaultCharClassifier fPathComponentCharClassifier; 153 BString fCurrentDirectory; 154 TermViewHighlight fHighlight; 155 bool fHighlightActive; 156 }; 157 158 159 class TermView::HyperLinkMenuState : public TermView::State { 160 public: 161 HyperLinkMenuState(TermView* view); 162 163 void Prepare(BPoint point, const HyperLink& link); 164 165 virtual void Exited(); 166 167 virtual bool MessageReceived(BMessage* message); 168 169 private: 170 class PopUpMenu; 171 172 private: 173 HyperLink fLink; 174 }; 175 176 177 #endif // TERMVIEW_STATES_H 178