/** ******************************************************************************* * @file Search.cpp * @brief Editeur De N'ours : Search system * @author Edouard DUPIN * @date 03/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. * ******************************************************************************* */ #include "appl/global.h" #include "Search.h" #include "SearchData.h" #include "BufferManager.h" #include "MainWindows.h" #include "appl/globalMsg.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #undef __class__ #define __class__ "Search" extern const char * const TYPE_EOBJECT_APPL_SEARCH = __class__; const char* const l_eventSearchEntry = "appl-search-entry"; const char* const l_eventReplaceEntry = "appl-replace-entry"; const char* const l_eventSearchBt = "appl-search-button"; const char* const l_eventReplaceBt = "appl-replace-button"; const char* const l_eventCaseCb = "appl-case-sensitive-CheckBox"; const char* const l_eventWrapCb = "appl-wrap-CheckBox"; const char* const l_eventForwardCb = "appl-forward-CheckBox"; const char* const l_eventHideBt = "appl-hide-button"; Search::Search(void) { m_forward = false; ewol::Entry * myEntry = NULL; ewol::Button * myButton = NULL; ewol::CheckBox * mycheckbox = NULL; myEntry = new ewol::Entry(); myEntry->RegisterOnEvent(this, ewolEventEntryModify, l_eventSearchEntry); myEntry->SetExpendX(true); myEntry->SetFillX(true); SubWidgetAdd(myEntry); myEntry = new ewol::Entry(); myEntry->RegisterOnEvent(this, ewolEventEntryModify, l_eventReplaceEntry); myEntry->SetExpendX(true); myEntry->SetFillX(true); SubWidgetAdd(myEntry); myButton = new ewol::Button("Search"); myButton->RegisterOnEvent(this, ewolEventButtonPressed, l_eventSearchBt); SubWidgetAdd(myButton); myButton = new ewol::Button("Replace"); myButton->RegisterOnEvent(this, ewolEventButtonPressed, l_eventReplaceBt); SubWidgetAdd(myButton); mycheckbox = new ewol::CheckBox("Aa"); mycheckbox->RegisterOnEvent(this, ewolEventCheckBoxClicked, l_eventCaseCb); SubWidgetAdd(mycheckbox); mycheckbox = new ewol::CheckBox("Wrap"); mycheckbox->RegisterOnEvent(this, ewolEventCheckBoxClicked, l_eventWrapCb); SubWidgetAdd(mycheckbox); mycheckbox = new ewol::CheckBox("Forward"); mycheckbox->RegisterOnEvent(this, ewolEventCheckBoxClicked, l_eventForwardCb); SubWidgetAdd(mycheckbox); myButton = new ewol::Button("Hide"); myButton->RegisterOnEvent(this, ewolEventButtonPressed, l_eventHideBt); SubWidgetAdd(myButton); RegisterMultiCast(ednMsgGuiSearch); RegisterMultiCast(ednMsgGuiReplace); } Search::~Search(void) { } /** * @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 Search::CheckObjectType(const char * const objectType) { if (NULL == objectType) { APPL_ERROR("check error : \"" << TYPE_EOBJECT_APPL_SEARCH << "\" != NULL(pointer) "); return false; } if (objectType == TYPE_EOBJECT_APPL_SEARCH) { return true; } else { if(true == ewol::SizerHori::CheckObjectType(objectType)) { return true; } APPL_ERROR("check error : \"" << TYPE_EOBJECT_APPL_SEARCH << "\" != \"" << 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 Search::GetObjectType(void) { return TYPE_EOBJECT_APPL_SEARCH; } /** * @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 Search::OnReceiveMessage(ewol::EObject * CallerObject, const char * eventId, etk::UString data) { ewol::SizerHori::OnReceiveMessage(CallerObject, eventId, data); //APPL_INFO("Search receive message : \"" << eventId << "\" data=\"" << data << "\""); if ( eventId == l_eventSearchEntry) { SearchData::SetSearch(data); } else if ( eventId == l_eventReplaceEntry) { SearchData::SetReplace(data); } else if ( eventId == l_eventSearchBt) { if (true==m_forward) { SendMultiCast(ednMsgGuiFind, "Previous"); } else { SendMultiCast(ednMsgGuiFind, "Next"); } } else if ( eventId == l_eventReplaceBt) { SendMultiCast(ednMsgGuiReplace, "Normal"); if (true==m_forward) { SendMultiCast(ednMsgGuiFind, "Previous"); } else { SendMultiCast(ednMsgGuiFind, "Next"); } } else if ( eventId == l_eventCaseCb) { if (data == "true") { SearchData::SetCase(true); } else { SearchData::SetCase(false); } } else if ( eventId == l_eventWrapCb) { if (data == "true") { SearchData::SetWrap(true); } else { SearchData::SetWrap(false); } } else if ( eventId == l_eventForwardCb) { if (data == "true") { m_forward = true; } else { m_forward = false; } } else if ( eventId == l_eventHideBt) { } } /* void Search::OnButtonPrevious(GtkWidget *widget, gpointer data) { //APPL_INFO("CALLBACK"); GeneralSendMessage(APPL_MSG__CURRENT_FIND_PREVIOUS); } void Search::OnButtonNext(GtkWidget *widget, gpointer data) { //APPL_INFO("CALLBACK"); GeneralSendMessage(APPL_MSG__CURRENT_FIND_NEXT); } void Search::OnButtonReplace(GtkWidget *widget, gpointer data) { //APPL_INFO("CALLBACK"); GeneralSendMessage(APPL_MSG__CURRENT_REPLACE); } void Search::OnButtonReplaceAndNext(GtkWidget *widget, gpointer data) { //APPL_INFO("CALLBACK"); GeneralSendMessage(APPL_MSG__CURRENT_REPLACE); GeneralSendMessage(APPL_MSG__CURRENT_FIND_NEXT); } void Search::OnButtonQuit(GtkWidget *widget, gpointer data) { //APPL_INFO("CALLBACK"); Search * self = static_cast(data); self->Destroy(); } void Search::OnCheckBoxEventWrap(GtkWidget *widget, gpointer data) { //APPL_INFO("CALLBACK"); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { SearchData::SetWrap(true); } else { SearchData::SetWrap(false); } } void Search::OnCheckBoxEventCase(GtkWidget *widget, gpointer data) { //APPL_INFO("CALLBACK"); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { SearchData::SetCase(true); } else { SearchData::SetCase(false); } } void Search::OnCheckBoxEventRegExp(GtkWidget *widget, gpointer data) { //APPL_INFO("CALLBACK"); Search * self = static_cast(data); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { SearchData::SetRegExp(true); gtk_widget_set_sensitive(self->m_CkMatchCase, false); } else { SearchData::SetRegExp(false); gtk_widget_set_sensitive(self->m_CkMatchCase, true); } } void Search::OnEntrySearchChange(GtkWidget *widget, gpointer data) { //APPL_INFO("CALLBACK"); Search * self = static_cast(data); // update research data const char *testData = gtk_entry_get_text(GTK_ENTRY(widget)); if (NULL != testData) { etk::UString myDataString = testData; SearchData::SetSearch(myDataString); if (0 == strlen(testData)) { self->m_haveSearchData = false; } else { self->m_haveSearchData = true; } gtk_widget_set_sensitive(self->m_BtPrevious, self->m_haveSearchData); gtk_widget_set_sensitive(self->m_BtNext, self->m_haveSearchData); if (false == self->m_haveSearchData) { gtk_widget_set_sensitive(self->m_BtReplace, false); gtk_widget_set_sensitive(self->m_BtReplaceAndNext, false); } else { gtk_widget_set_sensitive(self->m_BtReplace, true); gtk_widget_set_sensitive(self->m_BtReplaceAndNext, true); } } } void Search::OnEntryReplaceChange(GtkWidget *widget, gpointer data) { //APPL_INFO("CALLBACK"); Search * self = static_cast(data); // update replace data const char *testData = gtk_entry_get_text(GTK_ENTRY(widget)); if (NULL != testData) { etk::UString myDataString = testData; SearchData::SetReplace(myDataString); if (0 == strlen(testData)) { self->m_haveReplaceData = false; } else { self->m_haveReplaceData = true; } if (false == self->m_haveSearchData) { gtk_widget_set_sensitive(self->m_BtReplace, false); gtk_widget_set_sensitive(self->m_BtReplaceAndNext, false); } else { gtk_widget_set_sensitive(self->m_BtReplace, true); gtk_widget_set_sensitive(self->m_BtReplaceAndNext, true); } } } */