1 /* Desktop preferences box for the Midnight Commander
3 * Copyright (C) 1999 The Free Software Foundation
5 * Author: Federico Mena <federico@nuclecu.unam.mx>
11 #include "gdesktop-prefs.h"
14 /* Size of the icon position box */
15 #define ICON_POS_WIDTH 120
16 #define ICON_POS_HEIGHT 90
17 #define ICON_POS_INTERVAL 10
24 /* Structure to hold preferences information */
25 struct _GDesktopPrefs
{
26 /* Property box we are attached to */
27 GnomePropertyBox
*pbox
;
29 /* Canvas for the miniature icons */
32 /* Group that holds the miniature icons */
33 GnomeCanvasItem
*group
;
35 /* Icon position flags */
36 guint right_to_left
: 1;
37 guint bottom_to_top
: 1;
38 guint rows_not_columns
: 1;
40 /* Icon positioning options */
41 GtkWidget
*auto_placement
;
42 GtkWidget
*snap_icons
;
44 /* Icon shape options */
45 GtkWidget
*use_shaped_icons
;
46 GtkWidget
*use_shaped_text
;
50 /* Creates the canvas items that represent a mini-icon */
52 create_mini_icon (GnomeCanvasGroup
*group
, int x
, int y
, guint color
)
54 gnome_canvas_item_new (group
,
55 gnome_canvas_rect_get_type (),
56 "x1", (double) (x
- 1),
57 "y1", (double) (y
- 2),
58 "x2", (double) (x
+ 1),
60 "fill_color_rgba", color
,
63 gnome_canvas_item_new (group
,
64 gnome_canvas_rect_get_type (),
65 "x1", (double) (x
- 2),
66 "y1", (double) (y
+ 2),
67 "x2", (double) (x
+ 2),
68 "y2", (double) (y
+ 3),
69 "fill_color_rgba", color
,
73 /* Re-create the icon position mini-icons */
75 create_mini_icons (GDesktopPrefs
*dp
, int r2l
, int b2t
, int rows
)
86 dp
->right_to_left
= r2l
? TRUE
: FALSE
;
87 dp
->bottom_to_top
= b2t
? TRUE
: FALSE
;
88 dp
->rows_not_columns
= rows
? TRUE
: FALSE
;
90 /* Compute color for mini icons */
92 style
= gtk_widget_get_style (GTK_WIDGET (dp
->canvas
));
93 c
= &style
->fg
[GTK_STATE_NORMAL
];
94 color
= ((c
->red
& 0xff00) << 8) | (c
->green
& 0xff00) | (c
->blue
>> 8) | 0xff;
97 gtk_object_destroy (GTK_OBJECT (dp
->group
));
99 dp
->group
= gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (dp
->canvas
)),
100 gnome_canvas_group_get_type (),
103 if (dp
->right_to_left
) {
104 ox
= ICON_POS_WIDTH
- ICON_POS_INTERVAL
;
105 dx
= -ICON_POS_INTERVAL
;
107 ox
= ICON_POS_INTERVAL
;
108 dx
= ICON_POS_INTERVAL
;
111 if (dp
->bottom_to_top
) {
112 oy
= ICON_POS_HEIGHT
- ICON_POS_INTERVAL
;
113 dy
= -ICON_POS_INTERVAL
;
115 oy
= ICON_POS_INTERVAL
;
116 dy
= ICON_POS_INTERVAL
;
119 if (dp
->rows_not_columns
)
124 for (i
= 0; i
< 2; i
++) {
125 if (dp
->rows_not_columns
) {
127 max_j
= (i
== 1) ? (ICON_POS_WIDTH
/ 2) : ICON_POS_WIDTH
;
130 max_j
= (i
== 1) ? (ICON_POS_HEIGHT
/ 2) : ICON_POS_HEIGHT
;
133 for (j
= ICON_POS_INTERVAL
; j
< max_j
; j
+= ICON_POS_INTERVAL
) {
134 create_mini_icon (GNOME_CANVAS_GROUP (dp
->group
), x
, y
, color
);
136 if (dp
->rows_not_columns
)
142 if (dp
->rows_not_columns
)
149 /* Handler for button presses on the icon position canvas */
151 button_press (GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
161 if (!(event
->type
== GDK_BUTTON_PRESS
&& event
->button
== 1))
164 if (event
->x
> ICON_POS_WIDTH
/ 2) {
166 dx
= ICON_POS_WIDTH
- event
->x
;
172 if (event
->y
> ICON_POS_HEIGHT
/ 2) {
174 dy
= ICON_POS_HEIGHT
- event
->y
;
185 create_mini_icons (dp
, r2l
, b2t
, rows
);
186 gnome_property_box_changed (dp
->pbox
);
190 /* Creates the canvas widget and items to configure icon position */
192 create_icon_pos (GDesktopPrefs
*dp
)
194 dp
->canvas
= gnome_canvas_new ();
195 gtk_widget_set_usize (dp
->canvas
, ICON_POS_WIDTH
, ICON_POS_HEIGHT
);
196 gnome_canvas_set_scroll_region (GNOME_CANVAS (dp
->canvas
),
197 0.0, 0.0, ICON_POS_WIDTH
, ICON_POS_HEIGHT
);
199 gtk_signal_connect (GTK_OBJECT (dp
->canvas
), "button_press_event",
200 GTK_SIGNAL_FUNC (button_press
),
203 create_mini_icons (dp
, desktop_arr_r2l
, desktop_arr_b2t
, desktop_arr_rows
);
208 /* Callback used to notify a property box when a toggle button is toggled */
210 toggled (GtkWidget
*w
, gpointer data
)
212 gnome_property_box_changed (GNOME_PROPERTY_BOX (data
));
215 /* Creates a check box that will notify a property box when it changes */
217 create_check_box (char *text
, int state
, GnomePropertyBox
*pbox
)
221 w
= gtk_check_button_new_with_label (text
);
222 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w
), state
);
223 gtk_signal_connect (GTK_OBJECT (w
), "toggled",
224 GTK_SIGNAL_FUNC (toggled
),
230 /* Creates the widgets that are used to configure icon position and snapping */
232 create_position_widgets (GDesktopPrefs
*dp
)
238 vbox
= gtk_vbox_new (FALSE
, GNOME_PAD_SMALL
);
242 w
= gtk_label_new (_("Icon position"));
243 gtk_misc_set_alignment (GTK_MISC (w
), 0.0, 0.5);
244 gtk_box_pack_start (GTK_BOX (vbox
), w
, FALSE
, FALSE
, 0);
246 w
= gtk_alignment_new (0.0, 0.0, 0.0, 0.0);
247 gtk_box_pack_start (GTK_BOX (vbox
), w
, FALSE
, FALSE
, 0);
249 frame
= gtk_frame_new (NULL
);
250 gtk_frame_set_shadow_type (GTK_FRAME (frame
), GTK_SHADOW_IN
);
251 gtk_container_add (GTK_CONTAINER (w
), frame
);
253 w
= create_icon_pos (dp
);
254 gtk_container_add (GTK_CONTAINER (frame
), w
);
256 /* Snap and placement */
258 dp
->auto_placement
= create_check_box (_("Automatic icon placement"),
259 desktop_auto_placement
, dp
->pbox
);
260 gtk_box_pack_start (GTK_BOX (vbox
), dp
->auto_placement
, FALSE
, FALSE
, 0);
262 dp
->snap_icons
= create_check_box (_("Snap icons to grid"),
263 desktop_snap_icons
, dp
->pbox
);
264 gtk_box_pack_start (GTK_BOX (vbox
), dp
->snap_icons
, FALSE
, FALSE
, 0);
269 /* Creates the widgets that are used to configure the icon shape */
271 create_shape_widgets (GDesktopPrefs
*dp
)
275 vbox
= gtk_vbox_new (FALSE
, GNOME_PAD_SMALL
);
277 dp
->use_shaped_icons
= create_check_box (_("Use shaped icons"),
278 desktop_use_shaped_icons
, dp
->pbox
);
279 gtk_box_pack_start (GTK_BOX (vbox
), dp
->use_shaped_icons
, FALSE
, FALSE
, 0);
281 dp
->use_shaped_text
= create_check_box (_("Use shaped text"),
282 desktop_use_shaped_text
, dp
->pbox
);
283 gtk_box_pack_start (GTK_BOX (vbox
), dp
->use_shaped_text
, FALSE
, FALSE
, 0);
288 /* Callback to destroy the desktop preferences data */
290 destroy (GtkObject
*object
, gpointer data
)
298 /* Creates all the widgets in the desktop preferences page */
300 create_widgets (GDesktopPrefs
*dp
)
305 hbox
= gtk_hbox_new (FALSE
, GNOME_PAD_SMALL
);
306 gtk_container_set_border_width (GTK_CONTAINER (hbox
), GNOME_PAD_SMALL
);
307 gtk_signal_connect (GTK_OBJECT (hbox
), "destroy",
308 GTK_SIGNAL_FUNC (destroy
),
311 w
= create_position_widgets (dp
);
312 gtk_box_pack_start (GTK_BOX (hbox
), w
, TRUE
, TRUE
, 0);
314 w
= create_shape_widgets (dp
);
315 gtk_box_pack_start (GTK_BOX (hbox
), w
, TRUE
, TRUE
, 0);
317 gtk_widget_show_all (hbox
);
321 /* Creates the desktop preferences page */
323 desktop_prefs_new (GnomePropertyBox
*pbox
)
328 g_return_val_if_fail (pbox
!= NULL
, NULL
);
330 dp
= g_new0 (GDesktopPrefs
, 1);
334 page
= create_widgets (dp
);
335 gnome_property_box_append_page (pbox
, page
, gtk_label_new (_("Desktop")));
340 /* Applies the changes in the desktop preferences page */
342 desktop_prefs_apply (GDesktopPrefs
*dp
)
344 g_return_if_fail (dp
!= NULL
);
346 desktop_arr_r2l
= dp
->right_to_left
;
347 desktop_arr_b2t
= dp
->bottom_to_top
;
348 desktop_arr_rows
= dp
->rows_not_columns
;
350 desktop_auto_placement
= gtk_toggle_button_get_active (
351 GTK_TOGGLE_BUTTON (dp
->auto_placement
));
353 desktop_snap_icons
= gtk_toggle_button_get_active (
354 GTK_TOGGLE_BUTTON (dp
->snap_icons
));
356 desktop_use_shaped_icons
= gtk_toggle_button_get_active (
357 GTK_TOGGLE_BUTTON (dp
->use_shaped_icons
));
359 desktop_use_shaped_text
= gtk_toggle_button_get_active (
360 GTK_TOGGLE_BUTTON (dp
->use_shaped_text
));
362 desktop_reload_icons (FALSE
, 0, 0);