Widget.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <vector>
9 #include <etk/types.hpp>
10 #include <etk/math/Vector2D.hpp>
11 
12 #include <ewol/debug.hpp>
13 #include <ewol/object/Object.hpp>
14 #include <gale/Dimension.hpp>
15 #include <gale/context/cursor.hpp>
16 
17 namespace ewol {
18  class Widget;
19  namespace widget {
20  class Manager;
21  class Windows;
22  };
23  using WidgetShared = ememory::SharedPtr<ewol::Widget>;
24  using WidgetWeak = ememory::WeakPtr<ewol::Widget>;
25 };
26 #include <gale/context/clipBoard.hpp>
27 #include <gale/key/key.hpp>
28 #include <gale/context/cursor.hpp>
29 #include <ewol/event/Input.hpp>
30 #include <ewol/event/Entry.hpp>
31 #include <ewol/event/Time.hpp>
32 #include <etranslate/etranslate.hpp>
33 #include <esignal/Signal.hpp>
34 #include <ewol/DrawProperty.hpp>
35 #include <ewol/gravity.hpp>
36 
37 #define ULTIMATE_MAX_SIZE (99999999)
38 
39 #define DECLARE_WIDGET_FACTORY(className, name) \
40  DECLARE_FACTORY(className); \
41  static void createManagerWidget(ewol::widget::Manager& _widgetManager) { \
42  _widgetManager.addWidgetCreator(name, []() -> ewol::WidgetShared { \
43  return className::create(); \
44  }); \
45  }
46 
47 namespace ewol {
51  // TODO: change position of this ...
52  class EventShortCut {
53  public:
54  std::string message;
55  gale::key::Special specialKey;
56  char32_t unicodeValue;
57  enum gale::key::keyboard keyboardMoveValue;
58  EventShortCut() {
59  message = "";
60  unicodeValue = 0;
61  keyboardMoveValue = gale::key::keyboard::unknow;
62  };
63  virtual ~EventShortCut() { };
64  };
73  class Widget : public ewol::Object {
74  public: // signals:
75 
76  public: // properties:
84  protected:
89  Widget();
90  public:
94  virtual ~Widget();
95  // ----------------------------------------------------------------------------------------------------------------
96  // -- Widget size:
97  // ----------------------------------------------------------------------------------------------------------------
98  protected:
102  public:
108  virtual vec2 relativePosition(const vec2& _pos);
113  virtual void onChangeSize();
114  virtual void calculateSize() {};
120  virtual vec2 getSize();
126  virtual void setSize(const vec2& _value) {
127  m_size = _value;
128  }
133  virtual void calculateMinMaxSize();
139  virtual vec2 getCalculateMinSize();
145  virtual vec2 getCalculateMaxSize();
146  protected:
148  public:
153  virtual void setOffset(const vec2& _newVal);
158  virtual const vec2& getOffset() {
159  return m_offset;
160  };
161  protected:
162  // internal element calculated by the system
163  float m_zoom;
164  public:
169  virtual void setZoom(float _newVal);
174  virtual float getZoom();
179  virtual void changeZoom(float _range) {};
180  protected:
181  vec2 m_origin;
182  public:
189  virtual void setOrigin(const vec2& _pos);
194  virtual vec2 getOrigin();
195  public:
199  void setNoMinSize(); // TODO : Remove ==> default ... of the property
205  virtual void checkMinSize();
206  protected:
207 
208  public:
212  void setNoMaxSize(); // TODO : Remove ==> default ... of the property
218  virtual void checkMaxSize();
219  public:
225  virtual bvec2 canExpand();
226  public:
232  const bvec2& canFill();
233  // ----------------------------------------------------------------------------------------------------------------
234  // -- focus Area
235  // ----------------------------------------------------------------------------------------------------------------
236  private:
237  bool m_hasFocus;
238 
239  public:
244  virtual bool getFocus() {
245  return m_hasFocus;
246  };
251  virtual bool setFocus();
256  virtual bool rmFocus();
260  virtual void keepFocus();
261  protected:
265  virtual void onGetFocus() {};
269  virtual void onLostFocus() {};
270 
271  // ----------------------------------------------------------------------------------------------------------------
272  // -- Mouse event properties Area
273  // ----------------------------------------------------------------------------------------------------------------
274  private:
275  int32_t m_limitMouseEvent;
276  public:
281  virtual int32_t getMouseLimit() {
282  return m_limitMouseEvent;
283  };
288  virtual void setMouseLimit(int32_t _numberState) {
289  m_limitMouseEvent = _numberState;
290  };
291  // ----------------------------------------------------------------------------------------------------------------
292  // -- keyboard event properties Area
293  // ----------------------------------------------------------------------------------------------------------------
294  private:
295  bool m_allowRepeateKeyboardEvent;
296  public:
302  virtual bool getKeyboardRepeate() {
303  return m_allowRepeateKeyboardEvent;
304  };
305  protected:
310  virtual void setKeyboardRepeate(bool _state) {
311  m_allowRepeateKeyboardEvent = _state;
312  };
316  virtual void showKeyboard();
320  virtual void hideKeyboard();
321  public:
329  virtual ewol::WidgetShared getWidgetAtPos(const vec2& _pos) {
330  if (propertyHide.get() == false) {
331  return ememory::dynamicPointerCast<ewol::Widget>(sharedFromThis());
332  }
333  return nullptr;
334  };
335 
336  // event section:
337  public:
344  virtual bool systemEventInput(ewol::event::InputSystem& _event);
345  protected:
352  virtual bool onEventInput(const ewol::event::Input& _event) {
353  return false;
354  };
355  public:
362  virtual bool systemEventEntry(ewol::event::EntrySystem& _event);
363  protected:
374  virtual bool onEventEntry(const ewol::event::Entry& _event) {
375  return false;
376  };
377  public:
383  virtual void onEventClipboard(enum gale::context::clipBoard::clipboardListe _clipboardID) { };
384 
385  // ----------------------------------------------------------------------------------------------------------------
386  // -- Shortcut : management of the shortcut
387  // ----------------------------------------------------------------------------------------------------------------
388  public:
389  esignal::Signal<std::string> signalShortcut;
390  private:
391  std::vector<EventShortCut*> m_localShortcut;
392  protected:
398  virtual void shortCutAdd(const std::string& _descriptiveString,
399  const std::string& _message="");
403  virtual void shortCutClean();
408  virtual void shortCutRemove(const std::string& _message);
409  public:
419  virtual bool onEventShortCut(const gale::key::Special& _special,
420  char32_t _unicodeValue,
421  enum gale::key::keyboard _kbMove,
422  bool _isDown);
423  // ----------------------------------------------------------------------------------------------------------------
424  // -- drawing : All drawing must be done in 2 separate buffer 1 for the current display and 1 for the working...
425  // ----------------------------------------------------------------------------------------------------------------
426  protected:
428 
431  virtual void markToRedraw();
437  virtual bool needRedraw() {
438  bool tmpData = m_needRegenerateDisplay;
439  m_needRegenerateDisplay = false;
440  return tmpData;
441  };
442  public:
450  virtual void systemDraw(const DrawProperty& _displayProp);
451  protected:
455  virtual void onDraw() { };
456  public:
460  virtual void onRegenerateDisplay() { };
461  // grab cursor mode
462  private:
463  bool m_grabCursor;
464  public:
470  virtual void grabCursor();
474  virtual void unGrabCursor();
479  virtual bool getGrabStatus();
480  private:
481  enum gale::context::cursor m_cursorDisplay;
482  public:
487  virtual void setCursor(enum gale::context::cursor _newCursor);
492  virtual enum gale::context::cursor getCursor();
493  public:
494  virtual bool loadXML(const exml::Element& _node) override;
495  public:
499  void requestUpdateSize();
503  ewol::widget::Manager& getWidgetManager();
508  /*
509  * Annimation section :
510  */
511  public:
512  // event generated :
513  esignal::Signal<> signalAnnimationStart;
514  esignal::Signal<float> signalAnnimationRatio;
515  esignal::Signal<> signalAnnimationStop;
516  protected:
517  enum annimationMode {
518  annimationModeEnableAdd,
519  annimationModeEnableRemove,
520  annimationModeDisable
521  };
522  enum annimationMode m_annimationMode;
524  protected:
529  protected:
535  void addAnnimationType(enum ewol::Widget::annimationMode _mode, const char* _type);
536  public:
542  void setAnnimationType(enum ewol::Widget::annimationMode _mode, const std::string& _type);
548  void setAnnimationTime(enum ewol::Widget::annimationMode _mode, float _time);
554  bool startAnnimation(enum ewol::Widget::annimationMode _mode);
559  bool stopAnnimation();
560  protected:
566  virtual bool onStartAnnimation(enum ewol::Widget::annimationMode _mode) {
567  return false;
568  };
572  virtual void onStopAnnimation() { };
573  protected:
574  virtual void onChangePropertyCanFocus();
575  virtual void onChangePropertyGravity();
576  virtual void onChangePropertyHide();
577  virtual void onChangePropertyFill();
578  virtual void onChangePropertyExpand();
579  virtual void onChangePropertyMaxSize();
580  virtual void onChangePropertyMinSize();
581  };
582 };
583 
584 #include <ewol/widget/Manager.hpp>
585 
virtual bool needRedraw()
get the need of the redrawing of the widget and reset it to false
Definition: Widget.hpp:437
eproperty::Value< bool > propertyCanFocus
the focus can be done on this widget
Definition: Widget.hpp:83
eproperty::Range< float > propertyAnnimationTimeStart
time to produce start annimation
Definition: Widget.hpp:526
Definition: Entry.hpp:13
eproperty::Value< bool > propertyHide
hide a widget on the display
Definition: Widget.hpp:81
char32_t unicodeValue
0 if not used
Definition: Widget.hpp:56
Definition: DrawProperty.hpp:15
gale::key::Special specialKey
special board key
Definition: Widget.hpp:55
vec2 m_origin
internal ... I do not really known how if can use it ...
Definition: Widget.hpp:179
virtual void onStopAnnimation()
Event when Stop the annimation.
Definition: Widget.hpp:572
const TYPE & get() const
Basic message classes for ewol system this class mermit at every Object to communicate between them...
Definition: Object.hpp:113
Definition: Manager.hpp:16
virtual void onDraw()
Common widget drawing function (called by the drawing thread [Android, X11, ...]) ...
Definition: Widget.hpp:455
virtual ewol::WidgetShared getWidgetAtPos(const vec2 &_pos)
get the widget at the specific windows absolute position
Definition: Widget.hpp:329
Definition: Input.hpp:12
eproperty::Value< gale::Dimension > propertyMaxSize
user define the maximum size of the widget
Definition: Widget.hpp:78
virtual bool getFocus()
get the focus state of the widget
Definition: Widget.hpp:244
virtual const vec2 & getOffset()
get the offset property of the widget.
Definition: Widget.hpp:158
bool m_needRegenerateDisplay
the display might be done the next regeneration
Definition: Widget.hpp:427
float m_zoom
generic widget zoom
Definition: Widget.hpp:160
virtual bool onEventInput(const ewol::event::Input &_event)
Event on an input of this Widget (finger, mouse, stilet)
Definition: Widget.hpp:352
Definition: Area.hpp:16
eproperty::List< int32_t > propertyAnnimationTypeStop
type of start annimation
Definition: Widget.hpp:527
virtual bool onEventEntry(const ewol::event::Entry &_event)
Entry event. represent the physical event :
Definition: Widget.hpp:374
vec2 m_maxSize
internal: maximum size of the widget
Definition: Widget.hpp:101
Definition: Input.hpp:71
vec2 m_minSize
internal: minimum size of the widget
Definition: Widget.hpp:100
virtual bool onStartAnnimation(enum ewol::Widget::annimationMode _mode)
Event when start the annimation.
Definition: Widget.hpp:566
esignal::Signal< float > signalAnnimationRatio
event when % of annimation change (integer)
Definition: Widget.hpp:514
virtual void onRegenerateDisplay()
Event generated when a redraw is needed.
Definition: Widget.hpp:460
esignal::Signal signalAnnimationStop
event when stop annimation
Definition: Widget.hpp:515
virtual void setSize(const vec2 &_value)
set the widget size
Definition: Widget.hpp:126
eproperty::Range< float > propertyAnnimationTimeStop
time to produce start annimation
Definition: Widget.hpp:528
esignal::Signal signalAnnimationStart
event when start annimation
Definition: Widget.hpp:513
virtual void onGetFocus()
Event of the focus has been grep by the current widget.
Definition: Widget.hpp:265
vec2 m_size
internal: current size of the widget
Definition: Widget.hpp:99
Widget class is the main widget interface, it hase some generic properties: :** known his parent :** ...
Definition: Widget.hpp:73
eproperty::Value< bvec2 > propertyFill
the widget will fill all the space provided by the parrent.
Definition: Widget.hpp:80
virtual void onLostFocus()
Event of the focus has been lost by the current widget.
Definition: Widget.hpp:269
virtual int32_t getMouseLimit()
get the number of mouse event supported
Definition: Widget.hpp:281
Definition: Widget.hpp:52
eproperty::List< int32_t > propertyAnnimationTypeStart
type of start annimation
Definition: Widget.hpp:525
Definition: Entry.hpp:57
eproperty::Value< gale::Dimension > propertyMinSize
user define the minimum size of the widget
Definition: Widget.hpp:77
eproperty::Value< bvec2 > propertyExpand
the widget will expand if possible
Definition: Widget.hpp:79
float m_annimationratio
Ratio of the annimation [0..1].
Definition: Widget.hpp:523
std::string message
data link with the event
Definition: Widget.hpp:54
virtual bool getKeyboardRepeate()
get the keyboard repeating event supporting.
Definition: Widget.hpp:302
esignal::Signal< std::string > signalShortcut
signal handle of the message
Definition: Widget.hpp:383
eproperty::List< enum ewol::gravity > propertyGravity
Gravity of the widget.
Definition: Widget.hpp:82
vec2 m_offset
Offset of the display in the viewport.
Definition: Widget.hpp:147
virtual void setKeyboardRepeate(bool _state)
set the keyboard repeating event supporting.
Definition: Widget.hpp:310
virtual void setMouseLimit(int32_t _numberState)
get the number of mouse event supported
Definition: Widget.hpp:288