| 1 |
/* |
| 2 |
* Copyright (c) 2004 Stefan Ulrich |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 |
* of this software and associated documentation files (the "Software"), to |
| 6 |
* deal in the Software without restriction, including without limitation the |
| 7 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 8 |
* sell copies of the Software, and to permit persons to whom the Software is |
| 9 |
* furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included in |
| 12 |
* all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY CLAIM, |
| 18 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
* |
| 22 |
*/ |
| 23 |
|
| 24 |
/* |
| 25 |
* Color selector window showing a range of colors, and sliders to customize them. |
| 26 |
* Heavily influenced by color_slide.c from ch. 13 of O'Reilly's Motif Programming Manual 1.2. |
| 27 |
*/ |
| 28 |
|
| 29 |
#include "xdvi-config.h" |
| 30 |
#include "xdvi.h" |
| 31 |
|
| 32 |
#include "Tip.h" |
| 33 |
#include "x_util.h" |
| 34 |
#include "xm_colorsel.h" |
| 35 |
#include "xm_prefsP.h" |
| 36 |
#include "xm_prefs.h" |
| 37 |
#include "events.h" |
| 38 |
#include "dvi-draw.h" |
| 39 |
#include "util.h" |
| 40 |
#include "topic-window.h" |
| 41 |
#include "search-internal.h" |
| 42 |
|
| 43 |
#ifdef MOTIF /* entire file */ |
| 44 |
|
| 45 |
#include <X11/Xatom.h> |
| 46 |
|
| 47 |
#include <Xm/Xm.h> |
| 48 |
#include <Xm/Protocols.h> |
| 49 |
#include <Xm/DialogS.h> |
| 50 |
#include <Xm/LabelG.h> |
| 51 |
#include <Xm/PushB.h> |
| 52 |
#include <Xm/Form.h> |
| 53 |
#include <Xm/PanedW.h> |
| 54 |
#include <Xm/DrawnB.h> |
| 55 |
#include <Xm/RowColumn.h> |
| 56 |
#include <Xm/Scale.h> |
| 57 |
#include <Xm/SelectioB.h> |
| 58 |
# include <Xm/AtomMgr.h> |
| 59 |
|
| 60 |
#include <Xm/MwmUtil.h> |
| 61 |
|
| 62 |
#define ROWS 7 |
| 63 |
#define COLS 10 |
| 64 |
|
| 65 |
/* for passing around information - no global data here ;-) */ |
| 66 |
struct color_info { |
| 67 |
XColor new_color; |
| 68 |
Widget tooltip; |
| 69 |
Widget new_sample; |
| 70 |
Widget r_scale; |
| 71 |
Widget g_scale; |
| 72 |
Widget b_scale; |
| 73 |
struct color_button_info *button_info; |
| 74 |
}; |
| 75 |
|
| 76 |
/* |
| 77 |
* These are the colors of the GTK/Mozilla color picker |
| 78 |
* (see e.g. http://lxr.mozilla.org/mozilla/source/toolkit/content/widgets/colorpicker.xml) |
| 79 |
* which has the colors more or less sorted by columns. |
| 80 |
* It's terminated by NULL just in case the table gets out of sync with |
| 81 |
* the row/column number. |
| 82 |
*/ |
| 83 |
static const char *colors[] = { |
| 84 |
/* column 1 */ |
| 85 |
"#FFFFFF", "#CCCCCC", "#C0C0C0", "#999999", "#666666", "#333333", "#000000", |
| 86 |
/* column 2 */ |
| 87 |
"#FFCCCC", "#FF6666", "#FF0000", "#CC0000", "#990000", "#660000", "#330000", |
| 88 |
/* column 3 */ |
| 89 |
"#FFCC99", "#FF9966", "#FF9900", "#FF6600", "#CC6600", "#993300", "#663300", |
| 90 |
/* column 4 */ |
| 91 |
"#FFFF99", "#FFFF66", "#FFCC66", "#FFCC33", "#CC9933", "#996633", "#663333", |
| 92 |
/* column 5 */ |
| 93 |
"#FFFFCC", "#FFFF33", "#FFFF00", "#FFCC00", "#999900", "#666600", "#333300", |
| 94 |
/* column 6 */ |
| 95 |
"#99FF99", "#66FF99", "#33FF33", "#33CC00", "#009900", "#006600", "#003300", |
| 96 |
/* column 7 */ |
| 97 |
"#99FFFF", "#33FFFF", "#66CCCC", "#00CCCC", "#339999", "#336666", "#003333", |
| 98 |
/* column 8 */ |
| 99 |
"#CCFFFF", "#66FFFF", "#33CCFF", "#3366FF", "#3333FF", "#000099", "#000066", |
| 100 |
/* column 9 */ |
| 101 |
"#CCCCFF", "#9999FF", "#6666CC", "#6633FF", "#6600CC", "#333399", "#330099", |
| 102 |
/* column 10 */ |
| 103 |
"#FFCCFF", "#FF99FF", "#CC66CC", "#CC33CC", "#993399", "#663366", "#330033", |
| 104 |
/* safety */ |
| 105 |
NULL |
| 106 |
}; |
| 107 |
|
| 108 |
#define MOTIF 1 |
| 109 |
|
| 110 |
static void |
| 111 |
popdown_cb(Widget widget, XtPointer client_data, XtPointer call_data) |
| 112 |
{ |
| 113 |
Widget dialog; |
| 114 |
struct prefs_choice *prefs = (struct prefs_choice *)client_data; |
| 115 |
|
| 116 |
UNUSED(call_data); |
| 117 |
|
| 118 |
ASSERT(prefs != NULL, "user_data in popdown_cb musn't be NULL!"); |
| 119 |
if (get_widget_by_name(&dialog, widget, Xdvi_COLOR_DIALOG_NAME, True)) { |
| 120 |
/* fprintf(stderr, "popdown!\n"); */ |
| 121 |
remove_from_deplist(prefs, dialog); |
| 122 |
XtUnmanageChild(dialog); |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
static void |
| 127 |
h_update_sliders(struct color_info *cinfo) |
| 128 |
{ |
| 129 |
unsigned r, g, b; |
| 130 |
|
| 131 |
r = cinfo->new_color.red >> 8; |
| 132 |
g = cinfo->new_color.green >> 8; |
| 133 |
b = cinfo->new_color.blue >> 8; |
| 134 |
|
| 135 |
XtVaSetValues(cinfo->r_scale, XmNvalue, r, NULL); |
| 136 |
XtVaSetValues(cinfo->g_scale, XmNvalue, g, NULL); |
| 137 |
XtVaSetValues(cinfo->b_scale, XmNvalue, b, NULL); |
| 138 |
} |
| 139 |
|
| 140 |
static void |
| 141 |
popdown_apply_cb(Widget widget, XtPointer client_data, XtPointer call_data) |
| 142 |
{ |
| 143 |
struct color_info *cinfo = NULL; |
| 144 |
static XmDrawnButtonCallbackStruct cbs; |
| 145 |
struct prefs_choice *prefs = (struct prefs_choice *)client_data; |
| 146 |
|
| 147 |
UNUSED(call_data); |
| 148 |
ASSERT(prefs != NULL, "struct prefs_choice * in popdown_apply_cb mustn't be NULL!"); |
| 149 |
|
| 150 |
/* To update button to new color, set its button_info color |
| 151 |
and call the button's expose callback */ |
| 152 |
XtVaGetValues(widget, XmNuserData, &cinfo, NULL); |
| 153 |
ASSERT(cinfo != NULL, "XmNuserData in popdown_apply_cb musn't be NULL!"); |
| 154 |
cinfo->button_info->pixel = cinfo->new_color.pixel; |
| 155 |
|
| 156 |
cbs.reason = XmCR_EXPOSE; |
| 157 |
XtCallCallbacks(cinfo->button_info->w, XmNexposeCallback, &cbs); |
| 158 |
|
| 159 |
remove_from_deplist(prefs, widget); |
| 160 |
|
| 161 |
/* Store the current setting - |
| 162 |
FIXME: better way of converting color or pixel to string? pixel_to_str() in x_util.c is broken! */ |
| 163 |
store_preference(&(prefs->db), cinfo->button_info->resource_name, |
| 164 |
"#%.2x%.2x%.2x", |
| 165 |
cinfo->new_color.red >> 8, |
| 166 |
cinfo->new_color.green >> 8, |
| 167 |
cinfo->new_color.blue >> 8); |
| 168 |
|
| 169 |
/* Update the display to use the new foreground/background. |
| 170 |
* I don't really understand the entire color interface, but |
| 171 |
* apparently the following works, and nothing else I tried did ... */ |
| 172 |
if (strcmp(cinfo->button_info->resource_name, "foreground") == 0) { |
| 173 |
XGCValues values; |
| 174 |
|
| 175 |
fg_initial.r = cinfo->new_color.red; |
| 176 |
fg_initial.g = cinfo->new_color.green; |
| 177 |
fg_initial.b = cinfo->new_color.blue; |
| 178 |
|
| 179 |
values.foreground = resource.fore_Pixel = resource.rule_pixel = cinfo->new_color.pixel; |
| 180 |
XChangeGC(DISP, globals.gc.ruler, GCForeground, &values); |
| 181 |
|
| 182 |
scanned_page = scanned_page_color = scanned_page_reset; |
| 183 |
globals.ev.flags |= EV_NEWPAGE; |
| 184 |
|
| 185 |
} |
| 186 |
else if (strcmp(cinfo->button_info->resource_name, "background") == 0) { |
| 187 |
bg_initial.r = cinfo->new_color.red; |
| 188 |
bg_initial.g = cinfo->new_color.green; |
| 189 |
bg_initial.b = cinfo->new_color.blue; |
| 190 |
|
| 191 |
resource.back_Pixel = cinfo->new_color.pixel; |
| 192 |
scanned_page = scanned_page_color = scanned_page_reset; |
| 193 |
globals.ev.flags |= EV_RELOAD; /* EV_NEWPAGE not sufficient with color code ... */ |
| 194 |
} |
| 195 |
else if (strcmp(cinfo->button_info->resource_name, "highlight") == 0) { |
| 196 |
XGCValues values; |
| 197 |
values.foreground = resource.hl_Pixel = cinfo->new_color.pixel; |
| 198 |
XChangeGC(DISP, globals.gc.high, GCForeground, &values); |
| 199 |
/* hack to update match GC: fake change in inverted property, redraw |
| 200 |
so that GC is cleared, then change inverted property back */ |
| 201 |
resource.match_highlight_inverted = !resource.match_highlight_inverted; |
| 202 |
search_draw_inverted_regions(); |
| 203 |
resource.match_highlight_inverted = !resource.match_highlight_inverted; |
| 204 |
/* end of hack to update match GC */ |
| 205 |
globals.ev.flags |= EV_NEWPAGE; /* force redraw */ |
| 206 |
} |
| 207 |
|
| 208 |
XtUnmanageChild(widget); |
| 209 |
} |
| 210 |
|
| 211 |
static void |
| 212 |
popdown_cancel_cb(Widget widget, XtPointer client_data, XtPointer call_data) |
| 213 |
{ |
| 214 |
struct prefs_choice *prefs = (struct prefs_choice *)client_data; |
| 215 |
|
| 216 |
/* fprintf(stderr, "popdown cancel; call_data: %p!\n", call_data); */ |
| 217 |
if (call_data != NULL) { |
| 218 |
/* fprintf(stderr, "removing from deplist: %p!!!\n", prefs); */ |
| 219 |
remove_from_deplist(prefs, widget); |
| 220 |
} |
| 221 |
|
| 222 |
XtUnmanageChild(widget); |
| 223 |
/* XtPopdown(XtParent(widget)); */ |
| 224 |
} |
| 225 |
|
| 226 |
static void |
| 227 |
revert_color_cb(Widget widget, XtPointer client_data, XtPointer call_data) |
| 228 |
{ |
| 229 |
struct color_info *cinfo = (struct color_info *)client_data; |
| 230 |
Pixel pix; |
| 231 |
|
| 232 |
UNUSED(call_data); |
| 233 |
|
| 234 |
/* get color of old_sample button */ |
| 235 |
XtVaGetValues(widget, XmNbackground, &pix, NULL); |
| 236 |
/* fprintf(stderr, "Color: 0x%.6lx\n", pix); */ |
| 237 |
|
| 238 |
/* use this instead of XtVaSetValues on XmNbackground so that |
| 239 |
the foreground color gets also changed appropriately. */ |
| 240 |
#if XmVersion >= 1002 |
| 241 |
XmChangeColor(cinfo->new_sample, pix); |
| 242 |
#else |
| 243 |
XtVaSetValues(cinfo->new_sample, XmNbackground, pix, NULL); |
| 244 |
#endif |
| 245 |
|
| 246 |
/* update sliders */ |
| 247 |
XFreeColors(DISP, G_colormap, &(cinfo->new_color.pixel), 1, 0); |
| 248 |
pixel_to_color(pix, &(cinfo->new_color), DISP, G_colormap); |
| 249 |
h_update_sliders(cinfo); |
| 250 |
} |
| 251 |
|
| 252 |
static void |
| 253 |
show_color_cb(Widget widget, XtPointer client_data, XtPointer call_data) |
| 254 |
{ |
| 255 |
struct color_info *cinfo = (struct color_info *)client_data; |
| 256 |
Pixel pix; |
| 257 |
|
| 258 |
UNUSED(call_data); |
| 259 |
XtVaGetValues(widget, XmNbackground, &pix, NULL); |
| 260 |
/* fprintf(stderr, "Color: 0x%.6lx\n", pix); */ |
| 261 |
|
| 262 |
/* use this instead of XtVaSetValues on XmNbackground so that |
| 263 |
the foreground color gets also changed appropriately. */ |
| 264 |
#if XmVersion >= 1002 |
| 265 |
XmChangeColor(cinfo->new_sample, pix); |
| 266 |
#else |
| 267 |
XtVaSetValues(cinfo->new_sample, XmNbackground, pix, NULL); |
| 268 |
#endif |
| 269 |
|
| 270 |
/* update sliders */ |
| 271 |
XFreeColors(DISP, G_colormap, &(cinfo->new_color.pixel), 1, 0); |
| 272 |
pixel_to_color(pix, &(cinfo->new_color), DISP, G_colormap); |
| 273 |
h_update_sliders(cinfo); |
| 274 |
} |
| 275 |
|
| 276 |
static void |
| 277 |
slider_cb(Widget widget, XtPointer client_data, XtPointer call_data) |
| 278 |
{ |
| 279 |
struct color_info *cinfo = (struct color_info *)client_data; |
| 280 |
XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct *)call_data; |
| 281 |
|
| 282 |
/* fprintf(stderr, "Pixel1 : 0x%.6lx\n", cinfo->new_color.pixel); */ |
| 283 |
/* reuse cinfo->new_color */ |
| 284 |
XFreeColors(DISP, G_colormap, &(cinfo->new_color.pixel), 1, 0); |
| 285 |
|
| 286 |
if (widget == cinfo->r_scale) { |
| 287 |
cinfo->new_color.red = cbs->value << 8; /* << 8 == * 65535 */ |
| 288 |
} |
| 289 |
else if (widget == cinfo->g_scale) { |
| 290 |
cinfo->new_color.green = cbs->value << 8; |
| 291 |
} |
| 292 |
else if (widget == cinfo->b_scale) { |
| 293 |
cinfo->new_color.blue = cbs->value << 8; |
| 294 |
} |
| 295 |
|
| 296 |
if (!XAllocColor(DISP, G_colormap, &(cinfo->new_color))) { |
| 297 |
XDVI_ERROR((stderr, "Couldn't XAllocColor\n")); |
| 298 |
return; |
| 299 |
} |
| 300 |
/* fprintf(stderr, "Pixel: 0x%.6lx\n", cinfo->new_color.pixel); */ |
| 301 |
|
| 302 |
#if XmVersion >= 1002 |
| 303 |
/* if avaliable, use this so that the foreground color also |
| 304 |
gets updated appropriately: */ |
| 305 |
XmChangeColor(cinfo->new_sample, cinfo->new_color.pixel); |
| 306 |
#else |
| 307 |
XtVaSetValues(cinfo->new_sample, XmNbackground, cinfo->new_color.pixel, NULL); |
| 308 |
#endif |
| 309 |
} |
| 310 |
|
| 311 |
static Widget |
| 312 |
h_create_color_matrix(Widget parent, Widget top, struct color_info *cinfo) |
| 313 |
{ |
| 314 |
int i, j; |
| 315 |
const char **color_ptr = colors; |
| 316 |
|
| 317 |
Widget matrix = |
| 318 |
XtVaCreateManagedWidget("color_matrix", xmRowColumnWidgetClass, |
| 319 |
parent, |
| 320 |
XmNtopAttachment, XmATTACH_WIDGET, |
| 321 |
XmNtopWidget, top, |
| 322 |
XmNleftAttachment, XmATTACH_FORM, |
| 323 |
XmNrightAttachment, XmATTACH_FORM, |
| 324 |
XmNpacking, XmPACK_COLUMN, |
| 325 |
XmNnumColumns, COLS, |
| 326 |
XmNorientation, XmVERTICAL, |
| 327 |
XmNbackground, BlackPixelOfScreen(XtScreen(parent)), |
| 328 |
XmNspacing, 1, |
| 329 |
XmNmarginWidth, 1, |
| 330 |
XmNmarginHeight, 1, |
| 331 |
NULL); |
| 332 |
|
| 333 |
for (i = 0; i < ROWS; i++) { |
| 334 |
for (j = 0; j < COLS; j++) { |
| 335 |
Pixel pix = BlackPixelOfScreen(XtScreen(parent)); |
| 336 |
Widget button; |
| 337 |
if (*color_ptr == NULL) /* safety */ |
| 338 |
break; |
| 339 |
str_to_pixel(top, *color_ptr++, &pix); |
| 340 |
/* fprintf(stderr, "creating button %d, %d - %s\n", i, j, k % 2 ? "b" : "w"); */ |
| 341 |
button = XtVaCreateManagedWidget("c_button", xmDrawnButtonWidgetClass, |
| 342 |
matrix, |
| 343 |
XmNbackground, pix, |
| 344 |
XmNheight, 19, |
| 345 |
XmNwidth, 19, |
| 346 |
XmNmarginWidth, 0, |
| 347 |
XmNmarginHeight, 0, |
| 348 |
XmNhighlightThickness, 0, |
| 349 |
XmNshadowThickness, 0, |
| 350 |
NULL); |
| 351 |
XtAddCallback(button, XmNactivateCallback, show_color_cb, cinfo); |
| 352 |
} |
| 353 |
} |
| 354 |
return matrix; |
| 355 |
} |
| 356 |
|
| 357 |
static void |
| 358 |
h_create_sliders(Widget parent, Widget top, struct color_info *cinfo) |
| 359 |
{ |
| 360 |
XmString str; |
| 361 |
Widget r_label, g_label, b_label; |
| 362 |
Widget r_scale, g_scale, b_scale; |
| 363 |
Dimension curr, max; |
| 364 |
|
| 365 |
Arg scale_args[8]; |
| 366 |
Arg label_args[8]; |
| 367 |
int scale_n = 0; |
| 368 |
|
| 369 |
XtSetArg(scale_args[scale_n], XmNmaximum, 255); scale_n++; |
| 370 |
/* True is an older setting of XmNshowValue that should also work with 2.x */ |
| 371 |
XtSetArg(scale_args[scale_n], XmNshowValue, True); scale_n++; |
| 372 |
XtSetArg(scale_args[scale_n], XmNorientation, XmHORIZONTAL); scale_n++; |
| 373 |
#if XmVersion >= 2000 |
| 374 |
XtSetArg(scale_args[scale_n], XmNshowArrows, XmEACH_SIDE); scale_n++; |
| 375 |
/* XmVersion < 2000 only had `True' which was the default anyway */ |
| 376 |
#endif |
| 377 |
|
| 378 |
str = XmStringCreateLocalized("Red"); |
| 379 |
XtSetArg(label_args[0], XmNlabelString, str); |
| 380 |
r_label = XtCreateManagedWidget("r_label", xmLabelGadgetClass, parent, label_args, 1); |
| 381 |
XmStringFree(str); |
| 382 |
|
| 383 |
r_scale = XtCreateWidget("r_scale", xmScaleWidgetClass, parent, scale_args, scale_n); |
| 384 |
cinfo->r_scale = r_scale; |
| 385 |
XtAddCallback(r_scale, XmNdragCallback, slider_cb, cinfo); |
| 386 |
XtAddCallback(r_scale, XmNvalueChangedCallback, slider_cb, cinfo); |
| 387 |
|
| 388 |
str = XmStringCreateLocalized("Green"); |
| 389 |
XtSetArg(label_args[0], XmNlabelString, str); |
| 390 |
g_label = XtCreateManagedWidget("g_label", xmLabelGadgetClass, parent, label_args, 1); |
| 391 |
XmStringFree(str); |
| 392 |
|
| 393 |
g_scale = XtCreateWidget("g_scale", xmScaleWidgetClass, parent, scale_args, scale_n); |
| 394 |
cinfo->g_scale = g_scale; |
| 395 |
XtAddCallback(g_scale, XmNdragCallback, slider_cb, cinfo); |
| 396 |
XtAddCallback(g_scale, XmNvalueChangedCallback, slider_cb, cinfo); |
| 397 |
|
| 398 |
str = XmStringCreateLocalized("Blue"); |
| 399 |
XtSetArg(label_args[0], XmNlabelString, str); |
| 400 |
b_label = XtCreateManagedWidget("b_label", xmLabelGadgetClass, parent, label_args, 1); |
| 401 |
XmStringFree(str); |
| 402 |
|
| 403 |
b_scale = XtCreateWidget("b_scale", xmScaleWidgetClass, parent, scale_args, scale_n); |
| 404 |
cinfo->b_scale = b_scale; |
| 405 |
XtAddCallback(b_scale, XmNdragCallback, slider_cb, cinfo); |
| 406 |
XtAddCallback(b_scale, XmNvalueChangedCallback, slider_cb, cinfo); |
| 407 |
|
| 408 |
/* get max width of labels, and adjust scale size to what's left */ |
| 409 |
XtVaGetValues(r_label, XmNwidth, &curr, NULL); |
| 410 |
XtVaGetValues(g_label, XmNwidth, &max, NULL); |
| 411 |
if (curr > max) |
| 412 |
max = curr; |
| 413 |
XtVaGetValues(b_label, XmNwidth, &curr, NULL); |
| 414 |
if (curr > max) |
| 415 |
max = curr; |
| 416 |
/* we know the width of the color selector is about 200 pixels (10 fields each 20 wide), |
| 417 |
so we use that as max length */ |
| 418 |
curr = 200 - max - 2; /* some additional offset */ |
| 419 |
|
| 420 |
/* fprintf(stderr, "width of slider: %d\n", curr); */ |
| 421 |
/* fprintf(stderr, "width of string: %d\n", max); */ |
| 422 |
|
| 423 |
/* attach widgets; needs to be done after creating them since r_label |
| 424 |
attachment references g_label etc. */ |
| 425 |
XtVaSetValues(r_label, |
| 426 |
XmNleftAttachment, XmATTACH_FORM, |
| 427 |
XmNbottomAttachment, XmATTACH_WIDGET, |
| 428 |
XmNbottomWidget, g_label, |
| 429 |
XmNbottomOffset, 20, /* needed to make label visible */ |
| 430 |
NULL); |
| 431 |
XtVaSetValues(r_scale, |
| 432 |
XmNtopAttachment, XmATTACH_WIDGET, |
| 433 |
XmNtopWidget, top, |
| 434 |
XmNrightAttachment, XmATTACH_FORM, |
| 435 |
XmNbottomAttachment, XmATTACH_WIDGET, |
| 436 |
XmNbottomWidget, g_label, |
| 437 |
XmNbottomOffset, 20, /* needed to make label visible */ |
| 438 |
XmNscaleWidth, curr, |
| 439 |
NULL); |
| 440 |
XtVaSetValues(g_label, |
| 441 |
XmNleftAttachment, XmATTACH_FORM, |
| 442 |
XmNbottomAttachment, XmATTACH_WIDGET, |
| 443 |
XmNbottomWidget, b_label, |
| 444 |
XmNbottomOffset, 20, /* needed to make label visible */ |
| 445 |
NULL); |
| 446 |
XtVaSetValues(g_scale, |
| 447 |
XmNrightAttachment, XmATTACH_FORM, |
| 448 |
XmNbottomAttachment, XmATTACH_WIDGET, |
| 449 |
XmNbottomWidget, b_label, |
| 450 |
XmNbottomOffset, 20, /* needed to make label visible */ |
| 451 |
XmNscaleWidth, curr, |
| 452 |
NULL); |
| 453 |
XtVaSetValues(b_label, |
| 454 |
XmNleftAttachment, XmATTACH_FORM, |
| 455 |
XmNbottomAttachment, XmATTACH_FORM, |
| 456 |
XmNbottomOffset, 15, |
| 457 |
NULL); |
| 458 |
XtVaSetValues(b_scale, |
| 459 |
XmNrightAttachment, XmATTACH_FORM, |
| 460 |
XmNbottomAttachment, XmATTACH_FORM, |
| 461 |
XmNbottomOffset, 15, |
| 462 |
XmNscaleWidth, curr, |
| 463 |
NULL); |
| 464 |
|
| 465 |
XtManageChild(r_scale); |
| 466 |
XtManageChild(g_scale); |
| 467 |
XtManageChild(b_scale); |
| 468 |
|
| 469 |
h_update_sliders(cinfo); |
| 470 |
|
| 471 |
} |
| 472 |
|
| 473 |
static Widget |
| 474 |
h_create_shell(Widget parent, struct color_info *cinfo) |
| 475 |
{ |
| 476 |
Widget shell, dialog, form, button_row, color_matrix; |
| 477 |
Widget old_sample, new_sample; |
| 478 |
Widget tip_shell; |
| 479 |
Atom WM_DELETE_WINDOW; |
| 480 |
Arg args[32]; |
| 481 |
int n; |
| 482 |
|
| 483 |
XmString str; |
| 484 |
|
| 485 |
Pixel old_pixel = cinfo->button_info->pixel; |
| 486 |
/* hack to disable resizing of the shell, since this messes up the color matrix badly */ |
| 487 |
int decoration = MWM_DECOR_ALL | MWM_DECOR_RESIZEH | MWM_DECOR_MENU | MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE; |
| 488 |
int functions = MWM_FUNC_ALL | MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE; |
| 489 |
|
| 490 |
struct color_button_info *binfo = cinfo->button_info; |
| 491 |
struct topic_info *tinfo = binfo->tinfo; |
| 492 |
struct prefs_choice *prefs = (struct prefs_choice *)tinfo->data; |
| 493 |
/* struct prefs_choice *prefs; */ |
| 494 |
|
| 495 |
n = 0; |
| 496 |
XtSetArg(args[n], XmNuserData, cinfo); n++; |
| 497 |
|
| 498 |
/* XtSetArg(args[n], XmNdeleteResponse, XmDO_NOTHING); n++; */ |
| 499 |
/* XtSetArg(args[n], XmNnoResize, True); n++; */ |
| 500 |
/* XtSetArg(args[n], XmNmwmFunctions, functions); n++; */ |
| 501 |
/* XtSetArg(args[n], XmNmwmDecorations, decoration); n++; */ |
| 502 |
XtSetArg(args[n], XtNtitle, "Xdvik: Select Color"); n++; |
| 503 |
|
| 504 |
dialog = XmCreatePromptDialog(parent, Xdvi_COLOR_DIALOG_NAME, args, n); |
| 505 |
/* unmanage stuff to get a `scratch' widget */ |
| 506 |
XtUnmanageChild(XtNameToWidget(dialog, "Help")); |
| 507 |
XtUnmanageChild(XtNameToWidget(dialog, "Text")); |
| 508 |
XtUnmanageChild(XtNameToWidget(dialog, "Selection")); |
| 509 |
|
| 510 |
shell = XtParent(dialog); |
| 511 |
|
| 512 |
XtVaSetValues(shell, |
| 513 |
XmNdeleteResponse, XmDO_NOTHING, |
| 514 |
XmNnoResize, True, |
| 515 |
XmNmwmFunctions, functions, |
| 516 |
XmNmwmDecorations, decoration, |
| 517 |
NULL); |
| 518 |
|
| 519 |
/* cinfo->new_color is a allocated/freed by request; initialize it with old_pixel */ |
| 520 |
XAllocColor(DISP, G_colormap, &(cinfo->new_color)); |
| 521 |
cinfo->new_color.flags = DoRed | DoGreen | DoBlue; |
| 522 |
|
| 523 |
XFreeColors(DISP, G_colormap, &(cinfo->new_color.pixel), 1, 0); |
| 524 |
pixel_to_color(old_pixel, &(cinfo->new_color), DISP, G_colormap); |
| 525 |
|
| 526 |
|
| 527 |
tip_shell = XtVaCreatePopupShell("tipShell", tipWidgetClass, |
| 528 |
parent, XtNwidth, 1, XtNheight, 1, |
| 529 |
NULL); |
| 530 |
cinfo->tooltip = tip_shell; |
| 531 |
|
| 532 |
form = XtVaCreateWidget("form", xmFormWidgetClass, |
| 533 |
dialog, |
| 534 |
XmNhorizontalSpacing, 10, |
| 535 |
XmNverticalSpacing, 10, |
| 536 |
XmNallowResize, False, |
| 537 |
NULL); |
| 538 |
|
| 539 |
button_row = XtVaCreateManagedWidget("button_row", xmRowColumnWidgetClass, |
| 540 |
form, |
| 541 |
XmNtopAttachment, XmATTACH_FORM, |
| 542 |
XmNleftAttachment, XmATTACH_FORM, |
| 543 |
XmNorientation, XmHORIZONTAL, |
| 544 |
XmNpacking, XmPACK_COLUMN, |
| 545 |
XmNspacing, 8, |
| 546 |
XmNmarginWidth, 1, |
| 547 |
XmNmarginHeight, 1, |
| 548 |
NULL); |
| 549 |
|
| 550 |
str = XmStringCreateLocalized("Old"); |
| 551 |
old_sample = XtVaCreateManagedWidget(Xdvi_COLOR_DIALOG_OLD_SAMPLE_NAME, xmPushButtonWidgetClass, |
| 552 |
button_row, |
| 553 |
XmNbackground, old_pixel, |
| 554 |
XmNlabelString, str, |
| 555 |
XmNhighlightThickness, 0, |
| 556 |
XmNshadowThickness, 1, |
| 557 |
NULL); |
| 558 |
XtAddCallback(old_sample, XmNactivateCallback, revert_color_cb, cinfo); |
| 559 |
XmStringFree(str); |
| 560 |
str = XmStringCreateLocalized("New"); |
| 561 |
new_sample = XtVaCreateManagedWidget("new_sample", xmPushButtonWidgetClass, |
| 562 |
button_row, |
| 563 |
XmNbackground, cinfo->new_color.pixel, |
| 564 |
XmNlabelString, str, |
| 565 |
XmNhighlightThickness, 0, |
| 566 |
XmNshadowThickness, 1, |
| 567 |
NULL); |
| 568 |
XmStringFree(str); |
| 569 |
/* disable clicking on the new_sample button */ |
| 570 |
XtInsertEventHandler(new_sample, |
| 571 |
KeyPressMask | KeyReleaseMask | |
| 572 |
ButtonPressMask | ButtonReleaseMask, |
| 573 |
True, block_event_callback, |
| 574 |
(XtPointer)0, 0); |
| 575 |
cinfo->new_sample = new_sample; |
| 576 |
|
| 577 |
color_matrix = h_create_color_matrix(form, button_row, cinfo); |
| 578 |
|
| 579 |
h_create_sliders(form, color_matrix, cinfo); |
| 580 |
|
| 581 |
XtManageChild(form); |
| 582 |
|
| 583 |
XtAddCallback(dialog, XmNokCallback, popdown_apply_cb, prefs); |
| 584 |
XtAddCallback(dialog, XmNcancelCallback, popdown_cancel_cb, prefs); |
| 585 |
|
| 586 |
XtManageChild(dialog); |
| 587 |
|
| 588 |
add_to_deplist(prefs, dialog); |
| 589 |
|
| 590 |
TipAddWidget(tip_shell, old_sample, "Click to revert to old color"); |
| 591 |
TipAddWidget(tip_shell, new_sample, "Preview of new color"); |
| 592 |
/* TipAddWidget(tip_shell, color_matrix, "Select color"); */ |
| 593 |
|
| 594 |
WM_DELETE_WINDOW = XmInternAtom(DISP, "WM_DELETE_WINDOW", False); |
| 595 |
XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, popdown_cb, prefs); |
| 596 |
|
| 597 |
return dialog; |
| 598 |
} |
| 599 |
|
| 600 |
void |
| 601 |
popup_color_dialog(Widget parent, struct color_button_info *button_info) |
| 602 |
{ |
| 603 |
static Widget shell; |
| 604 |
static Boolean first_time = True; |
| 605 |
/* Must be static so that we can pass its address around */ |
| 606 |
static struct color_info cinfo; |
| 607 |
struct topic_info *tinfo = button_info->tinfo; |
| 608 |
struct prefs_choice *prefs = (struct prefs_choice *)tinfo->data; |
| 609 |
|
| 610 |
cinfo.button_info = button_info; |
| 611 |
|
| 612 |
if (first_time) { |
| 613 |
shell = h_create_shell(parent, &cinfo); |
| 614 |
first_time = False; |
| 615 |
} |
| 616 |
else { |
| 617 |
/* Already created, but we may need to change the colors of old_sample |
| 618 |
and new_sample. This is done by changing the value of old_sample and |
| 619 |
invoking its activate callback, which will `revert' new_sample to |
| 620 |
the same color. */ |
| 621 |
Widget w; |
| 622 |
if (get_widget_by_name(&w, shell, Xdvi_COLOR_DIALOG_OLD_SAMPLE_NAME, True)) { |
| 623 |
#if XmVersion >= 1002 |
| 624 |
XmChangeColor(w, cinfo.button_info->pixel); |
| 625 |
#else |
| 626 |
XtVaSetValues(w, XmNbackground, cinfo.button_info->pixel, NULL); |
| 627 |
#endif |
| 628 |
XtCallCallbacks(w, XmNactivateCallback, &cinfo); |
| 629 |
} |
| 630 |
add_to_deplist(prefs, shell); |
| 631 |
XtManageChild(shell); |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
#else |
| 636 |
/* silence `empty compilation unit' warnings */ |
| 637 |
static void bar(void); static void foo(void) { bar(); } static void bar(void) { foo(); } |
| 638 |
#endif /* MOTIF */ |