root/gui/graph_view.c @ 57a7eb7a0c44d4df3639bc2e11583651e30260da

Revision 57a7eb7a0c44d4df3639bc2e11583651e30260da, 5.2 KB (checked in by Nedko Arnaudov <nedko@…>, 4 years ago)

gui: reset window title when last view is destroyed

Last and currently the only view is destroyed when studio is unloaded

  • Property mode set to 100644
Line 
1/* -*- Mode: C ; c-basic-offset: 2 -*- */
2/*
3 * LADI Session Handler (ladish)
4 *
5 * Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
6 *
7 **************************************************************************
8 * This file contains implementation of the graph view object
9 **************************************************************************
10 *
11 * LADI Session Handler is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * LADI Session Handler is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25 */
26
27#include "common.h"
28#include "graph_view.h"
29#include "glade.h"
30#include "world_tree.h"
31
32struct graph_view
33{
34  struct list_head siblings;
35  char * name;
36  graph_canvas_handle graph_canvas;
37  graph_proxy_handle graph;
38  GtkWidget * canvas_widget;
39};
40
41struct list_head g_views;
42
43GtkScrolledWindow * g_main_scrolledwin;
44static struct graph_view * g_current_view;
45
46void view_init(void)
47{
48  g_main_scrolledwin = GTK_SCROLLED_WINDOW(get_glade_widget("main_scrolledwin"));
49  INIT_LIST_HEAD(&g_views);
50  g_current_view = NULL;
51}
52
53bool
54create_view(
55  const char * name,
56  const char * service,
57  const char * object,
58  bool graph_dict_supported,
59  bool force_activate,
60  graph_view_handle * handle_ptr)
61{
62  struct graph_view * view_ptr;
63
64  view_ptr = malloc(sizeof(struct graph_view));
65  if (view_ptr == NULL)
66  {
67    log_error("malloc() failed for struct graph_view");
68    goto fail;
69  }
70
71  view_ptr->name = strdup(name);
72  if (view_ptr->name == NULL)
73  {
74    log_error("strdup() failed for \"%s\"", name);
75    goto free_view;
76  }
77
78  if (!graph_proxy_create(service, object, graph_dict_supported, &view_ptr->graph))
79  {
80    goto free_name;
81  }
82
83  if (!graph_canvas_create(1600 * 2, 1200 * 2, &view_ptr->graph_canvas))
84  {
85    goto destroy_graph;
86  }
87
88  if (!graph_canvas_attach(view_ptr->graph_canvas, view_ptr->graph))
89  {
90    goto destroy_graph_canvas;
91  }
92
93  if (!graph_proxy_activate(view_ptr->graph))
94  {
95    goto detach_graph_canvas;
96  }
97
98  view_ptr->canvas_widget = canvas_get_widget(graph_canvas_get_canvas(view_ptr->graph_canvas));
99
100  list_add_tail(&view_ptr->siblings, &g_views);
101
102  gtk_widget_show(view_ptr->canvas_widget);
103
104  world_tree_add((graph_view_handle)view_ptr, force_activate);
105
106  *handle_ptr = (graph_view_handle)view_ptr;
107
108  return true;
109
110detach_graph_canvas:
111  graph_canvas_detach(view_ptr->graph_canvas);
112destroy_graph_canvas:
113  graph_canvas_destroy(view_ptr->graph_canvas);
114destroy_graph:
115  graph_proxy_destroy(view_ptr->graph);
116free_name:
117  free(view_ptr->name);
118free_view:
119  free(view_ptr);
120fail:
121  return false;
122}
123
124static void attach_canvas(struct graph_view * view_ptr)
125{
126  GtkWidget * child;
127
128  child = gtk_bin_get_child(GTK_BIN(g_main_scrolledwin));
129
130  if (child == view_ptr->canvas_widget)
131  {
132    return;
133  }
134
135  if (child != NULL)
136  {
137    gtk_container_remove(GTK_CONTAINER(g_main_scrolledwin), child);
138  }
139
140  g_current_view = view_ptr;
141  gtk_container_add(GTK_CONTAINER(g_main_scrolledwin), view_ptr->canvas_widget);
142
143  //_main_scrolledwin->property_hadjustment().get_value()->set_step_increment(10);
144  //_main_scrolledwin->property_vadjustment().get_value()->set_step_increment(10);
145}
146
147static void detach_canvas(struct graph_view * view_ptr)
148{
149  GtkWidget * child;
150
151  child = gtk_bin_get_child(GTK_BIN(g_main_scrolledwin));
152  if (child == view_ptr->canvas_widget)
153  {
154    gtk_container_remove(GTK_CONTAINER(g_main_scrolledwin), view_ptr->canvas_widget);
155    g_current_view = NULL;
156  }
157}
158
159#define view_ptr ((struct graph_view *)view)
160
161void destroy_view(graph_view_handle view)
162{
163  list_del(&view_ptr->siblings);
164  if (!list_empty(&g_views))
165  {
166    world_tree_activate((graph_view_handle)list_entry(g_views.next, struct graph_view, siblings));
167  }
168  else
169  {
170    set_main_window_title(NULL);
171  }
172
173  detach_canvas(view_ptr);
174
175  world_tree_remove(view);
176
177  graph_canvas_detach(view_ptr->graph_canvas);
178  graph_canvas_destroy(view_ptr->graph_canvas);
179  graph_proxy_destroy(view_ptr->graph);
180  free(view_ptr->name);
181  free(view_ptr);
182}
183
184void activate_view(graph_view_handle view)
185{
186  attach_canvas(view_ptr);
187  set_main_window_title(view);
188}
189
190const char * get_view_name(graph_view_handle view)
191{
192  return view_ptr->name;
193}
194
195bool set_view_name(graph_view_handle view, const char * cname)
196{
197  char * name;
198
199  name = strdup(cname);
200  if (name == NULL)
201  {
202    log_error("strdup() failed for \"%s\"", name);
203    return false;
204  }
205
206  free(view_ptr->name);
207  view_ptr->name = name;
208
209  world_tree_name_changed(view);
210
211  if (g_current_view == view_ptr)
212  {
213    set_main_window_title(view);
214  }
215
216  return true;
217}
218
219canvas_handle get_current_canvas()
220{
221  if (g_current_view == NULL)
222  {
223    return NULL;
224  }
225
226  return graph_canvas_get_canvas(g_current_view->graph_canvas);
227}
Note: See TracBrowser for help on using the browser.