[gtk+/client-side-decorations: 31/50] button event handlers



commit ef091cc4da3c0bc53245d870e66c9350fc97cf10
Author: Cody Russell <crussell canonical com>
Date:   Wed May 27 10:36:55 2009 +0200

    button event handlers

 gtk/gtkwindow.c |   69 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 64 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index d8bc838..5e68e02 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -214,6 +214,9 @@ struct _GtkWindowPrivate
   gchar *startup_id;
 
   GtkWidget *title_label;
+  GtkWidget *min_button;
+  GtkWidget *max_button;
+  GtkWidget *close_button;
   GtkWidget *button_box;
 };
 
@@ -1435,6 +1438,51 @@ gtk_window_new (GtkWindowType type)
 }
 
 static void
+min_button_clicked (GtkWidget *widget, gpointer data)
+{
+  GtkWindow *window = (GtkWindow *)data;
+  GdkWindowState state = gdk_window_get_state (widget->window);
+
+  if (state & GDK_WINDOW_STATE_ICONIFIED)
+    {
+      gtk_window_deiconify (window);
+    }
+  else
+    {
+      gtk_window_iconify (window);
+    }
+}
+
+static void
+max_button_clicked (GtkWidget *widget, gpointer data)
+{
+  GtkWindow *window = (GtkWindow *)data;
+  GdkWindowState state = gdk_window_get_state (widget->window);
+
+  if (state & GDK_WINDOW_STATE_MAXIMIZED)
+    {
+      gtk_window_unmaximize (window);
+    }
+  else
+    {
+      gtk_window_maximize (window);
+    }
+}
+
+static void
+close_button_clicked (GtkWidget *widget, gpointer data)
+{
+  GdkEvent *event = gdk_event_new (GDK_DELETE);
+
+  event->any.type = GDK_DELETE;
+  event->any.window = g_object_ref (widget->window);
+  event->any.send_event = TRUE;
+
+  gtk_main_do_event (event);
+  gdk_event_free (event);
+}
+
+static void
 ensure_title_box (GtkWindow *window)
 {
   GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window);
@@ -1450,21 +1498,30 @@ ensure_title_box (GtkWindow *window)
 
       button = gtk_button_new ();
       gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
-      image = gtk_image_new_from_stock (GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_MENU);
+      image = gtk_image_new_from_stock (GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_MENU);
       gtk_container_add (GTK_CONTAINER (button), image);
-      gtk_box_pack_end (GTK_BOX (hbox), button, TRUE, TRUE, 0);
+      gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
+      priv->min_button = button;
+      g_signal_connect (G_OBJECT (button), "clicked",
+                        G_CALLBACK (min_button_clicked), window);
 
       button = gtk_button_new ();
       gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
-      image = gtk_image_new_from_stock (GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_MENU);
+      image = gtk_image_new_from_stock (GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_MENU);
       gtk_container_add (GTK_CONTAINER (button), image);
-      gtk_box_pack_end (GTK_BOX (hbox), button, TRUE, TRUE, 0);
+      gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
+      priv->max_button = button;
+      g_signal_connect (G_OBJECT (button), "clicked",
+                        G_CALLBACK (max_button_clicked), window);
 
       button = gtk_button_new ();
       gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
       image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
       gtk_container_add (GTK_CONTAINER (button), image);
-      gtk_box_pack_end (GTK_BOX (hbox), button, TRUE, TRUE, 0);
+      gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
+      priv->close_button = button;
+      g_signal_connect (G_OBJECT (button), "clicked",
+                        G_CALLBACK (close_button_clicked), window);
 
       priv->button_box = hbox;
 
@@ -5169,6 +5226,8 @@ gtk_window_size_request (GtkWidget      *widget,
           child_height = MAX (child_height, box_requisition.height);
         }
 
+      // There should probably be some kind of padding property for
+      // "between the title/buttons and the bin.child".
       requisition->width += frame_left + frame_right;
       requisition->height += frame_top + frame_bottom + child_height;
     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]