1 /**
2  * File name: RkWidget.h
3  * Project: Redkite (A small GUI toolkit)
4  *
5  * Copyright (C) 2019 Iurie Nistor <http://geontime.com>
6  *
7  * This file is part of Redkite.
8  *
9  * Redkite is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #ifndef RK_WIDGET_H
25 #define RK_WIDGET_H
26 
27 #include "Rk.h"
28 #include "RkObject.h"
29 #include "RkEventQueue.h"
30 #include "RkCanvas.h"
31 #include "RkRect.h"
32 #include "RkColor.h"
33 #include "RkFont.h"
34 
35 class RkEvent;
36 class RkCloseEvent;
37 class RkKeyEvent;
38 class RkMouseEvent;
39 class RkWheelEvent;
40 class RkDropEvent;
41 class RkMoveEvent;
42 class RkResizeEvent;
43 class RkPaintEvent;
44 class RkShowEvent;
45 class RkHideEvent;
46 class RkFocusEvent;
47 class RkHoverEvent;
48 class RkMain;
49 struct RkWindowId;
50 class RkNativeWindowInfo;
51 
52 class RK_EXPORT RkWidget: public RkObject, public RkCanvas {
53   public:
54           RK_CLASS_INFO(style_element, "RkWidget")
55           RK_CLASS_INFO(style_class, "")
56           RK_CLASS_INFO(style_id, "")
57 
58           explicit RkWidget(RkMain *mainApp, Rk::WindowFlags flags = Rk::WindowFlags::Widget);
59           explicit RkWidget(RkMain *mainApp,
60                             const RkNativeWindowInfo &parent,
61                             Rk::WindowFlags flags = Rk::WindowFlags::Widget);
62           explicit RkWidget(RkWidget *parent, Rk::WindowFlags flags = Rk::WindowFlags::Widget);
63           virtual ~RkWidget();
64           Rk::WindowFlags windowFlags() const;
65 	  void show(bool b = true);
66 	  bool isShown() const;
67           void hide();
68           void setTitle(const std::string &title);
69 	  const std::string& title() const;
70           const RkNativeWindowInfo* nativeWindowInfo() const;
71 	  bool isClose() const;
72           RkWidget* parentWidget() const;
73           RkWindowId id() const;
74 	  void setSize(int w, int h);
75 	  void setSize(const RkSize &size);
76 	  RkSize size() const;
77 	  void setWidth(int w);
78 	  int width() const;
79           int minimumWidth() const;
80           int maximumWidth() const;
81           void setMinimumWidth(int width);
82           void setMaximumWidth(int width);
83 	  void setHeight(int h);
84 	  int height() const;
85           int minimumHeight() const;
86           int maximumHeight() const;
87           void setMinimumHeight(int height);
88           void setMaximumHeight(int height);
89           void setFixedWidth(int width);
90           void setFixedHeight(int height);
91           void setFixedSize(const RkSize &size);
92           void setFixedSize(int width, int height);
93           int x() const;
94           void setX(int x);
95           int y() const;
96           void setY(int y);
97           void setPosition(int x, int y);
98           void setPosition(const RkPoint &p);
99           RkPoint position() const;
100           void setBorderWidth(int width);
101           int borderWidth() const;
102           void setBackgroundColor(int red, int green, int blue);
103           void setBackgroundColor(const RkColor &color);
104           const RkColor& background() const;
105           void setBorderColor(int red, int green, int blue);
106           const RkColor& borderColor() const;
107           void setTextColor(const RkColor &color);
108           const RkColor& textColor() const;
109           const RkColor& color() const;
110           void setColor(const RkColor &color);
111           const RkFont& font() const;
112           void setFont(const RkFont &font);
113           const RkCanvasInfo *getCanvasInfo() const override;
114           RkRect rect() const;
115           void update();
116           void close();
117           Rk::Modality modality() const;
118           bool isModal() const;
119           void setWidgetAttribute(Rk::WidgetAttribute attribute);
120           void clearWidgetAttribute(Rk::WidgetAttribute attribute);
121           Rk::WidgetAttribute widgetAttributes() const;
122           void enableInput();
123           void disableInput();
124           bool isInputEnabled() const;
125           RkWidget* getTopWidget();
126           bool isTopWindow() const;
127           void enableGrabKey(bool b);
128           bool grabKeyEnabled() const;
129           void propagateGrabKey(bool b);
130           bool propagateGrabKeyEnabled() const;
131           void setFocus(bool b = true);
132           bool hasFocus() const;
133           void setPointerShape(Rk::PointerShape shape);
134           Rk::PointerShape pointerShape() const;
135           void setScaleFactor(double factor);
136           double scaleFactor() const;
137           bool pointerIsOverWindow() const;
138           bool isChild(RkWidget *widget);
139 
140   protected:
141           RK_DELCATE_IMPL_PTR(RkWidget);
142           RkWidget(RkWidget *parent, std::unique_ptr<RkWidgetImpl> impl);
143           virtual void event(RkEvent *event) override;
144           virtual void closeEvent(RkCloseEvent *event);
145           virtual void keyPressEvent(RkKeyEvent *event);
146           virtual void keyReleaseEvent(RkKeyEvent *event);
147           virtual void shortcutEvent(RkKeyEvent *event);
148           virtual void mouseMoveEvent(RkMouseEvent *event);
149           virtual void mouseButtonPressEvent(RkMouseEvent *event);
150           virtual void mouseButtonReleaseEvent(RkMouseEvent *event);
151           virtual void mouseDoubleClickEvent(RkMouseEvent *event);
152           virtual void wheelEvent(RkWheelEvent *event);
153           virtual void dropEvent(RkDropEvent *event);
154           virtual void moveEvent(RkMoveEvent *event);
155           virtual void resizeEvent(RkResizeEvent *event);
156           virtual void paintEvent(RkPaintEvent *event);
157           virtual void showEvent(RkShowEvent *event);
158           virtual void hideEvent(RkHideEvent *event);
159           virtual void focusEvent(RkFocusEvent *event);
160           virtual void hoverEvent(RkHoverEvent *event);
161 
162  private:
163           RK_DISABLE_COPY(RkWidget);
164           RK_DISABLE_MOVE(RkWidget);
165           friend class RkEventQueue;
166 };
167 
168 #endif // RK_WIDGET_H
169