00001 /* Handle caret blinking. 00002 * 00003 * Author: Mike Nordell (tamlin@algonet.se) 00004 * Pat Lam 00005 * Dom Lachowicz 00006 * Tomas Frydrych 00007 * Marc Maurer <uwog@uwog.net> 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License 00010 * as published by the Free Software Foundation; either version 2 00011 * of the License, or (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00021 * 02111-1307, USA. 00022 */ 00023 #ifndef GR_CARET_H 00024 #define GR_CARET_H 00025 00026 #include "ut_timer.h" 00027 #include "ut_misc.h" 00028 #include "ut_assert.h" 00029 #include "ut_string_class.h" 00030 00031 class GR_Graphics; 00032 00033 class ABI_EXPORT GR_Caret 00034 { 00035 friend class GR_Graphics; 00036 00037 public: 00038 explicit GR_Caret(GR_Graphics * pG); 00039 explicit GR_Caret(GR_Graphics * pG, UT_sint32 iID); 00040 ~GR_Caret(); 00041 00042 void enable(); 00043 // Disable hides the caret if it's currently visible. 00044 // The caret can be disabled multiple times, and just as many enable 00045 // calls need to take place for the cursor to show up. 00046 // If the cursor is already enabled, the enable call just makes the 00047 // cursor get redrawn. 00048 // if bNoMulti is true, then only one enable call needed to reverse this disable. 00049 void disable(bool bNoMulti = false); 00050 inline bool isEnabled() const { return m_nDisableCount == 0; } 00051 00052 void setBlink(bool bBlink); 00053 void forceDraw(void); 00054 // When you call setCoords, the cursor is explicitly shown 00055 // and the timer restarts from 0 for the next 500ms cycle. 00056 void setCoords(UT_sint32 x, UT_sint32 y, UT_uint32 h, 00057 UT_sint32 x2 = 0, UT_sint32 y2 = 0, UT_uint32 h2 = 0, 00058 bool bPointDirection = false, UT_RGBColor * pClr = NULL); 00059 00060 // The caret needs to know about this to clip the save/restore rects. 00061 void setWindowSize(UT_uint32 width, UT_uint32 height); 00062 00063 bool getInsertMode () { return m_insertMode; } 00064 void setInsertMode (bool mode) { m_insertMode = mode; } 00065 UT_sint32 getID(void); 00066 void setRemoteColor(UT_RGBColor clrRemote); 00067 00068 void resetBlinkTimeout(void); 00069 00070 private: 00071 GR_Caret(); // no impl 00072 GR_Caret(const GR_Caret& rhs); // no impl. 00073 void operator=(const GR_Caret& rhs); // no impl. 00074 00075 static void s_work(UT_Worker * w); 00076 static void s_enable(UT_Worker * w); 00077 static void s_blink_timeout(UT_Worker * w); 00078 00079 UT_uint32 _getCursorBlinkTime() const; 00080 UT_uint32 _getCursorBlinkTimeout() const; 00081 bool _getCanCursorBlink() const; 00082 00083 void _erase(); 00084 void _blink(bool bExplicit); 00085 00086 UT_sint32 m_xPoint; 00087 UT_sint32 m_yPoint; 00088 UT_uint32 m_iPointHeight; 00089 // for bidi 00090 UT_sint32 m_xPoint2; 00091 UT_sint32 m_yPoint2; 00092 UT_uint32 m_iPointHeight2; 00093 bool m_bPointDirection; 00094 UT_RGBColor * m_pClr; 00095 GR_Graphics * m_pG; 00096 00097 UT_uint32 m_iWindowWidth; 00098 UT_uint32 m_iWindowHeight; 00099 00100 UT_Timer * m_worker; 00101 UT_Timer * m_enabler; 00102 UT_Timer * m_blinkTimeout; 00103 00104 // m_nDisableCount > 0 implies a disabled cursor. 00105 // m_nDisableCount should never be negative. 00106 UT_uint32 m_nDisableCount; 00107 bool m_bCursorBlink; 00108 bool m_bCursorIsOn; 00109 bool m_bPositionSet; 00110 bool m_bRecursiveDraw; 00111 bool m_bSplitCaret; 00112 bool m_bCaret1OnScreen; 00113 bool m_bCaret2OnScreen; 00114 00115 UT_RGBColor m_clrInsert; 00116 UT_RGBColor m_clrOverwrite; 00117 00118 bool m_insertMode; 00119 bool m_bRemote; 00120 UT_RGBColor m_clrRemote; 00121 UT_sint32 m_iID; 00122 UT_sint32 m_iCaretNumber; 00123 }; 00124 00125 class ABI_EXPORT GR_CaretDisabler 00126 { 00127 public: 00128 00129 GR_CaretDisabler (GR_Caret * pCaret) 00130 : m_pCaret(pCaret) 00131 { 00132 if (m_pCaret) 00133 { 00134 m_pCaret->disable(); 00135 } 00136 } 00137 00138 ~GR_CaretDisabler () 00139 { 00140 if(m_pCaret) 00141 { 00142 m_pCaret->enable(); 00143 } 00144 } 00145 00146 private: 00147 // no impls 00148 GR_CaretDisabler (); 00149 GR_CaretDisabler (const GR_CaretDisabler & other); 00150 GR_CaretDisabler & operator=(const GR_CaretDisabler &other); 00151 00152 GR_Caret * m_pCaret; 00153 }; 00154 00155 00156 #endif // GR_CARET_H
1.5.5