8 #ifndef Guit_Gadget_hpp
9 #define Guit_Gadget_hpp
10 #include <gobject.hpp>
12 #include <gproplist.hpp>
13 #include <gadgettype.hpp>
17 enum struct GHandle : uint8_t {
19 Left, Right, Top, Bottom,
20 TopLeft, TopRight, BottomLeft, BottomRight,
27 enum struct GClone : uint8_t {
34 GClone operator|(GClone,GClone);
35 uint8_t operator&(GClone,GClone);
71 using IsGadget = bool;
72 using IsGadgetOrVarProp = bool;
73 using IsGadgetChild = bool;
94 virtual GType& type()
const {
return Type();}
99 GString
typeName()
const override {
return type().name_;}
100 GId typeId()
const {
return type().id_;}
107 virtual GItem* toItem() {
return nullptr;}
108 virtual GTextItem* toTextItem() {
return nullptr;}
109 virtual GValueItem* toValueItem() {
return nullptr;}
110 virtual GShape* toShape() {
return nullptr;}
111 virtual GChoiceBox* toChoiceBox() {
return nullptr;}
112 virtual GScrollBox* toScrollBox() {
return nullptr;}
113 virtual GChartBox* toChartBox() {
return nullptr;}
114 virtual GWindow* toWindow() {
return nullptr;}
115 virtual GMenu* toMenu() {
return nullptr;}
116 virtual GMenuBar* toMenuBar() {
return nullptr;}
117 virtual GTable* toTable() {
return nullptr;}
118 virtual GTRow* toTRow() {
return nullptr;}
119 virtual GTHead* toTHead() {
return nullptr;}
124 void blink(GString
const& message =
"", GTime duration = 350);
142 virtual GProp*
findProp(GPropType&)
const;
158 virtual GProp&
prop(GPropType&,
bool in_css =
false);
161 T&
prop(
bool in_css =
false) {
return dynamic_cast<T&
>(
prop(T::Type(), in_css));}
178 virtual GString
text()
const;
195 virtual void add(GString
const& str);
198 void add(GPropList
const& proplist);
209 void add(
class GStateTransition&);
210 void addFun(GFunction
const&);
211 void addFun(GEventFunction
const&);
212 void addFun(GCaller&);
226 virtual void add(GMenu* child);
227 virtual void add(GMenu& child) {
add(&child);}
228 virtual void add(GWindow*);
229 virtual void add(GWindow& child) {
add(&child);}
239 bool remove(GProp*
prop);
240 bool remove(GProp&
prop);
241 virtual bool remove(GTrigger&);
242 virtual bool remove(GPropType&);
262 Gadget& setRichText(
bool =
true);
272 bool isCatchingEvents()
const {
return modes_.catchEvents;}
279 bool isIgnoringEvents()
const {
return modes_.ignoreEvents;}
286 bool isChecked()
const {
return modes_.checked;}
294 bool isCheckable()
const {
return modes_.checkable;}
302 bool isSelfEnabled()
const {
return modes_.enabled;}
303 bool isTrulyEnabled()
const {
return settings_.trulyEnabled;}
311 bool isShown()
const {
return modes_.shown;}
320 enum struct Update {IfNeeded, Needed, Now, Css};
339 virtual Gadget* getPseudoParent()
const {
return parent_;}
375 bool read(GString
const& filename, GIOMode = GIOMode::Auto);
376 bool read(std::istream&, GIOMode = GIOMode::Auto);
382 bool write(GString
const& filename, GIOMode)
const;
383 bool write(std::ostream&, GIOMode)
const;
390 bool isColumn()
const {
return modes_.dir == GFlow::Column;}
391 bool isRow()
const {
return modes_.dir == GFlow::Row;}
392 bool isPie()
const {
return modes_.dir == GFlow::Pie;}
419 virtual void move(GPoint
const&);
420 virtual void move(
float x,
float y);
434 virtual void resize(
float w,
float h);
435 virtual void resize(GDim
const&);
453 virtual GPoint
pos()
const;
454 virtual float x()
const;
455 virtual float y()
const;
460 int zlayer()
const {
return layout_.layer;}
466 float wx()
const {
return frame_.x;}
467 float wy()
const {
return frame_.y;}
473 float screenX()
const;
474 float screenY()
const;
479 float w()
const {
return frame_.w;}
480 float h()
const {
return frame_.h;}
481 GDim dim()
const {
return GDim(frame_.w, frame_.h);}
492 float angleExtent()
const;
493 void setAngleStart(
float);
494 void setAngleExtent(
float);
504 Top = -10, Bottom = -20, Left = -30, Right = -40, ToolBar = -50, ScrollBar = -60
506 virtual Place place()
const {
return Place::Content;}
509 bool unclippedLayers()
const {
return modes_.unclippedLayers;}
510 Gadget& setUnclippedLayers(
bool =
true);
513 virtual void keepInside(GBox& box, GPoint& point);
524 Gadget& setActivable(
bool =
true);
530 Gadget& setDownActivable(
bool =
true);
536 bool isFocusable()
const {
return modes_.focusable;}
543 void setInternal() {modes_.internal = 1;}
547 GadgetModes
const&
modes()
const {
return modes_;}
550 GEventType
const&
eventMask()
const {
return eventmask_;}
562 virtual void doPaint(GRenderGraphics&, GRender* parent_render);
579 virtual void init(GRender* parrender);
580 virtual void initClone(
Gadget& from, GClone
const&);
581 virtual void addProp(GProp&,
bool add_to_list);
582 virtual void addProp2(GProp&,
bool add_to_list);
583 virtual bool removeProp(GProp&,
bool rem_from_proplist);
584 virtual bool removeProp2(GProp&,
bool rem_from_proplist);
586 virtual void addOpener(
Gadget& opened, GTrigger&,
int btn,
bool autoplace);
588 virtual void readValues(std::istream&,
class GIOBuffer&);
589 virtual void writeValues(std::ostream&,
class GIOBuffer&)
const;
591 virtual void readAll(std::istream&,
class GIOBuffer&);
592 virtual void writeAll(std::ostream&,
class GIOBuffer&)
const;
594 virtual void readAux(std::istream&,
class GIOBuffer&) {}
595 virtual void writeAux(std::ostream&,
class GIOBuffer&)
const {}
597 int8_t rowFlex(
Gadget const* parent);
598 int8_t columnFlex(
Gadget const* parent);
599 void setRowFlex(
Gadget const* parent, int8_t val);
600 void setColumnFlex(
Gadget const* parent, int8_t val);
602 enum SelectFrom {FromButton, FromChoice, FromSelect};
604 virtual void selectImpl(
bool state, SelectFrom from);
607 virtual Gadget* getUpdateParent();
610 virtual void computeSize(GRender* parent_render,
bool use_size_prop);
613 virtual void pack(GRender* parent_render) {}
616 virtual void packPos(
float parentx,
float parenty);
619 virtual void moveImpl(
float wx,
float wy,
bool callcb);
622 virtual void movedResizedCB(GRect
const& initialframe);
624 void setShape(
class GBorderValue*);
628 virtual GHandle handleDown(GPoint
const&
wpos,
bool inter);
629 virtual void handleDrag(
float dx,
float dy, GHandle
const&);
630 virtual void handleUp(GPoint
const&
wpos, GHandle
const&);
633 virtual void paintHandleFrame(GRenderGraphics&);
634 void paintHandle(GRenderGraphics& g,
float x,
float y,
float handle);
635 bool pickHandle(GPoint
const& pt,
float x,
float y);
638 virtual void keepTopLeftInParent(GBox& par, GPoint&,
float& dx,
float& dy);
639 virtual void keepBottomRightInParent(GBox& par, GPoint& p,
float&
w,
float& h);
641 static const GString emptystring_;
643 GadgetSettings settings_{};
644 GadgetModes modes_{};
645 GadgetLayout layout_{};
646 GEventType eventmask_{};
650 gptr<class GadgetStyle> style_;
651 GadgetShape* shape_{};
657 using GadgetList = std::vector<gptr<Gadget>>;