1 /***************************************************************************
2                           gdlwidget  -  base class for GDL widgets
3                              -------------------
4     begin                : Fri May 7 2004
5     copyright            : (C) 2004 by Marc Schellens
6     email                : m_schellens@users.sourceforge.net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 
19 #ifndef GDLWIDGET_HPP
20 #define GDLWIDGET_HPP
21 
22 #ifdef HAVE_LIBWXWIDGETS
23 // #define GDL_DEBUG_WIDGETS
24 // #define GDL_DEBUG_WIDGETS_COLORIZE
25 
26 // use "plain menubars" instead of 'taskbars used as menubars'. taskbars permit to change font in bar, put pixmaps instead of text, and will work
27 // on OSX. So we choose normally to undefine this
28 // #define PREFERS_MENUBAR 1
29 #include <wx/wx.h>
30 #include <wx/app.h>
31 #include <wx/panel.h>
32 #include <wx/treebase.h>
33 #include <wx/treectrl.h>
34 #include <wx/grid.h>
35 #ifdef HAVE_WXWIDGETS_PROPERTYGRID
36 //#include <wx/propgrid/propgrid.h>
37 #endif
38 #include <wx/defs.h>//for timer.
39 #include <wx/gdicmn.h>
40 #include <wx/imaglist.h>
41 #include <wx/artprov.h>
42 #include <wx/popupwin.h>
43 #include <wx/notebook.h>
44 #include <wx/dcbuffer.h>
45 #include <wx/toolbar.h>
46 #include <wx/listbox.h>
47 #include <deque>
48 #include <map>
49 
50 #include "typedefs.hpp"
51 #include "str.hpp"
52 #include "datatypes.hpp"
53 #include "widget.hpp"
54 
55 #define gdlSCROLL_RATE 20
56 #define gdlSCROLL_HEIGHT_X  sysScrollHeight //wxSystemSettings::GetMetric(wxSYS_VSCROLL_X,xxx) //25
57 #define gdlSCROLL_WIDTH_Y sysScrollWidth //wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y,xxx) //25
58 #define gdlABSENT_SIZE_VALUE 15;
59 #define gdlDEFAULT_XSIZE 100
60 #define gdlDEFAULT_YSIZE 100
61 #define gdlCOMBOBOX_ARROW_WIDTH sysComboboxArrow
62 #define gdlDEFAULT_SCROLL_SIZE 100 //gdlDEFAULT_XSIZE+gdlSCROLL_HEIGHT_X
63 #define gdlFRAME_MARGIN 0
64 #define gdlPAD 0 //3 //default padding
65 #define gdlSPACE 0
66 #define gdlLABEL_SPACE 2
67 #define gdlTEXT_SPACE 4
68 #define gdlBUTTON_SPACE 4
69 #define gdlSMALL_SPACE 1
70 #define gdlBORDER_SPACE 2
71 #define gdlBORDER_EXT wxBORDER_THEME // wxBORDER_SUNKEN //wxBORDER_RAISED//wxBORDER_SIMPLE //wxBORDER_RAISED
72 #define gdlBORDER_INT wxBORDER_NONE //wxBORDER_SUNKEN
73 #define gdlTEXT_XMARGIN 4
74 #define gdlTEXT_YMARGIN 4
75 #define DONOTALLOWSTRETCH 0
76 #define ALLOWSTRETCH 1
77 #define FRAME_ALLOWSTRETCH 1
78 #define DEFAULT_TREE_IMAGE_SIZE 16
79 
80 #ifdef __WXMSW__
81   #define NEWLINECHARSIZE 2  //length of <cr><nl>
82 #else
83   #define NEWLINECHARSIZE 1  //length of <nl>
84 #endif
85 
86 #define gdlSIZE_EVENT_HANDLER wxSizeEventHandler(gdlwxFrame::OnSizeWithTimer) //filter mouse events (manual resize) to avoid too many updtes for nothing
87 #define gdlSIZE_IMMEDIATE_EVENT_HANDLER wxSizeEventHandler(gdlwxFrame::OnSize)
88 typedef DLong WidgetIDT;
89 static std::string widgetNameList[]={"BASE","BUTTON","SLIDER","TEXT","DRAW","LABEL","LIST","MBAR","DROPLIST","TABLE","TAB","TREE","COMBOBOX","PROPERTYSHEET","WINDOW"};
90 static int    widgetTypeList[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
91 static bool handlersInited=false; //handlers of graphic formats for bitmaps (magick).
92 
93 enum { WINDOW_TIMER = -2*wxID_HIGHEST, RESIZE_TIMER, RESIZE_PLOT_TIMER }; //negative values, should not clash with our (positive) widget ids.
94 enum {
95   TREE_BITMAP_ITEM = 0,
96   TREE_BITMAP_ITEM_SELECTED = 0,
97   TREE_BITMAP_FOLDER,
98   TREE_BITMAP_FOLDER_OPEN,
99   TREE_BITMAP_END
100 };
101 enum {
102   gdlWxTree_UNCHECKED = 0,
103   gdlWxTree_CHECKED
104 };
105 class DStructGDL;
106 
107 // thread safe deque
108 class GDLEventQueue
109 {
110 private:
111   std::deque<DStructGDL*> dq;
112 public:
GDLEventQueue()113   GDLEventQueue() //normally we should have ~GDLEventQueue removing the DStructGDLs?
114   {}
115 
Pop()116   DStructGDL* Pop()
117   {
118     if( dq.empty())
119       return NULL;
120 //    if( dq.empty()) // needed again for thread safe behaviour
121 //      return NULL;
122     DStructGDL* front = dq.front();
123     dq.pop_front();
124     return front;
125   }
126   // for all regular events
PushBack(DStructGDL * ev)127   void PushBack( DStructGDL* ev)
128   {
129     dq.push_back( ev);
130   }
131   // for priority events (like delete widget)
PushFront(DStructGDL * ev)132   void PushFront( DStructGDL* ev)
133   {
134     dq.push_front( ev);
135   }
136   // Not good: between call of Empty and Pop another thread's Pop could be executed
137 //           -> Empty is useless (dangerous) for polling
138 // although: as used here (there is only one thread calling Pop) it would work
139 //   bool Empty() const
140 //   {
141 //     return isEmpty;
142 //   }
143   void Purge();
144   void Purge( WidgetIDT topID);
145 };
146 
147 // all locker classes are identical. For control of locking separately
148 // class GUIMutexLockerT
149 // {
150 //   bool left;
151 // public:
152 //   GUIMutexLockerT(): left(false) { wxMutexGuiEnter();}
153 //   ~GUIMutexLockerT() { if(!left) wxMutexGuiLeave();}
154 //   void Leave() { wxMutexGuiLeave(); left=true;}
155 // };
156 
157 class GDLWidget;
158 
159 // global widget list type
160 // typedef DLong                       WidgetIDT;
161 // typedef std::map<WidgetIDT, GDLWidget*> WidgetListT;
162 // typedef std::deque<DStructGDL*> EventQueueT;
163 
164 class WidgetListT
165 {
166 public:
167   typedef std::map<WidgetIDT, GDLWidget*> mapT;
168   typedef mapT::iterator iterator;
169   typedef mapT::size_type size_type;
170   typedef WidgetIDT key_type;
171   typedef GDLWidget* mapped_type;
172   typedef std::pair<const key_type,mapped_type> value_type;
173 
174 private:
175   mapT map;
176 
177 public:
WidgetListT()178   WidgetListT(): map(){}
~WidgetListT()179   ~WidgetListT() {}
180 
erase(iterator position)181   void erase (iterator position)
182   {
183     map.erase(position);
184   }
erase(const key_type & k)185   size_type erase (const key_type& k)
186   {
187     return map.erase(k);
188   }
find(const key_type & k)189   iterator find (const key_type& k)
190   {
191     return map.find(k);
192   }
begin()193   iterator begin()
194   {
195     return map.begin();
196   }
end()197   iterator end()
198   {
199     return map.end();
200   }
201 
insert(iterator position,value_type val)202   iterator insert (iterator position, value_type val)
203   {
204     return map.insert( position, val);
205   }
206 };
207 
208 class WidgetEventInfo {
209 public:
210  wxEventType t;
211  wxObjectEventFunction f;
212  wxWindow* w;
213 
WidgetEventInfo(wxEventType t_,wxObjectEventFunction f_,wxWindow * w_)214  WidgetEventInfo(wxEventType t_, wxObjectEventFunction f_, wxWindow* w_) : t(t_), f(f_), w(w_) {
215  }
216 };
217 #ifndef __WXMAC__
218 // main App class
219 class wxAppGDL: public wxApp
220 {
221  wxEventLoopBase* loop;
222 public:
OnRun()223  int OnRun(){return 0;}
224  int OnExit();
225  int MainLoop();
226 // virtual int OneLoop();
227  bool OnInit();
228 // bool Pending(); //Returns true if unprocessed events are in the window system event queue.
229 // int FilterEvent(wxEvent& event) //This function is called before processing any event and
230 //allows the application to preempt the processing of some events. If this method returns -1
231 //the event is processed normally, otherwise either true or false should be returned and
232 //the event processing stops immediately considering that the event had been already processed
233 //(for the former return value) or that it is not going to be processed at all (for the latter one).
234 };
235 wxDECLARE_APP(wxAppGDL); //wxAppGDL is equivalent to wxGetApp()
236 #endif
237 
238 // GDL versions of wxWidgets controls =======================================
239 DECLARE_LOCAL_EVENT_TYPE(wxEVT_SHOW_REQUEST, -1)
240 DECLARE_LOCAL_EVENT_TYPE(wxEVT_HIDE_REQUEST, -1)
241 
242 
243 // GUI base class **********************************
244 class GDLWidgetBase;
245 class GDLWidgetTopBase;
246 class GDLWidgetContainer;
247 
248 class gdlwxFrame : public wxFrame {
249 
250  bool mapped;
251  wxSize frameSize;
252  wxTimer * m_resizeTimer;
253  GDLWidgetTopBase* gdlOwner;
254 
255 public:
256 
257  // ctor(s)
258  gdlwxFrame(wxWindow* parent, GDLWidgetTopBase* gdlOwner_, wxWindowID id, const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE);
259  ~gdlwxFrame();
260  // called from ~GDLWidgetBase
NullGDLOwner()261  void NullGDLOwner() {
262   gdlOwner = NULL;
263  }
264 
GetGDLOwner()265  GDLWidgetTopBase* GetGDLOwner() {
266   return gdlOwner;
267  }
268 
IsMapped() const269  bool IsMapped() const {
270   return mapped;
271  }
272 
SendShowRequestEvent()273   void SendShowRequestEvent() {
274   wxCommandEvent* event;
275   event = new wxCommandEvent(wxEVT_SHOW_REQUEST, GetId());
276   event->SetEventObject(this);
277   // only for wWidgets > 2.9 (takes ownership of event)
278   //     this->QueueEvent( event);
279 //  this->AddPendingEvent(*event); // copies event
280   this->OnShowRequest(*event); // JP Apr 2015: Should block the main thread until the window opens,
281   //              so that the following WIDGET_INFO can properly read
282   //              the window's properties.
283   delete event;
284   mapped = true;
285  }
286 
SendHideRequestEvent()287  void SendHideRequestEvent() {
288   wxCommandEvent* event;
289   event = new wxCommandEvent(wxEVT_HIDE_REQUEST, GetId());
290   event->SetEventObject(this);
291   // only for wWidgets > 2.9 (takes ownership of event)
292   //     this->QueueEvent( event);
293   this->AddPendingEvent(*event); // copies event
294   delete event;
295   mapped = false;
296  }
297 
GetFrameSize()298  wxSize GetFrameSize(){return frameSize;}
SetFrameSize(wxSize & sz)299  void SetFrameSize(wxSize &sz){frameSize=sz;}
refreshFrameSize()300  void refreshFrameSize(){frameSize=this->GetSize();}
301 
302  // event handlers (these functions should _not_ be virtual)
303  void OnDropList(wxCommandEvent& event);
304  void OnListBox(wxCommandEvent& event);
305  void OnListBoxDoubleClicked(wxCommandEvent& event);
306  void OnComboBox(wxCommandEvent& event);
307  void OnComboBoxTextEnter(wxCommandEvent& event);
308  void OnButton(wxCommandEvent& event);
309  void OnRadioButton(wxCommandEvent& event);
310  void OnCheckBox(wxCommandEvent& event);
311  void OnPageChanged(wxNotebookEvent& event);
312  void OnText(wxCommandEvent& event);
313  void OnTextMouseEvents(wxMouseEvent& event);
314  void OnTextPaste(wxClipboardTextEvent& event);
315  void OnTextCut(wxClipboardTextEvent& event);
316  //  void OnTextEnter( wxCommandEvent& event); //NOT USED
317  void OnThumbTrack(wxScrollEvent& event);
318  void OnThumbRelease(wxScrollEvent& event);
319  void OnSize(wxSizeEvent& event); //unused.
320  void OnIconize(wxIconizeEvent & event);
321  void OnMove(wxMoveEvent & event);
322  void OnCloseFrame(wxCloseEvent & event);
323  void OnUnhandledCloseFrame(wxCloseEvent & event);
324 // void OnCloseWindow(wxCloseEvent & event);
325  void OnEnterWindow(wxMouseEvent& event);
326  void OnLeaveWindow(wxMouseEvent& event);
327  void OnShowRequest(wxCommandEvent& event);
328  void OnHideRequest(wxCommandEvent& event);
329  void OnIdle(wxIdleEvent& event);
330  void OnMenu(wxCommandEvent& event);
331  void OnSizeWithTimer(wxSizeEvent& event);
332  void OnTimerResize(wxTimerEvent& event);
333  void OnContextEvent(wxContextMenuEvent& event);
334  void OnTracking(wxFocusEvent& event);
335  void OnWidgetTimer(wxTimerEvent & event);
336  void OnKBRDFocusChange(wxFocusEvent &event);
337 private:
338  void OnListBoxDo(wxCommandEvent& event, DLong clicks);
339  DECLARE_EVENT_TABLE()
340 };
341 
342 static int sysScrollHeight=25;
343 static int sysScrollWidth=25;
344 static int sysComboboxArrow=25;
345 
346 class GDLWidget
347 {
348   // static part is used for the abstraction
349   // all widgets are refered to as IDs
350   static int gdl_lastControlId;
351   static bool wxIsOn; //tells if wx is started, permits to starts wxInit() as soon as needed but not before (speedup).
352   static bool handlersOk; //tells if wx is started, permits to starts wxInit() as soon as needed but not before (speedup).
353 private:
354   // the global widget list
355   // a widget is added by the constructor and removed by the destructor
356   // so no other action is necessary for list handling
357   static WidgetListT widgetList;
358 public:
359   static wxFont defaultFont;
360   static wxFont systemFont;
361   static GDLEventQueue eventQueue;
362   static GDLEventQueue readlineEventQueue;
363   static void PushEvent( WidgetIDT baseWidgetID, DStructGDL* ev);
364   static void InformAuthorities(const std::string& message);
365 
366   static void HandleWidgetEvents();
367   static const WidgetIDT NullID;
368 
369   GDLWidget( WidgetIDT p, EnvT* e, BaseGDL* vV=NULL, DULong eventFlags_=0);
370 
371   virtual ~GDLWidget();
372 
373   // get widget from ID
374   static GDLWidget* GetWidget( WidgetIDT widID);
375   static GDLWidget* GetParent( WidgetIDT widID);
376   static GDLWidgetTopBase* GetTopLevelBaseWidget( WidgetIDT widID);
377   //self variants
378   GDLWidgetTopBase* GetMyTopLevelBaseWidget();
379   GDLWidgetBase* GetMyBaseWidget();
380   GDLWidgetBase* GetMyParentBaseWidget();
381   GDLWidget* GetMyParent();
382   gdlwxFrame* GetMyTopLevelFrame();
383   // get ID of base widgets
384   static WidgetIDT  GetBaseId( WidgetIDT widID);
385   static WidgetIDT  GetIdOfTopLevelBase( WidgetIDT widID);
386 
387   //  static void RefreshWidgets();
388   void RefreshDynamicWidget();
389   void UpdateGui();
390 
391   static bool InitWx(); // global start of wxWidgets
392   static void Init(); // global GUI intialization upon GDL startup
393   static void UnInit(); // global GUI desinitialization in case it is useful (?)
wxIsStarted()394   static bool wxIsStarted(){return (wxIsOn);}
SetWxStarted()395   static void SetWxStarted(){wxIsOn=true;}
UnsetWxStarted()396   static void UnsetWxStarted(){gdl_lastControlId=0;/* not possible: wxWidgets library does not survive wxUniitiailze() ... wxIsOn=false; handlersOk=false;*/}
GDLNewControlId()397   static int  GDLNewControlId(){
398    gdl_lastControlId++;
399    if (gdl_lastControlId >= wxID_LOWEST && gdl_lastControlId <= wxID_HIGHEST) gdl_lastControlId=wxID_HIGHEST+1;
400    return gdl_lastControlId;
401   }
setDefaultFont(wxFont thefont)402   static void setDefaultFont(wxFont thefont){
403    defaultFont=thefont;
404   }
405   static BaseGDL * getSystemColours();
406 
407 protected:
408 
409 
410   WidgetIDT    widgetID;  // own index to widgetList
411   WidgetIDT    parentID;  // parent ID (0 for TLBs)
412 
413   //Accelerators to components inside and outside
414   wxSizer* widgetSizer; // the sizer (possibly NULL) that governs the widget size & position.
415                         // Usually the widgetSizer of the parent widget, a Base.
416   wxScrolled<wxPanel>* widgetPanel; // the wxPanel in which the widget is placed, i.e. the parentBase's theWxWidget, as a base is mostly a wxPanel.
417   wxPanel* framePanel; // Panel with frame in which the widget may be shown
418 
419   wxObject* theWxWidget; //the active wxWidget, the one that sends and gets events and subjects to widget_control actions. Note this is mostly a wxWindow,
420   //except the MENUs, that force theWxWidget to be a wxObject, not a wxWindow (which would have been simpler).
421   wxObject* theWxContainer; //the external wx Container (wxFrame mostly) that contains everything wx that must be destroyed, or created, and is what is seen.
422   //theWxContainer is subject to framing (AddFrame) and scrolling (AddScroll)
423   //position & size
424   wxPoint      wOffset;
425   wxSize       wSize;
426   wxSize       wScreenSize;
427 
428   BaseGDL*     uValue;    // the UVALUE
429   BaseGDL*     vValue;    // the VVALUE
430   bool         scrolled;
431   bool         sensitive;
432   bool         managed;
433   DULong eventFlags; // event types widget should reply to
434   int          exclusiveMode;
435 
436   DInt         widgetType;
437   DString      widgetName;
438   WidgetIDT    groupLeader;
439   wxRealPoint  unitConversionFactor;
440   DLong        frameWidth;
441   wxFont       font;
442   bool         valid; //if not, is in the process of being destroyed (prevent reentrance).
443   long  alignment; //alignment of the widget
444   int widgetStyle; //style (alignment code + other specific codes used as option to widgetsizer). Needed only because of frame/unframe  function
445   int dynamicResize; //for some widgets, will enable resizing: -1: not resizable, 0/1 resizable
446   std::vector<WidgetIDT> followers; //all the widgets that use me as group_leader
447   std::vector<WidgetEventInfo*> desiredEventsList; //list of all the events (and handlers) this widget must obey.
448   DString      notifyRealize;
449 
450   wxTimer * m_windowTimer;
451 
452 private:
453 
454   DString      uName;
455   DString      proValue;
456   DString      funcValue;
457   DString      eventPro; // event handler PRO
458   DString      eventFun; // event handler FUN
459   DString      killNotify;
460 
461   void GetCommonKeywords( EnvT* e);
462   void DefaultValuesInAbsenceofEnv();
463 
464 public:
465 
466  void setFont();
467  void setFont(wxObject* o);
468 
469   typedef enum BGroupMode_
470   { BGNORMAL=0
471   , BGEXCLUSIVE=1
472   , BGNONEXCLUSIVE=2
473   , BGEXCLUSIVE1ST=3
474   } BGroupMode;
475 
476   typedef enum EventTypeFlags_
477     { EV_NONE = 0
478     , EV_ALL = 1
479     , EV_CONTEXT = 2
480     , EV_KBRD_FOCUS = 4
481     , EV_TRACKING = 8
482     , EV_DROP = 16
483     , EV_EXPOSE = 32
484     , EV_MOTION = 64
485     , EV_VIEWPORT = 128
486     , EV_WHEEL = 256
487     , EV_BUTTON = 512
488     , EV_KEYBOARD = 1024 //widget_draw, normal keys in the KEY field, modifiers reported in the "MODIFIERS" field
489     , EV_KEYBOARD2 = 2048 //widget_draw, normal keys and compose keys reported in the KEY field
490     , EV_SIZE = 4096
491     , EV_MOVE = 8192
492     , EV_ICONIFY = 16384
493     , EV_DRAG = 32768
494     , EV_KILL = 65536
495     } EventTypeFlags;
496 
497    typedef enum WidgetTypes_
498     { WIDGET_UNKNOWN = -1
499      ,WIDGET_BASE = 0
500      ,WIDGET_BUTTON
501      ,WIDGET_SLIDER
502      ,WIDGET_TEXT
503      ,WIDGET_DRAW
504      ,WIDGET_LABEL
505      ,WIDGET_LIST
506      ,WIDGET_MBAR //actually this is not present in IDL, but this place is void in IDL...
507      ,WIDGET_DROPLIST
508      ,WIDGET_TABLE
509      ,WIDGET_TAB
510      ,WIDGET_TREE
511      ,WIDGET_COMBOBOX
512      ,WIDGET_PROPERTYSHEET
513      ,WIDGET_WINDOW
514     } WidgetTypes;
515     enum {
516         gdlwALIGN_NOT=0,
517         gdlwALIGN_LEFT=1,
518         gdlwALIGN_CENTER=2,
519         gdlwALIGN_RIGHT=4,
520         gdlwALIGN_TOP=8,
521         gdlwALIGN_BOTTOM=16
522     } gdlAlignmentPossibilities;
523 
524 
GetEventFlags() const525   DULong GetEventFlags()  const { return eventFlags;}
HasEventType(DULong evType) const526   bool HasEventType( DULong evType) const { return (eventFlags & evType) != 0;}
AddEventType(DULong evType)527   virtual void AddEventType( DULong evType) { eventFlags |= evType;}
RemoveEventType(DULong evType)528   virtual void RemoveEventType( DULong evType) { eventFlags &= ~evType;}
529   void Raise();
530   void Lower();
531   int buttonTextAlignment();
532   int labelTextAlignment();
533   virtual int widgetAlignment();
534   void EnableWidgetUpdate(bool update);
535   void ChangeUnitConversionFactor( EnvT* e);
536   wxRealPoint GetRequestedUnitConversionFactor( EnvT* e);
GetCurrentUnitConversionFactor()537   wxRealPoint GetCurrentUnitConversionFactor(){return unitConversionFactor;}
SetCurrentUnitConversionFactor(wxRealPoint value)538   void SetCurrentUnitConversionFactor(wxRealPoint value){unitConversionFactor = value;}
539   virtual DStructGDL* GetGeometry(wxRealPoint fact=wxRealPoint(1.0,1.0));
540 
541   // this is called from the GUI thread on (before) Show()
542   // wxTextCtrl and maybe other controls crash when called from the
543   // main thread
544 //  virtual void OnShow();
545   // this is called from the main thread on (before) Realize()
546   // for latest initialzation (like allocating the plplot stream)
547   // calls NOTIFY_REALIZE procedure
OnRealize()548   virtual void OnRealize() //virtual as redefined in gdlwidget container
549   {
550     //setFont() will set the font for this widget and children if FONT= is present in the WIDGET_XXX command (and is supported)
551    this->setFont();
552    this->SetSensitive(sensitive);
553 //   if (this->GetRealized()) this->RefreshWidget();
554    if( notifyRealize != "") { //insure it is called once only for this.
555       std::string note=notifyRealize;
556       notifyRealize.clear();
557       CallEventPro( note, new DLongGDL( widgetID));
558     }
559    //define Events now.
560    ConnectToDesiredEvents();
561   }
OnKill()562   void OnKill()
563   {
564     std::string RIP=killNotify;
565     killNotify.clear(); //remove kill notify for this widget BEFORE calling it (avoid infinite recursal)
566     if( RIP != ""){
567         try {
568         CallEventPro( RIP, new DLongGDL( widgetID));
569         } catch (GDLException& e) {
570          GDLWidget::InformAuthorities(e.getMessage());
571         }
572     }
573   }
574 
ReorderWidgets()575   virtual void ReorderWidgets(){} //do Nothing, only for Base.
AddToFollowers(WidgetIDT him)576   void AddToFollowers(WidgetIDT him)
577   {
578     followers.insert( followers.end( ), him );
579   }
RemoveIfFollower(WidgetIDT him)580    void RemoveIfFollower(WidgetIDT him)
581   {
582       std::vector<WidgetIDT>::iterator it = find(followers.begin(), followers.end(), him); // Find first,
583       if (it != followers.end()) followers.erase(it);                                   // ... and remove.
584   }
585 
586   virtual void SetWidgetSize(DLong sizex, DLong sizey);
SetWidgetVirtualSize(DLong sizex,DLong sizey)587   virtual void SetWidgetVirtualSize(DLong sizex, DLong sizey){}; //do Nothing
588   virtual void SetWidgetScreenSize(DLong sizex, DLong sizey);
589   void SetWidgetPosition(DLong posx, DLong posy);
GetXPos()590   DLong GetXPos(){return dynamic_cast<wxWindow*>(theWxWidget)->GetPosition().x;}
GetYPos()591   DLong GetYPos(){return dynamic_cast<wxWindow*>(theWxWidget)->GetPosition().y;}
IsValid()592   bool IsValid(){return valid;}
SetUnValid()593   void SetUnValid(){valid=false;}
SetValid()594   void SetValid(){valid=true;}
IsDynamicResize()595   bool IsDynamicResize(){return ((dynamicResize>0)|| (dynamicResize==0 && !IsRealized())); }
SetDynamicResize()596   void SetDynamicResize(){if (dynamicResize > -1) dynamicResize=1;}
UnsetDynamicResize()597   void UnsetDynamicResize(){if (dynamicResize > -1) dynamicResize=0;}
authorizeDynamicResize()598   void authorizeDynamicResize(){dynamicResize=1;}
599 
GetParentID() const600   WidgetIDT GetParentID() const { return parentID;}
601 
GetWxWidget() const602   wxObject* GetWxWidget() const { return theWxWidget;}
GetWxContainer() const603   wxObject* GetWxContainer() const { return theWxContainer;}
604 
GetUvalue() const605   BaseGDL* GetUvalue() const { return uValue;}
GetVvalue() const606   BaseGDL* GetVvalue() const { return vValue;}
607 
608   virtual void Realize( bool b, bool use_default=false);
609 
610   // for query of children
IsContainer() const611   virtual bool IsContainer() const { return false;}
IsBase() const612   virtual bool IsBase() const { return false;}
IsTopBase() const613   virtual bool IsTopBase() const { return false;}
IsContextBase() const614   virtual bool IsContextBase() const {  return false; }
IsButton() const615   virtual bool IsButton() const { return false;}
IsMenu() const616   virtual bool IsMenu() const { return false;}
IsEntry() const617   virtual bool IsEntry() const {return false;}
IsDropList() const618   virtual bool IsDropList() const { return false;}
IsList() const619   virtual bool IsList() const { return false;}
IsComboBox() const620   virtual bool IsComboBox() const { return false;}
IsTab() const621   virtual bool IsTab() const { return false;}
IsTable() const622   virtual bool IsTable() const { return false;}
IsText() const623   virtual bool IsText() const { return false;}
IsLabel() const624   virtual bool IsLabel() const { return false;}
IsTree() const625   virtual bool IsTree() const { return false;}
IsSlider() const626   virtual bool IsSlider() const { return false;}
IsDraw() const627   virtual bool IsDraw() const { return false;}
IsMenuBar() const628   virtual bool IsMenuBar() const {return false;}
IsPropertySheet() const629   virtual bool IsPropertySheet() const { return false;}
IsModal() const630   virtual bool IsModal() const { return false;}
IsInCharacters() const631   virtual bool IsInCharacters() const {return false;} //measurements are not in characters
632 
GetChild(DLong) const633   virtual WidgetIDT GetChild( DLong) const {return NullID;}
NChildren() const634   virtual DLong NChildren() const { return 0;}
635   DLong GetSibling();
GetChildrenList() const636   virtual DLongGDL* GetChildrenList() const {return new DLongGDL(0);}
637 
638   //returns a list of IDs of all the widgets starting at me and below.
639   DLongGDL* GetAllHeirs();
640 
SetXmanagerActiveCommand()641   virtual void SetXmanagerActiveCommand() {std::cerr<<"XMANAGER ACTIVE COMMAND on a not-top widget, please report."<<std::endl;}
642 
643   bool GetXmanagerActiveCommand();
644 
SetEventPro(const DString & ePro)645   void SetEventPro( const DString& ePro) { eventPro = StrUpCase( ePro);}
GetEventPro() const646   const DString& GetEventPro() const { return eventPro;};
SetEventFun(const DString & eFun)647   void SetEventFun( const DString& eFun) { eventFun = StrUpCase( eFun);}
GetEventFun() const648   const DString& GetEventFun() const { return eventFun;}
SetNotifyRealize(const DString & eNR)649   void SetNotifyRealize( const DString& eNR) { notifyRealize = StrUpCase( eNR);}
GetNotifyRealize() const650   const DString& GetNotifyRealize() const { return notifyRealize;}
SetKillNotify(const DString & eKN)651   void SetKillNotify( const DString& eKN) { killNotify = StrUpCase( eKN);}
GetKillNotify() const652   const DString& GetKillNotify() const { return killNotify;}
653 
654   static bool GetXmanagerBlock();
655   static DLong GetNumberOfWidgets();
656   static BaseGDL* GetWidgetsList();
657   static BaseGDL* GetManagedWidgetsList();
658 
GetWidgetID()659   WidgetIDT GetWidgetID() { return widgetID;}
660 
GetParentSizer()661  wxSizer* GetParentSizer() {
662   GDLWidget* gdlParent = GetWidget(parentID);
663   return gdlParent->GetSizer();
664  }
GetSizer()665   wxSizer* GetSizer() { return widgetSizer;}
666 
GetParentPanel()667  wxScrolled<wxPanel>* GetParentPanel() {
668   GDLWidget* gdlParent = GetWidget(parentID);
669   return gdlParent->GetPanel();
670  }
GetPanel()671   wxScrolled<wxPanel>* GetPanel() { return widgetPanel;}
672 
GetManaged() const673   bool GetManaged() const { return managed;}
674   bool IsRealized();
SetManaged(bool manval)675   void SetManaged( bool manval){managed = manval;}
676   virtual void SetSensitive( bool value);
677   bool GetSensitive();
GetTheSiblingOf(DLong myIdx)678   virtual DLong GetTheSiblingOf(DLong myIdx){return 0;}
679   virtual void SetFocus();
680 
GetExclusiveMode() const681   int  GetExclusiveMode() const { return exclusiveMode;}
SetExclusiveMode(int exclusiveval)682   void SetExclusiveMode( int exclusiveval){exclusiveMode = exclusiveval;}
683 
SetUvalue(BaseGDL * uV)684   void SetUvalue( BaseGDL *uV){uValue = uV;}
685 //  void SetVvalue( BaseGDL *vV){vValue = vV;} //unused!
686 
GetWidgetName() const687   const DString& GetWidgetName() const { return widgetName;}
SetWidgetName(const DString & wName)688   void SetWidgetName( const DString& wName){widgetName = wName;}
GetWidgetType()689   DInt GetWidgetType() { return widgetType;}
SetWidgetType(DInt type)690   void SetWidgetType( DInt type){widgetType=widgetTypeList[type]; widgetName = widgetNameList[type];}
691 
GetButtonSet() const692   virtual bool GetButtonSet() const { return 0;} //normally not a button
693 //   void SetButtonSet(bool onOff){buttonSet = onOff;}
694 
GetUname() const695   const DString& GetUname() const { return uName;}
SetUname(const DString & uname)696   void SetUname( const DString& uname){uName = uname;}
697 
GetProValue() const698   const DString& GetProValue() const { return proValue;}
SetProValue(const DString & provalue)699   void SetProValue( const DString& provalue){proValue = StrUpCase(provalue);}
700 
GetFuncValue() const701   const DString& GetFuncValue() const { return funcValue;}
SetFuncValue(const DString & funcvalue)702   void SetFuncValue( const DString& funcvalue){funcValue = StrUpCase(funcvalue);}
703 
704   virtual wxSize computeWidgetSize();
705   wxSize getFontSize();
getFont()706   wxFont getFont(){return font;};
707   wxSize calculateTextScreenSize(std::string &s, wxFont testFont=wxNullFont);
708   void ConnectToDesiredEvents();
709 
AddToDesiredEvents(wxEventType t,wxObjectEventFunction f,wxWindow * w)710   void AddToDesiredEvents(wxEventType t, wxObjectEventFunction f, wxWindow* w) {
711  //immediate: w->Connect(widgetID, t, f);
712    //delayed at Realize time
713  WidgetEventInfo *wei=new WidgetEventInfo(t,f,w);
714    desiredEventsList.push_back(wei);
715  }
716   bool DisableSizeEvents(gdlwxFrame* &tlbFrame,WidgetIDT &id);
717   static void EnableSizeEvents(gdlwxFrame* &tlbFrame,WidgetIDT &id);
718 
719   void SendWidgetTimerEvent(DDouble secs);
SetButtonWidget(bool onOff)720   virtual void SetButtonWidget( bool onOff){}
721   void ClearEvents();
722 };
723 
724 class GDLWidgetContainer: public GDLWidget
725 {
726 protected:
727   std::deque<WidgetIDT> children;
728   bool xfree;
729   bool yfree;
730 public:
731   GDLWidgetContainer( WidgetIDT parentID, EnvT* e, ULong eventFlags_=0);
732 
733   ~GDLWidgetContainer();
734 
IsContainer() const735   virtual bool IsContainer() const { return true;}
xFree()736   bool xFree() {return xfree;}
yFree()737   bool yFree() {return yfree;}
738 //Realize a Container==> realise first all children. Vertically-stored widgets in a base widget must be reordered, done in overriding GDLWidgetBase::OnRealize.
739   void OnRealize();
740 
741    // as this is called in the constructor, no type checking of c can be done
742   // hence the AddChild() function should be as simple as that
AddChildID(WidgetIDT c)743   void AddChildID( WidgetIDT c) { children.push_back( c);}
RemoveChild(WidgetIDT c)744   void RemoveChild( WidgetIDT  c) {
745       std::deque<WidgetIDT>::iterator it = find(children.begin(), children.end(), c); // Find first,
746       if (it != children.end()) children.erase(it);                                   // ... and remove.
747   }
NChildren() const748   DLong NChildren() const
749   {
750     return children.size( );
751   }
GetChild(DLong childIx) const752   WidgetIDT GetChild( DLong childIx) const final
753   {
754     assert( childIx >= 0 );
755     assert( childIx < children.size( ) );
756     return children[childIx];
757   }
758 
GetChildrenList() const759   DLongGDL* GetChildrenList() const
760   {
761     DLong size=children.size( );
762     if (size<1) return new DLongGDL(0);
763     DLongGDL* ret=new DLongGDL(dimension(size),BaseGDL::ZERO);
764     for (SizeT i=0; i< size; ++i) (*ret)[i]=children[i];
765     return ret;
766   }
767   //returns next in list or 0
GetTheSiblingOf(DLong myIdx)768   DLong GetTheSiblingOf(DLong myIdx)
769   {
770     DLong size=children.size( );
771     if (size<1) return 0;
772     DLong ret=0;
773     for (int i=0; i< size-1; ++i) {
774      if (children[i] == myIdx) {
775       ret=children[i+1];
776       break;
777      }
778     }
779     return ret;
780   }
781 };
782 
783 class gdlwxFrame;
784 // base for base widgets **************************************************
785 class GDLWidgetBase: public GDLWidgetContainer
786 {
787 public:
788 
789   // for radio buttons to generate deselect event
790   WidgetIDT lastRadioSelection; //valid for all types of baseq
791   DLong ncols;
792   DLong nrows;
793   bool grid;
794   long childrenAlignment;
795   int space;
796   int xpad;
797   int ypad;
798   bool doMap;
799   wxSize wScrollSize; //to be used everywhere
800 
801   GDLWidgetBase( WidgetIDT parentID, EnvT* e, ULong eventFlags_,
802 		 bool mapWid,
803 		 DLong col, DLong row,
804 		 int exclusiveMode,
805 		 const DString& resource_name, const DString& rname_mbar,
806 		 const DString& title,
807 		 const DString& display_name,
808 		 int xpad_, int ypad_,
809 		 DLong x_scroll_size, DLong y_scroll_size, bool grid_layout, long children_alignment=wxALIGN_LEFT,
810      int space_=0);
811 
812   void CreateBase(wxWindow* parent);
IsVertical()813   bool IsVertical() {return (ncols>0);}
IsHorizontal()814   bool IsHorizontal() {return (nrows>0);}
IsNormalBase() const815   virtual bool IsNormalBase() const { return false;}
IsTabbedBase() const816   virtual bool IsTabbedBase() const { return false;}
817   void SetWidgetSize(DLong sizex, DLong sizey) final;
818 
NullWxWidget()819   void NullWxWidget() { theWxWidget = NULL;}
820 
GetLastRadioSelection() const821   WidgetIDT GetLastRadioSelection() const { return lastRadioSelection;}
SetLastRadioSelection(WidgetIDT lastSel)822   void SetLastRadioSelection(WidgetIDT lastSel) { lastRadioSelection = lastSel;}
823 
IsBase() const824   bool IsBase() const { return true;}
IsContainer() const825   bool IsContainer() const final { return true;}
IsScrolled() const826   bool IsScrolled() const { return scrolled;}
getChildrenAlignment()827   long getChildrenAlignment(){return childrenAlignment;}
getSpace()828   long getSpace(){return space;}
getXPad()829   long getXPad(){return xpad;}
getYPad()830   long getYPad(){return ypad;}
831   virtual void mapBase(bool val);
832   DStructGDL* GetGeometry(wxRealPoint fact=wxRealPoint(1.0,1.0)) final;
833 //  wxScrolled<wxPanel>* AddBaseFrame(wxScrolled<wxPanel>* wxParent, int width=0);
834   wxScrolled<wxPanel>* AddXYPad(wxScrolled<wxPanel>* wxParent, int xpad=0, int ypad=0);
835 //Apparently children of a base are plotted in reverse order in IDL (last first)
836   void DoReorderColWidgets(int code=0,int style=0, int border=0);
837   void ReorderWidgets();
838   void ReorderForANewWidget(wxWindow* w, int code,int style, int border);
839 //  int widgetAlignment();
GetMap() const840   bool GetMap() const { return doMap;}
SetMap(bool mapval)841   void SetMap( bool mapval){ doMap = mapval;}
842 
DoMapAsRequested()843  void DoMapAsRequested() {
844   //descend all children, find all bases that need to be unmapped.
845   for (std::deque<WidgetIDT>::iterator c = children.begin(); c != children.end(); ++c) {
846    GDLWidget* w = GetWidget(*c);
847    if (w != NULL && w->IsBase()) static_cast<GDLWidgetBase*>(w)->DoMapAsRequested();
848   }
849   dynamic_cast<wxWindow*>(theWxContainer)->Show(doMap);
850  }
851 };
852 
853 class GDLWidgetTopBase : public GDLWidgetBase {
854  WidgetIDT mbarID;
855 public:
856  bool xmanActCom; //set by /XMANAGER_ACTIVE_COMMAND (GDL's) aka NO_BLOCK . indirectly used in pushEvent, selfDestroy, ~GDLWidgetContainer, ClearEvents
857  gdlwxFrame* topFrame;
858  bool modal;
859  bool realized;
860  GDLWidgetTopBase(EnvT* e, ULong eventFlags_,
861    bool mapWid,
862    WidgetIDT& mBarIDInOut, bool modal_, DLong frame_attr,
863    DLong col, DLong row,
864    int exclusiveMode,
865    bool floating, //to be written: this topbase will appear over the group leader base
866    const DString& resource_name, const DString& rname_mbar,
867    const DString& title,
868    const DString& display_name,
869    int xpad_, int ypad_,
870    DLong x_scroll_size, DLong y_scroll_size, bool grid_layout, long children_alignment = wxALIGN_LEFT,
871    int space_ = 0);
872 
873  ~GDLWidgetTopBase ();
874 
875  int widgetAlignment();
IsModal() const876  bool IsModal() const final {return modal;}
877  void mapBase(bool val) final;
878 
IsTopBase() const879  bool IsTopBase() const final{
880   return true;
881  }
IsTopLevelRealized()882  bool IsTopLevelRealized() { return realized; }
GetTopFrame()883  gdlwxFrame* GetTopFrame() {
884   return topFrame;
885  }
886  void Realize(bool map, bool use_default=false) final;
887  //Same as Container except that we have to reorder and map
888 
OnRealize()889  void OnRealize() final {
890 #ifdef GDL_DEBUG_WIDGETS
891     wxMessageOutputStderr().Printf(_T("GDLWidgetTopBase:OnRealize: %d\n"), widgetID);
892 #endif
893     ReorderWidgets();
894     //setFont() will set the font for this widget and children if FONT= is present in the WIDGET_XXX command (and is supported)
895   this->setFont();
896   this->SetSensitive(sensitive);
897 
898   for (std::deque<WidgetIDT>::reverse_iterator c = children.rbegin(); c != children.rend(); ++c) {
899 //  for (std::deque<WidgetIDT>::iterator c = children.begin(); c != children.end(); ++c) {
900    GDLWidget* w = GetWidget(*c);
901    if (w != NULL)
902     w->OnRealize();
903   }
904   topFrame->Fit();
905   topFrame->refreshFrameSize();
906   DoMapAsRequested();
907   ConnectToDesiredEvents();
908 
909   if (notifyRealize != "") { //insure it is called once only for this.
910    std::string note = notifyRealize;
911    notifyRealize.clear();
912    CallEventPro(note, new DLongGDL(widgetID));
913   }
914  }
915 
916 // void SelfDestroy(); // sends delete event to itself
917 
SetXmanagerActiveCommand()918  void SetXmanagerActiveCommand() {
919   xmanActCom = true;
920  }
921 
GetXmanagerActiveCommand() const922  bool GetXmanagerActiveCommand() const {
923   return xmanActCom;
924  }
925 
926 };
927 
928 //specialized for Normal Base
929 
930 class GDLWidgetNormalBase : public GDLWidgetBase {
931 public:
932  GDLWidgetNormalBase(WidgetIDT parentID, EnvT* e, ULong eventFlags_,
933    bool mapWid,
934    DLong col, DLong row,
935    int exclusiveMode,
936    const DString& resource_name, const DString& rname_mbar,
937    const DString& title,
938    const DString& display_name,
939    int xpad_, int ypad_,
940    DLong x_scroll_size, DLong y_scroll_size, bool grid_layout, long children_alignment = wxALIGN_LEFT,
941    int space_ = 0);
942 
IsNormalBase() const943  bool IsNormalBase() const final {
944   return true;
945  }
946  void SetBaseTitle(std::string &s);
947 
948  //Same as Container except that we have to reorder widgets in some cases
949 
OnRealize()950  void OnRealize() {
951   ReorderWidgets();
952   GDLWidgetContainer::OnRealize();
953  }
954 
955 };
956 //specialized for Tabbed Base
957 
958 class GDLWidgetTabbedBase : public GDLWidgetBase {
959  int myPage;
960 public:
961  GDLWidgetTabbedBase(WidgetIDT parentID, EnvT* e, ULong eventFlags_,
962    bool mapWid,
963    DLong col, DLong row,
964    int exclusiveMode,
965    const DString& resource_name, const DString& rname_mbar,
966    const DString& title,
967    const DString& display_name,
968    int xpad_, int ypad_,
969    DLong x_scroll_size, DLong y_scroll_size, bool grid_layout, long children_alignment = wxALIGN_LEFT,
970    int space_ = 0);
971 
972  ~GDLWidgetTabbedBase();
973  void SetBaseTitle(std::string &s);
IsTabbedBase() const974  bool IsTabbedBase() const {  return true; }
975  void mapBase(bool val) final;
976 
977  //Same as Container except that we have to reorder widgets in some cases
978 
OnRealize()979  void OnRealize() {
980    ReorderWidgets();
981    GDLWidgetContainer::OnRealize();
982  }
983 
984 };
985 
986 class wxButtonGDL: public wxButton
987 {
988   wxMenu* popupMenu;
989   wxPoint position;
990 public:
wxButtonGDL(wxFont font,wxWindow * parent,wxWindowID id,const wxString & label=wxEmptyString,const wxPoint & pos=wxDefaultPosition,const wxSize & size=wxDefaultSize,long style=0,const wxValidator & validator=wxDefaultValidator,const wxString & name=wxButtonNameStr)991   wxButtonGDL(wxFont font, wxWindow *parent,
992           wxWindowID id,
993           const wxString &label=wxEmptyString,
994           const wxPoint &pos=wxDefaultPosition,
995           const wxSize &size=wxDefaultSize,
996           long style=0,
997           const wxValidator &validator=wxDefaultValidator,
998           const wxString &name=wxButtonNameStr):
999       wxButton(parent,id,label,pos,size,style,validator,name){
1000       this->SetFont(font);
1001       popupMenu=new wxMenu();
1002       position=this->GetClientRect().GetBottomLeft();
1003       Connect(id, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(wxButtonGDL::OnButton));
1004       Connect(id, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxButtonGDL::OnButton));
1005     }
GetPopupMenu()1006   wxMenu* GetPopupMenu(){return popupMenu;}
SetPopupMenu(wxMenu * menu)1007   void SetPopupMenu(wxMenu* menu){popupMenu=menu;}
1008 private:
1009   void OnButton(wxCommandEvent& event);
1010 };
1011 
1012 class wxBitmapButtonGDL: public wxBitmapButton
1013 {
1014   wxMenu* popupMenu;
1015 public:
wxBitmapButtonGDL(wxWindow * parent,wxWindowID id,const wxBitmap & bitmap_,const wxPoint & pos=wxDefaultPosition,const wxSize & size=wxDefaultSize,long style=wxBU_AUTODRAW,const wxValidator & validator=wxDefaultValidator,const wxString & name=wxButtonNameStr)1016   wxBitmapButtonGDL(wxWindow *parent,
1017           wxWindowID id,
1018           const wxBitmap &bitmap_,
1019           const wxPoint &pos=wxDefaultPosition,
1020           const wxSize &size=wxDefaultSize,
1021           long style=wxBU_AUTODRAW,
1022           const wxValidator &validator=wxDefaultValidator,
1023           const wxString &name=wxButtonNameStr):
1024       wxBitmapButton(parent,id,bitmap_,pos,size,style,validator,name){
1025       popupMenu=new wxMenu();
1026       Connect(id, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(wxBitmapButtonGDL::OnButton));
1027       Connect(id, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxBitmapButtonGDL::OnButton));
1028   }
GetPopupMenu()1029   wxMenu* GetPopupMenu(){return popupMenu;}
SetPopupMenu(wxMenu * menu)1030   void SetPopupMenu(wxMenu* menu){popupMenu=menu;}
1031   void OnButton(wxCommandEvent& event);
1032 };
1033 
1034 class GDLWidgetButton: public GDLWidget
1035 {
1036 public:
1037 
1038  typedef enum ButtonType_ {
1039   UNDEFINED=-1, NORMAL=0, RADIO=1, CHECKBOX=2, MENU=3, ENTRY=4, BITMAP=5, POPUP_NORMAL=6, POPUP_BITMAP=7} ButtonType;
1040  ButtonType buttonType;
1041   wxBitmap* buttonBitmap;
1042   wxMenuItem* menuItem;
1043   bool       buttonState; //only for buttons
1044   wxString valueWxString;
1045 
1046   GDLWidgetButton( WidgetIDT parentID, EnvT* e, DStringGDL* value, DULong eventflags, wxBitmap* bitmap=NULL);
1047   ~GDLWidgetButton();
1048   // for WIDGET_CONTROL
1049 
SetButtonWidget(bool onOff)1050   virtual void SetButtonWidget( bool onOff)
1051   {
1052     if( theWxWidget != NULL)
1053     {
1054       switch( buttonType) {
1055         case RADIO: {
1056           SetRadioButton( onOff);
1057           wxRadioButton* radioButton = dynamic_cast<wxRadioButton*>(theWxWidget);
1058           radioButton->SetValue(onOff);
1059           break;
1060         }
1061         case CHECKBOX: {
1062           SetRadioButton( onOff);
1063           wxCheckBox* checkBox = dynamic_cast<wxCheckBox*>(theWxWidget);
1064           checkBox->SetValue(onOff);
1065           break;
1066         }
1067         default: break;
1068       }
1069     }
1070   }
SetButtonWidgetLabelText(const DString & value_)1071   virtual void SetButtonWidgetLabelText( const DString& value_ ) {std::cerr<<"SetButtonWidgetLabelText() ID="<<widgetID <<" error, please check!"<<std::endl;} ;//code in gdlwidget
1072   virtual void SetButtonWidgetBitmap( wxBitmap* bitmap_ );//code in gdlwidget
SetRadioButton(bool onOff)1073   void SetRadioButton( bool onOff)
1074   {
1075     buttonState = onOff;
1076   }
GetButtonSet() const1077   bool GetButtonSet() const
1078   {
1079     return buttonState;
1080   }
IsButton() const1081   bool IsButton() const final { return true;}
IsBitmapButton() const1082   bool IsBitmapButton() const {return ( buttonType==POPUP_BITMAP || buttonType==BITMAP);}
1083  };
1084 
1085 //A /MENU button in a Base, or a Button in a MBAR is a Container
1086 class GDLWidgetMenu: public GDLWidgetButton
1087 {
1088   std::deque<WidgetIDT>   children;  //as for Containers
1089 public:
1090  GDLWidgetMenu( WidgetIDT parentID, EnvT* e, DStringGDL* value, DULong eventflags, wxBitmap* bitmap=NULL);
1091   ~GDLWidgetMenu();
1092 
IsMenu() const1093   bool IsMenu() const final {return true;}
1094   //Realize a Container==> realise first all children. Vertically-stored widgets in a base widget must be reordered, done in overriding GDLWidgetBase::OnRealize.
1095   void OnRealize();
1096 
1097    // as this is called in the constructor, no type checking of c can be done
1098   // hence the AddChild() function should be as simple as that
AddChildID(WidgetIDT c)1099   void AddChildID( WidgetIDT c) { children.push_back( c);}
RemoveChild(WidgetIDT c)1100   void RemoveChild( WidgetIDT  c) {
1101       std::deque<WidgetIDT>::iterator it = find(children.begin(), children.end(), c); // Find first,
1102       if (it != children.end()) children.erase(it);                                   // ... and remove.
1103   }
NChildren() const1104   DLong NChildren() const
1105   {
1106     return children.size( );
1107   }
GetChild(DLong childIx) const1108   WidgetIDT GetChild( DLong childIx) const final
1109   {
1110     assert( childIx >= 0 );
1111     assert( childIx < children.size( ) );
1112     return children[childIx];
1113   }
GetChildrenList() const1114   DLongGDL* GetChildrenList() const
1115   {
1116     DLong size=children.size( );
1117     if (size<1) return new DLongGDL(0);
1118     DLongGDL* ret=new DLongGDL(dimension(size),BaseGDL::ZERO);
1119     for (SizeT i=0; i< size; ++i) (*ret)[i]=children[i];
1120     return ret;
1121   }
1122   //returns next in list or 0
GetTheSiblingOf(DLong myIdx)1123   DLong GetTheSiblingOf(DLong myIdx)
1124   {
1125     DLong size=children.size( );
1126     if (size<1) return 0;
1127     DLong ret=0;
1128     for (int i=0; i< size-1; ++i) {
1129      if (children[i] == myIdx) {
1130       ret=children[i+1];
1131       break;
1132      }
1133     }
1134     return ret;
1135   }
1136 
1137 };
1138 
1139 class GDLWidgetSubMenu: public GDLWidgetMenu
1140 {
1141  bool addSeparatorAbove;
1142  wxMenuItem* the_sep;
1143 public:
1144  GDLWidgetSubMenu( WidgetIDT parentID, EnvT* e, DStringGDL* value, DULong eventflags, bool hasSeparatorAbove=false, wxBitmap* bitmap=NULL);
1145  ~GDLWidgetSubMenu();
1146 // bool IsSubMenu() const {return true;}
1147  void SetSensitive(bool value);
1148  void SetButtonWidgetLabelText( const DString& value_ );
1149  void SetButtonWidgetBitmap( wxBitmap* bitmap );
1150 };
1151 
1152 class GDLWidgetMenuButton: public GDLWidgetMenu
1153 {
1154 public:
1155  GDLWidgetMenuButton( WidgetIDT parentID, EnvT* e, DStringGDL* value, DULong eventflags,  wxBitmap* bitmap=NULL, DStringGDL* buttonTooltip=NULL);
1156  ~GDLWidgetMenuButton();
1157  void SetSensitive( bool value);
1158  void SetButtonWidgetLabelText( const DString& value_ );
1159 } ;
1160 
1161 class GDLWidgetMenuBarButton: public GDLWidgetMenu {
1162 public:
1163 #ifdef PREFERS_MENUBAR
1164  int entry;
1165  GDLWidgetMenuBarButton(WidgetIDT parentID, EnvT* e, DStringGDL* value, DULong eventflags, DStringGDL* buttonTooltip = NULL);
1166 #else
1167  wxToolBarToolBase* entry;
1168  GDLWidgetMenuBarButton(WidgetIDT parentID, EnvT* e, DStringGDL* value, DULong eventflags, wxBitmap* bitmap_=NULL, DStringGDL* buttonTooltip = NULL);
1169 #endif
1170  wxSize computeWidgetSize(); //not a real menubar: buttons may have a different fontsize.
1171  ~GDLWidgetMenuBarButton();
1172  void SetSensitive(bool value);
1173  void SetButtonWidgetLabelText( const DString& value_ );
1174 
1175 };
1176 
1177 class GDLWidgetNormalButton: public GDLWidgetButton
1178 {
1179 public:
1180  GDLWidgetNormalButton( WidgetIDT parentID, EnvT* e, DStringGDL* value, DULong eventflags, wxBitmap* bitmap=NULL, DStringGDL* buttonTooltip=NULL);
1181  ~GDLWidgetNormalButton();
1182  void SetButtonWidgetLabelText( const DString& value_ );
1183 };
1184 
1185 class GDLWidgetMenuEntry: public GDLWidgetButton
1186 {
1187   bool addSeparatorAbove;
1188   wxMenuItem* the_sep;
1189   bool checkedState;
1190 public:
1191  GDLWidgetMenuEntry( WidgetIDT parentID, EnvT* e, DStringGDL* value, DULong eventflags, bool hasSeparatorAbove=false, wxBitmap* bitmap=NULL, bool checked_type=false);
1192  ~GDLWidgetMenuEntry();
IsEntry() const1193  bool IsEntry() const final {return true;}
1194  void SetSensitive(bool value);
1195  void SetButtonWidgetLabelText( const DString& value_ );
1196  void SetButtonWidgetBitmap( wxBitmap* bitmap );
GetButtonSet() const1197   bool GetButtonSet() const
1198   {
1199     return checkedState;
1200   }
SetButtonWidget(bool onOff)1201   virtual void SetButtonWidget(bool onOff) final {
1202     checkedState = onOff;
1203     wxMenuItem* mi = static_cast<wxMenuItem*> (theWxWidget);
1204     if (mi->GetKind() == wxITEM_CHECK || mi->GetKind() == wxITEM_RADIO) {
1205       mi->Check(checkedState);
1206     }
1207   }
1208 };
1209 
1210 //specialized for Context Menu Base
1211 
1212 class GDLWidgetContextBase : public GDLWidgetMenu { //GDLWidgetBase {
1213 public:
1214  GDLWidgetContextBase(WidgetIDT parentID, EnvT* e, ULong eventFlags_,
1215    bool mapWid,
1216    DLong col, DLong row,
1217    int exclusiveMode,
1218    const DString& resource_name, const DString& rname_mbar,
1219    const DString& title,
1220    const DString& display_name,
1221    int xpad_, int ypad_,
1222    DLong x_scroll_size, DLong y_scroll_size, bool grid_layout, long children_alignment = wxALIGN_LEFT,
1223    int space_ = 0);
1224 
1225  ~GDLWidgetContextBase();
1226 
IsContextBase() const1227  bool IsContextBase() const final {
1228   return true;
1229  }
1230 };
1231 
1232 
1233 // droplist widget **************************************************
1234 class GDLWidgetDropList: public GDLWidget
1235 {
1236   std::string lastValue;
1237   DString title;
1238   DLong style;
1239 
1240 public:
1241   GDLWidgetDropList( WidgetIDT p, EnvT* e, BaseGDL *value, DULong eventflags,
1242 		     const DString& title, DLong style);
1243   ~GDLWidgetDropList();
IsDropList() const1244   bool IsDropList() const final { return true;}
1245 
SetLastValue(const std::string & v)1246   void SetLastValue( const std::string& v) { lastValue = v;}
GetLastValue()1247   std::string GetLastValue() { return lastValue;}
1248 
1249   void SetValue(BaseGDL *value);
1250   void SelectEntry(DLong entry_number);
1251   BaseGDL* GetSelectedEntry();
1252 };
1253 
1254 // combobox widget **************************************************
1255 class GDLWidgetComboBox: public GDLWidget
1256 {
1257   std::string lastValue;
1258   DLong style;
1259 
1260 public:
1261   GDLWidgetComboBox( WidgetIDT p, EnvT* e, BaseGDL *value, DULong eventflags, DLong style);
1262  ~GDLWidgetComboBox();
1263 //  void OnShow();
1264 
1265 //   void SetSelectOff();
IsComboBox() const1266   bool IsComboBox() const final { return true;}
1267 
SetLastValue(const std::string & v)1268   void SetLastValue( const std::string& v) { lastValue = v;}
GetLastValue()1269   std::string GetLastValue() { return lastValue;}
1270   void SetValue(BaseGDL *value);
1271   void SelectEntry(DLong entry_number);
1272   BaseGDL* GetSelectedEntry();
1273   void AddItem(DString value, DLong pos);
1274   void DeleteItem(DLong pos);
1275 };
1276 
1277 // list widget **************************************************
1278 class GDLWidgetList : public GDLWidget
1279 {
1280   int maxlinelength;
1281   int nlines;
1282 public:
1283   GDLWidgetList( WidgetIDT p, EnvT* e, BaseGDL *value, DLong style, DULong eventflags);
1284   ~GDLWidgetList();
IsList() const1285   bool IsList() const final { return true;}
IsInCharacters() const1286   bool IsInCharacters() const final {return true;} //measurements are in characters
1287   void SetValue(BaseGDL *value);
1288   void SelectEntry(DLong entry_number);
1289   BaseGDL* GetSelectedEntries();
1290   wxSize computeWidgetSize() final;
1291   void SetWidgetSize(DLong sizex, DLong sizey) final;
1292 //  void OnRealize(){wxListBox* b=static_cast<wxListBox*> (theWxWidget); if(b) b->SetSelection(0,false); GDLWidget::OnRealize(); }
1293 };
1294 
1295 // text widget : overloading some wxTextCtrl basics fotr our purposes
1296 //**************************************************
1297 class wxTextCtrlGDL : public wxTextCtrl
1298 {
1299 public:
wxTextCtrlGDL(wxWindow * parent,wxWindowID id,const wxString & value=wxEmptyString,const wxPoint & pos=wxDefaultPosition,const wxSize & size=wxDefaultSize,long textStyle=0,const wxValidator & validator=wxDefaultValidator,const wxString & name=wxTextCtrlNameStr)1300  wxTextCtrlGDL(wxWindow *parent,
1301    wxWindowID id,
1302    const wxString &value = wxEmptyString,
1303    const wxPoint &pos = wxDefaultPosition,
1304    const wxSize &size = wxDefaultSize,
1305    long textStyle = 0,
1306                const wxValidator& validator = wxDefaultValidator,
1307                const wxString &name = wxTextCtrlNameStr):
1308    wxTextCtrl(parent, id,value,pos,size,textStyle,validator,name){
1309  }
~wxTextCtrlGDL()1310  ~ wxTextCtrlGDL(){}
1311   void OnChar(wxKeyEvent& event );
1312   void OnMouseEvents( wxMouseEvent& event);
1313 };
1314 
1315 class GDLWidgetText: public GDLWidget
1316 {
1317   std::string lastValue;
1318   bool noNewLine;
1319   bool editable;
1320   int maxlinelength; //the size of the longest line in the widgets current value.
1321   int nlines;
1322   bool wrapped;
1323   bool multiline;
1324   wxSize textSize; //the current size, in characters, not owing for the character sizes and spurious decorations as wxWidgets adds by itself
1325   wxSize initialSize; //memory of the initial (realized) textSize just after creation.
1326 public:
1327   GDLWidgetText( WidgetIDT parentID, EnvT* e, DStringGDL* value, DULong eventflags, bool noNewLine,
1328 		 bool editable);
1329   ~GDLWidgetText();
1330 
IsMultiline()1331   bool IsMultiline(){return multiline;}
IsEditable()1332   bool IsEditable(){return editable;}
SetEditable(bool v)1333   void SetEditable(bool v){ editable=v;}
1334   void ChangeText( DStringGDL* value, bool noNewLine=false);
1335   void InsertText( DStringGDL* value, bool noNewLine=false, bool insertAtEnd=false);
1336   void SetTextSelection(DLongGDL* pos);
1337   DLongGDL* GetTextSelection();
1338   DStringGDL* GetSelectedText();
1339   void AppendTextValue( DStringGDL* value, bool noNewLine);
1340 
IsText() const1341   bool IsText() const final { return true;}
IsInCharacters() const1342   bool IsInCharacters() const final {return true;} //measurements are in characters
SetLastValue(const std::string & v)1343   void SetLastValue( const std::string& v) { lastValue = v;}
GetLastValue()1344   std::string GetLastValue() { return lastValue;}
1345   wxSize computeWidgetSize() final;
1346   void SetWidgetSize(DLong sizex, DLong sizey) final;
1347 };
1348 
1349 
1350 // label widget **************************************************
1351 class GDLWidgetLabel: public GDLWidget
1352 {
1353   DString value;
1354   bool sunken;
1355 public:
1356   GDLWidgetLabel( WidgetIDT parentID, EnvT* e, const DString& value_, DULong eventflags, bool sunken);
1357  ~GDLWidgetLabel();
1358   void SetLabelValue( const DString& value_);
IsLabel() const1359   bool IsLabel() const final { return true;}
1360   wxSize computeWidgetSize() final;
1361   int widgetAlignment();
1362   void SetWidgetSize(DLong sizex, DLong sizey) final;
1363 };
1364 
1365 
1366 // draw widget **************************************************
1367 class GDLWidgetDraw: public GDLWidget
1368 {
1369   int pstreamIx;
1370   wxSize wScrollSize;
1371 public:
1372   GDLWidgetDraw( WidgetIDT parentID, EnvT* e, int windowIndex, DLong x_scroll_size, DLong y_scroll_size, bool app_scroll, DULong eventFlags, DStringGDL* drawToolTip=NULL);
1373 
1374   ~GDLWidgetDraw();
1375 
IsDraw() const1376   bool IsDraw() const final { return true;}
1377   void AddEventType( DULong evType) final; //specific for draw widgets
1378   void RemoveEventType( DULong evType) final;
1379   void SetWidgetSize(DLong sizex, DLong sizey) final;
1380   void SetWidgetVirtualSize(DLong sizex, DLong sizey) final;
1381   void SetWidgetScreenSize(DLong sizex, DLong sizey) final;
UnrefTheWxContainer()1382   void UnrefTheWxContainer(){theWxContainer=NULL;}
UnrefTheWxWidget()1383   void UnrefTheWxWidget(){theWxWidget=NULL;}
1384 };
1385 
1386 // menubar is best done with a toolbar at the moment, see below
1387 #ifdef PREFERS_MENUBAR
1388 // menu bar widget **************************************************
1389 class GDLWidgetMenuBar: public GDLWidget
1390 {
1391 protected:
1392   std::deque<WidgetIDT> children;
1393   ~GDLWidgetMenuBar();
1394 public:
GDLWidgetMenuBar(WidgetIDT p,EnvT * e)1395   GDLWidgetMenuBar( WidgetIDT p, EnvT* e):
1396   GDLWidget( p, NULL) //NULL because MBar must not re-read env Values of e
1397   {
1398     theWxWidget = theWxContainer = new wxMenuBar(wxMB_DOCKABLE);
1399     if (this->GetWidgetType()==GDLWidget::WIDGET_UNKNOWN ) this->SetWidgetType(WIDGET_MBAR);
1400   }
1401   //same as containers
AddChildID(WidgetIDT c)1402   void AddChildID( WidgetIDT c) { children.push_back( c);}
RemoveChild(WidgetIDT c)1403   void RemoveChild( WidgetIDT  c) {
1404       std::deque<WidgetIDT>::iterator it = find(children.begin(), children.end(), c); // Find first,
1405       if (it != children.end()) children.erase(it);                                   // ... and remove.
1406       }
NChildren() const1407   DLong NChildren() const
1408   {
1409     return children.size( );
1410   }
GetChild(DLong childIx) const1411   WidgetIDT GetChild( DLong childIx) const final
1412   {
1413     assert( childIx >= 0 );
1414     assert( childIx < children.size( ) );
1415     return children[childIx];
1416   }
1417 
GetChildrenList() const1418   DLongGDL* GetChildrenList() const
1419   {
1420     DLong size=children.size( );
1421     if (size<1) return new DLongGDL(0);
1422     DLongGDL* ret=new DLongGDL(dimension(size),BaseGDL::ZERO);
1423     for (SizeT i=0; i< size; ++i) (*ret)[i]=children[i];
1424     return ret;
1425   }
GetChildrenPos(WidgetIDT c)1426   int GetChildrenPos(WidgetIDT c)
1427   {
1428     DLong size=children.size( );
1429     if (size<1) return -1;
1430     for (SizeT i=0; i< size; ++i) if (children[i]==c) return i;
1431     return -1;
1432   }
IsMenuBar() const1433   bool IsMenuBar() const final { return true;}
1434 };
1435 #else
1436 // tool bar widget **************************************************
1437 //this widget is preferred to GDLWidgetMenuBar since 1) it can have any kind of buttons and 2) the menuBar is a problem on Apple OSX (too far from IDL rendering on Window
1438 class GDLWidgetMenuBar: public GDLWidget
1439 {
1440 protected:
1441   std::deque<WidgetIDT> children;
1442   ~GDLWidgetMenuBar();
1443 public:
GDLWidgetMenuBar(wxFrame * frame,WidgetIDT p,EnvT * e)1444   GDLWidgetMenuBar( wxFrame* frame, WidgetIDT p, EnvT* e):
1445   GDLWidget( p, NULL) //NULL because MBar must not re-read env Values of e
1446   {
1447    long style=wxTB_HORIZONTAL|wxTB_DOCKABLE|wxTB_FLAT;
1448    wxToolBar* t= frame->CreateToolBar(style, wxID_ANY);
1449     theWxWidget = theWxContainer = t;
1450 //    widgetSizer=new wxBoxSizer(wxHORIZONTAL);
1451 //    t->SetSizer(widgetSizer);
1452     this->SetWidgetType(WIDGET_MBAR);
1453   }
1454   //same as containers
AddChildID(WidgetIDT c)1455   void AddChildID( WidgetIDT c) { children.push_back( c);}
RemoveChild(WidgetIDT c)1456   void RemoveChild( WidgetIDT  c) {
1457       std::deque<WidgetIDT>::iterator it = find(children.begin(), children.end(), c); // Find first,
1458       if (it != children.end()) children.erase(it);                                   // ... and remove.
1459       }
NChildren() const1460   DLong NChildren() const
1461   {
1462     return children.size( );
1463   }
GetChild(DLong childIx) const1464   WidgetIDT GetChild( DLong childIx) const final
1465   {
1466     assert( childIx >= 0 );
1467     assert( childIx < children.size( ) );
1468     return children[childIx];
1469   }
1470 
GetChildrenList() const1471   DLongGDL* GetChildrenList() const
1472   {
1473     DLong size=children.size( );
1474     if (size<1) return new DLongGDL(0);
1475     DLongGDL* ret=new DLongGDL(dimension(size),BaseGDL::ZERO);
1476     for (SizeT i=0; i< size; ++i) (*ret)[i]=children[i];
1477     return ret;
1478   }
1479   //returns next in list or 0
GetTheSiblingOf(DLong myIdx)1480   DLong GetTheSiblingOf(DLong myIdx)
1481   {
1482     DLong size=children.size( );
1483     if (size<1) return 0;
1484     DLong ret=0;
1485     for (int i=0; i< size-1; ++i) {
1486      if (children[i] == myIdx) {
1487       ret=children[i+1];
1488       break;
1489      }
1490     }
1491     return ret;
1492   }
GetChildrenPos(WidgetIDT c)1493   int GetChildrenPos(WidgetIDT c)
1494   {
1495     DLong size=children.size( );
1496     if (size<1) return -1;
1497     for (SizeT i=0; i< size; ++i) if (children[i]==c) return i;
1498     return -1;
1499   }
IsMenuBar() const1500   bool IsMenuBar() const final { return true;}
1501 };
1502 #endif
1503 // tab widget **************************************************
1504 class GDLWidgetTab: public GDLWidgetContainer
1505 {
1506 public:
1507     GDLWidgetTab( WidgetIDT parentID, EnvT* e, ULong eventFlags, DLong location, DLong multiline);
1508 
1509   ~GDLWidgetTab();
1510 
IsTab() const1511   bool IsTab() const final { return true;}
IsContainer() const1512   bool IsContainer() const final { return true;}
1513   BaseGDL* GetTabNumber();
1514   BaseGDL* GetTabCurrent();
1515   void SetTabCurrent(int val);
1516   BaseGDL* GetTabMultiline(); //not exactly what expected, fixme.
1517 };
1518 
1519 
1520 // table widget **************************************************
1521 class GDLWidgetTable: public GDLWidget
1522 {
1523   DByteGDL* table_alignment;
1524   DStringGDL* amPm;
1525   DByteGDL* backgroundColor;
1526   DByteGDL* foregroundColor;
1527   DStringGDL* columnLabels;
1528   int majority;
1529   DLongGDL* columnWidth;
1530   DStringGDL* daysOfWeek;
1531   bool disjointSelection;
1532   DByteGDL* editable;
1533   DStringGDL* format;
1534 //  bool ignoreAccelerators;
1535   DStringGDL* month;
1536   bool noColumnHeaders;
1537   bool noRowHeaders;
1538   bool resizeableColumns;
1539   bool resizeableRows;
1540   DLongGDL* rowHeights;
1541   DStringGDL* rowLabels;
1542 //  DLong tabMode;
1543   DLong x_scroll_size;
1544   DLong y_scroll_size;
1545   DStringGDL * valueAsStrings;
1546   bool         updating; //widget is modified by program (avoid sending events)
1547 
1548 public:
1549  typedef enum TableMajority_ {NONE_MAJOR = 0, ROW_MAJOR, COLUMN_MAJOR} TableMajority;
1550 
1551  GDLWidgetTable( WidgetIDT p, EnvT* e,
1552 		  DByteGDL* alignment_,
1553 		  DStringGDL* amPm_,
1554 		  DByteGDL* backgroundColor_,
1555 		  DByteGDL* foregroundColor_,
1556 		  DStringGDL* columnLabels_,
1557 		  int majority_,
1558 		  DLongGDL* columnWidth_,
1559 		  DStringGDL* daysOfWeek_,
1560 		  bool disjointSelection_,
1561 		  DByteGDL* editable_,
1562 		  DStringGDL* format_,
1563 // 		  bool ignoreAccelerators_,
1564 		  DStringGDL* month_,
1565 		  bool noColumnHeaders_,
1566 		  bool noRowHeaders_,
1567 		  bool resizeableColumns_,
1568 		  bool resizeableRows_,
1569 		  DLongGDL* rowHeights_,
1570 		  DStringGDL* rowLabels_,
1571 //		  DLong tabMode_,
1572 		  BaseGDL* value_,
1573 		  DLong xScrollSize_,
1574 		  DLong yScrollSize_,
1575                   DStringGDL* valueAsStrings_,
1576                   DULong eventFlags_
1577          );
1578 
1579 ~GDLWidgetTable();
1580 
1581 
GetMajority()1582   int  GetMajority(){return majority;}
IsTable() const1583   bool IsTable() const final { return true;}
SetDOW(DStringGDL * val)1584   void SetDOW(DStringGDL* val){GDLDelete(daysOfWeek); daysOfWeek=val->Dup();}
SetAmPm(DStringGDL * val)1585   void SetAmPm(DStringGDL* val){GDLDelete(amPm); amPm=val->Dup();};
SetMonth(DStringGDL * val)1586   void SetMonth(DStringGDL* val){GDLDelete(month); month=val->Dup();};
1587 
1588   DLongGDL* GetSelection();
1589 
SetAlignment(DByteGDL * val)1590   void SetAlignment(DByteGDL* val){GDLDelete(table_alignment); table_alignment=val->Dup();};
1591   void DoAlign();
1592   void DoAlign(DLongGDL* selection);
1593 
SetBackgroundColor(DByteGDL * val)1594   void SetBackgroundColor(DByteGDL* val){GDLDelete(backgroundColor); backgroundColor=val->Dup();};
1595   void DoBackgroundColor();
1596   void DoBackgroundColor(DLongGDL* selection);
1597 
SetForegroundColor(DByteGDL * val)1598   void SetForegroundColor(DByteGDL* val){GDLDelete(foregroundColor); foregroundColor=val->Dup();};
1599   void DoForegroundColor();
1600   void DoForegroundColor(DLongGDL* selection);
1601 
SetColumnLabels(DStringGDL * val)1602   void SetColumnLabels(DStringGDL* val){GDLDelete(columnLabels); columnLabels=val->Dup();};
1603   void DoColumnLabels();
1604 
SetRowLabels(DStringGDL * val)1605   void SetRowLabels(DStringGDL* val){GDLDelete(rowLabels); rowLabels=val->Dup();};
1606   void DoRowLabels();
1607 
SetColumnWidth(DLongGDL * val)1608   void SetColumnWidth(DLongGDL* val){GDLDelete(columnWidth); columnWidth=val->Dup();};
1609   void DoColumnWidth();
1610   void DoColumnWidth(DLongGDL* selection);
1611   DFloatGDL* GetColumnWidth(DLongGDL* selection=NULL);
1612 
SetRowHeights(DLongGDL * val)1613   void SetRowHeights(DLongGDL* val){GDLDelete(rowHeights); rowHeights=val->Dup();};
1614   void DoRowHeights();
1615   void DoRowHeights(DLongGDL* selection);
1616   DFloatGDL* GetRowHeight(DLongGDL* selection=NULL);
1617 
GetDisjointSelection()1618   bool GetDisjointSelection(){return disjointSelection;}
SetDisjointSelection(bool b)1619   void SetDisjointSelection(bool b){disjointSelection = b;}
1620   void ClearSelection();
1621 
1622   void DeleteColumns(DLongGDL* selection=NULL);
1623   void DeleteRows(DLongGDL* selection=NULL);
1624 
1625   bool InsertColumns(DLong count, DLongGDL* selection=NULL);
1626   bool InsertRows(DLong count, DLongGDL* selection=NULL);
1627 
1628   void SetSelection(DLongGDL* selection);
1629   DStringGDL* GetTableValues(DLongGDL* selection=NULL);
1630   BaseGDL* GetTableValuesAsStruct(DLongGDL* selection=NULL);
1631   void SetTableValues(DStringGDL *val, DLongGDL* selection=NULL);
SetValue(BaseGDL * val)1632   void SetValue(BaseGDL * val){GDLDelete(vValue); vValue=val->Dup();};
1633 
1634   void SetTableView(DLongGDL* pos);
1635   void EditCell(DLongGDL* pos);
1636   void SetTableNumberOfColumns( DLong ncols);
1637   void SetTableNumberOfRows( DLong nrows);
1638 
1639   bool IsSomethingSelected();
1640 
IsUpdating()1641   bool IsUpdating(){return updating;}
ClearUpdating()1642   void ClearUpdating(){updating=false;}
SetUpdating()1643   void SetUpdating(){updating=true;}
1644   DStructGDL* GetGeometry(wxRealPoint fact=wxRealPoint(1.0,1.0)) final;
1645   void setFont();
1646 };
1647 
1648 
1649 // tree widget **************************************************
1650 class wxTreeCtrlGDL: public wxTreeCtrl {
1651   wxWindowID GDLWidgetTreeID;
1652   wxWindowID draggedGDLWidgetID;
1653   int KeyModifier; //Shift, Control... set during a drag
1654 public:
1655 
wxTreeCtrlGDL(wxWindow * parent,wxWindowID id=wxID_ANY,const wxPoint & pos=wxDefaultPosition,const wxSize & size=wxDefaultSize,long style=wxTR_DEFAULT_STYLE,const wxValidator & validator=wxDefaultValidator,const wxString & name=wxTreeCtrlNameStr)1656   wxTreeCtrlGDL(wxWindow *parent, wxWindowID id = wxID_ANY,
1657     const wxPoint& pos = wxDefaultPosition,
1658     const wxSize& size = wxDefaultSize,
1659     long style = wxTR_DEFAULT_STYLE,
1660     const wxValidator &validator = wxDefaultValidator,
1661     const wxString& name = wxTreeCtrlNameStr)
1662           :wxTreeCtrl( parent, id, pos, size, style, wxDefaultValidator , name ),
1663           GDLWidgetTreeID(id),
1664           draggedGDLWidgetID(0),
1665           KeyModifier(0)
1666           {
1667 //            Connect(GDLWidgetTableID, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler(wxTreeCtrlGDL::OnItemActivated));
1668 //            Connect(GDLWidgetTableID, wxEVT_COMMAND_TREE_ITEM_ACTIVATED,wxTreeEventHandler(wxTreeCtrlGDL::OnItemActivated));
1669 //            Connect(GDLWidgetTableID, wxEVT_COMMAND_TREE_BEGIN_DRAG,wxTreeEventHandler(wxTreeCtrlGDL::OnBeginDrag));
1670 //            Connect(GDLWidgetTableID, wxEVT_COMMAND_TREE_END_DRAG,wxTreeEventHandler(wxTreeCtrlGDL::OnItemDropped));
1671 //            Connect(GDLWidgetTableID, wxEVT_COMMAND_TREE_ITEM_COLLAPSED,wxTreeEventHandler(wxTreeCtrlGDL::OnItemCollapsed));
1672 //            Connect(GDLWidgetTableID, wxEVT_COMMAND_TREE_ITEM_EXPANDED,wxTreeEventHandler(wxTreeCtrlGDL::OnItemExpanded));
1673 //            Connect(GDLWidgetTableID, wxEVT_COMMAND_TREE_SEL_CHANGED,wxTreeEventHandler(wxTreeCtrlGDL::OnItemSelected));
1674   }
1675   //necessary to define the destructor otherwise compiler will try to find the bind event table for destruction event!
~wxTreeCtrlGDL()1676   ~wxTreeCtrlGDL(){}
SetCurrentModifier(int x,bool remove)1677   void SetCurrentModifier(int x, bool remove){ //We have to remap the wxWidgets events
1678     switch(x){
1679       case WXK_SHIFT:
1680         if (remove) KeyModifier &= ~(1); else KeyModifier |= 1; break; //bit 1
1681       case WXK_ALT:
1682         if (remove) KeyModifier &= ~(1<<3); else KeyModifier |= (1<<3); break; //bit 4
1683       case WXK_NUMLOCK:
1684         if (remove) KeyModifier &= ~(1<<2); else KeyModifier |= (1<<2); break; //bit 3
1685       case WXK_CONTROL:
1686         if (remove) KeyModifier &= ~(1<<1); else KeyModifier |= (1<<1); break; //bit 2
1687 
1688     }
1689   }
GetCurrentModifier()1690   int GetCurrentModifier(){return KeyModifier;}
1691   void OnTreeKeyDown(wxKeyEvent & event);
1692   void OnTreeKeyUp(wxKeyEvent & event);
1693   void OnItemActivated(wxTreeEvent & event);
1694   void OnItemCollapsed(wxTreeEvent & event);
1695   void OnItemStateClick(wxTreeEvent & event);
1696   void OnItemExpanded(wxTreeEvent & event);
1697   void OnDrag(wxTreeEvent & event);
1698   void OnDrop(wxTreeEvent & event);
1699   void OnItemSelected(wxTreeEvent & event);
SetDragged(wxWindowID that)1700   void SetDragged(wxWindowID that) {draggedGDLWidgetID=that;}
GetDragged()1701   wxWindowID GetDragged(){ return draggedGDLWidgetID;}
1702   DECLARE_EVENT_TABLE()
1703 };
1704 
1705 class wxTreeItemDataGDL : public wxTreeItemData {
1706   public:
1707     WidgetIDT widgetID;
1708     wxTreeCtrlGDL* myTree;
1709 
wxTreeItemDataGDL(WidgetIDT id,wxTreeCtrlGDL * myTree_)1710   wxTreeItemDataGDL(WidgetIDT id, wxTreeCtrlGDL* myTree_) : widgetID(id), myTree(myTree_) {}
GetWidgetID()1711   WidgetIDT GetWidgetID(){return widgetID;}
GetTree()1712   wxTreeCtrlGDL* GetTree(){return myTree;}
1713 };
1714 
1715 class GDLWidgetTree: public GDLWidget
1716 {
1717 int droppable  ;
1718 int draggable  ;
1719 bool has_checkbox;
1720 bool expanded;
1721 bool folder;
1722 bool noBitmaps;
1723 bool mask;
1724 bool multiple; //can select multiple
1725 wxTreeItemId treeItemID;
1726 wxTreeItemDataGDL* treeItemData;
1727 GDLWidgetTree* myRoot;
1728 DString dragNotify;
1729 
1730 public:
1731 GDLWidgetTree( WidgetIDT p, EnvT* e, BaseGDL* value_, DULong eventFlags
1732 ,wxBitmap* bitmap_
1733 ,DLong dropability
1734 ,DLong dragability
1735 ,bool expanded_
1736 ,bool folder_
1737 ,DLong treeindex
1738 ,DString &dragNotify_
1739 );
1740 
1741 ~GDLWidgetTree();
1742 
IsTree() const1743   bool IsTree() const final { return true;}
1744   //DRAG
GetDraggableValue()1745   int GetDraggableValue() {return draggable;}
1746   bool GetDragability();
SetDragability(DLong val)1747   void SetDragability(DLong val){draggable=val;}
1748   //DRAGNOTIFY
GetDragNotifyValue()1749   DString GetDragNotifyValue(){return dragNotify;}
SetDragNotify(DString & s)1750   void SetDragNotify(DString &s){Warning("SET_DRAG_NOTIFY is currently ignored by GDL, FIXME."); dragNotify=s;}
1751   //DROP
GetDroppableValue()1752   int  GetDroppableValue(){return droppable;}
1753   bool GetDropability();
SetDropability(DLong val)1754   void SetDropability(DLong val){droppable=val;}
IsExpanded()1755   bool IsExpanded() {
1756     return expanded;
1757   }
SetExpanded(bool b)1758   void SetExpanded(bool b){expanded=b;}
1759 
1760   void DoExpand(bool what);
1761   void Select(bool select);
1762   void SetTreeIndex(DLong where);
GetMyRootGDLWidgetTree()1763   GDLWidgetTree* GetMyRootGDLWidgetTree(){ return myRoot;}
1764   WidgetIDT IsSelectedID();
1765   WidgetIDT IsDragSelectedID();
1766   DLongGDL* GetAllSelectedID();
1767   DLongGDL* GetAllDragSelectedID();
1768   DInt GetTreeIndex();
GetItemID()1769   wxTreeItemId GetItemID(){ return treeItemID;}
SetItemID(wxTreeItemId id)1770   void SetItemID( wxTreeItemId id){treeItemID=id;}
1771   void SetValue(DString val);
1772   void OnRealize();
SetFolder()1773   void SetFolder(){folder=true;}
IsFolder()1774   bool IsFolder(){return folder;}
SetMask(bool b)1775   void SetMask(bool b){mask=b;}
HasMask()1776   bool HasMask(){return mask;}
1777   DByteGDL* ReturnBitmapAsBytes();
HasCheckBox()1778   bool HasCheckBox(){return has_checkbox;}
CheckItem(bool b)1779   void CheckItem(bool b){treeItemData->myTree->SetItemState(treeItemID,b);treeItemData->myTree->Refresh();}
IsUsingBitmaps()1780   bool IsUsingBitmaps(){return noBitmaps;}
1781   void SetBitmap(wxBitmap* bitmap);
SetVisible()1782   void SetVisible() {treeItemData->myTree->EnsureVisible(treeItemID);}
IsChecked()1783   bool IsChecked(){if (has_checkbox) return treeItemData->myTree->GetItemState(treeItemID); else return false;
1784   }
1785 
1786   DLong NChildren() const;
1787   WidgetIDT GetChild(DLong childIx) const final;
1788   DLongGDL* GetChildrenList() const;
1789   DLong GetTheSiblingOf(DLong myIx) final;
1790   DLong Sibling();
1791  };
1792 
1793 
1794 
1795 // slider widget **************************************************
1796 class GDLWidgetSlider: public GDLWidget
1797 {
1798   DLong value;
1799   DLong minimum;
1800   DLong maximum;
1801   DString title;
1802 public:
1803   GDLWidgetSlider( WidgetIDT parentID, EnvT* e, DLong value_,
1804        DULong eventFlags_ ,
1805 		   DLong minimum_, DLong maximum_,
1806 		   bool vertical,
1807 		   bool suppressValue,
1808 		   DString &title
1809  		);
1810 
1811   ~GDLWidgetSlider();
1812 
SetValue(DLong v)1813   void SetValue( DLong v) { value = v;}
1814   void ControlSetValue ( DLong v );
1815   void ControlSetMinValue ( DLong v );
1816   void ControlSetMaxValue ( DLong v );
GetValue() const1817   DLong GetValue() const { return value;}
1818 
IsSlider() const1819   bool IsSlider() const final { return true;}
1820 };
1821 
1822 
1823 
1824 
1825 class wxNotebookEvent;
1826 class wxGridEvent;
1827 class wxGridSizeEvent;
1828 class wxGridRangeSelectEvent;
1829 class wxGridGDL : public wxGrid
1830 {
1831   wxWindowID GDLWidgetTableID;
1832 public:
wxGridGDL(wxWindow * container,wxWindowID id,const wxPoint & pos=wxDefaultPosition,const wxSize & size=wxDefaultSize,long style=0,const wxString & name=wxPanelNameStr)1833   wxGridGDL(wxWindow* container, wxWindowID id,
1834 	    const wxPoint& pos = wxDefaultPosition,
1835 	    const wxSize& size = wxDefaultSize,
1836 	    long style = 0,
1837 	    const wxString& name = wxPanelNameStr):
1838   wxGrid( container, id, pos, size, style, name )
1839   , GDLWidgetTableID(id)
1840   {
1841    //replaced by addtodesiredevents.
1842 //    Connect(id,wxEVT_GRID_COL_SIZE,wxGridSizeEventHandler(wxGridGDL::OnTableColResizing));
1843 //    Connect(id,wxEVT_GRID_ROW_SIZE,wxGridSizeEventHandler(wxGridGDL::OnTableRowResizing));
1844 //    Connect(id,wxEVT_GRID_RANGE_SELECT,wxGridRangeSelectEventHandler(wxGridGDL::OnTableRangeSelection));
1845 //    Connect(id,wxEVT_GRID_SELECT_CELL,wxGridEventHandler(wxGridGDL::OnTableCellSelection));
1846 ////    Connect(id,wxEVT_GRID_CELL_LEFT_CLICK,wxGridEventHandler(gdlGrid::OnTableCellSelection));
1847   }
~wxGridGDL()1848   ~wxGridGDL(){
1849 #ifdef GDL_DEBUG_WIDGETS
1850     std::cout << "~wxGridGDL: " << this << std::endl;
1851 #endif
1852   }
1853 
IsSomethingSelected()1854   bool IsSomethingSelected(){
1855       wxGridCellCoordsArray cellSelection=this->GetSelectedCells();
1856       if ( cellSelection.Count() > 0 ) return true;
1857       wxGridCellCoordsArray selectionBR=this->GetSelectionBlockBottomRight();
1858       if ( selectionBR.Count() > 0 ) return true;
1859       wxArrayInt selectionRow=this->GetSelectedRows();
1860       if ( selectionRow.GetCount() > 0 ) return true;
1861       wxArrayInt selectionCol=this->GetSelectedCols();
1862       if ( selectionCol.GetCount() > 0 ) return true;
1863       return false;
1864   }
GetSelectedDisjointCellsList()1865   std::vector<wxPoint> GetSelectedDisjointCellsList(){
1866       std::vector<wxPoint> list;
1867       wxGridCellCoordsArray cellSelection=this->GetSelectedCells();
1868       for( int i=0; i<cellSelection.Count(); i++ ) {
1869        int row = cellSelection[i].GetRow();
1870        int col = cellSelection[i].GetCol();
1871        list.push_back(wxPoint(row,col));
1872       }
1873 
1874       wxGridCellCoordsArray selectionTL=this->GetSelectionBlockTopLeft();
1875       wxGridCellCoordsArray selectionBR=this->GetSelectionBlockBottomRight();
1876       for( int k=0; k<selectionBR.Count(); k++ ) {
1877        int rowTL = selectionTL[k].GetRow();
1878        int colTL = selectionTL[k].GetCol();
1879        int rowBR = selectionBR[k].GetRow();
1880        int colBR = selectionBR[k].GetCol();
1881        int nrows=rowBR-rowTL+1;
1882        int ncols=colBR-colTL+1;
1883        for ( int i=0; i< nrows; ++i) for (int j=0; j<ncols; ++j) list.push_back(wxPoint(rowTL+i,colTL+j));
1884       }
1885       wxArrayInt selectionRow=this->GetSelectedRows();
1886       for( int k=0; k<selectionRow.GetCount(); k++ ) {
1887        int row = selectionRow[k];
1888        for ( int i=0; i< this->GetNumberCols(); ++i) list.push_back(wxPoint(row,i));
1889       }
1890       wxArrayInt selectionCol=this->GetSelectedCols();
1891       for( int k=0; k<selectionCol.GetCount(); k++ ) {
1892        int col = selectionCol[k];
1893        for ( int i=0; i< this->GetNumberRows(); ++i) list.push_back(wxPoint(i,col));
1894       }
1895       return list;
1896   }
1897 
GetSelectedBlockOfCells()1898   wxArrayInt GetSelectedBlockOfCells() {
1899     wxArrayInt block;
1900     wxGridCellCoordsArray selectionTL = this->GetSelectionBlockTopLeft();
1901     wxGridCellCoordsArray selectionBR = this->GetSelectionBlockBottomRight();
1902     if (selectionBR.Count() > 0) {
1903       for (int k = 0; k < selectionBR.Count(); k++) {
1904         int colTL = selectionTL[k].GetCol();
1905         block.push_back(colTL);
1906         int rowTL = selectionTL[k].GetRow();
1907         block.push_back(rowTL);
1908         int colBR = selectionBR[k].GetCol();
1909         block.push_back(colBR);
1910         int rowBR = selectionBR[k].GetRow();
1911         block.push_back(rowBR);
1912       }
1913       return block;
1914     }
1915 
1916     wxArrayInt selectionRow=this->GetSelectedRows();
1917     if (selectionRow.GetCount() > 0) {
1918       block.push_back(0);
1919       block.push_back(selectionRow[0]);
1920       block.push_back(this->GetNumberCols()-1);
1921       block.push_back(selectionRow[selectionRow.GetCount()-1]);
1922       return block;
1923     }
1924 
1925     wxArrayInt selectionCol=this->GetSelectedCols();
1926     if (selectionCol.GetCount() > 0) {
1927       block.push_back(selectionCol[0]);
1928       block.push_back(0);
1929       block.push_back(selectionCol[selectionCol.GetCount()-1]);
1930       block.push_back(this->GetNumberRows()-1);
1931       return block;
1932     }
1933 
1934     wxGridCellCoordsArray cellSelection=this->GetSelectedCells(); //last chance for block selection, return only first if exist!
1935     if (cellSelection.Count()==0) return block; //should produce error...
1936     int row = cellSelection[0].GetRow();
1937     int col = cellSelection[0].GetCol();
1938     block.push_back(col);
1939     block.push_back(row);
1940     block.push_back(col);
1941     block.push_back(row);
1942     return block;
1943   }
1944 
GetSortedSelectedColsList()1945    wxArrayInt GetSortedSelectedColsList(){
1946    std::vector<wxPoint> list=GetSelectedDisjointCellsList();
1947    wxArrayInt cols;
1948    if (list.empty()) return cols;
1949    std::vector<wxPoint>::iterator iPoint;
1950    std::vector<int> allCols;
1951    std::vector<int>::iterator iter;
1952    for ( iPoint = list.begin(); iPoint !=list.end(); ++iPoint) {
1953        allCols.push_back((*iPoint).y);
1954     }
1955    std::sort (allCols.begin(), allCols.end());
1956    int theCol=-1;
1957    for ( iter = allCols.begin(); iter !=allCols.end(); ++iter) {
1958        if ((*iter)!=theCol) {theCol=(*iter);cols.Add(theCol);}
1959     }
1960    return cols;
1961   }
GetSortedSelectedRowsList()1962   wxArrayInt GetSortedSelectedRowsList(){
1963    std::vector<wxPoint> list=GetSelectedDisjointCellsList();
1964    wxArrayInt rows;
1965    if (list.empty()) return rows;
1966    std::vector<wxPoint>::iterator iPoint;
1967    std::vector<int> allRows;
1968    std::vector<int>::iterator iter;
1969    for ( iPoint = list.begin(); iPoint !=list.end(); ++iPoint) {
1970        allRows.push_back((*iPoint).x);
1971     }
1972    std::sort (allRows.begin(), allRows.end());
1973    int theRow=-1;
1974    for ( iter = allRows.begin(); iter !=allRows.end(); ++iter) {
1975        if ((*iter)!=theRow) {theRow=(*iter);rows.Add(theRow);}
1976     }
1977    return rows;
1978   }
1979 
1980   void OnTableCellSelection(wxGridEvent & event);
1981   void OnTableRangeSelection(wxGridRangeSelectEvent & event);
1982   void OnTableColResizing(wxGridSizeEvent & event);
1983   void OnTableRowResizing(wxGridSizeEvent & event);
1984 //  void OnText( wxCommandEvent& event);
1985 //  void OnTextEnter( wxCommandEvent& event);
1986 };
1987 #ifdef HAVE_WXWIDGETS_PROPERTYGRID
1988 //
1989 //class GDLWidgetPropertySheet : public GDLWidget
1990 //{
1991 //public:
1992 //  GDLWidgetPropertySheet( WidgetIDT parentID, EnvT* e);
1993 //
1994 //  ~GDLWidgetPropertySheet();
1995 //
1996 //  bool IsPropertySheet() const { return true;}
1997 //};
1998 #endif
1999 //phantom window used to find exactly the size of scrollbars, as wxWidgets does not coorectly report them
2000 class gdlwxPhantomFrame : public wxFrame {
2001  public:
2002  gdlwxPhantomFrame();
2003  void Realize();
2004 };
2005 
2006 
2007 // basic for (completely separated from widgets) plot windows done with wxWidgets driver.
2008 class gdlwxPlotFrame : public wxFrame {
2009  wxTimer * m_resizeTimer;
2010  wxSize frameSize;
2011  bool scrolled;
2012 public:
2013  // ctor(s)
2014  gdlwxPlotFrame(const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE, bool scrolled=false);
2015  ~gdlwxPlotFrame();
IsScrolled()2016   bool IsScrolled(){return scrolled;}
2017  void Realize();
2018 // event handlers (these functions should _not_ be virtual)
2019 // void OnClosePlotFrame(wxCloseEvent & event);
2020 // void OnPlotSizeWithTimer(wxSizeEvent& event);
2021  void OnTimerPlotResize(wxTimerEvent& event);
2022  void OnUnhandledClosePlotFrame(wxCloseEvent & event);
2023  void OnPlotSizeWithTimer(wxSizeEvent& event);
2024  void OnPlotWindowSize(wxSizeEvent& event);
2025  DECLARE_EVENT_TABLE()
2026 };
2027 class GDLWXStream;
2028 #include "graphicsdevice.hpp"
2029 // graphic panels. A basic one, conected with WXStream, used for plots. does not pertain to the widgets hierarchy.
2030 class gdlwxGraphicsPanel : public wxScrolled<wxPanel> {
2031 protected:
2032  GDLWXStream* pstreamP;
2033 public:
2034  int pstreamIx;
2035  wxSize drawSize;
2036  wxMemoryDC* wx_dc; //pointer on plplot's stream DC
2037 
2038  gdlwxGraphicsPanel(wxWindow* parent, wxWindowID id = wxID_ANY,
2039    const wxPoint& pos = wxDefaultPosition,
2040    const wxSize& size = wxDefaultSize,
2041    long style = 0,
2042    const wxString& name = wxPanelNameStr);
2043 
PStreamIx()2044  int PStreamIx() {return pstreamIx;}
SetPStreamIx(int ix)2045  void SetPStreamIx( int ix){pstreamIx=ix;}
2046  GDLWXStream* GetStream();
2047 
InitDrawSize(wxSize s)2048  void InitDrawSize(wxSize s) {drawSize = s;}
GetDrawSize()2049  wxSize GetDrawSize() {return drawSize;}
2050 
2051  void ResizeDrawArea(const wxSize s);
2052  void DeleteUsingWindowNumber();
2053  void SetStream(GDLWXStream* s);
2054 
2055  void OnPaint(wxPaintEvent& event);
2056  virtual void OnPlotWindowSize(wxSizeEvent &event);
2057 
2058 // virtual bool isPlot() const {return false;}
2059 
2060 
2061  void RepaintGraphics(bool doClear = false);
RaisePanel()2062  virtual void RaisePanel()  {}
LowerPanel()2063  virtual void LowerPanel()  {}
IconicPanel()2064  virtual void IconicPanel()    {}
DeIconicPanel()2065  virtual void DeIconicPanel()    {}
UnsetFocusPanel()2066  virtual bool UnsetFocusPanel()  {return false;}
SetFocusPanel()2067  virtual void SetFocusPanel()   {}
2068 };
2069 //for (non-widget) plot panels
2070 class gdlwxPlotPanel : public gdlwxGraphicsPanel
2071 {
2072  gdlwxPlotFrame* myFrame;
2073 public:
2074  gdlwxPlotPanel(gdlwxPlotFrame* parent);
2075  ~gdlwxPlotPanel();
2076 
2077 // bool isPlot() const final {return true;}
2078  void OnPlotWindowSize(wxSizeEvent &event) final;
GetMyFrame()2079  gdlwxPlotFrame* GetMyFrame(){return myFrame;}
2080 //works for basic panels, void for Draw widgets:
2081 
RaisePanel()2082  void RaisePanel() final {
2083   this->GetParent()->Raise();
2084  }
2085 
LowerPanel()2086  void LowerPanel() final {
2087   this->GetParent()->Lower();
2088  }
2089 
IconicPanel()2090  void IconicPanel() final {
2091   static_cast<wxFrame*> (this->GetParent())->Iconize(true);
2092  }
2093 
DeIconicPanel()2094  void DeIconicPanel() final {
2095   static_cast<wxFrame*> (this->GetParent())->Iconize(false);
2096  }
2097 
UnsetFocusPanel()2098  bool UnsetFocusPanel() final {  //focus in not given
2099   this->Disable(); //no buttons will not work!
2100   return true;
2101  }
2102 
2103 // virtual gdlWidgetDraw* GetGDLWidgetDraw() {
2104 //  return NULL;
2105 // }
2106  };
2107 //variant used in widget_draw, with specifics for widgets.
2108 class gdlwxDrawPanel : public gdlwxGraphicsPanel
2109 {
2110  GDLWidgetDraw* myWidgetDraw;
2111 
2112 public:
2113  // ctor(s)
2114  gdlwxDrawPanel(wxWindow* parent, wxWindowID id,
2115    const wxPoint& pos = wxDefaultPosition,
2116    const wxSize& size = wxDefaultSize,
2117    long style = 0,
2118    const wxString& name = wxPanelNameStr);
2119 
2120  ~gdlwxDrawPanel();
2121 
GetMyWidget()2122  GDLWidgetDraw* GetMyWidget()  {return myWidgetDraw;}
2123  void InitStream(int windowIndex = -1);
2124  //works for basic panels, void for Draw widgets:
2125 
2126 
2127  // event handlers (these functions should _not_ be virtual)
2128  void OnErase(wxEraseEvent& event);
2129  //  void OnClose(wxCloseEvent& event);
2130  void OnMouseMove(wxMouseEvent& event);
2131  void OnMouseDown(wxMouseEvent& event);
2132  void OnMouseUp(wxMouseEvent& event);
2133  void OnMouseWheel(wxMouseEvent& event);
2134  void OnKey(wxKeyEvent& event);
2135  //  void OnSize(wxSizeEvent &event);
2136 // void OnPlotWindowSize(wxSizeEvent &event);
2137 
2138 };
2139 
2140 #endif
2141 
2142 #endif
2143 
2144