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
|
/*======================================================================*/
/*= CHANGES AND UPDATES =*/
/*======================================================================*/
/*= date person file subject =*/
/*=--------------------------------------------------------------------=*/
/*= =*/
/*= 060794 hua multi_dial.hc created =*/
/*= =*/
/*======================================================================*/
#include "multi_dial.h"
#include "masks.h"
#define font "-misc-*-*-*-*-*-*-*-*-*-*-*-*-*"
#define line_dy 20
multi_dial::multi_dial (char name [],
char buttons [],
bool used_history)
{init;
pharse_params;
open_w;
init_values;
perhaps_load;
open_dials;
. init
{is_history = used_history;
strcpy (title, name);
}.
. init_values
{for (int i = 0; i < num_buttons; i++)
values [i] = true;
}.
. perhaps_load
{if (is_history)
load (name);
}.
. open_w
{w = new win (title, "", by_fix, by_fix,
max_b_title_dx + 44,
num_buttons * line_dy + 24);
background (w);
}.
. open_dials
{for (int i = 0; i < num_buttons; i++)
d_buttons [i] = new dial (w,
b_title [i],
max_b_title_dx + 12,
12, i * line_dy + 14,
values [i]);
}.
. pharse_params
{int p = 0;
XFontStruct *font_info;
Display *display;
num_buttons = 0;
max_b_title_dx = 0;
open_font_info;
while (get_cmd (buttons, p, act_title))
{grab_button;
};
close_font_info;
}.
. open_font_info
{char name [128];
strcpy (name, getenv ("DISPLAY"));
display = XOpenDisplay (name);
font_info = XLoadQueryFont (display, font);
}.
. close_font_info
{XFreeFont (display, font_info);
XCloseDisplay (display);
}.
. grab_button
{max_b_title_dx = i_max (max_b_title_dx, title_length);
num_buttons++;
}.
. title_length
XTextWidth (font_info, act_title, strlen (act_title)).
. act_title
b_title [num_buttons].
}
multi_dial::~multi_dial ()
{if (is_history)
save (title);
for (int i = 0; i < num_buttons; i++)
delete (d_buttons [i]);
delete (w);
}
void multi_dial::save (char name [])
{FILE *f;
open_f;
write_values;
fclose (f);
. open_f
{f = fopen (complete (name, ".mulopt"), "w");
}.
. write_values
{for (int i = 0; i < num_buttons; i++)
fprintf (f, "%d\n", values [i]);
}.
}
void multi_dial::load (char name [])
{FILE *f;
bool exists;
if (open_f)
perform_load;
. perform_load
{read_values;
fclose (f);
}.
. open_f
(f = fopen (complete (name, ".mulopt"), "r")) != NULL.
. read_values
{for (int i = 0; i < num_buttons; i++)
fscanf (f, "%d", &values [i]);
}.
}
bool multi_dial::eval ()
{bool anything = false;
w->mark_mouse ();
for (int i = 0; i < num_buttons; i++)
anything |= d_buttons [i]->eval (values [i]);
w->scratch_mouse ();
return anything;
}
bool multi_dial::pressed (int bno)
{return values [bno];
}
void multi_dial::press (int bno, bool mode)
{values [bno] = mode;
eval ();
}
bool multi_dial::get_cmd (char cmds [], int &p, char cmd [])
{if (eof)
return false;
else read_cmd;
return true;
. read_cmd
{int c = 0;
bool skip_mode = false;
skip_icon_symbol;
while (cmd_char != ':' && ! eof)
{handle_skip_mode;
store_char;
p++;
};
cmd [c] = 0;
p++;
}.
. handle_skip_mode
{if (cmd_char == ';')
switch_skip_mode;
}.
. store_char
{if (! skip_mode)
cmd [c++] = cmd_char;
}.
. switch_skip_mode
{skip_mode = ! skip_mode;
p++;
}.
. skip_icon_symbol
if (cmd_char == '$' || cmd_char == '&')
p++.
. eof
(p >= strlen (cmds)).
. cmd_char
cmds [p].
}
|