2004-04-08 11:43:06 +02:00
|
|
|
|
/* Eliot */
|
|
|
|
|
/* Copyright (C) 1999 Antoine Fraboulet */
|
|
|
|
|
/* Antoine.Fraboulet@free.fr */
|
|
|
|
|
/* */
|
|
|
|
|
/* This program 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; either version 2 of the License, or */
|
|
|
|
|
/* (at your option) any later version. */
|
|
|
|
|
/* */
|
|
|
|
|
/* This program 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 this program; if not, write to the Free Software */
|
|
|
|
|
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
2005-04-19 21:59:03 +02:00
|
|
|
|
/* $Id: searchpanel.cc,v 1.8 2005/04/19 19:59:03 afrab Exp $ */
|
2004-04-08 11:43:06 +02:00
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "wx/panel.h"
|
|
|
|
|
#include "wx/textctrl.h"
|
|
|
|
|
#include "wx/listbox.h"
|
|
|
|
|
#include "wx/sizer.h"
|
|
|
|
|
#include "wx/intl.h"
|
|
|
|
|
|
2005-01-01 16:42:55 +01:00
|
|
|
|
#include "ewx.h"
|
|
|
|
|
#include "dic.h"
|
|
|
|
|
#include "dic_search.h"
|
2005-04-19 18:21:15 +02:00
|
|
|
|
#include "regexp.h"
|
2005-01-01 16:42:55 +01:00
|
|
|
|
#include "searchpanel.h"
|
2005-04-19 18:21:15 +02:00
|
|
|
|
#include "tile.h"
|
2005-01-01 16:42:55 +01:00
|
|
|
|
#include "configdb.h"
|
|
|
|
|
|
2004-04-08 11:43:06 +02:00
|
|
|
|
enum {
|
|
|
|
|
ID_PANEL_CROSS,
|
|
|
|
|
ID_PANEL_PLUS1,
|
|
|
|
|
ID_PANEL_REGEXP,
|
|
|
|
|
|
|
|
|
|
ID_LIST,
|
|
|
|
|
ID_TEXT
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ************************************************************
|
|
|
|
|
// ************************************************************
|
|
|
|
|
// ************************************************************
|
|
|
|
|
|
|
|
|
|
class SimpleSearchPanel : public wxPanel
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
ConfigDB config;
|
|
|
|
|
Dictionary dic_;
|
|
|
|
|
wxTextCtrl* t;
|
|
|
|
|
wxListBox* l;
|
|
|
|
|
int check();
|
|
|
|
|
public:
|
|
|
|
|
SimpleSearchPanel(wxWindow* parent, int id, Dictionary dic);
|
|
|
|
|
virtual void compute_char(wxCommandEvent&) {};
|
|
|
|
|
virtual void compute_enter(wxCommandEvent&) {};
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(SimpleSearchPanel, wxPanel)
|
|
|
|
|
EVT_TEXT (ID_TEXT, SimpleSearchPanel::compute_char)
|
|
|
|
|
EVT_TEXT_ENTER(ID_TEXT, SimpleSearchPanel::compute_enter)
|
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
2005-01-01 16:42:55 +01:00
|
|
|
|
SimpleSearchPanel::SimpleSearchPanel(wxWindow* parent, int id, Dictionary dic)
|
2004-04-08 11:43:06 +02:00
|
|
|
|
: wxPanel(parent,id)
|
|
|
|
|
{
|
|
|
|
|
dic_ = dic;
|
|
|
|
|
|
2005-01-01 16:42:55 +01:00
|
|
|
|
t = new wxTextCtrl(this,ID_TEXT,wxT(""),wxPoint(0,0),wxSize(-1,-1),wxTE_PROCESS_ENTER);
|
2004-04-08 11:43:06 +02:00
|
|
|
|
t->SetFont(config.getFont(LISTFONT));
|
|
|
|
|
l = new wxListBox(this,ID_LIST);
|
|
|
|
|
l->SetFont(config.getFont(LISTFONT));
|
|
|
|
|
l->Show(TRUE);
|
|
|
|
|
|
|
|
|
|
wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
sizer->Add(t, 0, wxEXPAND | wxALL, 0);
|
|
|
|
|
sizer->Add(l, 1, wxEXPAND | wxALL, 0);
|
|
|
|
|
|
|
|
|
|
SetAutoLayout(TRUE);
|
|
|
|
|
SetSizer(sizer);
|
|
|
|
|
sizer->Fit(this);
|
|
|
|
|
sizer->SetSizeHints(this);
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-01 16:42:55 +01:00
|
|
|
|
int
|
2004-04-08 11:43:06 +02:00
|
|
|
|
SimpleSearchPanel::check()
|
|
|
|
|
{
|
2005-01-01 16:42:55 +01:00
|
|
|
|
wxString msg = wxT("");
|
2004-04-08 11:43:06 +02:00
|
|
|
|
if (dic_ == NULL)
|
|
|
|
|
{
|
|
|
|
|
l->Clear();
|
2005-01-01 16:42:55 +01:00
|
|
|
|
msg << wxT("Pas de dictionnaire");
|
2004-04-08 11:43:06 +02:00
|
|
|
|
l->Append(msg);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************
|
|
|
|
|
// ************************************************************
|
|
|
|
|
// ************************************************************
|
|
|
|
|
|
|
|
|
|
class PCross : public SimpleSearchPanel
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
public:
|
|
|
|
|
void compute_char(wxCommandEvent&) { };
|
|
|
|
|
void compute_enter(wxCommandEvent&);
|
|
|
|
|
PCross(wxWindow* parent, int id, Dictionary dic) : SimpleSearchPanel(parent,id,dic) {};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PCross::compute_enter(wxCommandEvent&)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
char rack[DIC_WORD_MAX];
|
|
|
|
|
char buff[RES_CROS_MAX][DIC_WORD_MAX];
|
|
|
|
|
|
|
|
|
|
if (!check())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (t->GetValue().Len() >= DIC_WORD_MAX)
|
|
|
|
|
{
|
2005-01-01 16:42:55 +01:00
|
|
|
|
wxString msg = wxT("");
|
|
|
|
|
msg << wxT("La recherche est limit<69>e <20> ") << DIC_WORD_MAX - 1 << wxT(" lettres");
|
2004-04-08 11:43:06 +02:00
|
|
|
|
l->Append(msg);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
|
strncpy(rack, t->GetValue().mb_str(), DIC_WORD_MAX);
|
2004-04-08 11:43:06 +02:00
|
|
|
|
Dic_search_Cros(dic_,rack,buff);
|
|
|
|
|
|
|
|
|
|
int resnum = 0;
|
|
|
|
|
wxString res[RES_CROS_MAX];
|
|
|
|
|
for(i=0; i < RES_CROS_MAX && buff[i][0]; i++)
|
2005-01-01 16:42:55 +01:00
|
|
|
|
res[resnum++] = wxU(buff[i]);
|
2004-04-08 11:43:06 +02:00
|
|
|
|
l->Set(resnum,res);
|
|
|
|
|
|
2004-06-22 23:04:07 +02:00
|
|
|
|
if (l->GetCount() == 0)
|
2005-01-01 16:42:55 +01:00
|
|
|
|
l->Append(wxT("Aucun r<>sultat"));
|
2004-04-08 11:43:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ************************************************************
|
|
|
|
|
// ************************************************************
|
|
|
|
|
// ************************************************************
|
|
|
|
|
|
|
|
|
|
class PPlus1 : public SimpleSearchPanel
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
public:
|
|
|
|
|
void compute_char(wxCommandEvent&) { };
|
|
|
|
|
void compute_enter(wxCommandEvent&);
|
|
|
|
|
PPlus1(wxWindow* parent, int id, Dictionary dic) : SimpleSearchPanel(parent,id,dic) {};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
PPlus1::compute_enter(wxCommandEvent&)
|
|
|
|
|
{
|
|
|
|
|
int i,j;
|
|
|
|
|
char rack[DIC_WORD_MAX];
|
2005-04-09 21:16:56 +02:00
|
|
|
|
char buff[DIC_LETTERS][RES_7PL1_MAX][DIC_WORD_MAX];
|
2004-04-08 11:43:06 +02:00
|
|
|
|
|
|
|
|
|
if (!check())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (t->GetValue().Len() >= DIC_WORD_MAX)
|
|
|
|
|
{
|
2005-01-01 16:42:55 +01:00
|
|
|
|
wxString msg = wxT("");
|
|
|
|
|
msg << wxT("La recherche est limit<69>e <20> ") << DIC_WORD_MAX - 1 << wxT(" lettres");
|
2004-04-08 11:43:06 +02:00
|
|
|
|
l->Append(msg);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
|
strncpy(rack, t->GetValue().mb_str(), DIC_WORD_MAX);
|
2004-04-08 11:43:06 +02:00
|
|
|
|
Dic_search_7pl1(dic_,rack,buff,TRUE);
|
|
|
|
|
|
|
|
|
|
int resnum = 0;
|
2005-04-09 21:16:56 +02:00
|
|
|
|
wxString res[DIC_LETTERS*(RES_7PL1_MAX+1)];
|
|
|
|
|
for(i=0; i < DIC_LETTERS; i++)
|
2004-04-08 11:43:06 +02:00
|
|
|
|
{
|
|
|
|
|
if (i && buff[i][0][0])
|
2005-01-01 16:42:55 +01:00
|
|
|
|
res[resnum++] = wxString(wxT("+")) + (wxChar)(i+'A'-1);
|
2004-04-08 11:43:06 +02:00
|
|
|
|
for(j=0; j < RES_7PL1_MAX && buff[i][j][0]; j++)
|
2005-01-01 16:42:55 +01:00
|
|
|
|
res[resnum++] = wxString(wxT(" ")) + wxU(buff[i][j]);
|
2004-04-08 11:43:06 +02:00
|
|
|
|
}
|
|
|
|
|
l->Set(resnum,res);
|
|
|
|
|
|
2004-06-22 23:04:07 +02:00
|
|
|
|
if (l->GetCount() == 0)
|
2005-01-01 16:42:55 +01:00
|
|
|
|
l->Append(wxT("Aucun r<>sultat"));
|
2004-04-08 11:43:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ************************************************************
|
|
|
|
|
// ************************************************************
|
|
|
|
|
// ************************************************************
|
|
|
|
|
|
2004-06-19 20:43:35 +02:00
|
|
|
|
class PRegExp : public SimpleSearchPanel
|
|
|
|
|
{
|
|
|
|
|
private:
|
2005-04-19 18:21:15 +02:00
|
|
|
|
struct search_RegE_list_t llist;
|
|
|
|
|
void build_letter_lists();
|
2004-06-19 20:43:35 +02:00
|
|
|
|
public:
|
|
|
|
|
void compute_char(wxCommandEvent&) { };
|
|
|
|
|
void compute_enter(wxCommandEvent&);
|
|
|
|
|
PRegExp(wxWindow* parent, int id, Dictionary dic) : SimpleSearchPanel(parent,id,dic) {};
|
|
|
|
|
};
|
|
|
|
|
|
2005-04-19 18:21:15 +02:00
|
|
|
|
void
|
|
|
|
|
PRegExp::build_letter_lists()
|
|
|
|
|
{
|
2005-04-19 21:59:03 +02:00
|
|
|
|
int i;
|
2005-04-19 18:21:15 +02:00
|
|
|
|
list<Tile> all_tiles;
|
|
|
|
|
|
|
|
|
|
llist.symbl[0] = RE_ALL_MATCH;
|
|
|
|
|
llist.symbl[1] = RE_VOWL_MATCH;
|
|
|
|
|
llist.symbl[2] = RE_CONS_MATCH;
|
|
|
|
|
llist.symbl[3] = RE_USR1_MATCH;
|
|
|
|
|
llist.symbl[5] = RE_USR2_MATCH;
|
|
|
|
|
|
|
|
|
|
llist.valid[0] = 1; // all letters
|
|
|
|
|
llist.valid[1] = 1; // vowels
|
|
|
|
|
llist.valid[2] = 1; // consonants
|
|
|
|
|
llist.valid[3] = 0; // user defined list 1
|
|
|
|
|
llist.valid[4] = 0; // user defined list 2
|
|
|
|
|
|
2005-04-19 21:59:03 +02:00
|
|
|
|
for(i=0; i < DIC_SEARCH_REGE_LIST; i++)
|
|
|
|
|
{
|
|
|
|
|
memset(llist.letters[i],0,sizeof(llist.letters[i]));
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-19 18:21:15 +02:00
|
|
|
|
const list<Tile>& allTiles = Tile::getAllTiles();
|
|
|
|
|
list<Tile>::const_iterator it;
|
|
|
|
|
for (it = allTiles.begin(); it != allTiles.end(); it++)
|
|
|
|
|
{
|
|
|
|
|
if (! it->isJoker() && ! it->isEmpty())
|
|
|
|
|
{
|
|
|
|
|
llist.letters[0][it->toCode()] = 1;
|
|
|
|
|
|
|
|
|
|
if (it->isVowel())
|
|
|
|
|
{
|
|
|
|
|
llist.letters[1][it->toCode()] = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (it->isConsonant())
|
|
|
|
|
{
|
|
|
|
|
llist.letters[2][it->toCode()] = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-19 20:43:35 +02:00
|
|
|
|
void
|
|
|
|
|
PRegExp::compute_enter(wxCommandEvent&)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
char re[DIC_WORD_MAX];
|
|
|
|
|
char buff[RES_REGE_MAX][DIC_WORD_MAX];
|
|
|
|
|
|
|
|
|
|
if (!check())
|
|
|
|
|
return;
|
|
|
|
|
|
2005-04-19 18:21:15 +02:00
|
|
|
|
build_letter_lists();
|
2005-01-01 16:42:55 +01:00
|
|
|
|
strncpy(re, t->GetValue().mb_str(),DIC_WORD_MAX);
|
2005-04-19 18:21:15 +02:00
|
|
|
|
Dic_search_RegE(dic_,re,buff,&llist);
|
2004-06-19 20:43:35 +02:00
|
|
|
|
|
|
|
|
|
int resnum = 0;
|
|
|
|
|
wxString res[RES_REGE_MAX];
|
|
|
|
|
for(i=0; i < RES_REGE_MAX && buff[i][0]; i++)
|
2005-01-01 16:42:55 +01:00
|
|
|
|
res[resnum++] = wxU(buff[i]);
|
2005-04-19 18:21:15 +02:00
|
|
|
|
|
2004-06-19 20:43:35 +02:00
|
|
|
|
l->Set(resnum,res);
|
|
|
|
|
|
2004-06-22 23:04:07 +02:00
|
|
|
|
if (l->GetCount() == 0)
|
2005-01-01 16:42:55 +01:00
|
|
|
|
l->Append(wxT("Aucun r<>sultat"));
|
2004-06-19 20:43:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ************************************************************
|
|
|
|
|
// ************************************************************
|
|
|
|
|
// ************************************************************
|
|
|
|
|
|
2004-04-08 11:43:06 +02:00
|
|
|
|
SearchPanel::SearchPanel(wxFrame *parent, Dictionary dic) :
|
|
|
|
|
wxNotebook(parent, -1)
|
|
|
|
|
{
|
2005-01-01 16:42:55 +01:00
|
|
|
|
AddPage(new PCross(this,ID_PANEL_CROSS,dic),wxT("Mots crois<69>s"));
|
|
|
|
|
AddPage(new PPlus1(this,ID_PANEL_PLUS1,dic),wxT("Plus 1"));
|
|
|
|
|
AddPage(new PRegExp(this,ID_PANEL_REGEXP,dic),wxT("Exp. Rationnelle"));
|
|
|
|
|
SetSelection(0);
|
2004-04-08 11:43:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SearchPanel::~SearchPanel()
|
|
|
|
|
{
|
|
|
|
|
}
|