nux-0.9.48
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef EDITTEXTBOX_H 00024 #define EDITTEXTBOX_H 00025 00026 #include "KeyboardHandler.h" 00027 #include "TimerProc.h" 00028 00029 namespace nux 00030 { 00031 class HLayout; 00032 class VLayout; 00033 class Layout; 00034 class BaseKeyboardHandler; 00035 class TextLine; 00036 class Validator; 00037 class TimerFunctor; 00038 00039 class EditTextBox : public View 00040 { 00041 public: 00042 EditTextBox (const TCHAR *Caption, NUX_FILE_LINE_PROTO); 00043 ~EditTextBox(); 00044 virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00045 virtual void Draw (GraphicsEngine &GfxContext, bool force_draw); 00046 virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw); 00047 virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw); 00048 00049 void SetText (const TCHAR &Caption); 00050 void SetText (const TCHAR *Caption); 00051 void SetText (const tstring &Caption); 00052 void SetText (const NString &Caption); 00053 const TCHAR *GetText() const; 00054 t_u32 GetTextSize() const 00055 { 00056 return (t_u32) m_Text.Length(); 00057 } 00058 00059 void SetDoubleValue (double d); 00060 void SetIntegerValue (int i); 00061 00063 virtual NString GetCleanText() const; 00064 00065 void SetTextBackgroundColor (const Color &color); 00066 Color GetTextBackgroundColor() const; 00067 00068 void SetSelectedTextColor (Color color) 00069 { 00070 m_SelectedTextColor = color; 00071 } 00072 void SetSelectedTextBackgroundColor (Color color) 00073 { 00074 m_SelectedTextBackgroundColor = color; 00075 } 00076 void SetTextBlinkColor (Color color) 00077 { 00078 m_TextBlinkColor = color; 00079 } 00080 void SetCursorColor (Color color) 00081 { 00082 m_CursorColor = color; 00083 } 00084 00085 Color GetSelectedTextColor() const 00086 { 00087 return m_SelectedTextColor; 00088 } 00089 Color GetSelectedTextBackgroundColor() const 00090 { 00091 return m_SelectedTextBackgroundColor; 00092 } 00093 Color GetTextBlinkColor() const 00094 { 00095 return m_TextBlinkColor; 00096 } 00097 Color GetCursorColor() const 00098 { 00099 return m_CursorColor; 00100 } 00101 00102 void SetKeyEntryType (BaseKeyboardHandler::eKeyEntryType keytype) 00103 { 00104 m_KeyboardHandler.SetKeyEntryType (keytype); 00105 } 00106 BaseKeyboardHandler::eKeyEntryType GetKeyEntryType() 00107 { 00108 return m_KeyboardHandler.GetKeyEntryType(); 00109 } 00110 00111 // Receivers 00112 void RecvMouseDoubleClick (int x, int y, unsigned long button_flags, unsigned long key_flags); 00113 void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags); 00114 void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags); 00115 void RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); 00116 void RecvKeyEvent ( 00117 GraphicsEngine &GfxContext , /*Graphics Context for text operation*/ 00118 unsigned long eventType , /*event type*/ 00119 unsigned long keysym , /*event keysym*/ 00120 unsigned long state , /*event state*/ 00121 const TCHAR* character , /*character*/ 00122 unsigned short keyCount /*key repeat count*/); 00123 00124 void RecvStartKeyFocus(); 00125 void RecvEndKeyFocus(); 00126 00127 00128 void SetPrefix (const tstring &p) 00129 { 00130 m_Prefix = p; 00131 }; 00132 void SetPrefix (const TCHAR *p) 00133 { 00134 m_Prefix = p; 00135 }; 00136 void SetPrefix (const TCHAR &p) 00137 { 00138 m_Prefix = p; 00139 }; 00140 void SetPrefix (const NString &p) 00141 { 00142 m_Prefix = p; 00143 }; 00144 NString GetPrefix() const 00145 { 00146 return m_Prefix; 00147 }; 00148 00149 void SetSuffix (const tstring &s) 00150 { 00151 m_Suffix = s; 00152 }; 00153 void SetSuffix (const TCHAR *s) 00154 { 00155 m_Suffix = s; 00156 }; 00157 void SetSuffix (const TCHAR &s) 00158 { 00159 m_Suffix = s; 00160 }; 00161 void SetSuffix (const NString &s) 00162 { 00163 m_Suffix = s; 00164 }; 00165 NString Getsuffix() const 00166 { 00167 return m_Suffix; 00168 }; 00169 00170 void SetValidator (const Validator *validator); 00171 00172 sigc::signal< void, EditTextBox *, unsigned int > sigCharacter; // Emitted every time a character typed 00173 sigc::signal< void, EditTextBox * > sigEditChange; // Emitted every time a character typed 00174 00175 sigc::signal< void, EditTextBox *, const NString &> sigValidateKeyboardEntry; 00176 sigc::signal< void, EditTextBox * > sigValidateEntry; // Emitted when the text is validated 00177 sigc::signal< void, EditTextBox * > sigSetText; // Emitted when text is set with setCaption 00178 sigc::signal< void, EditTextBox * > sigEscapeKeyboardFocus; 00179 sigc::signal< void, EditTextBox * > sigStartKeyboardFocus; 00180 sigc::signal< void, EditTextBox * > sigEndKeyboardFocus; 00181 00182 bool IsTextSelected() 00183 { 00184 return m_KeyboardHandler.IsTextSelected(); 00185 } 00186 bool IsEmpty(); 00187 00188 private: 00189 bool ValidateKeyboardEntry (const TCHAR *text) const; 00190 void EscapeKeyboardFocus(); 00191 void EnteringKeyboardFocus(); 00192 void QuitingKeyboardFocus(); 00193 00194 virtual long PostLayoutManagement (long LayoutResult); 00195 00196 NString m_Text; 00197 HLayout *hlayout; 00198 00199 Color m_BackgroundColor; 00200 Color m_SelectedTextColor; 00201 Color m_SelectedTextBackgroundColor; 00202 Color m_TextBlinkColor; 00203 Color m_CursorColor; 00204 00205 BaseKeyboardHandler m_KeyboardHandler; 00206 NString m_temporary_caption; 00207 BaseKeyboardHandler::eKeyEntryType m_keytype; 00208 00209 Validator *m_Validator; 00210 NString m_Suffix; 00211 NString m_Prefix; 00212 00213 bool BlinkCursor; 00214 void BlinkCursorTimerInterrupt (void *v); 00215 void StopBlinkCursor (bool BlinkState = false); 00216 void StartBlinkCursor (bool BlinkState = false); 00217 TimerFunctor *m_BlinkTimerFunctor; 00218 TimerHandle m_BlinkTimerHandler; 00219 00220 void ScrollTimerInterrupt (void *v); 00221 TimerFunctor *m_ScrollTimerFunctor; 00222 TimerHandle m_ScrollTimerHandler; 00223 00225 bool m_WriteAlpha; 00226 00227 friend class RGBValuator; 00228 }; 00229 00230 } 00231 00232 #endif // EDITTEXTBOX_H 00233