2013-09-19 22:23:31 +02:00
/**
* @ author Edouard DUPIN
*
* @ copyright 2010 , Edouard DUPIN , all right reserved
*
* @ license GPL v3 ( see license file )
*/
2013-10-25 20:49:26 +02:00
# include <appl/debug.h>
2013-09-19 22:23:31 +02:00
# include <appl/global.h>
2013-11-23 18:30:52 +01:00
# include <appl/Gui/TextViewer.h>
# include <appl/BufferManager.h>
2015-08-11 23:21:41 +02:00
# include <gale/context/clipBoard.h>
2013-09-19 22:23:31 +02:00
2013-12-13 21:50:40 +01:00
# include <ewol/widget/Manager.h>
2013-11-23 18:30:52 +01:00
# include <appl/Gui/ViewerManager.h>
2013-12-13 21:50:40 +01:00
# include <ewol/object/Object.h>
2013-10-28 21:47:51 +01:00
# include <appl/TextPluginManager.h>
2013-09-19 22:23:31 +02:00
# undef __class__
2013-10-09 22:00:24 +02:00
# define __class__ "TextViewer"
2013-09-19 22:23:31 +02:00
2013-11-20 21:57:00 +01:00
# define tic() \
int64_t startTime = ewol : : getTime ( ) ;
# define toc(comment) \
int64_t endTime = ewol : : getTime ( ) ; \
int64_t processTimeLocal = ( endTime - startTime ) ; \
APPL_DEBUG ( comment < < ( float ) ( ( float ) processTimeLocal / 1000.0 ) < < " ms " ) ;
2014-08-20 22:34:31 +02:00
2014-08-07 23:41:48 +02:00
appl : : TextViewer : : TextViewer ( ) :
2016-03-10 22:37:37 +01:00
propertyFontName ( this , " font-name " , " FreeMono;DejaVuSansMono;FreeSerif " , " Name of the font for the displayed text " , & appl : : TextViewer : : onChangePropertyFontName ) ,
propertyFontSize ( this , " font-size " , 12 , " Size of the font for the displayed text " , & appl : : TextViewer : : onChangePropertyFontSize ) ,
2013-10-09 22:00:24 +02:00
m_insertMode ( false ) {
2013-11-20 21:57:00 +01:00
addObjectType ( " appl::TextViewer " ) ;
2013-10-07 22:04:21 +02:00
setLimitScrolling ( 0.2 ) ;
2014-04-18 22:22:02 +02:00
setSingleFinger ( false ) ;
2013-09-19 22:23:31 +02:00
2013-10-29 21:13:45 +01:00
// load buffer manager:
2014-08-07 23:41:48 +02:00
m_bufferManager = appl : : BufferManager : : create ( ) ;
2014-09-18 22:27:54 +02:00
m_pluginManager = appl : : textPluginManager : : create ( ) ;
2014-08-07 23:41:48 +02:00
m_viewerManager = appl : : ViewerManager : : create ( ) ;
2013-10-29 21:13:45 +01:00
2013-10-27 20:36:54 +01:00
// load color properties
2014-08-07 23:41:48 +02:00
m_paintingProperties = appl : : GlyphPainting : : create ( " THEME:COLOR:textViewer.json " ) ;
2013-10-27 20:36:54 +01:00
// get all id properties ...
m_colorBackground = m_paintingProperties - > request ( " CODE_basicBackgroung " ) ;
m_colorSpace = m_paintingProperties - > request ( " CODE_space " ) ;
m_colorTabulation = m_paintingProperties - > request ( " CODE_tabulation " ) ;
m_colorCursor = m_paintingProperties - > request ( " CODE_cursor " ) ;
m_colorLineNumber = m_paintingProperties - > request ( " CODE_lineNumber " ) ;
m_colorSelection = m_paintingProperties - > request ( " SelectedText " ) ;
m_colorNormal = m_paintingProperties - > request ( " normal " ) ;
2014-08-07 23:41:48 +02:00
}
2016-03-10 22:37:37 +01:00
void appl : : TextViewer : : init ( ) {
2014-08-07 23:41:48 +02:00
ewol : : widget : : WidgetScrolled : : init ( ) ;
2016-02-15 22:04:10 +01:00
propertyCanFocus . set ( true ) ;
2016-03-10 22:37:37 +01:00
m_displayText . setFont ( * propertyFontName , * propertyFontSize ) ;
2014-09-18 22:27:54 +02:00
m_pluginManager - > connect ( * this ) ;
2013-11-07 21:08:57 +01:00
// last created has focus ...
setCurrentSelect ( ) ;
2016-02-19 23:33:00 +01:00
signalShortcut . connect ( shared_from_this ( ) , & appl : : TextViewer : : onCallbackShortCut ) ;
2014-08-17 23:30:37 +02:00
2014-08-25 22:44:42 +02:00
/*
2014-08-17 23:30:37 +02:00
registerMultiCast ( ednMsgBufferId ) ;
registerMultiCast ( ednMsgGuiFind ) ;
registerMultiCast ( ednMsgGuiReplace ) ;
registerMultiCast ( appl : : MsgSelectGotoLine ) ;
registerMultiCast ( appl : : MsgSelectGotoLineSelect ) ;
2014-08-25 22:44:42 +02:00
*/
if ( m_bufferManager ! = nullptr ) {
2016-02-19 23:33:00 +01:00
m_bufferManager - > signalSelectFile . connect ( shared_from_this ( ) , & appl : : TextViewer : : onCallbackselectNewFile ) ;
2016-03-10 22:37:37 +01:00
} else {
APPL_CRITICAL ( " Buffer manager has not been created at the init " ) ;
2014-08-25 22:44:42 +02:00
}
2013-09-19 22:23:31 +02:00
}
2014-05-15 21:37:39 +02:00
appl : : TextViewer : : ~ TextViewer ( ) {
2014-09-18 22:27:54 +02:00
m_pluginManager - > disconnect ( * this ) ;
2013-09-19 22:23:31 +02:00
}
2014-08-27 22:58:21 +02:00
void appl : : TextViewer : : onCallbackShortCut ( const std : : string & _value ) {
2014-09-18 22:27:54 +02:00
if ( m_pluginManager - > onReceiveShortCut ( * this , _value ) = = true ) {
2014-08-27 22:58:21 +02:00
return ;
}
}
2014-08-25 22:44:42 +02:00
void appl : : TextViewer : : onCallbackselectNewFile ( const std : : string & _value ) {
2016-03-10 22:37:37 +01:00
APPL_INFO ( " Select new file: " < < _value ) ;
2014-11-14 23:57:29 +01:00
if ( isSelectedLast ( ) = = false ) {
return ;
}
2014-08-25 22:44:42 +02:00
// reset scroll:
if ( m_buffer ! = nullptr ) {
2016-04-08 22:10:37 +02:00
m_buffer - > signals . disconnect ( shared_from_this ( ) ) ;
2014-08-25 22:44:42 +02:00
bool needAdd = true ;
2014-09-15 07:21:22 +02:00
auto it = m_drawingRemenber . begin ( ) ;
while ( it ! = m_drawingRemenber . end ( ) ) {
std : : shared_ptr < appl : : Buffer > tmpBuff = it - > first . lock ( ) ;
if ( tmpBuff = = nullptr ) {
it = m_drawingRemenber . erase ( it ) ;
continue ;
}
if ( tmpBuff = = m_buffer ) {
it - > second = m_originScrooled ;
2014-08-25 22:44:42 +02:00
APPL_VERBOSE ( " store origin : " < < m_originScrooled ) ;
needAdd = false ;
break ;
}
2014-09-15 07:21:22 +02:00
+ + it ;
2014-08-25 22:44:42 +02:00
}
if ( needAdd = = true ) {
2014-09-15 07:21:22 +02:00
m_drawingRemenber . push_back ( std : : make_pair ( std : : weak_ptr < appl : : Buffer > ( m_buffer ) , m_originScrooled ) ) ;
2014-08-25 22:44:42 +02:00
APPL_VERBOSE ( " Push origin : " < < m_originScrooled ) ;
}
}
m_originScrooled = vec2 ( 0 , 0 ) ;
if ( m_bufferManager ! = nullptr ) {
m_buffer = m_bufferManager - > get ( _value ) ;
m_bufferManager - > setBufferSelected ( m_buffer ) ;
if ( m_buffer ! = nullptr ) {
2016-02-19 23:33:00 +01:00
m_buffer - > signalIsModify . connect ( shared_from_this ( ) , & appl : : TextViewer : : onCallbackIsModify ) ;
m_buffer - > signalSelectChange . connect ( shared_from_this ( ) , & appl : : TextViewer : : onCallbackSelectChange ) ;
2014-08-25 22:44:42 +02:00
for ( auto element : m_drawingRemenber ) {
2014-09-15 07:21:22 +02:00
if ( element . first . lock ( ) = = m_buffer ) {
2014-08-25 22:44:42 +02:00
m_originScrooled = element . second ;
APPL_VERBOSE ( " retrive origin : " < < m_originScrooled ) ;
// TODO : Check if this element is not out of the display text ...
break ;
}
}
}
}
markToRedraw ( ) ;
return ;
}
2014-05-15 21:37:39 +02:00
std : : string appl : : TextViewer : : getBufferPath ( ) {
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2014-05-12 21:10:45 +02:00
return " " ;
}
std : : string filename = m_buffer - > getFileName ( ) ;
size_t pos = filename . rfind ( ' / ' ) ;
if ( pos = = std : : string : : npos ) {
return " " ;
}
return std : : string ( filename , 0 , pos ) ;
}
2014-01-15 01:15:27 +01:00
2014-05-15 21:37:39 +02:00
bool appl : : TextViewer : : calculateMinSize ( ) {
2013-09-19 22:23:31 +02:00
m_minSize . setValue ( 50 , 50 ) ;
return true ;
}
2014-05-15 21:37:39 +02:00
void appl : : TextViewer : : onDraw ( ) {
2013-10-07 22:04:21 +02:00
m_displayDrawing . draw ( ) ;
m_displayText . draw ( ) ;
2014-01-22 21:38:06 +01:00
WidgetScrolled : : onDraw ( ) ;
2013-09-19 22:23:31 +02:00
}
2014-05-15 21:37:39 +02:00
void appl : : TextViewer : : onRegenerateDisplay ( ) {
2013-10-07 22:04:21 +02:00
if ( false = = needRedraw ( ) ) {
2013-09-26 22:15:39 +02:00
return ;
}
2013-11-20 21:57:00 +01:00
//tic();
2013-09-26 22:15:39 +02:00
// For the scrooling windows
2013-10-07 22:04:21 +02:00
m_displayDrawing . clear ( ) ;
m_displayText . clear ( ) ;
2013-09-26 22:15:39 +02:00
2013-10-07 22:04:21 +02:00
// reset the background :
m_displayDrawing . setPos ( vec3 ( 0 , 0 , 0 ) ) ;
2013-10-27 20:36:54 +01:00
m_displayDrawing . setColor ( ( * m_paintingProperties ) [ m_colorBackground ] . getForeground ( ) ) ;
2013-10-07 22:04:21 +02:00
m_displayDrawing . rectangleWidth ( m_size ) ;
2013-09-26 22:15:39 +02:00
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2013-10-21 21:47:28 +02:00
m_maxSize . setX ( 256 ) ;
m_maxSize . setY ( 256 ) ;
2014-01-15 01:15:27 +01:00
m_displayText . setTextAlignement ( 10 , m_size . x ( ) - 20 , ewol : : compositing : : alignLeft ) ;
2013-10-07 22:04:21 +02:00
m_displayText . setRelPos ( vec3 ( 10 , 0 , 0 ) ) ;
2013-11-14 21:57:10 +01:00
std : : string tmpString ( " <br/> \n "
2013-09-26 22:15:39 +02:00
" <font color= \" red \" > \n "
" <b> \n "
" edn - Editeur De N'ours \n "
" </b> \n "
" </font> \n "
" <br/> \n "
" <br/> \n "
" <font color= \" indigo \" > \n "
" <i> \n "
" No Buffer Availlable to display \n "
" </i> \n "
" </font> \n " ) ;
2013-10-07 22:04:21 +02:00
m_displayText . setPos ( vec3 ( 0.0f , m_size . y ( ) , 0.0f ) ) ;
m_displayText . forceLineReturn ( ) ;
m_displayText . printDecorated ( tmpString ) ;
2013-09-26 22:15:39 +02:00
// call the herited class...
2014-01-22 21:38:06 +01:00
WidgetScrolled : : onRegenerateDisplay ( ) ;
2013-09-26 22:15:39 +02:00
return ;
}
// normal displa of the buffer :
vec3 tmpCursorPosition ( 0 , 0 , - 1 ) ;
2013-11-27 21:33:42 +01:00
float tmpCursorLenght = - 1.0 ;
2013-09-26 22:15:39 +02:00
// real display ...
2014-07-03 21:03:26 +02:00
m_displayText . setColor ( etk : : Color < > ( 0 , 0 , 0 , 255 ) ) ;
2013-09-26 22:15:39 +02:00
float countNbLine = 1 ;
2013-11-22 21:48:05 +01:00
int32_t countColomn = 0 ;
2013-09-26 22:15:39 +02:00
// the siplay string :
2013-11-14 21:57:10 +01:00
std : : u32string stringToDisplay ;
2013-10-21 21:47:28 +02:00
appl : : Buffer : : Iterator selectPosStart = m_buffer - > begin ( ) ;
appl : : Buffer : : Iterator selectPosStop = m_buffer - > begin ( ) ;
if ( m_buffer - > hasTextSelected ( ) = = true ) {
selectPosStart = m_buffer - > selectStart ( ) ;
selectPosStop = m_buffer - > selectStop ( ) ;
2013-10-17 21:57:31 +02:00
}
2013-10-21 21:47:28 +02:00
m_displayText . setPos ( vec3 ( - m_originScrooled . x ( ) , m_size . y ( ) + m_originScrooled . y ( ) , 0 ) ) ;
m_displayText . forceLineReturn ( ) ;
appl : : Buffer : : Iterator startingIt = m_buffer - > begin ( ) ;
2013-11-22 21:48:05 +01:00
int64_t startLineId = 0 ;
2013-10-21 21:47:28 +02:00
if ( m_size . y ( ) < m_displayText . getPos ( ) . y ( ) ) {
for ( startingIt = m_buffer - > begin ( ) ;
2014-10-05 23:46:57 +02:00
( bool ) startingIt = = true ;
2013-10-21 21:47:28 +02:00
+ + startingIt ) {
2013-12-28 14:23:25 +01:00
if ( * startingIt = = u32char : : Return ) {
2013-10-21 21:47:28 +02:00
+ + startLineId ;
m_displayText . forceLineReturn ( ) ;
if ( m_size . y ( ) > = m_displayText . getPos ( ) . y ( ) ) {
+ + startingIt ;
break ;
}
}
}
}
// Display line number :
m_lastOffsetDisplay = 0 ;
2013-11-14 21:57:10 +01:00
vec3 tmpLetterSize = m_displayText . calculateSize ( ( char32_t ) ' A ' ) ;
2013-10-21 21:47:28 +02:00
{
2013-11-22 21:48:05 +01:00
int32_t nbLine = m_buffer - > getNumberOfLines ( ) ;
2013-10-21 21:47:28 +02:00
float nbLineCalc = nbLine ;
int32_t nbChar = 0 ;
while ( nbLineCalc > = 1.0f ) {
+ + nbChar ;
nbLineCalc / = 10.0f ;
}
m_lastOffsetDisplay = tmpLetterSize . x ( ) * ( float ) nbChar + 1.0f ;
2013-10-27 20:36:54 +01:00
m_displayText . setFontItalic ( ( * m_paintingProperties ) [ m_colorLineNumber ] . getItalic ( ) ) ;
m_displayText . setFontBold ( ( * m_paintingProperties ) [ m_colorLineNumber ] . getBold ( ) ) ;
m_displayText . setColorBg ( ( * m_paintingProperties ) [ m_colorLineNumber ] . getBackground ( ) ) ;
m_displayText . setColor ( ( * m_paintingProperties ) [ m_colorLineNumber ] . getForeground ( ) ) ;
2013-10-21 21:47:28 +02:00
m_displayText . setClippingMode ( false ) ;
vec3 startWriteRealPosition = m_displayText . getPos ( ) ;
m_displayText . setPos ( vec3 ( 0.0f , startWriteRealPosition . y ( ) , 0.0f ) ) ;
for ( int32_t iii = startLineId ;
iii < nbLine ;
+ + iii ) {
char tmpLineNumber [ 50 ] ;
2013-11-20 21:57:00 +01:00
sprintf ( tmpLineNumber , " %*d " , nbChar , iii + 1 ) ;
2013-10-21 21:47:28 +02:00
m_displayText . print ( tmpLineNumber ) ;
m_displayText . forceLineReturn ( ) ;
if ( m_displayText . getPos ( ) . y ( ) < - 20.0f ) {
break ;
}
}
m_displayText . setPos ( vec3 ( - m_originScrooled . x ( ) + m_lastOffsetDisplay , startWriteRealPosition . y ( ) , 0.0f ) ) ;
m_displayText . setClipping ( vec2 ( m_lastOffsetDisplay , 0 ) , m_size ) ;
}
2013-10-27 20:36:54 +01:00
appl : : DisplayHLData displayLocalSyntax ;
2013-12-05 22:16:04 +01:00
m_buffer - > hightlightGenerateLines ( displayLocalSyntax , startingIt , ( m_size . y ( ) / tmpLetterSize . y ( ) ) + 5 ) ;
2013-10-21 21:47:28 +02:00
float maxSizeX = 0 ;
2014-06-05 22:01:24 +02:00
appl : : HighlightInfo * HLColor = nullptr ;
2013-11-23 18:30:52 +01:00
bool DisplayCursorAndSelection = isSelectedLast ( ) ;
2013-11-23 12:25:42 +01:00
appl : : Buffer : : Iterator it ;
for ( it = startingIt ;
2014-10-05 23:46:57 +02:00
( bool ) it = = true ;
2013-10-18 22:23:52 +02:00
+ + it ) {
2013-10-21 21:47:28 +02:00
if ( it = = m_buffer - > cursor ( ) ) {
2013-09-26 22:15:39 +02:00
// need to display the cursor :
2013-10-18 22:23:52 +02:00
tmpCursorPosition = m_displayText . getPos ( ) ;
2013-11-27 21:33:42 +01:00
tmpCursorLenght = 0.0f ;
2013-09-26 22:15:39 +02:00
}
2013-10-18 22:23:52 +02:00
//APPL_DEBUG("display element '" << currentValue << "'at pos : " << m_displayText.getPos() );
2013-09-26 22:15:39 +02:00
//APPL_DEBUG(" element size : " << iii << " : " << bufferElementSize);
2013-12-28 14:23:25 +01:00
if ( * it = = u32char : : Return ) {
2013-09-26 22:15:39 +02:00
countNbLine + = 1 ;
countColomn = 0 ;
2014-07-03 21:03:26 +02:00
maxSizeX = std : : max ( m_displayText . getPos ( ) . x ( ) , maxSizeX ) ;
2013-10-30 21:16:38 +01:00
// Display the end line position only if we have the focus ...
2013-11-23 18:30:52 +01:00
if ( DisplayCursorAndSelection = = true ) {
2013-10-30 21:16:38 +01:00
if ( it > = selectPosStart & & it < selectPosStop ) {
2013-12-13 21:50:40 +01:00
ewol : : compositing : : Drawing & draw = m_displayText . getDrawing ( ) ;
2014-07-03 21:03:26 +02:00
draw . setColor ( etk : : Color < > ( 0xFF , 0x00 , 0x00 , 0xFF ) ) ;
2013-10-30 21:16:38 +01:00
draw . setPos ( m_displayText . getPos ( ) + tmpLetterSize / 4.0f ) ;
draw . rectangle ( m_displayText . getPos ( ) + tmpLetterSize * 3.0f / 4.0f ) ;
}
2013-10-22 21:34:13 +02:00
}
2013-11-27 21:33:42 +01:00
if ( tmpCursorLenght = = 0.0f ) {
tmpCursorLenght = tmpLetterSize . x ( ) ;
}
2013-10-18 22:23:52 +02:00
m_displayText . forceLineReturn ( ) ;
2013-10-21 21:47:28 +02:00
m_displayText . setPos ( vec3 ( - m_originScrooled . x ( ) + m_lastOffsetDisplay , m_displayText . getPos ( ) . y ( ) , 0.0f ) ) ;
if ( m_displayText . getPos ( ) . y ( ) < - 20.0f ) {
break ;
}
2013-09-26 22:15:39 +02:00
continue ;
2013-09-19 22:23:31 +02:00
}
2014-10-05 23:46:57 +02:00
HLColor = m_buffer - > getElementColorAtPosition ( displayLocalSyntax , ( int64_t ) it ) ;
2013-10-27 20:36:54 +01:00
bool haveBackground = false ;
2014-06-05 22:01:24 +02:00
if ( HLColor ! = nullptr
& & HLColor - > patern ! = nullptr ) {
2013-10-27 20:36:54 +01:00
m_displayText . setColor ( HLColor - > patern - > getColorGlyph ( ) . getForeground ( ) ) ;
m_displayText . setColorBg ( HLColor - > patern - > getColorGlyph ( ) . getBackground ( ) ) ;
haveBackground = HLColor - > patern - > getColorGlyph ( ) . haveBackground ( ) ;
m_displayText . setFontItalic ( HLColor - > patern - > getColorGlyph ( ) . getItalic ( ) ) ;
m_displayText . setFontBold ( HLColor - > patern - > getColorGlyph ( ) . getBold ( ) ) ;
} else {
m_displayText . setFontItalic ( ( * m_paintingProperties ) [ m_colorNormal ] . getItalic ( ) ) ;
m_displayText . setFontBold ( ( * m_paintingProperties ) [ m_colorNormal ] . getBold ( ) ) ;
m_displayText . setColorBg ( ( * m_paintingProperties ) [ m_colorNormal ] . getBackground ( ) ) ;
m_displayText . setColor ( ( * m_paintingProperties ) [ m_colorNormal ] . getForeground ( ) ) ;
}
if ( haveBackground = = false ) {
2013-12-28 14:23:25 +01:00
if ( * it = = u32char : : Space ) {
2013-10-27 20:36:54 +01:00
m_displayText . setColorBg ( ( * m_paintingProperties ) [ m_colorSpace ] . getForeground ( ) ) ;
2013-12-28 14:23:25 +01:00
} else if ( * it = = u32char : : Tabulation ) {
2013-10-27 20:36:54 +01:00
m_displayText . setColorBg ( ( * m_paintingProperties ) [ m_colorTabulation ] . getForeground ( ) ) ;
}
2013-10-22 21:34:13 +02:00
}
2013-10-27 20:36:54 +01:00
m_buffer - > expand ( countColomn , * it , stringToDisplay ) ;
2013-10-30 21:16:38 +01:00
// Display selection only if we have the focus ...
2013-11-23 18:30:52 +01:00
if ( DisplayCursorAndSelection = = true ) {
2013-10-30 21:16:38 +01:00
if ( it > = selectPosStart & & it < selectPosStop ) {
m_displayText . setColor ( ( * m_paintingProperties ) [ m_colorSelection ] . getForeground ( ) ) ;
m_displayText . setColorBg ( ( * m_paintingProperties ) [ m_colorSelection ] . getBackground ( ) ) ;
}
2013-10-17 21:57:31 +02:00
}
2013-10-07 22:04:21 +02:00
//APPL_DEBUG("display : '" << currentValue << "' == > '" << stringToDisplay << "'");
2013-10-17 21:57:31 +02:00
m_displayText . print ( stringToDisplay ) ;
2013-11-27 21:33:42 +01:00
if ( tmpCursorLenght = = 0.0f ) {
tmpCursorLenght = m_displayText . getPos ( ) . x ( ) - tmpCursorPosition . x ( ) ;
}
2013-10-07 22:04:21 +02:00
countColomn + = stringToDisplay . size ( ) ;
2013-09-19 22:23:31 +02:00
}
2013-11-23 12:25:42 +01:00
if ( it = = m_buffer - > cursor ( ) ) {
tmpCursorPosition = m_displayText . getPos ( ) ;
2013-11-27 21:33:42 +01:00
tmpCursorLenght = 5 ;
2013-11-23 12:25:42 +01:00
}
2014-07-03 21:03:26 +02:00
maxSizeX = std : : max ( m_displayText . getPos ( ) . x ( ) , maxSizeX ) ;
2013-10-30 21:16:38 +01:00
// Display cursor only if we have the focus ...
if ( tmpCursorPosition . z ( ) ! = - 1
& & getFocus ( ) = = true ) {
2013-09-26 22:15:39 +02:00
// display the cursor:
2013-09-30 00:08:52 +02:00
//APPL_DEBUG("display cursor at position : " << tmpCursorPosition);
2013-10-07 22:04:21 +02:00
m_displayText . setPos ( tmpCursorPosition ) ;
2013-11-27 21:33:42 +01:00
if ( m_buffer - > hasTextSelected ( ) = = true ) {
m_displayText . setColorBg ( ( * m_paintingProperties ) [ m_colorCursor ] . getForeground ( ) ) ;
m_displayText . printCursor ( false ) ;
} else {
if ( m_insertMode = = true ) {
m_displayText . setColorBg ( ( * m_paintingProperties ) [ m_colorSelection ] . getBackground ( ) ) ;
} else {
m_displayText . setColorBg ( ( * m_paintingProperties ) [ m_colorCursor ] . getForeground ( ) ) ;
}
m_displayText . printCursor ( m_insertMode , tmpCursorLenght ) ;
}
2013-09-26 22:15:39 +02:00
}
2013-10-21 21:47:28 +02:00
// set maximum size (X&Y) :
{
2013-11-14 21:57:10 +01:00
vec3 tmpLetterSize = m_displayText . calculateSize ( ( char32_t ) ' A ' ) ;
2013-11-22 21:48:05 +01:00
int64_t nbLines = m_buffer - > getNumberOfLines ( ) ;
2013-10-21 21:47:28 +02:00
m_maxSize . setX ( maxSizeX + m_originScrooled . x ( ) ) ;
m_maxSize . setY ( ( float ) nbLines * tmpLetterSize . y ( ) ) ;
}
2013-11-20 21:57:00 +01:00
//toc("Display time : ");
2013-09-26 22:15:39 +02:00
// call the herited class...
2014-01-22 21:38:06 +01:00
WidgetScrolled : : onRegenerateDisplay ( ) ;
2013-09-19 22:23:31 +02:00
}
2013-12-13 21:50:40 +01:00
bool appl : : TextViewer : : onEventEntry ( const ewol : : event : : Entry & _event ) {
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2013-09-26 22:15:39 +02:00
return false ;
2013-09-19 22:23:31 +02:00
}
2013-10-20 18:14:22 +02:00
// First call plugin
2014-09-18 22:27:54 +02:00
if ( m_pluginManager - > onEventEntry ( * this , _event ) = = true ) {
2013-10-20 18:14:22 +02:00
markToRedraw ( ) ;
return true ;
}
2013-10-07 22:04:21 +02:00
// just forward event == > manage directly in the buffer
2015-08-11 23:21:41 +02:00
if ( _event . getType ( ) = = gale : : key : : keyboard_char ) {
2013-10-20 18:14:22 +02:00
//APPL_DEBUG("KB EVENT : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << "type=" << (int32_t)typeEvent);
2015-08-11 23:21:41 +02:00
if ( _event . getStatus ( ) ! = gale : : key : : status_down ) {
2013-10-20 18:14:22 +02:00
return false ;
}
2013-11-14 21:57:10 +01:00
char32_t localValue = _event . getChar ( ) ;
2013-12-28 14:23:25 +01:00
if ( localValue = = u32char : : Return ) {
2013-12-13 21:50:40 +01:00
if ( true = = _event . getSpecialKey ( ) . getShift ( ) ) {
2013-12-28 14:23:25 +01:00
localValue = u32char : : CarrierReturn ;
2013-10-20 18:14:22 +02:00
}
2013-12-28 14:23:25 +01:00
} else if ( localValue = = u32char : : Suppress ) {
2013-10-20 18:14:22 +02:00
//APPL_INFO("keyEvent : <suppr> pos=" << m_cursorPos);
if ( m_buffer - > hasTextSelected ( ) ) {
2013-10-22 21:34:13 +02:00
remove ( ) ;
2013-10-20 18:14:22 +02:00
} else {
appl : : Buffer : : Iterator pos = m_buffer - > cursor ( ) ;
appl : : Buffer : : Iterator posEnd = pos ;
+ + posEnd ;
replace ( " " , pos , posEnd ) ;
}
return true ;
2013-12-28 14:23:25 +01:00
} else if ( localValue = = u32char : : Delete ) {
2013-10-20 18:14:22 +02:00
//APPL_INFO("keyEvent : <del> pos=" << m_cursorPos);
if ( m_buffer - > hasTextSelected ( ) ) {
2013-10-22 21:34:13 +02:00
remove ( ) ;
2013-10-20 18:14:22 +02:00
} else {
appl : : Buffer : : Iterator pos = m_buffer - > cursor ( ) ;
appl : : Buffer : : Iterator posEnd = pos ;
- - pos ;
replace ( " " , pos , posEnd ) ;
}
return true ;
}
m_buffer - > setSelectMode ( false ) ;
// normal adding char ...
char output [ 5 ] ;
2014-04-16 22:21:20 +02:00
output [ 0 ] = ' 0 ' ;
u32char : : convertUtf8 ( localValue , output ) ;
2013-10-20 18:14:22 +02:00
if ( m_buffer - > hasTextSelected ( ) = = false
2013-12-13 21:50:40 +01:00
& & _event . getSpecialKey ( ) . getInsert ( ) = = true ) {
2013-10-20 18:14:22 +02:00
appl : : Buffer : : Iterator pos = m_buffer - > cursor ( ) ;
appl : : Buffer : : Iterator posEnd = pos ;
+ + posEnd ;
2013-11-14 21:57:10 +01:00
replace ( output , pos , posEnd ) ;
//TODO : choisce UTF ... replace(localValue, pos, posEnd);
2013-10-20 18:14:22 +02:00
} else {
2013-11-14 21:57:10 +01:00
std : : string myString = output ;
2013-10-20 18:14:22 +02:00
write ( myString ) ;
}
return true ;
}
// move events ...
2015-08-11 23:21:41 +02:00
if ( _event . getStatus ( ) = = gale : : key : : status_down ) {
2013-11-20 21:57:00 +01:00
// selection when shift is set:
2013-12-13 21:50:40 +01:00
m_buffer - > setSelectMode ( _event . getSpecialKey ( ) . getShift ( ) ) ;
2013-10-20 18:14:22 +02:00
// check selection event ...
switch ( _event . getType ( ) ) {
2015-08-11 23:21:41 +02:00
case gale : : key : : keyboard_insert :
2013-11-27 21:33:42 +01:00
m_insertMode = m_insertMode = = true ? false : true ;
markToRedraw ( ) ;
break ;
2015-08-11 23:21:41 +02:00
case gale : : key : : keyboard_left :
2013-10-20 18:14:22 +02:00
//APPL_INFO("keyEvent : <LEFT>");
moveCursorLeft ( ) ;
break ;
2015-08-11 23:21:41 +02:00
case gale : : key : : keyboard_right :
2013-10-20 18:14:22 +02:00
//APPL_INFO("keyEvent : <RIGHT>");
moveCursorRight ( ) ;
break ;
2015-08-11 23:21:41 +02:00
case gale : : key : : keyboard_up :
2013-10-20 18:14:22 +02:00
//APPL_INFO("keyEvent : <UP>");
moveCursorUp ( 1 ) ;
break ;
2015-08-11 23:21:41 +02:00
case gale : : key : : keyboard_down :
2013-10-20 18:14:22 +02:00
//APPL_INFO("keyEvent : <DOWN>");
moveCursorDown ( 1 ) ;
break ;
2015-08-11 23:21:41 +02:00
case gale : : key : : keyboard_pageUp :
2013-10-20 18:14:22 +02:00
//APPL_INFO("keyEvent : <PAGE-UP>");
2013-11-20 21:57:00 +01:00
moveCursorUp ( 15 ) ; // TODO : Set the real number of line ...
2013-10-20 18:14:22 +02:00
break ;
2015-08-11 23:21:41 +02:00
case gale : : key : : keyboard_pageDown :
2013-10-20 18:14:22 +02:00
//APPL_INFO("keyEvent : <PAGE-DOWN>");
2013-11-20 21:57:00 +01:00
moveCursorDown ( 15 ) ; // TODO : Set the real number of line ...
2013-10-20 18:14:22 +02:00
break ;
2015-08-11 23:21:41 +02:00
case gale : : key : : keyboard_start :
2013-10-20 18:14:22 +02:00
//APPL_INFO("keyEvent : <Start of line>");
moveCursorLeft ( moveEnd ) ;
break ;
2015-08-11 23:21:41 +02:00
case gale : : key : : keyboard_end :
2013-10-20 18:14:22 +02:00
//APPL_INFO("keyEvent : <End of line>");
moveCursorRight ( moveEnd ) ;
break ;
default :
break ;
}
2013-09-26 22:15:39 +02:00
return true ;
}
return false ;
2013-09-19 22:23:31 +02:00
}
2013-12-13 21:50:40 +01:00
bool appl : : TextViewer : : onEventInput ( const ewol : : event : : Input & _event ) {
2014-06-03 22:19:00 +02:00
if ( _event . getId ( ) ! = 0
2015-08-11 23:21:41 +02:00
& & _event . getStatus ( ) = = gale : : key : : status_down ) {
2013-11-07 21:08:57 +01:00
keepFocus ( ) ;
}
2013-11-20 21:57:00 +01:00
//tic();
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2013-10-16 21:55:45 +02:00
return false ;
2013-09-19 22:23:31 +02:00
}
2013-10-21 21:47:28 +02:00
// First call the scrolling widget :
2014-04-18 22:22:02 +02:00
if ( ewol : : widget : : WidgetScrolled : : onEventInput ( _event ) = = true ) {
2013-10-21 21:47:28 +02:00
markToRedraw ( ) ;
return true ;
}
// Second call plugin
2014-09-18 22:27:54 +02:00
if ( m_pluginManager - > onEventInput ( * this , _event ) = = true ) {
2013-10-20 18:14:22 +02:00
markToRedraw ( ) ;
return true ;
}
2013-10-16 21:55:45 +02:00
vec2 relativePos = relativePosition ( _event . getPos ( ) ) ;
2013-10-21 21:47:28 +02:00
// offset for the lineNumber:
relativePos - = vec2 ( m_lastOffsetDisplay , 0 ) ;
// offset for the scrolling:
relativePos + = vec2 ( m_originScrooled . x ( ) , - m_originScrooled . y ( ) ) ;
2013-10-16 21:55:45 +02:00
// invert for the buffer event ...
relativePos . setY ( m_size . y ( ) - relativePos . y ( ) ) ;
2013-10-20 18:14:22 +02:00
if ( relativePos . x ( ) < 0 ) {
relativePos . setX ( 0 ) ;
}
2013-11-19 21:43:43 +01:00
if ( _event . getId ( ) = = 12
2015-08-11 23:21:41 +02:00
& & _event . getStatus ( ) = = gale : : key : : status_single ) {
2014-08-25 22:44:42 +02:00
APPL_TODO ( " RAT5 SAVE button ==> TODO implement " ) ;
2013-11-19 21:43:43 +01:00
// Rat5 save event
2014-08-25 22:44:42 +02:00
//sendMultiCast(ednMsgGuiSave, "current");
2013-11-19 21:43:43 +01:00
return true ;
}
2013-10-16 21:55:45 +02:00
// just forward event == > manage directly in the buffer
2013-10-20 18:14:22 +02:00
if ( _event . getId ( ) = = 1 ) {
// mouse selection :
2015-08-11 23:21:41 +02:00
//if (_event.getType() == gale::key::typeMouse) {
if ( _event . getStatus ( ) = = gale : : key : : status_down ) {
2013-11-20 21:57:00 +01:00
//if (_event.getSpecialKey().isSetShift() == false) {
appl : : Buffer : : Iterator newPos = getMousePosition ( relativePos ) ;
2014-01-04 20:21:54 +01:00
m_buffer - > setSelectMode ( false ) ;
2013-11-20 21:57:00 +01:00
moveCursor ( newPos ) ;
m_buffer - > setSelectMode ( true ) ;
markToRedraw ( ) ;
return true ;
//}
2015-08-11 23:21:41 +02:00
} else if ( _event . getStatus ( ) = = gale : : key : : status_up ) {
2013-10-20 18:14:22 +02:00
appl : : Buffer : : Iterator newPos = getMousePosition ( relativePos ) ;
moveCursor ( newPos ) ;
m_buffer - > setSelectMode ( false ) ;
2013-11-20 21:57:00 +01:00
// Copy selection :
std : : string value ;
m_buffer - > copy ( value ) ;
if ( value . size ( ) ! = 0 ) {
2015-08-11 23:21:41 +02:00
gale : : context : : clipBoard : : set ( gale : : context : : clipBoard : : clipboardSelection , value ) ;
2013-11-20 21:57:00 +01:00
}
2013-10-20 18:14:22 +02:00
markToRedraw ( ) ;
return true ;
}
2014-01-04 20:21:54 +01:00
//}
2015-08-11 23:21:41 +02:00
if ( _event . getStatus ( ) = = gale : : key : : status_single ) {
if ( _event . getType ( ) = = gale : : key : : type_mouse
| | _event . getType ( ) = = gale : : key : : type_finger ) {
2013-10-20 18:14:22 +02:00
appl : : Buffer : : Iterator newPos = getMousePosition ( relativePos ) ;
moveCursor ( newPos ) ;
markToRedraw ( ) ;
return true ;
}
2015-08-11 23:21:41 +02:00
} else if ( _event . getStatus ( ) = = gale : : key : : status_double ) {
2013-10-20 18:14:22 +02:00
mouseEventDouble ( ) ;
2013-11-21 21:18:30 +01:00
// Copy selection :
std : : string value ;
m_buffer - > copy ( value ) ;
if ( value . size ( ) ! = 0 ) {
2015-08-11 23:21:41 +02:00
gale : : context : : clipBoard : : set ( gale : : context : : clipBoard : : clipboardSelection , value ) ;
2013-11-21 21:18:30 +01:00
}
2013-10-20 18:14:22 +02:00
markToRedraw ( ) ;
return true ;
2015-08-11 23:21:41 +02:00
} else if ( _event . getStatus ( ) = = gale : : key : : status_triple ) {
2013-10-20 18:14:22 +02:00
mouseEventTriple ( ) ;
2013-11-21 21:18:30 +01:00
// Copy selection :
std : : string value ;
m_buffer - > copy ( value ) ;
if ( value . size ( ) ! = 0 ) {
2015-08-11 23:21:41 +02:00
gale : : context : : clipBoard : : set ( gale : : context : : clipBoard : : clipboardSelection , value ) ;
2013-11-21 21:18:30 +01:00
}
2013-10-20 18:14:22 +02:00
markToRedraw ( ) ;
return true ;
2015-08-11 23:21:41 +02:00
} else if ( _event . getStatus ( ) = = gale : : key : : status_move ) {
2013-10-20 18:14:22 +02:00
if ( m_buffer - > getSelectMode ( ) = = true ) {
2013-12-05 22:16:04 +01:00
//int64_t timeStart = ewol::getTime();
2013-10-20 18:14:22 +02:00
appl : : Buffer : : Iterator newPos = getMousePosition ( relativePos ) ;
2013-12-05 22:16:04 +01:00
//int64_t timeMedium1 = ewol::getTime();
2013-10-20 18:14:22 +02:00
moveCursor ( newPos ) ;
2013-12-05 22:16:04 +01:00
//int64_t timeMedium2 = ewol::getTime();
2013-10-20 18:14:22 +02:00
markToRedraw ( ) ;
2013-12-05 22:16:04 +01:00
/*
int64_t timeStop = ewol : : getTime ( ) ;
APPL_DEBUG ( " Display selection= " < < ( timeStop - timeStart ) / 1000.0f < < " ms " ) ;
APPL_DEBUG ( " 1= " < < ( timeMedium1 - timeStart ) / 1000.0f < < " ms " ) ;
APPL_DEBUG ( " 2= " < < ( timeMedium2 - timeMedium1 ) / 1000.0f < < " ms " ) ;
*/
2013-10-20 18:14:22 +02:00
return true ;
}
}
} else if ( 2 = = _event . getId ( ) ) {
2015-08-11 23:21:41 +02:00
if ( gale : : key : : status_single = = _event . getStatus ( ) ) {
2013-10-20 18:14:22 +02:00
appl : : Buffer : : Iterator newPos = getMousePosition ( relativePos ) ;
moveCursor ( newPos ) ;
2015-08-11 23:21:41 +02:00
gale : : context : : clipBoard : : request ( gale : : context : : clipBoard : : clipboardSelection ) ;
2013-10-20 18:14:22 +02:00
markToRedraw ( ) ;
return true ;
}
2013-10-16 21:55:45 +02:00
}
2013-10-20 18:14:22 +02:00
return false ;
}
2014-05-15 21:37:39 +02:00
void appl : : TextViewer : : mouseEventDouble ( ) {
2013-10-20 18:14:22 +02:00
//m_selectMode = false;
appl : : Buffer : : Iterator beginPos , endPos ;
if ( true = = m_buffer - > getPosAround ( m_buffer - > cursor ( ) , beginPos , endPos ) ) {
moveCursor ( endPos ) ;
m_buffer - > setSelectionPos ( beginPos ) ;
}
}
2014-05-15 21:37:39 +02:00
void appl : : TextViewer : : mouseEventTriple ( ) {
2013-10-20 18:14:22 +02:00
//m_selectMode = false;
moveCursor ( m_buffer - > getEndLine ( m_buffer - > cursor ( ) ) ) ;
m_buffer - > setSelectionPos ( m_buffer - > getStartLine ( m_buffer - > cursor ( ) ) ) ;
}
2013-12-05 22:16:04 +01:00
// TODO : optimise this with retaine the display position buffer and his position in the real view ...
2013-10-20 18:14:22 +02:00
appl : : Buffer : : Iterator appl : : TextViewer : : getMousePosition ( const vec2 & _relativePos ) {
2013-11-14 21:57:10 +01:00
char32_t currentValue ;
2013-10-20 18:14:22 +02:00
vec3 positionCurentDisplay ( 0 , 0 , 0 ) ;
2013-11-14 21:57:10 +01:00
vec3 tmpLetterSize = m_displayText . calculateSize ( ( char32_t ) ' A ' ) ;
2013-11-22 21:48:05 +01:00
int32_t countColomn = 0 ;
2013-11-14 21:57:10 +01:00
std : : u32string stringToDisplay ;
2013-10-20 18:14:22 +02:00
m_displayText . clear ( ) ;
m_displayText . forceLineReturn ( ) ;
2013-11-26 21:33:45 +01:00
positionCurentDisplay = m_displayText . getPos ( ) ;
2013-10-20 18:14:22 +02:00
for ( appl : : Buffer : : Iterator it = m_buffer - > begin ( ) ;
2014-10-05 23:46:57 +02:00
( bool ) it = = true ;
2013-10-20 18:14:22 +02:00
+ + it ) {
currentValue = * it ;
2013-12-28 14:23:25 +01:00
if ( currentValue = = u32char : : Return ) {
2013-12-05 22:16:04 +01:00
m_displayText . forceLineReturn ( ) ;
countColomn = 0 ;
} else {
if ( - _relativePos . y ( ) > = positionCurentDisplay . y ( ) ) {
m_buffer - > expand ( countColomn , currentValue , stringToDisplay ) ;
for ( size_t kkk = 0 ; kkk < stringToDisplay . size ( ) ; + + kkk ) {
2013-12-28 14:23:25 +01:00
if ( stringToDisplay [ kkk ] = = u32char : : Return ) {
2013-12-05 22:16:04 +01:00
m_displayText . forceLineReturn ( ) ;
countColomn = 0 ;
} else {
//note : Without this condithion the time od selection change to 0.6 ms to 8ms ...
//APPL_DEBUG("check : " << -_relativePos.y() << ">=" << positionCurentDisplay.y());
2014-01-15 01:15:27 +01:00
m_displayText . printChar ( stringToDisplay [ kkk ] ) ;
2013-12-05 22:16:04 +01:00
+ + countColomn ;
}
2013-11-20 21:57:00 +01:00
}
2013-10-20 18:14:22 +02:00
}
}
if ( - _relativePos . y ( ) > = positionCurentDisplay . y ( ) ) {
if ( - _relativePos . y ( ) < positionCurentDisplay . y ( ) + tmpLetterSize . y ( ) ) {
2013-11-24 15:26:47 +01:00
APPL_VERBOSE ( " line position : ' " < < ( char ) ( * it ) < < " ' = ' " < < stringToDisplay < < " ' n= " < < countColomn < < " " < < positionCurentDisplay . x ( ) < < " < " < < _relativePos . x ( ) < < " < " < < m_displayText . getPos ( ) . x ( ) ) ;
2013-10-20 18:14:22 +02:00
if ( _relativePos . x ( ) > = positionCurentDisplay . x ( )
& & _relativePos . x ( ) < m_displayText . getPos ( ) . x ( ) ) {
2013-11-24 15:26:47 +01:00
APPL_VERBOSE ( " find ... " ) ;
2013-10-20 18:14:22 +02:00
return it ;
}
} else {
2013-11-24 15:26:47 +01:00
// previous line ...
2013-10-20 18:14:22 +02:00
return - - it ;
}
}
positionCurentDisplay = m_displayText . getPos ( ) ;
}
return m_buffer - > end ( ) ;
2013-09-19 22:23:31 +02:00
}
2015-08-11 23:21:41 +02:00
void appl : : TextViewer : : onEventClipboard ( enum gale : : context : : clipBoard : : clipboardListe _clipboardID ) {
2014-06-05 22:01:24 +02:00
if ( m_buffer ! = nullptr ) {
2015-08-11 23:21:41 +02:00
std : : string data = gale : : context : : clipBoard : : get ( _clipboardID ) ;
2013-10-20 18:14:22 +02:00
write ( data ) ;
2013-09-26 22:15:39 +02:00
}
2013-10-07 22:04:21 +02:00
markToRedraw ( ) ;
2013-09-26 22:15:39 +02:00
}
2014-08-25 05:55:06 +02:00
void appl : : TextViewer : : onCallbackIsModify ( ) {
markToRedraw ( ) ;
}
void appl : : TextViewer : : onCallbackSelectChange ( ) {
markToRedraw ( ) ;
}
2014-05-15 21:37:39 +02:00
void appl : : TextViewer : : onGetFocus ( ) {
2013-10-09 22:00:24 +02:00
showKeyboard ( ) ;
2013-09-19 22:23:31 +02:00
APPL_INFO ( " Focus - In " ) ;
2013-11-07 21:08:57 +01:00
setCurrentSelect ( ) ;
markToRedraw ( ) ;
2013-09-19 22:23:31 +02:00
}
2014-05-15 21:37:39 +02:00
void appl : : TextViewer : : onLostFocus ( ) {
2013-10-09 22:00:24 +02:00
hideKeyboard ( ) ;
2013-09-19 22:23:31 +02:00
APPL_INFO ( " Focus - out " ) ;
2013-11-07 21:08:57 +01:00
markToRedraw ( ) ;
2013-09-19 22:23:31 +02:00
}
2016-03-10 22:37:37 +01:00
void appl : : TextViewer : : onChangePropertyFontSize ( ) {
m_displayText . setFontSize ( * propertyFontSize ) ;
setScrollingSize ( * propertyFontSize * 3.0 * 1.46 ) ; // 1.46 is a magic number ...
2013-09-19 22:23:31 +02:00
}
2016-03-10 22:37:37 +01:00
void appl : : TextViewer : : onChangePropertyFontName ( ) {
m_displayText . setFontName ( * propertyFontName ) ;
2013-09-19 22:23:31 +02:00
}
2013-12-05 22:16:04 +01:00
// TODO : Update process time ==> a little expensive (2->4ms) in end of file
2014-05-15 21:37:39 +02:00
void appl : : TextViewer : : updateScrolling ( ) {
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2013-11-20 21:57:00 +01:00
return ;
}
vec2 realCursorPosition ( 0 , 0 ) ;
uint32_t lineId = m_buffer - > getCursorLinesId ( ) ;
m_displayText . clear ( ) ;
m_displayText . forceLineReturn ( ) ;
float lineSize = - m_displayText . getPos ( ) . y ( ) ;
for ( size_t iii = 0 ; iii < lineId ; + + iii ) {
m_displayText . forceLineReturn ( ) ;
}
realCursorPosition . setY ( - m_displayText . getPos ( ) . y ( ) ) ;
2013-11-23 18:30:52 +01:00
realCursorPosition . setX ( getScreenSize ( m_buffer - > getStartLine ( m_buffer - > cursor ( ) ) , m_buffer - > cursor ( ) ) ) ;
2013-11-20 21:57:00 +01:00
APPL_VERBOSE ( " position= " < < realCursorPosition < < " scrool= " < < m_originScrooled < < " size " < < m_size ) ;
2013-11-23 18:30:52 +01:00
if ( realCursorPosition . x ( ) < m_originScrooled . x ( ) + lineSize * 2.0f ) {
2013-11-20 21:57:00 +01:00
m_originScrooled . setX ( realCursorPosition . x ( ) - lineSize * 2.0f ) ;
2013-11-23 18:30:52 +01:00
} else if ( realCursorPosition . x ( ) > m_originScrooled . x ( ) + ( m_size . x ( ) - m_lastOffsetDisplay ) - lineSize * 2.0f - 10 ) {
m_originScrooled . setX ( realCursorPosition . x ( ) - ( m_size . x ( ) - m_lastOffsetDisplay ) + lineSize * 2.0f + 10 ) ;
2013-11-20 21:57:00 +01:00
}
if ( realCursorPosition . y ( ) < m_originScrooled . y ( ) + lineSize * 2.0f ) {
m_originScrooled . setY ( realCursorPosition . y ( ) - lineSize * 2.0f ) ;
} else if ( realCursorPosition . y ( ) > m_originScrooled . y ( ) + m_size . y ( ) - lineSize * 2.0f ) {
m_originScrooled . setY ( realCursorPosition . y ( ) - m_size . y ( ) + lineSize * 2.0f ) ;
}
2013-11-21 21:22:38 +01:00
m_originScrooled . setMax ( vec2 ( 0 , 0 ) ) ;
2013-11-21 21:56:22 +01:00
// TODO : Limit min position too ...
2013-11-20 21:57:00 +01:00
}
2013-10-20 18:14:22 +02:00
bool appl : : TextViewer : : moveCursor ( const appl : : Buffer : : Iterator & _pos ) {
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2013-10-20 18:14:22 +02:00
return false ;
}
2013-10-22 21:34:13 +02:00
markToRedraw ( ) ;
2014-09-18 22:27:54 +02:00
if ( m_pluginManager - > onCursorMove ( * this , _pos ) = = true ) {
2013-11-20 21:57:00 +01:00
updateScrolling ( ) ;
2013-10-20 18:14:22 +02:00
return true ;
}
2014-10-05 23:46:57 +02:00
m_buffer - > moveCursor ( ( int64_t ) _pos ) ;
2013-11-20 21:57:00 +01:00
updateScrolling ( ) ;
2013-10-20 18:14:22 +02:00
return true ;
}
2013-11-14 21:57:10 +01:00
bool appl : : TextViewer : : write ( const std : : string & _data ) {
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2013-10-20 18:14:22 +02:00
return false ;
}
if ( m_buffer - > hasTextSelected ( ) = = true ) {
return replace ( _data ) ;
}
return write ( _data , m_buffer - > cursor ( ) ) ;
}
2013-11-14 21:57:10 +01:00
bool appl : : TextViewer : : write ( const std : : string & _data , const appl : : Buffer : : Iterator & _pos ) {
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2013-10-20 18:14:22 +02:00
return false ;
}
2013-10-22 21:34:13 +02:00
markToRedraw ( ) ;
2014-09-18 22:27:54 +02:00
if ( m_pluginManager - > onWrite ( * this , _pos , _data ) = = true ) {
2013-10-22 21:34:13 +02:00
// no call of the move cursor, because pluging might call theses function to copy and cut data...
2013-11-27 21:45:56 +01:00
updateScrolling ( ) ;
2013-10-22 21:34:13 +02:00
return true ;
2013-10-20 18:14:22 +02:00
}
2013-10-22 21:34:13 +02:00
bool ret = m_buffer - > write ( _data , _pos ) ;
2014-09-18 22:27:54 +02:00
m_pluginManager - > onCursorMove ( * this , m_buffer - > cursor ( ) ) ;
2013-11-27 21:45:56 +01:00
updateScrolling ( ) ;
2013-10-20 18:14:22 +02:00
return ret ;
}
2013-11-14 21:57:10 +01:00
bool appl : : TextViewer : : replace ( const std : : string & _data , const appl : : Buffer : : Iterator & _pos , const appl : : Buffer : : Iterator & _posEnd ) {
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2013-10-20 18:14:22 +02:00
return false ;
}
2013-10-22 21:34:13 +02:00
markToRedraw ( ) ;
2014-09-18 22:27:54 +02:00
if ( m_pluginManager - > onReplace ( * this , _pos , _data , _posEnd ) = = true ) {
2013-10-22 21:34:13 +02:00
// no call of the move cursor, because pluging might call theses function to copy and cut data...
2013-11-27 21:45:56 +01:00
updateScrolling ( ) ;
2013-10-22 21:34:13 +02:00
return true ;
2013-10-20 18:14:22 +02:00
}
2013-10-22 21:34:13 +02:00
bool ret = m_buffer - > replace ( _data , _pos , _posEnd ) ;
2014-09-18 22:27:54 +02:00
m_pluginManager - > onCursorMove ( * this , m_buffer - > cursor ( ) ) ;
2013-11-27 21:45:56 +01:00
updateScrolling ( ) ;
2013-10-20 18:14:22 +02:00
return ret ;
}
2013-11-14 21:57:10 +01:00
bool appl : : TextViewer : : replace ( const std : : string & _data ) {
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2013-10-20 18:14:22 +02:00
return false ;
}
if ( m_buffer - > hasTextSelected ( ) = = false ) {
return write ( _data ) ;
}
return replace ( _data , m_buffer - > selectStart ( ) , m_buffer - > selectStop ( ) ) ;
}
2014-05-15 21:37:39 +02:00
void appl : : TextViewer : : remove ( ) {
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2013-10-20 18:14:22 +02:00
return ;
}
if ( m_buffer - > hasTextSelected ( ) = = false ) {
// nothing to do ...
return ;
}
2013-10-22 21:34:13 +02:00
markToRedraw ( ) ;
2014-09-18 22:27:54 +02:00
if ( m_pluginManager - > onRemove ( * this , m_buffer - > selectStart ( ) , m_buffer - > selectStop ( ) ) = = true ) {
2013-10-22 21:34:13 +02:00
return ;
2013-10-20 18:14:22 +02:00
}
2013-10-22 21:34:13 +02:00
m_buffer - > removeSelection ( ) ;
2014-09-18 22:27:54 +02:00
m_pluginManager - > onCursorMove ( * this , m_buffer - > cursor ( ) ) ;
2013-10-20 18:14:22 +02:00
}
void appl : : TextViewer : : moveCursorRight ( appl : : TextViewer : : moveMode _mode ) {
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2013-10-20 18:14:22 +02:00
return ;
}
2013-10-22 21:34:13 +02:00
markToRedraw ( ) ;
2013-10-20 18:14:22 +02:00
appl : : Buffer : : Iterator it ;
switch ( _mode ) {
default :
case moveLetter :
it = m_buffer - > cursor ( ) ;
2013-11-23 12:25:42 +01:00
+ + it ;
2013-10-20 18:14:22 +02:00
moveCursor ( it ) ;
break ;
case moveWord :
// TODO : ...
break ;
case moveEnd :
it = m_buffer - > getEndLine ( m_buffer - > cursor ( ) ) ;
moveCursor ( it ) ;
break ;
}
}
void appl : : TextViewer : : moveCursorLeft ( appl : : TextViewer : : moveMode _mode ) {
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2013-10-20 18:14:22 +02:00
return ;
}
2013-10-22 21:34:13 +02:00
markToRedraw ( ) ;
2013-10-20 18:14:22 +02:00
appl : : Buffer : : Iterator it ;
switch ( _mode ) {
default :
case moveLetter :
2013-11-23 12:25:42 +01:00
it = m_buffer - > cursor ( ) ;
2013-10-20 18:14:22 +02:00
- - it ;
moveCursor ( it ) ;
break ;
case moveWord :
// TODO : ...
break ;
case moveEnd :
it = m_buffer - > getStartLine ( m_buffer - > cursor ( ) ) ;
2013-11-21 21:56:22 +01:00
moveCursor ( it ) ;
2013-10-20 18:14:22 +02:00
break ;
}
}
2013-11-22 21:48:05 +01:00
void appl : : TextViewer : : moveCursorUp ( uint32_t _nbLine ) {
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2013-10-20 18:14:22 +02:00
return ;
}
2013-10-22 21:34:13 +02:00
markToRedraw ( ) ;
2013-10-20 18:14:22 +02:00
// find the position of the start of the line.
appl : : Buffer : : Iterator lineStartPos = m_buffer - > getStartLine ( m_buffer - > cursor ( ) ) ;
// check if we can go up ...
if ( lineStartPos = = m_buffer - > begin ( ) ) {
return ;
}
// Decide what column to move to, if there's a preferred column use that
if ( m_buffer - > getFavoriteUpDownPos ( ) < 0 ) {
2013-11-21 21:56:22 +01:00
m_buffer - > setFavoriteUpDownPos ( getScreenSize ( lineStartPos , m_buffer - > cursor ( ) ) ) ;
2013-10-20 18:14:22 +02:00
}
// get the previous line
2013-11-21 21:56:22 +01:00
appl : : Buffer : : Iterator prevLineStartPos = m_buffer - > countBackwardNLines ( lineStartPos - 1 , _nbLine ) ;
2013-10-20 18:14:22 +02:00
//APPL_INFO("Move line UP result : prevLineStartPos=" << prevLineStartPos);
// get the display char position
appl : : Buffer : : Iterator newPos = getPosSize ( prevLineStartPos , m_buffer - > getFavoriteUpDownPos ( ) ) ;
//APPL_INFO("Move to colomn : column=" << column << " newPos=" << newPos);
float posStore = m_buffer - > getFavoriteUpDownPos ( ) ;
moveCursor ( newPos ) ;
m_buffer - > setFavoriteUpDownPos ( posStore ) ;
}
2013-11-22 21:48:05 +01:00
void appl : : TextViewer : : moveCursorDown ( uint32_t _nbLine ) {
2014-06-05 22:01:24 +02:00
if ( m_buffer = = nullptr ) {
2013-10-20 18:14:22 +02:00
return ;
}
2013-10-22 21:34:13 +02:00
markToRedraw ( ) ;
2013-10-20 18:14:22 +02:00
// check if we are not at the end of Buffer
if ( m_buffer - > cursor ( ) = = m_buffer - > end ( ) ) {
return ;
}
// find the position of the start of the line.
appl : : Buffer : : Iterator lineStartPos = m_buffer - > getStartLine ( m_buffer - > cursor ( ) ) ;
if ( m_buffer - > getFavoriteUpDownPos ( ) < 0 ) {
2013-11-21 21:56:22 +01:00
m_buffer - > setFavoriteUpDownPos ( getScreenSize ( lineStartPos , m_buffer - > cursor ( ) ) ) ;
2013-10-20 18:14:22 +02:00
}
// get the next line :
appl : : Buffer : : Iterator nextLineStartPos = m_buffer - > countForwardNLines ( lineStartPos , _nbLine ) ;
//APPL_INFO("Move line DOWN result : nextLineStartPos=" << nextLineStartPos);
// get the display char position
appl : : Buffer : : Iterator newPos = getPosSize ( nextLineStartPos , m_buffer - > getFavoriteUpDownPos ( ) ) ;
//APPL_INFO("Move to colomn : column=" << column << " newPos=" << newPos);
float posStore = m_buffer - > getFavoriteUpDownPos ( ) ;
moveCursor ( newPos ) ;
m_buffer - > setFavoriteUpDownPos ( posStore ) ;
}
// TODO : Rename ...
appl : : Buffer : : Iterator appl : : TextViewer : : getPosSize ( const appl : : Buffer : : Iterator & _startLinePos , float _distance ) {
2013-11-14 21:57:10 +01:00
char32_t currentValue ;
2013-11-22 21:48:05 +01:00
int32_t countColomn = 0 ;
2013-11-14 21:57:10 +01:00
std : : u32string stringToDisplay ;
2013-10-20 18:14:22 +02:00
m_displayText . clear ( ) ;
m_displayText . forceLineReturn ( ) ;
for ( appl : : Buffer : : Iterator it = _startLinePos ;
2014-10-05 23:46:57 +02:00
( bool ) it = = true ;
2013-10-20 18:14:22 +02:00
+ + it ) {
currentValue = * it ;
m_buffer - > expand ( countColomn , currentValue , stringToDisplay ) ;
2013-11-22 21:48:05 +01:00
for ( size_t kkk = 0 ; kkk < stringToDisplay . size ( ) ; + + kkk ) {
2013-12-28 14:23:25 +01:00
if ( stringToDisplay [ kkk ] = = u32char : : Return ) {
2013-10-20 18:14:22 +02:00
return it ;
} else {
2014-01-15 01:15:27 +01:00
m_displayText . printChar ( stringToDisplay [ kkk ] ) ;
2013-10-20 18:14:22 +02:00
}
}
if ( m_displayText . getPos ( ) . x ( ) > = _distance ) {
return it ;
}
countColomn + = stringToDisplay . size ( ) ;
}
return m_buffer - > end ( ) ;
}
// TODO : Rename ...
float appl : : TextViewer : : getScreenSize ( const appl : : Buffer : : Iterator & _startLinePos , const appl : : Buffer : : Iterator & _stopPos ) {
float ret = 0 ;
2013-11-14 21:57:10 +01:00
char32_t currentValue ;
2013-11-22 21:48:05 +01:00
int32_t countColomn = 0 ;
2013-11-14 21:57:10 +01:00
std : : u32string stringToDisplay ;
2013-10-20 18:14:22 +02:00
m_displayText . clear ( ) ;
for ( appl : : Buffer : : Iterator it = _startLinePos ;
2014-10-05 23:46:57 +02:00
( bool ) it = = true & & it < = _stopPos ;
2013-10-20 18:14:22 +02:00
+ + it ) {
currentValue = * it ;
//APPL_DEBUG("parse : " << currentValue);
m_buffer - > expand ( countColomn , currentValue , stringToDisplay ) ;
2013-11-22 21:48:05 +01:00
for ( size_t kkk = 0 ; kkk < stringToDisplay . size ( ) ; + + kkk ) {
2013-12-28 14:23:25 +01:00
if ( stringToDisplay [ kkk ] = = u32char : : Return ) {
2013-10-20 18:14:22 +02:00
return m_displayText . getPos ( ) . x ( ) + 2 ; // TODO : Add the +2 for the end of line ...
} else {
2014-01-15 01:15:27 +01:00
m_displayText . printChar ( stringToDisplay [ kkk ] ) ;
2013-10-20 18:14:22 +02:00
}
}
ret = m_displayText . getPos ( ) . x ( ) ;
countColomn + = stringToDisplay . size ( ) ;
}
return ret ;
}
2013-11-07 21:08:57 +01:00
2014-05-15 21:37:39 +02:00
void appl : : TextViewer : : setCurrentSelect ( ) {
2014-06-05 22:01:24 +02:00
if ( m_viewerManager ! = nullptr ) {
2014-08-07 23:41:48 +02:00
m_viewerManager - > setViewerSelected ( std : : dynamic_pointer_cast < appl : : TextViewer > ( shared_from_this ( ) ) , m_buffer ) ;
2013-11-07 21:08:57 +01:00
}
}
2014-05-15 21:37:39 +02:00
bool appl : : TextViewer : : isSelectedLast ( ) {
2014-06-05 22:01:24 +02:00
if ( m_viewerManager ! = nullptr ) {
2014-08-07 23:41:48 +02:00
return m_viewerManager - > isLastSelected ( std : : dynamic_pointer_cast < appl : : TextViewer > ( shared_from_this ( ) ) ) ;
2013-11-07 21:08:57 +01:00
}
return false ;
}