Blame gtk/gtkwindow-decorate.c

Packit 98cdb6
/* GTK - The GIMP Toolkit
Packit 98cdb6
 * Copyright (C) 2001 Red Hat, Inc.
Packit 98cdb6
 *
Packit 98cdb6
 * This library is free software; you can redistribute it and/or
Packit 98cdb6
 * modify it under the terms of the GNU Lesser General Public
Packit 98cdb6
 * License as published by the Free Software Foundation; either
Packit 98cdb6
 * version 2 of the License, or (at your option) any later version.
Packit 98cdb6
 *
Packit 98cdb6
 * This library is distributed in the hope that it will be useful,
Packit 98cdb6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 98cdb6
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 98cdb6
 * Lesser General Public License for more details.
Packit 98cdb6
 *
Packit 98cdb6
 * You should have received a copy of the GNU Lesser General Public
Packit 98cdb6
 * License along with this library; if not, write to the
Packit 98cdb6
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 98cdb6
 * Boston, MA 02111-1307, USA.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
/* 
Packit 98cdb6
 * Authors: Alexander Larsson <alexl@redhat.com>
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
#include "config.h"
Packit 98cdb6
#include "gtkprivate.h"
Packit 98cdb6
#include "gtkwindow.h"
Packit 98cdb6
#include "gtkmain.h"
Packit 98cdb6
#include "gtkwindow-decorate.h"
Packit 98cdb6
#include "gtkintl.h"
Packit 98cdb6
#include "gtkalias.h"
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
#ifdef DECORATE_WINDOWS
Packit 98cdb6
Packit 98cdb6
typedef enum
Packit 98cdb6
{
Packit 98cdb6
  GTK_WINDOW_REGION_TITLE,
Packit 98cdb6
  GTK_WINDOW_REGION_MAXIMIZE,
Packit 98cdb6
  GTK_WINDOW_REGION_CLOSE,
Packit 98cdb6
  GTK_WINDOW_REGION_BR_RESIZE
Packit 98cdb6
} GtkWindowRegionType;
Packit 98cdb6
Packit 98cdb6
typedef struct _GtkWindowRegion GtkWindowRegion;
Packit 98cdb6
typedef struct _GtkWindowDecoration GtkWindowDecoration;
Packit 98cdb6
Packit 98cdb6
struct _GtkWindowRegion
Packit 98cdb6
{
Packit 98cdb6
  GdkRectangle rect;
Packit 98cdb6
  GtkWindowRegionType type;
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
typedef enum
Packit 98cdb6
{
Packit 98cdb6
  RESIZE_TOP_LEFT,
Packit 98cdb6
  RESIZE_TOP,
Packit 98cdb6
  RESIZE_TOP_RIGHT,
Packit 98cdb6
  RESIZE_RIGHT,
Packit 98cdb6
  RESIZE_BOTTOM_RIGHT,
Packit 98cdb6
  RESIZE_BOTTOM,
Packit 98cdb6
  RESIZE_BOTTOM_LEFT,
Packit 98cdb6
  RESIZE_LEFT,
Packit 98cdb6
  RESIZE_NONE,
Packit 98cdb6
} GtkWindowResizeType;
Packit 98cdb6
Packit 98cdb6
struct _GtkWindowDecoration
Packit 98cdb6
{
Packit 98cdb6
  gint n_regions;
Packit 98cdb6
  GtkWindowRegion *regions;
Packit 98cdb6
Packit 98cdb6
  gint last_x, last_y;
Packit 98cdb6
  gint last_w, last_h;
Packit 98cdb6
  
Packit 98cdb6
  PangoLayout *title_layout;
Packit 98cdb6
Packit 98cdb6
  GtkWindowResizeType resize;
Packit 98cdb6
  
Packit 98cdb6
  guint moving : 1;
Packit 98cdb6
  guint closing : 1;
Packit 98cdb6
  guint maximizing : 1;
Packit 98cdb6
  guint maximized : 1;
Packit 98cdb6
  guint maximizable : 1;
Packit 98cdb6
  guint decorated : 1;
Packit 98cdb6
  guint real_inner_move : 1;
Packit 98cdb6
  guint focused : 1;
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
#define DECORATION_BORDER_TOP 15
Packit 98cdb6
#define DECORATION_BORDER_LEFT 3
Packit 98cdb6
#define DECORATION_BORDER_RIGHT 3
Packit 98cdb6
#define DECORATION_BORDER_BOTTOM 3
Packit 98cdb6
#define DECORATION_BORDER_TOT_X (DECORATION_BORDER_LEFT + DECORATION_BORDER_RIGHT)
Packit 98cdb6
#define DECORATION_BORDER_TOT_Y (DECORATION_BORDER_TOP + DECORATION_BORDER_BOTTOM)
Packit 98cdb6
#define DECORATION_BUTTON_SIZE 9
Packit 98cdb6
#define DECORATION_BUTTON_Y_OFFSET 2
Packit 98cdb6
#define DECORATION_TITLE_FONT "Sans 9"
Packit 98cdb6
Packit 98cdb6
static void gtk_decorated_window_recalculate_regions      (GtkWindow      *window);
Packit 98cdb6
static GtkWindowRegionType gtk_decorated_window_region_type    (GtkWindow      *window,
Packit 98cdb6
						 gint            x,
Packit 98cdb6
						 gint            y);
Packit 98cdb6
static gint gtk_decorated_window_frame_event    (GtkWindow *window,
Packit 98cdb6
						 GdkEvent *event);
Packit 98cdb6
static gint gtk_decorated_window_button_press   (GtkWidget      *widget,
Packit 98cdb6
						 GdkEventButton *event);
Packit 98cdb6
static gint gtk_decorated_window_button_release (GtkWidget      *widget,
Packit 98cdb6
						 GdkEventButton *event);
Packit 98cdb6
static gint gtk_decorated_window_motion_notify  (GtkWidget      *widget,
Packit 98cdb6
						 GdkEventMotion *event);
Packit 98cdb6
static gint gtk_decorated_window_window_state   (GtkWidget           *widget,
Packit 98cdb6
						 GdkEventWindowState *event);
Packit 98cdb6
static void gtk_decorated_window_paint          (GtkWidget      *widget,
Packit 98cdb6
						 GdkRectangle   *area);
Packit 98cdb6
static gint gtk_decorated_window_focus_change   (GtkWidget         *widget,
Packit 98cdb6
						 GdkEventFocus     *event);
Packit 98cdb6
static void gtk_decorated_window_realize        (GtkWindow   *window);
Packit 98cdb6
static void gtk_decorated_window_unrealize      (GtkWindow   *window);
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_decoration_free (GtkWindowDecoration *deco)
Packit 98cdb6
{
Packit 98cdb6
  g_free (deco->regions);
Packit 98cdb6
  deco->regions = NULL;
Packit 98cdb6
  deco->n_regions = 0;
Packit 98cdb6
Packit 98cdb6
  g_free (deco);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
void
Packit 98cdb6
gtk_decorated_window_init (GtkWindow   *window)
Packit 98cdb6
{
Packit 98cdb6
  GtkWindowDecoration *deco;
Packit 98cdb6
Packit 98cdb6
  deco = g_new (GtkWindowDecoration, 1);
Packit 98cdb6
Packit 98cdb6
  deco->n_regions = 0;
Packit 98cdb6
  deco->regions = NULL;
Packit 98cdb6
  deco->title_layout = NULL;
Packit 98cdb6
  deco->resize = RESIZE_NONE;
Packit 98cdb6
  deco->moving = FALSE;
Packit 98cdb6
  deco->decorated = TRUE;
Packit 98cdb6
  deco->closing = FALSE;
Packit 98cdb6
  deco->maximizing = FALSE;
Packit 98cdb6
  deco->maximized = FALSE;
Packit 98cdb6
  deco->maximizable = FALSE;
Packit 98cdb6
  deco->real_inner_move = FALSE;
Packit 98cdb6
 
Packit 98cdb6
  g_object_set_data_full (G_OBJECT (window), I_("gtk-window-decoration"), deco,
Packit 98cdb6
			  (GDestroyNotify) gtk_decoration_free);
Packit 98cdb6
  
Packit 98cdb6
  gtk_window_set_has_frame (window, TRUE);
Packit 98cdb6
Packit 98cdb6
  g_signal_connect (window,
Packit 98cdb6
		    "frame-event",
Packit 98cdb6
		    G_CALLBACK (gtk_decorated_window_frame_event),
Packit 98cdb6
		    window);
Packit 98cdb6
  g_signal_connect (window,
Packit 98cdb6
		    "focus-in-event",
Packit 98cdb6
		    G_CALLBACK (gtk_decorated_window_focus_change),
Packit 98cdb6
		    window);
Packit 98cdb6
  g_signal_connect (window,
Packit 98cdb6
		    "focus-out-event",
Packit 98cdb6
		    G_CALLBACK (gtk_decorated_window_focus_change),
Packit 98cdb6
		    window);
Packit 98cdb6
  g_signal_connect (window,
Packit 98cdb6
		    "realize",
Packit 98cdb6
		    G_CALLBACK (gtk_decorated_window_realize),
Packit 98cdb6
		    window);
Packit 98cdb6
  g_signal_connect (window,
Packit 98cdb6
		    "unrealize",
Packit 98cdb6
		    G_CALLBACK (gtk_decorated_window_unrealize),
Packit 98cdb6
		    window);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static inline GtkWindowDecoration *
Packit 98cdb6
get_decoration (GtkWindow *window)
Packit 98cdb6
{
Packit 98cdb6
  return (GtkWindowDecoration *)g_object_get_data (G_OBJECT (window), "gtk-window-decoration");
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
void
Packit 98cdb6
gtk_decorated_window_set_title (GtkWindow   *window,
Packit 98cdb6
				const gchar *title)
Packit 98cdb6
{
Packit 98cdb6
  GtkWindowDecoration *deco = get_decoration (window);
Packit 98cdb6
  
Packit 98cdb6
  if (deco->title_layout)
Packit 98cdb6
    pango_layout_set_text (deco->title_layout, title, -1);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
void 
Packit 98cdb6
gtk_decorated_window_calculate_frame_size (GtkWindow *window)
Packit 98cdb6
{
Packit 98cdb6
  GdkWMDecoration decorations;
Packit 98cdb6
  GtkWindowDecoration *deco = get_decoration (window);
Packit 98cdb6
  
Packit 98cdb6
  if (gdk_window_get_decorations (GTK_WIDGET (window)->window,
Packit 98cdb6
				  &decorations))
Packit 98cdb6
    {
Packit 98cdb6
      if ((decorations & GDK_DECOR_BORDER) &&
Packit 98cdb6
	  (decorations & GDK_DECOR_TITLE))
Packit 98cdb6
	{
Packit 98cdb6
	  deco->decorated = TRUE;
Packit 98cdb6
	  if ((decorations & GDK_DECOR_MAXIMIZE) &&
Packit 98cdb6
	      (gtk_window_get_type_hint (window) == GDK_WINDOW_TYPE_HINT_NORMAL))
Packit 98cdb6
	    deco->maximizable = TRUE;
Packit 98cdb6
	}
Packit 98cdb6
      else
Packit 98cdb6
	deco->decorated = FALSE;
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    {
Packit 98cdb6
      deco->decorated = (window->type != GTK_WINDOW_POPUP);
Packit 98cdb6
      deco->maximizable = (gtk_window_get_type_hint (window) == GDK_WINDOW_TYPE_HINT_NORMAL);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (deco->decorated)
Packit 98cdb6
    gtk_window_set_frame_dimensions (window,
Packit 98cdb6
				     DECORATION_BORDER_LEFT,
Packit 98cdb6
				     DECORATION_BORDER_TOP,
Packit 98cdb6
				     DECORATION_BORDER_RIGHT,
Packit 98cdb6
				     DECORATION_BORDER_BOTTOM);
Packit 98cdb6
  else
Packit 98cdb6
    gtk_window_set_frame_dimensions (window, 0, 0, 0, 0);
Packit 98cdb6
Packit 98cdb6
  gtk_decorated_window_recalculate_regions (window);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gboolean
Packit 98cdb6
gtk_decorated_window_inner_change (GdkWindow *win,
Packit 98cdb6
				   gint x, gint y,
Packit 98cdb6
				   gint width, gint height,
Packit 98cdb6
				   gpointer user_data)
Packit 98cdb6
{
Packit 98cdb6
  GtkWindow *window = (GtkWindow *)user_data;
Packit 98cdb6
  GtkWidget *widget = GTK_WIDGET (window);
Packit 98cdb6
  GtkWindowDecoration *deco = get_decoration (window);
Packit 98cdb6
Packit 98cdb6
  if (deco->real_inner_move)
Packit 98cdb6
    {
Packit 98cdb6
      deco->real_inner_move = FALSE;
Packit 98cdb6
      return FALSE;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  deco->real_inner_move = TRUE;
Packit 98cdb6
  gdk_window_move_resize (widget->window,
Packit 98cdb6
			  window->frame_left, window->frame_top,
Packit 98cdb6
			  width, height);
Packit 98cdb6
Packit 98cdb6
  gdk_window_move_resize (window->frame,
Packit 98cdb6
			  x - window->frame_left, y - window->frame_top,
Packit 98cdb6
			  width + window->frame_left + window->frame_right,
Packit 98cdb6
			  height + window->frame_top + window->frame_bottom);
Packit 98cdb6
  return TRUE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_decorated_window_inner_get_pos (GdkWindow *win,
Packit 98cdb6
				    gint *x, gint *y,
Packit 98cdb6
				    gpointer user_data)
Packit 98cdb6
{
Packit 98cdb6
  GtkWindow *window = (GtkWindow *)user_data;
Packit 98cdb6
Packit 98cdb6
  gdk_window_get_position (window->frame, x, y);
Packit 98cdb6
  
Packit 98cdb6
  *x += window->frame_left;
Packit 98cdb6
  *y += window->frame_top;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_decorated_window_realize (GtkWindow   *window)
Packit 98cdb6
{
Packit 98cdb6
  GtkWindowDecoration *deco = get_decoration (window);
Packit 98cdb6
  GtkWidget *widget = GTK_WIDGET (window);
Packit 98cdb6
  PangoFontDescription *font_desc;
Packit 98cdb6
Packit 98cdb6
  deco->title_layout = gtk_widget_create_pango_layout (widget,
Packit 98cdb6
						       (window->title)?window->title:"");
Packit 98cdb6
Packit 98cdb6
  font_desc = pango_font_description_from_string(DECORATION_TITLE_FONT);
Packit 98cdb6
  pango_layout_set_font_description (deco->title_layout, font_desc);
Packit 98cdb6
  pango_font_description_free (font_desc);
Packit 98cdb6
Packit 98cdb6
#if 0
Packit 98cdb6
  /* What is this code exactly doing? I remember we were using the
Packit 98cdb6
     decorated windows with the DirectFB port and it did just work,
Packit 98cdb6
     and there was definitely no code in linux-fb involved. */
Packit 98cdb6
  gdk_fb_window_set_child_handler (window->frame,
Packit 98cdb6
				   gtk_decorated_window_inner_change,
Packit 98cdb6
				   gtk_decorated_window_inner_get_pos,
Packit 98cdb6
				   window);
Packit 98cdb6
Packit 98cdb6
  /* This is a huge hack to make frames have the same shape as
Packit 98cdb6
     the window they wrap */
Packit 98cdb6
  gdk_window_shape_combine_mask (window->frame, GDK_FB_USE_CHILD_SHAPE, 0, 0);
Packit 98cdb6
#endif
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_decorated_window_unrealize (GtkWindow   *window)
Packit 98cdb6
{
Packit 98cdb6
  GtkWindowDecoration *deco = get_decoration (window);
Packit 98cdb6
Packit 98cdb6
  if (deco->title_layout)
Packit 98cdb6
    {
Packit 98cdb6
      g_object_unref (deco->title_layout);
Packit 98cdb6
      deco->title_layout = NULL;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gint
Packit 98cdb6
gtk_decorated_window_frame_event (GtkWindow *window, GdkEvent *event)
Packit 98cdb6
{
Packit 98cdb6
  GtkWindowDecoration *deco = get_decoration (window);
Packit 98cdb6
  GtkWidget *widget = GTK_WIDGET (window);
Packit 98cdb6
  GdkEventExpose *expose_event;
Packit 98cdb6
Packit 98cdb6
  switch (event->type)
Packit 98cdb6
    {
Packit 98cdb6
    case GDK_EXPOSE:
Packit 98cdb6
      expose_event = (GdkEventExpose *)event;
Packit 98cdb6
      if (deco->decorated)
Packit 98cdb6
	gtk_decorated_window_paint (widget, &expose_event->area);
Packit 98cdb6
      return TRUE;
Packit 98cdb6
      break;
Packit 98cdb6
    case GDK_CONFIGURE:
Packit 98cdb6
      gtk_decorated_window_recalculate_regions (window);
Packit 98cdb6
      break;
Packit 98cdb6
    case GDK_MOTION_NOTIFY:
Packit 98cdb6
      return gtk_decorated_window_motion_notify (widget, (GdkEventMotion *)event);
Packit 98cdb6
      break;
Packit 98cdb6
    case GDK_BUTTON_PRESS:
Packit 98cdb6
      return gtk_decorated_window_button_press (widget, (GdkEventButton *)event);
Packit 98cdb6
      break;
Packit 98cdb6
    case GDK_BUTTON_RELEASE:
Packit 98cdb6
      return gtk_decorated_window_button_release (widget, (GdkEventButton *)event);
Packit 98cdb6
    case GDK_WINDOW_STATE:
Packit 98cdb6
      return gtk_decorated_window_window_state (widget, (GdkEventWindowState *)event);
Packit 98cdb6
    default:
Packit 98cdb6
      break;
Packit 98cdb6
    }
Packit 98cdb6
  return FALSE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gint
Packit 98cdb6
gtk_decorated_window_focus_change (GtkWidget         *widget,
Packit 98cdb6
				   GdkEventFocus     *event)
Packit 98cdb6
{
Packit 98cdb6
  GtkWindow *window = GTK_WINDOW(widget);
Packit 98cdb6
  GtkWindowDecoration *deco = get_decoration (window);
Packit 98cdb6
  deco->focused = event->in;
Packit 98cdb6
  gdk_window_invalidate_rect (window->frame, NULL, FALSE);
Packit 98cdb6
  return FALSE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gint
Packit 98cdb6
gtk_decorated_window_motion_notify (GtkWidget       *widget,
Packit 98cdb6
				    GdkEventMotion  *event)
Packit 98cdb6
{
Packit 98cdb6
  GtkWindow *window;
Packit 98cdb6
  GtkWindowDecoration *deco;
Packit 98cdb6
  GdkModifierType mask;
Packit 98cdb6
  GdkWindow *win;
Packit 98cdb6
  gint x, y;
Packit 98cdb6
  gint win_x, win_y, win_w, win_h;
Packit 98cdb6
  
Packit 98cdb6
  window = GTK_WINDOW (widget);
Packit 98cdb6
  deco = get_decoration (window);
Packit 98cdb6
  
Packit 98cdb6
  if (!deco->decorated)
Packit 98cdb6
    return TRUE;
Packit 98cdb6
  
Packit 98cdb6
  win = widget->window;
Packit 98cdb6
  gdk_window_get_pointer (window->frame, &x, &y, &mask);
Packit 98cdb6
  
Packit 98cdb6
  gdk_window_get_position (window->frame, &win_x, &win_y);
Packit 98cdb6
  win_x += DECORATION_BORDER_LEFT;
Packit 98cdb6
  win_y += DECORATION_BORDER_TOP;
Packit 98cdb6
  
Packit 98cdb6
  gdk_window_get_geometry (win, NULL, NULL, &win_w, &win_h, NULL);
Packit 98cdb6
Packit 98cdb6
  if (deco->moving)
Packit 98cdb6
    {
Packit 98cdb6
      int dx, dy;
Packit 98cdb6
      dx = x - deco->last_x;
Packit 98cdb6
      dy = y - deco->last_y;
Packit 98cdb6
Packit 98cdb6
      _gtk_window_reposition (window, win_x + dx, win_y + dy);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (deco->resize != RESIZE_NONE)
Packit 98cdb6
    {
Packit 98cdb6
      int w, h;
Packit 98cdb6
      
Packit 98cdb6
      w = win_w;
Packit 98cdb6
      h = win_h;
Packit 98cdb6
      
Packit 98cdb6
      switch(deco->resize) {
Packit 98cdb6
      case RESIZE_BOTTOM_RIGHT:
Packit 98cdb6
	w = x - DECORATION_BORDER_TOT_X;
Packit 98cdb6
	h = y - DECORATION_BORDER_TOT_Y;
Packit 98cdb6
	break;
Packit 98cdb6
      case RESIZE_RIGHT:
Packit 98cdb6
	w = x - DECORATION_BORDER_TOT_X;
Packit 98cdb6
	break;
Packit 98cdb6
      case RESIZE_BOTTOM:
Packit 98cdb6
	h = y - DECORATION_BORDER_TOT_Y;
Packit 98cdb6
	break;
Packit 98cdb6
      case RESIZE_TOP_LEFT:
Packit 98cdb6
      case RESIZE_TOP:
Packit 98cdb6
      case RESIZE_TOP_RIGHT:
Packit 98cdb6
      case RESIZE_BOTTOM_LEFT:
Packit 98cdb6
      case RESIZE_LEFT:
Packit 98cdb6
      default:
Packit 98cdb6
	g_warning ("Resize mode %d not handled yet.\n", deco->resize);
Packit 98cdb6
	break;
Packit 98cdb6
      }
Packit 98cdb6
      
Packit 98cdb6
      if ((w > 0) && (h > 0))
Packit 98cdb6
	{
Packit 98cdb6
	  _gtk_window_constrain_size (window, w,h, &w, &h);
Packit 98cdb6
	  
Packit 98cdb6
	  if ((w != win_w) || (h != win_h))
Packit 98cdb6
	    gdk_window_resize (widget->window, w, h);
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  return TRUE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static GtkWindowRegionType
Packit 98cdb6
gtk_decorated_window_region_type (GtkWindow *window, gint x, gint y)
Packit 98cdb6
{
Packit 98cdb6
  GtkWindowDecoration *deco = get_decoration (window);
Packit 98cdb6
  int i;
Packit 98cdb6
Packit 98cdb6
  for (i=0;i<deco->n_regions;i++)
Packit 98cdb6
    {
Packit 98cdb6
      if ((x > deco->regions[i].rect.x) &&
Packit 98cdb6
	  (x - deco->regions[i].rect.x < deco->regions[i].rect.width) &&
Packit 98cdb6
	  (y > deco->regions[i].rect.y) &&
Packit 98cdb6
	  (y - deco->regions[i].rect.y < deco->regions[i].rect.height))
Packit 98cdb6
	return deco->regions[i].type;
Packit 98cdb6
    }
Packit 98cdb6
  return -1;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gint
Packit 98cdb6
gtk_decorated_window_button_press (GtkWidget       *widget,
Packit 98cdb6
				   GdkEventButton  *event)
Packit 98cdb6
{
Packit 98cdb6
  GtkWindow *window;
Packit 98cdb6
  GtkWindowRegionType type;
Packit 98cdb6
  GtkWindowDecoration *deco;
Packit 98cdb6
  gint x, y; 
Packit 98cdb6
Packit 98cdb6
  window = GTK_WINDOW (widget);
Packit 98cdb6
  deco = get_decoration (window);
Packit 98cdb6
Packit 98cdb6
  if (!deco->decorated)
Packit 98cdb6
    return TRUE;
Packit 98cdb6
Packit 98cdb6
  x = event->x;
Packit 98cdb6
  y = event->y;
Packit 98cdb6
  
Packit 98cdb6
  type = gtk_decorated_window_region_type (window, x, y);
Packit 98cdb6
Packit 98cdb6
  switch (type)
Packit 98cdb6
    {
Packit 98cdb6
    case GTK_WINDOW_REGION_TITLE:
Packit 98cdb6
      if (!deco->maximized && event->state & GDK_BUTTON1_MASK)
Packit 98cdb6
	{
Packit 98cdb6
	  deco->last_x = x;
Packit 98cdb6
	  deco->last_y = y;
Packit 98cdb6
	  deco->moving = TRUE;
Packit 98cdb6
	}
Packit 98cdb6
      break;
Packit 98cdb6
    case GTK_WINDOW_REGION_MAXIMIZE:
Packit 98cdb6
      if (event->state & GDK_BUTTON1_MASK)
Packit 98cdb6
	deco->maximizing = TRUE;
Packit 98cdb6
      break;
Packit 98cdb6
    case GTK_WINDOW_REGION_CLOSE:
Packit 98cdb6
      if (event->state & GDK_BUTTON1_MASK)
Packit 98cdb6
	deco->closing = TRUE;
Packit 98cdb6
      break;
Packit 98cdb6
    case GTK_WINDOW_REGION_BR_RESIZE:
Packit 98cdb6
      if (!deco->maximized)
Packit 98cdb6
	{
Packit 98cdb6
	  if (event->state & GDK_BUTTON1_MASK)
Packit 98cdb6
	    deco->resize = RESIZE_BOTTOM_RIGHT;
Packit 98cdb6
	  deco->last_x = x;
Packit 98cdb6
	  deco->last_y = y;
Packit 98cdb6
	}
Packit 98cdb6
      break;
Packit 98cdb6
    default:
Packit 98cdb6
      break;
Packit 98cdb6
    }
Packit 98cdb6
  
Packit 98cdb6
  return TRUE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gint
Packit 98cdb6
gtk_decorated_window_button_release (GtkWidget	    *widget,
Packit 98cdb6
				     GdkEventButton *event)
Packit 98cdb6
{
Packit 98cdb6
  GtkWindow *window;
Packit 98cdb6
  GtkWindowRegionType type;
Packit 98cdb6
  GtkWindowDecoration *deco;
Packit 98cdb6
      
Packit 98cdb6
  window = GTK_WINDOW (widget);
Packit 98cdb6
  deco = get_decoration (window);
Packit 98cdb6
Packit 98cdb6
  if (deco->closing)
Packit 98cdb6
    {
Packit 98cdb6
      type = gtk_decorated_window_region_type (window, event->x, event->y);
Packit 98cdb6
      if (type == GTK_WINDOW_REGION_CLOSE)
Packit 98cdb6
	{
Packit 98cdb6
	  GdkEvent *event = gdk_event_new (GDK_DELETE);
Packit 98cdb6
Packit 98cdb6
	  event->any.type = GDK_DELETE;
Packit 98cdb6
	  event->any.window = g_object_ref (widget->window);
Packit 98cdb6
	  event->any.send_event = TRUE;
Packit 98cdb6
Packit 98cdb6
	  gtk_main_do_event (event);
Packit 98cdb6
	  gdk_event_free (event);
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
  else if (deco->maximizing)
Packit 98cdb6
    {
Packit 98cdb6
      type = gtk_decorated_window_region_type (window, event->x, event->y);
Packit 98cdb6
      if (type == GTK_WINDOW_REGION_MAXIMIZE)
Packit 98cdb6
        {
Packit 98cdb6
	  if (deco->maximized)
Packit 98cdb6
	    gtk_window_unmaximize (window);
Packit 98cdb6
	  else
Packit 98cdb6
	    gtk_window_maximize (window);
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
  
Packit 98cdb6
  deco->closing = FALSE;
Packit 98cdb6
  deco->maximizing = FALSE;
Packit 98cdb6
  deco->moving = FALSE;
Packit 98cdb6
  deco->resize = RESIZE_NONE;
Packit 98cdb6
  return TRUE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gint
Packit 98cdb6
gtk_decorated_window_window_state (GtkWidget	       *widget,
Packit 98cdb6
				   GdkEventWindowState *event)
Packit 98cdb6
{
Packit 98cdb6
  GtkWindow *window;
Packit 98cdb6
  GtkWindowDecoration *deco;
Packit 98cdb6
  GdkWindowObject *priv;
Packit 98cdb6
      
Packit 98cdb6
  window = GTK_WINDOW (widget);
Packit 98cdb6
  deco = get_decoration (window);
Packit 98cdb6
  priv = GDK_WINDOW_OBJECT (window->frame);
Packit 98cdb6
Packit 98cdb6
  if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED)
Packit 98cdb6
    {
Packit 98cdb6
      if (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED)
Packit 98cdb6
	{
Packit 98cdb6
	  int w, h;
Packit 98cdb6
	  gdk_window_get_geometry (widget->window, NULL, NULL,
Packit 98cdb6
				   &deco->last_w, &deco->last_h, NULL);
Packit 98cdb6
	  gdk_window_get_origin (widget->window, &deco->last_x, &deco->last_y);
Packit 98cdb6
	  w = gdk_screen_get_width(gdk_screen_get_default()) - DECORATION_BORDER_TOT_X;
Packit 98cdb6
	  h = gdk_screen_get_height(gdk_screen_get_default()) - DECORATION_BORDER_TOT_Y;
Packit 98cdb6
	  _gtk_window_constrain_size (window, w, h, &w, &h);
Packit 98cdb6
	  if (w != deco->last_w || h != deco->last_h)
Packit 98cdb6
	    {
Packit 98cdb6
	      _gtk_window_reposition (window, DECORATION_BORDER_LEFT, DECORATION_BORDER_TOP);
Packit 98cdb6
	      gdk_window_resize (widget->window, w, h);
Packit 98cdb6
	      deco->maximized = TRUE;
Packit 98cdb6
	    }
Packit 98cdb6
	}
Packit 98cdb6
      else
Packit 98cdb6
	{
Packit 98cdb6
	  _gtk_window_reposition (window, deco->last_x, deco->last_y);
Packit 98cdb6
	  _gtk_window_constrain_size (window, deco->last_w, deco->last_h,
Packit 98cdb6
				      &deco->last_w, &deco->last_h);
Packit 98cdb6
	  gdk_window_resize (widget->window, deco->last_w, deco->last_h);
Packit 98cdb6
	  deco->maximized = FALSE;
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
  return TRUE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_decorated_window_paint (GtkWidget    *widget,
Packit 98cdb6
			    GdkRectangle *area)
Packit 98cdb6
{
Packit 98cdb6
  GtkWindow *window = GTK_WINDOW (widget);
Packit 98cdb6
  GtkWindowDecoration *deco = get_decoration (window);
Packit 98cdb6
  gint x1, y1, x2, y2;
Packit 98cdb6
  GtkStateType border_state;
Packit 98cdb6
Packit 98cdb6
  if (deco->decorated)
Packit 98cdb6
    {
Packit 98cdb6
      GdkWindow *frame;
Packit 98cdb6
      gint width, height;
Packit 98cdb6
Packit 98cdb6
      frame = window->frame;
Packit 98cdb6
      gdk_drawable_get_size (frame, &width, &height);
Packit 98cdb6
Packit 98cdb6
      /* Top */
Packit 98cdb6
      gtk_paint_flat_box (widget->style, frame, GTK_STATE_NORMAL,
Packit 98cdb6
			  GTK_SHADOW_NONE, area, widget, "base",
Packit 98cdb6
			  0, 0,
Packit 98cdb6
			  width, DECORATION_BORDER_TOP);
Packit 98cdb6
      /* Bottom */
Packit 98cdb6
      gtk_paint_flat_box (widget->style, frame, GTK_STATE_NORMAL,
Packit 98cdb6
			  GTK_SHADOW_NONE, area, widget, "base",
Packit 98cdb6
			  0, height - DECORATION_BORDER_BOTTOM,
Packit 98cdb6
			  width, DECORATION_BORDER_BOTTOM);
Packit 98cdb6
      /* Left */
Packit 98cdb6
      gtk_paint_flat_box (widget->style, frame, GTK_STATE_NORMAL,
Packit 98cdb6
			  GTK_SHADOW_NONE, area, widget, "base",
Packit 98cdb6
			  0, DECORATION_BORDER_TOP,
Packit 98cdb6
			  DECORATION_BORDER_LEFT, height - DECORATION_BORDER_TOT_Y);
Packit 98cdb6
      /* Right */
Packit 98cdb6
      gtk_paint_flat_box (widget->style, frame, GTK_STATE_NORMAL,
Packit 98cdb6
			  GTK_SHADOW_NONE, area, widget, "base",
Packit 98cdb6
			  width - DECORATION_BORDER_RIGHT, DECORATION_BORDER_TOP,
Packit 98cdb6
			  DECORATION_BORDER_RIGHT, height - DECORATION_BORDER_TOT_Y);
Packit 98cdb6
      
Packit 98cdb6
      /* Border: */
Packit 98cdb6
      if (deco->focused)
Packit 98cdb6
	border_state = GTK_STATE_SELECTED;
Packit 98cdb6
      else 
Packit 98cdb6
	border_state = GTK_STATE_PRELIGHT;
Packit 98cdb6
Packit 98cdb6
      gtk_paint_box (widget->style, frame, border_state, 
Packit 98cdb6
		     GTK_SHADOW_OUT, area, widget, "base",
Packit 98cdb6
		     0, 0, width, height);
Packit 98cdb6
      
Packit 98cdb6
      gtk_paint_box (widget->style, frame, border_state, 
Packit 98cdb6
		     GTK_SHADOW_IN, area, widget, "base",
Packit 98cdb6
		     DECORATION_BORDER_LEFT - 2, DECORATION_BORDER_TOP - 2,
Packit 98cdb6
		     width - (DECORATION_BORDER_LEFT + DECORATION_BORDER_RIGHT) + 3,
Packit 98cdb6
		     height - (DECORATION_BORDER_TOP + DECORATION_BORDER_BOTTOM) + 3);
Packit 98cdb6
Packit 98cdb6
      if (deco->maximizable)
Packit 98cdb6
	{
Packit 98cdb6
	  /* Maximize button: */
Packit 98cdb6
Packit 98cdb6
	  x1 = width - (DECORATION_BORDER_LEFT * 2) - (DECORATION_BUTTON_SIZE * 2);
Packit 98cdb6
	  y1 = DECORATION_BUTTON_Y_OFFSET;
Packit 98cdb6
	  x2 = x1 + DECORATION_BUTTON_SIZE;
Packit 98cdb6
	  y2 = y1 + DECORATION_BUTTON_SIZE;
Packit 98cdb6
Packit 98cdb6
	  if (area)
Packit 98cdb6
	    gdk_gc_set_clip_rectangle (widget->style->bg_gc[widget->state], area);
Packit 98cdb6
Packit 98cdb6
	  gdk_draw_rectangle (frame, widget->style->bg_gc[widget->state], TRUE,
Packit 98cdb6
			      x1, y1, x2 - x1, y2 - y1);
Packit 98cdb6
Packit 98cdb6
	  gdk_draw_line (frame, widget->style->black_gc, x1 + 1, y1 + 1, x2 - 2, y1 + 1);
Packit 98cdb6
Packit 98cdb6
	  gdk_draw_rectangle (frame, widget->style->black_gc, FALSE,
Packit 98cdb6
			      x1 + 1, y1 + 2,
Packit 98cdb6
			      DECORATION_BUTTON_SIZE - 3, DECORATION_BUTTON_SIZE - 4);
Packit 98cdb6
Packit 98cdb6
	  if (area)
Packit 98cdb6
	    gdk_gc_set_clip_rectangle (widget->style->black_gc, NULL);
Packit 98cdb6
	}
Packit 98cdb6
      
Packit 98cdb6
      /* Close button: */
Packit 98cdb6
      
Packit 98cdb6
      x1 = width - DECORATION_BORDER_LEFT - DECORATION_BUTTON_SIZE;
Packit 98cdb6
      y1 = DECORATION_BUTTON_Y_OFFSET;
Packit 98cdb6
      x2 = width - DECORATION_BORDER_LEFT;
Packit 98cdb6
      y2 = DECORATION_BUTTON_Y_OFFSET + DECORATION_BUTTON_SIZE;
Packit 98cdb6
Packit 98cdb6
      if (area)
Packit 98cdb6
	gdk_gc_set_clip_rectangle (widget->style->bg_gc[widget->state], area);
Packit 98cdb6
Packit 98cdb6
      gdk_draw_rectangle (frame, widget->style->bg_gc[widget->state], TRUE,
Packit 98cdb6
			  x1, y1, x2 - x1, y2 - y1);
Packit 98cdb6
Packit 98cdb6
      if (area)
Packit 98cdb6
	gdk_gc_set_clip_rectangle (widget->style->bg_gc[widget->state], NULL);
Packit 98cdb6
      
Packit 98cdb6
      if (area)
Packit 98cdb6
	gdk_gc_set_clip_rectangle (widget->style->black_gc, area);
Packit 98cdb6
Packit 98cdb6
      gdk_draw_line (frame, widget->style->black_gc, x1, y1, x2-1, y2-1);
Packit 98cdb6
Packit 98cdb6
      gdk_draw_line (frame, widget->style->black_gc, x1, y2-1, x2-1, y1);
Packit 98cdb6
Packit 98cdb6
      if (area)
Packit 98cdb6
	gdk_gc_set_clip_rectangle (widget->style->black_gc, NULL);
Packit 98cdb6
      
Packit 98cdb6
      
Packit 98cdb6
Packit 98cdb6
      /* Title */
Packit 98cdb6
      if (deco->title_layout)
Packit 98cdb6
	{
Packit 98cdb6
	  if (area)
Packit 98cdb6
	    gdk_gc_set_clip_rectangle (widget->style->fg_gc [border_state], area);
Packit 98cdb6
Packit 98cdb6
	  gdk_draw_layout (frame,
Packit 98cdb6
			   widget->style->fg_gc [border_state],
Packit 98cdb6
			   DECORATION_BORDER_LEFT, 1,
Packit 98cdb6
			   deco->title_layout);
Packit 98cdb6
	  if (area)
Packit 98cdb6
	    gdk_gc_set_clip_rectangle (widget->style->fg_gc [border_state], NULL);
Packit 98cdb6
	}
Packit 98cdb6
      
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_decorated_window_recalculate_regions (GtkWindow *window)
Packit 98cdb6
{
Packit 98cdb6
  gint n_regions;
Packit 98cdb6
  gint width, height;
Packit 98cdb6
  GtkWindowRegion *region;
Packit 98cdb6
  GtkWindowDecoration *deco = get_decoration (window);
Packit 98cdb6
      
Packit 98cdb6
  n_regions = 0;
Packit 98cdb6
Packit 98cdb6
  if (!deco->decorated)
Packit 98cdb6
    return;
Packit 98cdb6
  
Packit 98cdb6
  n_regions += 2; /* close, Title */
Packit 98cdb6
  if (deco->maximizable)
Packit 98cdb6
    n_regions += 1;
Packit 98cdb6
  if (window->allow_shrink || window->allow_grow)
Packit 98cdb6
    n_regions += 2;
Packit 98cdb6
Packit 98cdb6
  if (deco->n_regions != n_regions)
Packit 98cdb6
    {
Packit 98cdb6
      g_free (deco->regions);
Packit 98cdb6
      deco->regions = g_new (GtkWindowRegion, n_regions);
Packit 98cdb6
      deco->n_regions = n_regions;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  width = GTK_WIDGET (window)->allocation.width + DECORATION_BORDER_TOT_X;
Packit 98cdb6
  height = GTK_WIDGET (window)->allocation.height + DECORATION_BORDER_TOT_Y;
Packit 98cdb6
Packit 98cdb6
  region = deco->regions;
Packit 98cdb6
Packit 98cdb6
  /* Maximize button */
Packit 98cdb6
  if (deco->maximizable)
Packit 98cdb6
    {
Packit 98cdb6
      region->rect.x = width - (DECORATION_BORDER_LEFT * 2) - (DECORATION_BUTTON_SIZE * 2);
Packit 98cdb6
      region->rect.y = DECORATION_BUTTON_Y_OFFSET;
Packit 98cdb6
      region->rect.width = DECORATION_BUTTON_SIZE;
Packit 98cdb6
      region->rect.height = DECORATION_BUTTON_SIZE;
Packit 98cdb6
      region->type = GTK_WINDOW_REGION_MAXIMIZE;
Packit 98cdb6
      region++;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  /* Close button */
Packit 98cdb6
  region->rect.x = width - DECORATION_BORDER_LEFT - DECORATION_BUTTON_SIZE;
Packit 98cdb6
  region->rect.y = DECORATION_BUTTON_Y_OFFSET;
Packit 98cdb6
  region->rect.width = DECORATION_BUTTON_SIZE;
Packit 98cdb6
  region->rect.height = DECORATION_BUTTON_SIZE;
Packit 98cdb6
  region->type = GTK_WINDOW_REGION_CLOSE;
Packit 98cdb6
  region++;
Packit 98cdb6
    
Packit 98cdb6
  /* title bar */
Packit 98cdb6
  region->rect.x = 0;
Packit 98cdb6
  region->rect.y = 0;
Packit 98cdb6
  region->rect.width = width;
Packit 98cdb6
  region->rect.height = DECORATION_BORDER_TOP;
Packit 98cdb6
  region->type = GTK_WINDOW_REGION_TITLE;
Packit 98cdb6
  region++;
Packit 98cdb6
  
Packit 98cdb6
  if (window->allow_shrink || window->allow_grow)
Packit 98cdb6
    {
Packit 98cdb6
      region->rect.x = width - (DECORATION_BORDER_RIGHT + 10);
Packit 98cdb6
      region->rect.y = height - DECORATION_BORDER_BOTTOM;
Packit 98cdb6
      region->rect.width = DECORATION_BORDER_RIGHT + 10;
Packit 98cdb6
      region->rect.height = DECORATION_BORDER_BOTTOM;
Packit 98cdb6
      region->type = GTK_WINDOW_REGION_BR_RESIZE;
Packit 98cdb6
      region++;
Packit 98cdb6
Packit 98cdb6
      region->rect.x = width - DECORATION_BORDER_RIGHT;
Packit 98cdb6
      region->rect.y = height - (DECORATION_BORDER_BOTTOM + 10);
Packit 98cdb6
      region->rect.width = DECORATION_BORDER_RIGHT;
Packit 98cdb6
      region->rect.height = DECORATION_BORDER_BOTTOM + 10;
Packit 98cdb6
      region->type = GTK_WINDOW_REGION_BR_RESIZE;
Packit 98cdb6
      region++;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
void
Packit 98cdb6
gtk_decorated_window_move_resize_window (GtkWindow   *window,
Packit 98cdb6
					 gint         x,
Packit 98cdb6
					 gint         y,
Packit 98cdb6
					 gint         width,
Packit 98cdb6
					 gint         height)
Packit 98cdb6
{
Packit 98cdb6
  GtkWidget *widget = GTK_WIDGET (window);
Packit 98cdb6
  GtkWindowDecoration *deco = get_decoration (window);
Packit 98cdb6
  
Packit 98cdb6
  deco->real_inner_move = TRUE;
Packit 98cdb6
  gdk_window_move_resize (widget->window,
Packit 98cdb6
			  x, y, width, height);
Packit 98cdb6
}
Packit 98cdb6
#else
Packit 98cdb6
Packit 98cdb6
void
Packit 98cdb6
gtk_decorated_window_init (GtkWindow  *window)
Packit 98cdb6
{
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
void 
Packit 98cdb6
gtk_decorated_window_calculate_frame_size (GtkWindow *window)
Packit 98cdb6
{
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
void
Packit 98cdb6
gtk_decorated_window_set_title (GtkWindow   *window,
Packit 98cdb6
				const gchar *title)
Packit 98cdb6
{
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
void
Packit 98cdb6
gtk_decorated_window_move_resize_window (GtkWindow   *window,
Packit 98cdb6
					 gint         x,
Packit 98cdb6
					 gint         y,
Packit 98cdb6
					 gint         width,
Packit 98cdb6
					 gint         height)
Packit 98cdb6
{
Packit 98cdb6
  gdk_window_move_resize (GTK_WIDGET (window)->window,
Packit 98cdb6
			  x, y, width, height);
Packit 98cdb6
}
Packit 98cdb6
#endif
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
#define __GTK_WINDOW_DECORATE_C__
Packit 98cdb6
#include "gtkaliasdef.c"