Commit 8ebbd3a6 authored by Havoc Pennington's avatar Havoc Pennington Committed by Havoc Pennington

lookup signum before it's first used.

1999-12-16  Havoc Pennington  <hp@redhat.com>

* src/ntl-window-state.c (nautilus_window_save_state): lookup
signum before it's first used.

* src/file-manager/desktop-layout.c: new layout module, not yet
done

* src/file-manager/desktop-canvas.c (desktop_canvas_init): Create
the right-click menu.

* src/file-manager/desktop-menu.c (desktop_menu_new): New module
to stick the right-click menu code in
parent 7048ea0a
1999-12-16 Havoc Pennington <hp@redhat.com>
* src/ntl-window-state.c (nautilus_window_save_state): lookup
signum before it's first used.
* src/file-manager/desktop-layout.c: new layout module, not yet
done
* src/file-manager/desktop-canvas.c (desktop_canvas_init): Create
the right-click menu.
* src/file-manager/desktop-menu.c (desktop_menu_new): New module
to stick the right-click menu code in
1999-12-16 Maciej Stachowiak <mjs@eazel.com>
* src/ntl-window.c: Put meta-views on the right.
......@@ -63,6 +77,7 @@
* src/file-manager/gnome-desktop.c (main): Quiet some warnings.
>>>>>>> 1.33
1999-12-16 Havoc Pennington <hp@redhat.com>
* src/file-manager/gnome-desktop.c (main): warning fixes
......
......@@ -17,6 +17,8 @@ libntl_file_manager_la_SOURCES= \
fm-icon-cache.h \
desktop-canvas.c \
desktop-canvas.h \
desktop-layout.h \
desktop-layout.c \
desktop-window.c \
desktop-window.h \
dfos-corba.c \
......@@ -36,6 +38,10 @@ noinst_PROGRAMS=gnome-desktop
gnome_desktop_SOURCES= \
desktop-canvas.c \
desktop-canvas.h \
desktop-layout.h \
desktop-layout.c \
desktop-menu.h \
desktop-menu.c \
desktop-window.c \
desktop-window.h \
gnome-desktop.c
......
......@@ -25,6 +25,7 @@
#include <libgnomeui/gnome-canvas-rect-ellipse.h>
#include <libgnomeui/gnome-canvas-text.h>
#include <gtk/gtk.h>
#include "desktop-menu.h"
static void desktop_canvas_class_init (DesktopCanvasClass *class);
static void desktop_canvas_init (DesktopCanvas *dcanvas);
......@@ -84,211 +85,19 @@ desktop_canvas_class_init (DesktopCanvasClass *class)
widget_class->size_allocate = desktop_canvas_size_allocate;
}
static void
event_cb(GnomeCanvasItem* item, GdkEvent* event, gpointer data)
{
/* Debug */
if (event->type == GDK_BUTTON_PRESS)
gtk_main_quit();
}
static gint
item_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
{
static double x, y;
double new_x, new_y;
GdkCursor *fleur;
static int dragging;
double item_x, item_y;
/* set item_[xy] to the event x,y position in the parent's item-relative coordinates */
item_x = event->button.x;
item_y = event->button.y;
gnome_canvas_item_w2i (item->parent, &item_x, &item_y);
switch (event->type) {
case GDK_BUTTON_PRESS:
switch (event->button.button) {
case 1:
if (event->button.state & GDK_SHIFT_MASK)
gtk_object_destroy (GTK_OBJECT (item));
else {
x = item_x;
y = item_y;
fleur = gdk_cursor_new (GDK_FLEUR);
gnome_canvas_item_grab (item,
GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
fleur,
event->button.time);
gdk_cursor_destroy (fleur);
dragging = TRUE;
}
break;
case 2:
if (event->button.state & GDK_SHIFT_MASK)
gnome_canvas_item_lower_to_bottom (item);
else
gnome_canvas_item_lower (item, 1);
break;
case 3:
if (event->button.state & GDK_SHIFT_MASK)
gnome_canvas_item_raise_to_top (item);
else
gnome_canvas_item_raise (item, 1);
break;
default:
break;
}
break;
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
new_x = item_x;
new_y = item_y;
gnome_canvas_item_move (item, new_x - x, new_y - y);
x = new_x;
y = new_y;
}
break;
case GDK_BUTTON_RELEASE:
gnome_canvas_item_ungrab (item, event->button.time);
dragging = FALSE;
break;
default:
break;
}
return FALSE;
}
static void
setup_item (GnomeCanvasItem *item)
{
gtk_signal_connect (GTK_OBJECT (item), "event",
(GtkSignalFunc) item_event,
NULL);
}
#define gray50_width 2
#define gray50_height 2
static char gray50_bits[] = {
0x02, 0x01, };
static void
desktop_canvas_init (DesktopCanvas *dcanvas)
{
GnomeCanvasItem* ellipse;
GnomeCanvasItem* rect;
GnomeCanvasItem* text;
double x, y;
GdkBitmap* stipple;
gboolean use_stipple = FALSE;
dcanvas->background_info = desktop_background_info_new();
dcanvas->background_update_idle = 0;
stipple = gdk_bitmap_create_from_data (NULL, gray50_bits, gray50_width, gray50_height);
rect = gnome_canvas_item_new ((GnomeCanvasGroup*)GNOME_CANVAS(dcanvas)->root,
gnome_canvas_rect_get_type (),
"x1", 0.0,
"y1", 0.0,
"x2", (double)gdk_screen_width(),
"y2", (double)gdk_screen_height(),
"outline_color", "red",
"fill_color", "blue",
"width_pixels", 8,
NULL);
x = gdk_screen_width();
y = 0.0;
while (x > 0.0 || y < gdk_screen_height()) {
rect = gnome_canvas_item_new ((GnomeCanvasGroup*)GNOME_CANVAS(dcanvas)->root,
gnome_canvas_rect_get_type (),
"x1", x - 103.0,
"y1", y,
"x2", x,
"y2", y + 70.0,
"fill_color", "red",
"fill_stipple",
use_stipple ? stipple : NULL,
NULL);
setup_item(rect);
use_stipple = !use_stipple;
x -= 105;
y += 80;
}
x = 0.0;
y = 0.0;
while (x < gdk_screen_width() || y < gdk_screen_height()) {
rect = gnome_canvas_item_new ((GnomeCanvasGroup*)GNOME_CANVAS(dcanvas)->root,
gnome_canvas_rect_get_type (),
"x1", x,
"y1", y,
"x2", x + 53.0,
"y2", y + 30.0,
"fill_color", "green",
"fill_stipple",
use_stipple ? stipple : NULL,
NULL);
setup_item(rect);
use_stipple = !use_stipple;
x += 90;
y += 80;
}
dcanvas->popup = desktop_menu_new();
gdk_bitmap_unref (stipple);
ellipse =
gnome_canvas_item_new ((GnomeCanvasGroup*)GNOME_CANVAS(dcanvas)->root,
gnome_canvas_ellipse_get_type (),
"x1", 220.0,
"y1", 30.0,
"x2", 270.0,
"y2", 60.0,
"outline_color", "goldenrod",
"width_pixels", 8,
NULL);
gtk_signal_connect(GTK_OBJECT(ellipse), "event",
GTK_SIGNAL_FUNC(event_cb), NULL);
text = gnome_canvas_item_new ((GnomeCanvasGroup*)GNOME_CANVAS(dcanvas)->root,
gnome_canvas_text_get_type (),
"x", 300.0,
"y", 70.0,
"text", "click ellipse to exit",
"font", "fixed",
"anchor", GTK_ANCHOR_NORTH_WEST,
"fill_color", "black",
NULL);
setup_item(text);
/* the attachment holds a refcount and eventually destroys
the popup */
gnome_popup_menu_attach(dcanvas->popup, dcanvas, NULL);
}
static void
desktop_canvas_destroy (GtkObject *object)
{
......@@ -415,7 +224,7 @@ update_bg_idle(gpointer data)
set_widget_color(GTK_WIDGET(canvas), canvas->background_info->solid_color);
break;
default:
g_warning("FIXME not implemented yet");
g_warning("FIXME background features not all implemented yet");
break;
}
......
......@@ -86,6 +86,8 @@ struct _DesktopCanvas {
DesktopBackgroundInfo *background_info;
guint background_update_idle;
GtkWidget *popup;
};
struct _DesktopCanvasClass {
......
/* -*- Mode: C; c-set-style: linux; indent-tabs-mode: nil; c-basic-offset: 8 -*-
* Desktop component of GNOME file manager
*
* Copyright (C) 1999 Red Hat Inc., Free Software Foundation
* (based on Midnight Commander code by Federico Mena Quintero and Miguel de Icaza)
*
* This program 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 program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "desktop-layout.h"
struct _DesktopLayoutItem {
guint refcount;
/* Store the allocation here */
gint x;
gint y;
gint width;
gint height;
/* Callbacks */
DesktopLayoutSizeRequestFunc request_func;
DesktopLayoutSizeAllocateFunc allocate_func;
/* data */
GDestroyNotify destroy_notify_func;
gpointer user_data;
};
static void
item_size_request (DesktopLayoutItem* item,
gint *x,
gint *y,
gint *width,
gint *height)
{
g_return_if_fail(item != NULL);
g_return_if_fail(item->request_func != NULL);
/* set these so user functions can be lazy and only set w/h */
*x = -1;
*y = -1;
/* set these in order to check up on user functions */
*width = 0;
*height = 0;
(* item->request_func) (item, x, y, width, height, item->user_data);
/* check up */
g_return_if_fail(*width > 0);
g_return_if_fail(*height > 0);
/* can't set one and not the other */
g_return_if_fail((*x >= 0 && *y >= 0) || (*x < 0 && *y < 0));
}
static void
item_size_allocate (DesktopLayoutItem* item,
gint x, gint y, gint width, gint height)
{
item->x = x;
item->y = y;
item->width = width;
item->height = height;
/* the allocate func is optional since users can request
the allocation after-the-fact */
if (item->allocate_func)
(* item->allocate_func) (item, x, y, width, height, item->user_data);
}
DesktopLayoutItem*
desktop_layout_item_new (DesktopLayoutSizeRequestFunc request_func,
DesktopLayoutSizeAllocateFunc allocate_func,
GDestroyNotify destroy_notify_func,
gpointer user_data)
{
DesktopLayoutItem *item;
g_return_val_if_fail(request_func != NULL, NULL);
item = g_new(DesktopLayoutItem, 1);
item->refcount = 1;
item->x = item->y = 0;
item->width = item->height = 1;
item->request_func = request_func;
item->allocate_func = allocate_func;
item->destroy_notify_func = destroy_notify_func;
item->user_data = user_data;
return item;
}
void
desktop_layout_item_ref (DesktopLayoutItem *item)
{
g_return_if_fail(item != NULL);
item->refcount += 1;
}
void
desktop_layout_item_unref (DesktopLayoutItem *item)
{
g_return_if_fail(item != NULL);
g_return_if_fail(item->refcount > 0);
item->refcount -= 1;
if (item->refcount == 0) {
if (item->destroy_notify_func) {
(* item->destroy_notify_func) (item->user_data);
}
g_free(item);
}
}
gpointer
desktop_item_get_user_data (DesktopLayoutItem *item)
{
return item->user_data;
}
void
desktop_layout_item_get_allocation (DesktopLayoutItem *item,
gint *x,
gint *y,
gint *w,
gint *h)
{
g_return_if_fail(item != NULL);
if (x)
*x = item->x;
if (y)
*y = item->y;
if (w)
*w = item->width;
if (h)
*h = item->height;
}
/*
* DesktopLayout
*/
struct _DesktopLayout {
guint refcount;
GList* items;
gboolean rows_not_columns;
DesktopHLayoutMode hmode;
DesktopVLayoutMode vmode;
gint hpadding;
gint vpadding;
/* Our rectangle to put the items in */
gint x;
gint y;
gint width;
gint height;
};
DesktopLayout*
desktop_layout_new (void)
{
DesktopLayout *layout;
layout = g_new(DesktopLayout, 1);
layout->refcount = 1;
layout->items = NULL;
layout->x = layout->y = 0;
layout->width = layout->height = 1;
layout->rows_not_columns = FALSE;
layout->hmode = DesktopLayoutRightToLeft;
layout->vmode = DesktopLayoutTopToBottom;
layout->hpadding = 8;
layout->vpadding = 8;
}
void
desktop_layout_ref (DesktopLayout *layout)
{
g_return_if_fail(layout != NULL);
layout->refcount += 1;
}
void
desktop_layout_unref (DesktopLayout *layout)
{
g_return_if_fail(layout != NULL);
g_return_if_fail(layout->refcount > 0);
layout->refcount -= 1;
if (layout->refcount == 0) {
GList *iter;
iter = layout->items;
while (iter != NULL) {
desktop_layout_item_unref(iter->data);
iter = g_list_next(iter);
}
g_list_free(layout->items);
g_free(layout);
}
}
/* FIXME changing any of this stuff requires a layout recomputation */
void
desktop_layout_set_size (DesktopLayout *layout,
gint x,
gint y,
gint width,
gint height)
{
layout->x = x;
layout->y = y;
layout->width = width;
layout->height = height;
}
void
desktop_layout_set_mode (DesktopLayout *layout,
gboolean rows_not_columns,
DesktopHLayoutMode hmode,
DesktopVLayoutMode vmode)
{
layout->rows_not_columns = rows_not_columns;
layout->hmode = hmode;
layout->vmode = vmode;
}
void
desktop_layout_add_item (DesktopLayout *layout,
DesktopLayoutItem *item)
{
desktop_layout_item_ref(item);
layout->items = g_list_prepend(layout->items, item);
}
void
desktop_layout_remove_item (DesktopLayout *layout,
DesktopLayoutItem *item)
{
layout->items = g_list_remove(layout->items, item);
desktop_layout_item_unref(item);
}
static void
layout_top_to_bottom_right_to_left(DesktopLayout *layout,
gboolean ignore_position_requests)
{
}
static void
layout_top_to_bottom_left_to_right(DesktopLayout *layout,
gboolean ignore_position_requests)
{
}
static void
layout_rows_left_to_right(DesktopLayout *layout,
gboolean ignore_position_requests)
{
gint next_x = layout->x + layout->hpadding;
gint next_y = layout->y + layout->vpadding;
gint right_edge = layout->x + layout->width - layout->hpadding;
gint bottom_edge = layout->y + layout->height - layout->vpadding;
gint row_height = 0;
GList *iter;
iter = layout->items;
while (iter != NULL) {
DesktopLayoutItem *item = iter->data;
gint req_x, req_y, req_w, req_h;
item_size_request(item, &req_x, &req_y, &req_w, &req_h);
if (!ignore_position_requests && req_x >= 0) {
g_assert(req_y >= 0); /* req_x and req_y must be on the same side of 0 */
/* Give it its request - eventually we may take w/h into account though,
and flow the other icons around this one? */
item_size_allocate(item, req_x, req_y, req_w, req_h);
iter = g_list_next(iter);
continue;
} else {
/* We're either ignoring req_x or the item did not specify
a req_x */
g_assert(ignore_position_requests || req_x < 0);