auxframes.cc

Go to the documentation of this file.
00001 /* Eliot                                                                     */
00002 /* Copyright (C) 1999  Antoine Fraboulet                                     */
00003 /*                                                                           */
00004 /* This file is part of Eliot.                                               */
00005 /*                                                                           */
00006 /* Eliot is free software; you can redistribute it and/or modify             */
00007 /* it under the terms of the GNU General Public License as published by      */
00008 /* the Free Software Foundation; either version 2 of the License, or         */
00009 /* (at your option) any later version.                                       */
00010 /*                                                                           */
00011 /* Eliot is distributed in the hope that it will be useful,                  */
00012 /* but WITHOUT ANY WARRANTY; without even the implied warranty of            */
00013 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             */
00014 /* GNU General Public License for more details.                              */
00015 /*                                                                           */
00016 /* You should have received a copy of the GNU General Public License         */
00017 /* along with this program; if not, write to the Free Software               */
00018 /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00019 
00020 /**
00021  *  \file   auxframes.cc
00022  *  \brief  Window Frames used in Eliot
00023  *  \author Antoine Fraboulet
00024  *  \date   2005
00025  */
00026 
00027 #include <iostream>
00028 #include <sstream>
00029 
00030 #include "wx/sizer.h"
00031 #include "wx/button.h"
00032 #include "wx/intl.h"
00033 
00034 #include "wx/clipbrd.h"
00035 #include "wx/dataobj.h"
00036 
00037 #include "ewx.h"
00038 
00039 #include "dic.h"
00040 #include "dic_search.h"
00041 #include "training.h"
00042 #include "player.h"
00043 #include "game.h"
00044 
00045 #include "configdb.h"
00046 #include "auxframes.h"
00047 #include "mainframe.h"
00048 #include "searchpanel.h"
00049 
00050 /****************************************************************/
00051 /* AUXFRAME */
00052 /****************************************************************/
00053 
00054 AuxFrame::AuxFrame(wxFrame* parent, int _id, wxString _name, wxString _classname):
00055     wxFrame(parent, -1, wxU("Eliot: ") + _name, wxPoint(-1, -1), wxSize(-1, -1),
00056             wxRESIZE_BORDER | wxCAPTION | wxFRAME_FLOAT_ON_PARENT, _classname)
00057 {
00058   frameid   = (frames_id_t)_id;
00059   name      = _name;
00060   classname = _classname;
00061   show      = config.getFrameShow(classname);
00062 }
00063 
00064 AuxFrame::~AuxFrame()
00065 {
00066     wxPoint p = GetPosition();
00067     wxSize  s = GetClientSize();
00068     config.setFramePos(classname, p);
00069     config.setFrameSize(classname, s);
00070     config.setFrameShow(classname, show);
00071 }
00072 
00073 void
00074 AuxFrame::SwitchDisplay()
00075 {
00076     if (show == 0)
00077     {
00078         Show(TRUE);
00079         Raise();
00080         show = 1;
00081         Reload();
00082     }
00083     else
00084     {
00085         Show(FALSE);
00086         show = 0;
00087     }
00088 }
00089 
00090 void
00091 AuxFrame::Reload()
00092 {
00093 #define MINW 50
00094 #define MINH 50
00095 
00096     wxSize size;
00097     //debug("  %s::Reload() - %s\n",(const char*)classname.mb_str(),(const char*)name.mb_str());
00098 
00099     Move(config.getFramePos(classname));
00100     size = config.getFrameSize(classname);
00101 
00102     if (size.GetWidth() < MINW)
00103         size.SetWidth(MINW);
00104     if (size.GetHeight() < MINH)
00105         size.SetHeight(MINH);
00106 
00107     SetClientSize(size);
00108     Refresh();
00109     if (show)
00110     {
00111         Show(FALSE);
00112         Show(TRUE);
00113     }
00114 }
00115 
00116 /****************************************************************/
00117 /* BOARD FRAME */
00118 /****************************************************************/
00119 
00120 BoardFrame::BoardFrame(wxFrame* parent, Game& iGame):
00121     AuxFrame(parent, ID_Frame_Board, wxT("Grille"), FRAMEBOARD)
00122 {
00123     board = new GfxBoard(this, iGame);
00124     wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
00125     sizer->Add(board, 1, wxEXPAND, 0);
00126     SetAutoLayout(TRUE);
00127     SetSizer(sizer);
00128     sizer->Fit(this);
00129     sizer->SetSizeHints(this);
00130 }
00131 
00132 void
00133 BoardFrame::Refresh(refresh_t force)
00134 {
00135     //debug("    BoardFrame::Refresh\n");
00136     if (force == REFRESH)
00137         board->Refresh(GfxBoard::BOARD_REFRESH);
00138     else
00139         board->Refresh(GfxBoard::BOARD_FORCE_REFRESH);
00140 }
00141 
00142 /****************************************************************/
00143 /* BAG FRAME */
00144 /****************************************************************/
00145 
00146 BagFrame::BagFrame(wxFrame* parent, Game& iGame):
00147     AuxFrame(parent, ID_Frame_Bag, wxT("sac"), FRAMEBAG),
00148     m_game(iGame)
00149 {
00150     tiles = new wxListCtrl(this, -1);
00151     tiles->SetSingleStyle(wxLC_LIST);
00152     //tiles->SetColumnWidth(0, wxLIST_AUTOSIZE);
00153     //tiles->SetFont(config.getFont(LISTFONT));
00154     //tiles->SetToolTip(wxT("Lettre, nombre restant"));
00155 
00156 #ifdef DEBUG
00157     wxFont font(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
00158                 wxFONTWEIGHT_NORMAL, false, wxString(wxT("Courier New")), wxFONTENCODING_SYSTEM);
00159     tiles->SetFont(font);
00160 #endif
00161 
00162     wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
00163     sizer->Add(tiles, 1, wxEXPAND | wxALL, 1);
00164     SetAutoLayout(TRUE);
00165     SetSizer(sizer);
00166     sizer->Fit(this);
00167 }
00168 
00169 void
00170 BagFrame::Refresh(refresh_t force)
00171 { 
00172     //debug("    BagFrame::Refresh\n");
00173     int n,index;
00174     wxString buf;
00175 #ifdef DEBUG
00176     wxChar format[] = wxT("%c:%2d[%2d]");
00177 #else
00178     wxChar format[] = wxT("%c:%2d");
00179 #endif
00180 
00181     tiles->ClearAll();
00182 
00183     std::list<Tile>::const_iterator it;
00184     const std::list<Tile>& allTiles = Tile::getAllTiles();
00185     for (index = 0, it = allTiles.begin(); it != allTiles.end(); index++, it++)
00186     {
00187         n = m_game.getBag().in(*it);
00188 #ifdef DEBUG
00189         buf.Printf(format, it->toChar(), n, n - it->maxNumber());
00190 #else
00191         buf.Printf(format, it->toChar(), n);
00192 #endif
00193         tiles->InsertItem(index,buf);
00194     }
00195 }
00196 
00197 /****************************************************************/
00198 /* RECHERCHE */
00199 /****************************************************************/
00200 
00201 SearchFrame::SearchFrame(wxFrame *parent, Dictionary _dic):
00202     AuxFrame(parent, ID_Frame_Search, wxT("recherche"), FRAMESEARCH)
00203 {
00204     panel = new SearchPanel(this, _dic);
00205     wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
00206     sizer->Add(panel, 1, wxEXPAND, 0);
00207     SetAutoLayout(TRUE);
00208     SetSizer(sizer);
00209     sizer->Fit(this);
00210 }
00211 
00212 void
00213 SearchFrame::Refresh(refresh_t force)
00214 {
00215     //debug("    SearchFrame::Refresh\n");
00216 }
00217 
00218 /****************************************************************/
00219 /* VERIF FRAME */
00220 /****************************************************************/
00221 
00222 enum
00223 {
00224     Word_Id,
00225     Result_Id,
00226 };
00227 
00228 BEGIN_EVENT_TABLE(VerifFrame, AuxFrame)
00229   EVT_TEXT(Word_Id, VerifFrame::OnText)
00230 END_EVENT_TABLE()
00231 
00232 VerifFrame::VerifFrame(wxFrame* parent, Dictionary _dic):
00233 // XXX:  AuxFrame(parent, ID_Frame_Verif, wxT("vérification"), FRAMEVERIF)
00234   AuxFrame(parent, ID_Frame_Verif, wxT("verification"), FRAMEVERIF)
00235 {
00236     dic = _dic;
00237     word = new wxTextCtrl(this, Word_Id, wxT(""));
00238     word->SetFont(config.getFont(LISTFONT));
00239 // XXX:    word->SetToolTip(wxT("Mot ŕ vérifier"));
00240     word->SetToolTip(wxT("Mot a verifier"));
00241     result = new wxStaticText(this, Result_Id, wxT(""));
00242     result->SetFont(config.getFont(LISTFONT));
00243     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00244     sizer->Add(word, 1, wxEXPAND | wxALL, 1);
00245     sizer->Add(result, 1, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, 1);
00246 
00247     SetAutoLayout(TRUE);
00248     SetSizer(sizer);
00249     sizer->Fit(this);
00250     sizer->SetSizeHints(this);
00251 }
00252 
00253 void
00254 VerifFrame::verif()
00255 {
00256     if (dic == NULL)
00257     {
00258         result->SetLabel(wxT("pas de dictionnaire"));
00259         return;
00260     }
00261     if (Dic_search_word(dic, word->GetValue().mb_str()))
00262         result->SetLabel(wxT("existe"));
00263     else
00264         result->SetLabel(wxT("n'existe pas"));
00265 }
00266 
00267 void
00268 VerifFrame::OnText(wxCommandEvent&)
00269 {
00270     verif();
00271 }
00272 
00273 void
00274 VerifFrame::Refresh(refresh_t force)
00275 {
00276     //debug("    VerifFrame::Refresh\n");
00277 }
00278 
00279 /****************************************************************/
00280 /* AUXFRAMELIST */
00281 /****************************************************************/
00282 
00283 enum {
00284   ListBoxID,
00285   ButtonCopyID
00286 };
00287 
00288 BEGIN_EVENT_TABLE(AuxFrameList, AuxFrame)
00289   EVT_BUTTON        (ButtonCopyID , AuxFrameList::OnCopy)
00290 END_EVENT_TABLE()
00291 
00292 AuxFrameList::AuxFrameList(wxFrame* parent, int _id, wxString _name, wxString _classname, Game *g):
00293   AuxFrame(parent, _id, _name, _classname)
00294 
00295 {
00296     game = g;
00297     savedword = "";
00298 
00299     wxBoxSizer *sizer_v = new wxBoxSizer(wxVERTICAL);
00300     listbox = new wxListBox(this, ListBoxID);
00301     listbox->SetFont(config.getFont(LISTFONT));
00302     listbox->SetToolTip(name);
00303     sizer_v->Add(listbox, 1, wxEXPAND | wxALL, 1);
00304 
00305     button = new wxButton(this, ButtonCopyID, wxT("Copier"), wxPoint(0, 0), wxSize(-1, -1));
00306     sizer_v->Add(button, 0, wxEXPAND | wxALL, 1);
00307 
00308     wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
00309     sizer->Add(sizer_v, 1, wxEXPAND, 0);
00310 
00311     SetAutoLayout(TRUE);
00312     SetSizer(sizer);
00313     sizer->Fit(this);
00314     sizer->SetSizeHints(this);
00315 }
00316 
00317 void
00318 AuxFrameList::OnCopy(wxCommandEvent& event)
00319 {
00320     wxString textdata;
00321 
00322     if (wxTheClipboard->Open())
00323     {
00324         textdata = wxT("");
00325         for (int i = 0; i < listbox->GetCount(); i++)
00326         {
00327             textdata << listbox->GetString(i) << wxT("\n");
00328         }
00329         wxTextDataObject* ptr = new wxTextDataObject(textdata);
00330         wxTheClipboard->AddData(ptr);
00331         wxTheClipboard->Close();
00332     }
00333 }
00334 
00335 void
00336 AuxFrameList::Waiting()
00337 {
00338     listbox->Clear();
00339     listbox->Show(TRUE);
00340 }
00341 
00342 void
00343 AuxFrameList::Refresh(refresh_t force)
00344 {
00345     //debug("    %s : Refresh start\n",(const char*)name.mb_str());
00346     if (game == NULL)
00347         {
00348             listbox->Clear();
00349             listbox->Append(wxT("Pas de partie en cours"));
00350             //debug("  %s : Refresh end - no game\n",(const char*)name.mb_str());
00351             return;
00352         }
00353     if (game->getDic() == NULL)
00354         {
00355             listbox->Clear();
00356             listbox->Append(wxT("Pas de dictionnaire"));
00357             //debug("  %s : Refresh end - no dictionnary\n",(const char*)name.mb_str());
00358             return;
00359         }
00360     if (show == 0)
00361         {
00362             //debug("  %s : Refresh end - no window\n",(const char*)name.mb_str());
00363             return;
00364         }
00365     noresult = true;
00366     refresh();
00367     if (noresult == true)
00368         {
00369             //debug("      %s : noresult == true\n",(const char*)name.mb_str());
00370             listbox->Clear();
00371             listbox->Append(wxT("Aucun resultat"));
00372         }
00373     //debug("  %s : Refresh end\n",(const char*)name.mb_str());
00374 }
00375 
00376 /****************************************************************/
00377 /* PLUS1 FRAME */
00378 /****************************************************************/
00379 
00380 void
00381 Plus1Frame::refresh()
00382 {
00383     std::string rack;
00384     //debug("      Plus1Frame::refresh start\n");
00385     rack = game->getCurrentPlayer().getCurrentRack().toString();
00386     //debug("         CurrentPlayer -> rack : %s\n",rack.c_str());
00387 
00388     if (savedword == rack)
00389         {
00390             noresult = false; // keep old results
00391             //debug("      Plus1Frame::refresh end, no change\n");
00392             return;
00393         }
00394     savedword = rack;
00395 
00396     char buff[DIC_LETTERS][RES_7PL1_MAX][DIC_WORD_MAX];
00397     Dic_search_7pl1(game->getDic(), rack.c_str(), buff, config.getJokerPlus1());
00398 
00399     listbox->Clear();
00400     wxString res[DIC_LETTERS*(RES_7PL1_MAX+1)];
00401     int resnum = 0;
00402     res[resnum++] = wxString(wxT("Tirage: ")) + wxString(wxU(rack.c_str()));
00403     for (int i = 0; i < DIC_LETTERS; i++)
00404     {
00405         if (i && buff[i][0][0])
00406             {
00407                 res[resnum++] = wxString(wxT("+")) + (wxChar)(i + 'A' - 1);
00408                 noresult = false;
00409             }
00410         for (int j = 0; j < RES_7PL1_MAX && buff[i][j][0]; j++)
00411             {
00412                 res[resnum++] = wxString(wxT("  ")) + wxU(buff[i][j]);
00413                 noresult = false;
00414             }
00415     }
00416     listbox->Set(resnum, res);
00417     //debug("      Plus1Frame::refresh end\n");
00418 }
00419 
00420 /****************************************************************/
00421 /*  BENJAMINS */
00422 /****************************************************************/
00423 
00424 void
00425 BenjFrame::refresh()
00426 {
00427     std::string word;
00428 
00429     if (game->getMode() != Game::kTRAINING)
00430         return;
00431 
00432     word = ((Training*)game)->getTestPlayWord();
00433     if (savedword == word)
00434         {
00435             noresult = false; // keep old results
00436             return;
00437         }
00438     savedword = word;
00439     //debug("   BenjFrame::refresh : %s\n",word.c_str());
00440     char wordlist[RES_BENJ_MAX][DIC_WORD_MAX];
00441     Dic_search_Benj(game->getDic(), word.c_str(), wordlist);
00442 
00443     wxString res[RES_BENJ_MAX];
00444     int resnum = 0;
00445     for (int i = 0; (i < RES_BENJ_MAX) && (wordlist[i][0]); i++)
00446         {
00447             res[resnum++] = wxU(wordlist[i]);
00448             //debug("      BenjFrame : %s (%d)\n",wordlist[i],resnum);
00449             noresult = false;
00450         }
00451     listbox->Set(resnum, res);
00452 }
00453 
00454 
00455 /****************************************************************/
00456 /* RACC FRAME */
00457 /****************************************************************/
00458 
00459 void
00460 RaccFrame::refresh()
00461 {
00462     std::string word;
00463 
00464     if (game->getMode() != Game::kTRAINING)
00465         return;
00466 
00467     word = ((Training*)game)->getTestPlayWord();
00468     if (savedword == word)
00469         {
00470             noresult = false; // keep old results
00471             return;
00472         }
00473     savedword = word;
00474     //debug("   RaccFrame::refresh : %s\n",word.c_str());
00475     char wordlist[RES_RACC_MAX][DIC_WORD_MAX];
00476     Dic_search_Racc(game->getDic(), word.c_str(), wordlist);
00477 
00478     wxString res[RES_RACC_MAX];
00479     int resnum = 0;
00480     for (int i = 0; (i < RES_RACC_MAX) && (wordlist[i][0]); i++)
00481         {
00482             res[resnum++] = wxU(wordlist[i]);
00483             //debug("      RaccFrame : %s (%d)\n",wordlist[i],resnum);
00484             noresult = false;
00485         }
00486     listbox->Set(resnum, res);
00487 }
00488 
00489 /****************************************************************/
00490 /* AUXFRAMETEXT */
00491 /****************************************************************/
00492 
00493 AuxFrameText::AuxFrameText(wxFrame* parent, int _id, wxString _name, wxString _classname, int _style):
00494   AuxFrame(parent, _id, _name, _classname)
00495 
00496 {
00497     wxBoxSizer *sizer_v = new wxBoxSizer(wxVERTICAL);
00498     wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
00499 
00500     wxFont font(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
00501                 wxFONTWEIGHT_NORMAL, false, wxString(wxT("Courier New")), wxFONTENCODING_SYSTEM);
00502 
00503     textbox = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, _style);
00504     textbox->SetFont(font);
00505 
00506     sizer_v->Add(textbox, 1, wxEXPAND | wxALL, 1);
00507     sizer->Add(sizer_v, 1, wxEXPAND, 0);
00508 
00509     SetAutoLayout(TRUE);
00510     SetSizer(sizer);
00511     sizer->Fit(this);
00512     sizer->SetSizeHints(this);
00513 }
00514 
00515 /****************************************************************/
00516 /* GAME FRAME */
00517 /****************************************************************/
00518 
00519 GameFrame::GameFrame(wxFrame* parent, Game& iGame):
00520     AuxFrameText(parent, ID_Frame_Game, wxT("partie"), FRAMEGAME, wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP),
00521     m_game(iGame)
00522 {
00523     textbox->Clear();
00524     textbox->AppendText(wxT(""));
00525 }
00526 
00527 void
00528 GameFrame::Refresh(refresh_t force)
00529 {
00530     std::ostringstream mos;
00531     m_game.save(mos);
00532 #ifdef DEBUG
00533     mos << std::string(30,'-') << std::endl;
00534     mos << "Player History\n";
00535     mos << m_game.getPlayer(0).toString();
00536     mos << std::string(30,'-') << std::endl;
00537     mos << "Game History\n";
00538     mos << m_game.getHistory().toString();
00539 #endif
00540     textbox->Clear();
00541     textbox->AppendText( wxU( mos.str().c_str() ) );
00542 }
00543 
00544 /****************************************************************/
00545 /* RESULT FRAME */
00546 /****************************************************************/
00547 
00548 BEGIN_EVENT_TABLE(ResultFrame, AuxFrame)
00549 END_EVENT_TABLE()
00550 
00551 ResultFrame::ResultFrame(wxFrame* parent, Game* iGame):
00552     AuxFrame(parent, ID_Frame_Result, wxT("recherche"), FRAMERESULT)
00553 {
00554     reslist = new GfxResult(this, (MainFrame*)parent, iGame);
00555 
00556     wxBoxSizer *sizer_v = new wxBoxSizer(wxVERTICAL);
00557     wxBoxSizer *sizer   = new wxBoxSizer(wxHORIZONTAL);
00558 
00559     sizer_v->Add(reslist, 1, wxEXPAND, 0);
00560     sizer->Add  (sizer_v, 1, wxEXPAND | wxALL, 2);
00561 
00562     SetAutoLayout(TRUE);
00563     SetSizer(sizer);
00564     sizer->Fit(this);
00565     sizer->SetSizeHints(this);
00566     //debug("ResultFrame created\n");
00567 }
00568 
00569 void
00570 ResultFrame::Refresh(refresh_t WXUNUSED(force))
00571 {
00572     if (reslist != NULL)
00573         {
00574             reslist->Show(false);
00575             //debug("ResultFrame refresh\n");
00576             reslist->Refresh();
00577             reslist->Show(true);
00578         }
00579 }
00580 
00581 void
00582 ResultFrame::Search()
00583 {
00584     if (reslist != NULL)
00585         {
00586             reslist->Search();
00587         }
00588 }
00589 
00590 int
00591 ResultFrame::GetSelected()
00592 {
00593     if (reslist != NULL)
00594         {
00595             return reslist->GetSelected();
00596         }
00597     return -1;
00598 }
00599 
00600 void
00601 ResultFrame::OnSize(wxSizeEvent& e)
00602 {
00603     int w,h;
00604     GetClientSize(&w,&h);
00605     //debug("ResultFrame::OnSize (%d,%d)\n",w,h);
00606 }
00607 
00608 /****************************************************************/
00609 /****************************************************************/
00610 
00611 /// Local Variables:
00612 /// mode: c++
00613 /// mode: hs-minor
00614 /// c-basic-offset: 4
00615 /// End:

Generated on Thu Dec 29 02:01:15 2005 for Eliot by  doxygen 1.4.5