1 | /* |
---|
2 | * sample-control-container.c |
---|
3 | * |
---|
4 | * Authors: |
---|
5 | * Nat Friedman (nat@helixcode.com) |
---|
6 | * Michael Meeks (michael@helixcode.com) |
---|
7 | * |
---|
8 | * Copyright 1999, 2000 Helix Code, Inc. |
---|
9 | */ |
---|
10 | |
---|
11 | #include <config.h> |
---|
12 | #include <gnome.h> |
---|
13 | |
---|
14 | #if USING_OAF |
---|
15 | #include <liboaf/liboaf.h> |
---|
16 | #else |
---|
17 | #include <libgnorba/gnorba.h> |
---|
18 | #endif |
---|
19 | |
---|
20 | #include <bonobo.h> |
---|
21 | |
---|
22 | #include "properties.h" |
---|
23 | |
---|
24 | static gboolean |
---|
25 | populate_property_list (BonoboControlFrame *cf, GtkCList *clist) |
---|
26 | { |
---|
27 | GList *property_list, *l; |
---|
28 | Bonobo_PropertyBag pb; |
---|
29 | |
---|
30 | pb = bonobo_control_frame_get_control_property_bag (cf, NULL); |
---|
31 | |
---|
32 | /* Get the list of properties. */ |
---|
33 | if (pb == CORBA_OBJECT_NIL) |
---|
34 | return FALSE; |
---|
35 | |
---|
36 | property_list = bonobo_property_bag_client_get_property_names (pb, NULL); |
---|
37 | for (l = property_list; l != NULL; l = l->next) { |
---|
38 | char *row_array[2]; |
---|
39 | CORBA_TypeCode tc; |
---|
40 | gchar *name = l->data; |
---|
41 | |
---|
42 | row_array [0] = name; |
---|
43 | |
---|
44 | tc = bonobo_property_bag_client_get_property_type (pb, name, NULL); |
---|
45 | switch (tc->kind) { |
---|
46 | |
---|
47 | case CORBA_tk_boolean: |
---|
48 | row_array [1] = g_strdup ( |
---|
49 | bonobo_property_bag_client_get_value_gboolean (pb, name, NULL) ? "TRUE" : "FALSE"); |
---|
50 | break; |
---|
51 | |
---|
52 | case CORBA_tk_string: |
---|
53 | row_array [1] = g_strdup (bonobo_property_bag_client_get_value_string (pb, name, NULL)); |
---|
54 | break; |
---|
55 | |
---|
56 | case CORBA_tk_long: |
---|
57 | row_array [1] = g_strdup_printf ("%ld", bonobo_property_bag_client_get_value_glong (pb, name, NULL)); |
---|
58 | break; |
---|
59 | |
---|
60 | case CORBA_tk_float: |
---|
61 | row_array [1] = g_strdup_printf ("%f", bonobo_property_bag_client_get_value_gfloat (pb, name, NULL)); |
---|
62 | break; |
---|
63 | |
---|
64 | case CORBA_tk_double: |
---|
65 | row_array [1] = g_strdup_printf ("%g", bonobo_property_bag_client_get_value_gdouble (pb, name, NULL)); |
---|
66 | break; |
---|
67 | |
---|
68 | default: |
---|
69 | row_array [1] = g_strdup ("Unhandled Property Type"); |
---|
70 | break; |
---|
71 | } |
---|
72 | |
---|
73 | gtk_clist_append (clist, row_array); |
---|
74 | } |
---|
75 | g_list_free (property_list); |
---|
76 | |
---|
77 | return TRUE; |
---|
78 | } |
---|
79 | |
---|
80 | static void |
---|
81 | edit_property (GtkCList *clist, GdkEventButton *event, BonoboControlFrame *cf) |
---|
82 | { |
---|
83 | gchar *prop; |
---|
84 | gint row, col; |
---|
85 | GList *l; |
---|
86 | CORBA_TypeCode tc; |
---|
87 | Bonobo_PropertyBag pb; |
---|
88 | |
---|
89 | pb = bonobo_control_frame_get_control_property_bag (cf, NULL); |
---|
90 | g_return_if_fail (pb != CORBA_OBJECT_NIL); |
---|
91 | |
---|
92 | if (event->button == 3) { |
---|
93 | gtk_clist_get_selection_info (clist, event->x, event->y, |
---|
94 | &row, &col); |
---|
95 | if (row < 0) return; |
---|
96 | l = bonobo_property_bag_client_get_property_names (pb, NULL); |
---|
97 | if (row > g_list_length (l) - 1) return; |
---|
98 | |
---|
99 | /* Get the value of the property they clicked on. */ |
---|
100 | prop = g_list_nth_data (l, row); |
---|
101 | /* Change it appropriately. */ |
---|
102 | tc = bonobo_property_bag_client_get_property_type (pb, prop, NULL); |
---|
103 | |
---|
104 | switch (tc->kind) { |
---|
105 | |
---|
106 | case CORBA_tk_boolean: |
---|
107 | bonobo_property_bag_client_set_value_gboolean ( |
---|
108 | pb, prop, !bonobo_property_bag_client_get_value_gboolean (pb, prop, NULL), NULL); |
---|
109 | break; |
---|
110 | |
---|
111 | default: |
---|
112 | g_warning ("Cannot set_value this type of property yet, sorry."); |
---|
113 | break; |
---|
114 | |
---|
115 | } |
---|
116 | |
---|
117 | g_list_free (l); |
---|
118 | |
---|
119 | /* Redraw the property list. */ |
---|
120 | gtk_clist_clear (clist); |
---|
121 | populate_property_list (cf, clist); |
---|
122 | } |
---|
123 | |
---|
124 | } |
---|
125 | |
---|
126 | static GtkWidget * |
---|
127 | create_proplist (BonoboControlFrame *cf) |
---|
128 | { |
---|
129 | gchar *clist_titles[] = {"Property Name", "Value"}; |
---|
130 | GtkWidget *clist; |
---|
131 | |
---|
132 | /* Put the property CList on the bottom. */ |
---|
133 | clist = gtk_clist_new_with_titles (2, clist_titles); |
---|
134 | gtk_signal_connect (GTK_OBJECT (clist), "button_press_event", |
---|
135 | GTK_SIGNAL_FUNC (edit_property), cf); |
---|
136 | |
---|
137 | populate_property_list (cf, GTK_CLIST (clist)); |
---|
138 | |
---|
139 | return clist; |
---|
140 | } |
---|
141 | |
---|
142 | void |
---|
143 | show_property_dialog (BonoboControlFrame *cf) |
---|
144 | { |
---|
145 | GtkWidget *dialog; |
---|
146 | GtkWidget *clist; |
---|
147 | |
---|
148 | clist = create_proplist (cf); |
---|
149 | |
---|
150 | if (!clist || !cf) { |
---|
151 | dialog = gnome_message_box_new ( |
---|
152 | _("Component has no editable properties"), |
---|
153 | GNOME_MESSAGE_BOX_INFO, GNOME_STOCK_BUTTON_OK, NULL); |
---|
154 | } else { |
---|
155 | dialog = gnome_dialog_new ("Properties", GNOME_STOCK_BUTTON_OK, NULL); |
---|
156 | |
---|
157 | gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), |
---|
158 | clist, TRUE, TRUE, 0); |
---|
159 | |
---|
160 | gtk_widget_show (clist); |
---|
161 | } |
---|
162 | |
---|
163 | gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); |
---|
164 | } |
---|
165 | |
---|
166 | |
---|