// XABSearchPanel.cpp - XABSearchPanel widget.
//
// (c) 2012-2015 Xestia Software Development.
//
// This file is part of Xestia Address Book.
//
// Xestia Address Book is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, version 3 of the license.
//
// Xestia Address Book is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with Xestia Address Book. If not, see
#include "XABSearchPanel.h"
DEFINE_EVENT_TYPE(XABSP_ENABLECONTROLS);
DEFINE_EVENT_TYPE(XABSP_DISABLECONTROLS);
BEGIN_EVENT_TABLE(XABSearchPanel, wxPanel)
EVT_COMMAND(wxID_ANY, XABSP_ENABLECONTROLS, XABSearchPanel::EnableControls)
EVT_COMMAND(wxID_ANY, XABSP_DISABLECONTROLS, XABSearchPanel::DisableControls)
END_EVENT_TABLE()
XABSearchPanel::XABSearchPanel( wxWindow* parent )
:
XABSearchPanelADT( parent )
{
// Setup the search panel.
// Setup the images for the add and delete buttons.
wxMemoryInputStream astream(buttons_add_png, sizeof(buttons_add_png));
wxImage buttons_add_png(astream, wxBITMAP_TYPE_PNG);
wxBitmap addbmp(buttons_add_png, -1);
wxMemoryInputStream bstream(buttons_minus_png, sizeof(buttons_minus_png));
wxImage buttons_minus_png(bstream, wxBITMAP_TYPE_PNG);
wxBitmap delbmp(buttons_minus_png, -1);
btnAdd->SetBitmapLabel(addbmp);
btnDelete->SetBitmapLabel(delbmp);
// Insert the options into the combo box.
choOption->Append(_("Forename begins with"));
choOption->Append(_("Forename ends with"));
choOption->Append(_("Forename contains"));
choOption->Append(_("Forename doesn't contain"));
choOption->Append(_("Surname begins with"));
choOption->Append(_("Surname ends with"));
choOption->Append(_("Surname contains"));
choOption->Append(_("Surname doesn't contain"));
choOption->Append(_("Nickname begins with"));
choOption->Append(_("Nickname ends with"));
choOption->Append(_("Nickname contains"));
choOption->Append(_("Nickname doesn't contain"));
choOption->Append(_("Does/Doesn't have photo"));
choOption->Append(_("Does/Doesn't have logo"));
choOption->Append(_("Does/Doesn't have sound"));
chkActive->Hide();
chkActive->SetValue(FALSE);
txtSearch->Show();
szrSSet->Layout();
choOption->SetSelection(0);
}
void XABSearchPanel::UpdateOptions( wxCommandEvent& event )
{
// Update the options in the search panel.
if (choOption->GetSelection() == 12 ||
choOption->GetSelection() == 13 ||
choOption->GetSelection() == 14 ){
chkActive->Show();
txtSearch->Hide();
txtSearch->Clear();
szrSSet->Layout();
} else {
chkActive->Hide();
chkActive->SetValue(FALSE);
txtSearch->Show();
szrSSet->Layout();
}
}
void XABSearchPanel::AddSearchWidget( wxCommandEvent& event )
{
// Add the search panel.
frmSearch *SCHWin = static_cast(SCHWinPtr);
wxCommandEvent eventsend(SE_ADDSEARCHSETTING);
wxPostEvent(SCHWin, eventsend);
}
void XABSearchPanel::RemoveSearchWidget( wxCommandEvent& event )
{
// Remove the search panel.
frmSearch *SCHWin = static_cast(SCHWinPtr);
wxCommandEvent eventsend(SE_REMOVESEARCHSETTING);
eventsend.SetInt(this->GetInteger());
wxPostEvent(SCHWin, eventsend);
}
void XABSearchPanel::EnableButtons(bool AddButton, bool DeleteButton)
{
// Enable the buttons for the search panel.
if (AddButton == TRUE){
btnAdd->Enable();
} else {
btnAdd->Disable();
}
if (DeleteButton == TRUE){
btnDelete->Enable();
} else {
btnDelete->Disable();
}
}
void XABSearchPanel::SetupPointers(void* SCHWinPtrInc){
// Setup the pointers for the search panel.
SCHWinPtr = SCHWinPtrInc;
}
void XABSearchPanel::SetupInteger(int IntInc){
// Set the ID of the search panel.
SCHInt = IntInc;
}
int XABSearchPanel::GetInteger(){
// Get the ID of the search panel.
return SCHInt;
}
void XABSearchPanel::DisableControls(wxCommandEvent &event){
// Disable the search controls.
choOption->Disable();
chkActive->Disable();
txtSearch->Disable();
btnAdd->Disable();
btnDelete->Disable();
}
void XABSearchPanel::EnableControls(wxCommandEvent &event){
// Enable the search controls.
choOption->Enable();
chkActive->Enable();
txtSearch->Enable();
btnAdd->Enable();
btnDelete->Enable();
}
int XABSearchPanel::GetSelectionOption(){
// Get the selection option.
return choOption->GetSelection();
}
bool XABSearchPanel::GetCheckboxSetting(){
// Get the checkbox setting.
return chkActive->IsChecked();
}
wxString XABSearchPanel::GetStringSetting(){
// Get the search string setting.
return txtSearch->GetValue();
}