/[eliot]/eliot/wxwin/searchpanel.cc
ViewVC logotype

Diff of /eliot/wxwin/searchpanel.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by ipkiss, Sun Oct 23 14:53:44 2005 UTC revision 1.10.2.1 by afrab, Sun Oct 23 17:10:47 2005 UTC
# Line 1  Line 1 
1  /* Eliot                                                                     */  /* Eliot                                                                     */
2  /* Copyright (C) 1999  Antoine Fraboulet                                     */  /* Copyright (C) 1999  Antoine Fraboulet                                     */
 /* Antoine.Fraboulet@free.fr                                                 */  
3  /*                                                                           */  /*                                                                           */
4  /* This program is free software; you can redistribute it and/or modify      */  /* This file is part of Eliot.                                               */
5    /*                                                                           */
6    /* Eliot is free software; you can redistribute it and/or modify             */
7  /* it under the terms of the GNU General Public License as published by      */  /* it under the terms of the GNU General Public License as published by      */
8  /* the Free Software Foundation; either version 2 of the License, or         */  /* the Free Software Foundation; either version 2 of the License, or         */
9  /* (at your option) any later version.                                       */  /* (at your option) any later version.                                       */
10  /*                                                                           */  /*                                                                           */
11  /* This program is distributed in the hope that it will be useful,           */  /* Eliot is distributed in the hope that it will be useful,                  */
12  /* but WITHOUT ANY WARRANTY; without even the implied warranty of            */  /* but WITHOUT ANY WARRANTY; without even the implied warranty of            */
13  /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             */  /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             */
14  /* GNU General Public License for more details.                              */  /* GNU General Public License for more details.                              */
# Line 19  Line 20 
20  /* $Id$ */  /* $Id$ */
21    
22  #include <string.h>  #include <string.h>
23  #include "wx/panel.h"  #include "wx/wx.h"
 #include "wx/textctrl.h"  
 #include "wx/listbox.h"  
 #include "wx/sizer.h"  
 #include "wx/intl.h"  
24    
25  #include "ewx.h"  #include "ewx.h"
26  #include "dic.h"  #include "dic.h"
# Line 39  enum { Line 36  enum {
36    ID_PANEL_REGEXP,    ID_PANEL_REGEXP,
37    
38    ID_LIST,    ID_LIST,
39    ID_TEXT    ID_TEXT,
40      ID_OPTION1,
41      ID_OPTION2,
42      ID_OPTION3
43  };  };
44    
45  // ************************************************************  // ************************************************************
# Line 49  enum { Line 49  enum {
49  class SimpleSearchPanel : public wxPanel  class SimpleSearchPanel : public wxPanel
50  {  {
51  protected:  protected:
52    ConfigDB config;      ConfigDB config;
53    Dictionary dic_;      Dictionary dic;
54    wxTextCtrl* t;      wxTextCtrl* t;
55    wxListBox* l;      wxListBox*  l;
56    int check();      wxBoxSizer *sizer;
57    
58        int  check_dic();
59        void check_end();
60        void panel_build();
61        virtual void panel_options() = 0;
62  public:  public:
63    SimpleSearchPanel(wxWindow* parent, int id, Dictionary dic);    SimpleSearchPanel(wxWindow* parent, int id, Dictionary d) : wxPanel(parent,id) { dic = d; };
64    virtual void compute_char(wxCommandEvent&) {};    virtual void compute_char(wxCommandEvent&) {};
65    virtual void compute_enter(wxCommandEvent&) {};    virtual void compute_enter(wxCommandEvent&) {};
66    DECLARE_EVENT_TABLE()    DECLARE_EVENT_TABLE()
67  };  };
68    
69  BEGIN_EVENT_TABLE(SimpleSearchPanel, wxPanel)  BEGIN_EVENT_TABLE(SimpleSearchPanel, wxPanel)
70    EVT_TEXT      (ID_TEXT, SimpleSearchPanel::compute_char)    EVT_TEXT      (ID_TEXT   , SimpleSearchPanel::compute_char)
71    EVT_TEXT_ENTER(ID_TEXT, SimpleSearchPanel::compute_enter)    EVT_TEXT_ENTER(ID_TEXT   , SimpleSearchPanel::compute_enter)
72      EVT_TEXT_ENTER(ID_OPTION1, SimpleSearchPanel::compute_enter)
73      EVT_TEXT_ENTER(ID_OPTION2, SimpleSearchPanel::compute_enter)
74      EVT_TEXT_ENTER(ID_OPTION3, SimpleSearchPanel::compute_enter)
75  END_EVENT_TABLE()  END_EVENT_TABLE()
76    
77  SimpleSearchPanel::SimpleSearchPanel(wxWindow* parent, int id, Dictionary dic)  void SimpleSearchPanel::panel_build()
   : wxPanel(parent,id)  
78  {  {
   dic_ = dic;  
   
79    t = new wxTextCtrl(this,ID_TEXT,wxT(""),wxPoint(0,0),wxSize(-1,-1),wxTE_PROCESS_ENTER);    t = new wxTextCtrl(this,ID_TEXT,wxT(""),wxPoint(0,0),wxSize(-1,-1),wxTE_PROCESS_ENTER);
80    t->SetFont(config.getFont(LISTFONT));    t->SetFont(config.getFont(LISTFONT));
81    l = new wxListBox(this,ID_LIST);    l = new wxListBox(this,ID_LIST);
82    l->SetFont(config.getFont(LISTFONT));    l->SetFont(config.getFont(LISTFONT));
83    l->Show(TRUE);    l->Show(TRUE);
84    
85    wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );    sizer = new wxBoxSizer( wxVERTICAL );
86    sizer->Add(t, 0, wxEXPAND | wxALL, 0);    sizer->Add(t, 0, wxEXPAND | wxALL, 0);
87      panel_options();
88    sizer->Add(l, 1, wxEXPAND | wxALL, 0);    sizer->Add(l, 1, wxEXPAND | wxALL, 0);
89    
90    SetAutoLayout(TRUE);    SetAutoLayout(TRUE);
# Line 88  SimpleSearchPanel::SimpleSearchPanel(wxW Line 94  SimpleSearchPanel::SimpleSearchPanel(wxW
94  }  }
95    
96  int  int
97  SimpleSearchPanel::check()  SimpleSearchPanel::check_dic()
98  {  {
99    wxString msg = wxT("");    wxString msg = wxT("");
100    if (dic_ == NULL)    if (dic == NULL)
101      {      {
102        l->Clear();        l->Clear();
103        msg << wxT("Pas de dictionnaire");        msg << wxT("Pas de dictionnaire");
# Line 101  SimpleSearchPanel::check() Line 107  SimpleSearchPanel::check()
107    return 1;    return 1;
108  }  }
109    
110    void
111    SimpleSearchPanel::check_end()
112    {
113      if (l->GetCount() == 0)
114        {
115          l->Append(wxT("Aucun resultat"));
116        }
117    }
118    
119  // ************************************************************  // ************************************************************
120  // ************************************************************  // ************************************************************
# Line 108  SimpleSearchPanel::check() Line 122  SimpleSearchPanel::check()
122    
123  class PCross : public SimpleSearchPanel  class PCross : public SimpleSearchPanel
124  {  {
125  private:  protected:
126      virtual void panel_options() {};
127  public:  public:
128    void compute_char(wxCommandEvent&) { };    void compute_char(wxCommandEvent&) { };
129    void compute_enter(wxCommandEvent&);    void compute_enter(wxCommandEvent&);
130    PCross(wxWindow* parent, int id, Dictionary dic) : SimpleSearchPanel(parent,id,dic) {};    PCross(wxWindow* parent, int id, Dictionary dic) : SimpleSearchPanel(parent,id,dic) { panel_build(); };
131  };  };
132    
133  void  void
# Line 122  PCross::compute_enter(wxCommandEvent&) Line 137  PCross::compute_enter(wxCommandEvent&)
137    char rack[DIC_WORD_MAX];    char rack[DIC_WORD_MAX];
138    char buff[RES_CROS_MAX][DIC_WORD_MAX];    char buff[RES_CROS_MAX][DIC_WORD_MAX];
139    
140    if (!check())    if (!check_dic())
141      return;      return;
142    
143    if (t->GetValue().Len() >= DIC_WORD_MAX)    if (t->GetValue().Len() >= DIC_WORD_MAX)
144      {      {
145        wxString msg = wxT("");        wxString msg = wxT("");
146        msg << wxT("La recherche est limitée à ") << DIC_WORD_MAX - 1 << wxT(" lettres");        msg << wxT("La recherche est limitee a ") << DIC_WORD_MAX - 1 << wxT(" lettres");
147        l->Append(msg);        l->Append(msg);
148        return;        return;
149      }      }
150    
151    strncpy(rack, t->GetValue().mb_str(), DIC_WORD_MAX);    strncpy(rack, t->GetValue().mb_str(), DIC_WORD_MAX);
152    Dic_search_Cros(dic_,rack,buff);    Dic_search_Cros(dic,rack,buff);
153    
154    int resnum = 0;    int resnum = 0;
155    wxString res[RES_CROS_MAX];    wxString res[RES_CROS_MAX];
156    for(i=0; i < RES_CROS_MAX && buff[i][0]; i++)    for(i=0; i < RES_CROS_MAX && buff[i][0]; i++)
157      res[resnum++] =  wxU(buff[i]);      res[resnum++] =  wxU(buff[i]);
158    l->Set(resnum,res);    l->Set(resnum,res);
159      check_end();
   if (l->GetCount() == 0)  
     l->Append(wxT("Aucun résultat"));  
160  }  }
161    
162  // ************************************************************  // ************************************************************
# Line 152  PCross::compute_enter(wxCommandEvent&) Line 165  PCross::compute_enter(wxCommandEvent&)
165    
166  class PPlus1 : public SimpleSearchPanel  class PPlus1 : public SimpleSearchPanel
167  {  {
168  private:  protected:
169      virtual void panel_options() {};
170  public:  public:
171    void compute_char(wxCommandEvent&) { };    void compute_char(wxCommandEvent&) { };
172    void compute_enter(wxCommandEvent&);    void compute_enter(wxCommandEvent&);
173    PPlus1(wxWindow* parent, int id, Dictionary dic) : SimpleSearchPanel(parent,id,dic) {};    PPlus1(wxWindow* parent, int id, Dictionary dic) : SimpleSearchPanel(parent,id,dic) { panel_build(); };
174  };  };
175    
176  void  void
# Line 166  PPlus1::compute_enter(wxCommandEvent&) Line 180  PPlus1::compute_enter(wxCommandEvent&)
180    char rack[DIC_WORD_MAX];    char rack[DIC_WORD_MAX];
181    char buff[DIC_LETTERS][RES_7PL1_MAX][DIC_WORD_MAX];    char buff[DIC_LETTERS][RES_7PL1_MAX][DIC_WORD_MAX];
182    
183    if (!check())    if (!check_dic())
184      return;      return;
185    
186    if (t->GetValue().Len() >= DIC_WORD_MAX)    if (t->GetValue().Len() >= DIC_WORD_MAX)
187      {      {
188        wxString msg = wxT("");        wxString msg = wxT("");
189        msg << wxT("La recherche est limitée à ") << DIC_WORD_MAX - 1 << wxT(" lettres");        msg << wxT("La recherche est limitee a ") << DIC_WORD_MAX - 1 << wxT(" lettres");
190        l->Append(msg);        l->Append(msg);
191        return;        return;
192      }      }
193    
194    strncpy(rack, t->GetValue().mb_str(), DIC_WORD_MAX);    strncpy(rack, t->GetValue().mb_str(), DIC_WORD_MAX);
195    Dic_search_7pl1(dic_,rack,buff,TRUE);    Dic_search_7pl1(dic,rack,buff,TRUE);
196    
197    int resnum = 0;    int resnum = 0;
198    wxString res[DIC_LETTERS*(RES_7PL1_MAX+1)];    wxString res[DIC_LETTERS*(RES_7PL1_MAX+1)];
# Line 190  PPlus1::compute_enter(wxCommandEvent&) Line 204  PPlus1::compute_enter(wxCommandEvent&)
204            res[resnum++] = wxString(wxT("  ")) + wxU(buff[i][j]);            res[resnum++] = wxString(wxT("  ")) + wxU(buff[i][j]);
205      }      }
206    l->Set(resnum,res);    l->Set(resnum,res);
207      check_end();
   if (l->GetCount() == 0)  
     l->Append(wxT("Aucun résultat"));  
208  }  }
209    
210  // ************************************************************  // ************************************************************
# Line 201  PPlus1::compute_enter(wxCommandEvent&) Line 213  PPlus1::compute_enter(wxCommandEvent&)
213    
214  class PRegExp : public SimpleSearchPanel  class PRegExp : public SimpleSearchPanel
215  {  {
216  private:  protected:
217      wxTextCtrl* omin;
218      wxTextCtrl* omax;
219    struct search_RegE_list_t llist;    struct search_RegE_list_t llist;
220    void build_letter_lists();    virtual void build_letter_lists();
221      virtual void panel_options();
222  public:  public:
223    void compute_char(wxCommandEvent&) { };    void compute_char(wxCommandEvent&) { };
224    void compute_enter(wxCommandEvent&);    void compute_enter(wxCommandEvent&);
225    PRegExp(wxWindow* parent, int id, Dictionary dic) : SimpleSearchPanel(parent,id,dic) {};    PRegExp(wxWindow* parent, int id, Dictionary dic) : SimpleSearchPanel(parent,id,dic) { panel_build(); };
226  };  };
227    
228  void  void
229  PRegExp::build_letter_lists()  PRegExp::build_letter_lists()
230  {  {
231    int i;    int i;
232    list<Tile> all_tiles;    std::list<Tile> all_tiles;
233    
234    memset (&llist,0,sizeof(llist));    memset (&llist,0,sizeof(llist));
235    
236      llist.minlength = 1;
237      llist.maxlength = 15;
238    
239    llist.symbl[0] = RE_ALL_MATCH;    llist.symbl[0] = RE_ALL_MATCH;
240    llist.symbl[1] = RE_VOWL_MATCH;    llist.symbl[1] = RE_VOWL_MATCH;
241    llist.symbl[2] = RE_CONS_MATCH;    llist.symbl[2] = RE_CONS_MATCH;
# Line 235  PRegExp::build_letter_lists() Line 253  PRegExp::build_letter_lists()
253        memset(llist.letters[i],0,sizeof(llist.letters[i]));        memset(llist.letters[i],0,sizeof(llist.letters[i]));
254      }      }
255    
256    const list<Tile>& allTiles = Tile::getAllTiles();    const std::list<Tile>& allTiles = Tile::getAllTiles();
257    list<Tile>::const_iterator it;    std::list<Tile>::const_iterator it;
258    for (it = allTiles.begin(); it != allTiles.end(); it++)    for (it = allTiles.begin(); it != allTiles.end(); it++)
259      {      {
260        if (! it->isJoker() && ! it->isEmpty())        if (! it->isJoker() && ! it->isEmpty())
# Line 257  PRegExp::build_letter_lists() Line 275  PRegExp::build_letter_lists()
275      }      }
276  }  }
277    
278    
279    void
280    PRegExp::panel_options()
281    {
282      wxStaticText *otmin;
283      wxStaticText *otmax;
284    
285      otmin = new wxStaticText(this,wxID_ANY,wxT("Longueur min."));
286      omin  = new wxTextCtrl(this,ID_OPTION1,wxT( "1"),wxDefaultPosition,wxDefaultSize,wxTE_PROCESS_ENTER);
287      otmax = new wxStaticText(this,wxID_ANY,wxT("max."));
288      omax  = new wxTextCtrl(this,ID_OPTION2,wxT("15"),wxDefaultPosition,wxDefaultSize,wxTE_PROCESS_ENTER);
289    
290      wxBoxSizer *s = new wxBoxSizer( wxHORIZONTAL );
291      s->Add(otmin, 0, wxALIGN_CENTRE_VERTICAL | wxLEFT | wxRIGHT, 4);
292      s->Add(omin , 1, wxALIGN_CENTRE_VERTICAL, 0);
293      s->Add(otmax, 0, wxALIGN_CENTRE_VERTICAL | wxLEFT | wxRIGHT, 4);
294      s->Add(omax , 1, wxALIGN_CENTRE_VERTICAL, 0);
295      sizer->Add(s, 0, wxEXPAND | wxALL, 1);
296    }
297    
298    
299    #define DIC_RE_MAX (3*DIC_WORD_MAX) // yes, it's 3
300    
301  void  void
302  PRegExp::compute_enter(wxCommandEvent&)  PRegExp::compute_enter(wxCommandEvent&)
303  {  {
304    int  i;    char re[DIC_RE_MAX];
   char re[DIC_WORD_MAX];  
305    char buff[RES_REGE_MAX][DIC_WORD_MAX];    char buff[RES_REGE_MAX][DIC_WORD_MAX];
306    
307    if (!check())    if (!check_dic())
308      return;      return;
309    
310    build_letter_lists();    build_letter_lists();
311    strncpy(re, t->GetValue().mb_str(),DIC_WORD_MAX);    strncpy(re, t->GetValue().mb_str(),DIC_RE_MAX);
312    Dic_search_RegE(dic_,re,buff,&llist);    debug("PRegExp::compute_enter for %s",re);
313    
314      int lmin = atoi((const char*)omin->GetValue().mb_str());
315      int lmax = atoi((const char*)omax->GetValue().mb_str());
316      if (lmax <= (DIC_WORD_MAX - 1) && lmin >= 1 && lmin <= lmax)
317        {
318          llist.minlength = lmin;
319          llist.maxlength = lmax;
320          debug(" length %d,%d",lmin,lmax);
321        }
322      else
323        {
324          debug(" bad length -%s,%s-",
325                (const char*)omin->GetValue().mb_str(),
326                (const char*)omax->GetValue().mb_str());
327        }
328      debug("\n");
329    
330      Dic_search_RegE(dic,re,buff,&llist);
331    
332    int resnum = 0;    int resnum = 0;
333    wxString res[RES_REGE_MAX];    wxString res[RES_REGE_MAX];
334    for(i=0; i < RES_REGE_MAX && buff[i][0]; i++)    for(int i=0; i < RES_REGE_MAX && buff[i][0]; i++)
335      res[resnum++] =  wxU(buff[i]);      res[resnum++] =  wxU(buff[i]);
336    
337    l->Set(resnum,res);    l->Set(resnum,res);
338      check_end();
   if (l->GetCount() == 0)  
     l->Append(wxT("Aucun résultat"));  
339  }  }
340    
341  // ************************************************************  // ************************************************************
# Line 289  PRegExp::compute_enter(wxCommandEvent&) Line 345  PRegExp::compute_enter(wxCommandEvent&)
345  SearchPanel::SearchPanel(wxFrame *parent, Dictionary dic) :  SearchPanel::SearchPanel(wxFrame *parent, Dictionary dic) :
346    wxNotebook(parent, -1)    wxNotebook(parent, -1)
347  {  {
348    AddPage(new PCross(this,ID_PANEL_CROSS,dic),wxT("Mots croisés"));    AddPage(new PCross (this,ID_PANEL_CROSS ,dic),wxT("Mots croises"));
349    AddPage(new PPlus1(this,ID_PANEL_PLUS1,dic),wxT("Plus 1"));    AddPage(new PPlus1 (this,ID_PANEL_PLUS1 ,dic),wxT("Plus 1"));
350    AddPage(new PRegExp(this,ID_PANEL_REGEXP,dic),wxT("Exp. Rationnelle"));    AddPage(new PRegExp(this,ID_PANEL_REGEXP,dic),wxT("Exp. Rationnelle"));
351    SetSelection(0);    SetSelection(2);
352  }  }
353    
354  SearchPanel::~SearchPanel()  SearchPanel::~SearchPanel()
355  {  {
356  }  }
357    
358    // ************************************************************
359    // ************************************************************
360    // ************************************************************
361    
362    
363    /// Local Variables:
364    /// mode: hs-minor
365    /// c-basic-offset: 4
366    /// End:

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.10.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26