00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "wx/printdlg.h"
00020
00021 #include "ewx.h"
00022
00023 #include "dic.h"
00024 #include "game.h"
00025
00026 #include "configdb.h"
00027 #include "printout.h"
00028 #include "confdimdlg.h"
00029
00030 enum {
00031 Button_Ok,
00032 Button_Cancel,
00033 Button_Printer,
00034 Button_Page,
00035 Button_Save,
00036 Button_FontHeader,
00037 Button_FontText
00038 };
00039
00040 BEGIN_EVENT_TABLE(ConfDimDlg,wxDialog)
00041 EVT_CLOSE (ConfDimDlg::OnCloseWindow)
00042 EVT_BUTTON(Button_Ok, ConfDimDlg::OnButtonOk)
00043 EVT_BUTTON(Button_Save, ConfDimDlg::OnButtonSave)
00044 EVT_BUTTON(Button_Ok, ConfDimDlg::OnButtonOk)
00045 EVT_BUTTON(Button_Cancel, ConfDimDlg::OnButtonCancel)
00046 EVT_BUTTON(Button_Printer, ConfDimDlg::OnConfPrinter)
00047 EVT_BUTTON(Button_Page, ConfDimDlg::OnConfPage)
00048 EVT_BUTTON(Button_FontHeader, ConfDimDlg::OnConfFontHead)
00049 EVT_BUTTON(Button_FontText, ConfDimDlg::OnConfFontText)
00050 END_EVENT_TABLE()
00051
00052
00053 static int
00054 max(int i,int j)
00055 {
00056 return i>j ? i : j;
00057 }
00058
00059
00060 ConfDimDlg::ConfDimDlg(wxWindow* parent, wxPrintData pd, wxPageSetupData psd)
00061 : wxDialog(parent, -1, wxString(wxT("Eliot : Impression")))
00062 {
00063 int i;
00064 wxString choices[3];
00065 choices[0] = wxT("gauche");
00066
00067 choices[1] = wxT("centre");
00068 choices[2] = wxT("droite");
00069 wxStaticText* Hcomment[5];
00070 wxRect Hcommentrect[5];
00071 wxRect Htitlerect[5];
00072 wxRect Hjustrect[5];
00073 wxRect Hspacesrect[5];
00074 wxStaticText* Tcomment[5];
00075 wxRect Tcommentrect[5];
00076 wxRect Tdimrect[5];
00077 wxStaticText* Tunit[5];
00078 wxRect Tjustrect[5];
00079 wxRect Tspacesrect[5];
00080
00081 printdata = pd;
00082 pagesetupdata = psd;
00083
00084
00085
00086
00087
00088
00089
00090
00091 #define VSPACE 10
00092 #define HSPACE 5
00093
00094
00095
00096
00097 #define HFONT wxPoint(HSPACE,VSPACE)
00098 #define HCOMMENTY(i) (i==0 ? bfontheadrect.GetBottom() + VSPACE : \
00099 VSPACE + Hcommentrect[i-1].GetBottom())
00100 #define HCOMMENT(i) wxPoint(HSPACE,HCOMMENTY(i)+2)
00101 #define HTITLE(i) wxPoint(2*HSPACE+max(Hcommentrect[0].GetRight(), \
00102 Tcommentrect[0].GetRight()),HCOMMENTY(i))
00103 #define HJUST(i) wxPoint(Htitlerect[0].GetRight() + HSPACE,HCOMMENTY(i))
00104 #define HSPACES(i) wxPoint(Hjustrect[0].GetRight() + HSPACE,HCOMMENTY(i))
00105
00106
00107
00108
00109 #define TFONT wxPoint(HSPACE, Hcommentrect[4].GetBottom() + 2*VSPACE)
00110 #define TCOMMENTY(i) (i==0 ? bfonttextrect.GetBottom() + VSPACE : \
00111 VSPACE + Tcommentrect[i-1].GetBottom())
00112 #define TCOMMENT(i) wxPoint(HSPACE, TCOMMENTY(i)+2)
00113 #define TDIM(i) wxPoint(2*HSPACE+max(Tcommentrect[0].GetRight(), \
00114 Hcommentrect[0].GetRight()),TCOMMENTY(i))
00115 #define TJUST(i) wxPoint(Htitlerect[0].GetRight() + HSPACE, TCOMMENTY(i))
00116 #define TSPACES(i) wxPoint(Hjustrect[0].GetRight() + HSPACE, TCOMMENTY(i))
00117
00118
00119 #define ESPSIZE wxSize(spacerect.GetRight() - spacerect.GetLeft(),-1)
00120
00121
00122 wxStaticText* justif = new wxStaticText(this,-1,wxT("Justification"),wxPoint(0,0));
00123 wxRect justifrect = justif->GetRect();
00124 wxStaticText* space = new wxStaticText(this,-1,wxT("Espacement"),wxPoint(0,0));
00125 wxRect spacerect = space->GetRect();
00126
00127
00128
00129 bfontheader = new wxButton(this,Button_FontHeader,wxT("Caracteres"),HFONT);
00130 wxRect bfontheadrect = bfontheader->GetRect();
00131 for(i=0; i<5; i++)
00132 {
00133 wxString txt;
00134 txt << wxT("Titre colonne ") << (i+1);
00135 Hcomment[i] = new wxStaticText(this,-1,txt,HCOMMENT(i));
00136 Hcommentrect[i] = Hcomment[i]->GetRect();
00137 }
00138
00139
00140
00141 bfonttext = new wxButton(this,Button_FontText,wxT("Caracteres"),TFONT);
00142 wxRect bfonttextrect = bfonttext->GetRect();
00143 for(i=0; i<5; i++)
00144 {
00145 wxString txt;
00146 txt << wxT("Texte colonne ") << (i+1);
00147 Tcomment[i] = new wxStaticText(this,-1,txt,TCOMMENT(i),wxSize(-1,-1));
00148 Tcommentrect[i] = Tcomment[i]->GetRect();
00149 }
00150
00151
00152 for(i=0; i<5; i++)
00153 {
00154 Htitle[i] = new wxTextCtrl(this,-1,wxT(""),HTITLE(i),wxSize(100,-1));
00155 Htitlerect[i] = Htitle[i]->GetRect();
00156 Htitle[i]->SetToolTip(wxT("Texte du titre de la colonne"));
00157
00158 Hjust[i] = new wxChoice(this,-1,HJUST(i),wxSize(-1,-1),3,choices);
00159 Hjustrect[i] = Hjust[i]->GetRect();
00160 Hjust[i]->SetToolTip(wxT("Justification du titre de la colonne"));
00161
00162 Hspaces[i] = new wxTextCtrl(this,-1,wxT("00"),HSPACES(i),ESPSIZE);
00163 Hspacesrect[i] = Hspaces[i]->GetRect();
00164
00165 Hspaces[i]->SetToolTip(wxT("Espacement des caracteres du titre"));
00166 }
00167
00168
00169
00170 for(i=0; i<5; i++)
00171 {
00172 Tdim[i] = new wxTextCtrl(this,-1,wxT(""),TDIM(i),wxSize(50,-1));
00173 Tdimrect[i] = Tdim[i]->GetRect();
00174
00175 Tdim[i]->SetToolTip(wxT("Dimension interieure de la colonne (en mm)"));
00176
00177 Tunit[i] = new wxStaticText(this,-1,wxT("mm"),
00178 wxPoint(Tdimrect[i].GetRight()+
00179 HSPACE,TCOMMENTY(i)+2),
00180 wxSize(-1,-1));
00181
00182 Tjust[i] = new wxChoice(this,-1,TJUST(i),wxSize(-1,-1),3,choices);
00183 Tjustrect[i] = Tjust[i]->GetRect();
00184 Tjust[i]->SetToolTip(wxT("Justification du texte de la colonne"));
00185
00186 Tspaces[i] = new wxTextCtrl(this,-1,wxT(""),TSPACES(i),ESPSIZE);
00187 Tspacesrect[i] = Tspaces[i]->GetRect();
00188
00189 Tspaces[i]->SetToolTip(wxT("Espacement des caracteres"));
00190 }
00191
00192 justif->Move(wxPoint(Tjustrect[0].GetLeft(),bfontheadrect.GetBottom()
00193 - (justifrect.GetBottom() - justifrect.GetTop())));
00194 justifrect = justif->GetRect();
00195 space->Move(wxPoint(Tspacesrect[0].GetLeft(),justifrect.GetTop()));
00196 spacerect = space->GetRect();
00197
00198
00199
00200 #define YPOS(i) (2*VSPACE + Tcommentrect[4].GetBottom() + \
00201 i*(VSPACE+Tspacesrect[0].GetBottom()-Tspacesrect[0].GetTop()))
00202
00203
00204 #define COL2START HSPACE
00205
00206
00207
00208 #define XPOSLEFT (HSPACE + max(dyh1textrect.GetRight(), \
00209 max(dyt1textrect.GetRight(), dxbegintextrect.GetRight() )))
00210 #define XPOSRIGHT (HSPACE + max(dyh2textrect.GetRight(), \
00211 max(dyt2textrect.GetRight(), dxendtextrect.GetRight() )))
00212
00213 #define DYH1COMMENT wxPoint(COL2START, YPOS(0)+2)
00214 #define DYH1TEXT wxPoint(XPOSLEFT, YPOS(0))
00215 #define DYH1UNIT wxPoint(dyh1rect.GetRight() + HSPACE, YPOS(0))
00216
00217 #define DYH2COMMENT wxPoint(3*HSPACE + dyh1mmrect.GetRight(), YPOS(0)+2)
00218 #define DYH2TEXT wxPoint(XPOSRIGHT, YPOS(0))
00219 #define DYH2UNIT wxPoint(dyh2rect.GetRight() + HSPACE, YPOS(0))
00220
00221 #define DYT1COMMENT wxPoint(COL2START, YPOS(1)+2)
00222 #define DYT1TEXT wxPoint(XPOSLEFT, YPOS(1))
00223 #define DYT1UNIT wxPoint(dyt1rect.GetRight() + HSPACE, YPOS(1))
00224
00225 #define DYT2COMMENT wxPoint(3*HSPACE + dyt1mmrect.GetRight(), YPOS(1)+2)
00226 #define DYT2TEXT wxPoint(XPOSRIGHT, YPOS(1))
00227 #define DYT2UNIT wxPoint(dyt2rect.GetRight() + HSPACE, YPOS(1))
00228
00229 #define DXBEGINCOMMENT wxPoint(COL2START, YPOS(2)+2)
00230 #define DXBEGINTEXT wxPoint(XPOSLEFT, YPOS(2))
00231 #define DXBEGINUNIT wxPoint(dxbeginrect.GetRight() + HSPACE, YPOS(2))
00232
00233 #define DXENDCOMMENT wxPoint(3*HSPACE + dxbeginmmrect.GetRight(), YPOS(2)+2)
00234 #define DXENDTEXT wxPoint(XPOSRIGHT, YPOS(2))
00235 #define DXENDUNIT wxPoint(dxendrect.GetRight() + HSPACE, YPOS(2))
00236
00237 #define DIM wxSize(30,-1)
00238
00239
00240 wxStaticText* dyh1text = new wxStaticText(this,-1,wxT("Titre esp. sup."),DYH1COMMENT,wxSize(-1,-1));
00241 wxRect dyh1textrect = dyh1text->GetRect();
00242 wxStaticText* dyt1text = new wxStaticText(this,-1,wxT("Texte esp. sup."),DYT1COMMENT,wxSize(-1,-1));
00243 wxRect dyt1textrect = dyt1text->GetRect();
00244 wxStaticText* dxbegintext = new wxStaticText(this,-1,wxT("Texte esp. gauche."),DXBEGINCOMMENT,wxSize(-1,-1));
00245 wxRect dxbegintextrect = dxbegintext->GetRect();
00246
00247 dyh1 = new wxTextCtrl(this,-1,wxT("00"),DYH1TEXT,DIM);
00248 wxRect dyh1rect = dyh1->GetRect();
00249 wxStaticText* dyh1mm = new wxStaticText(this,-1,wxT("mm"),DYH1UNIT,wxSize(-1,-1));
00250 wxRect dyh1mmrect = dyh1mm->GetRect();
00251 dyt1 = new wxTextCtrl(this,-1,wxT("00"),DYT1TEXT,DIM);
00252 wxRect dyt1rect = dyt1->GetRect();
00253 wxStaticText* dyt1mm = new wxStaticText(this,-1,wxT("mm"),DYT1UNIT,wxSize(-1,-1));
00254 wxRect dyt1mmrect = dyt1mm->GetRect();
00255 dxbegin = new wxTextCtrl(this,-1,wxT("00"),DXBEGINTEXT,DIM);
00256 wxRect dxbeginrect = dxbegin->GetRect();
00257 wxStaticText* dxbeginmm = new wxStaticText(this,-1,wxT("mm"),DXBEGINUNIT,wxSize(-1,-1));
00258 wxRect dxbeginmmrect = dxbeginmm->GetRect();
00259
00260
00261 wxStaticText* dyh2text = new wxStaticText(this,-1,wxT("Titre esp. inf."),DYH2COMMENT,wxSize(-1,-1));
00262 wxRect dyh2textrect = dyh2text->GetRect();
00263 wxStaticText* dyt2text = new wxStaticText(this,-1,wxT("Texte esp. inf."),DYT2COMMENT,wxSize(-1,-1));
00264 wxRect dyt2textrect = dyt2text->GetRect();
00265 wxStaticText* dxendtext = new wxStaticText(this,-1,wxT("Texte esp. droit."),DXENDCOMMENT,wxSize(-1,-1));
00266 wxRect dxendtextrect = dxendtext->GetRect();
00267
00268 dyh2 = new wxTextCtrl(this,-1,wxT("00"),DYH2TEXT,DIM);
00269 wxRect dyh2rect = dyh2->GetRect();
00270 wxStaticText* dyh2mm = new wxStaticText(this,-1,wxT("mm"),DYH2UNIT,wxSize(-1,-1));
00271 wxRect dyh2mmrect = dyh2mm->GetRect();
00272 dyt2 = new wxTextCtrl(this,-1,wxT("00"),DYT2TEXT,DIM);
00273 wxRect dyt2rect = dyt2->GetRect();
00274 wxStaticText* dyt2mm = new wxStaticText(this,-1,wxT("mm"),DYT2UNIT,wxSize(-1,-1));
00275 wxRect dyt2mmrect = dyt2mm->GetRect();
00276 dxend = new wxTextCtrl(this,-1,wxT("00"),DXENDTEXT,DIM);
00277 wxRect dxendrect = dxend->GetRect();
00278 wxStaticText* dxendmm = new wxStaticText(this,-1,wxT("mm"),DXENDUNIT,wxSize(-1,-1));
00279 wxRect dxendmmrect = dxendmm->GetRect();
00280
00281
00282 {int t = dyh2mmrect.GetTop() + dyt2mmrect.GetTop() + dxendmmrect.GetTop(); t++; }
00283
00284 #define BHSPACE 1
00285 #define BPOS (2*VSPACE + dxendrect.GetBottom())
00286
00287 #define BPRINTERPOINT wxPoint(COL2START,BPOS)
00288 #define BPAGEPOINT wxPoint(bprinterrect.GetRight() + BHSPACE,BPOS)
00289 #define BOKPOINT wxPoint(bcancelrect.GetLeft() - (bokrect.GetRight() \
00290 - bokrect.GetLeft() + BHSPACE),BPOS)
00291 #define CANCELWIDTH (bcancelrect.GetRight() - bcancelrect.GetLeft())
00292 #define BCANCELPOINT wxPoint(Tspacesrect[0].GetRight() - CANCELWIDTH,BPOS)
00293
00294
00295 bprinter = new wxButton(this,Button_Printer,wxT("Imprimante"),BPRINTERPOINT);
00296 wxRect bprinterrect = bprinter->GetRect();
00297 bprinter->SetToolTip(wxT("Configurer l'imprimante"));
00298
00299 bpage = new wxButton(this,Button_Page,wxT("Page"),BPAGEPOINT);
00300
00301 bpage->SetToolTip(wxT("Configurer la taille de page"));
00302
00303 bcancel = new wxButton(this,Button_Cancel,wxT("Annuler"));
00304 wxRect bcancelrect = bcancel->GetRect();
00305 bcancel->Move(BCANCELPOINT);
00306 bcancelrect = bcancel->GetRect();
00307 bcancel->SetToolTip(wxT("Annuler les dernier changements et quitter"));
00308
00309 bok = new wxButton(this,Button_Ok,wxT("OK"));
00310 wxRect bokrect = bok->GetRect();
00311 bok->Move(BOKPOINT);
00312 bokrect = bok->GetRect();
00313 bok->SetToolTip(wxT("Enregistrer les changements et quitter"));
00314
00315 #define DLGWIDTH (bcancelrect.GetRight() + HSPACE)
00316 #define DLGHEIGHT (bokrect.GetBottom() + VSPACE)
00317
00318 SetClientSize(DLGWIDTH,DLGHEIGHT);
00319 readconf();
00320 }
00321
00322 ConfDimDlg::~ConfDimDlg()
00323 {
00324 }
00325
00326 void
00327 ConfDimDlg::set(wxTextCtrl *t, long val)
00328 {
00329 wxString str;
00330 str << (int)val;
00331 t->SetValue(str);
00332 }
00333
00334 long
00335 ConfDimDlg::get(wxTextCtrl* t)
00336 {
00337 wxString str;
00338 str = t->GetValue();
00339 return atoi(str.mb_str());
00340 }
00341
00342 void
00343 ConfDimDlg::readconf()
00344 {
00345 int i;
00346 for(i=0; i<5; i++) {
00347 Htitle[i]->SetValue(config.getNameH(i));
00348 switch (config.getJustifH(i)) {
00349 case LEFT: Hjust[i]->SetSelection(0); break;
00350 case CENTER: Hjust[i]->SetSelection(1); break;
00351 case RIGHT: Hjust[i]->SetSelection(2); break;
00352 }
00353 set(Hspaces[i],config.getSpacesH(i));
00354 }
00355 for(i=0; i<5; i++) {
00356 wxString str;
00357 str << (int)config.getDxText(i);
00358 Tdim[i]->SetValue(str);
00359 switch (config.getJustifT(i)) {
00360 case LEFT: Tjust[i]->SetSelection(0); break;
00361 case CENTER: Tjust[i]->SetSelection(1); break;
00362 case RIGHT: Tjust[i]->SetSelection(2); break;
00363 }
00364 set(Tspaces[i],config.getSpacesT(i));
00365 }
00366 set(dyh1,config.getDyH1());
00367 set(dyh2,config.getDyH2());
00368 set(dyt1,config.getDyT1());
00369 set(dyt2,config.getDyT2());
00370 set(dxbegin,config.getDxBegin());
00371 set(dxend,config.getDxEnd());
00372
00373 headfont = config.getFont(PRINTHFONT);
00374 textfont = config.getFont(PRINTTFONT);
00375 }
00376
00377 void
00378 ConfDimDlg::writeconf()
00379 {
00380 int i;
00381 for(i=0; i<5; i++) {
00382 config.setNameH(i,Htitle[i]->GetValue());
00383 switch (Hjust[i]->GetSelection()) {
00384 case -1: break;
00385 case 0: config.setJustifH(i,LEFT); break;
00386 case 1: config.setJustifH(i,CENTER); break;
00387 case 2: config.setJustifH(i,RIGHT); break;
00388 }
00389 config.setSpacesH(i,get(Hspaces[i]));
00390 }
00391 for(i=0; i<5; i++) {
00392 wxString str;
00393 str = Tdim[i]->GetValue();
00394 config.setDxText(i, atoi(str.mb_str()));
00395 switch (Tjust[i]->GetSelection()) {
00396 case -1: break;
00397 case 0: config.setJustifT(i,LEFT); break;
00398 case 1: config.setJustifT(i,CENTER); break;
00399 case 2: config.setJustifT(i,RIGHT); break;
00400 }
00401 config.setSpacesT(i,get(Tspaces[i]));
00402 }
00403 config.setDyH1(get(dyh1));
00404 config.setDyH2(get(dyh2));
00405 config.setDyT1(get(dyt1));
00406 config.setDyT2(get(dyt2));
00407 config.setDxBegin(get(dxbegin));
00408 config.setDxEnd(get(dxend));
00409
00410 config.setFont(PRINTHFONT,headfont);
00411 config.setFont(PRINTTFONT,textfont);
00412 }
00413
00414 void
00415 ConfDimDlg::OnCloseWindow(wxCloseEvent& event)
00416 {
00417 if (IsModal() == TRUE)
00418 EndModal(1);
00419 else
00420 this->Destroy();
00421 }
00422
00423 void
00424 ConfDimDlg::OnButtonOk(wxCommandEvent& event)
00425 {
00426 writeconf();
00427 if (IsModal() == TRUE)
00428 EndModal(1);
00429 else
00430 this->Destroy();
00431 }
00432
00433 void
00434 ConfDimDlg::OnButtonCancel(wxCommandEvent &event)
00435 {
00436 if (IsModal() == TRUE)
00437 EndModal(1);
00438 else
00439 this->Destroy();
00440 }
00441
00442 void
00443 ConfDimDlg::OnButtonSave(wxCommandEvent& event)
00444 {
00445 writeconf();
00446 }
00447
00448 void
00449 ConfDimDlg::OnConfPage(wxCommandEvent& event)
00450 {
00451
00452 pagesetupdata = printdata;
00453 wxPageSetupDialog pageSetupDialog(this, &pagesetupdata);
00454 pageSetupDialog.ShowModal();
00455 printdata = pageSetupDialog.GetPageSetupData().GetPrintData();
00456 pagesetupdata = pageSetupDialog.GetPageSetupData();
00457
00458
00459
00460
00461
00462 }
00463
00464 void
00465 ConfDimDlg::OnConfPrinter(wxCommandEvent& event)
00466 {
00467
00468 wxPrintDialogData printDialogData(printdata);
00469 wxPrintDialog printerDialog(this, & printDialogData);
00470 printerDialog.GetPrintDialogData().SetSetupDialog(TRUE);
00471 printerDialog.ShowModal();
00472 printdata = printerDialog.GetPrintDialogData().GetPrintData();
00473
00474
00475
00476
00477
00478
00479 }
00480
00481 void
00482 ConfDimDlg::OnConfFontHead(wxCommandEvent& event)
00483 {
00484 headfont = config.ChooseFont((wxFrame*)this,headfont);
00485 }
00486
00487 void
00488 ConfDimDlg::OnConfFontText(wxCommandEvent& event)
00489 {
00490 textfont = config.ChooseFont((wxFrame*)this,textfont);
00491 }
00492
00493 wxPrintData
00494 ConfDimDlg::getPrintData()
00495 {
00496 return printdata;
00497 }
00498
00499 wxPageSetupData
00500 ConfDimDlg::getPageSetupData()
00501 {
00502 return pagesetupdata;
00503 }