2011-07-20 10:33:24 +02:00
/**
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* @ file CodeView . cpp
* @ brief Editeur De N ' ours : Code Viewer Widget
* This is an abstraction
* @ author Edouard DUPIN
* @ date 05 / 01 / 2011
* @ par Project
* Edn
*
* @ par Copyright
* Copyright 2010 Edouard DUPIN , all right reserved
*
* This software is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY .
*
* Licence summary :
* You can modify and redistribute the sources code and binaries .
* You can send me the bug - fix
* You can not earn money with this Software ( if the source extract from Edn
* represent less than 50 % of original Sources )
* Term of the licence in in the file licence . txt .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
2012-01-11 15:26:53 +01:00
# include <CodeView.h>
2011-07-20 10:33:24 +02:00
2012-04-23 10:15:43 +02:00
# include <appl/Debug.h>
2012-04-24 09:42:14 +02:00
# include <appl/global.h>
2012-01-11 15:26:53 +01:00
# include <CodeView.h>
# include <BufferManager.h>
# include <ColorizeManager.h>
2012-04-04 18:18:27 +02:00
# include <ewol/ClipBoard.h>
2012-01-11 15:26:53 +01:00
# include <SearchData.h>
2011-07-20 10:33:24 +02:00
2012-08-20 18:12:14 +02:00
# include <ewol/widget/WidgetManager.h>
# include <ewol/eObject/EObject.h>
2012-01-13 13:06:15 +01:00
# undef __class__
2012-03-14 09:26:14 +01:00
# define __class__ "CodeView"
2012-01-13 13:06:15 +01:00
2012-09-07 16:31:49 +02:00
void CodeView : : Init ( void )
2012-01-13 13:06:15 +01:00
{
2012-11-19 08:00:52 +01:00
m_alignement = ewol : : Text : : alignJustify ;
2012-01-13 13:06:15 +01:00
m_label = " CodeView is disable ... " ;
2012-02-03 18:14:45 +01:00
2012-01-13 13:06:15 +01:00
m_bufferID = - 1 ;
m_buttunOneSelected = false ;
2012-08-09 14:26:30 +02:00
m_lineNumberList . Clear ( ) ;
2012-05-10 16:01:03 +02:00
2012-08-21 18:17:09 +02:00
m_textColorFg = draw : : color : : black ;
2012-01-13 13:06:15 +01:00
2012-08-21 18:17:09 +02:00
m_textColorBg = draw : : color : : black ;
m_textColorBg . a = 0x40 ;
2012-01-13 13:06:15 +01:00
SetCanHaveFocus ( true ) ;
2012-02-29 18:06:08 +01:00
RegisterMultiCast ( ednMsgBufferId ) ;
2012-04-04 18:18:27 +02:00
RegisterMultiCast ( ednMsgGuiCopy ) ;
RegisterMultiCast ( ednMsgGuiPaste ) ;
RegisterMultiCast ( ednMsgGuiCut ) ;
2012-04-16 09:16:43 +02:00
RegisterMultiCast ( ednMsgGuiRedo ) ;
RegisterMultiCast ( ednMsgGuiUndo ) ;
RegisterMultiCast ( ednMsgGuiRm ) ;
RegisterMultiCast ( ednMsgGuiSelect ) ;
2012-04-17 11:01:26 +02:00
RegisterMultiCast ( ednMsgGuiChangeCharset ) ;
2012-07-01 17:54:50 +02:00
RegisterMultiCast ( ednMsgGuiFind ) ;
RegisterMultiCast ( ednMsgGuiReplace ) ;
2012-10-16 18:32:21 +02:00
RegisterMultiCast ( ednMsgGuiGotoLine ) ;
2012-07-20 14:37:46 +02:00
SetLimitScrolling ( 0.2 ) ;
2012-10-23 17:47:31 +02:00
ShortCutAdd ( " ctrl+w " , ednMsgGuiRm , " Line " ) ;
ShortCutAdd ( " ctrl+shift+w " , ednMsgGuiRm , " Paragraph " ) ;
ShortCutAdd ( " ctrl+x " , ednMsgGuiCut , " STD " ) ;
ShortCutAdd ( " ctrl+c " , ednMsgGuiCopy , " STD " ) ;
ShortCutAdd ( " ctrl+v " , ednMsgGuiPaste , " STD " ) ;
ShortCutAdd ( " ctrl+a " , ednMsgGuiSelect , " ALL " ) ;
ShortCutAdd ( " ctrl+shift+a " , ednMsgGuiSelect , " NONE " ) ;
2012-01-13 13:06:15 +01:00
}
2012-11-13 22:50:35 +01:00
CodeView : : CodeView ( etk : : UString fontName , int32_t fontSize ) :
2012-11-16 23:37:21 +01:00
m_OObjectText ( fontName , fontSize ) ,
2012-11-19 08:00:52 +01:00
//m_displayText("Times_New_Roman", 14)
m_displayText ( " Arial " , 14 )
2012-11-13 22:50:35 +01:00
{
Init ( ) ;
}
2012-09-07 16:31:49 +02:00
CodeView : : CodeView ( void )
{
Init ( ) ;
}
2012-01-13 13:06:15 +01:00
CodeView : : ~ CodeView ( void )
{
}
2012-05-10 16:01:03 +02:00
/**
* @ brief Check if the number of reference buffer is good or not . . .
* @ param [ in ] bufferID id of the current Buffer that needed to have a reference
* @ return - - -
*/
void CodeView : : UpdateNumberOfLineReference ( int32_t bufferID )
{
2012-10-26 16:56:53 +02:00
etk : : Vector2D < float > tmpCoord ;
2012-05-10 16:01:03 +02:00
tmpCoord . x = 0 ;
tmpCoord . y = 0 ;
2012-08-09 14:26:30 +02:00
if ( m_lineNumberList . Size ( ) < = bufferID ) {
2012-05-10 16:01:03 +02:00
// update the number of elements :
2012-08-09 14:26:30 +02:00
for ( int32_t iii = m_lineNumberList . Size ( ) ; iii < = bufferID ; iii + + ) {
2012-05-10 16:01:03 +02:00
// add start line at 0 :
2012-08-09 14:26:30 +02:00
m_lineNumberList . PushBack ( tmpCoord ) ;
2012-05-10 16:01:03 +02:00
}
}
}
2012-01-13 13:06:15 +01:00
bool CodeView : : CalculateMinSize ( void )
{
m_minSize . x = 50 ;
m_minSize . y = 50 ;
return true ;
}
2012-02-07 18:04:15 +01:00
void CodeView : : CalculateMaxSize ( void )
{
2012-02-10 18:20:03 +01:00
m_maxSize . x = 2048 ;
2012-11-13 22:50:35 +01:00
int32_t letterHeight = m_OObjectText . GetHeight ( ) ;
2012-02-20 20:30:26 +01:00
m_maxSize . y = BufferManager : : Get ( m_bufferID ) - > GetNumberOfLine ( ) * letterHeight ;
2012-02-07 18:04:15 +01:00
}
2012-02-19 15:48:08 +01:00
2012-02-07 18:04:15 +01:00
2012-07-19 16:54:44 +02:00
void CodeView : : OnDraw ( ewol : : DrawProperty & displayProp )
2012-02-18 15:56:00 +01:00
{
2012-08-10 17:27:32 +02:00
m_OObjectsColored . Draw ( ) ;
2012-11-16 23:37:21 +01:00
//m_OObjectText.Draw();
2012-11-19 08:00:52 +01:00
m_displayDrawing . Draw ( ) ;
2012-11-16 23:37:21 +01:00
m_displayText . Draw ( ) ;
2012-07-19 16:54:44 +02:00
WidgetScrooled : : OnDraw ( displayProp ) ;
2012-02-18 15:56:00 +01:00
}
2012-01-13 13:06:15 +01:00
void CodeView : : OnRegenerateDisplay ( void )
{
2012-02-07 18:04:15 +01:00
if ( true = = NeedRedraw ( ) ) {
2012-08-16 18:22:10 +02:00
int64_t startTime = ewol : : GetTime ( ) ;
2012-02-18 11:50:29 +01:00
2012-02-07 18:04:15 +01:00
// For the scrooling windows
CalculateMaxSize ( ) ;
2012-11-13 22:50:35 +01:00
m_OObjectText . Clear ( ) ;
2012-11-19 08:00:52 +01:00
m_displayDrawing . Clear ( ) ;
2012-11-16 23:37:21 +01:00
m_displayText . Clear ( ) ;
2012-08-10 17:27:32 +02:00
m_OObjectsColored . Clear ( ) ;
2012-02-18 15:56:00 +01:00
2012-11-16 23:37:21 +01:00
# if 1
2012-11-19 08:00:52 +01:00
2012-11-16 23:37:21 +01:00
m_OObjectsColored . SetColor ( draw : : color : : white ) ;
m_OObjectsColored . Rectangle ( 0 , 0 , m_size . x , m_size . y ) ;
2012-11-19 08:00:52 +01:00
m_displayText . SetColor ( draw : : color : : red ) ;
etk : : UString tmpString ( " PETIT test sur les Text Display : " ) ;
2012-11-16 23:37:21 +01:00
2012-11-19 08:00:52 +01:00
switch ( m_alignement )
{
case ewol : : Text : : alignJustify :
m_displayText . SetFontMode ( ewol : : font : : Regular ) ;
tmpString + = " mode JUSTIFY " ;
break ;
case ewol : : Text : : alignLeft :
m_displayText . SetFontMode ( ewol : : font : : Bold ) ;
tmpString + = " mode Left " ;
break ;
case ewol : : Text : : alignRight :
m_displayText . SetFontMode ( ewol : : font : : Italic ) ;
tmpString + = " mode Right " ;
break ;
case ewol : : Text : : alignCenter :
m_displayText . SetFontMode ( ewol : : font : : BoldItalic ) ;
tmpString + = " mode Center " ;
break ;
case ewol : : Text : : alignDisable :
tmpString + = " mode Disable " ;
break ;
}
2012-11-16 23:37:21 +01:00
m_displayText . SetPos ( etk : : Vector3D < float > ( ( float ) 20 , ( float ) m_size . y - 20 , ( float ) 0 ) ) ;
m_displayText . Print ( tmpString ) ;
2012-11-19 08:00:52 +01:00
tmpString = " test de text complexe ... " ;
etk : : Vector < ewol : : TextDecoration > decoration ;
ewol : : TextDecoration plop ;
plop . m_colorFg = draw : : color : : red ;
plop . m_colorBg = draw : : color : : green ;
plop . m_mode = ewol : : font : : Regular ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : green ;
plop . m_colorBg = draw : : color : : red ;
plop . m_mode = ewol : : font : : BoldItalic ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : yellow ;
plop . m_colorBg = draw : : color : : orange ;
plop . m_mode = ewol : : font : : Bold ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : black ;
plop . m_colorBg = draw : : color : : gray ;
plop . m_mode = ewol : : font : : Italic ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : red ;
plop . m_colorBg = draw : : color : : green ;
plop . m_mode = ewol : : font : : Regular ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : red ;
plop . m_colorBg = draw : : color : : green ;
plop . m_mode = ewol : : font : : Regular ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : green ;
plop . m_colorBg = draw : : color : : red ;
plop . m_mode = ewol : : font : : BoldItalic ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : yellow ;
plop . m_colorBg = draw : : color : : orange ;
plop . m_mode = ewol : : font : : Bold ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : black ;
plop . m_colorBg = draw : : color : : gray ;
plop . m_mode = ewol : : font : : Italic ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : red ;
plop . m_colorBg = draw : : color : : green ;
plop . m_mode = ewol : : font : : Regular ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : red ;
plop . m_colorBg = draw : : color : : green ;
plop . m_mode = ewol : : font : : Regular ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : green ;
plop . m_colorBg = draw : : color : : red ;
plop . m_mode = ewol : : font : : BoldItalic ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : yellow ;
plop . m_colorBg = draw : : color : : orange ;
plop . m_mode = ewol : : font : : Bold ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : black ;
plop . m_colorBg = draw : : color : : gray ;
plop . m_mode = ewol : : font : : Italic ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : red ;
plop . m_colorBg = draw : : color : : green ;
plop . m_mode = ewol : : font : : Regular ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : red ;
plop . m_colorBg = draw : : color : : green ;
plop . m_mode = ewol : : font : : Regular ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : green ;
plop . m_colorBg = draw : : color : : red ;
plop . m_mode = ewol : : font : : BoldItalic ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : yellow ;
plop . m_colorBg = draw : : color : : orange ;
plop . m_mode = ewol : : font : : Bold ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : black ;
plop . m_colorBg = draw : : color : : gray ;
plop . m_mode = ewol : : font : : Italic ;
decoration . PushBack ( plop ) ;
plop . m_colorFg = draw : : color : : red ;
plop . m_colorBg = draw : : color : : green ;
plop . m_mode = ewol : : font : : Regular ;
decoration . PushBack ( plop ) ;
m_displayText . SetPos ( etk : : Vector3D < float > ( ( float ) 20 , ( float ) m_size . y - 50 , ( float ) 0 ) ) ;
m_displayText . Print ( tmpString , decoration ) ;
m_displayText . SetColor ( draw : : color : : black ) ;
m_displayText . SetFontMode ( ewol : : font : : Regular ) ;
m_OObjectsColored . SetColor ( draw : : color : : aqua ) ;
m_OObjectsColored . Rectangle ( 20 , 0 , m_size . x - 40 , m_size . y - 100 ) ;
m_displayText . SetColorBG ( draw : : color : : none ) ;
m_OObjectsColored . SetColor ( draw : : color : : green ) ;
m_OObjectsColored . Rectangle ( 200 , 200 , 200 , 200 ) ;
etk : : Vector3D < float > drawClippingPos ( 200.0 , 200.0 , - 0.5 ) ;
etk : : Vector3D < float > drawClippingSize ( 400.0 , 400.0 , 1.0 ) ;
m_displayText . SetClipping ( drawClippingPos , drawClippingSize ) ;
2012-11-16 23:37:21 +01:00
tmpString = " Un jour Cosette se regarda par hasard dans son miroir et se dit: Tiens! Il lui semblait presque qu'elle était jolie. Ceci la jeta dans un trouble singulier. Jusqu'à ce moment elle n'avait point songé à sa figure. Elle se voyait dans son miroir, mais elle ne s'y regardait pas. Et puis, on lui avait souvent dit qu'elle était laide ; Jean Valjean seul disait doucement : Mais non! mais non! Quoi qu'il en fût, Cosette s'était toujours crue laide, et avait grandi dans cette idée avec la résignation facile de l'enfance. Voici que tout d'un coup son miroir lui disait comme Jean Valjean : Mais non! Elle ne dormit pas de la nuit. Si j'étais jolie ? pensait-elle, comme cela serait drôle que je fusse jolie! Et elle se rappelait celles de ses compagnes dont la beauté faisait effet dans le couvent, et elle se disait : Comment ! je serais comme mademoiselle une telle! \n "
" sdfsqdfqsdjfhqlskdjhf qlksjdhflqkjsdhlfkqjshdlkfjqhslkdjfhqlskdjhfqlksjdhflqkjsdhflkqjsdhlkfqjshdlkfjqshldkjqfhsldkfjqhslkdjfqhlskdjfhqlskjdhflqksjdhflkqjshdlfkqjsdf \n \n "
" Le lendemain elle se regarda, mais non par hasard, et elle douta: Où avais-je l'esprit ? dit-elle, non, je suis laide. Elle avait tout simplement mal dormi, elle avait les yeux battus et elle était pâle. Elle ne s'était pas sentie très joyeuse la veille de croire à sa beauté, mais elle fut triste de n'y plus croire. Elle ne se regarda plus, et pendant plus de quinze jours elle tâcha de se coiffer tournant le dos au miroir. \n "
" Le soir, après le dîner, elle faisait assez habituellement de la tapisserie dans le salon, ou quelque ouvrage de couvent, et Jean Valjean lisait à côté d'elle. Une fois elle leva les yeux de son ouvrage et elle fut toute surprise de la façon inquiète dont son père la regardait. \n "
" Une autre fois, elle passait dans la rue, et il lui sembla que quelqu'un qu'elle ne vit pas disait derrière elle : Jolie femme ! mais mal mise. Bah ! pensa-t-elle, ce n'est pas moi. Je suis bien mise et laide. Elle avait alors son chapeau de peluche et sa robe de mérinos. \n "
" Un jour enfin, elle était dans le jardin, et elle entendit la pauvre vieille Toussaint qui disait : Monsieur, remarquez-vous comme mademoiselle devient jolie ? Cosette n'entendit pas ce que son père répondit, les paroles de Toussaint furent pour elle une sorte de commotion. Elle s'échappa du jardin, monta à sa chambre, courut à la glace, il y avait trois mois qu'elle ne s'était regardée, et poussa un cri. Elle venait de s'éblouir elle-même. " ;
2012-11-19 08:00:52 +01:00
m_displayText . SetPos ( etk : : Vector3D < float > ( ( float ) 40 , ( float ) m_size . y - 100 , ( float ) 0 ) ) ;
m_displayText . SetTextAlignement ( 20 , m_size . x - 20 , m_alignement ) ;
2012-11-16 23:37:21 +01:00
m_displayText . Print ( tmpString ) ;
2012-11-19 08:00:52 +01:00
draw : : Color tmpColor = 0x0000FF55 ;
m_displayDrawing . SetColor ( tmpColor ) ;
m_displayDrawing . Tranlate ( etk : : Vector3D < float > ( 100 , 100 , 0 ) ) ;
m_displayDrawing . SetThickness ( 2 ) ;
m_displayDrawing . Rectangle ( etk : : Vector3D < float > ( 200 , 200 , 0 ) ) ;
m_displayDrawing . SetColor ( 0x00F46799 ) ;
m_displayDrawing . SetPos ( etk : : Vector3D < float > ( 300 , 0 , 0 ) ) ;
m_displayDrawing . SetThickness ( 20 ) ;
m_displayDrawing . LineTo ( etk : : Vector3D < float > ( 200 , 200 , 0 ) ) ;
2012-11-16 23:37:21 +01:00
// force the redraw
PeriodicCallSet ( true ) ;
MarkToRedraw ( ) ;
# else
2012-05-10 16:01:03 +02:00
if ( true = = BufferManager : : Get ( m_bufferID ) - > NeedToUpdateDisplayPosition ( ) ) {
2012-10-26 16:56:53 +02:00
etk : : Vector2D < float > borderWidth = BufferManager : : Get ( m_bufferID ) - > GetBorderSize ( ) ;
2012-04-24 13:17:04 +02:00
bool centerRequested = false ;
2012-08-22 18:18:59 +02:00
// TODO : set it back ...
2012-10-26 16:56:53 +02:00
etk : : Vector2D < float > currentPosition = BufferManager : : Get ( m_bufferID ) - > GetPosition ( 999 /*m_OObjectTextNormal.GetFontID()*/ , centerRequested ) ;
2012-04-24 13:17:04 +02:00
SetScrollingPositionDynamic ( borderWidth , currentPosition , centerRequested ) ;
} // else : nothing to do ...
2012-02-07 18:04:15 +01:00
// generate the objects :
2012-11-13 22:50:35 +01:00
BufferManager : : Get ( m_bufferID ) - > Display ( m_OObjectText ,
m_OObjectsColored ,
m_originScrooled . x , m_originScrooled . y , m_size . x , m_size . y ) ;
2012-04-24 13:36:25 +02:00
// set the current size of the windows
SetMaxSize ( BufferManager : : Get ( m_bufferID ) - > GetMaxSize ( ) ) ;
2012-02-07 18:04:15 +01:00
2012-08-16 18:22:10 +02:00
int64_t stopTime = ewol : : GetTime ( ) ;
2012-04-24 13:17:04 +02:00
APPL_DEBUG ( " Display Code Generation = " < < stopTime - startTime < < " micro-s " ) ;
2012-02-18 11:50:29 +01:00
2012-02-07 18:04:15 +01:00
// call the herited class...
WidgetScrooled : : OnRegenerateDisplay ( ) ;
2012-11-16 23:37:21 +01:00
# endif
2012-02-07 18:04:15 +01:00
}
2012-01-13 13:06:15 +01:00
}
2012-02-13 18:03:09 +01:00
bool CodeView : : OnEventKb ( ewol : : eventKbType_te typeEvent , uniChar_t unicodeData )
2012-01-13 13:06:15 +01:00
{
2012-04-23 10:15:43 +02:00
//APPL_DEBUG("KB EVENT : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << "type=" << (int32_t)typeEvent);
2012-01-15 16:09:32 +01:00
if ( typeEvent = = ewol : : EVENT_KB_TYPE_DOWN ) {
2012-02-20 20:30:26 +01:00
BufferManager : : Get ( m_bufferID ) - > AddChar ( unicodeData ) ;
2012-08-14 08:58:56 +02:00
MarkToRedraw ( ) ;
2012-01-13 13:06:15 +01:00
}
2012-01-17 15:35:34 +01:00
return true ;
2012-01-13 13:06:15 +01:00
}
2012-01-17 15:35:34 +01:00
bool CodeView : : OnEventKbMove ( ewol : : eventKbType_te typeEvent , ewol : : eventKbMoveType_te moveTypeEvent )
{
if ( typeEvent = = ewol : : EVENT_KB_TYPE_DOWN ) {
2012-02-20 20:30:26 +01:00
BufferManager : : Get ( m_bufferID ) - > cursorMove ( moveTypeEvent ) ;
2012-08-14 08:58:56 +02:00
MarkToRedraw ( ) ;
2012-01-17 15:35:34 +01:00
}
return true ;
}
2012-08-18 21:06:21 +02:00
/**
* @ brief Event on a past event = = > this event is asynchronous due to all system does not support direct getting datas
* @ note : need to have focus . . .
* @ param [ in ] mode Mode of data requested
* @ return - - -
*/
void CodeView : : OnEventClipboard ( ewol : : clipBoard : : clipboardListe_te clipboardID )
{
BufferManager : : Get ( m_bufferID ) - > Paste ( clipboardID ) ;
MarkToRedraw ( ) ;
}
2012-01-17 15:35:34 +01:00
2012-03-09 18:08:08 +01:00
/**
* @ brief Event on an input of this Widget
2012-05-22 09:49:11 +02:00
* @ param [ in ] type Type of the input ( ewol : : INPUT_TYPE_MOUSE / ewol : : INPUT_TYPE_FINGER . . . )
2012-03-09 18:08:08 +01:00
* @ param [ in ] IdInput Id of the current Input ( PC : left = 1 , right = 2 , middle = 3 , none = 0 / Tactil : first finger = 1 , second = 2 ( only on this widget , no knowledge at ouside finger ) )
* @ param [ in ] typeEvent ewol type of event like EVENT_INPUT_TYPE_DOWN / EVENT_INPUT_TYPE_MOVE / EVENT_INPUT_TYPE_UP / EVENT_INPUT_TYPE_SINGLE / EVENT_INPUT_TYPE_DOUBLE / . . .
* @ param [ in ] pos Absolute position of the event
* @ return true the event is used
* @ return false the event is not used
*/
2012-10-26 16:56:53 +02:00
bool CodeView : : OnEventInput ( ewol : : inputType_te type , int32_t IdInput , ewol : : eventInputType_te typeEvent , etk : : Vector2D < float > pos )
2011-07-20 10:33:24 +02:00
{
2012-10-26 16:56:53 +02:00
etk : : Vector2D < float > relativePos = RelativePosition ( pos ) ;
2012-07-20 14:37:46 +02:00
// corection for the openGl abstraction
2012-08-31 16:46:57 +02:00
//relativePos.y = m_size.y - relativePos.y;
2012-10-26 16:56:53 +02:00
etk : : Vector2D < float > limitedPos = relativePos ;
2012-08-31 16:46:57 +02:00
limitedPos . x = etk_avg ( 1 , limitedPos . x , m_size . x - 1 ) ;
limitedPos . y = etk_avg ( 1 , limitedPos . y , m_size . y - 1 ) ;
2012-11-19 08:00:52 +01:00
if ( 1 = = IdInput ) {
if ( ewol : : EVENT_INPUT_TYPE_SINGLE = = typeEvent ) {
APPL_DEBUG ( " Must change the display ... " ) ;
switch ( m_alignement )
{
case ewol : : Text : : alignJustify :
m_alignement = ewol : : Text : : alignLeft ;
break ;
case ewol : : Text : : alignLeft :
m_alignement = ewol : : Text : : alignRight ;
break ;
case ewol : : Text : : alignRight :
m_alignement = ewol : : Text : : alignCenter ;
break ;
case ewol : : Text : : alignCenter :
m_alignement = ewol : : Text : : alignDisable ;
break ;
case ewol : : Text : : alignDisable :
m_alignement = ewol : : Text : : alignJustify ;
break ;
}
MarkToRedraw ( ) ;
}
}
2012-07-20 14:37:46 +02:00
2012-02-23 13:43:57 +01:00
if ( m_bufferID < 0 ) {
return false ;
}
2012-05-22 09:49:11 +02:00
if ( true = = WidgetScrooled : : OnEventInput ( type , IdInput , typeEvent , pos ) ) {
2012-02-06 17:59:48 +01:00
ewol : : widgetManager : : FocusKeep ( this ) ;
2012-05-22 09:49:11 +02:00
// nothing to do ... done on upper widget ...
2012-02-06 17:59:48 +01:00
return true ;
}
2012-01-15 16:09:32 +01:00
if ( 1 = = IdInput ) {
2012-02-11 11:18:27 +01:00
# ifndef __MODE__Touch
if ( ewol : : EVENT_INPUT_TYPE_DOWN = = typeEvent ) {
m_buttunOneSelected = true ;
ewol : : widgetManager : : FocusKeep ( this ) ;
2012-08-22 18:18:59 +02:00
// TODO : Set something good
2012-08-31 16:46:57 +02:00
BufferManager : : Get ( m_bufferID ) - > MouseEvent ( limitedPos ) ;
2012-08-14 08:58:56 +02:00
MarkToRedraw ( ) ;
2012-02-11 11:18:27 +01:00
} else if ( ewol : : EVENT_INPUT_TYPE_UP = = typeEvent ) {
m_buttunOneSelected = false ;
2012-04-04 18:18:27 +02:00
BufferManager : : Get ( m_bufferID ) - > Copy ( ewol : : clipBoard : : CLIPBOARD_SELECTION ) ;
2012-08-14 08:58:56 +02:00
MarkToRedraw ( ) ;
2012-02-11 11:18:27 +01:00
} else
# endif
if ( ewol : : EVENT_INPUT_TYPE_SINGLE = = typeEvent ) {
# ifdef __MODE__Touch
ewol : : widgetManager : : FocusKeep ( this ) ;
2012-08-31 16:46:57 +02:00
BufferManager : : Get ( m_bufferID ) - > MouseEvent ( limitedPos ) ;
2012-08-14 08:58:56 +02:00
MarkToRedraw ( ) ;
2012-02-11 11:18:27 +01:00
# else
// nothing to do ...
# endif
2012-01-15 15:42:01 +01:00
} else if ( ewol : : EVENT_INPUT_TYPE_DOUBLE = = typeEvent ) {
2012-02-20 20:30:26 +01:00
BufferManager : : Get ( m_bufferID ) - > MouseEventDouble ( ) ;
2012-08-14 08:58:56 +02:00
MarkToRedraw ( ) ;
2012-01-15 15:42:01 +01:00
} else if ( ewol : : EVENT_INPUT_TYPE_TRIPLE = = typeEvent ) {
2012-02-20 20:30:26 +01:00
BufferManager : : Get ( m_bufferID ) - > MouseEventTriple ( ) ;
2012-08-14 08:58:56 +02:00
MarkToRedraw ( ) ;
2012-01-15 16:09:32 +01:00
} else if ( ewol : : EVENT_INPUT_TYPE_MOVE = = typeEvent ) {
if ( true = = m_buttunOneSelected ) {
int xxx , yyy ;
2012-03-09 18:08:08 +01:00
xxx = relativePos . x ;
yyy = relativePos . y ;
2012-01-15 16:09:32 +01:00
if ( xxx < 0 ) {
xxx = 0 ;
}
if ( yyy < 0 ) {
yyy = 0 ;
}
2012-04-23 10:15:43 +02:00
//APPL_INFO("mouse-motion BT1 %d, %d", xxx, yyy);
2012-08-22 18:18:59 +02:00
// TODO : Set something good
2012-08-31 16:46:57 +02:00
BufferManager : : Get ( m_bufferID ) - > MouseSelectFromCursorTo ( limitedPos ) ;
2012-08-14 08:58:56 +02:00
MarkToRedraw ( ) ;
2012-01-15 16:09:32 +01:00
}
}
} else if ( 2 = = IdInput ) {
if ( ewol : : EVENT_INPUT_TYPE_SINGLE = = typeEvent ) {
2012-08-22 18:18:59 +02:00
// TODO : Set something good
2012-08-31 16:46:57 +02:00
BufferManager : : Get ( m_bufferID ) - > MouseEvent ( limitedPos ) ;
2012-08-18 21:06:21 +02:00
ewol : : clipBoard : : Request ( ewol : : clipBoard : : CLIPBOARD_SELECTION ) ;
2012-01-15 16:09:32 +01:00
ewol : : widgetManager : : FocusKeep ( this ) ;
2012-01-15 15:42:01 +01:00
}
}
return true ;
2011-07-20 10:33:24 +02:00
}
2012-02-29 18:06:08 +01:00
/**
* @ brief Receive a message from an other EObject with a specific eventId and data
* @ param [ in ] CallerObject Pointer on the EObject that information came from
* @ param [ in ] eventId Message registered by this class
* @ param [ in ] data Data registered by this class
* @ return - - -
*/
void CodeView : : OnReceiveMessage ( ewol : : EObject * CallerObject , const char * eventId , etk : : UString data )
2011-07-20 10:33:24 +02:00
{
2012-02-29 18:06:08 +01:00
ewol : : WidgetScrooled : : OnReceiveMessage ( CallerObject , eventId , data ) ;
2012-04-23 10:15:43 +02:00
APPL_DEBUG ( " Extern Event : " < < CallerObject < < " type : " < < eventId < < " data= \" " < < data < < " \" " ) ;
2012-01-31 18:26:04 +01:00
2012-02-29 18:06:08 +01:00
if ( eventId = = ednMsgBufferId ) {
2012-05-10 16:01:03 +02:00
//keep the reference of the display offset :
if ( m_bufferID > = 0
2012-08-09 14:26:30 +02:00
& & m_bufferID < m_lineNumberList . Size ( ) ) {
2012-05-10 16:01:03 +02:00
m_lineNumberList [ m_bufferID ] = m_originScrooled ;
}
2012-02-03 18:14:45 +01:00
int32_t bufferID = 0 ;
2012-08-14 16:11:09 +02:00
sscanf ( data . c_str ( ) , " %d " , & bufferID ) ;
2012-04-23 10:15:43 +02:00
APPL_INFO ( " Select a new Buffer ... " < < bufferID ) ;
2012-05-10 16:01:03 +02:00
// set the new buffer ID
2012-02-03 18:14:45 +01:00
m_bufferID = bufferID ;
2012-05-10 16:01:03 +02:00
// update the start display position...
UpdateNumberOfLineReference ( m_bufferID ) ;
// set back if needed the display position ...
if ( m_bufferID > = 0
2012-08-09 14:26:30 +02:00
& & m_bufferID < m_lineNumberList . Size ( ) ) {
2012-05-10 16:01:03 +02:00
m_originScrooled = m_lineNumberList [ m_bufferID ] ;
}
2012-04-04 18:18:27 +02:00
} else if ( eventId = = ednMsgGuiCopy ) {
BufferManager : : Get ( m_bufferID ) - > Copy ( ewol : : clipBoard : : CLIPBOARD_STD ) ;
} else if ( eventId = = ednMsgGuiCut ) {
BufferManager : : Get ( m_bufferID ) - > Cut ( ewol : : clipBoard : : CLIPBOARD_STD ) ;
} else if ( eventId = = ednMsgGuiPaste ) {
2012-08-18 21:06:21 +02:00
ewol : : clipBoard : : Request ( ewol : : clipBoard : : CLIPBOARD_STD ) ;
2012-04-16 09:16:43 +02:00
} else if ( eventId = = ednMsgGuiUndo ) {
BufferManager : : Get ( m_bufferID ) - > Undo ( ) ;
} else if ( eventId = = ednMsgGuiRedo ) {
BufferManager : : Get ( m_bufferID ) - > Redo ( ) ;
} else if ( eventId = = ednMsgGuiRm ) {
// data : "Word" "Line" "Paragraph"
if ( data = = " Word " ) {
2012-04-23 10:15:43 +02:00
APPL_WARNING ( " on event " < < eventId < < " data= \" " < < data < < " \" ==> not coded " ) ;
2012-04-16 09:16:43 +02:00
} else if ( data = = " Line " ) {
BufferManager : : Get ( m_bufferID ) - > RemoveLine ( ) ;
} else if ( data = = " Paragraph " ) {
2012-04-23 10:15:43 +02:00
APPL_WARNING ( " on event " < < eventId < < " data= \" " < < data < < " \" ==> not coded " ) ;
2012-04-16 09:16:43 +02:00
} else {
2012-04-23 10:15:43 +02:00
APPL_ERROR ( " on event " < < eventId < < " unknow data= \" " < < data < < " \" " ) ;
2012-04-16 09:16:43 +02:00
}
} else if ( eventId = = ednMsgGuiSelect ) {
// data : "ALL" "NONE"
if ( data = = " ALL " ) {
BufferManager : : Get ( m_bufferID ) - > SelectAll ( ) ;
} else if ( data = = " NONE " ) {
BufferManager : : Get ( m_bufferID ) - > SelectNone ( ) ;
} else {
2012-04-23 10:15:43 +02:00
APPL_ERROR ( " on event " < < eventId < < " unknow data= \" " < < data < < " \" " ) ;
2012-04-16 09:16:43 +02:00
}
2012-04-17 11:01:26 +02:00
} else if ( eventId = = ednMsgGuiChangeCharset ) {
// data : "UTF-8" "ISO-8859-1" "ISO-8859-15"
if ( data = = " UTF-8 " ) {
BufferManager : : Get ( m_bufferID ) - > SetCharset ( unicode : : EDN_CHARSET_UTF8 ) ;
} else if ( data = = " ISO-8859-1 " ) {
BufferManager : : Get ( m_bufferID ) - > SetCharset ( unicode : : EDN_CHARSET_ISO_8859_1 ) ;
} else if ( data = = " ISO-8859-15 " ) {
BufferManager : : Get ( m_bufferID ) - > SetCharset ( unicode : : EDN_CHARSET_ISO_8859_15 ) ;
} else {
2012-04-23 10:15:43 +02:00
APPL_ERROR ( " on event " < < eventId < < " unknow data= \" " < < data < < " \" " ) ;
2012-04-17 11:01:26 +02:00
}
2012-07-01 17:54:50 +02:00
} else if ( eventId = = ednMsgGuiFind ) {
etk : : UString myDataString ;
SearchData : : GetSearch ( myDataString ) ;
if ( data = = " Next " ) {
BufferManager : : Get ( m_bufferID ) - > Search ( myDataString , false , SearchData : : GetCase ( ) , SearchData : : GetWrap ( ) , SearchData : : GetRegExp ( ) ) ;
} else if ( data = = " Previous " ) {
BufferManager : : Get ( m_bufferID ) - > Search ( myDataString , true , SearchData : : GetCase ( ) , SearchData : : GetWrap ( ) , SearchData : : GetRegExp ( ) ) ;
}
} else if ( eventId = = ednMsgGuiReplace ) {
etk : : UString myDataString ;
SearchData : : GetReplace ( myDataString ) ;
if ( data = = " Normal " ) {
BufferManager : : Get ( m_bufferID ) - > Replace ( myDataString ) ;
} else if ( data = = " All " ) {
}
2012-10-16 18:32:21 +02:00
} else if ( eventId = = ednMsgGuiGotoLine ) {
int32_t lineID = 0 ;
sscanf ( data . c_str ( ) , " %d " , & lineID ) ;
APPL_INFO ( " Goto line : " < < lineID ) ;
BufferManager : : Get ( m_bufferID ) - > JumpAtLine ( lineID ) ;
2012-02-03 18:14:45 +01:00
}
2011-07-20 10:33:24 +02:00
// Force redraw of the widget
2012-08-14 08:58:56 +02:00
MarkToRedraw ( ) ;
2011-07-20 10:33:24 +02:00
}
2012-01-17 15:35:34 +01:00
void CodeView : : OnGetFocus ( void )
2011-07-20 10:33:24 +02:00
{
2012-02-27 18:15:56 +01:00
/*
2012-02-09 17:20:52 +01:00
ewol : : widgetMessageMultiCast : : Send ( GetWidgetId ( ) , ednMsgBufferId , m_bufferID ) ;
2012-02-27 18:15:56 +01:00
*/
2012-08-19 16:56:59 +02:00
ewol : : KeyboardShow ( ) ;
2012-04-23 10:15:43 +02:00
APPL_INFO ( " Focus - In " ) ;
2011-07-20 10:33:24 +02:00
}
2012-01-17 15:35:34 +01:00
void CodeView : : OnLostFocus ( void )
2011-07-20 10:33:24 +02:00
{
2012-02-09 17:20:52 +01:00
ewol : : KeyboardHide ( ) ;
2012-04-23 10:15:43 +02:00
APPL_INFO ( " Focus - out " ) ;
2011-07-20 10:33:24 +02:00
}
2012-02-03 18:14:45 +01:00
void CodeView : : SetFontSize ( int32_t size )
{
2012-11-13 22:50:35 +01:00
m_OObjectText . SetSize ( size ) ;
2012-08-22 18:18:59 +02:00
SetScrollingSize ( size * 3.0 * 1.46 ) ; // 1.46 is a magic nmber ...
2012-02-03 18:14:45 +01:00
}
2012-11-13 22:50:35 +01:00
void CodeView : : SetFontName ( etk : : UString fontName )
{
m_OObjectText . SetFont ( fontName ) ;
}
2012-11-04 15:46:13 +01:00