vmap/libs/gtkutil/widget.h

118 lines
3.1 KiB
C
Raw Normal View History

2020-11-17 11:16:16 +00:00
/*
Copyright (C) 2001-2006, William Joseph.
All Rights Reserved.
This file is part of GtkRadiant.
GtkRadiant is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GtkRadiant is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GtkRadiant; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#if !defined( INCLUDED_GTKUTIL_WIDGET_H )
#define INCLUDED_GTKUTIL_WIDGET_H
#include <list>
#include <uilib/uilib.h>
#include <gdk/gdk.h>
#include "generic/callback.h"
#include "warnings.h"
#include "debugging/debugging.h"
#include "property.h"
class ToggleItem {
2021-08-04 20:23:18 +00:00
Callback<void(const Callback<void(bool)> &)> m_exportCallback;
typedef std::list<Callback<void (bool)> > ImportCallbacks;
ImportCallbacks m_importCallbacks;
2020-11-17 11:16:16 +00:00
public:
2021-08-04 20:23:18 +00:00
ToggleItem(const Callback<void(const Callback<void(bool)> &)> &exportCallback) : m_exportCallback(exportCallback)
{
}
void update()
{
for (ImportCallbacks::iterator i = m_importCallbacks.begin(); i != m_importCallbacks.end(); ++i) {
m_exportCallback(*i);
}
}
void addCallback(const Callback<void(bool)> &callback)
{
m_importCallbacks.push_back(callback);
m_exportCallback(callback);
}
typedef MemberCaller<ToggleItem, void (const Callback<void (bool)> &), &ToggleItem::addCallback> AddCallbackCaller;
2020-11-17 11:16:16 +00:00
};
class ToggleShown {
2021-08-04 20:23:18 +00:00
bool m_shownDeferred;
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
ToggleShown(const ToggleShown &other); // NOT COPYABLE
ToggleShown &operator=(const ToggleShown &other); // NOT ASSIGNABLE
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
static gboolean notify_visible(ui::Widget widget, gpointer dummy, ToggleShown *self);
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
static gboolean destroy(ui::Widget widget, ToggleShown *self);
2020-11-17 11:16:16 +00:00
public:
2021-08-04 20:23:18 +00:00
ui::Widget m_widget;
ToggleItem m_item;
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
ToggleShown(bool shown)
: m_shownDeferred(shown), m_widget(ui::null), m_item(ActiveCaller(*this))
{
}
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
void update();
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
bool active() const;
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
void exportActive(const Callback<void(bool)> &importCallback);
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
typedef MemberCaller<ToggleShown, void (const Callback<void (bool)> &), &ToggleShown::exportActive> ActiveCaller;
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
void set(bool shown);
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
void toggle();
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
typedef MemberCaller<ToggleShown, void (), &ToggleShown::toggle> ToggleCaller;
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
void connect(ui::Widget widget);
2020-11-17 11:16:16 +00:00
};
void widget_queue_draw(ui::Widget &widget);
2021-08-04 20:23:18 +00:00
typedef ReferenceCaller<ui::Widget, void (), widget_queue_draw> WidgetQueueDrawCaller;
2020-11-17 11:16:16 +00:00
void widget_make_default(ui::Widget widget);
class WidgetFocusPrinter {
2021-08-04 20:23:18 +00:00
const char *m_name;
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
static gboolean focus_in(ui::Widget widget, GdkEventFocus *event, WidgetFocusPrinter *self);
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
static gboolean focus_out(ui::Widget widget, GdkEventFocus *event, WidgetFocusPrinter *self);
2020-11-17 11:16:16 +00:00
public:
2021-08-04 20:23:18 +00:00
WidgetFocusPrinter(const char *name) : m_name(name)
{
}
2020-11-17 11:16:16 +00:00
2021-08-04 20:23:18 +00:00
void connect(ui::Widget widget);
2020-11-17 11:16:16 +00:00
};
#endif