edn/jni/appl/Gui/BufferView.cpp

204 lines
5.5 KiB
C++
Raw Normal View History

/**
*******************************************************************************
* @file BufferViewer.cpp
* @brief Editeur De N'ours : main textViewer diplayer
* @author Edouard DUPIN
* @date 04/12/2010
* @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-04-23 10:15:43 +02:00
#include <appl/Debug.h>
2012-04-24 09:42:14 +02:00
#include <appl/global.h>
#include <BufferView.h>
#include <BufferManager.h>
#include <ColorizeManager.h>
#include <MainWindows.h>
2012-02-28 18:22:49 +01:00
#include <ewol/EObject.h>
#undef __class__
#define __class__ "BufferView"
extern const char * const TYPE_EOBJECT_EDN_BUFFER_VIEW = "BufferView";
BufferView::BufferView(void)
{
SetCanHaveFocus(true);
2012-02-29 18:06:08 +01:00
RegisterMultiCast(ednMsgBufferListChange);
RegisterMultiCast(ednMsgBufferState);
RegisterMultiCast(ednMsgBufferId);
m_selectedID = -1;
m_selectedIdRequested = -1;
}
BufferView::~BufferView(void)
{
}
2012-02-29 18:06:08 +01:00
/**
* @brief Check if the object has the specific type.
* @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it
* @param[in] objectType type of the object we want to check
* @return true if the object is compatible, otherwise false
*/
bool BufferView::CheckObjectType(const char * const objectType)
{
if (NULL == objectType) {
EWOL_ERROR("check error : \"" << TYPE_EOBJECT_EDN_BUFFER_VIEW << "\" != NULL(pointer) ");
return false;
}
if (objectType == TYPE_EOBJECT_EDN_BUFFER_VIEW) {
return true;
} else {
if(true == ewol::List::CheckObjectType(objectType)) {
return true;
}
EWOL_ERROR("check error : \"" << TYPE_EOBJECT_EDN_BUFFER_VIEW << "\" != \"" << objectType << "\"");
return false;
}
}
/**
* @brief Get the current Object type of the EObject
* @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it
* @param[in] objectType type description
* @return true if the object is compatible, otherwise false
*/
const char * const BufferView::GetObjectType(void)
{
return TYPE_EOBJECT_EDN_BUFFER_VIEW;
}
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 BufferView::OnReceiveMessage(ewol::EObject * CallerObject, const char * eventId, etk::UString data)
{
2012-02-29 18:06:08 +01:00
ewol::List::OnReceiveMessage(CallerObject, eventId, data);
if (eventId == ednMsgBufferListChange) {
MarkToReedraw();
2012-02-29 18:06:08 +01:00
}else if (eventId == ednMsgBufferId) {
m_selectedIdRequested = BufferManager::GetSelected();
MarkToReedraw();
2012-02-29 18:06:08 +01:00
}else if (eventId == ednMsgBufferState) {
MarkToReedraw();
}
}
color_ts BufferView::GetBasicBG(void)
{
2012-02-19 22:33:43 +01:00
return ColorizeManager::Get(COLOR_LIST_BG_1);
}
uint32_t BufferView::GetNuberOfColomn(void)
{
return 1;
}
2012-02-15 16:23:20 +01:00
bool BufferView::GetTitle(int32_t colomn, etk::UString &myTitle, color_ts &fg, color_ts &bg)
{
myTitle = "Buffers : ";
return true;
}
uint32_t BufferView::GetNuberOfRaw(void)
{
return BufferManager::SizeOpen();
}
2012-02-15 16:23:20 +01:00
bool BufferView::GetElement(int32_t colomn, int32_t raw, etk::UString &myTextToWrite, color_ts &fg, color_ts &bg)
{
etk::File name;
bool isModify;
basicColor_te selectFG = COLOR_LIST_TEXT_NORMAL;
basicColor_te selectBG = COLOR_LIST_BG_1;
// when requested a new display selection ==> reset the previous one ...
if (m_selectedIdRequested != -1) {
m_selectedID = -1;
}
// transforme the ID in the real value ...
int32_t realID = BufferManager::WitchBuffer(raw+1);
if (BufferManager::Exist(realID)) {
isModify = BufferManager::Get(realID)->IsModify();
name = BufferManager::Get(realID)->GetFileName();
#if 0
char *tmpModify = (char*)" ";
if (true == isModify) {
tmpModify = (char*)"M";
}
myTextToWrite = "[";
myTextToWrite += realID;
myTextToWrite += "](";
myTextToWrite += tmpModify;
myTextToWrite += ") ";
#else
myTextToWrite = "";
#endif
2012-02-15 16:23:20 +01:00
myTextToWrite += name.GetShortFilename();
if (true == isModify) {
selectFG = COLOR_LIST_TEXT_MODIFY;
} else {
selectFG = COLOR_LIST_TEXT_NORMAL;
}
if (raw%2==0) {
selectBG = COLOR_LIST_BG_1;
} else {
selectBG = COLOR_LIST_BG_2;
}
// the buffer change of selection ...
if (m_selectedIdRequested == realID) {
m_selectedID = raw;
// stop searching
m_selectedIdRequested = -1;
}
if (m_selectedID == raw) {
selectBG = COLOR_LIST_BG_SELECTED;
}
} else {
myTextToWrite = "ERROR";
}
2012-02-19 22:33:43 +01:00
fg = ColorizeManager::Get(selectFG);
bg = ColorizeManager::Get(selectBG);
return true;
}
bool BufferView::OnItemEvent(int32_t IdInput, ewol::eventInputType_te typeEvent, int32_t colomn, int32_t raw, etkFloat_t x, etkFloat_t y)
{
2012-02-19 15:48:08 +01:00
if (1 == IdInput && typeEvent == ewol::EVENT_INPUT_TYPE_SINGLE) {
2012-04-23 10:15:43 +02:00
APPL_INFO("Event on List : IdInput=" << IdInput << " colomn=" << colomn << " raw=" << raw );
int32_t selectBuf = BufferManager::WitchBuffer(raw+1);
if ( 0 <= selectBuf) {
m_selectedID = raw;
2012-02-29 18:06:08 +01:00
SendMultiCast(ednMsgBufferId, selectBuf);
}
}
MarkToReedraw();
return false;
}