File: callbacks.c

package info (click to toggle)
xbmbrowser 5.1-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 420 kB
  • ctags: 343
  • sloc: ansic: 2,550; sed: 347; sh: 108; makefile: 46
file content (277 lines) | stat: -rw-r--r-- 8,367 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/****************************************************************************
** FILE: callbacks.c
**
** xbmbrowser is Public Domain. However it, and all the code still belong to me.
** I do, however grant permission for you to freely copy and distribute it on 
** the condition that this and all other copyright notices remain unchanged in 
** all distributions.
**
** This software comes with NO warranty whatsoever. I therefore take no
** responsibility for any damages, losses or problems that the program may 
** cause.
**                                     Anthony Thyssen and Ashley Roll
*****************************************************************************
*/

#include "xbmbrowser.h"

void 
set_name(widget, event)
/* This function is added to the notify callback on all the 
** menuButtons so that the global 'bitmap_info' contains the most 
** reciently selected bitmap information line. This is then used
** in  popup_user_menu() when a menu is requested to set the other
** information about the file the pointed to widget represents.
*/
  Widget   widget;
  XEvent  *event;
{
  current_item = (Item *)GetInfoPtr( widget );
  XtVaSetValues( label, XtNlabel, (XtPointer)current_item->info, NULL );
}


void 
set_label(widget, event)
/* As the pointer leaves a window -- set the label widget to point to
** file counts and/or some error string stored in the label_info string.
*/
  Widget    widget;
  XEvent   *event;
{
  XtVaSetValues(label, XtNlabel, (XtArgVal)label_info, NULL);
  /* current_item = NULL; */
}


void 
rescan(widget, client_data, call_data )
/* User pressed the rescan button -- so do it
** NOTE: no arguments used
*/
  Widget    widget;
  XtPointer client_data, call_data;
{
  set_busywait();
  rescan_images();
  clear_busywait();
}


void 
scan(widget, client_data, call_data )
/* User pressed the scan button -- so do it
** NOTE: no arguments used
*/
  Widget    widget;
  XtPointer client_data, call_data;
{
  set_busywait();
  scan_images();
  clear_busywait();
}


void 
dir_return(widget, event)
/* Event:- User pressed return in directory widget.
** Try to change directory to the dirwidget contents
** NOTE: Arguments not used.
*/
  Widget     widget;
  XEvent    *event;
{
  set_busywait();
  change_dir( XawDialogGetValueString(dirwidget) );
  clear_busywait();
}


void 
dir_menu(widget, client_data, call_data )
/* User selected a directory from the directory menu.
** Try to change dir to item selected by the user.
** NOTE: List widget call back data required.
*/
  Widget    widget;
  XtPointer client_data, call_data;
{
  XawListReturnStruct *dir = (XawListReturnStruct *)call_data;

  set_busywait();
  change_dir( dir->string );
  clear_busywait();
}


void
pos_dir(widget, event)
/* Event:- User is tring to popup directory menu.
** This procedure positions the menu under the cursour
*/
  Widget        widget;
  XButtonEvent *event;
{
  Position w;

  XtVaGetValues(dirmenu, XtNwidth, &w, NULL);
  XtVaSetValues(dirmenu, XtNx, event->x_root - w/2,
                         XtNy, event->y_root, NULL);
}


void
toggle_option(widget, client_data, call_data )
/* toggle the options in the options menu.
** NOTE: the client data is a pointer to the Boolean value which
** is to be toggled.
*/
  Widget     widget;
  XtPointer  client_data, call_data;
{
  Boolean *value = client_data;

  set_busywait();

  *value = !*value;  /* toggle the user option */
  XtVaSetValues(widget, XtNleftBitmap, *value ? tickon : tickoff, NULL);

  if ( value == &app_data.solid_bgnd )
    set_stipple();             /* Add or remove the stipple pattern */

  if (   value == &app_data.shape_syms
      || value == &app_data.solid_bgnd ) 
    redisplay_images(False);   /* Display style change -- FAST (dont unmap) */
  else
  if (   value == &app_data.label_all
      || value == &app_data.label_icons
      || value == &app_data.label_syms )
    redisplay_images(True);    /* Display style change -- FAST (with unmap) */
  else
  if ( value == &app_data.recursive )
    rescan_images();           /* Rescan directory and merge in changes */
  else
  /* if ( vaule == &app_data.show_{...} ) */
    reassign_images();         /* just reassign -- dont re-read directory */

  clear_busywait();
}


void
popup_user_menu(widget, event)
/* Initialize the substitution variables, figure out which menu is
** to be popped up, and if required popup the user defined menu.
** or other action required by the situation.
**
** NOTE: This routine must be registered with XtRegisterGrabAction()
** for it to work properly. See final note on the MenuButton widget
** in the Xaw Interface Guide.     --- Anthony Thyssen   2 May 1994
*/
  Widget        widget;
  XButtonEvent  *event;  /* this may client data */
{
  Widget         popup_menu = NULL;   /* menu to position and popup */

  /* Assume that no item has been selected */ 
  file_name[0] = '\0';
  base_name[0] = '\0';
  suffix[0]    = '\0';

  if ( widget == mainmenu ) {
    /* User pushed the main menu button */
    popup_menu = menu_main;
  }
  else if ( widget == iconbox && (event->subwindow == None) ) {
    /* Button press inside the icon box itself (NOT a icon)
    ** NOTE: the test for subwindow insurse that we really are in the
    ** iconbox window and not a sub-window of iconbox EG: a dispayed icon
    ** or symbol. This is needed because XtRegisterGrabAction() is searched
    ** from the top down and not the bottom up.
    */
    popup_menu = menu_global;
  }
  else if ( current_item != NULL ) {
    /* OK button press was within a displayed icon or symbol
    ** So grab the file name being represented by that widget
    */
    strcpy(file_name, current_item->fname ); 
    
    switch( event->button ) {
    case Button1:
      if ( IsDirItem(current_item) ) {
        /* CD into the directory selected */
	set_busywait();
	change_dir(file_name);   /* WARNING: change_dir() modifies string */
	clear_busywait();        /*          do not pass item->fname direct */
	return;          /* done -- don't continue */
      } /* fall through if NOT a directory */
    case Button2:
      /* popup global menu */
      popup_menu = menu_global;
      break;
    case Button3:
    case Button4:
    case Button5:
      /* popup appropiate menu for the file type */
      switch( current_item->type ) {
      case Xbm:     popup_menu = menu_bitmap;    break;
      case Xpm:
      case XpmBad:  popup_menu = menu_pixmap;    break;
      case Dir:
      case DirUp:
      case DirLink:
      case DirBad:  popup_menu = menu_directory; break;
      default:      popup_menu = menu_other;     break;
      }
    }
  }

  /* Menu Determined -- Do the popup */
  if( popup_menu != NULL ) {
    char      *s;    /* where the suffix starts in file_name */

    /* now complete the substitution list if file_name set */
    if ( file_name[0] != '\0' ) {
      /* extract the basename and suffix of the filename */
      s = rindex(file_name, '.');   /* find split point */
      if ( s == file_name || s == NULL ) {  
	/* The suffix is the whole filename OR non-existant */
	strcpy(base_name, file_name);  /* base_name = file_name */
	suffix[0] = '\0';              /* suffix = "" */
      } else {
	/* A valid split point was found -- split file_name */
	int len = s - file_name;
	strncpy(base_name, file_name,  len );  /* base_name is upto suffix */
	base_name[len] = '\0';
	strcpy(suffix, s);                   /* suffix (includes `.') */
      }
    }

    /* width is invalid unless realised -- so do so */
    XtRealizeWidget(popup_menu);

    /* position the menu as appropriate */
    if ( XtIsSubclass( widget, commandWidgetClass ) ) {
      /* Position under the button pushed -- no event given */
      Position    x, y, h;
      XtVaGetValues(widget, XtNheight, &h, NULL);
      XtTranslateCoords(widget, 0, h+2, &x, &y );
      XtVaSetValues(popup_menu, XtNx, x, XtNy, y, NULL);
    }
    else {
      /* Position relative to the users pointer */
      Dimension   w;    /* width of this menu */
      XtVaGetValues(popup_menu, XtNwidth, &w, NULL); /* get width */
      XtVaSetValues(popup_menu, XtNx, event->x_root - w/2,
				XtNy, event->y_root, NULL);
    } 
    /* OK now popup the menu -- and let user-menu take it from here */
    XtPopupSpringLoaded(popup_menu);

  } else {
    /* no menu found -- beep user */
    XBell( event->display, 0 );
  }
}