00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <wx/wx.h>
00028
00029 #include "ewx.h"
00030 #include "dic.h"
00031 #include "game.h"
00032 #include "player.h"
00033 #include "training.h"
00034 #include "configdb.h"
00035 #include "gfxresult.h"
00036 #include "mainframe.h"
00037
00038
00039
00040
00041 enum {
00042 ListCtrl_ID = 11000
00043 };
00044
00045 BEGIN_EVENT_TABLE(GfxResult, wxControl)
00046 EVT_SIZE(GfxResult::OnSize)
00047 EVT_LIST_ITEM_SELECTED (ListCtrl_ID, GfxResult::OnListCtrlSelected)
00048 EVT_LIST_ITEM_ACTIVATED (ListCtrl_ID, GfxResult::OnListCtrlActivated)
00049 END_EVENT_TABLE()
00050
00051
00052
00053
00054 GfxResult::GfxResult(wxFrame *parent, MainFrame* _mf, Game* _game) :
00055 wxControl(parent, wxWindowID(234), wxDefaultPosition, wxDefaultSize,
00056 wxNO_BORDER | wxFULL_REPAINT_ON_RESIZE)
00057 {
00058 mf = _mf;
00059 game = _game;
00060 savedrack = std::string("");
00061 results = new wxListCtrl(this, ListCtrl_ID);
00062 #if defined(ENABLE_LC_NO_HEADER)
00063 results->SetSingleStyle(wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL);
00064 #else
00065 results->SetSingleStyle(wxLC_REPORT | wxLC_SINGLE_SEL);
00066 #endif
00067 results->InsertColumn(0, wxT("Sol"));
00068 results->InsertColumn(1, wxT("*"));
00069 results->InsertColumn(2, wxT("Pos"));
00070 results->InsertColumn(3, wxT("Pts"));
00071 results->SetToolTip(wxT("Resultats de la recherche"));
00072
00073 wxBoxSizer *sizer_v = new wxBoxSizer(wxVERTICAL);
00074 wxBoxSizer *sizer_h = new wxBoxSizer(wxHORIZONTAL);
00075
00076 sizer_v->Add(results, 1, wxEXPAND, 0);
00077 sizer_h->Add(sizer_v, 1, wxEXPAND, 0);
00078
00079 SetAutoLayout(TRUE);
00080 SetSizer(sizer_h);
00081 sizer_h->Fit(this);
00082 sizer_h->SetSizeHints(this);
00083 }
00084
00085
00086
00087
00088 GfxResult::~GfxResult(void)
00089 {
00090
00091 Show(false);
00092 Show(true);
00093 }
00094
00095
00096
00097
00098 void
00099 GfxResult::SetGame(Game* g)
00100 {
00101 game = g;
00102 savedrack = std::string("");
00103 results->DeleteAllItems();
00104 }
00105
00106
00107
00108
00109 void
00110 GfxResult::Refresh()
00111 {
00112 if (game == NULL)
00113 return;
00114
00115 debug(" GfxResult::Refresh : ");
00116 std::string rack = game->getCurrentPlayer().getCurrentRack().toString();
00117
00118 if (savedrack != rack)
00119 {
00120 debug("changed (%s -> %s)",savedrack.c_str(),rack.c_str());
00121 savedrack = rack;
00122 results->DeleteAllItems();
00123 }
00124 else
00125 {
00126 debug("unchanged");
00127 }
00128 debug("\n");
00129 }
00130
00131
00132
00133
00134 void
00135 GfxResult::Search()
00136 {
00137 debug("GfxResult::Search()\n");
00138 if (game == NULL)
00139 return;
00140
00141 ((Training*)game)->search();
00142
00143 results->DeleteAllItems();
00144 results->SetFont(config.getFont(LISTFONT));
00145
00146 const Results &res = ((Training*)game)->getResults();
00147 debug(" GfxResult::Search size = %d\n",res.size());
00148 for (int i = 0; i < res.size(); i++)
00149 {
00150 Round r = res.get(i);
00151
00152 wxString pts;
00153 wxString word = wxU(r.getWord().c_str());
00154 wxString coords = wxU(r.getCoord().toString().c_str());
00155 wxChar bonus = r.getBonus() ? wxT('*') : wxT(' ');
00156 pts << r.getPoints();
00157
00158 long tmp = results->InsertItem(i, word);
00159 results->SetItemData(tmp, i);
00160 tmp = results->SetItem(i, 1, bonus);
00161 tmp = results->SetItem(i, 2, coords);
00162 tmp = results->SetItem(i, 3, pts);
00163 }
00164
00165 for (int i = 0; i < 4; i++)
00166 results->SetColumnWidth(i, wxLIST_AUTOSIZE);
00167
00168
00169
00170 if (res.size() > 0)
00171 {
00172 results->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED | wxLIST_MASK_STATE);
00173 ((Training*)game)->testPlay(0);
00174 }
00175 }
00176
00177
00178
00179
00180 int
00181 GfxResult::GetSelected()
00182 {
00183 int item = -1;
00184 item = results->GetNextItem(item,wxLIST_NEXT_ALL,wxLIST_STATE_SELECTED);
00185
00186 return item;
00187 }
00188
00189
00190
00191
00192 void
00193 GfxResult::OnListCtrlSelected(wxListEvent& event)
00194 {
00195
00196 if (event.m_itemIndex > -1)
00197 {
00198 mf->TestPlay(event.m_itemIndex);
00199 }
00200 }
00201
00202
00203
00204
00205 void
00206 GfxResult::OnListCtrlActivated(wxListEvent& event)
00207 {
00208
00209 if (event.m_itemIndex > -1)
00210 {
00211 mf->Play(1);
00212 results->DeleteAllItems();
00213 }
00214 }
00215
00216
00217
00218
00219 void
00220 GfxResult::OnSize(wxSizeEvent& e)
00221 {
00222 int w,h;
00223 GetClientSize(&w,&h);
00224 results->SetClientSize(w,h);
00225
00226 }
00227
00228
00229
00230
00231
00232
00233
00234