File: X11toggle.c

package info (click to toggle)
xlispstat 3.52.14-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,560 kB
  • ctags: 12,676
  • sloc: ansic: 91,357; lisp: 21,759; sh: 1,525; makefile: 521; csh: 1
file content (168 lines) | stat: -rw-r--r-- 5,149 bytes parent folder | download | duplicates (3)
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
/* X11toggle - toggle items for X11 dialogs                            */
/* XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney                  */
/* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz    */
/* You may give out copies of this software; for conditions see the    */
/* file COPYING included with this distribution.                       */
 
/***********************************************************************/
/**                                                                   **/
/**                    General Includes and Definitions               **/
/**                                                                   **/
/***********************************************************************/

#include "dialogs.h"

extern Display *StX11Display();
extern Point DialogStringSize();
extern LVAL StX11ItemObject();
extern char *checkstring();
extern LVAL s_window_id;

typedef struct {
  unsigned long fore, back;
} ColorPair;

/* layout defines */
# define TOGGLE_PAD 20
# define TOGGLE_MARK_HEIGHT 16

/***********************************************************************/
/**                                                                   **/
/**                        Global Variables                           **/
/**                                                                   **/
/***********************************************************************/

/* configuration parameters - should be set using the defaults database */
extern XFontStruct *DialogFont;
extern unsigned long DialogBorderColor;
extern ColorPair DialogC;
extern unsigned int dialog_border_width;
extern int min_toggle_height;

extern GC DialogGC, DialogRGC;

extern XContext ObjectContext;

extern Pixmap ToggleOffPM, ToggleOnPM;

/***********************************************************************/
/**                                                                   **/
/**                         Toggle Items                              **/
/**                                                                   **/
/***********************************************************************/

static VOID draw_toggle(dpy, win, item)
     Display *dpy;
     Window win;
     LVAL item;
{
  char *text;
  int x, y, len, ascent, on;
  Pixmap mark;

  ascent = DialogFont->max_bounds.ascent;

  text = checkstring(slot_value(item, s_text));
  on = (slot_value(item, s_value) != NIL) ? TRUE : FALSE;
  mark = (on) ? ToggleOnPM : ToggleOffPM;
  XCopyPlane(dpy, mark, win, DialogGC, 
	     0, 0, TOGGLE_MARK_HEIGHT, TOGGLE_MARK_HEIGHT,
	     0, max(0, ascent - TOGGLE_MARK_HEIGHT), 1);
  x = TOGGLE_PAD;
  y = max(TOGGLE_MARK_HEIGHT, ascent);
  len = strlen(text);
  XDrawString(dpy, win, DialogGC, x, y, text, len);
}
  
static LVAL toggle_handler(report, modal)
     XEvent report;
     int modal;
{
  Display *dpy = StX11Display();
  Window win;
  LVAL item;
  LVAL result = NIL;

  win = report.xany.window;
  item = StX11ItemObject(dpy, win);
  if (item != NIL) {
    switch (report.type) {
    case Expose:
      draw_toggle(dpy, win, item);
      break;
    case ButtonPress:
      set_slot_value(item, s_value, 
		     (slot_value(item, s_value) != NIL) ? NIL : s_true);
      draw_toggle(dpy, win, item);
      if (! modal) send_message(item, sk_do_action);
      break;
    case ButtonRelease:
      break;
    default: 
      break;
    }
  }
  return(result);
}

VOID InstallToggleItem(win, item)
     Window win;
     LVAL item;
{
  Display *dpy = StX11Display();
  Point loc, size;
  Window toggle;

  loc = ListToPoint(slot_value(item, s_location));
  size = ListToPoint(slot_value(item, s_size));
  toggle = XCreateSimpleWindow(dpy, win, loc.h, loc.v, size.h, size.v,
			       0, DialogBorderColor, DialogC.back);
  XSelectInput(dpy, toggle, 
	       ExposureMask | ButtonPressMask | ButtonReleaseMask);

  set_slot_value(item, s_window_id, cvfixnum((FIXTYPE) toggle));

  install_dialog_item_handler(dpy, toggle, toggle_handler, item);
  if (XSaveContext(dpy, toggle, ObjectContext, (caddr_t) item) != 0)
    xlfail("could not install object in window");
}

VOID DeleteToggleItem(win, item)
     Window win;
     LVAL item;
{
  Display *dpy = StX11Display();
  Window toggle;

  toggle = (Window) getfixnum(slot_value(item, s_window_id));

  delete_dialog_item_handler(dpy, toggle);
  if (XDeleteContext(dpy, toggle, ObjectContext) != 0)
    xlfail("could not delete object context");
  set_slot_value(item, s_window_id, NIL);
}

VOID DialogToggleGetDefaultSize(item, width, height)
     LVAL item;
     int *width, *height;
{
  Point sz;
  sz = DialogStringSize(checkstring(slot_value(item, s_text)));
  if (width != NULL) *width = sz.h + TOGGLE_PAD;
  if (height != NULL) *height = max(sz.v, min_toggle_height);
}

LVAL DialogToggleItemValue(item, set, value)
     LVAL item, value;
     int set;
{
  Display *dpy = StX11Display();
  LVAL win_id;

  if (set) {
    set_slot_value(item, s_value, (value != NIL) ? s_true : NIL);
    win_id = slot_value(item, s_window_id);
    if (fixp(win_id)) draw_toggle(dpy, (Window) getfixnum(win_id), item);
  }
  return(slot_value(item, s_value));
}