File: utils2_c

package info (click to toggle)
xmorph 1%3A20150712-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,404 kB
  • sloc: ansic: 24,887; sh: 7,755; cpp: 1,231; makefile: 524; sed: 16
file content (156 lines) | stat: -rw-r--r-- 3,218 bytes parent folder | download | duplicates (9)
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


gchar * compute_title (int j)
{
  if(sp->im_widget_is_difference_mesh[j] ) {
    const gchar * R = _("differential mesh");
    gchar  *N;
    if(sp->im_mesh_filename[j] ) 
      N=g_strdup_printf("%s %d '%s'",R,j,sp->im_mesh_filename[j]);
    else
      N=g_strdup_printf("%s %d",R,j);
    return N;
  } else {
    const gchar * R = _("resulting image");
    gchar *I = R, *N;
    if(j != MAIN_WIN)
	/* warning: due to main.c:144 , this _("input image") will always
	   be translated using a UTF-8 locale, regardless of the real LANG setting */
      I = g_strdup_printf("%s %d",_("input image"),j);
    if(sp->im_filename_in[j] ) 
      N=g_strdup_printf("%s '%s'",I, sp->im_filename_in[j]);
    else
      N=g_strdup(I);
    if (I!=R) g_free(I);
    return N;
  }  
}




/*********************** 
			 some commonly used routines 
********************** 
*/



void set_sensitive(GtkWidget * widget, gboolean flag)
{
  if(flag) {
    gtk_widget_show(widget);  
    gtk_widget_set_sensitive(widget,flag);
  } else {
    if(settings_get_value("hide unusable"))
      {
      	gtk_widget_hide(widget);
      }
    else {
      gtk_widget_show(widget);  
      gtk_widget_set_sensitive(widget,flag);
    }
  }
}


void set_info_label(gchar *t)
{
  static GtkWidget *m=NULL;
  if(!m) m=lookup_widget(sp->im_widget[MAIN_WIN],"main_info_label");
  if(m) {
    gtk_label_set_text(m,t);
  } 
}







/* linking callbacks to optionmenu does not work...
  this comes from the glade FAQ */
void
on_optionmenu_editview__selected (GtkMenuShell *menu_shell,
                    gpointer data)
{
  GtkWidget *active_item;
  gint item_index;

  /* the following fails: the menu_shell has a different window
    int i=
    GPOINTER_TO_UINT(gtk_widget_get_data_top(GTK_WIDGET(data),
					     "imagenum")); 
  */
  int i=
    GPOINTER_TO_UINT(data);
  g_assert(i>0);

  active_item = gtk_menu_get_active (GTK_MENU (menu_shell));
  item_index = g_list_index (menu_shell->children, active_item);

  /* thanks GOD this works!!
    g_print ("In on_option_selected active: %i\n", item_index);*/
  sp->im_editview[i]=item_index;

  g_debug("on_optionmenu_editview__selected %d is now %d ",i,item_index);

  editview_callback(i);
#ifndef IS_PLYMORPH
  drawingarea_configure(i);
#endif
  MY_GTK_DRAW(sp->im_widget[i]);
}













/************************************


setup_handlebox_factors()

if there is only one image , then we may only warp it
so the handlebox is hidden

otherwise if in showmeshes mode, they are shown,
and the user may set the factors and warp the image

***********************************/
void
setup_handlebox_factor(int lp,int force)
{
#ifndef IS_PLYMORPH
  if(sp->im_widget_is_difference_mesh[lp]) return;
#endif
  GtkWidget* hb= lookup_widget  ( sp->im_widget[lp]  ,
				  "handlebox_factors");
  g_assert(hb);
  // these are really to be hidden!
  //set_sensitive(hb,( sp->max_wins>1 
  //		     && (sp->im_editview[lp] == EDITVIEW_SHOWMESHES  
			 // ||sp->im_editview[lp] == EDITVIEW_SHOW)
  //		     )));
  //return ;
  if(  sp->max_wins>1 && (force 
#ifndef IS_PLYMORPH
			  || sp->im_editview[lp] == EDITVIEW_SHOWMESHES
#endif
			  ))
    gtk_widget_show(hb);
  else
    gtk_widget_hide(hb);
}