1 /** 2 * Copyright (c) 2005 PCMan <pcman.tw@gmail.com> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 */ 18 19 #ifndef TERMVIEW_H 20 #define TERMVIEW_H 21 22 #ifdef __GNUG__ 23 #pragma interface "termview.h" 24 #endif 25 26 #include "pcmanx_utils.h" 27 28 #include "view.h" 29 #include "caret.h" 30 31 #include <string> 32 33 #include <X11/Xft/Xft.h> 34 35 using namespace std; 36 37 /** 38 @author PCMan 39 */ 40 class CTermData; 41 class CHyperLink; 42 class CFont; 43 44 class X_EXPORT CTermView : public CView 45 { 46 friend class CTermData; 47 public: 48 enum {FONT_START = 0, FONT_DEFAULT = 0, FONT_EN, FONT_END}; 49 50 CTermView(); 51 52 virtual bool PreKeyDown(GdkEventKey *evt); 53 virtual bool OnKeyDown(GdkEventKey* evt); 54 virtual void OnTextInput(const gchar* string); 55 int DrawChar(int row, int col); 56 void PointToLineCol(int *x, int *y, bool *left = NULL); 57 58 GtkIMContext* m_IMContext; 59 60 virtual void OnLButtonDown(GdkEventButton* evt); 61 virtual void OnRButtonDown(GdkEventButton* evt); 62 virtual void OnLButtonUp(GdkEventButton* evt); 63 virtual void OnRButtonUp(GdkEventButton* evt); 64 virtual void OnMouseMove(GdkEventMotion* evt); 65 virtual void OnMouseScroll(GdkEventScroll* evt); 66 virtual void OnHyperlinkClicked(string url); 67 void OnBlinkTimer(); 68 virtual void OnMButtonDown(GdkEventButton* evt); 69 void PasteFromClipboard(bool primary); 70 virtual void DoPasteFromClipboard(string text, bool contain_ansi_color); 71 virtual void CopyToClipboard(bool primary, bool with_color, bool trim); 72 void SetFont( string name, int pt_size, bool compact, bool anti_alias, int font_type); 73 void SetFontFamily(string name, int font_type); 74 void SetFont(CFont* font, int font_type); SetHyperLinkColor(GdkColor * clr)75 void SetHyperLinkColor( GdkColor* clr ){ m_pHyperLinkColor = clr; } GetFont(int font_type)76 CFont* GetFont(int font_type){ return m_Font[font_type]; } 77 void SetHorizontalCenterAlign( bool is_hcenter ); 78 void SetVerticalCenterAlign( bool is_vcenter ); 79 void SetUAO( gint idx ); SetTermData(CTermData * data)80 void SetTermData(CTermData* data){ m_pTermData = data; } 81 82 protected: 83 void OnPaint(GdkEventExpose* evt); 84 void OnSetFocus(GdkEventFocus* evt); 85 void OnCreate(); 86 void OnSize(GdkEventConfigure* evt); 87 void OnKillFocus(GdkEventFocus *evt); 88 static void OnBeforeDestroy( GtkWidget* widget, CTermView* _this); 89 void UpdateCaretPos(); 90 bool HyperLinkHitTest(int x, int y, int* start, int* end); 91 void OnDestroy(); 92 void RecalcCharDimension(); 93 void GetCellSize( int &w, int &h ); 94 void ClearSelection(); 95 void ExtendSelection( int row, int col, bool left ); 96 bool DrawSpaceFillingChar(const char* ch, int len, int x, int y, GdkRectangle* clip, GdkColor* clr); IsSpaceFillingChar(const char * ch,int len)97 bool IsSpaceFillingChar( const char* ch, int len ) { return bool( len >= 3 && *(guchar*)ch == 0xe2 ); } 98 protected: 99 CTermData* m_pTermData; 100 101 XftDraw* m_XftDraw; 102 CFont* m_Font[FONT_END]; 103 104 int m_CharW; 105 int m_CharH; 106 int m_LeftMargin; 107 int m_TopMargin; 108 bool m_bHorizontalCenterAlign; 109 bool m_bVerticalCenterAlign; 110 gint m_UAO; 111 112 CCaret m_Caret; 113 CHyperLink* m_pHyperLink; 114 115 bool m_ShowBlink; 116 int m_CharPaddingX; 117 int m_CharPaddingY; 118 GdkColor* m_pColorTable; 119 GdkColor* m_pHyperLinkColor; 120 GdkGC* m_GC; 121 bool m_AutoFontSize; 122 123 bool m_CancelSel; // If selection is canceled in OnLButtonDown, this flag is set to true. 124 125 static string m_s_ANSIColorStr; 126 static string m_s_CharSet; 127 128 int m_FontSize; 129 string m_FontFamily; 130 131 static GdkCursor* m_HandCursor; 132 static GdkCursor* m_ExitCursor; 133 static GdkCursor* m_BullsEyeCursor; 134 static GdkCursor* m_PageDownCursor; 135 static GdkCursor* m_PageUpCursor; 136 static GdkCursor* m_EndCursor; 137 static GdkCursor* m_HomeCursor; 138 139 // Mouse Cursor State for Click Behaviour 140 // Hand=-1, Normal=0, Exit=1, BullsEye=2, PageDown=3, PageUp=4, End=5, Home=6 141 static int m_CursorState; 142 }; 143 144 #endif 145