2014-02-07 19:51:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2014 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the licence, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Matthias Clasen
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2019-11-11 10:58:43 +00:00
|
|
|
#include "gtkmodelbuttonprivate.h"
|
2014-02-07 19:51:34 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
#include "gtkactionhelperprivate.h"
|
2019-09-28 08:32:14 +00:00
|
|
|
#include "gtkboxlayout.h"
|
2019-09-28 10:37:00 +00:00
|
|
|
#include "gtkgestureclick.h"
|
2014-02-07 19:51:34 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2019-06-10 03:10:13 +00:00
|
|
|
#include "gtkmenutrackeritemprivate.h"
|
2014-02-07 19:51:34 +00:00
|
|
|
#include "gtkimage.h"
|
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkbox.h"
|
|
|
|
#include "gtkstylecontext.h"
|
|
|
|
#include "gtktypebuiltins.h"
|
2014-10-24 03:38:46 +00:00
|
|
|
#include "gtkstack.h"
|
2019-06-13 00:13:21 +00:00
|
|
|
#include "gtkpopovermenuprivate.h"
|
2014-10-26 22:08:26 +00:00
|
|
|
#include "gtkintl.h"
|
2015-10-30 04:29:47 +00:00
|
|
|
#include "gtkcssnodeprivate.h"
|
2015-12-19 19:53:57 +00:00
|
|
|
#include "gtkcsstypesprivate.h"
|
2015-10-30 04:29:47 +00:00
|
|
|
#include "gtkstylecontextprivate.h"
|
2020-01-28 14:03:42 +00:00
|
|
|
#include "gtkbuiltiniconprivate.h"
|
2019-06-06 00:41:45 +00:00
|
|
|
#include "gtksizegroup.h"
|
2019-06-07 13:02:45 +00:00
|
|
|
#include "gtkactionable.h"
|
2019-06-13 00:13:21 +00:00
|
|
|
#include "gtkeventcontrollermotion.h"
|
|
|
|
#include "gtkeventcontrollerkey.h"
|
2020-02-20 01:51:03 +00:00
|
|
|
#include "gtkeventcontrollerfocus.h"
|
2019-08-27 08:28:29 +00:00
|
|
|
#include "gtknative.h"
|
2020-03-24 05:07:09 +00:00
|
|
|
#include "gtkshortcuttrigger.h"
|
|
|
|
#include "gtkshortcutcontroller.h"
|
|
|
|
#include "gtkshortcut.h"
|
2014-02-07 19:51:34 +00:00
|
|
|
|
2014-10-26 23:04:28 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtkmodelbutton
|
|
|
|
* @Short_description: A button that uses a GAction as model
|
|
|
|
* @Title: GtkModelButton
|
|
|
|
*
|
|
|
|
* GtkModelButton is a button class that can use a #GAction as its model.
|
|
|
|
* In contrast to #GtkToggleButton or #GtkRadioButton, which can also
|
2015-02-18 10:57:05 +00:00
|
|
|
* be backed by a #GAction via the #GtkActionable:action-name property,
|
2014-10-26 23:04:28 +00:00
|
|
|
* GtkModelButton will adapt its appearance according to the kind of
|
|
|
|
* action it is backed by, and appear either as a plain, check or
|
|
|
|
* radio button.
|
|
|
|
*
|
|
|
|
* Model buttons are used when popovers from a menu model with
|
2020-02-21 08:04:27 +00:00
|
|
|
* gtk_popover_menu_new_from_model(); they can also be used manually in
|
2014-10-26 23:04:28 +00:00
|
|
|
* a #GtkPopoverMenu.
|
|
|
|
*
|
|
|
|
* When the action is specified via the #GtkActionable:action-name
|
|
|
|
* and #GtkActionable:action-target properties, the role of the button
|
|
|
|
* (i.e. whether it is a plain, check or radio button) is determined by
|
|
|
|
* the type of the action and doesn't have to be explicitly specified
|
|
|
|
* with the #GtkModelButton:role property.
|
|
|
|
*
|
|
|
|
* The content of the button is specified by the #GtkModelButton:text
|
|
|
|
* and #GtkModelButton:icon properties.
|
|
|
|
*
|
|
|
|
* The appearance of model buttons can be influenced with the
|
|
|
|
* #GtkModelButton:centered and #GtkModelButton:iconic properties.
|
|
|
|
*
|
|
|
|
* Model buttons have built-in support for submenus in #GtkPopoverMenu.
|
|
|
|
* To make a GtkModelButton that opens a submenu when activated, set
|
|
|
|
* the #GtkModelButton:menu-name property. To make a button that goes
|
|
|
|
* back to the parent menu, you should set the #GtkModelButton:inverted
|
|
|
|
* property to place the submenu indicator at the opposite side.
|
|
|
|
*
|
|
|
|
* # Example
|
|
|
|
*
|
|
|
|
* |[
|
|
|
|
* <object class="GtkPopoverMenu">
|
|
|
|
* <child>
|
|
|
|
* <object class="GtkBox">
|
|
|
|
* <property name="visible">True</property>
|
2020-02-26 01:57:20 +00:00
|
|
|
* <property name="margin-start">10</property>
|
|
|
|
* <property name="margin-end">10</property>
|
|
|
|
* <property name="margin-top">10</property>
|
|
|
|
* <property name="margin-bottom">10</property>
|
2014-10-26 23:04:28 +00:00
|
|
|
* <child>
|
|
|
|
* <object class="GtkModelButton">
|
|
|
|
* <property name="visible">True</property>
|
|
|
|
* <property name="action-name">view.cut</property>
|
|
|
|
* <property name="text" translatable="yes">Cut</property>
|
|
|
|
* </object>
|
|
|
|
* </child>
|
|
|
|
* <child>
|
|
|
|
* <object class="GtkModelButton">
|
|
|
|
* <property name="visible">True</property>
|
|
|
|
* <property name="action-name">view.copy</property>
|
|
|
|
* <property name="text" translatable="yes">Copy</property>
|
|
|
|
* </object>
|
|
|
|
* </child>
|
|
|
|
* <child>
|
|
|
|
* <object class="GtkModelButton">
|
|
|
|
* <property name="visible">True</property>
|
|
|
|
* <property name="action-name">view.paste</property>
|
|
|
|
* <property name="text" translatable="yes">Paste</property>
|
|
|
|
* </object>
|
|
|
|
* </child>
|
|
|
|
* </object>
|
|
|
|
* </child>
|
|
|
|
* </object>
|
|
|
|
* ]|
|
2015-11-03 17:51:52 +00:00
|
|
|
*
|
|
|
|
* # CSS nodes
|
|
|
|
*
|
|
|
|
* |[<!-- language="plain" -->
|
|
|
|
* modelbutton
|
2015-12-16 15:55:52 +00:00
|
|
|
* ├── <child>
|
2015-11-03 17:51:52 +00:00
|
|
|
* ╰── check
|
|
|
|
* ]|
|
|
|
|
*
|
|
|
|
* |[<!-- language="plain" -->
|
|
|
|
* modelbutton
|
2015-12-16 15:55:52 +00:00
|
|
|
* ├── <child>
|
2015-11-03 17:51:52 +00:00
|
|
|
* ╰── radio
|
|
|
|
* ]|
|
|
|
|
*
|
|
|
|
* |[<!-- language="plain" -->
|
|
|
|
* modelbutton
|
2015-12-16 15:55:52 +00:00
|
|
|
* ├── <child>
|
2015-11-03 17:51:52 +00:00
|
|
|
* ╰── arrow
|
|
|
|
* ]|
|
|
|
|
*
|
|
|
|
* GtkModelButton has a main CSS node with name modelbutton, and a subnode,
|
|
|
|
* which will have the name check, radio or arrow, depending on the role
|
|
|
|
* of the button and whether it has a menu name set.
|
|
|
|
*
|
|
|
|
* The subnode is positioned before or after the content nodes and gets the
|
|
|
|
* .left or .right style class, depending on where it is located.
|
2015-12-16 16:37:49 +00:00
|
|
|
*
|
|
|
|
* |[<!-- language="plain" -->
|
|
|
|
* button.model
|
|
|
|
* ├── <child>
|
|
|
|
* ╰── check
|
|
|
|
* ]|
|
|
|
|
*
|
2016-02-08 21:49:01 +00:00
|
|
|
* Iconic model buttons (see #GtkModelButton:iconic) change the name of
|
2015-12-16 16:37:49 +00:00
|
|
|
* their main node to button and add a .model style class to it. The indicator
|
|
|
|
* subnode is invisible in this case.
|
2014-10-26 23:04:28 +00:00
|
|
|
*/
|
|
|
|
|
2014-02-07 19:51:34 +00:00
|
|
|
struct _GtkModelButton
|
|
|
|
{
|
2019-09-28 10:37:00 +00:00
|
|
|
GtkWidget parent_instance;
|
2014-10-26 23:04:28 +00:00
|
|
|
|
2014-02-07 19:51:34 +00:00
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *image;
|
|
|
|
GtkWidget *label;
|
2019-06-06 23:04:52 +00:00
|
|
|
GtkWidget *accel_label;
|
2019-06-07 02:37:24 +00:00
|
|
|
GtkWidget *start_box;
|
2019-06-06 00:41:45 +00:00
|
|
|
GtkWidget *start_indicator;
|
|
|
|
GtkWidget *end_indicator;
|
2019-08-27 08:28:29 +00:00
|
|
|
GtkWidget *popover;
|
2019-09-28 10:37:00 +00:00
|
|
|
GtkActionHelper *action_helper;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *menu_name;
|
2014-10-26 22:08:26 +00:00
|
|
|
GtkButtonRole role;
|
2019-06-06 00:41:45 +00:00
|
|
|
GtkSizeGroup *indicators;
|
2019-06-06 23:04:52 +00:00
|
|
|
char *accel;
|
2019-09-08 22:45:58 +00:00
|
|
|
guint open_timeout;
|
2020-03-24 05:07:09 +00:00
|
|
|
GtkEventController *controller;
|
2019-09-28 10:37:00 +00:00
|
|
|
|
|
|
|
guint active : 1;
|
|
|
|
guint centered : 1;
|
|
|
|
guint iconic : 1;
|
2014-02-07 19:51:34 +00:00
|
|
|
};
|
|
|
|
|
2020-05-07 00:25:42 +00:00
|
|
|
typedef struct _GtkModelButtonClass GtkModelButtonClass;
|
|
|
|
|
|
|
|
struct _GtkModelButtonClass
|
|
|
|
{
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
|
|
|
|
void (* clicked) (GtkModelButton *button);
|
|
|
|
};
|
2014-02-07 19:51:34 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
static void gtk_model_button_actionable_iface_init (GtkActionableInterface *iface);
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkModelButton, gtk_model_button, GTK_TYPE_WIDGET,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIONABLE, gtk_model_button_actionable_iface_init))
|
2014-02-07 19:51:34 +00:00
|
|
|
|
2019-11-11 10:58:43 +00:00
|
|
|
GType
|
|
|
|
gtk_button_role_get_type (void)
|
|
|
|
{
|
|
|
|
static gsize gtk_button_role_type;
|
|
|
|
|
|
|
|
if (g_once_init_enter (>k_button_role_type))
|
|
|
|
{
|
|
|
|
static const GEnumValue values[] = {
|
|
|
|
{ GTK_BUTTON_ROLE_NORMAL, "GTK_BUTTON_ROLE_NORMAL", "normal" },
|
|
|
|
{ GTK_BUTTON_ROLE_CHECK, "GTK_BUTTON_ROLE_CHECK", "check" },
|
|
|
|
{ GTK_BUTTON_ROLE_RADIO, "GTK_BUTTON_ROLE_RADIO", "radio" },
|
|
|
|
{ GTK_BUTTON_ROLE_TITLE, "GTK_BUTTON_ROLE_RADIO", "title" },
|
|
|
|
{ 0, NULL, NULL }
|
|
|
|
};
|
|
|
|
GType type;
|
|
|
|
|
|
|
|
type = g_enum_register_static (I_("GtkButtonRole"), values);
|
|
|
|
|
|
|
|
g_once_init_leave (>k_button_role_type, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gtk_button_role_type;
|
|
|
|
}
|
|
|
|
|
2014-02-07 19:51:34 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2014-10-26 22:08:26 +00:00
|
|
|
PROP_ROLE,
|
2014-02-07 19:51:34 +00:00
|
|
|
PROP_ICON,
|
|
|
|
PROP_TEXT,
|
2018-04-23 09:06:17 +00:00
|
|
|
PROP_USE_MARKUP,
|
2014-10-24 01:43:28 +00:00
|
|
|
PROP_ACTIVE,
|
2014-10-24 03:38:46 +00:00
|
|
|
PROP_MENU_NAME,
|
2019-08-27 08:28:29 +00:00
|
|
|
PROP_POPOVER,
|
2014-10-26 22:08:26 +00:00
|
|
|
PROP_ICONIC,
|
2019-06-07 13:02:45 +00:00
|
|
|
PROP_ACCEL,
|
2019-06-06 00:41:45 +00:00
|
|
|
PROP_INDICATOR_SIZE_GROUP,
|
2019-09-28 10:37:00 +00:00
|
|
|
|
|
|
|
/* actionable properties */
|
|
|
|
PROP_ACTION_NAME,
|
|
|
|
PROP_ACTION_TARGET,
|
|
|
|
LAST_PROP = PROP_ACTION_NAME
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_CLICKED,
|
|
|
|
LAST_SIGNAL
|
2014-02-07 19:51:34 +00:00
|
|
|
};
|
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
static GParamSpec *properties[LAST_PROP] = { NULL, };
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_model_button_set_action_name (GtkActionable *actionable,
|
|
|
|
const char *action_name)
|
|
|
|
{
|
|
|
|
GtkModelButton *self = GTK_MODEL_BUTTON (actionable);
|
|
|
|
|
|
|
|
if (!self->action_helper)
|
|
|
|
self->action_helper = gtk_action_helper_new (actionable);
|
|
|
|
|
|
|
|
gtk_action_helper_set_action_name (self->action_helper, action_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_model_button_set_action_target_value (GtkActionable *actionable,
|
|
|
|
GVariant *action_target)
|
|
|
|
{
|
|
|
|
GtkModelButton *self = GTK_MODEL_BUTTON (actionable);
|
|
|
|
|
|
|
|
if (!self->action_helper)
|
|
|
|
self->action_helper = gtk_action_helper_new (actionable);
|
|
|
|
|
|
|
|
gtk_action_helper_set_action_target_value (self->action_helper, action_target);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
gtk_model_button_get_action_name (GtkActionable *actionable)
|
|
|
|
{
|
|
|
|
GtkModelButton *self = GTK_MODEL_BUTTON (actionable);
|
|
|
|
|
|
|
|
return gtk_action_helper_get_action_name (self->action_helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GVariant *
|
|
|
|
gtk_model_button_get_action_target_value (GtkActionable *actionable)
|
|
|
|
{
|
|
|
|
GtkModelButton *self = GTK_MODEL_BUTTON (actionable);
|
|
|
|
|
|
|
|
return gtk_action_helper_get_action_target_value (self->action_helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_model_button_actionable_iface_init (GtkActionableInterface *iface)
|
|
|
|
{
|
|
|
|
iface->get_action_name = gtk_model_button_get_action_name;
|
|
|
|
iface->set_action_name = gtk_model_button_set_action_name;
|
|
|
|
iface->get_action_target_value = gtk_model_button_get_action_target_value;
|
|
|
|
iface->set_action_target_value = gtk_model_button_set_action_target_value;
|
|
|
|
}
|
2014-10-26 22:08:26 +00:00
|
|
|
|
2019-06-05 22:31:14 +00:00
|
|
|
static void
|
|
|
|
update_node_ordering (GtkModelButton *button)
|
|
|
|
{
|
|
|
|
GtkWidget *child;
|
|
|
|
|
2019-06-06 00:41:45 +00:00
|
|
|
if (gtk_widget_get_direction (GTK_WIDGET (button)) == GTK_TEXT_DIR_LTR)
|
2019-06-05 22:31:14 +00:00
|
|
|
{
|
2020-01-29 11:11:39 +00:00
|
|
|
if (button->start_indicator)
|
2019-09-28 10:37:00 +00:00
|
|
|
{
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (button->start_indicator, "left");
|
|
|
|
gtk_widget_remove_css_class (button->start_indicator, "right");
|
2019-09-28 10:37:00 +00:00
|
|
|
}
|
|
|
|
|
2020-01-29 11:11:39 +00:00
|
|
|
if (button->end_indicator)
|
2019-09-28 10:37:00 +00:00
|
|
|
{
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (button->end_indicator, "right");
|
|
|
|
gtk_widget_remove_css_class (button->end_indicator, "left");
|
2019-09-28 10:37:00 +00:00
|
|
|
}
|
2019-06-05 22:31:14 +00:00
|
|
|
|
|
|
|
child = gtk_widget_get_first_child (GTK_WIDGET (button));
|
2019-09-28 10:37:00 +00:00
|
|
|
if (button->start_indicator && child != button->start_box)
|
2019-06-07 02:37:24 +00:00
|
|
|
gtk_widget_insert_before (button->start_box, GTK_WIDGET (button), child);
|
2019-09-28 10:37:00 +00:00
|
|
|
|
2019-06-06 00:41:45 +00:00
|
|
|
child = gtk_widget_get_last_child (GTK_WIDGET (button));
|
2019-09-28 10:37:00 +00:00
|
|
|
if (button->end_indicator && child != button->end_indicator)
|
2019-09-28 08:08:50 +00:00
|
|
|
gtk_widget_insert_after (button->end_indicator, GTK_WIDGET (button), child);
|
2019-06-05 22:31:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-29 11:11:39 +00:00
|
|
|
if (button->start_indicator)
|
2019-09-28 10:37:00 +00:00
|
|
|
{
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (button->start_indicator, "right");
|
|
|
|
gtk_widget_remove_css_class (button->start_indicator, "left");
|
2019-09-28 10:37:00 +00:00
|
|
|
}
|
|
|
|
|
2020-01-29 11:11:39 +00:00
|
|
|
if (button->end_indicator)
|
2019-09-28 10:37:00 +00:00
|
|
|
{
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (button->end_indicator, "left");
|
|
|
|
gtk_widget_remove_css_class (button->end_indicator, "right");
|
2020-01-29 11:11:39 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
}
|
2019-06-05 22:31:14 +00:00
|
|
|
|
|
|
|
child = gtk_widget_get_first_child (GTK_WIDGET (button));
|
2019-09-28 10:37:00 +00:00
|
|
|
if (button->end_indicator && child != button->end_indicator)
|
2019-09-28 08:08:50 +00:00
|
|
|
gtk_widget_insert_before (button->end_indicator, GTK_WIDGET (button), child);
|
2019-09-28 10:37:00 +00:00
|
|
|
|
2019-06-06 00:41:45 +00:00
|
|
|
child = gtk_widget_get_last_child (GTK_WIDGET (button));
|
2019-06-07 02:37:24 +00:00
|
|
|
if (child != button->start_box)
|
|
|
|
gtk_widget_insert_after (button->start_box, GTK_WIDGET (button), child);
|
2019-06-05 22:31:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-26 22:13:02 +00:00
|
|
|
static void
|
2019-09-28 10:37:00 +00:00
|
|
|
update_end_indicator (GtkModelButton *self)
|
2014-10-26 22:13:02 +00:00
|
|
|
{
|
2019-09-28 10:37:00 +00:00
|
|
|
const gboolean is_ltr = gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_LTR;
|
2019-06-05 21:22:01 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
if (!self->end_indicator)
|
|
|
|
return;
|
2015-11-03 17:20:53 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
if (is_ltr)
|
|
|
|
{
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (self->end_indicator, "right");
|
|
|
|
gtk_widget_remove_css_class (self->end_indicator, "left");
|
2019-09-28 10:37:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (self->end_indicator, "left");
|
|
|
|
gtk_widget_remove_css_class (self->end_indicator, "right");
|
2015-11-03 17:20:53 +00:00
|
|
|
}
|
2019-09-28 10:37:00 +00:00
|
|
|
}
|
2014-10-26 22:13:02 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
static GtkStateFlags
|
|
|
|
get_start_indicator_state (GtkModelButton *self)
|
|
|
|
{
|
|
|
|
GtkStateFlags state = gtk_widget_get_state_flags (GTK_WIDGET (self));
|
|
|
|
|
|
|
|
if (self->role == GTK_BUTTON_ROLE_CHECK ||
|
|
|
|
self->role == GTK_BUTTON_ROLE_RADIO)
|
2019-06-05 22:31:14 +00:00
|
|
|
{
|
2019-09-28 10:37:00 +00:00
|
|
|
if (self->active)
|
|
|
|
state |= GTK_STATE_FLAG_CHECKED;
|
|
|
|
else
|
|
|
|
state &= ~GTK_STATE_FLAG_CHECKED;
|
2019-06-05 22:31:14 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_start_indicator (GtkModelButton *self)
|
|
|
|
{
|
|
|
|
const gboolean is_ltr = gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_LTR;
|
|
|
|
|
|
|
|
if (!self->start_indicator)
|
|
|
|
return;
|
2016-01-27 15:32:39 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
gtk_widget_set_state_flags (self->start_indicator, get_start_indicator_state (self), TRUE);
|
|
|
|
|
|
|
|
if (is_ltr)
|
|
|
|
{
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (self->start_indicator, "left");
|
|
|
|
gtk_widget_remove_css_class (self->start_indicator, "right");
|
2019-09-28 10:37:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (self->start_indicator, "right");
|
|
|
|
gtk_widget_remove_css_class (self->start_indicator, "left");
|
2019-09-28 10:37:00 +00:00
|
|
|
}
|
2020-01-29 11:11:39 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_model_button_update_state (GtkModelButton *self)
|
|
|
|
{
|
2020-01-31 18:14:05 +00:00
|
|
|
GtkStateFlags indicator_state;
|
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
update_start_indicator (self);
|
|
|
|
update_end_indicator (self);
|
|
|
|
|
2020-01-31 18:14:05 +00:00
|
|
|
indicator_state = get_start_indicator_state (self);
|
2019-09-28 10:37:00 +00:00
|
|
|
if (self->iconic)
|
2020-01-31 18:14:05 +00:00
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (self), indicator_state, TRUE);
|
2014-10-26 22:13:02 +00:00
|
|
|
}
|
|
|
|
|
2015-10-31 04:08:00 +00:00
|
|
|
static void
|
|
|
|
gtk_model_button_state_flags_changed (GtkWidget *widget,
|
|
|
|
GtkStateFlags previous_flags)
|
|
|
|
{
|
|
|
|
gtk_model_button_update_state (GTK_MODEL_BUTTON (widget));
|
2015-12-02 03:36:31 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_model_button_parent_class)->state_flags_changed (widget, previous_flags);
|
2015-10-31 04:08:00 +00:00
|
|
|
}
|
2014-10-26 22:13:02 +00:00
|
|
|
|
2014-02-07 19:51:34 +00:00
|
|
|
static void
|
2015-11-03 17:20:53 +00:00
|
|
|
gtk_model_button_direction_changed (GtkWidget *widget,
|
|
|
|
GtkTextDirection previous_dir)
|
|
|
|
{
|
|
|
|
GtkModelButton *button = GTK_MODEL_BUTTON (widget);
|
|
|
|
|
|
|
|
gtk_model_button_update_state (button);
|
|
|
|
update_node_ordering (button);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_model_button_parent_class)->direction_changed (widget, previous_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-09-28 10:37:00 +00:00
|
|
|
update_node_name (GtkModelButton *self)
|
2014-02-07 19:51:34 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *start_name;
|
|
|
|
const char *end_name;
|
2014-02-07 19:51:34 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
switch (self->role)
|
2014-02-07 19:51:34 +00:00
|
|
|
{
|
2019-06-05 21:22:01 +00:00
|
|
|
case GTK_BUTTON_ROLE_TITLE:
|
2020-01-23 23:43:26 +00:00
|
|
|
start_name = "arrow";
|
|
|
|
end_name = NULL;
|
2019-06-06 00:41:45 +00:00
|
|
|
break;
|
|
|
|
case GTK_BUTTON_ROLE_NORMAL:
|
2020-01-23 23:43:26 +00:00
|
|
|
start_name = NULL;
|
2019-09-28 10:37:00 +00:00
|
|
|
if (self->menu_name || self->popover)
|
2020-01-23 23:43:26 +00:00
|
|
|
end_name = "arrow";
|
2015-11-03 17:20:53 +00:00
|
|
|
else
|
2020-01-23 23:43:26 +00:00
|
|
|
end_name = NULL;
|
2014-02-07 19:51:34 +00:00
|
|
|
break;
|
|
|
|
|
2014-10-26 22:08:26 +00:00
|
|
|
case GTK_BUTTON_ROLE_CHECK:
|
2020-01-23 23:43:26 +00:00
|
|
|
start_name = "check";
|
|
|
|
end_name = NULL;
|
2014-02-07 19:51:34 +00:00
|
|
|
break;
|
|
|
|
|
2014-10-26 22:08:26 +00:00
|
|
|
case GTK_BUTTON_ROLE_RADIO:
|
2020-01-23 23:43:26 +00:00
|
|
|
start_name = "radio";
|
|
|
|
end_name = NULL;
|
2014-02-07 19:51:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
if (self->iconic)
|
2019-06-06 00:41:45 +00:00
|
|
|
{
|
2020-01-23 23:43:26 +00:00
|
|
|
start_name = NULL;
|
|
|
|
end_name = NULL;
|
2019-06-06 00:41:45 +00:00
|
|
|
}
|
2015-12-05 06:42:41 +00:00
|
|
|
|
2020-01-23 23:43:26 +00:00
|
|
|
if (start_name && !self->start_indicator)
|
2019-09-28 10:37:00 +00:00
|
|
|
{
|
2020-01-28 14:03:42 +00:00
|
|
|
self->start_indicator = gtk_builtin_icon_new (start_name);
|
2019-09-28 10:37:00 +00:00
|
|
|
gtk_widget_set_halign (self->start_indicator, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (self->start_indicator, GTK_ALIGN_CENTER);
|
|
|
|
update_start_indicator (self);
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (self->start_box), self->start_indicator);
|
2019-09-28 10:37:00 +00:00
|
|
|
}
|
2020-01-23 23:43:26 +00:00
|
|
|
else if (start_name)
|
2019-09-28 10:37:00 +00:00
|
|
|
{
|
2020-01-23 23:43:26 +00:00
|
|
|
gtk_css_node_set_name (gtk_widget_get_css_node (self->start_indicator), g_quark_from_static_string (start_name));
|
2019-09-28 10:37:00 +00:00
|
|
|
}
|
|
|
|
else if (self->start_indicator)
|
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_remove (GTK_BOX (self->start_box), self->start_indicator);
|
2019-09-28 10:37:00 +00:00
|
|
|
self->start_indicator = NULL;
|
|
|
|
}
|
|
|
|
|
2020-01-23 23:43:26 +00:00
|
|
|
if (end_name && !self->end_indicator)
|
2019-09-28 10:37:00 +00:00
|
|
|
{
|
2020-01-28 14:03:42 +00:00
|
|
|
self->end_indicator = gtk_builtin_icon_new (end_name);
|
2019-09-28 10:37:00 +00:00
|
|
|
gtk_widget_set_halign (self->end_indicator, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (self->end_indicator, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_parent (self->end_indicator, GTK_WIDGET (self));
|
|
|
|
update_end_indicator (self);
|
|
|
|
}
|
2020-01-23 23:43:26 +00:00
|
|
|
else if (end_name)
|
2019-09-28 10:37:00 +00:00
|
|
|
{
|
2020-01-23 23:43:26 +00:00
|
|
|
gtk_css_node_set_name (gtk_widget_get_css_node (self->end_indicator), g_quark_from_static_string (end_name));
|
2019-09-28 10:37:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_clear_pointer (&self->end_indicator, gtk_widget_unparent);
|
|
|
|
}
|
2015-11-03 17:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-09-28 10:37:00 +00:00
|
|
|
gtk_model_button_set_role (GtkModelButton *self,
|
2015-11-03 17:20:53 +00:00
|
|
|
GtkButtonRole role)
|
|
|
|
{
|
2019-09-28 10:37:00 +00:00
|
|
|
if (role == self->role)
|
2015-11-03 17:20:53 +00:00
|
|
|
return;
|
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
self->role = role;
|
2015-11-03 17:20:53 +00:00
|
|
|
|
2019-06-07 02:37:24 +00:00
|
|
|
if (role == GTK_BUTTON_ROLE_TITLE)
|
2019-09-28 10:37:00 +00:00
|
|
|
{
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (self), "title");
|
2019-09-28 10:37:00 +00:00
|
|
|
gtk_widget_set_halign (self->label, GTK_ALIGN_CENTER);
|
|
|
|
}
|
2019-06-07 02:37:24 +00:00
|
|
|
else
|
2019-09-28 10:37:00 +00:00
|
|
|
{
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_remove_css_class (GTK_WIDGET (self), "title");
|
2019-09-28 10:37:00 +00:00
|
|
|
gtk_widget_set_halign (self->label, GTK_ALIGN_START);
|
|
|
|
}
|
2019-06-07 02:37:24 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
update_node_name (self);
|
|
|
|
gtk_model_button_update_state (self);
|
2019-06-05 21:22:01 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ROLE]);
|
2014-02-07 19:51:34 +00:00
|
|
|
}
|
|
|
|
|
2014-04-26 17:50:55 +00:00
|
|
|
static void
|
2019-09-28 10:37:00 +00:00
|
|
|
update_visibility (GtkModelButton *self)
|
2014-04-26 17:50:55 +00:00
|
|
|
{
|
|
|
|
gboolean has_icon;
|
|
|
|
gboolean has_text;
|
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
has_icon = self->image && gtk_image_get_storage_type (GTK_IMAGE (self->image)) != GTK_IMAGE_EMPTY;
|
|
|
|
has_text = gtk_label_get_text (GTK_LABEL (self->label))[0] != '\0';
|
2014-04-26 17:50:55 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
gtk_widget_set_visible (self->label, has_text && (!self->iconic || !has_icon));
|
|
|
|
gtk_widget_set_hexpand (self->label,
|
|
|
|
gtk_widget_get_visible (self->label) && !has_icon);
|
|
|
|
|
2020-04-17 13:04:26 +00:00
|
|
|
if (self->accel_label)
|
|
|
|
gtk_widget_set_visible (self->accel_label, has_text && (!self->iconic || !has_icon));
|
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
if (self->image)
|
|
|
|
{
|
|
|
|
gtk_widget_set_visible (self->image, has_icon && (self->iconic || !has_text));
|
|
|
|
gtk_widget_set_hexpand (self->image,
|
|
|
|
has_icon && (!has_text || !gtk_widget_get_visible (self->label)));
|
|
|
|
}
|
2014-04-26 17:50:55 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 19:51:34 +00:00
|
|
|
static void
|
2019-09-28 10:37:00 +00:00
|
|
|
gtk_model_button_set_icon (GtkModelButton *self,
|
2014-02-07 19:51:34 +00:00
|
|
|
GIcon *icon)
|
|
|
|
{
|
2019-09-28 10:37:00 +00:00
|
|
|
if (!self->image && icon)
|
|
|
|
{
|
|
|
|
self->image = gtk_image_new_from_gicon (icon);
|
|
|
|
gtk_widget_insert_before (self->image, GTK_WIDGET (self), self->label);
|
|
|
|
}
|
|
|
|
else if (self->image && !icon)
|
|
|
|
{
|
|
|
|
g_clear_pointer (&self->image, gtk_widget_unparent);
|
|
|
|
}
|
|
|
|
else if (icon)
|
|
|
|
{
|
|
|
|
gtk_image_set_from_gicon (GTK_IMAGE (self->image), icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
update_visibility (self);
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON]);
|
2014-02-07 19:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_model_button_set_text (GtkModelButton *button,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *text)
|
2014-02-07 19:51:34 +00:00
|
|
|
{
|
2019-06-06 00:41:45 +00:00
|
|
|
gtk_label_set_text_with_mnemonic (GTK_LABEL (button->label),
|
|
|
|
text ? text : "");
|
2014-04-26 17:50:55 +00:00
|
|
|
update_visibility (button);
|
2014-10-26 22:08:26 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_TEXT]);
|
2014-02-07 19:51:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-23 09:06:17 +00:00
|
|
|
static void
|
|
|
|
gtk_model_button_set_use_markup (GtkModelButton *button,
|
|
|
|
gboolean use_markup)
|
|
|
|
{
|
|
|
|
use_markup = !!use_markup;
|
|
|
|
if (gtk_label_get_use_markup (GTK_LABEL (button->label)) == use_markup)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_label_set_use_markup (GTK_LABEL (button->label), use_markup);
|
|
|
|
update_visibility (button);
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_USE_MARKUP]);
|
|
|
|
}
|
|
|
|
|
2014-02-07 19:51:34 +00:00
|
|
|
static void
|
2014-10-24 01:43:28 +00:00
|
|
|
gtk_model_button_set_active (GtkModelButton *button,
|
|
|
|
gboolean active)
|
2014-02-07 19:51:34 +00:00
|
|
|
{
|
2018-04-08 11:43:07 +00:00
|
|
|
active = !!active;
|
2014-10-26 22:08:26 +00:00
|
|
|
if (button->active == active)
|
|
|
|
return;
|
|
|
|
|
2014-10-24 01:43:28 +00:00
|
|
|
button->active = active;
|
2014-07-02 19:12:46 +00:00
|
|
|
gtk_model_button_update_state (button);
|
2014-02-07 19:51:34 +00:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (button));
|
2014-10-26 22:08:26 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_ACTIVE]);
|
2014-02-07 19:51:34 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 03:38:46 +00:00
|
|
|
static void
|
|
|
|
gtk_model_button_set_menu_name (GtkModelButton *button,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *menu_name)
|
2014-10-24 03:38:46 +00:00
|
|
|
{
|
|
|
|
g_free (button->menu_name);
|
|
|
|
button->menu_name = g_strdup (menu_name);
|
2015-11-03 17:20:53 +00:00
|
|
|
|
|
|
|
update_node_name (button);
|
2014-10-24 03:38:46 +00:00
|
|
|
gtk_model_button_update_state (button);
|
2015-11-03 17:20:53 +00:00
|
|
|
|
2014-10-24 03:38:46 +00:00
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (button));
|
2014-10-26 22:08:26 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_MENU_NAME]);
|
2014-10-24 03:38:46 +00:00
|
|
|
}
|
|
|
|
|
2014-04-26 17:50:55 +00:00
|
|
|
static void
|
2019-09-28 10:37:00 +00:00
|
|
|
gtk_model_button_set_iconic (GtkModelButton *self,
|
2014-04-26 17:50:55 +00:00
|
|
|
gboolean iconic)
|
|
|
|
{
|
2020-01-29 11:11:39 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (self);
|
2015-10-30 04:29:47 +00:00
|
|
|
GtkCssNode *widget_node;
|
2014-06-28 04:00:16 +00:00
|
|
|
|
2018-04-08 11:43:07 +00:00
|
|
|
iconic = !!iconic;
|
2019-09-28 10:37:00 +00:00
|
|
|
if (self->iconic == iconic)
|
2014-10-26 22:08:26 +00:00
|
|
|
return;
|
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
self->iconic = iconic;
|
2014-06-28 04:00:16 +00:00
|
|
|
|
2020-01-29 11:11:39 +00:00
|
|
|
widget_node = gtk_widget_get_css_node (widget);
|
2014-04-26 17:50:55 +00:00
|
|
|
if (iconic)
|
|
|
|
{
|
2019-09-28 10:37:00 +00:00
|
|
|
gtk_widget_hide (self->start_box);
|
2020-01-23 23:43:26 +00:00
|
|
|
gtk_css_node_set_name (widget_node, g_quark_from_static_string ("button"));
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (widget, "model");
|
|
|
|
gtk_widget_add_css_class (widget, "image-button");
|
|
|
|
gtk_widget_remove_css_class (widget, "flat");
|
2014-04-26 17:50:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-28 10:37:00 +00:00
|
|
|
gtk_widget_show (self->start_box);
|
2020-01-23 23:43:26 +00:00
|
|
|
gtk_css_node_set_name (widget_node, g_quark_from_static_string ("modelbutton"));
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_remove_css_class (widget, "model");
|
|
|
|
gtk_widget_remove_css_class (widget, "image-button");
|
|
|
|
gtk_widget_add_css_class (widget, "flat");
|
2014-04-26 17:50:55 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
self->centered = iconic;
|
2019-06-07 02:37:24 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
if (!iconic)
|
|
|
|
{
|
|
|
|
if (self->start_indicator)
|
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_remove (GTK_BOX (self->start_box), self->start_indicator);
|
2019-09-28 10:37:00 +00:00
|
|
|
self->start_indicator = NULL;
|
|
|
|
}
|
|
|
|
g_clear_pointer (&self->end_indicator, gtk_widget_unparent);
|
|
|
|
}
|
2019-06-05 22:31:14 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
update_node_name (self);
|
|
|
|
update_visibility (self);
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICONIC]);
|
2014-04-26 17:50:55 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 08:28:29 +00:00
|
|
|
static void
|
|
|
|
gtk_model_button_set_popover (GtkModelButton *button,
|
|
|
|
GtkWidget *popover)
|
|
|
|
{
|
|
|
|
if (button->popover)
|
2020-02-24 12:21:46 +00:00
|
|
|
gtk_widget_unparent (button->popover);
|
2019-08-27 08:28:29 +00:00
|
|
|
|
|
|
|
button->popover = popover;
|
|
|
|
|
|
|
|
if (button->popover)
|
|
|
|
{
|
2020-02-24 12:21:46 +00:00
|
|
|
gtk_widget_set_parent (button->popover, GTK_WIDGET (button));
|
2019-08-27 08:28:29 +00:00
|
|
|
gtk_popover_set_position (GTK_POPOVER (button->popover), GTK_POS_RIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
update_node_name (button);
|
|
|
|
gtk_model_button_update_state (button);
|
|
|
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (button));
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_POPOVER]);
|
|
|
|
}
|
|
|
|
|
2019-06-07 13:02:45 +00:00
|
|
|
static void
|
2019-09-28 08:03:08 +00:00
|
|
|
update_accel (GtkModelButton *self,
|
2019-06-06 23:04:52 +00:00
|
|
|
const char *accel)
|
2019-06-07 13:02:45 +00:00
|
|
|
{
|
|
|
|
if (accel)
|
|
|
|
{
|
|
|
|
guint key;
|
|
|
|
GdkModifierType mods;
|
|
|
|
char *str;
|
|
|
|
|
2019-09-28 08:03:08 +00:00
|
|
|
if (!self->accel_label)
|
|
|
|
{
|
|
|
|
self->accel_label = g_object_new (GTK_TYPE_LABEL,
|
|
|
|
"css-name", "accelerator",
|
|
|
|
NULL);
|
|
|
|
gtk_widget_insert_before (self->accel_label, GTK_WIDGET (self), NULL);
|
|
|
|
}
|
|
|
|
|
2019-06-07 13:02:45 +00:00
|
|
|
gtk_accelerator_parse (accel, &key, &mods);
|
2018-08-13 02:59:49 +00:00
|
|
|
str = gtk_accelerator_get_label (key, mods);
|
2019-09-28 08:03:08 +00:00
|
|
|
gtk_label_set_label (GTK_LABEL (self->accel_label), str);
|
2019-06-07 13:02:45 +00:00
|
|
|
g_free (str);
|
2020-03-24 05:07:09 +00:00
|
|
|
|
|
|
|
if (GTK_IS_POPOVER (gtk_widget_get_native (GTK_WIDGET (self))))
|
|
|
|
{
|
|
|
|
GtkShortcutTrigger *trigger;
|
|
|
|
GtkShortcutAction *action;
|
|
|
|
|
|
|
|
if (self->controller)
|
|
|
|
{
|
|
|
|
while (g_list_model_get_n_items (G_LIST_MODEL (self->controller)) > 0)
|
|
|
|
{
|
2020-03-26 16:31:38 +00:00
|
|
|
GtkShortcut *shortcut = g_list_model_get_item (G_LIST_MODEL (self->controller), 0);
|
2020-03-24 05:07:09 +00:00
|
|
|
gtk_shortcut_controller_remove_shortcut (GTK_SHORTCUT_CONTROLLER (self->controller),
|
|
|
|
shortcut);
|
|
|
|
g_object_unref (shortcut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self->controller = gtk_shortcut_controller_new ();
|
|
|
|
gtk_shortcut_controller_set_scope (GTK_SHORTCUT_CONTROLLER (self->controller), GTK_SHORTCUT_SCOPE_MANAGED);
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (self), self->controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
trigger = gtk_keyval_trigger_new (key, mods);
|
|
|
|
action = gtk_signal_action_new ("clicked");
|
2020-03-26 16:31:38 +00:00
|
|
|
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (self->controller),
|
|
|
|
gtk_shortcut_new (trigger, action));
|
2020-03-24 05:07:09 +00:00
|
|
|
}
|
2019-06-07 13:02:45 +00:00
|
|
|
}
|
|
|
|
else
|
2019-06-06 23:04:52 +00:00
|
|
|
{
|
2019-09-28 08:03:08 +00:00
|
|
|
g_clear_pointer (&self->accel_label, gtk_widget_unparent);
|
2020-03-24 05:07:09 +00:00
|
|
|
if (self->controller)
|
|
|
|
{
|
|
|
|
gtk_widget_remove_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (self->controller));
|
|
|
|
g_clear_object (&self->controller);
|
|
|
|
}
|
2019-06-06 23:04:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_model_button_set_accel (GtkModelButton *button,
|
|
|
|
const char *accel)
|
|
|
|
{
|
|
|
|
g_free (button->accel);
|
|
|
|
button->accel = g_strdup (accel);
|
|
|
|
update_accel (button, button->accel);
|
2020-04-17 13:04:26 +00:00
|
|
|
update_visibility (button);
|
2019-06-06 23:04:52 +00:00
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_ACCEL]);
|
2019-06-07 13:02:45 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 01:43:28 +00:00
|
|
|
static void
|
|
|
|
gtk_model_button_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2019-09-28 10:37:00 +00:00
|
|
|
GtkModelButton *self = GTK_MODEL_BUTTON (object);
|
2014-10-24 01:43:28 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2014-10-26 22:08:26 +00:00
|
|
|
case PROP_ROLE:
|
2019-09-28 10:37:00 +00:00
|
|
|
g_value_set_enum (value, self->role);
|
2014-10-26 22:08:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ICON:
|
2019-09-28 10:37:00 +00:00
|
|
|
g_value_set_object (value, self->image ? gtk_image_get_gicon (GTK_IMAGE (self->image)) : NULL);
|
2014-10-26 22:08:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TEXT:
|
2019-09-28 10:37:00 +00:00
|
|
|
g_value_set_string (value, gtk_label_get_text (GTK_LABEL (self->label)));
|
2014-10-26 22:08:26 +00:00
|
|
|
break;
|
|
|
|
|
2018-04-23 09:06:17 +00:00
|
|
|
case PROP_USE_MARKUP:
|
2019-09-28 10:37:00 +00:00
|
|
|
g_value_set_boolean (value, gtk_label_get_use_markup (GTK_LABEL (self->label)));
|
2018-04-23 09:06:17 +00:00
|
|
|
break;
|
|
|
|
|
2014-10-24 01:43:28 +00:00
|
|
|
case PROP_ACTIVE:
|
2019-09-28 10:37:00 +00:00
|
|
|
g_value_set_boolean (value, self->active);
|
2014-10-24 01:43:28 +00:00
|
|
|
break;
|
|
|
|
|
2014-10-24 03:38:46 +00:00
|
|
|
case PROP_MENU_NAME:
|
2019-09-28 10:37:00 +00:00
|
|
|
g_value_set_string (value, self->menu_name);
|
2014-10-24 03:38:46 +00:00
|
|
|
break;
|
|
|
|
|
2019-08-27 08:28:29 +00:00
|
|
|
case PROP_POPOVER:
|
2019-09-28 10:37:00 +00:00
|
|
|
g_value_set_object (value, self->popover);
|
2019-08-27 08:28:29 +00:00
|
|
|
break;
|
|
|
|
|
2014-10-26 22:08:26 +00:00
|
|
|
case PROP_ICONIC:
|
2019-09-28 10:37:00 +00:00
|
|
|
g_value_set_boolean (value, self->iconic);
|
2014-10-26 22:08:26 +00:00
|
|
|
break;
|
|
|
|
|
2019-06-07 13:02:45 +00:00
|
|
|
case PROP_ACCEL:
|
2019-09-28 10:37:00 +00:00
|
|
|
g_value_set_string (value, self->accel);
|
2019-06-07 13:02:45 +00:00
|
|
|
break;
|
|
|
|
|
2019-06-06 00:41:45 +00:00
|
|
|
case PROP_INDICATOR_SIZE_GROUP:
|
2019-09-28 10:37:00 +00:00
|
|
|
g_value_set_object (value, self->indicators);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ACTION_NAME:
|
|
|
|
g_value_set_string (value, gtk_action_helper_get_action_name (self->action_helper));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ACTION_TARGET:
|
|
|
|
g_value_set_variant (value, gtk_action_helper_get_action_target_value (self->action_helper));
|
2019-06-06 00:41:45 +00:00
|
|
|
break;
|
|
|
|
|
2014-10-24 01:43:28 +00:00
|
|
|
default:
|
2018-04-08 17:13:33 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2014-10-24 01:43:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-07 19:51:34 +00:00
|
|
|
static void
|
|
|
|
gtk_model_button_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkModelButton *button = GTK_MODEL_BUTTON (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2014-10-26 22:08:26 +00:00
|
|
|
case PROP_ROLE:
|
|
|
|
gtk_model_button_set_role (button, g_value_get_enum (value));
|
2014-02-07 19:51:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ICON:
|
|
|
|
gtk_model_button_set_icon (button, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TEXT:
|
|
|
|
gtk_model_button_set_text (button, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
2018-04-23 09:06:17 +00:00
|
|
|
case PROP_USE_MARKUP:
|
|
|
|
gtk_model_button_set_use_markup (button, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2014-10-24 01:43:28 +00:00
|
|
|
case PROP_ACTIVE:
|
|
|
|
gtk_model_button_set_active (button, g_value_get_boolean (value));
|
2014-02-07 19:51:34 +00:00
|
|
|
break;
|
|
|
|
|
2014-10-24 03:38:46 +00:00
|
|
|
case PROP_MENU_NAME:
|
|
|
|
gtk_model_button_set_menu_name (button, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
2019-08-27 08:28:29 +00:00
|
|
|
case PROP_POPOVER:
|
|
|
|
gtk_model_button_set_popover (button, (GtkWidget *)g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2014-04-26 17:50:55 +00:00
|
|
|
case PROP_ICONIC:
|
|
|
|
gtk_model_button_set_iconic (button, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2019-06-07 13:02:45 +00:00
|
|
|
case PROP_ACCEL:
|
|
|
|
gtk_model_button_set_accel (button, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
2019-06-06 00:41:45 +00:00
|
|
|
case PROP_INDICATOR_SIZE_GROUP:
|
|
|
|
if (button->indicators)
|
2019-06-07 02:37:24 +00:00
|
|
|
gtk_size_group_remove_widget (button->indicators, button->start_box);
|
2019-06-06 00:41:45 +00:00
|
|
|
button->indicators = GTK_SIZE_GROUP (g_value_get_object (value));
|
|
|
|
if (button->indicators)
|
2019-06-07 02:37:24 +00:00
|
|
|
gtk_size_group_add_widget (button->indicators, button->start_box);
|
2019-06-06 00:41:45 +00:00
|
|
|
break;
|
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
case PROP_ACTION_NAME:
|
|
|
|
gtk_model_button_set_action_name (GTK_ACTIONABLE (button), g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ACTION_TARGET:
|
|
|
|
gtk_model_button_set_action_target_value (GTK_ACTIONABLE (button), g_value_get_variant (value));
|
|
|
|
break;
|
|
|
|
|
2014-02-07 19:51:34 +00:00
|
|
|
default:
|
2018-04-08 17:13:33 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2014-02-07 19:51:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-25 12:56:59 +00:00
|
|
|
static void
|
2020-05-05 20:48:39 +00:00
|
|
|
gtk_model_button_dispose (GObject *object)
|
2015-06-25 12:56:59 +00:00
|
|
|
{
|
2020-05-05 20:48:39 +00:00
|
|
|
GtkModelButton *model_button = GTK_MODEL_BUTTON (object);
|
2015-06-25 12:56:59 +00:00
|
|
|
|
|
|
|
g_clear_pointer (&model_button->menu_name, g_free);
|
|
|
|
|
2020-05-05 20:48:39 +00:00
|
|
|
G_OBJECT_CLASS (gtk_model_button_parent_class)->dispose (object);
|
2015-06-25 12:56:59 +00:00
|
|
|
}
|
|
|
|
|
2019-06-09 02:21:05 +00:00
|
|
|
static void
|
|
|
|
switch_menu (GtkModelButton *button)
|
|
|
|
{
|
|
|
|
GtkWidget *stack;
|
|
|
|
|
|
|
|
stack = gtk_widget_get_ancestor (GTK_WIDGET (button), GTK_TYPE_STACK);
|
|
|
|
if (stack != NULL)
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (stack), button->menu_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-09-28 10:37:00 +00:00
|
|
|
close_menu (GtkModelButton *self)
|
2019-06-09 02:21:05 +00:00
|
|
|
{
|
|
|
|
GtkWidget *popover;
|
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
popover = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_POPOVER);
|
2019-08-27 08:28:29 +00:00
|
|
|
while (popover != NULL)
|
|
|
|
{
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (popover));
|
|
|
|
if (GTK_IS_POPOVER_MENU (popover))
|
|
|
|
popover = gtk_popover_menu_get_parent_menu (GTK_POPOVER_MENU (popover));
|
|
|
|
else
|
|
|
|
popover = NULL;
|
|
|
|
}
|
2019-06-09 02:21:05 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 03:38:46 +00:00
|
|
|
static void
|
2020-05-07 00:25:42 +00:00
|
|
|
gtk_model_button_clicked (GtkModelButton *self)
|
2014-10-24 03:38:46 +00:00
|
|
|
{
|
2019-09-28 10:37:00 +00:00
|
|
|
if (self->menu_name != NULL)
|
2014-10-24 03:38:46 +00:00
|
|
|
{
|
2019-09-28 10:37:00 +00:00
|
|
|
switch_menu (self);
|
2014-10-24 03:38:46 +00:00
|
|
|
}
|
2019-09-28 10:37:00 +00:00
|
|
|
else if (self->popover != NULL)
|
2019-08-27 08:28:29 +00:00
|
|
|
{
|
|
|
|
GtkPopoverMenu *menu;
|
|
|
|
GtkWidget *submenu;
|
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
menu = (GtkPopoverMenu *)gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_POPOVER_MENU);
|
|
|
|
submenu = self->popover;
|
2019-08-27 08:28:29 +00:00
|
|
|
gtk_popover_popup (GTK_POPOVER (submenu));
|
|
|
|
gtk_popover_menu_set_open_submenu (menu, submenu);
|
|
|
|
gtk_popover_menu_set_parent_menu (GTK_POPOVER_MENU (submenu), GTK_WIDGET (menu));
|
|
|
|
}
|
2019-09-28 10:37:00 +00:00
|
|
|
else if (self->role == GTK_BUTTON_ROLE_NORMAL)
|
2014-10-24 03:38:46 +00:00
|
|
|
{
|
2019-09-28 10:37:00 +00:00
|
|
|
close_menu (self);
|
2014-10-24 03:38:46 +00:00
|
|
|
}
|
2019-09-28 10:37:00 +00:00
|
|
|
|
|
|
|
if (self->action_helper)
|
|
|
|
gtk_action_helper_activate (self->action_helper);
|
2014-10-24 03:38:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-05 06:42:41 +00:00
|
|
|
static void
|
|
|
|
gtk_model_button_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkModelButton *button = GTK_MODEL_BUTTON (object);
|
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
g_clear_pointer (&button->image, gtk_widget_unparent);
|
|
|
|
g_clear_pointer (&button->label, gtk_widget_unparent);
|
|
|
|
g_clear_pointer (&button->start_box, gtk_widget_unparent);
|
|
|
|
g_clear_pointer (&button->accel_label, gtk_widget_unparent);
|
|
|
|
g_clear_pointer (&button->end_indicator, gtk_widget_unparent);
|
|
|
|
g_clear_object (&button->action_helper);
|
2019-06-06 23:04:52 +00:00
|
|
|
g_free (button->accel);
|
2019-08-27 08:28:29 +00:00
|
|
|
g_clear_pointer (&button->popover, gtk_widget_unparent);
|
2015-12-05 06:42:41 +00:00
|
|
|
|
2019-09-08 22:45:58 +00:00
|
|
|
if (button->open_timeout)
|
|
|
|
g_source_remove (button->open_timeout);
|
|
|
|
|
2015-12-05 06:42:41 +00:00
|
|
|
G_OBJECT_CLASS (gtk_model_button_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2019-06-09 02:21:05 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_model_button_focus (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
|
|
|
GtkModelButton *button = GTK_MODEL_BUTTON (widget);
|
|
|
|
|
|
|
|
if (gtk_widget_is_focus (widget))
|
|
|
|
{
|
|
|
|
if (direction == GTK_DIR_LEFT &&
|
|
|
|
button->role == GTK_BUTTON_ROLE_TITLE &&
|
|
|
|
button->menu_name != NULL)
|
|
|
|
{
|
|
|
|
switch_menu (button);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (direction == GTK_DIR_RIGHT &&
|
|
|
|
button->role == GTK_BUTTON_ROLE_NORMAL &&
|
|
|
|
button->menu_name != NULL)
|
|
|
|
{
|
|
|
|
switch_menu (button);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-08-27 08:28:29 +00:00
|
|
|
else if (direction == GTK_DIR_RIGHT &&
|
|
|
|
button->role == GTK_BUTTON_ROLE_NORMAL &&
|
|
|
|
button->popover != NULL)
|
|
|
|
{
|
|
|
|
GtkPopoverMenu *menu;
|
|
|
|
GtkWidget *submenu;
|
|
|
|
|
|
|
|
menu = GTK_POPOVER_MENU (gtk_widget_get_ancestor (GTK_WIDGET (button), GTK_TYPE_POPOVER_MENU));
|
|
|
|
submenu = button->popover;
|
|
|
|
gtk_popover_popup (GTK_POPOVER (submenu));
|
|
|
|
gtk_popover_menu_set_open_submenu (menu, submenu);
|
|
|
|
gtk_popover_menu_set_parent_menu (GTK_POPOVER_MENU (submenu), GTK_WIDGET (menu));
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-06-09 02:21:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_grab_focus (widget);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-07 19:51:34 +00:00
|
|
|
static void
|
|
|
|
gtk_model_button_class_init (GtkModelButtonClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
|
|
|
|
2020-05-05 20:48:39 +00:00
|
|
|
object_class->dispose = gtk_model_button_dispose;
|
2015-12-05 06:42:41 +00:00
|
|
|
object_class->finalize = gtk_model_button_finalize;
|
2014-10-24 01:43:28 +00:00
|
|
|
object_class->get_property = gtk_model_button_get_property;
|
2014-02-07 19:51:34 +00:00
|
|
|
object_class->set_property = gtk_model_button_set_property;
|
|
|
|
|
2015-10-31 04:08:00 +00:00
|
|
|
widget_class->state_flags_changed = gtk_model_button_state_flags_changed;
|
2015-11-03 17:20:53 +00:00
|
|
|
widget_class->direction_changed = gtk_model_button_direction_changed;
|
2019-06-09 02:21:05 +00:00
|
|
|
widget_class->focus = gtk_model_button_focus;
|
2014-02-07 19:51:34 +00:00
|
|
|
|
2020-05-07 00:25:42 +00:00
|
|
|
class->clicked = gtk_model_button_clicked;
|
|
|
|
|
2014-10-26 23:04:28 +00:00
|
|
|
/**
|
|
|
|
* GtkModelButton:role:
|
|
|
|
*
|
|
|
|
* Specifies whether the button is a plain, check or radio button.
|
|
|
|
* When #GtkActionable:action-name is set, the role will be determined
|
|
|
|
* from the action and does not have to be set explicitly.
|
|
|
|
*/
|
2014-10-26 22:08:26 +00:00
|
|
|
properties[PROP_ROLE] =
|
2014-10-26 23:04:28 +00:00
|
|
|
g_param_spec_enum ("role",
|
|
|
|
P_("Role"),
|
|
|
|
P_("The role of this button"),
|
2014-10-26 22:08:26 +00:00
|
|
|
GTK_TYPE_BUTTON_ROLE,
|
|
|
|
GTK_BUTTON_ROLE_NORMAL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
2014-10-26 23:04:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkModelButton:icon:
|
|
|
|
*
|
|
|
|
* A #GIcon that will be used if iconic appearance for the button is
|
|
|
|
* desired.
|
|
|
|
*/
|
2014-10-26 22:08:26 +00:00
|
|
|
properties[PROP_ICON] =
|
2014-10-26 23:04:28 +00:00
|
|
|
g_param_spec_object ("icon",
|
|
|
|
P_("Icon"),
|
|
|
|
P_("The icon"),
|
2014-10-26 22:08:26 +00:00
|
|
|
G_TYPE_ICON,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
2014-10-26 23:04:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkModelButton:text:
|
|
|
|
*
|
|
|
|
* The label for the button.
|
|
|
|
*/
|
2014-10-26 22:08:26 +00:00
|
|
|
properties[PROP_TEXT] =
|
2014-10-26 23:04:28 +00:00
|
|
|
g_param_spec_string ("text",
|
|
|
|
P_("Text"),
|
|
|
|
P_("The text"),
|
2014-11-23 20:05:01 +00:00
|
|
|
"",
|
2014-10-26 22:08:26 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
2014-10-26 23:04:28 +00:00
|
|
|
|
2018-04-23 09:06:17 +00:00
|
|
|
/**
|
|
|
|
* GtkModelButton:use-markup:
|
|
|
|
*
|
|
|
|
* If %TRUE, XML tags in the text of the button are interpreted as by
|
|
|
|
* pango_parse_markup() to format the enclosed spans of text. If %FALSE, the
|
|
|
|
* text will be displayed verbatim.
|
|
|
|
*/
|
|
|
|
properties[PROP_USE_MARKUP] =
|
|
|
|
g_param_spec_boolean ("use-markup",
|
|
|
|
P_("Use markup"),
|
|
|
|
P_("The text of the button includes XML markup. See pango_parse_markup()"),
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
2014-10-26 23:04:28 +00:00
|
|
|
/**
|
|
|
|
* GtkModelButton:active:
|
|
|
|
*
|
|
|
|
* The state of the button. This is reflecting the state of the associated
|
|
|
|
* #GAction.
|
|
|
|
*/
|
2014-10-26 22:08:26 +00:00
|
|
|
properties[PROP_ACTIVE] =
|
2014-10-26 23:04:28 +00:00
|
|
|
g_param_spec_boolean ("active",
|
|
|
|
P_("Active"),
|
|
|
|
P_("Active"),
|
2014-10-26 22:08:26 +00:00
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
2014-10-26 23:04:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkModelButton:menu-name:
|
|
|
|
*
|
2019-08-27 08:28:29 +00:00
|
|
|
* The name of a submenu to open when the button is activated. * If this is set, the button should not have an action associated with it.
|
2014-10-26 23:04:28 +00:00
|
|
|
*/
|
2014-10-26 22:08:26 +00:00
|
|
|
properties[PROP_MENU_NAME] =
|
2014-10-26 23:04:28 +00:00
|
|
|
g_param_spec_string ("menu-name",
|
|
|
|
P_("Menu name"),
|
|
|
|
P_("The name of the menu to open"),
|
2014-10-26 22:08:26 +00:00
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
2014-10-26 23:04:28 +00:00
|
|
|
|
2019-08-27 08:28:29 +00:00
|
|
|
properties[PROP_POPOVER] =
|
|
|
|
g_param_spec_object ("popover",
|
|
|
|
P_("Popover"),
|
|
|
|
P_("Popover to open"),
|
|
|
|
GTK_TYPE_POPOVER,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
2014-10-26 23:04:28 +00:00
|
|
|
/**
|
|
|
|
* GtkModelButton:iconic:
|
|
|
|
*
|
|
|
|
* If this property is set, the button will show an icon if one is set.
|
|
|
|
* If no icon is set, the text will be used. This is typically used for
|
|
|
|
* horizontal sections of linked buttons.
|
|
|
|
*/
|
2014-10-26 22:08:26 +00:00
|
|
|
properties[PROP_ICONIC] =
|
2014-10-26 23:04:28 +00:00
|
|
|
g_param_spec_boolean ("iconic",
|
|
|
|
P_("Iconic"),
|
|
|
|
P_("Whether to prefer the icon over text"),
|
2014-11-23 20:05:01 +00:00
|
|
|
FALSE,
|
2014-10-26 22:08:26 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
2019-06-06 00:41:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkModelButton:indicator-size-group:
|
|
|
|
*
|
|
|
|
* Containers like #GtkPopoverMenu can provide a size group
|
|
|
|
* in this property to align the checks and radios of all
|
|
|
|
* the model buttons in a menu.
|
|
|
|
*/
|
|
|
|
properties[PROP_INDICATOR_SIZE_GROUP] =
|
|
|
|
g_param_spec_object ("indicator-size-group",
|
|
|
|
P_("Size group"),
|
|
|
|
P_("Size group for checks and radios"),
|
|
|
|
GTK_TYPE_SIZE_GROUP,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
2019-06-07 13:02:45 +00:00
|
|
|
properties[PROP_ACCEL] =
|
|
|
|
g_param_spec_string ("accel",
|
|
|
|
P_("Accel"),
|
|
|
|
P_("The accelerator"),
|
2019-06-06 23:04:52 +00:00
|
|
|
NULL,
|
2019-06-07 13:02:45 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
2019-09-28 10:37:00 +00:00
|
|
|
g_object_class_install_properties (object_class, LAST_PROP, properties);
|
|
|
|
|
|
|
|
g_object_class_override_property (object_class, PROP_ACTION_NAME, "action-name");
|
|
|
|
g_object_class_override_property (object_class, PROP_ACTION_TARGET, "action-target");
|
|
|
|
|
|
|
|
signals[SIGNAL_CLICKED] = g_signal_new (I_("clicked"),
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
2020-05-07 00:25:42 +00:00
|
|
|
G_STRUCT_OFFSET (GtkModelButtonClass, clicked),
|
2019-09-28 10:37:00 +00:00
|
|
|
NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
2014-02-07 19:51:34 +00:00
|
|
|
|
2020-03-24 03:03:29 +00:00
|
|
|
widget_class->activate_signal = signals[SIGNAL_CLICKED];
|
|
|
|
|
2019-09-28 08:32:14 +00:00
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
|
2017-11-18 03:49:57 +00:00
|
|
|
gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (class), I_("modelbutton"));
|
2015-10-30 04:29:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 00:13:21 +00:00
|
|
|
static void
|
2019-08-27 08:28:29 +00:00
|
|
|
close_submenus (GtkPopover *popover)
|
2019-06-13 00:13:21 +00:00
|
|
|
{
|
2019-08-27 08:28:29 +00:00
|
|
|
GtkPopoverMenu *menu;
|
2019-06-13 00:13:21 +00:00
|
|
|
|
2019-08-27 08:28:29 +00:00
|
|
|
if (GTK_IS_POPOVER_MENU (popover))
|
|
|
|
{
|
|
|
|
GtkWidget *submenu;
|
2019-06-13 00:13:21 +00:00
|
|
|
|
2019-08-27 08:28:29 +00:00
|
|
|
menu = GTK_POPOVER_MENU (popover);
|
|
|
|
submenu = gtk_popover_menu_get_open_submenu (menu);
|
|
|
|
if (submenu)
|
|
|
|
{
|
|
|
|
close_submenus (GTK_POPOVER (submenu));
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (submenu));
|
|
|
|
gtk_popover_menu_set_open_submenu (menu, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-13 00:13:21 +00:00
|
|
|
|
2019-09-08 22:45:58 +00:00
|
|
|
static gboolean
|
|
|
|
open_submenu (gpointer data)
|
2019-08-27 08:28:29 +00:00
|
|
|
{
|
2019-09-08 22:45:58 +00:00
|
|
|
GtkModelButton *button = data;
|
|
|
|
GtkPopover *popover;
|
|
|
|
|
|
|
|
popover = (GtkPopover*)gtk_widget_get_ancestor (GTK_WIDGET (button), GTK_TYPE_POPOVER);
|
|
|
|
|
2019-08-27 08:28:29 +00:00
|
|
|
if (GTK_IS_POPOVER_MENU (popover))
|
|
|
|
{
|
2019-09-08 22:45:58 +00:00
|
|
|
gtk_popover_menu_set_active_item (GTK_POPOVER_MENU (popover), GTK_WIDGET (button));
|
2019-08-27 08:28:29 +00:00
|
|
|
|
2019-09-08 22:45:58 +00:00
|
|
|
if (button->popover)
|
2019-08-27 08:28:29 +00:00
|
|
|
{
|
2019-09-08 22:45:58 +00:00
|
|
|
GtkWidget *submenu = button->popover;
|
2019-08-27 08:28:29 +00:00
|
|
|
|
|
|
|
if (gtk_popover_menu_get_open_submenu (GTK_POPOVER_MENU (popover)) != submenu)
|
|
|
|
close_submenus (popover);
|
|
|
|
|
|
|
|
gtk_popover_popup (GTK_POPOVER (submenu));
|
|
|
|
gtk_popover_menu_set_open_submenu (GTK_POPOVER_MENU (popover), submenu);
|
|
|
|
gtk_popover_menu_set_parent_menu (GTK_POPOVER_MENU (submenu), GTK_WIDGET (popover));
|
|
|
|
}
|
|
|
|
}
|
2019-09-08 22:45:58 +00:00
|
|
|
|
|
|
|
button->open_timeout = 0;
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define OPEN_TIMEOUT 80
|
|
|
|
|
|
|
|
static void
|
|
|
|
start_open (GtkModelButton *button)
|
|
|
|
{
|
|
|
|
if (button->open_timeout)
|
|
|
|
g_source_remove (button->open_timeout);
|
|
|
|
|
|
|
|
if (button->popover &&
|
|
|
|
gtk_widget_get_visible (button->popover))
|
|
|
|
return;
|
|
|
|
|
|
|
|
button->open_timeout = g_timeout_add (OPEN_TIMEOUT, open_submenu, button);
|
|
|
|
g_source_set_name_by_id (button->open_timeout, "[gtk] open_submenu");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
stop_open (GtkModelButton *button)
|
|
|
|
{
|
|
|
|
if (button->open_timeout)
|
|
|
|
{
|
|
|
|
g_source_remove (button->open_timeout);
|
|
|
|
button->open_timeout = 0;
|
|
|
|
}
|
2019-06-13 00:13:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-20 03:04:28 +00:00
|
|
|
pointer_cb (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer data)
|
2019-06-13 00:13:21 +00:00
|
|
|
{
|
2020-02-20 03:04:28 +00:00
|
|
|
gboolean contains;
|
|
|
|
|
|
|
|
contains = gtk_event_controller_motion_contains_pointer (GTK_EVENT_CONTROLLER_MOTION (object));
|
2019-06-13 00:13:21 +00:00
|
|
|
|
2020-02-20 03:04:28 +00:00
|
|
|
if (contains)
|
2019-08-27 08:28:29 +00:00
|
|
|
{
|
2020-02-20 03:04:28 +00:00
|
|
|
GtkWidget *target;
|
|
|
|
GtkWidget *popover;
|
|
|
|
|
|
|
|
target = GTK_WIDGET (data);
|
2020-02-16 01:47:23 +00:00
|
|
|
popover = gtk_widget_get_ancestor (target, GTK_TYPE_POPOVER_MENU);
|
|
|
|
|
2020-02-20 03:04:28 +00:00
|
|
|
if (popover)
|
2020-02-16 01:47:23 +00:00
|
|
|
{
|
|
|
|
if (gtk_popover_menu_get_open_submenu (GTK_POPOVER_MENU (popover)) != NULL)
|
|
|
|
start_open (GTK_MODEL_BUTTON (target));
|
|
|
|
else
|
|
|
|
open_submenu (target);
|
|
|
|
}
|
2019-08-27 08:28:29 +00:00
|
|
|
}
|
2020-02-16 01:47:23 +00:00
|
|
|
else
|
2020-02-20 03:04:28 +00:00
|
|
|
{
|
|
|
|
GtkModelButton *button = data;
|
|
|
|
|
|
|
|
stop_open (button);
|
|
|
|
}
|
2019-06-13 00:13:21 +00:00
|
|
|
}
|
|
|
|
|
2019-09-08 22:45:58 +00:00
|
|
|
static void
|
|
|
|
motion_cb (GtkEventController *controller,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
start_open (GTK_MODEL_BUTTON (data));
|
|
|
|
}
|
|
|
|
|
2019-06-13 00:13:21 +00:00
|
|
|
static void
|
2020-02-20 01:51:03 +00:00
|
|
|
focus_in_cb (GtkEventController *controller,
|
|
|
|
gpointer data)
|
2019-06-13 00:13:21 +00:00
|
|
|
{
|
|
|
|
GtkWidget *target;
|
|
|
|
GtkWidget *popover;
|
|
|
|
|
2020-02-20 01:51:03 +00:00
|
|
|
target = gtk_event_controller_get_widget (controller);
|
|
|
|
popover = gtk_widget_get_ancestor (target, GTK_TYPE_POPOVER_MENU);
|
2019-06-13 00:13:21 +00:00
|
|
|
|
2020-02-20 01:51:03 +00:00
|
|
|
if (popover)
|
|
|
|
gtk_popover_menu_set_active_item (GTK_POPOVER_MENU (popover), target);
|
2019-06-13 00:13:21 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 00:25:42 +00:00
|
|
|
static void
|
|
|
|
emit_clicked (GtkModelButton *button)
|
|
|
|
{
|
|
|
|
g_signal_emit (button, signals[SIGNAL_CLICKED], 0);
|
|
|
|
}
|
|
|
|
|
2014-02-07 19:51:34 +00:00
|
|
|
static void
|
2019-09-28 10:37:00 +00:00
|
|
|
gtk_model_button_init (GtkModelButton *self)
|
2014-02-07 19:51:34 +00:00
|
|
|
{
|
2019-06-13 00:13:21 +00:00
|
|
|
GtkEventController *controller;
|
2019-09-28 10:37:00 +00:00
|
|
|
GtkGesture *gesture;
|
2019-06-13 00:13:21 +00:00
|
|
|
|
2020-05-05 18:57:21 +00:00
|
|
|
gtk_widget_set_focusable (GTK_WIDGET (self), TRUE);
|
2019-12-28 02:58:54 +00:00
|
|
|
|
2019-09-28 10:37:00 +00:00
|
|
|
self->role = GTK_BUTTON_ROLE_NORMAL;
|
|
|
|
self->label = gtk_label_new ("");
|
|
|
|
gtk_widget_set_halign (self->label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_parent (self->label, GTK_WIDGET (self));
|
|
|
|
|
|
|
|
self->start_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_widget_insert_after (self->start_box, GTK_WIDGET (self), NULL);
|
|
|
|
update_node_ordering (self);
|
|
|
|
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (self), "flat");
|
2019-06-13 00:13:21 +00:00
|
|
|
|
|
|
|
controller = gtk_event_controller_motion_new ();
|
2020-02-20 03:04:28 +00:00
|
|
|
g_signal_connect (controller, "notify::contains-pointer", G_CALLBACK (pointer_cb), self);
|
2019-09-28 10:37:00 +00:00
|
|
|
g_signal_connect (controller, "motion", G_CALLBACK (motion_cb), self);
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (self), controller);
|
2019-06-13 00:13:21 +00:00
|
|
|
|
2020-02-20 01:51:03 +00:00
|
|
|
controller = gtk_event_controller_focus_new ();
|
2020-04-10 02:22:28 +00:00
|
|
|
gtk_event_controller_set_propagation_limit (controller, GTK_LIMIT_NONE);
|
2020-02-20 01:51:03 +00:00
|
|
|
g_signal_connect (controller, "enter", G_CALLBACK (focus_in_cb), NULL);
|
2019-09-28 10:37:00 +00:00
|
|
|
gtk_widget_add_controller (GTK_WIDGET (self), controller);
|
|
|
|
|
|
|
|
gesture = gtk_gesture_click_new ();
|
|
|
|
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE);
|
|
|
|
gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (gesture), TRUE);
|
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_PRIMARY);
|
2020-05-07 00:25:42 +00:00
|
|
|
g_signal_connect_swapped (gesture, "released", G_CALLBACK (emit_clicked), self);
|
2019-09-28 10:37:00 +00:00
|
|
|
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_CAPTURE);
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture));
|
2014-02-07 19:51:34 +00:00
|
|
|
}
|
|
|
|
|
2014-11-24 00:16:49 +00:00
|
|
|
/**
|
|
|
|
* gtk_model_button_new:
|
|
|
|
*
|
|
|
|
* Creates a new GtkModelButton.
|
|
|
|
*
|
|
|
|
* Returns: the newly created #GtkModelButton widget
|
|
|
|
*/
|
2014-02-07 19:51:34 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_model_button_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_MODEL_BUTTON, NULL);
|
|
|
|
}
|