FOX/ObjCryst++  2022
wxCryst.cpp
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2000-2002 Vincent Favre-Nicolin vincefn@users.sourceforge.net
3  2000-2001 University of Geneva (Switzerland)
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 //#include <sstream> //for stringstream
20 #include <fstream>
21 
22 // wx headers, with or without precompilation
23 #include "wx/wxprec.h"
24 #ifdef __BORLANDC__
25  #pragma hdrstop
26 #endif
27 #ifndef WX_PRECOMP
28  #include "wx/wx.h"
29 #endif
30 
31 #include "ObjCryst/wxCryst/wxCryst.h"
32 #include "ObjCryst/ObjCryst/Undo.h"
33 
34 //#include "ObjCryst/Quirks/VFNStreamFormat.h"
35 #include "ObjCryst/Quirks/VFNDebug.h"
36 
37 //#include "ObjCryst/RefinableObj/GlobalOptimObj.h"
38 
39 //Fixes for Cygwin; where do those stupid macros come from ? Somewhere in wxMSW headers
40 #ifdef max
41 #undef max
42 #endif
43 #ifdef min
44 #undef min
45 #endif
46 #ifdef DrawText
47 #undef DrawText
48 #endif
49 
50 namespace ObjCryst
51 {
52 std::map<wxWindowID,std::pair<wxPoint,wxSize> > gvWindowPosition;
53 
54 wxMultiChoiceDialog_ListBox::wxMultiChoiceDialog_ListBox(wxWindow* parent, const wxString& message, const wxString& caption,
55  int n, const wxString* choices):
56 wxDialog(parent,-1,_T("Choose the molecule's atoms"),wxDefaultPosition,wxSize(300,400),wxCAPTION|wxSTAY_ON_TOP),
57 mListBox(this,-1,wxDefaultPosition,wxSize(250,350),n,choices,wxLB_MULTIPLE)
58 {
59  wxBoxSizer *sizer=new wxBoxSizer(wxVERTICAL);
60  sizer->Add(&mListBox);
61  sizer->Add(this->CreateSeparatedButtonSizer(wxOK | wxCANCEL));
62  this->SetSizer(sizer);
63  sizer->SetSizeHints(this);
64  sizer->Fit(this);
65 }
66 
67 wxArrayInt wxMultiChoiceDialog_ListBox::GetSelections() const
68 {
69  wxArrayInt choice;
70  mListBox.GetSelections(choice);
71  return choice;
72 }
73 
75 //
76 // Unique ID for menus incrementer
77 //
79 WXCRYST_ID::WXCRYST_ID(){mIndex=mCounter++;}
80 WXCRYST_ID::operator long(){return mIndex;}
81 long WXCRYST_ID::mCounter=wxID_HIGHEST+100;
82 
83 #ifdef VFN_CRYST_MUTEX
85 //
86 // Mutex
87 //
89 CrystMutex::CrystMutex():mNbLock(0){}
90 CrystMutex::~CrystMutex()
91 {
92  cout <<"~CrystMutex("<<this<<"), Total number of Locks="<<mNbLock<<endl;
93 }
94 wxMutexError CrystMutex::Lock()
95 {
96  #if 1
97  return this->wxMutex::Lock();
98  #else
99  cout <<"Thread:"<<wxThread::IsMain()<<":CrystMutex("<<this<<")::Lock() ?"<<endl;
100  wxMutexError res=this->wxMutex::TryLock();
101  if(res==wxMUTEX_NO_ERROR)
102  cout <<"Thread:"<<wxThread::IsMain()<<":CrystMutex("<<this<<")::Lock()-OK"<<endl;
103  if(res==wxMUTEX_DEAD_LOCK)
104  {
105  cout <<"Thread:"<<wxThread::IsMain()<<":CrystMutex("<<this<<")::Lock()-DEADLOCK!"<<endl;
106  exit(0);
107  }
108  if(res==wxMUTEX_BUSY)
109  {
110  cout <<"Thread:"<<wxThread::IsMain()<<":CrystMutex("<<this<<")::Lock()-Busy?"<<endl;
111  res=this->wxMutex::Lock();
112  cout <<"Thread:"<<wxThread::IsMain()<<":CrystMutex("<<this<<")::Lock()-OK2"<<endl;
113  }
114  return res;
115  #endif
116 }
117 wxMutexError CrystMutex::Unlock()
118 {
119  //cout <<"Thread:"<<wxThread::IsMain()<<":CrystMutex("<<this<<"::Unlock()"<<endl;
120  mNbLock++;
121  return this->wxMutex::Unlock();
122 }
123 #endif
124 
126 //
127 // WXCrystObjBasic
128 //
130 WXCrystObjBasic::WXCrystObjBasic(wxWindow* parent):
131 wxWindow(parent,-1),mWXCrystParent(0),mIsShown(true),mNeedUpdateUI(true)
132 {
133  VFN_DEBUG_MESSAGE("WXCrystObjBasic::WXCrystObjBasic() at "<<this,6)
134  if(parent !=0) mWXCrystParent=dynamic_cast<WXCrystObjBasic*>(parent);
135 #ifdef __WXGTK__
136 #ifndef __WXGTK20__
137  // Why is this necessary for GTK 1.2 ? wxWidgets 2.6.3
138  this->SetBackgroundColour(wxColour(240,240,240));// wxLIGHT_GREY
139 #endif
140 #endif
141  VFN_DEBUG_MESSAGE("WXCrystObjBasic::WXCrystObjBasic():End",6)
142 }
143 
145 {
146  // Every time we destroy a widget, validate all input to make sure the destroyed
147  // widget does not have some unread info.
149  set<WXCrystObjBasicList*> vpList=mvpList;//use a copy
150  for(set<WXCrystObjBasicList*>::iterator pos=vpList.begin();pos!=vpList.end();++pos)
151  (*pos)->Remove(this);
152 }
153 
154 void WXCrystObjBasic::BottomLayout(WXCrystObjBasic *pChild)
155 {
156  VFN_DEBUG_ENTRY("WXCrystObjBasic::BottomLayout(...)"<<this->GetSize().GetWidth()<<","<<this->GetSize().GetHeight(),5);
157  wxTheApp->GetTopWindow()->SendSizeEvent();
158  VFN_DEBUG_EXIT("WXCrystObjBasic::BottomLayout(...)"<<this->GetSize().GetWidth()<<","<<this->GetSize().GetHeight(),5);
159 }
160 void WXCrystObjBasic::AddChild(WXCrystObjBasic *pChild, bool doBottomLayout)
161 {
162  VFN_DEBUG_ENTRY("WXCrystObjBasic::AddChild(...)"<<this->GetSize().GetWidth()<<","<<this->GetSize().GetHeight(),5);
163  wxSizer *pSizer=this->GetSizer();
164  if(pSizer!=0)
165  {
166  pSizer->Add(pChild);
167  }
168  if(doBottomLayout) wxTheApp->GetTopWindow()->SendSizeEvent();
169  VFN_DEBUG_EXIT("WXCrystObjBasic::AddChild(...)"<<this->GetSize().GetWidth()<<","<<this->GetSize().GetHeight(),5);
170 }
171 
174 bool WXCrystObjBasic::Layout()
175 {
176  //static unsigned long ct=0;
177  //cout<<"WXCrystObjBasic::Layout() #"<<++ct<<endl;
178  return wxWindow::Layout();
179 }
180 void WXCrystObjBasic::SetToolTip(const wxString& tip){this->wxWindow::SetToolTip(tip);}
181 
183 //
184 // WXCrystObjBasicList
185 //
188 {}
189 
191 {
192  set<WXCrystObjBasic*> vpWXCrystObj=mvpWXCrystObj;
193  for(set<WXCrystObjBasic*>::iterator pos=vpWXCrystObj.begin();pos!=vpWXCrystObj.end();pos++)
194  (*pos)->RemovedFromList(this);
195  mvpWXCrystObj.clear();
196 }
197 
198 unsigned int WXCrystObjBasicList::GetNb()const {return mvpWXCrystObj.size();}
199 
201 {
202  VFN_DEBUG_MESSAGE("WXCrystObjBasicList::Add()",6)
203  win->AddedToList(this);
204  mvpWXCrystObj.insert(win);
205 }
206 
208 {
209  VFN_DEBUG_MESSAGE("WXCrystObjBasicList::Remove():"<<win,6)
210  mvpWXCrystObj.erase(win);
211  win->RemovedFromList(this);
212 }
213 
215 {
216  VFN_DEBUG_MESSAGE("WXCrystObjBasicList::Show(bool)",3)
217  for(set<WXCrystObjBasic*>::iterator pos=mvpWXCrystObj.begin();pos!=mvpWXCrystObj.end();pos++)
218  (*pos)->Show(show);
219  //this->CrystUpdate();
220  VFN_DEBUG_MESSAGE("WXCrystObjBasicList::Show(bool):End",3)
221  return true;
222 }
223 
224 void WXCrystObjBasicList::CrystUpdate(const bool updateUI,const bool mutexlock)
225 {
226  VFN_DEBUG_ENTRY("WXCrystObjBasicList::CrystUpdate()",5)
227  for(set<WXCrystObjBasic*>::iterator pos=mvpWXCrystObj.begin();pos!=mvpWXCrystObj.end();pos++)
228  {
229  VFN_DEBUG_MESSAGE("WXCrystObjBasicList::CrystUpdate("<<updateUI<<mutexlock<<")@"<<*pos,5)
230  (*pos)->CrystUpdate(updateUI,mutexlock);
231  }
232  VFN_DEBUG_EXIT("WXCrystObjBasicList::CrystUpdate()",5)
233 }
234 void WXCrystObjBasicList::UpdateUI(const bool mutexlock)
235 {
236  VFN_DEBUG_ENTRY("WXCrystObjBasicList::UpdateUI("<<mutexlock<<")"<<"MainThread="<<wxThread::IsMain(),5)
237  for(set<WXCrystObjBasic*>::iterator pos=mvpWXCrystObj.begin();pos!=mvpWXCrystObj.end();pos++)
238  (*pos)->UpdateUI(mutexlock);
239  VFN_DEBUG_EXIT("WXCrystObjBasicList::UpdateUI()",5)
240 }
241 void WXCrystObjBasicList::Enable(bool enable)
242 {
243  for(set<WXCrystObjBasic*>::iterator pos=mvpWXCrystObj.begin();pos!=mvpWXCrystObj.end();pos++)
244  (*pos)->Enable(enable);
245 }
246 
248 //
249 // For the automatic validation of user input
250 //
257 
259 {
260  #ifdef __FOX_UNDO__
261  // Hijack this function to record changes in the configuration
263  #endif
264  if(0==spLastWXFieldInputNotValidated) return;
265  VFN_DEBUG_ENTRY("WXCrystValidateAllUserInput()...",6)
266  static WXField *pField;
268  spLastWXFieldInputNotValidated=0;//avoid loops
269  pField->ValidateUserInput();
270  VFN_DEBUG_EXIT("WXCrystValidateAllUserInput()...",6)
271 }
272 
274 //
275 // WXField
276 //
278 WXField::WXField(wxWindow *parent,const string& label,const int id):
279 WXCrystObjBasic(parent),mId(id)
280 {
281  VFN_DEBUG_ENTRY("WXField::WXField()",6)
282  mpSizer = new wxBoxSizer(wxHORIZONTAL);
283  mpLabel=new wxStaticText(this,-1,wxString::FromAscii(label.c_str()));
284  mpSizer->Add(mpLabel,0,wxALIGN_CENTER);
285  this->SetSizer(mpSizer);
286  //mpSizer->SetSizeHints(this);
287  //this->Layout();
288  VFN_DEBUG_EXIT("WXField::WXField()",6)
289 }
290 void WXField::SetLabel(const string& s)
291 {
292  VFN_DEBUG_MESSAGE("WXField::SetLabel()",3)
293  mpLabel->SetLabel(wxString::FromAscii(s.c_str()));
294  mpLabel->Layout();
295 }
296 bool WXField::SetForegroundColour(const wxColour& colour)
297 {
298  VFN_DEBUG_MESSAGE("WXField::SetLabel()",3)
299  mpLabel->SetForegroundColour(colour);
300  return this->wxWindow::SetForegroundColour(colour);
301 }
302 
303 void WXField::SetSize(int width, int height)
304 {}
306 //
307 // WXFieldString
308 //
310 BEGIN_EVENT_TABLE(WXFieldString,wxWindow)
311  EVT_TEXT_ENTER(ID_WXFIELD, WXFieldString::OnEnter)
312  EVT_TEXT( ID_WXFIELD, WXFieldString::OnText)
313 END_EVENT_TABLE()
314 
315 WXFieldString::WXFieldString(wxWindow *parent,string& st,
316  const int id,const int hsize, bool isEditable):
317 WXField(parent,"",id),mpString(&st),mValue(st),mIsSelfUpdating(false)
318 {
319  VFN_DEBUG_MESSAGE("WXFieldString::WXFieldName():End",6)
320 
321  if(true==isEditable)
322  mpField=new wxTextCtrl(this,ID_WXFIELD,wxString::FromAscii(mValue.c_str()),
323  wxDefaultPosition,wxSize(hsize,-1),wxTE_PROCESS_ENTER,
324  wxTextValidator(wxFILTER_ASCII));
325  else
326  mpField=new wxTextCtrl(this,ID_WXFIELD,wxString::FromAscii(mValue.c_str()),
327  wxDefaultPosition,wxSize(hsize,-1),wxTE_READONLY,
328  wxTextValidator(wxFILTER_ASCII));
329 
330  mpSizer->Add(mpField,0,wxALIGN_CENTER);
331  mpSizer->SetSizeHints(this);
332  this->Layout();
333 }
334 
335 void WXFieldString::OnEnter(wxCommandEvent & WXUNUSED(event))
336 {
337  VFN_DEBUG_MESSAGE("WXFieldString::OnEnter()",6)
339 }
340 void WXFieldString::OnText(wxCommandEvent & WXUNUSED(event))
341 {
342  if(true==mIsSelfUpdating) return;
343  VFN_DEBUG_MESSAGE("WXFieldString::OnText():",6)
345  {
348  }
349 }
350 
351 void WXFieldString::SetValue(const string&s)
352 {
353  VFN_DEBUG_ENTRY("WXFieldString::SetValue()",3)
354  wxMutexLocker mlock(mMutex);
355  if(mValue==s)
356  {
357  VFN_DEBUG_EXIT("WXFieldString::SetValue(): string unchanged",3)
358  return;
359  }
360  mValue=s;
361  mNeedUpdateUI=true;
362  VFN_DEBUG_EXIT("WXFieldString::SetValue()",3)
363 }
364 
365 const string WXFieldString::GetValue() const
366 {
367  VFN_DEBUG_MESSAGE("WXFieldString::GetValue()"<<mValue<<":"<<mpField->GetValue(),6)
368  return mValue;
369 }
370 void WXFieldString::CrystUpdate(const bool uui,const bool lock)
371 {
372  VFN_DEBUG_ENTRY("WXFieldString::CrystUpdate()",3)
373  if(lock) mMutex.Lock();
374  if(mValue==*mpString)
375  {
376  if(lock)mMutex.Unlock();
377  return;
378  }
380  mValue=*mpString;
381  mNeedUpdateUI=true;
382  if(lock) mMutex.Unlock();
383  if(uui) if(true==wxThread::IsMain()) this->UpdateUI(lock);
384  VFN_DEBUG_EXIT("WXFieldString::CrystUpdate()",3)
385 }
386 void WXFieldString::UpdateUI(const bool lock)
387 {
388  if(lock) mMutex.Lock();
389  if(mNeedUpdateUI==false)
390  {
391  if(lock) mMutex.Unlock();
392  return;
393  }
394  VFN_DEBUG_ENTRY("WXFieldString::UpdateUI("<<lock<<")"<<"MainThread="<<wxThread::IsMain(),4)
395  mIsSelfUpdating=true;
396  mpField->SetValue(wxString::FromAscii(mValue.c_str()));
397  mIsSelfUpdating=false;
398  mNeedUpdateUI=false;
399  if(lock) mMutex.Unlock();
400  VFN_DEBUG_EXIT("WXFieldString::UpdateUI()",4)
401 }
403 {
404  VFN_DEBUG_MESSAGE("WXFieldString::Revert()",3)
405  wxMutexLocker mlock(mMutex);
407  mNeedUpdateUI=true;
408 }
410 {
411  VFN_DEBUG_MESSAGE("WXFieldString::ValidateUserInput()",6)
412  //:TODO: Check that the object is not busy (input should be frozen)
413  wxMutexLocker mlock(mMutex);
415  mValue=mpField->GetValue().ToAscii();
416  *mpString=mValue;
417 }
418 void WXFieldString::SetSize(int width, int height)
419 {
420  mpField->SetSize(width,height);
421  //wxTheApp->GetTopWindow()->SendSizeEvent();
422 }
423 
424 void WXFieldString::SetToolTip(const wxString& tip){mpField->SetToolTip(tip);}
425 
427 //
428 // WXFieldName
429 //
431 BEGIN_EVENT_TABLE(WXFieldName,wxWindow)
432  EVT_TEXT_ENTER(ID_WXFIELD, WXFieldName::OnEnter)
433  EVT_TEXT( ID_WXFIELD, WXFieldName::OnText)
434 END_EVENT_TABLE()
435 
436 WXFieldName::WXFieldName(wxWindow *parent,const string& label, WXCrystObj* owner,
437  const int id,const int hsize, bool isEditable):
438 WXField(parent,label,id),mpWXObj(owner),mValue(""),mIsSelfUpdating(false)
439 {
440  VFN_DEBUG_ENTRY("WXFieldName::WXFieldName()",6)
441  if(true==isEditable)
442  mpField=new wxTextCtrl(this,ID_WXFIELD,wxString::FromAscii(mValue.c_str()),
443  wxDefaultPosition,wxSize(hsize,-1),wxTE_PROCESS_ENTER,
444  wxTextValidator(wxFILTER_ASCII));
445  else
446  mpField=new wxTextCtrl(this,ID_WXFIELD,wxString::FromAscii(mValue.c_str()),
447  wxDefaultPosition,wxSize(hsize,-1),wxTE_READONLY,
448  wxTextValidator(wxFILTER_ASCII));
449 
450  mpSizer->Add(mpField,0,wxALIGN_CENTER);
451  //mpSizer->SetSizeHints(this);
452  this->Layout();
453  VFN_DEBUG_EXIT("WXFieldName::WXFieldName()",6)
454 }
455 
456 void WXFieldName::OnEnter(wxCommandEvent & WXUNUSED(event))
457 {
458  VFN_DEBUG_MESSAGE("WXFieldName::OnEnter()",6)
460 }
461 void WXFieldName::OnText(wxCommandEvent & WXUNUSED(event))
462 {
463  if(true==mIsSelfUpdating) return;
464  VFN_DEBUG_MESSAGE("WXFieldName::OnText():",6)
466  {
469  }
470 }
471 
472 void WXFieldName::SetValue(const string&s)
473 {
474  VFN_DEBUG_ENTRY("WXFieldName::SetValue()",3)
475  wxMutexLocker mlock(mMutex);
476  if(mValue==s)
477  {
478  VFN_DEBUG_EXIT("WXFieldName::SetValue():name unchanged",3)
479  return;
480  }
481  mValue=s;
482  mNeedUpdateUI=true;
483  VFN_DEBUG_EXIT("WXFieldName::SetValue()",3)
484 }
485 
486 const string WXFieldName::GetValue() const
487 {
488  VFN_DEBUG_MESSAGE("WXFieldName::GetValue()"<<mValue<<":"<<mpField->GetValue(),6)
489  return mValue;
490 }
491 void WXFieldName::CrystUpdate(const bool updateUI,const bool lock)
492 {
493  VFN_DEBUG_MESSAGE("WXFieldName::CrystUpdate()",3)
494  // The name must be updated by the owner
495 }
496 void WXFieldName::UpdateUI(const bool lock)
497 {
498  if(lock) mMutex.Lock();
499  if(mNeedUpdateUI==false)
500  {
501  if(lock) mMutex.Unlock();
502  return;
503  }
504  VFN_DEBUG_ENTRY("WXFieldName::UpdateUI("<<lock<<")"<<"MainThread="<<wxThread::IsMain(),4)
505  mIsSelfUpdating=true;
506  mpField->SetValue(wxString::FromAscii(mValue.c_str()));
507  //:TODO: Some way of resizing the field which is less of a kludge...
508  int w=mpField->GetTextExtent(wxString::FromAscii(mValue.c_str())).GetWidth();
509  const int wmax=wxTheApp->GetTopWindow()->GetSize().GetWidth();
510  if(w>wmax)w=wmax;
511  if(w>mpField->GetSize().GetWidth())
512  this->GetSizer()->SetItemMinSize(mpField,w+30,-1);
513  this->GetSizer()->Fit(this);
514 
515  mIsSelfUpdating=false;
516  mNeedUpdateUI=false;
517  if(lock) mMutex.Unlock();
518  VFN_DEBUG_EXIT("WXFieldName::UpdateUI()",4)
519 }
521 {
522  VFN_DEBUG_MESSAGE("WXFieldName::Revert()",3)
523  wxMutexLocker mlock(mMutex);
525  mNeedUpdateUI=true;
526 }
528 {
529  VFN_DEBUG_MESSAGE("WXFieldName::ValidateUserInput()",6)
530  mMutex.Lock();
532  mValue=mpField->GetValue().ToAscii();
533  mMutex.Unlock();
535 }
536 void WXFieldName::SetSize(int width, int height)
537 {//:TODO: deprecate this function ?
538  mpField->SetSize(width,height);
539 }
540 
541 void WXFieldName::SetToolTip(const wxString& tip){mpField->SetToolTip(tip);}
542 
544 //
545 // WXFieldParBase
546 //
548 BEGIN_EVENT_TABLE(WXFieldParBase,wxWindow)
549  EVT_TEXT_ENTER(ID_WXFIELD, WXFieldParBase::OnEnter)
550  EVT_TEXT( ID_WXFIELD, WXFieldParBase::OnText)
551 END_EVENT_TABLE()
552 
553 WXFieldParBase::WXFieldParBase(wxWindow *parent,const string& label,
554  const int id, const int hsize):
555 WXField(parent,label,id),mIsSelfUpdating(false),mFormat(_T("%8f"))
556 {
557  VFN_DEBUG_MESSAGE("WXFieldParBase::WXFieldName():End",6)
558 
559  mpField=new wxTextCtrl(this,ID_WXFIELD,_T(""),
560  wxDefaultPosition,wxSize(hsize,-1),wxTE_PROCESS_ENTER,
561  wxTextValidator(wxFILTER_NUMERIC));
562  mpSizer->Add(mpField,0,wxALIGN_CENTER);
563 
564  this->Layout();
565 }
566 
567 
568 void WXFieldParBase::OnEnter(wxCommandEvent & WXUNUSED(event))
569 {
570  VFN_DEBUG_MESSAGE("WXFieldRefPar::OnEnter()",6)
572 }
573 void WXFieldParBase::OnText(wxCommandEvent & WXUNUSED(event))
574 {
575  if(true==mIsSelfUpdating) return;
576  VFN_DEBUG_MESSAGE("WXFieldRefPar::OnText()",6)
578  {
581  }
582 }
584 {
585  VFN_DEBUG_MESSAGE("WXFieldRefPar::ValidateUserInput()",6)
586  this->ReadNewValue();
587 }
588 
589 void WXFieldParBase::SetToolTip(const wxString& tip){mpField->SetToolTip(tip);}
590 
591 void WXFieldParBase::SetFormat(const wxString &format)
592 {
593  mFormat=format;
594 }
595 
597 //
598 // WXFieldPar<T>
599 //
601 template<class T> WXFieldPar<T>::WXFieldPar(wxWindow *parent,const string& label,
602  const int id,T *par,const int hsize):
603 WXFieldParBase(parent,label,id,hsize),mpValue(par),mValue(*par),mValueOld(*par),mHumanScale(1)
604 {
605  this->CrystUpdate(true,true);
606 }
607 
608 template<> WXFieldPar<long>::WXFieldPar(wxWindow *parent,const string& label,
609  const int id,long *par,const int hsize):
610 WXFieldParBase(parent,label,id,hsize),mpValue(par),mValue(*par),mValueOld(*par),mHumanScale(1)
611 {
612  mFormat=_T("%ld");
613  this->CrystUpdate(true,true);
614 }
615 
616 template<class T> void WXFieldPar<T>::CrystUpdate(const bool uui,const bool lock)
617 {
618  if(lock) mMutex.Lock();
619  if(mValue==*mpValue)
620  {
621  if(lock) mMutex.Unlock();
622  return;
623  }
624  VFN_DEBUG_ENTRY("WXFieldPar<T>::CrystUpdate()",6)
625  mValueOld=mValue;
626  mValue=*mpValue;
627  mNeedUpdateUI=true;
628  if(lock) mMutex.Unlock();
629  if(uui) if(true==wxThread::IsMain()) this->UpdateUI(lock);
630  VFN_DEBUG_EXIT("WXFieldPar<T>::CrystUpdate()",6)
631 }
632 
633 template<> void WXFieldPar<REAL>::UpdateUI(const bool lock)
634 {
635  if(lock)mMutex.Lock();
636  if(mNeedUpdateUI==false)
637  {
638  if(lock)mMutex.Unlock();
639  return;
640  }
641  VFN_DEBUG_ENTRY("WXFieldPar<REAL>::UpdateUI("<<lock<<")"<<"MainThread="<<wxThread::IsMain(),4)
642  wxString tmp;
643  if((abs(mValue*mHumanScale)<1000)&&(abs(mValue*mHumanScale)>0.01)) tmp.Printf(_T("%6.4f"),mValue*mHumanScale);
644  else tmp.Printf(mFormat,mValue*mHumanScale);
645  mIsSelfUpdating=true;
646  mpField->SetValue(tmp);
647  mIsSelfUpdating=false;
648  mNeedUpdateUI=false;
649  if(lock)mMutex.Unlock();
650  VFN_DEBUG_EXIT("WXFieldPar<REAL>::UpdateUI()",4)
651 }
652 
653 template<> void WXFieldPar<long>::UpdateUI(const bool lock)
654 {
655  if(lock)mMutex.Lock();
656  if(mNeedUpdateUI==false)
657  {
658  if(lock)mMutex.Unlock();
659  return;
660  }
661  VFN_DEBUG_ENTRY("WXFieldPar<long>::UpdateUI("<<lock<<")"<<"MainThread="<<wxThread::IsMain(),4)
662  wxString tmp;
663  tmp.Printf(mFormat,mValue*mHumanScale);
664  mIsSelfUpdating=true;
665  mpField->SetValue(tmp);
666  mIsSelfUpdating=false;
667  mNeedUpdateUI=false;
668  if(lock)mMutex.Unlock();
669  VFN_DEBUG_EXIT("WXFieldPar<long>::UpdateUI()",4)
670 }
671 /*
672 template<class T> void WXFieldPar<T>::UpdateUI(const bool lock)
673 {
674  if(lock)mMutex.Lock();
675  if(mNeedUpdateUI==false)
676  {
677  if(lock)mMutex.Unlock();
678  return;
679  }
680  stringstream s;
681  s <<*mpValue;
682  mIsSelfUpdating=true;
683  mpField->SetValue(s.str().c_str());;
684  mpField->SetValue(wxString::Printf("%f",mValue));
685  mIsSelfUpdating=false;
686  mNeedUpdateUI=false;
687  if(lock)mMutex.Unlock();
688 }
689 */
690 
691 template<class T> void WXFieldPar<T>::Revert()
692 {
693  VFN_DEBUG_MESSAGE("WXFieldPar<T>::Revert()",6)
694  mMutex.Lock();
695  *mpValue=mValueOld;
696  mValue=mValueOld;
697  mNeedUpdateUI=true;
698  mMutex.Unlock();
699  if(true==wxThread::IsMain()) this->UpdateUI(true);
700 }
701 
702 template<class T> void WXFieldPar<T>::SetHumanValueScale(const T s)
703 {
704  mHumanScale=s;
705 }
706 
708 {
709  VFN_DEBUG_MESSAGE("WXFieldPar<REAL>::ReadNewValue()",6)
710  wxMutexLocker mlock(mMutex);
711  mValueOld=*mpValue;
712  wxString s=mpField->GetValue();
713  double tmp;
714  s.ToDouble(&tmp);
715  *mpValue=tmp;
716  *mpValue /= mHumanScale;
717 }
719 {
720  VFN_DEBUG_MESSAGE("WXFieldPar<long>::ReadNewValue()",6)
721  wxMutexLocker mlock(mMutex);
722  mValueOld=*mpValue;
723  wxString s=mpField->GetValue();
724  s.ToLong(mpValue);
725  *mpValue /= mHumanScale;
726 }
727 
728 
729 template class WXFieldPar<REAL>;
730 template class WXFieldPar<long>;
731 
732 
734 //
735 // WXFieldChoice
736 //
738 WXFieldChoice::WXFieldChoice
739  (wxWindow *parent,const int field_id,const string &name,const int hsize):
740 WXField(parent,name,field_id)
741 {
742  mpButton=new wxButton(this,field_id,wxString::FromAscii(name.c_str()),wxDefaultPosition,wxSize(hsize,-1));
743  mpSizer->Add(mpButton,0,wxALIGN_CENTER);
744  //mpSizer->SetItemMinSize(mpButton,
745  // mpButton->GetSize().GetWidth(),
746  // mpButton->GetSize().GetHeight());
747  //mpSizer->SetSizeHints(this);
748  this->Layout();
749 }
750 
751 void WXFieldChoice::CrystUpdate(const bool uui,const bool lock)
752 {
753  //Nothing to do. This should be done by the owner
754 }
755 void WXFieldChoice::UpdateUI(const bool lock)
756 {
757  //Nothing to do. This should be done by the owner
758 }
759 
761 {
762  //Nothing to do. This should be done by the owner
763 }
764 void WXFieldChoice::SetValue(const string&name)
765 {
766  mpButton->SetLabel(wxString::FromAscii(name.c_str()));
767 }
769 
771 //
772 // WXCrystObj
773 //
775 const long ID_WXOBJ_ENABLE=WXCRYST_ID(); //These are used in ObjCryst/RefinableObj.cpp
776 const long ID_WXOBJ_DISABLE=WXCRYST_ID();
777 BEGIN_EVENT_TABLE(WXCrystObj,wxWindow)
778  EVT_BUTTON(ID_WXOBJ_COLLAPSE,WXCrystObj::OnToggleCollapse)
779  EVT_UPDATE_UI(ID_WXOBJ_ENABLE,WXCrystObj::OnEnable)
780  EVT_UPDATE_UI(ID_WXOBJ_DISABLE,WXCrystObj::OnEnable)
781 END_EVENT_TABLE()
782 
783 WXCrystObj::WXCrystObj(wxWindow* parent,int orient,bool showName):
784 WXCrystObjBasic(parent),mIsExpanded(true)
785 {
786  VFN_DEBUG_ENTRY("WXCrystObj::WXCrystObj()",6)
787  mpTopSizer= new wxBoxSizer(orient);
788  this->SetSizer(mpTopSizer);
789 
790  mpCollapseButton=new wxButton(this,ID_WXOBJ_COLLAPSE,_T("-"),
791  wxDefaultPosition,wxSize(14,14));
792  mpTopSizer->Add(mpCollapseButton,0, wxALIGN_TOP);//wxRIGHT | wxTOP | wxALIGN_TOP,4
793  //mpCollapseButton->PushEventHandler(this);
794 
795  mpSizer=new wxBoxSizer(wxVERTICAL);
796  mpTopSizer->Add(mpSizer,0, wxALIGN_TOP);
797 
798  if(showName)
799  {
800  mpWXTitle = new WXFieldName(this,"name:",this,ID_WXOBJ_NAME,100);
801  mpSizer->Add(mpWXTitle,0,wxALIGN_LEFT);
802  }else mpWXTitle=0;
803 
804  //this->Layout();
805  VFN_DEBUG_EXIT("WXCrystObj::WXCrystObj():End",6)
806 }
807 
808 WXCrystObj::~WXCrystObj()
809 {
810  //if(0!=mpWXTitle)
811  //{
812  // delete mpWXTitle;
813  //}
814  //delete mpCollapseButton;
815  //sizers are automatically deleted
816 }
817 
818 void WXCrystObj::OnToggleCollapse(wxCommandEvent & WXUNUSED(event))
819 {
820  #if 0
821  VFN_DEBUG_MESSAGE("WXCrystObj::OnToggleCollapse()",6)
824  if(true==mIsExpanded) mpCollapseButton->SetLabel("-");
825  else mpCollapseButton->SetLabel("+");
826  this->Layout();
827  VFN_DEBUG_MESSAGE("WXCrystObj::OnToggleCollapse():End",6)
828  #endif
829 }
830 
831 void WXCrystObj::CrystUpdate(const bool uui,const bool lock)
832 {
833  VFN_DEBUG_ENTRY("WXCrystObj::CrystUpdate("<<uui<<lock<<")",6)
834  //if(lock) mMutex.Lock();
835  mList.CrystUpdate(uui,lock);
836  //if(lock) mMutex.Unlock();
837  VFN_DEBUG_EXIT("WXCrystObj::CrystUpdate()",6)
838 }
839 void WXCrystObj::UpdateUI(const bool lock)
840 {
841  VFN_DEBUG_ENTRY("WXCrystObj::UpdateUI("<<lock<<")"<<"MainThread="<<wxThread::IsMain(),6)
842  if(lock) mMutex.Lock();
843  if(mpWXTitle!=0) mpWXTitle->UpdateUI(false);
844  mList.UpdateUI(false);
845  if(lock) mMutex.Unlock();
846  VFN_DEBUG_EXIT("WXCrystObj::UpdateUI()",6)
847 }
848 void WXCrystObj::OnEnable(wxUpdateUIEvent &event)
849 {
850  if(ID_WXOBJ_ENABLE==event.GetId()) this->Enable(true);
851  else this->Enable(false);
852  event.Skip();
853 }
854 bool WXCrystObj::Enable(bool enable)
855 {
856  mList.Enable(enable);
857  return this->wxWindow::Enable(enable);
858 }
859 
860 void WXCrystObj::AddChild(WXCrystObjBasic *pChild, bool doBottomLayout)
861 {
862  VFN_DEBUG_ENTRY("WXCrystObj::AddChild(..)"<<this->GetSize().GetWidth()<<","<<this->GetSize().GetHeight(),5);
863  if(mpSizer!=0)
864  {
865  mpSizer->Add(pChild);
866  }
867  if(doBottomLayout) wxTheApp->GetTopWindow()->SendSizeEvent();
868  VFN_DEBUG_EXIT("WXCrystObj::AddChild(..)"<<this->GetSize().GetWidth()<<","<<this->GetSize().GetHeight(),5);
869 }
870 
872 //
873 // WXCrystMenuBar
874 //
876 WXCRYST_ID ID_CRYST_MENU1;
877 WXCRYST_ID ID_CRYST_MENU2;
878 WXCRYST_ID ID_CRYST_MENU3;
879 WXCRYST_ID ID_CRYST_MENU4;
880 WXCRYST_ID ID_CRYST_MENU5;
881 WXCRYST_ID ID_CRYST_MENU6;
882 WXCRYST_ID ID_CRYST_MENU7;
883 WXCRYST_ID ID_CRYST_MENU8;
884 WXCRYST_ID ID_CRYST_MENU9;
885 WXCRYST_ID ID_CRYST_MENU10;
886 WXCRYST_ID ID_CRYST_MENU11;
887 WXCRYST_ID ID_CRYST_MENU12;
888 WXCRYST_ID ID_CRYST_MENU13;
889 WXCRYST_ID ID_CRYST_MENU14;
890 WXCRYST_ID ID_CRYST_MENU15;
891 WXCRYST_ID ID_CRYST_MENU16;
892 
893 
894 BEGIN_EVENT_TABLE(WXCrystMenuBar,wxWindow)
895  EVT_BUTTON(ID_CRYST_MENU1 ,WXCrystMenuBar::OnPopupMenu)
896  EVT_BUTTON(ID_CRYST_MENU2 ,WXCrystMenuBar::OnPopupMenu)
897  EVT_BUTTON(ID_CRYST_MENU3 ,WXCrystMenuBar::OnPopupMenu)
898  EVT_BUTTON(ID_CRYST_MENU4 ,WXCrystMenuBar::OnPopupMenu)
899  EVT_BUTTON(ID_CRYST_MENU5 ,WXCrystMenuBar::OnPopupMenu)
900  EVT_BUTTON(ID_CRYST_MENU6 ,WXCrystMenuBar::OnPopupMenu)
901  EVT_BUTTON(ID_CRYST_MENU7 ,WXCrystMenuBar::OnPopupMenu)
902  EVT_BUTTON(ID_CRYST_MENU8 ,WXCrystMenuBar::OnPopupMenu)
903  EVT_BUTTON(ID_CRYST_MENU9 ,WXCrystMenuBar::OnPopupMenu)
904 END_EVENT_TABLE()
905 
906 WXCrystMenuBar::WXCrystMenuBar(wxWindow *parent, WXCrystObj* owner):
907 WXCrystObjBasic(parent)
908 {
909  VFN_DEBUG_MESSAGE("WXCrystMenuBar::WXCrystMenuBar():",6)
910  mpSizer=new wxBoxSizer(wxHORIZONTAL);
911  this->SetSizer(mpSizer);
912 }
913 
914 void WXCrystMenuBar::AddMenu(const string &name,const int menuId, const string& help)
915 {
916  VFN_DEBUG_MESSAGE("WXCrystMenuBar::AddMenu()",6)
917  const long id=ID_CRYST_MENU1+mvpMenu.size();
918  mvpMenu[menuId]=make_pair(new wxMenu(wxString::FromAscii(name.c_str())),
919  new wxButton(this,id,wxString::FromAscii(name.c_str())));
920  VFN_DEBUG_MESSAGE("WXCrystMenuBar::AddMenu():2",6)
921  mvpMenu[menuId].second->Layout();
922  mpSizer->Add(mvpMenu[menuId].second,0,wxALIGN_CENTER);
923  //wxTheApp->GetTopWindow()->SendSizeEvent();
924  VFN_DEBUG_MESSAGE("WXCrystMenuBar::AddMenu():End",6)
925 }
926 
927 wxMenu& WXCrystMenuBar::GetMenu(const int menuId)
928 {
929  //:TODO: Check we found the correct menu
930  return *(mvpMenu[menuId].first);
931 }
932 
933 void WXCrystMenuBar::AddMenuItem(const int menuId, int id, const string& item, const string& help,const bool checkable)
934 {
935  VFN_DEBUG_MESSAGE("WXCrystMenuBar::AddMenuItem():",6)
936  //:TODO: Check we found the correct menu
937  this->GetMenu(menuId).Append(id,wxString::FromAscii(item.c_str()),wxString::FromAscii(help.c_str()),checkable);
938 }
939 
940 void WXCrystMenuBar::AddMenuItem(const int menuId,int id, const wxString& item,
941  wxMenu *subMenu, const wxString& helpString)
942 {
943  VFN_DEBUG_MESSAGE("WXCrystMenuBar::AddMenuItem():",6)
944  //:TODO: Check we found the correct menu
945  this->GetMenu(menuId).Append(id,item,subMenu,helpString);
946 }
947 
948 void WXCrystMenuBar::CrystUpdate(const bool updateUI,const bool mutexlock)
949 {
950 }
951 void WXCrystMenuBar::UpdateUI(const bool mutexlock)
952 {
953 }
954 
955 void WXCrystMenuBar::OnPopupMenu(wxCommandEvent & event)
956 {
957  VFN_DEBUG_MESSAGE("WXCrystMenuBar::OnPopupMenu():",6)
958  // The ID of the button is not the same as the ID of the menu,
959  // so look it up. (to have the same ID we'd need to delegate event handling,
960  // which would be a pain.
961  std::map<long,pair<wxMenu *,wxButton*> >::iterator pos;
962  const int i=event.GetId();
963  for(pos=mvpMenu.begin();pos!=mvpMenu.end();++pos) if(i==pos->second.second->GetId()) break;
964  if(pos!=mvpMenu.end())
965  this->PopupMenu(pos->second.first,pos->second.second->GetPosition());
966 }
967 void WXCrystMenuBar::SetToolTip(const wxString& tip,long menuId){mvpMenu[menuId].second->SetToolTip(tip);}
968 
969 }//namespace
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: doc-main.h:25
void WXCrystValidateAllUserInput()
This function validates all user input (in a WXField) not yet taken into account, if needs be.
Definition: wxCryst.cpp:258
WXField * spLastWXFieldInputNotValidated
This pointer records the last wxField in which something was enetered, so that it can be validated wh...
Definition: wxCryst.cpp:256
XMLConfigHistory gConfigHistory
Global object to hold configurations history.
Definition: Undo.cpp:26
std::map< wxWindowID, std::pair< wxPoint, wxSize > > gvWindowPosition
Used to remember window positions.
Definition: wxCryst.cpp:52
bool Store()
Store a new configuration.
Definition: Undo.cpp:362
Class to automatically assign a unique wxID to each window.
Definition: wxCryst.h:75
Abstract base class for all objects in wxCryst.
Definition: wxCryst.h:128
virtual ~WXCrystObjBasic()
Destructor.
Definition: wxCryst.cpp:144
CrystMutex mMutex
Mutex used to lock data when preparing to update the UI in non-main thread.
Definition: wxCryst.h:189
virtual void SetToolTip(const wxString &tip)
Set tooltip for this window.
Definition: wxCryst.cpp:180
void AddedToList(WXCrystObjBasicList *list)
Definition: wxCryst.cpp:172
void RemovedFromList(WXCrystObjBasicList *list)
Definition: wxCryst.cpp:173
WXCrystObjBasic * mWXCrystParent
Parent, if a WXCrystObjBasic itself.
Definition: wxCryst.h:183
bool mNeedUpdateUI
Do we need to update the display ?
Definition: wxCryst.h:187
virtual void AddChild(WXCrystObjBasic *pChild, bool doBottomLayout=true)
Notify that a new children has been added, also adding it to the correct sizer (which can be the top ...
Definition: wxCryst.cpp:160
std::set< WXCrystObjBasicList * > mvpList
WXCrystObjBasicList which are aware of this object, and which should be told on destruction.
Definition: wxCryst.h:192
A List of WXCrystObjBasic.
Definition: wxCryst.h:197
void Remove(WXCrystObjBasic *)
remove an object from the list
Definition: wxCryst.cpp:207
unsigned int GetNb() const
Number of objects.
Definition: wxCryst.cpp:198
void UpdateUI(const bool mutexlock=false)
Forces all objects in the list to update.
Definition: wxCryst.cpp:234
void Add(WXCrystObjBasic *)
Add an object to the list.
Definition: wxCryst.cpp:200
std::set< WXCrystObjBasic * > mvpWXCrystObj
List of pointers to the objects.
Definition: wxCryst.h:231
WXCrystObjBasicList()
Constructor.
Definition: wxCryst.cpp:187
void CrystUpdate(const bool updateUI=false, const bool mutexlock=false)
Forces all objects in the list to update.
Definition: wxCryst.cpp:224
bool Show(bool)
Show or hide all of the windows.
Definition: wxCryst.cpp:214
~WXCrystObjBasicList()
Destructor.
Definition: wxCryst.cpp:190
Base class for all displayed ObjCryst objects (with a title, and a sizer to stack objects).
Definition: wxCryst.h:249
WXFieldName * mpWXTitle
The title.
Definition: wxCryst.h:273
bool mIsExpanded
To be used for collapsing the sub-objects.
Definition: wxCryst.h:275
wxBoxSizer * mpSizer
Sizer including all sub-objects.
Definition: wxCryst.h:271
virtual void CrystUpdate(const bool updateUI=false, const bool mutexlock=false)
Get new values to be displayed from the underlying object, and raise flag if an UI update is necessar...
Definition: wxCryst.cpp:831
virtual void AddChild(WXCrystObjBasic *pChild, bool doBottomLayout=true)
Notify that a new children has been added, also adding it to the correct sizer (which can be the top ...
Definition: wxCryst.cpp:860
WXCrystObjBasicList mList
All windows but the title and collapse button are in this list.
Definition: wxCryst.h:277
virtual bool OnChangeName(const int id)=0
When a WXFieldName has been changed by the user, it is handled here.
virtual void UpdateUI(const bool mutexlock=false)
Update the User Interface, if necessary.
Definition: wxCryst.cpp:839
wxButton * mpCollapseButton
The collapse button.
Definition: wxCryst.h:279
void OnToggleCollapse(wxCommandEvent &WXUNUSED(event))
Only display the title, and collapse everything else.
Definition: wxCryst.cpp:818
This is the abstract base class for all fields, wether they contain a floating-point parameter,...
Definition: wxCryst.h:292
void SetLabel(const string &)
Change the field's label.
Definition: wxCryst.cpp:290
wxStaticText * mpLabel
The label.
Definition: wxCryst.h:314
virtual bool SetForegroundColour(const wxColour &colour)
Change the colour of the field's title.
Definition: wxCryst.cpp:296
WXField(wxWindow *parent, const string &label, const int field_id)
Constructor, specifying the label of the field.
Definition: wxCryst.cpp:278
wxBoxSizer * mpSizer
The horizontal sizer in which the title, button, fields, are put.
Definition: wxCryst.h:312
virtual void SetSize(int width, int height)
Change the size of the field (excluding the title)
Definition: wxCryst.cpp:303
virtual void ValidateUserInput()=0
This function shall be called when a new value has been entered.
const int mId
The Id of this field.
Definition: wxCryst.h:316
A field which directly links to a string.
Definition: wxCryst.h:329
void Revert()
After a user entry, this allows to go back to the last value, if for some reason the entry was reject...
Definition: wxCryst.cpp:402
void OnText(wxCommandEvent &WXUNUSED(event))
Records when text is entered (either from self-updating or user input)
Definition: wxCryst.cpp:340
virtual void SetSize(int width, int height)
Change the size of the field (excluding the title)
Definition: wxCryst.cpp:418
void SetValue(const string &)
This actually posts an UpdateUI event, so that it is safe to call it from a non-graphic thread.
Definition: wxCryst.cpp:351
string mValueOld
Last name displayed, before the value was changed by the user.
Definition: wxCryst.h:361
void OnEnter(wxCommandEvent &event)
When a new value is entered (must type it and then hit the 'enter' key).
Definition: wxCryst.cpp:335
const string GetValue() const
Get the current name.
Definition: wxCryst.cpp:365
string mValue
Last name displayed.
Definition: wxCryst.h:356
bool mIsSelfUpdating
Set to true if the Field is being updated, so that no 'EVT_TEXT' is understood as user input.
Definition: wxCryst.h:364
wxTextCtrl * mpField
The text window.
Definition: wxCryst.h:358
virtual void CrystUpdate(const bool updateUI=false, const bool mutexlock=false)
Get new values to be displayed from the underlying object, and raise flag if an UI update is necessar...
Definition: wxCryst.cpp:370
virtual void ValidateUserInput()
This function shall be called when a new value has been entered.
Definition: wxCryst.cpp:409
virtual void UpdateUI(const bool mutexlock=false)
Update the User Interface, if necessary.
Definition: wxCryst.cpp:386
virtual void SetToolTip(const wxString &tip)
Set tooltip for this window. It will be activated when going over the entry field.
Definition: wxCryst.cpp:424
string * mpString
The WXCrystObj whose name is shown here.
Definition: wxCryst.h:354
A field with the name of a WXCrystObj.
Definition: wxCryst.h:372
virtual void CrystUpdate(const bool updateUI=false, const bool mutexlock=false)
This does nothing.
Definition: wxCryst.cpp:491
wxTextCtrl * mpField
The text window.
Definition: wxCryst.h:403
void SetValue(const string &)
This actually posts an UpdateUI event, so that it is safe to call it from a non-graphic thread.
Definition: wxCryst.cpp:472
string mValueOld
Last name displayed, before the value was changed by the user.
Definition: wxCryst.h:406
bool mIsSelfUpdating
Set to true if the Field is being updated, so that no 'EVT_TEXT' is understood as user input.
Definition: wxCryst.h:409
void Revert()
After a user entry, this allows to go back to the last value, if for some reason the entry was reject...
Definition: wxCryst.cpp:520
virtual void UpdateUI(const bool mutexlock=false)
Update the User Interface, if necessary.
Definition: wxCryst.cpp:496
virtual void SetSize(int width, int height)
Change the size of the field (excluding the title)
Definition: wxCryst.cpp:536
virtual void SetToolTip(const wxString &tip)
Set tooltip for this window. It will be activated when going over the entry field.
Definition: wxCryst.cpp:541
string mValue
Last name displayed.
Definition: wxCryst.h:401
virtual void ValidateUserInput()
This function shall be called when a new value has been entered.
Definition: wxCryst.cpp:527
void OnText(wxCommandEvent &WXUNUSED(event))
Records when text is entered (either from self-updating or user input)
Definition: wxCryst.cpp:461
WXCrystObj * mpWXObj
The WXCrystObj whose name is shown here.
Definition: wxCryst.h:399
void OnEnter(wxCommandEvent &event)
When a new value is entered (must type it and then hit the 'enter' key).
Definition: wxCryst.cpp:456
const string GetValue() const
Get the current name.
Definition: wxCryst.cpp:486
A field for a parameter.
Definition: wxCryst.h:417
bool mIsSelfUpdating
Set to true if the Field is being updated, so that no 'EVT_TEXT' is understood as user input.
Definition: wxCryst.h:444
void OnEnter(wxCommandEvent &WXUNUSED(event))
When a new value is entered (must type it and then hit the 'enter' key).
Definition: wxCryst.cpp:568
virtual void SetToolTip(const wxString &tip)
Set tooltip for this window. It will be activated when going over the entry field.
Definition: wxCryst.cpp:589
wxString mFormat
Format to be used, default = _T("%8f")
Definition: wxCryst.h:446
wxTextCtrl * mpField
The field in which the value is written.
Definition: wxCryst.h:441
virtual void ValidateUserInput()
This function shall be called when a new value has been entered.
Definition: wxCryst.cpp:583
virtual void ReadNewValue()=0
Reads the new value when the Enter key is hit.
void OnText(wxCommandEvent &WXUNUSED(event))
Records when text is entered (either from self-updating or user input)
Definition: wxCryst.cpp:573
void SetFormat(const wxString &format)
Set Format.
Definition: wxCryst.cpp:591
A field for a parameter.
Definition: wxCryst.h:453
virtual void UpdateUI(const bool mutexlock=false)
Update the User Interface, if necessary.
virtual void CrystUpdate(const bool updateUI=false, const bool mutexlock=false)
This gets a new value from the parameter.
Definition: wxCryst.cpp:616
WXFieldPar(wxWindow *parent, const string &label, const int field_id, T *par, const int hsize=65)
Constructor.
Definition: wxCryst.cpp:601
void Revert()
After a user entry, this allows to go back to the last value, if for some reason the entry was reject...
Definition: wxCryst.cpp:760
virtual void CrystUpdate(const bool updateUI=false, const bool mutexlock=false)
Does nothing.
Definition: wxCryst.cpp:751
wxButton * mpButton
The button to be clicked to change the value.
Definition: wxCryst.h:499
virtual void UpdateUI(const bool mutexlock=false)
Does nothing.
Definition: wxCryst.cpp:755
void SetValue(const string &)
Used by the owner to change the name of the choice.
Definition: wxCryst.cpp:764
virtual void ValidateUserInput()
Unnecessary here. Any change is immediately taken into account.
Definition: wxCryst.cpp:768
Our own local menu bar, using buttons and Popup menus.
Definition: wxCryst.h:504
wxBoxSizer * mpSizer
The sizer of the menu.
Definition: wxCryst.h:526
virtual void SetToolTip(const wxString &tip, long menu=0)
Set tooltip for each menu.
Definition: wxCryst.cpp:967
wxMenu & GetMenu(const int menuId)
Get access to a menu.
Definition: wxCryst.cpp:927
void AddMenuItem(const int menuId, int id, const string &item, const string &help="", const bool checkable=false)
Add an entry to a menu.
Definition: wxCryst.cpp:933
std::map< long, pair< wxMenu *, wxButton * > > mvpMenu
List of menus, first is the menu Id and second is a pair of <pointer to the menu, pointer to the butt...
Definition: wxCryst.h:529
virtual void UpdateUI(const bool mutexlock=false)
Update the User Interface, if necessary.
Definition: wxCryst.cpp:951
void AddMenu(const string &name, const int menuId, const string &help="")
Add a menu.
Definition: wxCryst.cpp:914
virtual void CrystUpdate(const bool updateUI=false, const bool mutexlock=false)
Get new values to be displayed from the underlying object, and raise flag if an UI update is necessar...
Definition: wxCryst.cpp:948
void OnPopupMenu(wxCommandEvent &event)
Event handler to popu the menu when the button is clicked.
Definition: wxCryst.cpp:955