File: menus.c

package info (click to toggle)
ggobi 2.1.9~20091212-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 19,340 kB
  • ctags: 5,083
  • sloc: ansic: 57,242; xml: 30,604; cpp: 833; makefile: 355; java: 225; perl: 201; sh: 122; python: 23
file content (183 lines) | stat: -rw-r--r-- 5,359 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*-- menus.c: menus in the display menubar that change with the mode;
*/
/*
 * ggobi
 * Copyright (C) AT&T, Duncan Temple Lang, Dianne Cook 1999-2005
 *
 * ggobi is free software; you may use, redistribute, and/or modify it
 * under the terms of the Common Public License, which is distributed
 * with the source code and displayed on the ggobi web site, 
 * www.ggobi.org.  For more information, contact the authors:
 *
 *   Deborah F. Swayne   dfs@research.att.com
 *   Di Cook             dicook@iastate.edu
 *   Duncan Temple Lang  duncan@wald.ucdavis.edu
 *   Andreas Buja        andreas.buja@wharton.upenn.edu
*/

#include <gtk/gtk.h>
#include "vars.h"
#include "externs.h"


/*
 * These menus have migrated from the main menubar to the display
 * menubar.
 */

static gboolean
pmode_has_display_menu (ProjectionMode pmode)
{
  return (pmode == TOUR1D || pmode == TOUR2D || pmode == COTOUR);
}

static const gchar *tour1d_pmode_ui =
  "<ui>"
  "	<menubar>"
  "		<menu action='Tour1D'>"
  "			<menuitem action='ShowAxes'/>"
  "			<menuitem action='FadeVariables1D'/>"
  "			<menuitem action='SelectAllVariables1D'/>"
  "		</menu>" "	</menubar>" "</ui>";

static const gchar *tour2d_pmode_ui =
  "<ui>"
  "	<menubar>"
  "		<menu action='Tour2D'>"
  "			<menuitem action='ShowAxes'/>"
  "			<menuitem action='ShowAxesLabels'/>"
  "			<menuitem action='ShowAxesVals'/>"
  "			<separator/>"
  "			<menuitem action='FadeVariables2D'/>"
  "			<menuitem action='SelectAllVariables2D'/>"
  "		</menu>" "	</menubar>" "</ui>";


static const gchar *cotour_pmode_ui =
  "<ui>"
  "	<menubar>"
  "		<menu action='CorrTour'>"
  "			<menuitem action='ShowAxes'/>"
  "			<separator/>"
  "			<menuitem action='FadeVariablesCo'/>"
  "		</menu>" "	</menubar>" "</ui>";


static const gchar *brush_imode_ui =
  "<ui>"
  "	<menubar>"
  "		<menu action='Brush'>"
  "			<menuitem action='ExcludeShadowedPoints'/>"
  "			<menuitem action='IncludeShadowedPoints'/>"
  "			<menuitem action='UnshadowAllPoints'/>"
  "			<separator/>"
  "			<menuitem action='ExcludeShadowedEdges'/>"
  "			<menuitem action='IncludeShadowedEdges'/>"
  "			<menuitem action='UnshadowAllEdges'/>"
  "			<separator/>"
  "			<menuitem action='ResetBrushSize'/>"
  "			<menuitem action='UpdateBrushContinuously'/>"
  "			<menuitem action='BrushOn'/>" "		</menu>" "	</menubar>" "</ui>";

static const gchar *scale_imode_ui =
  "<ui>"
  "	<menubar>"
  "		<menu action='Scale'>"
  "			<menuitem action='ResetPan'/>"
  "			<menuitem action='ResetZoom'/>"
  "			<menuitem action='UpdateContinuously'/>"
  "		</menu>" "	</menubar>" "</ui>";


gboolean
imode_has_display_menu (InteractionMode imode)
{
  return (imode == SCALE || imode == BRUSH);
}

void
display_mode_menus_update (ProjectionMode pmode_prev,
                           InteractionMode imode_prev, displayd * display,
                           ggobid * gg)
{
  ProjectionMode pmode = display->cpanel.pmode;
  InteractionMode imode = display->cpanel.imode;
  const gchar *ui = NULL;
  GError *error = NULL;

  if (imode != imode_prev) {
    /* Remove any existing imode submenu */
    if (imode_has_display_menu (imode_prev)) {
      gtk_ui_manager_remove_ui (display->menu_manager,
                                display->imode_merge_id);
      /* I don't understand why all these tests are necessary ... dfs */
      /*if (GTK_IS_MENU_ITEM(display->imode_item))
         gtk_menu_item_remove_submenu (GTK_MENU_ITEM (display->imode_item));
         if (GTK_IS_WIDGET(display->imode_item))
         gtk_widget_destroy (display->imode_item);
         display->imode_item = NULL; */
    }

    /* If the new mode has an imode menu, build it */
    if (imode_has_display_menu (imode)) {
      if (imode == BRUSH) {
        ui = brush_imode_ui;
      }
      else if (imode == SCALE) {
        ui = scale_imode_ui;
      }

      if (ui)
        display->imode_merge_id =
          gtk_ui_manager_add_ui_from_string (display->menu_manager, ui, -1,
                                             &error);
      if (ui == NULL || error) {
        g_message ("Failed to load display imode ui!\n");
        g_error_free (error);
      }

    }
  }

  /* I'm not completely certain I have the correct test here */
  if (pmode != pmode_prev && imode == DEFAULT_IMODE) {

    /* Remove any existing pmode submenu */
    if (pmode_has_display_menu (pmode_prev) && display->pmode_merge_id) {
      gtk_ui_manager_remove_ui (display->menu_manager,
                                display->pmode_merge_id);
      /*gtk_menu_item_remove_submenu (GTK_MENU_ITEM (display->pmode_item));
         gtk_widget_destroy (display->pmode_item);
         display->pmode_item = NULL; */
    }

    /* Do we need to be in the default imode for this?  I don't see
       why */

    /* If the new mode has a pmode menu, build it */
    if (pmode_has_display_menu (pmode)) {
      if (pmode == TOUR1D) {
        ui = tour1d_pmode_ui;
      }
      else if (pmode == TOUR2D) {
        ui = tour2d_pmode_ui;
      }
      else if (pmode == COTOUR) {
        ui = cotour_pmode_ui;
      }

      display->pmode_merge_id =
        gtk_ui_manager_add_ui_from_string (display->menu_manager, ui, -1,
                                           &error);
      if (error) {
        g_message ("Failed to load display pmode ui!\n");
        g_error_free (error);
      }


    }


  }

}