Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

edit.h

00001 // $Id: edit.h,v 1.1.1.1 2003/06/24 15:33:11 sjcomp Exp $
00002 // Copyright (c) 2003, Alexander Shyrokov aka SJ
00003 // E-mail: sjcomp[@]users.sourceforge.com
00004 // Web:    http://sjgui.sourceforge.net
00005 //
00006 // This code is under BSD license agreement.
00007 //
00008 // Alexander Shyrokov makes no representations about the suitability of this software 
00009 // for any purpose. It is provided "AS IS" without express or implied warranty.
00010 
00011 #if !defined(SJEDIT_H_INCLUDED)
00012 #define SJEDIT_H_INCLUDED
00013 
00014 #include <time.h>
00015 
00016 #include "globals.h"
00017 
00018 namespace sjgui{
00019 
00020     namespace SJGUI_USE_STYLE
00021     {
00022         extern int def_edit_font_size; 
00023         extern int def_edit_blink_period; 
00024         extern CWnd::CSize  def_edit_size; 
00025     }
00026 
00048 template<class Ttext>
00049 class CEditCtrlTmpl : public Ttext
00050 {
00051     long            m_lNextBlink; 
00052     long            m_lBlinkPeriod; 
00053 public:
00054     virtual void Animate(); 
00055     virtual void KeyDown(int &iKey); 
00056 
00057     virtual void OnFocusRecv(){IgnoreRepeates(false);};
00059     virtual void OnFocusDism(){IgnoreRepeates(true);HideCursor();};
00060 public:
00062     CEditCtrlTmpl();
00064     void SetText(const char* str){ClearText();AddLine(str);MoveCursorToEnd();}
00066     const char* GetText(){if(m_Strings.size()==0)m_Strings.push_back("");return m_Strings[0].data();}
00068     void SetBlinkPeriod(long miliseconds){m_lBlinkPeriod=miliseconds;m_lNextBlink=0;}
00070     long GetBlinkPeriod(){return m_lBlinkPeriod;}
00071 };
00072 
00073 template<class Ttext>
00074 inline void CEditCtrlTmpl<Ttext>::KeyDown(int &iKey)
00075 {
00076     Ttext::KeyDown(iKey);
00077     switch(iKey)
00078     {
00079         case SJ_KEY_DELETE:
00080             RemoveAfterCursor();
00081             iKey=SJ_KEY_IGNORE;
00082             break;
00083         case SJ_KEY_BACKSPACE:
00084             RemoveBeforeCursor();
00085             iKey=SJ_KEY_IGNORE;
00086             break;
00087         case SJ_KEY_LEFT:
00088             MoveCursorLeft();
00089             iKey=SJ_KEY_IGNORE;
00090             break;
00091         case SJ_KEY_RIGHT:
00092             MoveCursorRight();
00093             iKey=SJ_KEY_IGNORE;
00094             break;
00095         case SJ_KEY_HOME:
00096             MoveCursorToBeginning();
00097             iKey=SJ_KEY_IGNORE;
00098             break;
00099         case SJ_KEY_END:
00100             MoveCursorToEnd();
00101             iKey=SJ_KEY_IGNORE;
00102             break;
00103         case SJ_KEY_MOUSE_LEFT:
00104             int inX=GetMouseX()-GetAbsX()-(int)(GetFontSize()/2);
00105 #define ROUND_DIV(a,b) (((a%b)>0.5f)?(a/b+1):(a/b))
00106             inX=ROUND_DIV(inX,GetFontSize());
00107 #undef ROUND_DIV
00108             SetCursorPos(GetShift()+inX);
00109             break;
00110     }
00111     if(iKey!=SJ_KEY_IGNORE && iKey>31 && iKey<128)
00112     {
00113         unsigned char cSymbol=(unsigned char)iKey;
00114         InsertAtCursor(cSymbol);
00115         iKey=SJ_KEY_IGNORE;
00116     }
00117 }
00118 
00119 template<class Ttext>
00120 inline void CEditCtrlTmpl<Ttext>::Animate()
00121 {
00122     long lt=clock();
00123     // no blinking if not selected
00124     if(IsInFocus() && m_lNextBlink<lt)
00125     {
00126         m_lNextBlink=lt+GetBlinkPeriod();
00127         ShowCursor(!IsCursorShown());
00128     }
00129     Ttext::Animate();
00130 }
00131 
00132 template<class Ttext>
00133 inline CEditCtrlTmpl<Ttext>::CEditCtrlTmpl():Ttext()
00134 {
00135     SetAllowedForFocus(true);
00136     SetFontSize(SJGUI_USE_STYLE::def_edit_font_size);
00137     SetText("Edit1");
00138     // set period to less then 1 second
00139     SetBlinkPeriod(SJGUI_USE_STYLE::def_edit_blink_period);
00140     // set default size of the control
00141     SetSize(SJGUI_USE_STYLE::def_edit_size);
00142     // reset position of cursor
00143     MoveCursorToBeginning();
00144 }
00145 
00146 } // namespace sjgui
00147 
00148 #endif // !defined(SJEDIT_H_INCLUDED)
sjgui logo
Quick Links:

 News
 Description
 Screen Shots
 Projects
 Downloads
 Source Code
 Help/FAQ
 Want to help?
 Credits
 Disclaimer


Documentation:

 Documentation
 Reference
 Lessons


Useful links:

sjcomp logo
sjcomp

opengl logo

nehe logo

SourceForge.net Logo

Last modified:


Started by Alexander Shyrokov. Generated at Wed Apr 28 12:31:04 2004 for the sjgui by doxygen 1.3.1. SourceForge.net Logo