~ubuntu-branches/ubuntu/edgy/tilp/edgy

« back to all changes in this revision

Viewing changes to gtk/ctree.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien BLACHE
  • Date: 2002-04-22 14:08:55 UTC
  • Revision ID: james.westby@ubuntu.com-20020422140855-f2uqleap86io68xy
Tags: upstream-5.03
ImportĀ upstreamĀ versionĀ 5.03

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  tilp - a linking program for TI graphing calculators
 
2
 *  Copyright (C) 1999-2002  Romain Lievin
 
3
 *
 
4
 *  This program is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU General Public License as published by
 
6
 *  the Free Software Foundation; either version 2 of the License, or
 
7
 *  (at your option) any later version.
 
8
 *
 
9
 *  This program is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *  GNU General Public License for more details.
 
13
 *
 
14
 *  You should have received a copy of the GNU General Public License
 
15
 *  along with this program; if not, write to the Free Software
 
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
#include <gtk/gtk.h>
 
20
#include <stdio.h>
 
21
#include <string.h>
 
22
 
 
23
#include "struct.h"
 
24
#include "gstruct.h"
 
25
#include "defs.h"
 
26
#include "files.h"
 
27
#include "vars.h"
 
28
#include "gxpm.h"
 
29
#include "select.h"
 
30
 
 
31
/* 
 
32
   Note: callbacks are in gtk_tilp_cb.c 
 
33
*/
 
34
 
 
35
/* Load a TI font */
 
36
GdkFont* load_ti_font()
 
37
{
 
38
  GdkFont *font = NULL;
 
39
  
 
40
#if defined(__LINUX__)
 
41
  font = gdk_font_load("-lpg-tixx-calc-r-expanded--10-100-75-75-m-80-iso8859-1");
 
42
#elif defined(__WIN32__)
 
43
  /*
 
44
    Thank to Timothy Singer for her fonts. Timothy Singer is the developper 
 
45
    of FastLink, another linking program for Windows.
 
46
  */
 
47
  /*
 
48
    switch(options.lp.calc_type)
 
49
    {
 
50
    case CALC_TI82:
 
51
    case CALC_TI83:
 
52
    case CALC_TI83P:
 
53
    font = gdk_font_load("-*-Fastlink TI%2d83-normal-r-normal--*-13-*-*-m-*-iso8859-1");
 
54
    break;
 
55
    case CALC_TI85:
 
56
    case CALC_TI86:
 
57
    font = gdk_font_load("-*-Fastlink TI%2d86-normal-r-normal--*-13-*-*-m-*-iso8859-1");
 
58
    break;
 
59
    case CALC_TI89:
 
60
    case CALC_TI92:
 
61
    case CALC_TI92P:
 
62
    font = gdk_font_load("-*-Fastlink TI%2d89-normal-r-normal--*-13-*-*-m-*-iso8859-1");
 
63
    break;
 
64
    }
 
65
  */
 
66
#endif
 
67
 
 
68
  return font;
 
69
}
 
70
 
 
71
 
 
72
/* Refresh the ctree */
 
73
void refresh_ctree()
 
74
{
 
75
  GdkPixmap *pixmap1, *pixmap2, *pixmap3, *pixmap4; 
 
76
  GdkPixmap *pixmap5, *pixmap6, *pixmap7;
 
77
  GdkBitmap *mask1, *mask2, *mask3, *mask4;
 
78
  GdkBitmap *mask5, *mask6, *mask7;
 
79
  GtkCTreeNode *vars_node = NULL;
 
80
  GtkCTreeNode *apps_node = NULL;
 
81
  GtkCTreeNode *parent_node = NULL;
 
82
  GtkCTreeNode *child_node = NULL;
 
83
  GtkStyle *style;
 
84
  GdkFont *font;
 
85
  GList *p;
 
86
  struct varinfo *q;
 
87
  gchar *tab[4] = { 0 };
 
88
  int i;
 
89
  gchar *prev_app = g_strdup("");
 
90
 
 
91
  gchar *vars[] = { N_("Variables"), N_(""), N_(""), N_("") };
 
92
  gchar *apps[] = { N_("Applications"), N_(""), N_(""), N_("") };
 
93
 
 
94
  // Load font
 
95
  tab[1]=NULL;    
 
96
  style = gtk_style_copy(GTK_WIDGET(ctree_wnd)->style);
 
97
  font = load_ti_font();
 
98
  if(font != NULL)
 
99
    style->font = font;
 
100
  else
 
101
    DISPLAY(_("** Warning: unable to load the 'tifont' font. Use default font instead.\n"));  
 
102
 
 
103
  // Sort variables
 
104
  switch(options.ctree_sort)
 
105
    {
 
106
    case SORT_BY_NAME:
 
107
      sort_cfiles_by_name(ctree_win.varlist);
 
108
      break;
 
109
    case SORT_BY_INFO:
 
110
      sort_cfiles_by_info(ctree_win.varlist);
 
111
      break;
 
112
    case SORT_BY_TYPE:
 
113
      sort_cfiles_by_type(ctree_win.varlist);
 
114
      break;
 
115
    case SORT_BY_SIZE:
 
116
      sort_cfiles_by_size(ctree_win.varlist);
 
117
      break;
 
118
    }
 
119
 
 
120
  gtk_clist_freeze(GTK_CLIST (ctree_wnd));
 
121
  gtk_clist_clear(GTK_CLIST (ctree_wnd));
 
122
  gtk_widget_realize(main_wnd);
 
123
 
 
124
  // Load pixmaps
 
125
  open_xpm("dir_closed.xpm",         main_wnd, &pixmap1, &mask1);
 
126
  open_xpm("dir_opened.xpm",         main_wnd, &pixmap3, &mask3);
 
127
  open_xpm("doc.xpm",           main_wnd, &pixmap2, &mask2);
 
128
  open_xpm("locked.xpm",        main_wnd, &pixmap4, &mask4);
 
129
  open_xpm("archived.xpm",      main_wnd, &pixmap5, &mask5);
 
130
  open_xpm("screen_mini.xpm",   main_wnd, &pixmap6, &mask6);
 
131
  open_xpm("keyboard_mini.xpm", main_wnd, &pixmap7, &mask7);
 
132
 
 
133
  // Variables
 
134
  vars_node=gtk_ctree_insert_node (GTK_CTREE (ctree_wnd), NULL, NULL, vars, 
 
135
                                   5, pixmap1, mask1, pixmap2, mask2, 
 
136
                                   FALSE, TRUE);
 
137
  gtk_ctree_node_set_row_data (GTK_CTREE(ctree_wnd), vars_node, 
 
138
                               (gpointer)NULL);
 
139
  gtk_ctree_node_set_selectable(GTK_CTREE(ctree_wnd), vars_node, 0);
 
140
 
 
141
  // Applications
 
142
  apps_node=gtk_ctree_insert_node (GTK_CTREE (ctree_wnd), NULL, NULL, apps, 
 
143
                                   5, pixmap1, mask1, pixmap2, mask2, 
 
144
                                   FALSE, TRUE);
 
145
  gtk_ctree_node_set_row_data (GTK_CTREE(ctree_wnd), apps_node, 
 
146
                               (gpointer)NULL);
 
147
  gtk_ctree_node_set_selectable(GTK_CTREE(ctree_wnd), apps_node, 0);
 
148
  
 
149
  // Variables tree
 
150
  p=ctree_win.varlist;
 
151
  parent_node = vars_node;
 
152
  while(p != NULL)
 
153
    {
 
154
      q=(struct varinfo *)(p->data);
 
155
 
 
156
      /* Skip varnames with FLASH apps */
 
157
      if(q->vartype ==  ticalc_flash_type(options.lp.calc_type))
 
158
        {
 
159
          p=p->next;
 
160
          continue;
 
161
        }
 
162
      tab[0] = g_strdup(q->translate);
 
163
      if(q->is_folder == FOLDER)
 
164
        {
 
165
          tab[2]=NULL;
 
166
          tab[3]=NULL;
 
167
          parent_node=gtk_ctree_insert_node (GTK_CTREE (ctree_wnd), vars_node,
 
168
                                             NULL, tab, 5, 
 
169
                                             pixmap1, mask1, pixmap3, mask3, 
 
170
                                             FALSE, TRUE);
 
171
          gtk_ctree_node_set_row_data (GTK_CTREE(ctree_wnd), parent_node, 
 
172
                                       (gpointer)q);
 
173
          gtk_ctree_node_set_selectable(GTK_CTREE(ctree_wnd), parent_node, 0);
 
174
        }
 
175
      else
 
176
        {
 
177
          tab[2] = g_strdup_printf("%s", ti_calc.byte2type(q->vartype));
 
178
          tab[3] = g_strdup_printf("%u", (int)(q->varsize));
 
179
          child_node=gtk_ctree_insert_node(GTK_CTREE (ctree_wnd), parent_node,
 
180
                                           NULL, tab, 5, 
 
181
                                           pixmap1, mask1, pixmap2, mask2, 
 
182
                                           FALSE, TRUE);
 
183
          switch(q->varattr)
 
184
            {
 
185
            case VARATTR_LOCK:
 
186
              gtk_ctree_node_set_pixmap(GTK_CTREE (ctree_wnd), 
 
187
                                        child_node, 1, pixmap4, mask4);
 
188
              break;
 
189
            case VARATTR_ARCH:
 
190
              gtk_ctree_node_set_pixmap(GTK_CTREE (ctree_wnd), 
 
191
                                        child_node, 1, pixmap5, mask5);
 
192
              break;
 
193
            }
 
194
          gtk_ctree_node_set_row_data (GTK_CTREE(ctree_wnd), 
 
195
                                       child_node, (gpointer)q);
 
196
          gtk_ctree_node_set_cell_style(GTK_CTREE(ctree_wnd), 
 
197
                                        child_node, 0, style);
 
198
        }
 
199
      
 
200
      p = p->next;
 
201
      for(i=0; i<4; i++) g_free(tab[i]);
 
202
    }
 
203
 
 
204
  // Applications tree
 
205
  p=ctree_win.varlist;
 
206
  parent_node=apps_node;
 
207
  while(p != NULL)
 
208
    {
 
209
      q=(struct varinfo *)(p->data);
 
210
 
 
211
      /* Skip varnames which are not FLASH apps */
 
212
      if(q->vartype != ticalc_flash_type(options.lp.calc_type))
 
213
        {
 
214
          p=p->next;
 
215
          continue;
 
216
        }
 
217
      if(!strcmp(q->translate, prev_app))
 
218
        {
 
219
          p=p->next;
 
220
          continue;
 
221
        }
 
222
 
 
223
      tab[0] = g_strdup(q->translate);
 
224
      g_free(prev_app); prev_app = g_strdup(q->translate);
 
225
 
 
226
      tab[2] = g_strdup_printf("%s", ti_calc.byte2type(q->vartype));
 
227
      tab[3] = g_strdup_printf("%u", (int)(q->varsize));
 
228
      child_node=gtk_ctree_insert_node(GTK_CTREE (ctree_wnd), parent_node,
 
229
                                       NULL, tab, 5, 
 
230
                                       pixmap1, mask1, pixmap2, mask2, 
 
231
                                       FALSE, TRUE);
 
232
      switch(q->varattr)
 
233
        {
 
234
        case VARATTR_LOCK:
 
235
          gtk_ctree_node_set_pixmap(GTK_CTREE (ctree_wnd), 
 
236
                                    child_node, 1, pixmap4, mask4);
 
237
          break;
 
238
        case VARATTR_ARCH:
 
239
          gtk_ctree_node_set_pixmap(GTK_CTREE (ctree_wnd), 
 
240
                                    child_node, 1, pixmap5, mask5);
 
241
          break;
 
242
        }
 
243
      gtk_ctree_node_set_row_data (GTK_CTREE(ctree_wnd), 
 
244
                                   child_node, (gpointer)q);
 
245
      gtk_ctree_node_set_cell_style(GTK_CTREE(ctree_wnd), 
 
246
                                    child_node, 0, style);
 
247
      
 
248
      p = p->next;
 
249
      for(i=0; i<4; i++) g_free(tab[i]);
 
250
    }
 
251
  
 
252
  gdk_pixmap_unref(pixmap1);
 
253
  gdk_pixmap_unref(pixmap2);
 
254
  gdk_pixmap_unref(pixmap3);
 
255
  gdk_pixmap_unref(pixmap4);
 
256
  gdk_pixmap_unref(pixmap5);
 
257
 
 
258
  gtk_clist_thaw(GTK_CLIST (ctree_wnd));
 
259
}
 
260
 
 
261
 
 
262
/* Refresh the selection of the ctree window */
 
263
void ctree_selection_refresh(void)
 
264
{
 
265
  GList *p;
 
266
  gint row;
 
267
  GList *s1, *s2;
 
268
  
 
269
  s1 = g_list_copy(ctree_win.selection);
 
270
  s2 = g_list_copy(ctree_win.selection2);
 
271
  /*
 
272
  DISPLAY("ctree_selection_refresh\n");
 
273
  for(i=0; i<g_list_length(s1); i++)
 
274
    {
 
275
      p = g_list_nth(ctree_win.selection, i);
 
276
      DISPLAY("varname=%s\n", ((VariableInfo *)(p->data))->varname);
 
277
      DISPLAY("%p %p %p\n", p->prev, p->data, p->next);
 
278
    }
 
279
  */
 
280
  if(ctree_wnd == NULL)  return;
 
281
  gtk_clist_unselect_all(GTK_CLIST(ctree_wnd));
 
282
  ctree_selection_destroy();
 
283
 
 
284
  // Variables
 
285
  p = s1;
 
286
  while(p != NULL)
 
287
    {
 
288
      row=gtk_clist_find_row_from_data(GTK_CLIST (ctree_wnd), p->data);
 
289
      
 
290
      if(row == -1)
 
291
        {
 
292
          fprintf(stderr, "Context debugging:\n");
 
293
          fprintf(stderr, "Filename: %s\n", ((struct file_info *)(p->data))->filename);
 
294
          fprintf(stderr, "Selection error: please report this bug.\n");
 
295
        }
 
296
      gtk_clist_select_row(GTK_CLIST (ctree_wnd), row, 1);
 
297
      
 
298
      p = g_list_next(p);
 
299
    }
 
300
 
 
301
  // Applications
 
302
  p = s2;
 
303
  while(p != NULL)
 
304
    {
 
305
      row=gtk_clist_find_row_from_data(GTK_CLIST (ctree_wnd), p->data);
 
306
      if(row == -1)
 
307
        {
 
308
          fprintf(stderr, "Context debugging:\n");
 
309
          fprintf(stderr, "Filename: %s\n", ((struct file_info *)(p->data))->filename);
 
310
          fprintf(stderr, "Selection error: please report this bug.\n");
 
311
        }
 
312
      gtk_clist_select_row(GTK_CLIST (ctree_wnd), row, 1);
 
313
      
 
314
      p = g_list_next(p);
 
315
    }
 
316
 
 
317
  return;
 
318
}
 
319
 
 
320