Back to index

nux  3.0.0
KeyboardHandler.h
Go to the documentation of this file.
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 KEYBOARDHANDLER_H
00024 #define KEYBOARDHANDLER_H
00025 
00026 #include <string>
00027 #include "Utils.h"
00028 #include "NuxGraphics/FontTexture.h"
00029 #if defined(NUX_OS_WINDOWS)
00030 #include "NuxGraphics/Events.h"
00031 #elif defined(NUX_OS_LINUX)
00032 #include "NuxGraphics/Events.h"
00033 #endif
00034 #include "NuxCore/Color.h"
00035 
00036 namespace nux
00037 {
00038 
00039   class GraphicsEngine;
00040 
00041   class BaseKeyboardHandler
00042   {
00043   public:
00044     enum eKeyEntryType
00045     {
00046       eAlphaNumeric,
00047       eDecimalNumber,
00048       eIntegerNumber,
00049       eHexadecimalNumber,
00050       eBinaryNumber
00051     };
00052 
00053     BaseKeyboardHandler();
00054     virtual ~BaseKeyboardHandler();
00055 
00056 
00057     virtual long ProcessKey(
00058       unsigned long    eventType    /*event type*/,
00059       unsigned long    keysym       /*event keysym*/,
00060       unsigned long    state        /*event state*/,
00061       char      character    /*character*/,
00062       const Geometry &g);
00063 
00064     NString GetTextLine() const
00065     {
00066       return m_textline;
00067     }
00068     unsigned int GetLength() const
00069     {
00070       return (unsigned int) m_textline.Length();
00071     }
00072 
00073     unsigned int GetCursorPosition() const
00074     {
00075       return m_caret;
00076     }
00077     bool QueueDraw() const
00078     {
00079       return m_need_redraw;
00080     }
00081     int GetPositionX() const
00082     {
00083       return m_text_positionx;
00084     }
00085     int GetPositionY() const
00086     {
00087       return m_text_positiony;
00088     }
00089 
00090     void SetText(const char *str);
00091     void SetText(const tstring &s);
00092     void SetText(const NString &s);
00093 
00094     void ClearText();
00095     void PlaceCaret(unsigned int cp);
00096 
00097     void MoveCursorAtStart();
00098     void MoveCursorAtEnd();
00099 
00100     void SetKeyEntryType(eKeyEntryType keytype);
00101     eKeyEntryType GetKeyEntryType();
00102 
00103     void SetClipRegion(const Geometry &g);
00104     void GetTextSelection(int *start, int *end) const;
00105     int GetTextSelectionStart() const;
00106     int GetTextSelectionEnd() const;
00107     NString GetSelectedText() const;
00108     void SelectAllText();
00109     void UnselectAllText();
00110     bool IsTextSelected();
00111 
00112     void SetPrefix(NString); // 0x865, 25 rad, 25 degree...
00113     void SetPostfix(NString);
00114 
00115     void EnterFocus();
00116 
00117     unsigned int NextWordPosition(unsigned int cp);
00118     unsigned int PrevWordPosition(unsigned int cp);
00119     void ResolveCaretPosition(int x, int y);
00120     void CaretAutoScroll(int x, int y, Geometry geo);
00121     void MouseDown(int x, int y);
00122     void MouseUp(int x, int y);
00123     void MouseDrag(int x, int y);
00124     //bool IsMouseDrag();
00125 
00126     void SetFont(ObjectPtr<FontTexture> Font);
00127     ObjectPtr<FontTexture> GetFont() const;
00128 
00129   protected:
00130     ObjectPtr<FontTexture> m_Font;
00131     NString m_textline;
00132     int m_previous_cursor_position;
00133     bool m_need_redraw;
00134     int m_text_positionx;
00135     int m_text_positiony;
00136     Geometry m_clip_region;
00137 
00138     eKeyEntryType m_KeyType;
00139 
00140     int   m_caret;           
00141     bool    m_insert_mode;     
00142     int   m_selection_start; 
00143     int   m_first_visible_char;   
00144 
00145     void DeleteSelectionText();
00146     void InsertChar(unsigned int character);
00147     void AdjustCursorAndTextPosition();
00148 
00149 
00150     bool m_entering_focus;
00151     bool m_mouse_drag;
00152     // m_mouse_inside_text_area Detects the fast transition of the mouse from inside the text area to outside
00153     bool m_mouse_inside_text_area;
00154 
00159     static int s_jump_offset_at_borders;
00160     static int s_cursor_width;
00161   };
00162 
00163 }
00164 
00165 #endif // KEYBOARDHANDLER_H