vmap/libs/gtkutil/widget.cpp

87 lines
1.8 KiB
C++
Raw Normal View History

2020-11-17 11:16:16 +00:00
#include "widget.h"
#include <gtk/gtk.h>
void widget_queue_draw(ui::Widget &widget)
{
2021-08-04 20:23:18 +00:00
gtk_widget_queue_draw(widget);
2020-11-17 11:16:16 +00:00
}
void widget_make_default(ui::Widget widget)
{
2021-08-04 20:23:18 +00:00
gtk_widget_set_can_default(widget, true);
gtk_widget_grab_default(widget);
2020-11-17 11:16:16 +00:00
}
gboolean ToggleShown::notify_visible(ui::Widget widget, gpointer dummy, ToggleShown *self)
{
2021-08-04 20:23:18 +00:00
self->update();
return FALSE;
2020-11-17 11:16:16 +00:00
}
gboolean ToggleShown::destroy(ui::Widget widget, ToggleShown *self)
{
2021-08-04 20:23:18 +00:00
self->m_shownDeferred = gtk_widget_get_visible(self->m_widget) != FALSE;
self->m_widget = ui::Widget(ui::null);
return FALSE;
2020-11-17 11:16:16 +00:00
}
void ToggleShown::update()
{
2021-08-04 20:23:18 +00:00
m_item.update();
2020-11-17 11:16:16 +00:00
}
bool ToggleShown::active() const
{
2021-08-04 20:23:18 +00:00
if (!m_widget) {
return m_shownDeferred;
} else {
return gtk_widget_get_visible(m_widget) != FALSE;
}
2020-11-17 11:16:16 +00:00
}
void ToggleShown::exportActive(const Callback<void(bool)> &importCallback)
{
2021-08-04 20:23:18 +00:00
importCallback(active());
2020-11-17 11:16:16 +00:00
}
void ToggleShown::set(bool shown)
{
2021-08-04 20:23:18 +00:00
if (!m_widget) {
m_shownDeferred = shown;
} else {
m_widget.visible(shown);
}
2020-11-17 11:16:16 +00:00
}
void ToggleShown::toggle()
{
2021-08-04 20:23:18 +00:00
m_widget.visible(!m_widget.visible());
2020-11-17 11:16:16 +00:00
}
void ToggleShown::connect(ui::Widget widget)
{
2021-08-04 20:23:18 +00:00
m_widget = widget;
m_widget.visible(m_shownDeferred);
m_widget.connect("notify::visible", G_CALLBACK(notify_visible), this);
m_widget.connect("destroy", G_CALLBACK(destroy), this);
update();
2020-11-17 11:16:16 +00:00
}
gboolean WidgetFocusPrinter::focus_in(ui::Widget widget, GdkEventFocus *event, WidgetFocusPrinter *self)
{
2021-08-04 20:23:18 +00:00
globalOutputStream() << self->m_name << " takes focus\n";
return FALSE;
2020-11-17 11:16:16 +00:00
}
gboolean WidgetFocusPrinter::focus_out(ui::Widget widget, GdkEventFocus *event, WidgetFocusPrinter *self)
{
2021-08-04 20:23:18 +00:00
globalOutputStream() << self->m_name << " loses focus\n";
return FALSE;
2020-11-17 11:16:16 +00:00
}
void WidgetFocusPrinter::connect(ui::Widget widget)
{
2021-08-04 20:23:18 +00:00
widget.connect("focus_in_event", G_CALLBACK(focus_in), this);
widget.connect("focus_out_event", G_CALLBACK(focus_out), this);
2020-11-17 11:16:16 +00:00
}