void AbstractToolItem::toolButtonCallback(GtkToolButton* toolbutton, AbstractToolItem* item) { XOJ_CHECK_TYPE_OBJ(item, AbstractToolItem); if (toolbutton && GTK_IS_TOGGLE_TOOL_BUTTON(toolbutton)) { bool selected = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(toolbutton)); // ignore this event... GTK Broadcast to much events, e.g. if you call set_active if (item->toolToggleButtonActive == selected) { return; } // don't allow deselect this button if (item->toolToggleOnlyEnable && selected == false) { gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(toolbutton), true); return; } item->toolToggleButtonActive = selected; } item->activated(NULL, NULL, toolbutton); }
/** * gtk_toggle_tool_button_get_active: * @button: a #GtkToggleToolButton * * Queries a #GtkToggleToolButton and returns its current state. * Returns %TRUE if the toggle button is pressed in and %FALSE if it is raised. * * Return value: %TRUE if the toggle tool button is pressed in, %FALSE if not * * Since: 2.4 **/ gboolean gtk_toggle_tool_button_get_active (GtkToggleToolButton *button) { g_return_val_if_fail (GTK_IS_TOGGLE_TOOL_BUTTON (button), FALSE); return button->priv->active; }
void ToolDrawCombocontrol::selected(ActionGroup group, ActionType action) { XOJ_CHECK_TYPE(ToolDrawCombocontrol); if (!this->item) { return; } if (!GTK_IS_TOGGLE_TOOL_BUTTON(this->item)) { g_warning("ToolDrawCombocontrol: selected action %i which is not a toggle action!", action); return; } string description; for (ToolDrawType* t : drawTypes) { if (action == t->type && this->action != t->type) { this->action = t->type; gtk_image_set_from_icon_name(GTK_IMAGE(iconWidget), t->icon.c_str(), GTK_ICON_SIZE_SMALL_TOOLBAR); description = t->name; break; } } gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(item), description.c_str()); if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(this->item)) != (this->action == action)) { this->toolToggleButtonActive = (this->action == action); gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(this->item), this->toolToggleButtonActive); } }
/** * gtk_toggle_tool_button_set_active: * @button: a #GtkToggleToolButton * @is_active: whether @button should be active * * Sets the status of the toggle tool button. Set to %TRUE if you * want the GtkToggleButton to be 'pressed in', and %FALSE to raise it. * This action causes the toggled signal to be emitted. * * Since: 2.4 **/ void gtk_toggle_tool_button_set_active (GtkToggleToolButton *button, gboolean is_active) { g_return_if_fail (GTK_IS_TOGGLE_TOOL_BUTTON (button)); is_active = is_active != FALSE; if (button->priv->active != is_active) gtk_button_clicked (GTK_BUTTON (_gtk_tool_button_get_button (GTK_TOOL_BUTTON (button)))); }
GtkToolItem* AbstractToolItem::createItem(bool horizontal) { XOJ_CHECK_TYPE(AbstractToolItem); if (this->item) { return this->item; } this->item = createTmpItem(horizontal); g_object_ref(this->item); if (GTK_IS_TOOL_BUTTON(this->item) || GTK_IS_TOGGLE_TOOL_BUTTON(this->item)) { g_signal_connect(this->item, "clicked", G_CALLBACK(&toolButtonCallback), this); } return this->item; }
void AbstractToolItem::selected(ActionGroup group, ActionType action) { XOJ_CHECK_TYPE(AbstractToolItem); if (this->item == NULL) { return; } if (!GTK_IS_TOGGLE_TOOL_BUTTON(this->item)) { g_warning("selected action %i (group=%i) which is not a toggle action!", action, group); return; } if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(this->item)) != (this->action == action)) { this->toolToggleButtonActive = (this->action == action); gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(this->item), this->toolToggleButtonActive); } }
void ToolSelectCombocontrol::selected(ActionGroup group, ActionType action) { XOJ_CHECK_TYPE(ToolSelectCombocontrol); if (this->item) { if (!GTK_IS_TOGGLE_TOOL_BUTTON(this->item)) { g_warning("selected action %i which is not a toggle action! 2", action); return; } const char * description = NULL; if (action == ACTION_TOOL_SELECT_RECT && this->action != ACTION_TOOL_SELECT_RECT) { this->action = ACTION_TOOL_SELECT_RECT; gtk_image_set_from_pixbuf(GTK_IMAGE(iconWidget), this->iconSelectRect); description = _("Select Rectangle"); } else if (action == ACTION_TOOL_SELECT_REGION && this->action != ACTION_TOOL_SELECT_REGION) { this->action = ACTION_TOOL_SELECT_REGION; gtk_image_set_from_pixbuf(GTK_IMAGE(iconWidget), this->iconSelectRgion); description = _("Select Region"); } else if (action == ACTION_TOOL_SELECT_OBJECT && this->action != ACTION_TOOL_SELECT_OBJECT) { this->action = ACTION_TOOL_SELECT_OBJECT; gtk_image_set_from_pixbuf(GTK_IMAGE(iconWidget), this->iconSelectObject); description = _("Select Object"); } gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(item), description); if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(this->item)) != (this->action == action)) { this->toolToggleButtonActive = (this->action == action); gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(this->item), this->toolToggleButtonActive); } } }