X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fwdgt-chain-button.c;h=e3cd8c01ae85c1bc58fc3d732b16d97bb356ac5b;hb=cbc5b369069a355c3fa9715c059271d45dbb33e0;hp=7491311f4befdd6c2efaba5e993eb6a8421a83f8;hpb=b13649a65b7dfa46ba1ed7fe9e8afa4aaef70f79;p=glabels diff --git a/src/wdgt-chain-button.c b/src/wdgt-chain-button.c index 7491311f..e3cd8c01 100644 --- a/src/wdgt-chain-button.c +++ b/src/wdgt-chain-button.c @@ -1,39 +1,36 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ - -/* wdgt-chain-button.c - * Modified version of gimpchainbutton.c for gLabels: +/* + * wdgt-chain-button.c + * Modified version of gimpchainbutton.h for gLabels: + * + * LIBGIMP - The GIMP Library + * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball * - * LIBGIMP - The GIMP Library - * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball + * gimpchainbutton.h + * Copyright (C) 1999-2000 Sven Neumann * - * gimpchainbutton.c - * Copyright (C) 1999-2000 Sven Neumann + * Modified or gLabels by Jim Evins * - * Modified or gLabels by Jim Evins * - * This library 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. + * This file is part of gLabels. * - * 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 - * General Public License for more details. + * gLabels 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 3 of the License, or + * (at your option) any later version. * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * gLabels 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 gLabels. If not, see . */ #include "wdgt-chain-button.h" -#include -#include -#include - -#include "stock.h" +#include +#include enum @@ -46,16 +43,16 @@ enum static void gl_wdgt_chain_button_clicked_callback (GtkWidget *widget, glWdgtChainButton *button); static gboolean gl_wdgt_chain_button_draw_lines (GtkWidget *widget, - GdkEventExpose *eevent, + cairo_t *cr, glWdgtChainButton *button); static const gchar *gl_wdgt_chain_stock_items[] = { - GL_STOCK_HCHAIN, - GL_STOCK_HCHAIN_BROKEN, - GL_STOCK_VCHAIN, - GL_STOCK_VCHAIN_BROKEN + "changes-prevent", + "changes-allow", + "changes-prevent", + "changes-allow" }; @@ -63,7 +60,7 @@ static guint gl_wdgt_chain_button_signals[LAST_SIGNAL] = { 0 }; -G_DEFINE_TYPE (glWdgtChainButton, gl_wdgt_chain_button, GTK_TYPE_TABLE); +G_DEFINE_TYPE (glWdgtChainButton, gl_wdgt_chain_button, GTK_TYPE_TABLE) static void @@ -93,21 +90,23 @@ gl_wdgt_chain_button_init (glWdgtChainButton *button) button->line2 = gtk_drawing_area_new (); button->image = gtk_image_new (); - button->button = gtk_button_new (); + button->button = gtk_toggle_button_new (); gtk_button_set_relief (GTK_BUTTON (button->button), GTK_RELIEF_NONE); + gtk_button_set_focus_on_click (GTK_BUTTON (button->button), FALSE); gtk_container_add (GTK_CONTAINER (button->button), button->image); gtk_widget_show (button->image); g_signal_connect (button->button, "clicked", G_CALLBACK (gl_wdgt_chain_button_clicked_callback), button); - g_signal_connect (button->line1, "expose_event", + g_signal_connect (button->line1, "draw", G_CALLBACK (gl_wdgt_chain_button_draw_lines), button); - g_signal_connect (button->line2, "expose_event", + g_signal_connect (button->line2, "draw", G_CALLBACK (gl_wdgt_chain_button_draw_lines), button); + } @@ -138,7 +137,7 @@ gl_wdgt_chain_button_new (glWdgtChainPosition position) button->position = position; - gtk_image_set_from_stock + gtk_image_set_from_icon_name (GTK_IMAGE (button->image), gl_wdgt_chain_stock_items[((position & GL_WDGT_CHAIN_LEFT) << 1) + ! button->active], GTK_ICON_SIZE_BUTTON); @@ -148,20 +147,20 @@ gl_wdgt_chain_button_new (glWdgtChainPosition position) gtk_table_resize (GTK_TABLE (button), 3, 1); gtk_table_attach (GTK_TABLE (button), button->button, 0, 1, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0); - gtk_table_attach_defaults (GTK_TABLE (button), - button->line1, 0, 1, 0, 1); - gtk_table_attach_defaults (GTK_TABLE (button), - button->line2, 0, 1, 2, 3); + gtk_table_attach (GTK_TABLE (button), button->line1, 0, 1, 0, 1, + GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0 ); + gtk_table_attach (GTK_TABLE (button), button->line2, 0, 1, 2, 3, + GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0 ); } else { gtk_table_resize (GTK_TABLE (button), 1, 3); gtk_table_attach (GTK_TABLE (button), button->button, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0); - gtk_table_attach_defaults (GTK_TABLE (button), - button->line1, 0, 1, 0, 1); - gtk_table_attach_defaults (GTK_TABLE (button), - button->line2, 2, 3, 0, 1); + gtk_table_attach (GTK_TABLE (button), button->line1, 0, 1, 0, 1, + GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0 ); + gtk_table_attach (GTK_TABLE (button), button->line2, 2, 3, 0, 1, + GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0 ); } gtk_widget_show (button->button); @@ -181,7 +180,7 @@ gl_wdgt_chain_button_new (glWdgtChainPosition position) */ void gl_wdgt_chain_button_set_active (glWdgtChainButton *button, - gboolean active) + gboolean active) { g_return_if_fail (GL_WDGT_IS_CHAIN_BUTTON (button)); @@ -193,9 +192,15 @@ gl_wdgt_chain_button_set_active (glWdgtChainButton *button, num = ((button->position & GL_WDGT_CHAIN_LEFT) << 1) + (active ? 0 : 1); - gtk_image_set_from_stock (GTK_IMAGE (button->image), - gl_wdgt_chain_stock_items[num], - GTK_ICON_SIZE_BUTTON); + gtk_image_set_from_icon_name (GTK_IMAGE (button->image), + gl_wdgt_chain_stock_items[num], + GTK_ICON_SIZE_MENU); + + g_signal_handlers_block_by_func (G_OBJECT (button->button), + gl_wdgt_chain_button_clicked_callback, button); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button->button), active); + g_signal_handlers_unblock_by_func (G_OBJECT (button->button), + gl_wdgt_chain_button_clicked_callback, button); } } @@ -217,7 +222,7 @@ gl_wdgt_chain_button_get_active (glWdgtChainButton *button) static void gl_wdgt_chain_button_clicked_callback (GtkWidget *widget, - glWdgtChainButton *button) + glWdgtChainButton *button) { g_return_if_fail (GL_WDGT_IS_CHAIN_BUTTON (button)); @@ -228,23 +233,19 @@ gl_wdgt_chain_button_clicked_callback (GtkWidget *widget, static gboolean gl_wdgt_chain_button_draw_lines (GtkWidget *widget, - GdkEventExpose *eevent, + cairo_t *cr, glWdgtChainButton *button) { - GdkPoint points[3]; - GdkPoint buf; - GtkShadowType shadow; + GtkAllocation allocation; + gdouble w, h; glWdgtChainPosition position; gint which_line; -#define SHORT_LINE 4 - /* don't set this too high, there's no check against drawing outside - the widgets bounds yet (and probably never will be) */ - g_return_val_if_fail (GL_WDGT_IS_CHAIN_BUTTON (button), FALSE); - points[0].x = widget->allocation.width / 2; - points[0].y = widget->allocation.height / 2; + gtk_widget_get_allocation (widget, &allocation); + w = allocation.width; + h = allocation.height; which_line = (widget == button->line1) ? 1 : -1; @@ -266,59 +267,45 @@ gl_wdgt_chain_button_draw_lines (GtkWidget *widget, switch (position) { case GL_WDGT_CHAIN_LEFT: - points[0].x += SHORT_LINE; - points[1].x = points[0].x - SHORT_LINE; - points[1].y = points[0].y; - points[2].x = points[1].x; - points[2].y = (which_line == 1) ? widget->allocation.height - 1 : 0; - shadow = GTK_SHADOW_ETCHED_IN; + cairo_move_to (cr, w-2, (which_line == 1) ? 0.6*h : 0.4*h); + cairo_line_to (cr, w/2, (which_line == 1) ? 0.6*h : 0.4*h); + cairo_line_to (cr, w/2, (which_line == 1) ? h-2 : 1); break; case GL_WDGT_CHAIN_RIGHT: - points[0].x -= SHORT_LINE; - points[1].x = points[0].x + SHORT_LINE; - points[1].y = points[0].y; - points[2].x = points[1].x; - points[2].y = (which_line == 1) ? widget->allocation.height - 1 : 0; - shadow = GTK_SHADOW_ETCHED_OUT; + cairo_move_to (cr, 1, (which_line == 1) ? 0.6*h : 0.4*h); + cairo_line_to (cr, w/2, (which_line == 1) ? 0.6*h : 0.4*h); + cairo_line_to (cr, w/2, (which_line == 1) ? h-2 : 1); break; case GL_WDGT_CHAIN_TOP: - points[0].y += SHORT_LINE; - points[1].x = points[0].x; - points[1].y = points[0].y - SHORT_LINE; - points[2].x = (which_line == 1) ? widget->allocation.width - 1 : 0; - points[2].y = points[1].y; - shadow = GTK_SHADOW_ETCHED_OUT; + cairo_move_to (cr, w/2, h-2); + cairo_line_to (cr, w/2, h/2); + cairo_line_to (cr, (which_line == 1) ? w-2 : 1, h/2); break; case GL_WDGT_CHAIN_BOTTOM: - points[0].y -= SHORT_LINE; - points[1].x = points[0].x; - points[1].y = points[0].y + SHORT_LINE; - points[2].x = (which_line == 1) ? widget->allocation.width - 1 : 0; - points[2].y = points[1].y; - shadow = GTK_SHADOW_ETCHED_IN; + cairo_move_to (cr, w/2, 1); + cairo_line_to (cr, w/2, h/2); + cairo_line_to (cr, (which_line == 1) ? w-2 : 1, h/2); break; default: return FALSE; } - if ( ((shadow == GTK_SHADOW_ETCHED_OUT) && (which_line == -1)) || - ((shadow == GTK_SHADOW_ETCHED_IN) && (which_line == 1)) ) - { - buf = points[0]; - points[0] = points[2]; - points[2] = buf; - } + cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); + cairo_set_line_width (cr, 1.0); + cairo_set_source_rgb (cr, 0, 0, 0); - gtk_paint_polygon (widget->style, - widget->window, - GTK_STATE_NORMAL, - shadow, - &eevent->area, - widget, - "chainbutton", - points, - 3, - FALSE); + cairo_stroke (cr); return TRUE; } + + + +/* + * Local Variables: -- emacs + * mode: C -- emacs + * c-basic-offset: 8 -- emacs + * tab-width: 8 -- emacs + * indent-tabs-mode: nil -- emacs + * End: -- emacs + */