|
12 | 12 | #include <LibGUI/GWindowServerConnection.h>
|
13 | 13 | #include <unistd.h>
|
14 | 14 |
|
| 15 | +#include <LibGUI/GButton.h> |
| 16 | +#include <LibGUI/GCheckBox.h> |
| 17 | +#include <LibGUI/GGroupBox.h> |
| 18 | +#include <LibGUI/GLabel.h> |
| 19 | +#include <LibGUI/GRadioButton.h> |
| 20 | +#include <LibGUI/GScrollBar.h> |
| 21 | +#include <LibGUI/GSlider.h> |
| 22 | +#include <LibGUI/GSpinBox.h> |
| 23 | +#include <LibGUI/GTextBox.h> |
| 24 | + |
| 25 | +REGISTER_GWIDGET(GButton) |
| 26 | +REGISTER_GWIDGET(GCheckBox) |
| 27 | +REGISTER_GWIDGET(GGroupBox) |
| 28 | +REGISTER_GWIDGET(GLabel) |
| 29 | +REGISTER_GWIDGET(GRadioButton) |
| 30 | +REGISTER_GWIDGET(GScrollBar) |
| 31 | +REGISTER_GWIDGET(GSlider) |
| 32 | +REGISTER_GWIDGET(GSpinBox) |
| 33 | +REGISTER_GWIDGET(GTextBox) |
| 34 | +REGISTER_GWIDGET(GWidget) |
| 35 | + |
| 36 | +static HashMap<String, GWidgetClassRegistration*>& widget_classes() |
| 37 | +{ |
| 38 | + static HashMap<String, GWidgetClassRegistration*>* map; |
| 39 | + if (!map) |
| 40 | + map = new HashMap<String, GWidgetClassRegistration*>; |
| 41 | + return *map; |
| 42 | +} |
| 43 | + |
| 44 | +GWidgetClassRegistration::GWidgetClassRegistration(const String& class_name, Function<NonnullRefPtr<GWidget>(GWidget*)> factory) |
| 45 | + : m_class_name(class_name) |
| 46 | + , m_factory(move(factory)) |
| 47 | +{ |
| 48 | + widget_classes().set(class_name, this); |
| 49 | +} |
| 50 | + |
| 51 | +GWidgetClassRegistration::~GWidgetClassRegistration() |
| 52 | +{ |
| 53 | + ASSERT_NOT_REACHED(); |
| 54 | +} |
| 55 | + |
| 56 | +void GWidgetClassRegistration::for_each(Function<void(const GWidgetClassRegistration&)> callback) |
| 57 | +{ |
| 58 | + for (auto& it : widget_classes()) { |
| 59 | + callback(*it.value); |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +const GWidgetClassRegistration* GWidgetClassRegistration::find(const String& class_name) |
| 64 | +{ |
| 65 | + return widget_classes().get(class_name).value_or(nullptr); |
| 66 | +} |
| 67 | + |
15 | 68 | GWidget::GWidget(GWidget* parent)
|
16 | 69 | : CObject(parent, true)
|
17 | 70 | , m_font(Font::default_font())
|
|
0 commit comments