SetToggleButtonState -> ToggleButtonSetState
[grace.git] / src / qtgui / qtgrace.cpp
blobbbad5bb5b18c5b23311b5f57658eb78d3c31d1c3
1 /*
2 * Grace - GRaphing, Advanced Computation and Exploration of data
3 *
4 * Home page: http://plasma-gate.weizmann.ac.il/Grace/
5 *
6 * Copyright (c) 1991-1995 Paul J Turner, Portland, OR
7 * Copyright (c) 1996-2010 Grace Development Team
8 *
9 * Maintained by Evgeny Stambulchik
12 * All Rights Reserved
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 * utilities for Qt
35 #define CANVAS_BACKEND_API
37 #include <QDebug>
38 #include <QtGlobal>
39 #include <QApplication>
40 #include <QMainWindow>
41 #include <QToolBar>
42 #include <QGridLayout>
43 #include <QScrollArea>
44 #include <QStatusBar>
45 #include <QMenuBar>
46 #include <QMenu>
47 #include <QWidgetAction>
48 #include <QLabel>
49 #include <QBitmap>
50 #include <QAbstractButton>
51 #include <QMessageBox>
52 #include <QDialog>
53 #include <QGroupBox>
54 #include <QCheckBox>
55 #include <QPushButton>
56 #include <QSignalMapper>
57 #include <QComboBox>
58 #include <QPainter>
59 #include <QDoubleSpinBox>
60 #include <QLCDNumber>
61 #include <QPlainTextEdit>
62 #include <QLineEdit>
63 #include <QListWidget>
64 #include <QScrollBar>
65 #include <QTableWidget>
66 #include <QStandardItemModel>
67 #include <QTableView>
68 #include <QTextCodec>
69 #include <QWhatsThis>
70 #include <QShortcut>
71 #include <mainwindow.h>
72 #include <canvaswidget.h>
73 #include <fileselectiondialog.h>
74 #include <qtinc.h>
76 extern "C" {
77 #include <globals.h>
78 #include <bitmaps.h>
79 #include "qbitmaps.h"
80 #include "jbitmaps.h"
81 #include "xprotos.h"
82 #include "utils.h"
83 #include "explorer.h"
84 #include "events.h"
85 Widget app_shell;
88 //#define canvas grace_get_canvas(gapp->grace)
90 #include <qtgrace.h>
92 CallBack::CallBack(QObject *parent) : QObject(parent) {}
94 static MainWindow *mainWin;
95 static CanvasWidget *canvasWidget;
96 static QApplication *app;
99 void set_wait_cursor()
101 QApplication::setOverrideCursor(Qt::WaitCursor);
104 void unset_wait_cursor()
106 QApplication::restoreOverrideCursor();
110 * build the GUI
112 void startup_gui(GraceApp *gapp)
114 qDebug("startup_gui start");
116 MainWinUI *mwui = gapp->gui->mwui;
117 X11Stuff *xstuff = gapp->gui->xstuff;
119 mwui->loclab = mainWin->ui.locatorBar;
120 mwui->frtop = mwui->loclab;
122 mwui->statlab = CreateLabel(mainWin, NULL);
123 mwui->frbot = mwui->statlab;
124 mainWin->ui.statusBar->addWidget(mwui->statlab);
126 mwui->frleft = mainWin->ui.toolBar;
128 // if (!gui_is_page_free(gapp->gui)) {
129 // mwui->drawing_window = XtVaCreateManagedWidget("drawing_window",
130 // xmScrolledWindowWidgetClass, form,
131 // XmNscrollingPolicy, XmAUTOMATIC,
132 // XmNvisualPolicy, XmVARIABLE,
133 // NULL);
134 // xstuff->canvas = XtVaCreateManagedWidget("canvas",
135 // xmDrawingAreaWidgetClass,
136 // mwui->drawing_window,
137 // NULL);
138 // } else {
139 // xstuff->canvas = XtVaCreateManagedWidget("canvas",
140 // xmDrawingAreaWidgetClass, form,
141 // NULL);
142 // mwui->drawing_window = xstuff->canvas;
143 // }
145 mwui->drawing_window = mainWin->ui.scrollArea;
146 xstuff->canvas = mainWin->ui.canvasWidget;
148 AddHelpCB(xstuff->canvas, "doc/UsersGuide.html#canvas");
150 //toolBar->setStyleSheet(QString::fromUtf8(" QToolButton {\n"
151 // " border: 1px solid #8f8f91;\n"
152 // " border-radius: 2px;\n"
153 // " background-color: #b0c4de;\n"
154 // " }\n"
155 // "\n"
156 // " QToolButton:pressed {\n"
157 // " background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\n"
158 // " stop: 0 #dadbde, stop: 1 #f6f7fa);\n"
159 // " }"));
161 QMenuBar *menuBar = (QMenuBar *) CreateMainMenuBar(mainWin);
162 mainWin->setMenuBar(menuBar);
164 CreateToolBar(mainWin->ui.toolBar);
166 * initialize some option menus
168 init_option_menus();
171 * initialize the tool bars
173 set_view_items();
175 set_tracker_string(NULL);
176 // set_left_footer(NULL);
179 * set icon
181 mainWin->setWindowIcon(QPixmap(gapp_icon_xpm));
183 gapp->gui->inwin = TRUE;
186 * set the title
188 // update_app_title(gapp->gp);
190 xdrawgraph(gapp->gp);
191 update_all();
193 //XtAppMainLoop(app_con);
194 mainWin->show();
195 qDebug("startup_gui end");
196 app->exec();
197 exit(0);
200 int initialize_gui(int *argc, char **argv)
202 qDebug("initialize_gui start");
203 X11Stuff *xstuff;
204 MainWinUI *mwui;
205 char **enc;
206 char *encoding;
207 // Screen *screen;
208 // ApplicationData rd;
209 // String *allResources, *resolResources;
210 // int lowres = FALSE;
211 // unsigned int i, n_common, n_resol;
212 // char *display_name = NULL;
214 xstuff = (X11Stuff*) xmalloc(sizeof(X11Stuff));
215 memset(xstuff, 0, sizeof(X11Stuff));
216 gapp->gui->xstuff = xstuff;
218 mwui = (MainWinUI*) xmalloc(sizeof(MainWinUI));
219 memset(mwui, 0, sizeof(MainWinUI));
220 gapp->gui->mwui = mwui;
222 app = new QApplication(*argc, argv);
224 enc = get_default_encoding(grace_get_canvas(gapp->grace));
225 encoding = copy_string(NULL, enc[256]);
226 printf("Encoding=%s\n", encoding);
228 if (!strcmp(encoding,"CP1251"))
229 encoding = copy_string(encoding, "Windows-1251");
230 else if (!strcmp(encoding,"ISOLatin1Encoding"))
231 encoding = copy_string(encoding, "ISO 8859-1");
232 else if (!strcmp(encoding,"ISOLatin2Encoding"))
233 encoding = copy_string(encoding, "ISO 8859-2");
234 else if (!strcmp(encoding,"ISOLatin7Encoding"))
235 encoding = copy_string(encoding, "ISO 8859-13");
236 else if (!strcmp(encoding,"ISOLatin9Encoding"))
237 encoding = copy_string(encoding, "ISO 8859-15");
238 else if (!strcmp(encoding,"KOI8-R"))
239 encoding = copy_string(encoding, "KOI8-R");
240 else if (!strcmp(encoding,"KOI8-U"))
241 encoding = copy_string(encoding, "KOI8-U");
242 else if (!strcmp(encoding,"MacRomanEncoding"))
243 encoding = copy_string(encoding, "Apple Roman");
244 else if (!strcmp(encoding,"PDFDocEncoding"))
245 encoding = copy_string(encoding, "ISO 8859-1"); //TODO:
246 else if (!strcmp(encoding,"PSLatin1Encoding"))
247 encoding = copy_string(encoding, "ISO 8859-1"); //TODO:
248 else if (!strcmp(encoding,"WinAnsiEncoding"))
249 encoding = copy_string(encoding, "Windows-1252");
250 else
251 encoding = copy_string(encoding, "ISO 8859-1");
253 QTextCodec::setCodecForCStrings(QTextCodec::codecForName(encoding));
255 xfree(encoding);
257 // installXErrorHandler();
259 // /* Locale settings for GUI */
260 // XtSetLanguageProc(NULL, NULL, NULL);
262 // XtToolkitInitialize();
263 // app_con = XtCreateApplicationContext();
265 // /* Check if we're running in the low-resolution X */
266 // for (i = 1; i < *argc - 1; i++) {
267 // /* See if display name was specified in the args */
268 // char *pattern = "-display";
269 // if (strlen(argv[i]) > 1 && strstr(pattern, argv[i]) == pattern) {
270 // display_name = argv[i + 1];
271 // }
272 // }
273 // xstuff->disp = XOpenDisplay(display_name);
274 // if (xstuff->disp == NULL) {
275 // errmsg("Can't open display");
276 // return RETURN_FAILURE;
277 // }
279 // screen = DefaultScreenOfDisplay(xstuff->disp);
280 // if (HeightOfScreen(screen) < 740) {
281 // lowres = TRUE;
282 // }
284 // n_common = sizeof(fallbackResourcesCommon)/sizeof(String) - 1;
285 // if (lowres) {
286 // n_resol = sizeof(fallbackResourcesLowRes)/sizeof(String) - 1;
287 // resolResources = fallbackResourcesLowRes;
288 // } else {
289 // n_resol = sizeof(fallbackResourcesHighRes)/sizeof(String) - 1;
290 // resolResources = fallbackResourcesHighRes;
291 // }
292 // allResources = xmalloc((n_common + n_resol + 1)*sizeof(String));
293 // for (i = 0; i < n_common; i++) {
294 // allResources[i] = fallbackResourcesCommon[i];
295 // }
296 // for (i = 0; i < n_resol; i++) {
297 // allResources[n_common + i] = resolResources[i];
298 // }
299 // allResources[n_common + n_resol] = NULL;
300 // XtAppSetFallbackResources(app_con, allResources);
302 // XtDisplayInitialize(app_con, xstuff->disp, "xmgrace", "XmGrace", NULL, 0, argc, argv);
304 // XtAppAddActions(app_con, dummy_actions, XtNumber(dummy_actions));
305 // XtAppAddActions(app_con, canvas_actions, XtNumber(canvas_actions));
306 // XtAppAddActions(app_con, list_select_actions, XtNumber(list_select_actions));
307 // XtAppAddActions(app_con, cstext_actions, XtNumber(cstext_actions));
309 // app_shell = XtAppCreateShell(NULL, "XmGrace", applicationShellWidgetClass,
310 // xstuff->disp, NULL, 0);
312 // if (is_motif_compatible() != TRUE) {
313 // return RETURN_FAILURE;
314 // }
316 // XtGetApplicationResources(app_shell, &rd,
317 // resources, XtNumber(resources), NULL, 0);
319 // gapp->gui->invert = rd.invert;
320 // gapp->gui->instant_update = rd.instantupdate;
321 // gapp->gui->toolbar = rd.toolbar;
322 // gapp->gui->statusbar = rd.statusbar;
323 // gapp->gui->locbar = rd.locatorbar;
324 gapp->gui->invert = TRUE;
325 gapp->gui->instant_update = TRUE;
326 gapp->gui->toolbar = TRUE;
327 gapp->gui->statusbar = TRUE;
328 gapp->gui->locbar = TRUE;
331 x11_init(gapp);
333 /* initialize cursors */
334 init_cursors(gapp->gui);
336 qDebug("initialize_gui end");
337 return RETURN_SUCCESS;
340 int x11_init(GraceApp *gapp)
342 X11Stuff *xstuff = gapp->gui->xstuff;
343 // XGCValues gc_val;
344 // long mrsize;
345 // int max_path_limit;
347 // xstuff->screennumber = DefaultScreen(xstuff->disp);
348 // xstuff->root = RootWindow(xstuff->disp, xstuff->screennumber);
350 // xstuff->gc = DefaultGC(xstuff->disp, xstuff->screennumber);
352 // xstuff->depth = DisplayPlanes(xstuff->disp, xstuff->screennumber);
354 // /* init colormap */
355 // xstuff->cmap = DefaultColormap(xstuff->disp, xstuff->screennumber);
356 // /* redefine colormap, if needed */
357 // if (gapp->gui->install_cmap == CMAP_INSTALL_ALWAYS) {
358 // xstuff->cmap = XCopyColormapAndFree(xstuff->disp, xstuff->cmap);
359 // gapp->gui->private_cmap = TRUE;
360 // }
362 // /* set GCs */
363 // if (gapp->gui->invert) {
364 // gc_val.function = GXinvert;
365 // } else {
366 // gc_val.function = GXxor;
367 // }
368 // gcxor = XCreateGC(xstuff->disp, xstuff->root, GCFunction, &gc_val);
370 // /* XExtendedMaxRequestSize() appeared in X11R6 */
371 //#if XlibSpecificationRelease > 5
372 // mrsize = XExtendedMaxRequestSize(xstuff->disp);
373 //#else
374 // mrsize = 0;
375 //#endif
376 // if (mrsize <= 0) {
377 // mrsize = XMaxRequestSize(xstuff->disp);
378 // }
379 // max_path_limit = (mrsize - 3)/2;
380 // if (max_path_limit < get_max_path_limit(grace_get_canvas(gapp->grace))) {
381 // char buf[128];
382 // sprintf(buf,
383 // "Setting max drawing path length to %d (limited by the X server)",
384 // max_path_limit);
385 // errmsg(buf);
386 // set_max_path_limit(grace_get_canvas(gapp->grace), max_path_limit);
387 // }
389 // xstuff->dpi = rint(MM_PER_INCH*DisplayWidth(xstuff->disp, xstuff->screennumber)/
390 // DisplayWidthMM(xstuff->disp, xstuff->screennumber));
391 mainWin = new MainWindow();
392 canvasWidget = mainWin->ui.canvasWidget;
393 xstuff->dpi = canvasWidget->physicalDpiX();
395 return RETURN_SUCCESS;
398 // FOR main.c
399 int x11_get_pixelsize(const GUI *gui)
401 // Screen *screen = DefaultScreenOfDisplay(gui->xstuff->disp);
402 // int i, n;
403 // XPixmapFormatValues *pmf;
404 // int pixel_size = 0;
406 // pmf = XListPixmapFormats(DisplayOfScreen(screen), &n);
407 // if (pmf) {
408 // for (i = 0; i < n; i++) {
409 // if (pmf[i].depth == PlanesOfScreen(screen)) {
410 // pixel_size = pmf[i].bits_per_pixel/8;
411 // break;
412 // }
413 // }
414 // XFree((char *) pmf);
415 // }
417 // return pixel_size;
418 return 8;
421 // src/xutil.c
422 void xunregister_rti(const Input_buffer *ib)
426 // src/xutil.c
427 void xregister_rti(Input_buffer *ib)
431 void QtAddCallback(const QObject *sender,
432 const char *signal,
433 void (*callback)(Widget, XtPointer, XtPointer),
434 void *data)
436 CallBack *callBack = new CallBack(mainWin);
437 callBack->setCallBack(sender, callback, data);
438 QObject::connect(sender, signal, callBack, SLOT(callBack()));
442 * Auxiliary routines for simultaneous drawing on display and pixmap
444 void aux_XDrawLine(GUI *gui, int x1, int y1, int x2, int y2)
446 QImage *pixmap = (QImage*) gui->xstuff->bufpixmap;
448 QPainter painter(pixmap);
449 painter.setPen(QPen(Qt::white));
450 painter.setBrush(QBrush(Qt::NoBrush));
451 painter.setCompositionMode(QPainter::CompositionMode_Exclusion);
452 painter.drawLine(x1, y1, x2, y2);
453 canvasWidget->update(); // TODO: repaint just drawn rectangle
454 // X11Stuff *xstuff = gui->xstuff;
455 // XDrawLine(xstuff->disp, xstuff->xwin, gcxor, x1, y1, x2, y2);
456 // if (xstuff->bufpixmap != (Pixmap) NULL) {
457 // XDrawLine(xstuff->disp, xstuff->bufpixmap, gcxor, x1, y1, x2, y2);
458 // }
461 void aux_XDrawRectangle(GUI *gui, int x1, int y1, int x2, int y2)
463 QImage *pixmap = (QImage*) gui->xstuff->bufpixmap;
465 QPainter painter(pixmap);
466 painter.setPen(QPen(Qt::white));
467 painter.setBrush(QBrush(Qt::NoBrush));
468 painter.setCompositionMode(QPainter::CompositionMode_Exclusion);
469 painter.drawRect(x1, y1, x2, y2);
470 canvasWidget->update(x1, y1, x2 + 1, y2 + 1); // Plus pen = 1
471 // XDrawRectangle(xstuff->disp, xstuff->xwin, gcxor, x1, y1, x2, y2);
472 // if (xstuff->bufpixmap != (Pixmap) NULL) {
473 // XDrawRectangle(xstuff->disp, xstuff->bufpixmap, gcxor, x1, y1, x2, y2);
474 // }
477 void aux_XFillRectangle(GUI *gui, int x, int y, unsigned int width, unsigned int height)
479 QImage *pixmap = (QImage*) gui->xstuff->bufpixmap;
481 QPainter painter(pixmap);
482 painter.setPen(QPen(Qt::NoPen));
483 painter.setBrush(QBrush(Qt::white));
484 painter.setCompositionMode(QPainter::CompositionMode_Exclusion);
485 painter.drawRect(x, y, width, height);
486 canvasWidget->update(x, y, width, height);
487 // XFillRectangle(xstuff->disp, xstuff->xwin, gcxor, x, y, width, height);
488 // if (xstuff->bufpixmap != (Pixmap) NULL) {
489 // XFillRectangle(xstuff->disp, xstuff->bufpixmap, gcxor, x, y, width, height);
490 // }
493 void init_xstream(X11stream *xstream)
495 X11Stuff *xstuff = gapp->gui->xstuff;
497 // xstream->screen = DefaultScreenOfDisplay(xstuff->disp);
498 xstream->pixmap = xstuff->bufpixmap;
501 void create_pixmap(unsigned int w, unsigned int h)
503 qDebug("create_pixmap");
504 X11Stuff *xstuff = gapp->gui->xstuff;
506 // xstuff->bufpixmap = XCreatePixmap(xstuff->disp, xstuff->root, w, h, xstuff->depth);
507 /* 8 bits per color channel (i.e., 256^3 colors) */
508 /* are defined in CANVAS_BPCC canvas.h file. */
509 /* Use alpha channel to be able to use QPainter::setCompositionMode(CompositionMode mode)*/
510 /* Image composition using alpha blending are faster using premultiplied ARGB32 than with plain ARGB32 */
511 xstuff->bufpixmap = new QImage(w, h, QImage::Format_ARGB32_Premultiplied);
514 void recreate_pixmap(unsigned int w, unsigned int h)
516 qDebug("recreate_pixmap");
517 X11Stuff *xstuff = gapp->gui->xstuff;
519 // XFreePixmap(xstuff->disp, xstuff->bufpixmap);
520 delete (QImage*)xstuff->bufpixmap;
521 create_pixmap(w, h);
524 void xdrawgrid(X11Stuff *xstuff)
526 int i, j;
527 double step;
528 double x, y;
530 double w = canvasWidget->width();
531 double h = canvasWidget->height();
533 QImage *pixmap = (QImage*) xstuff->bufpixmap;
535 QPainter painter(pixmap);
537 QPen pen;
538 pen.setColor(Qt::black);
539 pen.setWidth(1);
540 pen.setStyle(Qt::SolidLine);
541 pen.setCapStyle(Qt::FlatCap);
542 pen.setJoinStyle(Qt::MiterJoin);
543 painter.setPen(pen);
545 QBrush brush;
546 brush.setColor(Qt::white);
547 painter.setBrush(brush);
549 painter.drawRect(canvasWidget->rect());
551 step = MIN2(w, h)/10;
552 for (i = 0; i < w/step; i++) {
553 for (j = 0; j < h/step; j++) {
554 x = i*step;
555 y = h - j*step;
556 painter.drawPoint(QPointF(x, y));
561 void x11_redraw_all()
563 X11Stuff *xstuff = gapp->gui->xstuff;
565 canvasWidget->pixmap = (QImage*) xstuff->bufpixmap;
566 canvasWidget->update();
567 // X11Stuff *xstuff = gapp->gui->xstuff;
568 // if (gapp->gui->inwin == TRUE && xstuff->bufpixmap != (Pixmap) NULL) {
569 // XCopyArea(xstuff->disp, xstuff->bufpixmap, window, xstuff->gc, x, y, width, height, x, y);
570 // }
573 void move_pointer(short x, short y)
575 // TODO:
576 // X11Stuff *xstuff = gapp->gui->xstuff;
578 // XWarpPointer(xstuff->disp, None, xstuff->xwin, 0, 0, 0, 0, x, y);
583 char *display_name(GUI *gui)
585 //return DisplayString(gui->xstuff->disp);
586 return "0:0";
591 void set_cursor(GUI *gui, int c)
593 X11Stuff *xstuff = gui->xstuff;
595 if (xstuff->cur_cursor == c) {
596 return;
599 // XUndefineCursor(xstuff->disp, xstuff->xwin);
600 canvasWidget->unsetCursor();
601 xstuff->cur_cursor = c;
602 switch (c) {
603 case 0:
604 canvasWidget->setCursor(Qt::CrossCursor);
605 //XDefineCursor(xstuff->disp, xstuff->xwin, xstuff->line_cursor);
606 break;
607 case 1:
608 //TODO:
609 canvasWidget->setCursor(Qt::CrossCursor);
610 // XDefineCursor(xstuff->disp, xstuff->xwin, xstuff->find_cursor);
611 break;
612 case 2:
613 canvasWidget->setCursor(Qt::IBeamCursor);
614 // XDefineCursor(xstuff->disp, xstuff->xwin, xstuff->text_cursor);
615 break;
616 case 3:
617 //TODO:
618 canvasWidget->setCursor(Qt::CrossCursor);
619 // XDefineCursor(xstuff->disp, xstuff->xwin, xstuff->kill_cursor);
620 break;
621 case 4:
622 canvasWidget->setCursor(Qt::SizeAllCursor);
623 // XDefineCursor(xstuff->disp, xstuff->xwin, xstuff->move_cursor);
624 break;
625 case 5:
626 canvasWidget->setCursor(Qt::PointingHandCursor);
627 // XDefineCursor(xstuff->disp, xstuff->xwin, xstuff->drag_cursor);
628 break;
629 default:
630 xstuff->cur_cursor = -1;
631 break;
633 // XFlush(xstuff->disp);
637 void create_netcdfs_popup(Widget but, void *data)
641 void create_load_frame(Widget but, void *data)
645 void create_reg_frame(Widget but, void *data)
649 void create_points_frame(Widget but, void *data)
654 void create_nonl_frame(Widget but, void *data)
659 void set_view_items(void)
661 MainWinUI *mwui = gapp->gui->mwui;
663 if (gapp->gui->statusbar) {
664 ToggleButtonSetState(mwui->windowbarw[1], TRUE);
665 WidgetManage(mwui->frbot);
666 } else {
667 ToggleButtonSetState(mwui->windowbarw[1], FALSE);
668 WidgetUnmanage(mwui->frbot);
670 if (gapp->gui->toolbar) {
671 ToggleButtonSetState(mwui->windowbarw[2], TRUE);
672 WidgetManage(mwui->frleft);
673 } else {
674 ToggleButtonSetState(mwui->windowbarw[2], FALSE);
675 WidgetUnmanage(mwui->frleft);
677 if (gapp->gui->locbar) {
678 ToggleButtonSetState(mwui->windowbarw[0], TRUE);
679 WidgetManage(mwui->frtop);
680 } else {
681 ToggleButtonSetState(mwui->windowbarw[0], FALSE);
682 WidgetUnmanage(mwui->frtop);
686 //Widget CreateScrolledWindow(Widget parent)
688 // return XtVaCreateManagedWidget("ui->sw",
689 // xmScrolledWindowWidgetClass, parent,
690 // XmNheight, 320,
691 // XmNscrollingPolicy, XmAUTOMATIC,
692 // NULL);
694 Widget CreateScrolledWindow(Widget parent)
696 QScrollArea *scrollArea = new QScrollArea(parent);
697 scrollArea->setWidgetResizable(true);
698 QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
699 sizePolicy.setHorizontalStretch(1);
700 sizePolicy.setVerticalStretch(0);
701 scrollArea->setSizePolicy(sizePolicy);
703 QWidget *widget = new QWidget;
704 QVBoxLayout *vLayout = new QVBoxLayout;
705 vLayout->setContentsMargins(3,3,3,3);
706 vLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
707 widget->setLayout(vLayout);
710 scrollArea->setWidget(widget);
712 QLayout *layout = parent->layout();
713 if (layout != 0) {
714 layout->addWidget(scrollArea);
717 return widget;
720 Widget CreatePanedWindow(Widget parent)
722 QSplitter *splitter = new QSplitter(parent);
723 splitter->setChildrenCollapsible(false);
725 QLayout *layout = parent->layout();
726 if (layout != 0) {
727 layout->addWidget(splitter);
730 return splitter;
736 * utilities for Qt
740 //#include <config.h>
742 //#include <stdlib.h>
743 //#include <ctype.h>
744 //#include <stdarg.h>
746 //#include <X11/X.h>
747 //#include <X11/Xatom.h>
748 //#include <X11/cursorfont.h>
750 //#include <Xm/Xm.h>
751 //#include <Xm/Protocols.h>
752 //#include <Xm/BulletinB.h>
753 //#include <Xm/MessageB.h>
754 //#include <Xm/DialogS.h>
755 //#include <Xm/FileSB.h>
756 //#include <Xm/Frame.h>
757 //#include <Xm/Form.h>
758 //#include <Xm/Scale.h>
759 //#include <Xm/Label.h>
760 //#include <Xm/LabelG.h>
761 //#include <Xm/List.h>
762 //#include <Xm/PushB.h>
763 //#include <Xm/CascadeBG.h>
764 //#include <Xm/RowColumn.h>
765 //#include <Xm/Separator.h>
766 //#include <Xm/Text.h>
767 //#include <Xm/ToggleB.h>
768 //#include <Xm/ArrowBG.h>
770 //#ifdef WITH_EDITRES
771 //# include <X11/Xmu/Editres.h>
772 //#endif
774 //#if XmVersion < 2000
775 //# define XmStringConcatAndFree(a, b) XmStringConcat(a, b); XmStringFree(a); XmStringFree(b)
776 //#endif
778 //#include "Tab.h"
779 //#include "motifinc.h"
780 //#include "explorer.h"
782 //#include "defines.h"
783 //#include "globals.h"
784 //#include "grace/canvas.h"
785 //#include "jbitmaps.h"
786 //#include "core_utils.h"
787 //#include "utils.h"
788 //#include "xprotos.h"
790 //#define canvas grace_get_canvas(gapp->grace)
792 //extern XtAppContext app_con;
794 //static XmStringCharSet charset = XmFONTLIST_DEFAULT_TAG;
796 //static unsigned long *xvlibcolors;
799 static OptionItem *color_option_items = NULL;
800 static unsigned int ncolor_option_items = 0;
801 static OptionStructure **color_selectors = NULL;
802 static unsigned int ncolor_selectors = 0;
804 static Widget color_choice_popup = NULL;
806 //static char *label_to_resname(const char *s, const char *suffix)
808 // char *retval, *rs;
809 // int capitalize = FALSE;
811 // retval = copy_string(NULL, s);
812 // rs = retval;
813 // while (*s) {
814 // if (isalnum(*s)) {
815 // if (capitalize == TRUE) {
816 // *rs = toupper(*s);
817 // capitalize = FALSE;
818 // } else {
819 // *rs = tolower(*s);
820 // }
821 // rs++;
822 // } else {
823 // capitalize = TRUE;
824 // }
825 // s++;
826 // }
827 // *rs = '\0';
828 // if (suffix != NULL) {
829 // retval = concat_strings(retval, suffix);
830 // }
831 // return retval;
835 //void Beep(void)
837 // XBell(xstuff->disp, 50);
839 void Beep(void)
841 QApplication::beep();
844 //void ShowMenu(Widget w, void *data)
846 // XmMenuPosition(popup, (XButtonEvent *) data);
847 // XtManageChild(popup);
849 void PopupMenuShow(Widget w, void *data)
851 QMenu *popup = (QMenu*) w;
852 QPoint *point = (QPoint*) data;
854 popup->exec(*point);
857 //void ManageChild(Widget w)
859 // XtManageChild(w);
861 void WidgetManage(Widget w)
863 if (QAction *action = qobject_cast<QAction *>(w)) {
864 action->setVisible(true);
865 } else {
866 w->show();
870 //void UnmanageChild(Widget w)
872 // XtUnmanageChild(w);
874 void WidgetUnmanage(Widget w)
876 if (QAction *action = qobject_cast<QAction *>(w)) {
877 action->setVisible(false);
878 } else {
879 w->hide();
883 //int IsManaged(Widget w)
885 // return (XtIsManaged(w) == True) ? TRUE:FALSE;
887 int WidgetIsManaged(Widget w)
889 return TRUE;
892 //void SetSensitive(Widget w, int onoff)
894 // XtSetSensitive(w, onoff ? True : False);
896 void WidgetSetSensitive(Widget w, int onoff)
898 if (QAction *action = qobject_cast<QAction *>(w)) {
899 action->setEnabled(onoff ? true : false);
900 } else {
901 w->setEnabled(onoff ? true : false);
905 //Widget GetParent(Widget w)
907 // if (w) {
908 // return (XtParent(w));
909 // } else {
910 // errmsg("Internal error: GetParent() called with NULL widget");
911 // return NULL;
912 // }
914 Widget GetParent(Widget w)
916 if (w) {
917 //return (XtParent(w));
918 return w;
919 } else {
920 errmsg("Internal error: GetParent() called with NULL widget");
921 return NULL;
925 //void RegisterEditRes(Widget shell)
927 //#ifdef WITH_EDITRES
928 // XtAddEventHandler(shell, (EventMask) 0, True, _XEditResCheckMessages, NULL);
929 //#endif
932 void WidgetSetHeight(Widget w, unsigned int height)
934 if (QScrollArea *scrollArea = qobject_cast<QScrollArea *>(w->parent()->parent())) {
935 scrollArea->setMinimumHeight(height);
936 } else {
937 w->resize(w->size().width(), height);
941 //void SetDimensions(Widget w, unsigned int width, unsigned int height)
943 // XtVaSetValues(w,
944 // XmNwidth, (Dimension) width,
945 // XmNheight, (Dimension) height,
946 // NULL);
948 void WidgetSetSize(Widget w, unsigned int width, unsigned int height)
950 w->resize(width, height);
953 //void GetDimensions(Widget w, unsigned int *width, unsigned int *height)
955 // Dimension ww, wh;
957 // XtVaGetValues(w,
958 // XmNwidth, &ww,
959 // XmNheight, &wh,
960 // NULL);
962 // *width = (unsigned int) ww;
963 // *height = (unsigned int) wh;
965 void WidgetGetSize(Widget w, unsigned int *width, unsigned int *height)
967 unsigned int ww, wh;
969 ww = w->width();
970 wh = w->height();
972 *width = (unsigned int) ww;
973 *height = (unsigned int) wh;
976 void PanedWindowSetMinWidth(Widget w, unsigned int width)
978 w->setMinimumSize(width, 0);
981 //void *GetUserData(Widget w)
983 // void *udata = NULL;
984 // XtVaGetValues(w, XmNuserData, &udata, NULL);
986 // return udata;
988 void *WidgetGetUserData(Widget w)
990 void *udata = NULL;
991 udata = w->userData(0);
993 return udata;
996 //void SetUserData(Widget w, void *udata)
998 // XtVaSetValues(w, XmNuserData, udata, NULL);
1000 void WidgetSetUserData(Widget w, void *udata)
1002 w->setUserData(0, (QObjectUserData *) udata);
1006 #define MAX_PULLDOWN_LENGTH 30
1008 //OptionStructure *CreateOptionChoice(Widget parent, char *labelstr,
1009 // int ncols, int nchoices, OptionItem *items)
1011 // Arg args[2];
1012 // XmString str;
1013 // OptionStructure *retval;
1015 // retval = xcalloc(1, sizeof(OptionStructure));
1016 // if (!retval) {
1017 // return NULL;
1018 // }
1020 // XtSetArg(args[0], XmNpacking, XmPACK_COLUMN);
1021 // retval->pulldown = XmCreatePulldownMenu(parent, "pulldownMenu", args, 1);
1023 // retval->ncols = ncols;
1025 // UpdateOptionChoice(retval, nchoices, items);
1027 // str = XmStringCreateLocalized(labelstr);
1028 // XtSetArg(args[0], XmNlabelString, str);
1029 // XtSetArg(args[1], XmNsubMenuId, retval->pulldown);
1031 // retval->menu = XmCreateOptionMenu(parent, "optionMenu", args, 2);
1033 // XmStringFree(str);
1035 // XtManageChild(retval->menu);
1037 // return retval;
1039 OptionStructure *CreateOptionChoice(Widget parent, char *labelstr,
1040 int ncols, int nchoices, OptionItem *items)
1042 OptionStructure *retval;
1044 retval = (OptionStructure *) xcalloc(1, sizeof(OptionStructure));
1045 if (!retval) {
1046 return NULL;
1049 QWidget *widget = new QWidget(parent);
1051 QComboBox *comboBox = new QComboBox(widget);
1053 QStandardItemModel *model = new QStandardItemModel(comboBox);
1054 comboBox->setModel(model);
1056 QTableView *tableView = new QTableView(comboBox);
1057 tableView->horizontalHeader()->setVisible(false);
1058 tableView->verticalHeader()->setVisible(false);
1059 comboBox->setView(tableView);
1061 retval->pulldown = comboBox;
1062 retval->menu = comboBox;
1064 retval->ncols = ncols;
1066 UpdateOptionChoice(retval, nchoices, items);
1068 QLabel *label = new QLabel(widget);
1069 label->setText(labelstr);
1071 QHBoxLayout *hLayout = new QHBoxLayout(widget);
1072 hLayout->setContentsMargins(0,0,0,0);
1073 hLayout->addWidget(label);
1074 hLayout->addWidget(comboBox);
1076 QLayout *layout = parent->layout();
1077 if (layout != 0) {
1078 layout->addWidget(widget);
1081 return retval;
1084 //OptionStructure *CreateOptionChoiceVA(Widget parent, char *labelstr, ...)
1086 // OptionStructure *retval;
1087 // int nchoices = 0;
1088 // OptionItem *oi = NULL;
1089 // va_list var;
1090 // char *s;
1091 // int value;
1093 // va_start(var, labelstr);
1094 // while ((s = va_arg(var, char *)) != NULL) {
1095 // value = va_arg(var, int);
1096 // nchoices++;
1097 // oi = xrealloc(oi, nchoices*sizeof(OptionItem));
1098 // oi[nchoices - 1].value = value;
1099 // oi[nchoices - 1].label = copy_string(NULL, s);
1100 // }
1101 // va_end(var);
1103 // retval = CreateOptionChoice(parent, labelstr, 1, nchoices, oi);
1105 // while (nchoices) {
1106 // nchoices--;
1107 // xfree(oi[nchoices].label);
1108 // }
1109 // xfree(oi);
1111 // return retval;
1113 OptionStructure *CreateOptionChoiceVA(Widget parent, char *labelstr, ...)
1115 OptionStructure *retval;
1116 int nchoices = 0;
1117 OptionItem *oi = NULL;
1118 va_list var;
1119 char *s;
1120 int value;
1122 va_start(var, labelstr);
1123 while ((s = va_arg(var, char *)) != NULL) {
1124 value = va_arg(var, int);
1125 nchoices++;
1126 oi = (OptionItem *) xrealloc(oi, nchoices*sizeof(OptionItem));
1127 oi[nchoices - 1].value = value;
1128 oi[nchoices - 1].label = copy_string(NULL, s);
1130 va_end(var);
1132 retval = CreateOptionChoice(parent, labelstr, 1, nchoices, oi);
1134 while (nchoices) {
1135 nchoices--;
1136 xfree(oi[nchoices].label);
1138 xfree(oi);
1140 return retval;
1143 static void oc_int_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
1145 int value;
1147 OC_CBdata *cbdata = (OC_CBdata *) client_data;
1149 value = GetOptionChoice(cbdata->opt);
1150 cbdata->cbproc(cbdata->opt, value, cbdata->anydata);
1153 //void AddOptionChoiceCB(OptionStructure *opt, OC_CBProc cbproc, void *anydata)
1155 // OC_CBdata *cbdata;
1156 // unsigned int i;
1158 // cbdata = xmalloc(sizeof(OC_CBdata));
1160 // cbdata->opt = opt;
1161 // cbdata->cbproc = cbproc;
1162 // cbdata->anydata = anydata;
1164 // opt->cblist = xrealloc(opt->cblist, (opt->cbnum + 1)*sizeof(OC_CBdata *));
1165 // opt->cblist[opt->cbnum] = cbdata;
1166 // opt->cbnum++;
1168 // for (i = 0; i < opt->nchoices; i++) {
1169 // XtAddCallback(opt->options[i].widget, XmNactivateCallback,
1170 // oc_int_cb_proc, (XtPointer) cbdata);
1171 // }
1173 void AddOptionChoiceCB(OptionStructure *opt, OC_CBProc cbproc, void *anydata)
1175 OC_CBdata *cbdata;
1177 cbdata = (OC_CBdata*) xmalloc(sizeof(OC_CBdata));
1179 cbdata->opt = opt;
1180 cbdata->cbproc = cbproc;
1181 cbdata->anydata = anydata;
1183 opt->cblist = (OC_CBdata**) xrealloc(opt->cblist, (opt->cbnum + 1)*sizeof(OC_CBdata *));
1184 opt->cblist[opt->cbnum] = cbdata;
1185 opt->cbnum++;
1187 QtAddCallback(opt->pulldown, SIGNAL(activated(int)),
1188 oc_int_cb_proc, (XtPointer) cbdata);
1191 //void UpdateOptionChoice(OptionStructure *optp, int nchoices, OptionItem *items)
1193 // int i, nold, ncols, nw;
1194 // Widget *wlist;
1196 // nold = optp->nchoices;
1198 // if (optp->ncols == 0) {
1199 // ncols = 1;
1200 // } else {
1201 // ncols = optp->ncols;
1202 // }
1204 // /* Don't create too tall pulldowns */
1205 // if (nchoices > MAX_PULLDOWN_LENGTH*ncols) {
1206 // ncols = (nchoices + MAX_PULLDOWN_LENGTH - 1)/MAX_PULLDOWN_LENGTH;
1207 // }
1209 // XtVaSetValues(optp->pulldown, XmNnumColumns, ncols, NULL);
1211 // nw = nold - nchoices;
1212 // if (nw > 0) {
1213 // /* Unmanage extra items before destroying to speed the things up */
1214 // wlist = xmalloc(nw*sizeof(Widget));
1215 // for (i = nchoices; i < nold; i++) {
1216 // wlist[i - nchoices] = optp->options[i].widget;
1217 // }
1218 // XtUnmanageChildren(wlist, nw);
1219 // xfree(wlist);
1221 // for (i = nchoices; i < nold; i++) {
1222 // XtDestroyWidget(optp->options[i].widget);
1223 // }
1224 // }
1226 // optp->options = xrealloc(optp->options, nchoices*sizeof(OptionWidgetItem));
1227 // optp->nchoices = nchoices;
1229 // for (i = nold; i < nchoices; i++) {
1230 // unsigned int j;
1231 // optp->options[i].widget =
1232 // XmCreatePushButton(optp->pulldown, "button", NULL, 0);
1233 // for (j = 0; j < optp->cbnum; j++) {
1234 // OC_CBdata *cbdata = optp->cblist[j];
1235 // XtAddCallback(optp->options[i].widget, XmNactivateCallback,
1236 // oc_int_cb_proc, (XtPointer) cbdata);
1237 // }
1238 // }
1240 // for (i = 0; i < nchoices; i++) {
1241 // optp->options[i].value = items[i].value;
1242 // if (items[i].label != NULL) {
1243 // XmString str, ostr;
1244 // XtVaGetValues(optp->options[i].widget, XmNlabelString, &ostr, NULL);
1245 // str = XmStringCreateLocalized(items[i].label);
1246 // if (XmStringCompare(str, ostr) != True) {
1247 // XtVaSetValues(optp->options[i].widget, XmNlabelString, str, NULL);
1248 // }
1249 // XmStringFree(str);
1250 // }
1251 // }
1253 // nw = nchoices - nold;
1254 // if (nw > 0) {
1255 // wlist = xmalloc(nw*sizeof(Widget));
1256 // for (i = nold; i < nchoices; i++) {
1257 // wlist[i - nold] = optp->options[i].widget;
1258 // }
1259 // XtManageChildren(wlist, nw);
1260 // xfree(wlist);
1261 // }
1263 void UpdateOptionChoice(OptionStructure *optp, int nchoices, OptionItem *items)
1265 int i, nold, ncols, nw;
1266 QComboBox *comboBox = (QComboBox *) optp->pulldown;
1267 QStandardItemModel *model = (QStandardItemModel *) comboBox->model();
1268 QTableView *tableView = (QTableView *) comboBox->view();
1270 nold = optp->nchoices;
1272 if (optp->ncols == 0) {
1273 ncols = 1;
1274 } else {
1275 ncols = optp->ncols;
1278 /* Don't create too tall pulldowns */
1279 if (nchoices > MAX_PULLDOWN_LENGTH*ncols) {
1280 ncols = (nchoices + MAX_PULLDOWN_LENGTH - 1)/MAX_PULLDOWN_LENGTH;
1283 nw = nold - nchoices;
1284 if (nw > 0) {
1285 for (i = nchoices; i < nold; i++) {
1286 // TODO:
1287 // delete optp->options[i].widget;
1291 optp->options = (OptionWidgetItem *) xrealloc(optp->options, nchoices*sizeof(OptionWidgetItem));
1292 optp->nchoices = nchoices;
1294 int row = 0;
1295 int col = 0;
1296 int nrows = (int) ceil(nchoices/ncols);
1297 for (i = 0; i < nchoices; i++) {
1298 QStandardItem *item = new QStandardItem(items[i].label);
1299 optp->options[i].widget = (QWidget *) item;
1300 item->setData(QVariant(items[i].value));
1301 model->setItem(row, col, item);
1302 row++;
1303 if (row == nrows) {
1304 row = 0;
1305 col++;
1308 comboBox->setModelColumn(0);
1309 comboBox->setCurrentIndex(0);
1311 tableView->resizeColumnsToContents();
1312 int max = 0;
1313 for (int i = 0; i < nchoices; i++) {
1314 int size = tableView->horizontalHeader()->sectionSize(i);
1315 if (size > max) max = size;
1317 tableView->horizontalHeader()->setDefaultSectionSize(max);
1318 tableView->horizontalHeader()->resizeSections(QHeaderView::Fixed);
1319 tableView->resizeRowsToContents();
1320 tableView->setFixedWidth(tableView->horizontalHeader()->length());
1321 tableView->setFixedHeight(tableView->verticalHeader()->length());
1324 void UpdateBitmapOptionChoice(OptionStructure *optp, int nchoices,
1325 int width, int height, BitmapOptionItem *items)
1327 int nold, ncols;
1328 QComboBox *comboBox = (QComboBox *) optp->pulldown;
1329 QStandardItemModel *model = (QStandardItemModel *) comboBox->model();
1330 QTableView *tableView = (QTableView *) comboBox->view();
1332 nold = optp->nchoices;
1334 if (optp->ncols == 0) {
1335 ncols = 1;
1336 } else {
1337 ncols = optp->ncols;
1340 /* Don't create too tall pulldowns */
1341 if (nchoices > MAX_PULLDOWN_LENGTH*ncols) {
1342 ncols = (nchoices + MAX_PULLDOWN_LENGTH - 1)/MAX_PULLDOWN_LENGTH;
1345 optp->nchoices = nchoices;
1347 int row = 0;
1348 int col = 0;
1349 int nrows = (int) ceil(nchoices/ncols);
1350 QStandardItem *item;
1351 for (int i = 0; i < nchoices; i++) {
1352 if (items[i].bitmap != NULL) {
1353 QBitmap bitmap = QBitmap::fromData(QSize(width, height),
1354 items[i].bitmap, QImage::Format_MonoLSB);
1355 item = new QStandardItem;
1356 item->setIcon(QIcon(bitmap));
1357 } else {
1358 item = new QStandardItem("None");
1360 item->setData(QVariant(items[i].value));
1361 model->setItem(row, col, item);
1362 row++;
1363 if (row == nrows) {
1364 row = 0;
1365 col++;
1368 comboBox->setModelColumn(0);
1369 comboBox->setCurrentIndex(0);
1371 tableView->resizeColumnsToContents();
1372 tableView->resizeRowsToContents();
1374 tableView->setFixedWidth(tableView->columnViewportPosition(ncols - 1) +
1375 tableView->columnWidth(ncols - 1));
1376 tableView->setFixedHeight(tableView->rowViewportPosition(nrows - 1) +
1377 tableView->rowHeight(nrows - 1));
1379 //OptionStructure *CreateBitmapOptionChoice(Widget parent, char *labelstr, int ncols,
1380 // int nchoices, int width, int height, BitmapOptionItem *items)
1382 // X11Stuff *xstuff = gapp->gui->xstuff;
1383 // int i;
1384 // XmString str;
1385 // OptionStructure *retval;
1386 // Pixel fg, bg;
1387 // Pixmap ptmp;
1389 // retval = xcalloc(1, sizeof(OptionStructure));
1390 // if (!retval) {
1391 // return NULL;
1392 // }
1393 // retval->nchoices = nchoices;
1394 // retval->options = xmalloc(nchoices*sizeof(OptionWidgetItem));
1395 // if (retval->options == NULL) {
1396 // errmsg("Malloc error in CreateBitmapOptionChoice()");
1397 // XCFREE(retval);
1398 // return retval;
1399 // }
1402 // retval->pulldown = XmCreatePulldownMenu(parent, "pulldownMenu", NULL, 0);
1403 // XtVaSetValues(retval->pulldown,
1404 // XmNentryAlignment, XmALIGNMENT_CENTER,
1405 // NULL);
1407 // if (ncols > 0) {
1408 // XtVaSetValues(retval->pulldown,
1409 // XmNpacking, XmPACK_COLUMN,
1410 // XmNnumColumns, ncols,
1411 // NULL);
1412 // }
1414 // XtVaGetValues(retval->pulldown,
1415 // XmNforeground, &fg,
1416 // XmNbackground, &bg,
1417 // NULL);
1419 // for (i = 0; i < nchoices; i++) {
1420 // retval->options[i].value = items[i].value;
1421 // if (items[i].bitmap != NULL) {
1422 // ptmp = XCreatePixmapFromBitmapData(xstuff->disp, xstuff->root,
1423 // (char *) items[i].bitmap, width, height,
1424 // fg, bg, xstuff->depth);
1425 // retval->options[i].widget =
1426 // XtVaCreateWidget("pixButton", xmPushButtonWidgetClass,
1427 // retval->pulldown,
1428 // XmNlabelType, XmPIXMAP,
1429 // XmNlabelPixmap, ptmp,
1430 // NULL);
1431 // } else {
1432 // retval->options[i].widget =
1433 // XmCreatePushButton(retval->pulldown, "None", NULL, 0);
1434 // }
1436 // }
1437 // for (i = 0; i < nchoices; i++) {
1438 // XtManageChild(retval->options[i].widget);
1439 // }
1441 // retval->menu = XmCreateOptionMenu(parent, "optionMenu", NULL, 0);
1442 // str = XmStringCreateLocalized(labelstr);
1443 // XtVaSetValues(retval->menu,
1444 // XmNlabelString, str,
1445 // XmNsubMenuId, retval->pulldown,
1446 // NULL);
1447 // XmStringFree(str);
1448 // XtManageChild(retval->menu);
1450 // return retval;
1452 OptionStructure *CreateBitmapOptionChoice(Widget parent, char *labelstr, int ncols,
1453 int nchoices, int width, int height, BitmapOptionItem *items)
1455 OptionStructure *retval;
1457 retval = (OptionStructure *) xcalloc(1, sizeof(OptionStructure));
1458 if (!retval) {
1459 return NULL;
1461 retval->nchoices = nchoices;
1463 QWidget *widget = new QWidget(parent);
1465 QComboBox *comboBox = new QComboBox(widget);
1467 QStandardItemModel *model = new QStandardItemModel(comboBox);
1468 comboBox->setModel(model);
1470 QTableView *tableView = new QTableView(comboBox);
1471 tableView->horizontalHeader()->setVisible(false);
1472 tableView->verticalHeader()->setVisible(false);
1473 comboBox->setView(tableView);
1475 comboBox->setIconSize(QSize(width, height));
1477 retval->pulldown = comboBox;
1478 retval->menu = comboBox;
1480 retval->ncols = ncols;
1482 UpdateBitmapOptionChoice(retval, nchoices, width, height, items);
1484 QLabel *label = new QLabel(widget);
1485 label->setText(labelstr);
1487 QHBoxLayout *hLayout = new QHBoxLayout(widget);
1488 hLayout->setContentsMargins(0,0,0,0);
1489 hLayout->addWidget(label);
1490 hLayout->addWidget(comboBox);
1492 QLayout *layout = parent->layout();
1493 if (layout != 0) {
1494 layout->addWidget(widget);
1497 return retval;
1500 //void UpdateCharOptionChoice(OptionStructure *opt, int font)
1502 // int *old_font;
1503 // old_font = (int *) GetUserData(opt->menu);
1504 // if (*old_font != font) {
1505 // int i, csize = 24;
1506 // for (i = 0; i < opt->nchoices; i++) {
1507 // Widget w = opt->options[i].widget;
1508 // Pixmap ptmp = char_to_pixmap(opt->pulldown, font, (char) i, csize);
1509 // XtVaSetValues(w, XmNlabelPixmap, ptmp, NULL);
1510 // SetSensitive(w, ptmp ? TRUE:FALSE);
1511 // }
1512 // *old_font = font;
1513 // }
1515 void UpdateCharOptionChoice(OptionStructure *opt, int font)
1517 int *old_font;
1518 old_font = (int *) WidgetGetUserData(opt->menu);
1519 if (*old_font != font) {
1520 int i, csize = 24;
1521 for (i = 0; i < opt->nchoices; i++) {
1522 QStandardItem *item = (QStandardItem *) opt->options[i].widget;
1523 QPixmap *pixmap = (QPixmap *) char_to_pixmap(opt->pulldown, font, (char) i, csize);
1524 if (pixmap) {
1525 item->setIcon(QIcon(*pixmap));
1527 item->setEnabled(pixmap ? true:false);
1529 *old_font = font;
1533 static unsigned char dummy_bits[] = {
1534 0x00, 0x00, 0x00, 0x00, 0xec, 0x2e, 0x04, 0x20, 0x00, 0x20, 0x04, 0x00,
1535 0x04, 0x20, 0x04, 0x20, 0x00, 0x20, 0x04, 0x00, 0x04, 0x20, 0x04, 0x20,
1536 0x00, 0x20, 0xdc, 0x1d, 0x00, 0x00, 0x00, 0x00};
1538 //OptionStructure *CreateCharOptionChoice(Widget parent, char *s)
1540 // X11Stuff *xstuff = gapp->gui->xstuff;
1541 // int i;
1542 // int ncols = 16, nchoices = 256;
1543 // XmString str;
1544 // OptionStructure *retval;
1545 // long bg, fg;
1546 // Pixmap ptmp;
1547 // int *fontid;
1549 // retval = xcalloc(1, sizeof(OptionStructure));
1550 // if (retval == NULL) {
1551 // errmsg("Malloc error in CreateBitmapOptionChoice()");
1552 // }
1553 // retval->nchoices = nchoices;
1554 // retval->options = xmalloc(nchoices*sizeof(OptionWidgetItem));
1555 // if (retval->options == NULL) {
1556 // errmsg("Malloc error in CreateBitmapOptionChoice()");
1557 // XCFREE(retval);
1558 // return retval;
1559 // }
1561 // retval->pulldown = XmCreatePulldownMenu(parent, "pulldownMenu", NULL, 0);
1562 // XtVaSetValues(retval->pulldown,
1563 // XmNentryAlignment, XmALIGNMENT_CENTER,
1564 // XmNpacking, XmPACK_COLUMN,
1565 // XmNorientation, XmHORIZONTAL,
1566 // XmNnumColumns, ncols,
1567 // NULL);
1569 // XtVaGetValues(retval->pulldown,
1570 // XmNforeground, &fg,
1571 // XmNbackground, &bg,
1572 // NULL);
1573 // ptmp = XCreatePixmapFromBitmapData(xstuff->disp,
1574 // xstuff->root, (char *) dummy_bits, 16, 16, fg, bg, xstuff->depth);
1576 // for (i = 0; i < nchoices; i++) {
1577 // retval->options[i].value = (char) i;
1578 // retval->options[i].widget =
1579 // XtVaCreateWidget("pixButton", xmPushButtonWidgetClass,
1580 // retval->pulldown,
1581 // XmNlabelType, XmPIXMAP,
1582 // XmNlabelPixmap, ptmp,
1583 // NULL);
1584 // }
1585 // for (i = 0; i < nchoices; i++) {
1586 // XtManageChild(retval->options[i].widget);
1587 // }
1589 // retval->menu = XmCreateOptionMenu(parent, "optionMenu", NULL, 0);
1590 // str = XmStringCreateLocalized(s);
1591 // XtVaSetValues(retval->menu,
1592 // XmNlabelString, str,
1593 // XmNsubMenuId, retval->pulldown,
1594 // NULL);
1595 // XmStringFree(str);
1596 // XtManageChild(retval->menu);
1598 // fontid = xmalloc(SIZEOF_INT);
1599 // *fontid = -1;
1600 // SetUserData(retval->menu, fontid);
1602 // return retval;
1604 OptionStructure *CreateCharOptionChoice(Widget parent, char *s)
1606 int ncols = 16, nchoices = 256;
1607 OptionStructure *retval;
1608 int *fontid;
1610 retval = (OptionStructure *) xcalloc(1, sizeof(OptionStructure));
1611 if (retval == NULL) {
1612 errmsg("Malloc error in CreateBitmapOptionChoice()");
1614 retval->nchoices = nchoices;
1615 retval->options = (OptionWidgetItem *) xmalloc(nchoices*sizeof(OptionWidgetItem));
1616 if (retval->options == NULL) {
1617 errmsg("Malloc error in CreateBitmapOptionChoice()");
1618 XCFREE(retval);
1619 return retval;
1622 QWidget *widget = new QWidget(parent);
1624 QComboBox *comboBox = new QComboBox(widget);
1626 QStandardItemModel *model = new QStandardItemModel(comboBox);
1627 comboBox->setModel(model);
1629 QTableView *tableView = new QTableView(comboBox);
1630 tableView->horizontalHeader()->setVisible(false);
1631 tableView->verticalHeader()->setVisible(false);
1632 tableView->horizontalHeader()->setDefaultSectionSize(24);
1633 tableView->verticalHeader()->setDefaultSectionSize(24);
1634 comboBox->setView(tableView);
1636 comboBox->setIconSize(QSize(24, 24));
1638 retval->pulldown = comboBox;
1639 retval->menu = comboBox;
1641 retval->ncols = ncols;
1643 int row = 0;
1644 int col = 0;
1645 int nrows = (int) ceil(nchoices/ncols);
1646 QStandardItem *item;
1647 for (int i = 0; i < nchoices; i++) {
1648 retval->options[i].value = (char) i;
1649 QBitmap bitmap = QBitmap::fromData(QSize(16, 16),
1650 dummy_bits, QImage::Format_MonoLSB);
1651 item = new QStandardItem;
1652 item->setIcon(QIcon(bitmap));
1653 item->setData(QVariant((char) i));
1654 model->setItem(row, col, item);
1655 retval->options[i].widget = (QWidget *) item;
1656 col++;
1657 if (col == ncols) {
1658 col = 0;
1659 row++;
1663 tableView->setMinimumWidth(tableView->columnViewportPosition(ncols - 1) +
1664 tableView->columnWidth(ncols - 1));
1665 tableView->setMinimumHeight(tableView->rowViewportPosition(nrows - 1) +
1666 tableView->rowHeight(nrows - 1));
1668 QLabel *label = new QLabel(widget);
1669 label->setText(s);
1671 QHBoxLayout *hLayout = new QHBoxLayout(widget);
1672 hLayout->setContentsMargins(0,0,0,0);
1673 hLayout->addWidget(label);
1674 hLayout->addWidget(comboBox);
1676 QLayout *layout = parent->layout();
1677 if (layout != 0) {
1678 layout->addWidget(widget);
1681 fontid = (int *) xmalloc(SIZEOF_INT);
1682 *fontid = -1;
1683 WidgetSetUserData(retval->menu, fontid);
1685 return retval;
1688 //void SetOptionChoice(OptionStructure *opt, int value)
1690 // int i;
1691 // Arg a;
1693 // if (opt->options == NULL || opt->nchoices <= 0) {
1694 // return;
1695 // }
1697 // for (i = 0; i < opt->nchoices; i++) {
1698 // if (opt->options[i].value == value) {
1699 // XtSetArg(a, XmNmenuHistory, opt->options[i].widget);
1700 // XtSetValues(opt->menu, &a, 1);
1701 // return;
1702 // }
1703 // }
1705 // errmsg("Value not found in SetOptionChoice()");
1707 void SetOptionChoice(OptionStructure *opt, int value)
1709 int ncols;
1711 if (QComboBox *comboBox = qobject_cast<QComboBox *>(opt->pulldown)) {
1712 QStandardItemModel *model = (QStandardItemModel *) comboBox->model();
1713 QTableView *tableView = (QTableView *) comboBox->view();
1715 if (opt->ncols == 0) {
1716 ncols = 1;
1717 } else {
1718 ncols = opt->ncols;
1721 int row = 0;
1722 int col = 0;
1723 int nrows = (int) ceil(opt->nchoices/ncols);
1724 for (int i = 0; i < opt->nchoices; i++) {
1725 QModelIndex index = model->index(row, col);
1726 QVariant v = index.data(Qt::UserRole + 1);
1727 if (v.toInt() == value) {
1728 comboBox->setModelColumn(col);
1729 comboBox->setCurrentIndex(row);
1730 tableView->setCurrentIndex(index);
1731 return;
1733 row++;
1734 if (row == nrows) {
1735 row = 0;
1736 col++;
1741 errmsg("Value not found in SetOptionChoice()");
1744 //int GetOptionChoice(OptionStructure *opt)
1746 // Arg a;
1747 // Widget warg;
1748 // int i;
1750 // if (opt->options == NULL || opt->nchoices <= 0) {
1751 // errmsg("Internal error in GetOptionChoice()");
1752 // return 0;
1753 // }
1755 // XtSetArg(a, XmNmenuHistory, &warg);
1756 // XtGetValues(opt->menu, &a, 1);
1758 // for (i = 0; i < opt->nchoices; i++) {
1759 // if (opt->options[i].widget == warg) {
1760 // return(opt->options[i].value);
1761 // }
1762 // }
1763 // errmsg("Internal error in GetOptionChoice()");
1764 // return 0;
1766 int GetOptionChoice(OptionStructure *opt)
1768 if (QComboBox *comboBox = qobject_cast<QComboBox *>(opt->pulldown)) {
1769 QTableView *tableView = (QTableView *) comboBox->view();
1771 QStandardItemModel *model = (QStandardItemModel *) comboBox->model();
1772 QModelIndex currentIndex = tableView->currentIndex();
1773 int row = currentIndex.row();
1774 int col = currentIndex.column();
1776 QModelIndex index = model->index(row, col);
1777 QVariant v = index.data(Qt::UserRole + 1);
1778 int i = v.toInt();
1779 return i;
1782 errmsg("Internal error in GetOptionChoice()");
1783 return 0;
1786 //typedef struct {
1787 // SpinStructure *spin;
1788 // Spin_CBProc cbproc;
1789 // void *anydata;
1790 // XtIntervalId timeout_id;
1791 //} Spin_CBdata;
1792 typedef struct {
1793 SpinStructure *spin;
1794 Spin_CBProc cbproc;
1795 void *anydata;
1796 } Spin_CBdata;
1798 //typedef struct {
1799 // Widget scale;
1800 // Scale_CBProc cbproc;
1801 // void *anydata;
1802 //} Scale_CBdata;
1805 //static char list_translation_table[] = "\
1806 // Ctrl<Key>E: list_activate_action()\n\
1807 // Ctrl<Key>A: list_selectall_action()\n\
1808 // Ctrl<Key>U: list_unselectall_action()\n\
1809 // Ctrl<Key>I: list_invertselection_action()";
1811 //static void list_selectall(Widget list)
1813 // XtCallActionProc(list, "ListKbdSelectAll", NULL, NULL, 0);
1815 static void list_selectall(Widget list)
1817 QListWidget *listWidget = (QListWidget*) list;
1818 listWidget->selectAll();
1821 //static void list_unselectall(Widget list)
1823 // XmListDeselectAllItems(list);
1825 static void list_unselectall(Widget list)
1827 QListWidget *listWidget = (QListWidget*) list;
1828 listWidget->clearSelection();
1831 //static void list_invertselection(Widget list)
1833 // X11Stuff *xstuff = gapp->gui->xstuff;
1834 // int i, n;
1835 // unsigned char selection_type_save;
1837 // XtVaGetValues(list,
1838 // XmNselectionPolicy, &selection_type_save,
1839 // XmNitemCount, &n,
1840 // NULL);
1841 // if (selection_type_save == XmSINGLE_SELECT) {
1842 // XBell(xstuff->disp, 50);
1843 // return;
1844 // }
1846 // XtVaSetValues(list, XmNselectionPolicy, XmMULTIPLE_SELECT, NULL);
1847 // for (i = 0; i < n; i++) {
1848 // XmListSelectPos(list, i, False);
1849 // }
1850 // XtVaSetValues(list, XmNselectionPolicy, selection_type_save, NULL);
1852 static void list_invertselection(Widget list)
1854 int i, n;
1855 QListWidget *listWidget = (QListWidget*) list;
1856 QListWidgetItem *item;
1857 QAbstractItemView::SelectionMode selection_type_save;
1859 selection_type_save = listWidget->selectionMode();
1860 n = listWidget->count();
1862 if (selection_type_save == QAbstractItemView::SingleSelection) {
1863 QApplication::beep();
1864 qDebug("beep");
1865 return;
1868 listWidget->setSelectionMode(QAbstractItemView::MultiSelection);
1869 for (i = 0; i < n; i++) {
1870 item = listWidget->item(i);
1871 item->setSelected(true);
1873 listWidget->setSelectionMode(selection_type_save);
1876 //static int list_get_selected_count(Widget list)
1878 // int n;
1879 //#if XmVersion < 2000
1880 // int *selected;
1881 // if (XmListGetSelectedPos(list, &selected, &n) != True) {
1882 // n = 0;
1883 // } else {
1884 // XFree(selected);
1885 // }
1886 //#else
1887 // XtVaGetValues(list, XmNselectedPositionCount, &n, NULL);
1888 //#endif
1889 // return n;
1891 static int list_get_selected_count(Widget list)
1893 QListWidget *listWidget = (QListWidget*) list;
1895 return listWidget->selectedItems().size();
1898 //static void list_activate_action(Widget w, XEvent *e, String *par, Cardinal *npar)
1900 // XtCallActionProc(w, "ListKbdActivate", NULL, NULL, 0);
1903 //static void list_selectall_action(Widget w, XEvent *e, String *par, Cardinal *npar)
1905 // list_selectall(w);
1908 //static void list_unselectall_action(Widget w, XEvent *e, String *par, Cardinal *npar)
1910 // list_unselectall(w);
1913 //static void list_invertselection_action(Widget w, XEvent *e, String *par,
1914 // Cardinal *npar)
1916 // list_invertselection(w);
1919 //ListStructure *CreateListChoice(Widget parent, char *labelstr, int type,
1920 // int nvisible, int nchoices, OptionItem *items)
1922 // Arg args[4];
1923 // Widget lab;
1924 // ListStructure *retval;
1926 // retval = xmalloc(sizeof(ListStructure));
1927 // retval->rc = XmCreateRowColumn(parent, "rcList", NULL, 0);
1928 // AddHelpCB(retval->rc, "doc/UsersGuide.html#list-selector");
1930 // lab = XmCreateLabel(retval->rc, labelstr, NULL, 0);
1931 // XtManageChild(lab);
1933 // XtSetArg(args[0], XmNlistSizePolicy, XmCONSTANT);
1934 // XtSetArg(args[1], XmNscrollBarDisplayPolicy, XmSTATIC);
1935 // if (type == LIST_TYPE_SINGLE) {
1936 // XtSetArg(args[2], XmNselectionPolicy, XmSINGLE_SELECT);
1937 // } else {
1938 // XtSetArg(args[2], XmNselectionPolicy, XmEXTENDED_SELECT);
1939 // }
1940 // XtSetArg(args[3], XmNvisibleItemCount, nvisible);
1941 // retval->list = XmCreateScrolledList(retval->rc, "listList", args, 4);
1942 // retval->values = NULL;
1944 // XtOverrideTranslations(retval->list,
1945 // XtParseTranslationTable(list_translation_table));
1947 // UpdateListChoice(retval, nchoices, items);
1949 // XtManageChild(retval->list);
1951 // XtManageChild(retval->rc);
1953 // return retval;
1955 ListStructure *CreateListChoice(Widget parent, char *labelstr, int type,
1956 int nvisible, int nchoices, OptionItem *items)
1958 ListStructure *retval;
1960 retval = (ListStructure*) xmalloc(sizeof(ListStructure));
1962 QWidget *widget = new QWidget(parent);
1963 retval->rc = widget;
1964 AddHelpCB(retval->rc, "doc/UsersGuide.html#list-selector");
1966 QLabel *label = new QLabel(widget);
1967 label->setText(labelstr);
1969 QListWidget *listWidget = new QListWidget(widget);
1970 listWidget->setUniformItemSizes(true);
1971 QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
1972 listWidget->setSizePolicy(sizePolicy);
1974 if (type == LIST_TYPE_SINGLE) {
1975 listWidget->setSelectionMode(QAbstractItemView::SingleSelection);
1976 } else {
1977 listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
1980 //TODO: fix spacing of nvisible
1981 listWidget->setMaximumHeight(nvisible * 15 + 1);
1982 //XtSetArg(args[3], XmNvisibleItemCount, nvisible);
1983 //retval->list = XmCreateScrolledList(retval->rc, "listList", args, 4);
1985 retval->list = listWidget;
1986 retval->values = NULL;
1988 //TODO: add acelerators
1989 //XtOverrideTranslations(retval->list,
1990 // XtParseTranslationTable(list_translation_table));
1992 UpdateListChoice(retval, nchoices, items);
1994 QVBoxLayout *vBoxLayout = new QVBoxLayout;
1995 vBoxLayout->setContentsMargins(0,0,0,0);
1996 vBoxLayout->addWidget(label);
1997 vBoxLayout->addWidget(listWidget);
1998 widget->setLayout(vBoxLayout);
2000 QLayout *layout = parent->layout();
2001 if (layout != 0) {
2002 layout->addWidget(widget);
2005 return retval;
2008 //void UpdateListChoice(ListStructure *listp, int nchoices, OptionItem *items)
2010 // int i, nsel;
2011 // int *selvalues;
2012 // XmString str;
2014 // if (listp == NULL) {
2015 // return;
2016 // }
2018 // nsel = GetListChoices(listp, &selvalues);
2020 // listp->nchoices = nchoices;
2021 // listp->values = xrealloc(listp->values, nchoices*SIZEOF_INT);
2022 // for (i = 0; i < nchoices; i++) {
2023 // listp->values[i] = items[i].value;
2024 // }
2026 // XmListDeleteAllItems(listp->list);
2027 // for (i = 0; i < nchoices; i++) {
2028 // str = XmStringCreateLocalized(items[i].label);
2029 // XmListAddItemUnselected(listp->list, str, 0);
2030 // XmStringFree(str);
2031 // }
2032 // SelectListChoices(listp, nsel, selvalues);
2033 // if (nsel > 0) {
2034 // xfree(selvalues);
2035 // }
2037 void UpdateListChoice(ListStructure *listp, int nchoices, OptionItem *items)
2039 int i, nsel;
2040 int *selvalues;
2042 if (listp == NULL) {
2043 return;
2046 QListWidget *listWidget = (QListWidget*) listp->list;
2048 nsel = GetListChoices(listp, &selvalues);
2050 listp->nchoices = nchoices;
2051 listp->values = (int*) xrealloc(listp->values, nchoices*SIZEOF_INT);
2052 for (i = 0; i < nchoices; i++) {
2053 listp->values[i] = items[i].value;
2056 listWidget->clear();
2057 for (i = 0; i < nchoices; i++) {
2058 QListWidgetItem *item = new QListWidgetItem(items[i].label);
2059 item->setSizeHint(QSize(0,14));
2060 listWidget->addItem(item);
2062 SelectListChoices(listp, nsel, selvalues);
2063 if (nsel > 0) {
2064 xfree(selvalues);
2068 //int SelectListChoice(ListStructure *listp, int choice)
2070 // int top, visible;
2071 // int i = 0;
2073 // while (i < listp->nchoices && listp->values[i] != choice) {
2074 // i++;
2075 // }
2076 // if (i < listp->nchoices) {
2077 // i++;
2078 // XmListDeselectAllItems(listp->list);
2079 // XmListSelectPos(listp->list, i, True);
2080 // XtVaGetValues(listp->list, XmNtopItemPosition, &top,
2081 // XmNvisibleItemCount, &visible,
2082 // NULL);
2083 // if (i < top) {
2084 // XmListSetPos(listp->list, i);
2085 // } else if (i >= top + visible) {
2086 // XmListSetBottomPos(listp->list, i);
2087 // }
2089 // return RETURN_SUCCESS;
2090 // } else {
2091 // return RETURN_FAILURE;
2092 // }
2094 int SelectListChoice(ListStructure *listp, int choice)
2096 int top, visible;
2097 int i = 0;
2098 QListWidgetItem *item;
2100 QListWidget *listWidget = (QListWidget*) listp->list;
2102 while (i < listp->nchoices && listp->values[i] != choice) {
2103 i++;
2105 if (i < listp->nchoices) {
2106 i++;
2107 listWidget->clearSelection();
2108 // XmListDeselectAllItems(listp->list);
2109 item = listWidget->item(i);
2110 item->setSelected(true);
2111 // XmListSelectPos(listp->list, i, True);
2112 // XtVaGetValues(listp->list, XmNtopItemPosition, &top,
2113 // XmNvisibleItemCount, &visible,
2114 // NULL);
2115 //TODO:
2116 // if (i < top) {
2117 // XmListSetPos(listp->list, i);
2118 // } else if (i >= top + visible) {
2119 // XmListSetBottomPos(listp->list, i);
2120 // }
2122 return RETURN_SUCCESS;
2123 } else {
2124 return RETURN_FAILURE;
2128 //void SelectListChoices(ListStructure *listp, int nchoices, int *choices)
2130 // int i = 0, j;
2131 // unsigned char selection_type_save;
2132 // int bottom, visible;
2134 // XtVaGetValues(listp->list, XmNselectionPolicy, &selection_type_save, NULL);
2135 // XtVaSetValues(listp->list, XmNselectionPolicy, XmMULTIPLE_SELECT, NULL);
2137 // XmListDeselectAllItems(listp->list);
2138 // for (j = 0; j < nchoices; j++) {
2139 // i = 0;
2140 // while (i < listp->nchoices && listp->values[i] != choices[j]) {
2141 // i++;
2142 // }
2143 // if (i < listp->nchoices) {
2144 // i++;
2145 // XmListSelectPos(listp->list, i, True);
2146 // }
2147 // }
2149 // if (nchoices > 0) {
2150 // /* Rewind list so the last choice is always visible */
2151 // XtVaGetValues(listp->list, XmNtopItemPosition, &bottom,
2152 // XmNvisibleItemCount, &visible,
2153 // NULL);
2154 // if (i > bottom) {
2155 // XmListSetBottomPos(listp->list, i);
2156 // } else if (i <= bottom - visible) {
2157 // XmListSetPos(listp->list, i);
2158 // }
2159 // }
2161 // XtVaSetValues(listp->list, XmNselectionPolicy, selection_type_save, NULL);
2163 void SelectListChoices(ListStructure *listp, int nchoices, int *choices)
2165 int i = 0, j;
2166 QAbstractItemView::SelectionMode selection_type_save;
2167 QListWidgetItem *item;
2168 int bottom, visible;
2170 QListWidget *listWidget = (QListWidget*) listp->list;
2172 selection_type_save = listWidget->selectionMode();
2173 listWidget->setSelectionMode(QAbstractItemView::MultiSelection);
2174 //XtVaGetValues(listp->list, XmNselectionPolicy, &selection_type_save, NULL);
2175 //XtVaSetValues(listp->list, XmNselectionPolicy, XmMULTIPLE_SELECT, NULL);
2177 listWidget->clearSelection();
2178 //XmListDeselectAllItems(listp->list);
2179 for (j = 0; j < nchoices; j++) {
2180 i = 0;
2181 while (i < listp->nchoices && listp->values[i] != choices[j]) {
2182 i++;
2184 if (i < listp->nchoices) {
2185 item = listWidget->item(i);
2186 item->setSelected(true);
2187 i++;
2189 //XmListSelectPos(listp->list, i, True);
2193 //TODO:
2194 //if (nchoices > 0) {
2195 /* Rewind list so the last choice is always visible */
2196 //XtVaGetValues(listp->list, XmNtopItemPosition, &bottom,
2197 // XmNvisibleItemCount, &visible,
2198 // NULL);
2199 // if (i > bottom) {
2200 // XmListSetBottomPos(listp->list, i);
2201 // } else if (i <= bottom - visible) {
2202 // XmListSetPos(listp->list, i);
2203 // }
2204 // }
2206 listWidget->setSelectionMode(selection_type_save);
2207 //XtVaSetValues(listp->list, XmNselectionPolicy, selection_type_save, NULL);
2210 //int GetListChoices(ListStructure *listp, int **values)
2212 // int i, n;
2214 // if (XmListGetSelectedPos(listp->list, values, &n) != True) {
2215 // return 0;
2216 // }
2218 // for (i = 0; i < n; i++) {
2219 // (*values)[i] = listp->values[(*values)[i] - 1];
2220 // }
2222 // return n;
2224 int GetListChoices(ListStructure *listp, int **values)
2226 int i, n, nrow;
2228 QListWidget *listWidget = (QListWidget*) listp->list;
2229 QList<QListWidgetItem *> list = listWidget->selectedItems();
2231 n = list.size();
2233 if (n > 0) {
2234 *values = (int*) xmalloc(n*SIZEOF_INT);
2237 for (i = 0; i < n; i++) {
2238 nrow = listWidget->row(list.at(i));
2239 (*values)[i] = listp->values[nrow];
2242 return n;
2245 int GetSingleListChoice(ListStructure *listp, int *value)
2247 int n, *values, retval;
2249 n = GetListChoices(listp, &values);
2250 if (n == 1) {
2251 *value = values[0];
2252 retval = RETURN_SUCCESS;
2253 } else {
2254 retval = RETURN_FAILURE;
2256 if (n > 0) {
2257 xfree(values);
2259 return retval;
2262 //int GetListSelectedCount(ListStructure *listp)
2264 // int count;
2265 // XtVaGetValues(listp->list, XmNselectedItemCount, &count, NULL);
2266 // return count;
2270 typedef struct {
2271 ListStructure *listp;
2272 List_CBProc cbproc;
2273 void *anydata;
2274 } List_CBdata;
2276 static void list_int_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
2278 int n, *values;
2279 List_CBdata *cbdata = (List_CBdata *) client_data;
2281 n = GetListChoices(cbdata->listp, &values);
2283 cbdata->cbproc(cbdata->listp, n, values, cbdata->anydata);
2285 if (n > 0) {
2286 xfree(values);
2290 //void AddListChoiceCB(ListStructure *listp, List_CBProc cbproc, void *anydata)
2292 // List_CBdata *cbdata;
2294 // cbdata = xmalloc(sizeof(List_CBdata));
2295 // cbdata->listp = listp;
2296 // cbdata->cbproc = (List_CBProc) cbproc;
2297 // cbdata->anydata = anydata;
2298 // XtAddCallback(listp->list,
2299 // XmNsingleSelectionCallback, list_int_cb_proc, (XtPointer) cbdata);
2300 // XtAddCallback(listp->list,
2301 // XmNmultipleSelectionCallback, list_int_cb_proc, (XtPointer) cbdata);
2302 // XtAddCallback(listp->list,
2303 // XmNextendedSelectionCallback, list_int_cb_proc, (XtPointer) cbdata);
2305 void AddListChoiceCB(ListStructure *listp, List_CBProc cbproc, void *anydata)
2307 List_CBdata *cbdata;
2309 cbdata = (List_CBdata *) xmalloc(sizeof(List_CBdata));
2310 cbdata->listp = listp;
2311 cbdata->cbproc = (List_CBProc) cbproc;
2312 cbdata->anydata = anydata;
2314 QtAddCallback(listp->list, SIGNAL(itemClicked(QListWidgetItem *)),
2315 list_int_cb_proc, (XtPointer) cbdata);
2320 #define SS_HIDE_CB 0
2321 #define SS_SHOW_CB 1
2322 #define SS_DELETE_CB 2
2323 #define SS_DUPLICATE_CB 3
2324 #define SS_BRING_TO_FRONT_CB 4
2325 #define SS_SEND_TO_BACK_CB 5
2326 #define SS_MOVE_UP_CB 6
2327 #define SS_MOVE_DOWN_CB 7
2329 static char *default_storage_labeling_proc(Quark *q, unsigned int *rid)
2331 qDebug("labeling_proc");
2332 char *buf;
2334 if (!q) {
2335 return NULL;
2338 buf = (char *) xmalloc(strlen(QIDSTR(q)) + 128);
2339 if (!buf) {
2340 return NULL;
2343 sprintf(buf, "Quark \"%s\"", QIDSTR(q));
2345 (*rid)++;
2347 return buf;
2350 typedef struct {
2351 StorageStructure *ss;
2352 unsigned int rid;
2353 } storage_traverse_data;
2355 //static int traverse_hook(Quark *q, void *udata, QTraverseClosure *closure)
2357 // char *s;
2358 // storage_traverse_data *stdata = (storage_traverse_data *) udata;
2359 // StorageStructure *ss = stdata->ss;
2361 // s = ss->labeling_proc(q, &stdata->rid);
2362 // if (s) {
2363 // char buf[16], *sbuf;
2364 // XmString str;
2366 // ss->values = xrealloc(ss->values, SIZEOF_VOID_P*(ss->nchoices + 1));
2367 // ss->values[ss->nchoices++] = q;
2369 // sprintf(buf, "(%c) ", quark_is_active(q) ? '+':'-');
2370 // sbuf = copy_string(NULL, buf);
2371 // sbuf = concat_strings(sbuf, s);
2372 // xfree(s);
2374 // str = XmStringCreateLocalized(sbuf);
2375 // xfree(sbuf);
2377 // XmListAddItemUnselected(ss->list, str, 0);
2378 // XmStringFree(str);
2379 // }
2381 // return TRUE;
2383 static int traverse_hook(Quark *q, void *udata, QTraverseClosure *closure)
2385 char *s;
2386 storage_traverse_data *stdata = (storage_traverse_data *) udata;
2387 StorageStructure *ss = stdata->ss;
2389 s = ss->labeling_proc(q, &stdata->rid);
2390 if (s) {
2391 char buf[16], *sbuf;
2392 //XmString str;
2394 ss->values = (Quark**) xrealloc(ss->values, SIZEOF_VOID_P*(ss->nchoices + 1));
2395 ss->values[ss->nchoices++] = q;
2397 sprintf(buf, "(%c) ", quark_is_active(q) ? '+':'-');
2398 sbuf = copy_string(NULL, buf);
2399 sbuf = concat_strings(sbuf, s);
2400 xfree(s);
2402 QListWidget *listWidget = (QListWidget*) ss->list;
2403 QListWidgetItem *item = new QListWidgetItem(sbuf);
2404 item->setSizeHint(QSize(0,14));
2405 listWidget->addItem(item);
2406 //str = XmStringCreateLocalized(sbuf);
2407 xfree(sbuf);
2409 //XmListAddItemUnselected(ss->list, str, 0);
2410 //XmStringFree(str);
2413 return TRUE;
2416 //static void storage_popup(Widget parent,
2417 // XtPointer closure, XEvent *event, Boolean *cont)
2419 // XButtonPressedEvent *e = (XButtonPressedEvent *) event;
2420 // StorageStructure *ss = (StorageStructure *) closure;
2421 // Widget popup = ss->popup;
2422 // int n, selected;
2424 // if (e->button != 3) {
2425 // return;
2426 // }
2428 // /* don't post menu if governor selection isn't single */
2429 // if (ss->governor && list_get_selected_count(ss->governor->list) != 1) {
2430 // return;
2431 // }
2433 // n = list_get_selected_count(ss->list);
2435 // if (n != 0) {
2436 // selected = TRUE;
2437 // } else {
2438 // selected = FALSE;
2439 // }
2441 // SetSensitive(ss->popup_hide_bt, selected);
2442 // SetSensitive(ss->popup_show_bt, selected);
2443 // SetSensitive(ss->popup_delete_bt, selected);
2444 // SetSensitive(ss->popup_duplicate_bt, selected);
2445 // SetSensitive(ss->popup_bring_to_front_bt, selected);
2446 // SetSensitive(ss->popup_send_to_back_bt, selected);
2447 // SetSensitive(ss->popup_move_up_bt, selected);
2448 // SetSensitive(ss->popup_move_down_bt, selected);
2450 // SetSensitive(ss->popup_properties_bt, n == 1);
2452 // if (ss->popup_cb) {
2453 // ss->popup_cb(ss, n);
2454 // }
2456 // XmMenuPosition(popup, e);
2457 // XtManageChild(popup);
2459 static void storage_popup(Widget w, XtPointer client_data, XtPointer call_data)
2461 StorageStructure *ss = (StorageStructure *) client_data;
2462 QMenu *popup = (QMenu*) ss->popup;
2463 int n, selected;
2465 //if (e->button != 3) {
2466 // return;
2469 /* don't post menu if governor selection isn't single */
2470 if (ss->governor && list_get_selected_count(ss->governor->list) != 1) {
2471 return;
2474 n = list_get_selected_count(ss->list);
2476 if (n != 0) {
2477 selected = TRUE;
2478 } else {
2479 selected = FALSE;
2482 WidgetSetSensitive(ss->popup_hide_bt, selected);
2483 WidgetSetSensitive(ss->popup_show_bt, selected);
2484 WidgetSetSensitive(ss->popup_delete_bt, selected);
2485 WidgetSetSensitive(ss->popup_duplicate_bt, selected);
2486 WidgetSetSensitive(ss->popup_bring_to_front_bt, selected);
2487 WidgetSetSensitive(ss->popup_send_to_back_bt, selected);
2488 WidgetSetSensitive(ss->popup_move_up_bt, selected);
2489 WidgetSetSensitive(ss->popup_move_down_bt, selected);
2491 WidgetSetSensitive(ss->popup_properties_bt, n == 1);
2493 if (ss->popup_cb) {
2494 ss->popup_cb(ss, n);
2497 //XmMenuPosition(popup, e);
2498 //XtManageChild(popup);
2499 popup->exec(QCursor::pos());
2503 static void ss_any_cb(StorageStructure *ss, int type)
2505 int i, n;
2506 Quark **values;
2508 n = GetStorageChoices(ss, &values);
2510 for (i = 0; i < n; i ++) {
2511 Quark *q;
2513 switch (type) {
2514 case SS_SEND_TO_BACK_CB:
2515 case SS_MOVE_UP_CB:
2516 q = values[n - i - 1];
2517 break;
2518 default:
2519 q = values[i];
2520 break;
2523 switch (type) {
2524 case SS_HIDE_CB:
2525 quark_set_active(q, FALSE);
2526 break;
2527 case SS_SHOW_CB:
2528 quark_set_active(q, TRUE);
2529 break;
2530 case SS_DELETE_CB:
2531 quark_free(q);
2532 break;
2533 case SS_BRING_TO_FRONT_CB:
2534 quark_push(q, TRUE);
2535 break;
2536 case SS_SEND_TO_BACK_CB:
2537 quark_push(q, FALSE);
2538 break;
2539 case SS_MOVE_UP_CB:
2540 quark_move(q, TRUE);
2541 break;
2542 case SS_MOVE_DOWN_CB:
2543 quark_move(q, FALSE);
2544 break;
2545 case SS_DUPLICATE_CB:
2546 quark_copy(q);
2547 break;
2551 if (n > 0) {
2552 xfree(values);
2553 snapshot_and_update(gapp->gp, TRUE);
2557 static void ss_hide_cb(Widget but, void *udata)
2559 ss_any_cb((StorageStructure *) udata, SS_HIDE_CB);
2562 static void ss_show_cb(Widget but, void *udata)
2564 ss_any_cb((StorageStructure *) udata, SS_SHOW_CB);
2567 static void ss_delete_cb(Widget but, void *udata)
2569 if (yesno("Really delete selected item(s)?", NULL, NULL, NULL)) {
2570 ss_any_cb((StorageStructure *) udata, SS_DELETE_CB);
2574 static void ss_duplicate_cb(Widget but, void *udata)
2576 ss_any_cb((StorageStructure *) udata, SS_DUPLICATE_CB);
2579 static void ss_bring_to_front_cb(Widget but, void *udata)
2581 ss_any_cb((StorageStructure *) udata, SS_BRING_TO_FRONT_CB);
2584 static void ss_send_to_back_cb(Widget but, void *udata)
2586 ss_any_cb((StorageStructure *) udata, SS_SEND_TO_BACK_CB);
2589 static void ss_move_up_cb(Widget but, void *udata)
2591 ss_any_cb((StorageStructure *) udata, SS_MOVE_UP_CB);
2594 static void ss_move_down_cb(Widget but, void *udata)
2596 ss_any_cb((StorageStructure *) udata, SS_MOVE_DOWN_CB);
2599 static void ss_properties_cb(Widget but, void *udata)
2601 StorageStructure *ss = (StorageStructure *) udata;
2602 Quark *q;
2604 if (GetSingleStorageChoice(ss, &q) == RETURN_SUCCESS) {
2605 raise_explorer(gapp->gui, q);
2609 static void ss_select_all_cb(Widget but, void *udata)
2611 list_selectall(((StorageStructure *) udata)->list);
2614 static void ss_unselect_all_cb(Widget but, void *udata)
2616 list_unselectall(((StorageStructure *) udata)->list);
2619 static void ss_invert_selection_cb(Widget but, void *udata)
2621 list_invertselection(((StorageStructure *) udata)->list);
2624 static void ss_update_cb(Widget but, void *udata)
2626 StorageStructure *ss = (StorageStructure *) udata;
2628 UpdateStorageChoice(ss);
2631 static void s_dc_cb(StorageStructure *ss, Quark *q, void *data)
2633 raise_explorer(gapp->gui, q);
2636 //static void CreateStorageChoicePopup(StorageStructure *ss)
2638 // Widget popup, submenupane;
2640 // popup = XmCreatePopupMenu(ss->list, "popupMenu", NULL, 0);
2641 // ss->popup = popup;
2642 //#if XmVersion >= 2000
2643 // XtVaSetValues(popup, XmNpopupEnabled, XmPOPUP_DISABLED, NULL);
2644 //#else
2645 // XtVaSetValues(popup, XmNpopupEnabled, False, NULL);
2646 //#endif
2648 // ss->popup_properties_bt =
2649 // CreateMenuButton(popup, "Properties...", '\0', ss_properties_cb, ss);
2651 // CreateMenuSeparator(popup);
2653 // ss->popup_hide_bt = CreateMenuButton(popup, "Hide", '\0', ss_hide_cb, ss);
2654 // ss->popup_show_bt = CreateMenuButton(popup, "Show", '\0', ss_show_cb, ss);
2655 // CreateMenuSeparator(popup);
2657 // ss->popup_delete_bt =
2658 // CreateMenuButton(popup, "Delete", '\0', ss_delete_cb, ss);
2659 // ss->popup_duplicate_bt =
2660 // CreateMenuButton(popup, "Duplicate", '\0', ss_duplicate_cb, ss);
2662 // CreateMenuSeparator(popup);
2664 // ss->popup_bring_to_front_bt = CreateMenuButton(popup,
2665 // "Bring to front", '\0', ss_bring_to_front_cb, ss);
2666 // ss->popup_move_up_bt =
2667 // CreateMenuButton(popup, "Move up", '\0', ss_move_up_cb, ss);
2668 // ss->popup_move_down_bt =
2669 // CreateMenuButton(popup, "Move down", '\0', ss_move_down_cb, ss);
2670 // ss->popup_send_to_back_bt =
2671 // CreateMenuButton(popup, "Send to back", '\0', ss_send_to_back_cb, ss);
2673 // CreateMenuSeparator(popup);
2675 // submenupane = CreateMenu(popup, "Selector operations", 'o', FALSE);
2676 // ss->selpopup = submenupane;
2678 // ss->popup_select_all_bt =
2679 // CreateMenuButton(submenupane, "Select all", '\0', ss_select_all_cb, ss);
2680 // ss->popup_unselect_all_bt =
2681 // CreateMenuButton(submenupane, "Unselect all", '\0', ss_unselect_all_cb, ss);
2682 // ss->popup_invert_selection_bt = CreateMenuButton(submenupane,
2683 // "Invert selection", '\0', ss_invert_selection_cb, ss);
2685 // CreateMenuSeparator(submenupane);
2687 // CreateMenuButton(submenupane, "Update list", '\0', ss_update_cb, ss);
2689 // AddStorageChoiceDblClickCB(ss, s_dc_cb, NULL);
2691 static void CreateStorageChoicePopup(StorageStructure *ss)
2693 Widget popup, submenupane;
2695 //popup = XmCreatePopupMenu(ss->list, "popupMenu", NULL, 0);
2696 popup = new QMenu(ss->list);
2697 ss->popup = popup;
2698 #if XmVersion >= 2000
2699 // XtVaSetValues(popup, XmNpopupEnabled, XmPOPUP_DISABLED, NULL);
2700 #else
2701 // XtVaSetValues(popup, XmNpopupEnabled, False, NULL);
2702 #endif
2704 ss->popup_properties_bt =
2705 CreateMenuButton(popup, "Properties...", '\0', ss_properties_cb, ss);
2707 CreateMenuSeparator(popup);
2709 ss->popup_hide_bt = CreateMenuButton(popup, "Hide", '\0', ss_hide_cb, ss);
2710 ss->popup_show_bt = CreateMenuButton(popup, "Show", '\0', ss_show_cb, ss);
2711 CreateMenuSeparator(popup);
2713 ss->popup_delete_bt =
2714 CreateMenuButton(popup, "Delete", '\0', ss_delete_cb, ss);
2715 ss->popup_duplicate_bt =
2716 CreateMenuButton(popup, "Duplicate", '\0', ss_duplicate_cb, ss);
2718 CreateMenuSeparator(popup);
2720 ss->popup_bring_to_front_bt = CreateMenuButton(popup,
2721 "Bring to front", '\0', ss_bring_to_front_cb, ss);
2722 ss->popup_move_up_bt =
2723 CreateMenuButton(popup, "Move up", '\0', ss_move_up_cb, ss);
2724 ss->popup_move_down_bt =
2725 CreateMenuButton(popup, "Move down", '\0', ss_move_down_cb, ss);
2726 ss->popup_send_to_back_bt =
2727 CreateMenuButton(popup, "Send to back", '\0', ss_send_to_back_cb, ss);
2729 CreateMenuSeparator(popup);
2731 submenupane = CreateMenu(popup, "Selector operations", 'o', FALSE);
2732 ss->selpopup = submenupane;
2734 ss->popup_select_all_bt =
2735 CreateMenuButton(submenupane, "Select all", '\0', ss_select_all_cb, ss);
2736 ss->popup_unselect_all_bt =
2737 CreateMenuButton(submenupane, "Unselect all", '\0', ss_unselect_all_cb, ss);
2738 ss->popup_invert_selection_bt = CreateMenuButton(submenupane,
2739 "Invert selection", '\0', ss_invert_selection_cb, ss);
2741 CreateMenuSeparator(submenupane);
2743 CreateMenuButton(submenupane, "Update list", '\0', ss_update_cb, ss);
2745 AddStorageChoiceDblClickCB(ss, s_dc_cb, NULL);
2748 //StorageStructure *CreateStorageChoice(Widget parent,
2749 // char *labelstr, int type, int nvisible)
2751 // Arg args[4];
2752 // Widget lab;
2753 // StorageStructure *retval;
2755 // retval = xmalloc(sizeof(StorageStructure));
2756 // memset(retval, 0, sizeof(StorageStructure));
2758 // retval->labeling_proc = default_storage_labeling_proc;
2759 // retval->rc = XmCreateRowColumn(parent, "rc", NULL, 0);
2760 // AddHelpCB(retval->rc, "doc/UsersGuide.html#list-selector");
2762 // lab = XmCreateLabel(retval->rc, labelstr, NULL, 0);
2763 // XtManageChild(lab);
2765 // XtSetArg(args[0], XmNlistSizePolicy, XmCONSTANT);
2766 // XtSetArg(args[1], XmNscrollBarDisplayPolicy, XmSTATIC);
2767 // if (type == LIST_TYPE_SINGLE) {
2768 // XtSetArg(args[2], XmNselectionPolicy, XmSINGLE_SELECT);
2769 // } else {
2770 // XtSetArg(args[2], XmNselectionPolicy, XmEXTENDED_SELECT);
2771 // }
2772 // XtSetArg(args[3], XmNvisibleItemCount, nvisible);
2773 // retval->list = XmCreateScrolledList(retval->rc, "list", args, 4);
2774 // retval->values = NULL;
2776 // CreateStorageChoicePopup(retval);
2777 // XtAddEventHandler(retval->list,
2778 // ButtonPressMask, False, storage_popup, retval);
2780 // XtOverrideTranslations(retval->list,
2781 // XtParseTranslationTable(list_translation_table));
2783 // XtManageChild(retval->list);
2785 // XtManageChild(retval->rc);
2787 // return retval;
2789 StorageStructure *CreateStorageChoice(Widget parent,
2790 char *labelstr, int type, int nvisible)
2792 StorageStructure *retval;
2794 retval = (StorageStructure*) xmalloc(sizeof(StorageStructure));
2795 memset(retval, 0, sizeof(StorageStructure));
2797 retval->labeling_proc = default_storage_labeling_proc;
2799 QWidget *widget = new QWidget(parent);
2800 retval->rc = widget;
2802 AddHelpCB(widget, "doc/UsersGuide.html#list-selector");
2804 QLabel *label = new QLabel(widget);
2805 label->setText(labelstr);
2807 QListWidget *listWidget = new QListWidget(widget);
2808 listWidget->setUniformItemSizes(true);
2809 QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
2810 listWidget->setSizePolicy(sizePolicy);
2812 if (type == LIST_TYPE_SINGLE) {
2813 listWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2814 } else {
2815 listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
2818 //TODO: fix spacing of nvisible
2819 listWidget->setMaximumHeight(nvisible * 15 + 2);
2820 //XtSetArg(args[3], XmNvisibleItemCount, nvisible);
2821 //retval->list = XmCreateScrolledList(retval->rc, "list", args, 4);
2823 retval->list = listWidget;
2824 retval->values = NULL;
2826 CreateStorageChoicePopup(retval);
2828 listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
2829 QtAddCallback(listWidget, SIGNAL(customContextMenuRequested(const QPoint)),
2830 storage_popup, retval);
2832 //TODO: add acelerators
2833 //XtOverrideTranslations(retval->list,
2834 // XtParseTranslationTable(list_translation_table));
2836 QVBoxLayout *vBoxLayout = new QVBoxLayout;
2837 vBoxLayout->setContentsMargins(0,0,0,0);
2838 vBoxLayout->addWidget(label);
2839 vBoxLayout->addWidget(listWidget);
2840 widget->setLayout(vBoxLayout);
2842 QLayout *layout = parent->layout();
2843 if (layout != 0) {
2844 layout->addWidget(widget);
2847 return retval;
2850 void SetStorageChoiceLabeling(StorageStructure *ss, Storage_LabelingProc proc)
2852 ss->labeling_proc = proc;
2855 //int GetStorageSelectedCount(StorageStructure *ss)
2857 // int count;
2858 // XtVaGetValues(ss->list, XmNselectedItemCount, &count, NULL);
2859 // return count;
2862 //int GetStorageChoices(StorageStructure *ss, Quark ***values)
2864 // int i, n;
2865 // int *selected;
2867 // if (XmListGetSelectedPos(ss->list, &selected, &n) != True) {
2868 // return 0;
2869 // }
2871 // *values = xmalloc(n*SIZEOF_VOID_P);
2872 // for (i = 0; i < n; i++) {
2873 // (*values)[i] = ss->values[selected[i] - 1];
2874 // }
2876 // if (n) {
2877 // XtFree((char *) selected);
2878 // }
2880 // return n;
2882 int GetStorageChoices(StorageStructure *ss, Quark ***values)
2884 int i, n, nrow;
2886 QListWidget *listWidget = (QListWidget*) ss->list;
2887 QList<QListWidgetItem *> list = listWidget->selectedItems();
2889 n = list.size();
2891 if (n == 0) {
2892 return 0;
2895 *values = (Quark**) xmalloc(n*SIZEOF_VOID_P);
2896 for (i = 0; i < n; i++) {
2897 nrow = listWidget->row(list.at(i));
2898 (*values)[i] = ss->values[nrow];
2901 return n;
2904 int GetSingleStorageChoice(StorageStructure *ss, Quark **value)
2906 int n, retval;
2907 Quark **values;
2909 n = GetStorageChoices(ss, &values);
2910 if (n == 1) {
2911 *value = values[0];
2912 retval = RETURN_SUCCESS;
2913 } else {
2914 retval = RETURN_FAILURE;
2917 if (n) {
2918 xfree(values);
2921 return retval;
2925 //int SelectStorageChoices(StorageStructure *ss, int nchoices, Quark **choices)
2927 // int i = 0, j;
2928 // unsigned char selection_type_save;
2929 // int bottom, visible;
2931 // XtVaGetValues(ss->list, XmNselectionPolicy, &selection_type_save, NULL);
2932 // XtVaSetValues(ss->list, XmNselectionPolicy, XmMULTIPLE_SELECT, NULL);
2934 // XmListDeselectAllItems(ss->list);
2935 // for (j = 0; j < nchoices; j++) {
2936 // i = 0;
2937 // while (i < ss->nchoices && ss->values[i] != choices[j]) {
2938 // i++;
2939 // }
2940 // if (i < ss->nchoices) {
2941 // i++;
2942 // XmListSelectPos(ss->list, i, True);
2943 // }
2944 // }
2946 // if (nchoices > 0) {
2947 // /* Rewind list so the last choice is always visible */
2948 // XtVaGetValues(ss->list, XmNtopItemPosition, &bottom,
2949 // XmNvisibleItemCount, &visible,
2950 // NULL);
2951 // if (i > bottom) {
2952 // XmListSetBottomPos(ss->list, i);
2953 // } else if (i <= bottom - visible) {
2954 // XmListSetPos(ss->list, i);
2955 // }
2956 // }
2958 // XtVaSetValues(ss->list, XmNselectionPolicy, selection_type_save, NULL);
2960 // return RETURN_SUCCESS;
2962 int SelectStorageChoices(StorageStructure *ss, int nchoices, Quark **choices)
2964 int i = 0, j;
2965 QAbstractItemView::SelectionMode selection_type_save;
2966 QListWidgetItem *item;
2967 int bottom, visible;
2969 QListWidget *listWidget = (QListWidget*) ss->list;
2971 selection_type_save = listWidget->selectionMode();
2972 listWidget->setSelectionMode(QAbstractItemView::MultiSelection);
2973 //XtVaGetValues(ss->list, XmNselectionPolicy, &selection_type_save, NULL);
2974 //XtVaSetValues(ss->list, XmNselectionPolicy, XmMULTIPLE_SELECT, NULL);
2976 listWidget->clearSelection();
2977 //XmListDeselectAllItems(ss->list);
2978 for (j = 0; j < nchoices; j++) {
2979 i = 0;
2980 while (i < ss->nchoices && ss->values[i] != choices[j]) {
2981 i++;
2983 if (i < ss->nchoices) {
2984 item = listWidget->item(i);
2985 item->setSelected(true);
2986 i++;
2987 //XmListSelectPos(ss->list, i, True);
2991 // if (nchoices > 0) {
2992 /* Rewind list so the last choice is always visible */
2993 //XtVaGetValues(ss->list, XmNtopItemPosition, &bottom,
2994 // XmNvisibleItemCount, &visible,
2995 // NULL);
2996 // if (i > bottom) {
2997 //XmListSetBottomPos(ss->list, i);
2998 // } else if (i <= bottom - visible) {
2999 //XmListSetPos(ss->list, i);
3000 // }
3001 // }
3003 listWidget->setSelectionMode(selection_type_save);
3004 //XtVaSetValues(ss->list, XmNselectionPolicy, selection_type_save, NULL);
3006 return RETURN_SUCCESS;
3009 int SelectStorageChoice(StorageStructure *ss, Quark *choice)
3011 return SelectStorageChoices(ss, 1, &choice);
3014 //void UpdateStorageChoice(StorageStructure *ss)
3016 // Quark **selvalues;
3017 // storage_traverse_data stdata;
3018 // int nsel;
3020 // nsel = GetStorageChoices(ss, &selvalues);
3022 // XmListDeleteAllItems(ss->list);
3024 // ss->nchoices = 0;
3025 // stdata.rid = 0;
3026 // stdata.ss = ss;
3027 // if (ss->q) {
3028 // quark_traverse(ss->q, traverse_hook, &stdata);
3030 // SelectStorageChoices(ss, nsel, selvalues);
3031 // }
3033 // if (nsel > 0) {
3034 // xfree(selvalues);
3035 // }
3037 // nsel = GetStorageSelectedCount(ss);
3038 // if (!nsel && XtHasCallbacks(ss->list, XmNsingleSelectionCallback) ==
3039 // XtCallbackHasSome) {
3040 // /* invoke callbacks to make any dependent GUI control to sync */
3041 // XtCallCallbacks(ss->list, XmNsingleSelectionCallback, NULL);
3042 // }
3043 //}
3044 void UpdateStorageChoice(StorageStructure *ss)
3046 Quark **selvalues;
3047 storage_traverse_data stdata;
3048 int nsel;
3050 nsel = GetStorageChoices(ss, &selvalues);
3052 QListWidget *listWidget = (QListWidget*) ss->list;
3054 listWidget->clear();
3055 //XmListDeleteAllItems(ss->list);
3057 ss->nchoices = 0;
3058 stdata.rid = 0;
3059 stdata.ss = ss;
3060 if (ss->q) {
3061 quark_traverse(ss->q, traverse_hook, &stdata);
3063 SelectStorageChoices(ss, nsel, selvalues);
3066 if (nsel > 0) {
3067 xfree(selvalues);
3070 //nsel = GetStorageSelectedCount(ss);
3071 //if (!nsel && XtHasCallbacks(ss->list, XmNsingleSelectionCallback) ==
3072 // XtCallbackHasSome) {
3073 // /* invoke callbacks to make any dependent GUI control to sync */
3074 // XtCallCallbacks(ss->list, XmNsingleSelectionCallback, NULL);
3075 // }
3078 void SetStorageChoiceQuark(StorageStructure *ss, Quark *q)
3080 ss->q = q;
3081 UpdateStorageChoice(ss);
3085 typedef struct {
3086 StorageStructure *ss;
3087 Storage_CBProc cbproc;
3088 void *anydata;
3089 } Storage_CBdata;
3091 typedef struct {
3092 StorageStructure *ss;
3093 Storage_DCCBProc cbproc;
3094 void *anydata;
3095 } Storage_DCCBdata;
3097 static void storage_int_cb_proc(Widget w,
3098 XtPointer client_data, XtPointer call_data)
3100 int n;
3101 Quark **values;
3102 Storage_CBdata *cbdata = (Storage_CBdata *) client_data;
3104 n = GetStorageChoices(cbdata->ss, &values);
3106 cbdata->cbproc(cbdata->ss, n, values, cbdata->anydata);
3108 if (n > 0) {
3109 xfree(values);
3113 //void AddStorageChoiceCB(StorageStructure *ss,
3114 // Storage_CBProc cbproc, void *anydata)
3116 // Storage_CBdata *cbdata;
3118 // cbdata = xmalloc(sizeof(Storage_CBdata));
3119 // cbdata->ss = ss;
3120 // cbdata->cbproc = cbproc;
3121 // cbdata->anydata = anydata;
3122 // XtAddCallback(ss->list,
3123 // XmNsingleSelectionCallback, storage_int_cb_proc, (XtPointer) cbdata);
3124 // XtAddCallback(ss->list,
3125 // XmNmultipleSelectionCallback, storage_int_cb_proc, (XtPointer) cbdata);
3126 // XtAddCallback(ss->list,
3127 // XmNextendedSelectionCallback, storage_int_cb_proc, (XtPointer) cbdata);
3129 void AddStorageChoiceCB(StorageStructure *ss,
3130 Storage_CBProc cbproc, void *anydata)
3132 Storage_CBdata *cbdata;
3134 cbdata = (Storage_CBdata*) xmalloc(sizeof(Storage_CBdata));
3135 cbdata->ss = ss;
3136 cbdata->cbproc = cbproc;
3137 cbdata->anydata = anydata;
3139 QtAddCallback(ss->list, SIGNAL(itemClicked(QListWidgetItem*)),
3140 storage_int_cb_proc, (XtPointer) cbdata);
3142 // XtAddCallback(ss->list,
3143 // XmNsingleSelectionCallback, storage_int_cb_proc, (XtPointer) cbdata);
3144 // XtAddCallback(ss->list,
3145 // XmNmultipleSelectionCallback, storage_int_cb_proc, (XtPointer) cbdata);
3146 // XtAddCallback(ss->list,
3147 // XmNextendedSelectionCallback, storage_int_cb_proc, (XtPointer) cbdata);
3150 //static void storage_int_dc_cb_proc(Widget w,
3151 // XtPointer client_data, XtPointer call_data)
3153 // void *value;
3154 // XmListCallbackStruct *cbs = (XmListCallbackStruct *) call_data;
3155 // Storage_DCCBdata *cbdata = (Storage_DCCBdata *) client_data;
3157 // value = cbdata->ss->values[cbs->item_position - 1];
3159 // cbdata->cbproc(cbdata->ss, value, cbdata->anydata);
3161 static void storage_int_dc_cb_proc(Widget w,
3162 XtPointer client_data, XtPointer call_data)
3164 Quark *value;
3165 QListWidget *listWidget = (QListWidget*) w;
3166 //XmListCallbackStruct *cbs = (XmListCallbackStruct *) call_data;
3167 Storage_DCCBdata *cbdata = (Storage_DCCBdata *) client_data;
3169 value = cbdata->ss->values[listWidget->currentRow()];
3171 cbdata->cbproc(cbdata->ss, value, cbdata->anydata);
3172 qDebug("double click");
3175 //void AddStorageChoiceDblClickCB(StorageStructure *ss,
3176 // Storage_DCCBProc cbproc, void *anydata)
3178 // Storage_DCCBdata *cbdata;
3180 // cbdata = xmalloc(sizeof(Storage_DCCBdata));
3181 // cbdata->ss = ss;
3182 // cbdata->cbproc = cbproc;
3183 // cbdata->anydata = anydata;
3184 // XtAddCallback(ss->list,
3185 // XmNdefaultActionCallback, storage_int_dc_cb_proc, (XtPointer) cbdata);
3187 void AddStorageChoiceDblClickCB(StorageStructure *ss,
3188 Storage_DCCBProc cbproc, void *anydata)
3190 Storage_DCCBdata *cbdata;
3192 cbdata = (Storage_DCCBdata*) xmalloc(sizeof(Storage_DCCBdata));
3193 cbdata->ss = ss;
3194 cbdata->cbproc = cbproc;
3195 cbdata->anydata = anydata;
3197 QtAddCallback(ss->list, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
3198 storage_int_dc_cb_proc, (XtPointer) cbdata);
3202 static void spin_arrow_cb(Widget w, XtPointer client_data, XtPointer call_data)
3204 SpinStructure *spinp;
3205 double value, incr;
3207 spinp = (SpinStructure *) client_data;
3208 value = GetSpinChoice(spinp);
3209 incr = spinp->incr;
3211 if (w == spinp->arrow_up) {
3212 incr = spinp->incr;
3213 } else if (w == spinp->arrow_down) {
3214 incr = -spinp->incr;
3215 } else {
3216 errmsg("Wrong call to spin_arrow_cb()");
3217 return;
3219 value += incr;
3220 SetSpinChoice(spinp, value);
3223 //static void sp_double_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
3225 // Spin_CBdata *cbdata = (Spin_CBdata *) client_data;
3226 // XmAnyCallbackStruct* xmcb = call_data;
3228 // if (w == cbdata->spin->arrow_up ||
3229 // w == cbdata->spin->arrow_down ||
3230 // xmcb->reason == XmCR_ACTIVATE) {
3231 // cbdata->cbproc(cbdata->spin, GetSpinChoice(cbdata->spin), cbdata->anydata);
3232 // }
3234 static void sp_double_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
3236 Spin_CBdata *cbdata = (Spin_CBdata *) client_data;
3238 cbdata->cbproc(cbdata->spin, GetSpinChoice(cbdata->spin), cbdata->anydata);
3241 //static void sp_timer_proc(XtPointer client_data, XtIntervalId *id)
3243 // Spin_CBdata *cbdata = (Spin_CBdata *) client_data;
3245 // cbdata->cbproc(cbdata->spin, GetSpinChoice(cbdata->spin), cbdata->anydata);
3246 // cbdata->timeout_id = (XtIntervalId) 0;
3249 //static void sp_ev_proc(Widget w,
3250 // XtPointer client_data, XEvent *event, Boolean *cont)
3252 // XButtonPressedEvent *e = (XButtonPressedEvent *) event;
3253 // Spin_CBdata *cbdata = (Spin_CBdata *) client_data;
3255 // if (e->button == 4 || e->button == 5) {
3256 // /* we count elapsed time since the last event, so first remove
3257 // an existing timeout, if there is one */
3258 // if (cbdata->timeout_id) {
3259 // XtRemoveTimeOut(cbdata->timeout_id);
3260 // }
3261 // cbdata->timeout_id = XtAppAddTimeOut(app_con,
3262 // 250 /* 0.25 second */, sp_timer_proc, client_data);
3263 // }
3266 //void AddSpinChoiceCB(SpinStructure *spinp, Spin_CBProc cbproc, void *anydata)
3268 // Spin_CBdata *cbdata;
3270 // cbdata = xmalloc(sizeof(Spin_CBdata));
3272 // cbdata->spin = spinp;
3273 // cbdata->cbproc = cbproc;
3274 // cbdata->anydata = anydata;
3275 // cbdata->timeout_id = (XtIntervalId) 0;
3276 // XtAddCallback(spinp->text,
3277 // XmNactivateCallback, sp_double_cb_proc, (XtPointer) cbdata);
3278 // XtAddCallback(spinp->arrow_up,
3279 // XmNactivateCallback, sp_double_cb_proc, (XtPointer) cbdata);
3280 // XtAddCallback(spinp->arrow_down,
3281 // XmNactivateCallback, sp_double_cb_proc, (XtPointer) cbdata);
3282 // XtAddEventHandler(spinp->text,
3283 // ButtonPressMask, False, sp_ev_proc, (XtPointer) cbdata);
3285 void AddSpinChoiceCB(SpinStructure *spinp, Spin_CBProc cbproc, void *anydata)
3287 Spin_CBdata *cbdata;
3289 cbdata = (Spin_CBdata *) xmalloc(sizeof(Spin_CBdata));
3291 cbdata->spin = spinp;
3292 cbdata->cbproc = cbproc;
3293 cbdata->anydata = anydata;
3295 QtAddCallback(spinp->text, SIGNAL(editingFinished()),
3296 sp_double_cb_proc, (XtPointer) cbdata);
3297 QtAddCallback(spinp->arrow_up, SIGNAL(clicked()),
3298 sp_double_cb_proc, (XtPointer) cbdata);
3299 QtAddCallback(spinp->arrow_down, SIGNAL(clicked()),
3300 sp_double_cb_proc, (XtPointer) cbdata);
3301 //TODO:
3302 // XtAddEventHandler(spinp->text,
3303 // ButtonPressMask, False, sp_ev_proc, (XtPointer) cbdata);
3306 //static void spin_updown(Widget parent,
3307 // XtPointer closure, XEvent *event, Boolean *cont)
3309 // XButtonPressedEvent *e = (XButtonPressedEvent *) event;
3310 // SpinStructure *spinp = (SpinStructure *) closure;
3311 // double value, incr;
3313 // if (e->button == 4) {
3314 // incr = spinp->incr;
3315 // } else
3316 // if (e->button == 5) {
3317 // incr = -spinp->incr;
3318 // } else {
3319 // return;
3320 // }
3321 // value = GetSpinChoice(spinp) + incr;
3322 // SetSpinChoice(spinp, value);
3325 //SpinStructure *CreateSpinChoice(Widget parent, char *s, int len,
3326 // int type, double min, double max, double incr)
3328 // SpinStructure *retval;
3329 // Widget fr, form;
3330 // XmString str;
3332 // if (min >= max) {
3333 // errmsg("min >= max in CreateSpinChoice()!");
3334 // return NULL;
3335 // }
3337 // retval = xmalloc(sizeof(SpinStructure));
3339 // retval->type = type;
3340 // retval->min = min;
3341 // retval->max = max;
3342 // retval->incr = incr;
3344 // retval->rc = XtVaCreateWidget("rc", xmRowColumnWidgetClass, parent,
3345 // XmNorientation, XmHORIZONTAL,
3346 // NULL);
3347 // str = XmStringCreateLocalized(s);
3348 // XtVaCreateManagedWidget("label", xmLabelWidgetClass, retval->rc,
3349 // XmNlabelString, str,
3350 // NULL);
3351 // XmStringFree(str);
3352 // fr = XtVaCreateWidget("fr", xmFrameWidgetClass, retval->rc,
3353 // XmNshadowType, XmSHADOW_ETCHED_OUT,
3354 // NULL);
3355 // form = XtVaCreateWidget("form", xmFormWidgetClass, fr,
3356 // NULL);
3357 // retval->text = XtVaCreateWidget("text", xmTextWidgetClass, form,
3358 // XmNtraversalOn, True,
3359 // XmNcolumns, len,
3360 // NULL);
3362 // XtAddEventHandler(retval->text, ButtonPressMask, False, spin_updown, retval);
3364 // retval->arrow_up = XtVaCreateWidget("form", xmArrowButtonGadgetClass, form,
3365 // XmNarrowDirection, XmARROW_UP,
3366 // NULL);
3367 // XtAddCallback(retval->arrow_up, XmNactivateCallback,
3368 // spin_arrow_cb, (XtPointer) retval);
3369 // retval->arrow_down = XtVaCreateWidget("form", xmArrowButtonGadgetClass, form,
3370 // XmNarrowDirection, XmARROW_DOWN,
3371 // NULL);
3372 // XtAddCallback(retval->arrow_down, XmNactivateCallback,
3373 // spin_arrow_cb, (XtPointer) retval);
3374 // XtVaSetValues(retval->text,
3375 // XmNtopAttachment, XmATTACH_FORM,
3376 // XmNleftAttachment, XmATTACH_FORM,
3377 // XmNbottomAttachment, XmATTACH_FORM,
3378 // XmNrightAttachment, XmATTACH_NONE,
3379 // NULL);
3380 // XtVaSetValues(retval->arrow_down,
3381 // XmNtopAttachment, XmATTACH_FORM,
3382 // XmNbottomAttachment, XmATTACH_FORM,
3383 // XmNleftAttachment, XmATTACH_WIDGET,
3384 // XmNleftWidget, retval->text,
3385 // XmNrightAttachment, XmATTACH_NONE,
3386 // NULL);
3387 // XtVaSetValues(retval->arrow_up,
3388 // XmNtopAttachment, XmATTACH_FORM,
3389 // XmNbottomAttachment, XmATTACH_FORM,
3390 // XmNrightAttachment, XmATTACH_FORM,
3391 // XmNleftAttachment, XmATTACH_WIDGET,
3392 // XmNleftWidget, retval->arrow_down,
3393 // NULL);
3395 // XtManageChild(retval->text);
3396 // XtManageChild(retval->arrow_up);
3397 // XtManageChild(retval->arrow_down);
3398 // XtManageChild(form);
3399 // XtManageChild(fr);
3400 // XtManageChild(retval->rc);
3402 // return retval;
3405 static void SetLineEditWidth(QLineEdit *lineEdit, int len)
3407 QFontMetrics fm = lineEdit->fontMetrics();
3408 int fontWidth = fm.width(QLatin1Char('0'));
3410 int leftTextMargin, rightTextMargin;
3411 int leftMargin, rightMargin;
3412 lineEdit->getTextMargins(&leftTextMargin, 0, &rightTextMargin, 0);
3413 lineEdit->getContentsMargins(&leftMargin, 0, &rightMargin, 0);
3414 int frameWidth = lineEdit->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, 0);
3415 int cursorWidth = lineEdit->style()->pixelMetric(QStyle::PM_TextCursorWidth, 0, 0);
3416 int w = fontWidth * len + 2*2 //2 = horizontalMargin, hardcoded in the qlineedit_p.cpp
3417 + leftTextMargin + rightTextMargin
3418 + leftMargin + rightMargin
3419 + 2*frameWidth + cursorWidth; // "some"
3421 lineEdit->setFixedWidth(w);
3424 static QPushButton* CreateArrowButton(Widget parent, QStyle::PrimitiveElement element)
3426 QStyle *style = QApplication::style();
3428 QPushButton *arrow = new QPushButton(parent);
3429 arrow->setFixedSize(20, 20);
3430 arrow->setIconSize(QSize(14, 14));
3432 QPixmap *pixmap = new QPixmap(14, 14);
3433 pixmap->fill(parent->palette().color(QPalette::Window));
3435 QPainter painter(pixmap);
3436 painter.setPen(Qt::black);
3438 QStyleOptionSpinBox option;
3439 option.rect = QRect(-3, -3, 18, 18);
3440 style->drawPrimitive(element, &option, &painter);
3442 arrow->setIcon(QIcon(*pixmap));
3444 return arrow;
3447 SpinStructure *CreateSpinChoice(Widget parent, char *s, int len,
3448 int type, double min, double max, double incr)
3450 SpinStructure *retval;
3452 if (min >= max) {
3453 errmsg("min >= max in CreateSpinChoice()!");
3454 return NULL;
3457 retval = (SpinStructure*) xmalloc(sizeof(SpinStructure));
3459 retval->type = type;
3460 retval->min = min;
3461 retval->max = max;
3462 retval->incr = incr;
3464 QWidget *widget = new QWidget(parent);
3465 retval->rc = widget;
3467 QLabel *label = new QLabel(widget);
3468 label->setText(s);
3470 QLineEdit *lineEdit = new QLineEdit(widget);
3471 SetLineEditWidth(lineEdit, len);
3472 retval->text = lineEdit;
3474 //TODO:
3475 //QtAddCallback(lineEdit, SIGNAL(clicked()),
3476 // spin_updown, (XtPointer) retval);
3477 //XtAddEventHandler(retval->text, ButtonPressMask, False, spin_updown, retval);
3479 QPushButton *arrow_down = CreateArrowButton(widget, QStyle::PE_IndicatorSpinDown);
3480 QtAddCallback(arrow_down, SIGNAL(clicked()),
3481 spin_arrow_cb, (XtPointer) retval);
3482 retval->arrow_down = arrow_down;
3484 QPushButton *arrow_up = CreateArrowButton(widget, QStyle::PE_IndicatorSpinUp);
3485 QtAddCallback(arrow_up, SIGNAL(clicked()),
3486 spin_arrow_cb, (XtPointer) retval);
3487 retval->arrow_up = arrow_up;
3489 QSpacerItem *vSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
3491 QHBoxLayout *hLayout = new QHBoxLayout;
3492 hLayout->setContentsMargins(0,0,0,0);
3493 hLayout->setSpacing(0);
3494 hLayout->addWidget(label);
3495 hLayout->addWidget(lineEdit);
3496 hLayout->addWidget(arrow_down);
3497 hLayout->addWidget(arrow_up);
3498 hLayout->addItem(vSpacer);
3499 widget->setLayout(hLayout);
3501 QLayout *layout = parent->layout();
3502 if (layout != 0) {
3503 layout->addWidget(widget);
3506 return retval;
3509 //void SetSpinChoice(SpinStructure *spinp, double value)
3511 // X11Stuff *xstuff = gapp->gui->xstuff;
3512 // char buf[64];
3514 // if (value < spinp->min) {
3515 // XBell(xstuff->disp, 50);
3516 // value = spinp->min;
3517 // } else if (value > spinp->max) {
3518 // XBell(xstuff->disp, 50);
3519 // value = spinp->max;
3520 // }
3522 // if (spinp->type == SPIN_TYPE_FLOAT) {
3523 // sprintf(buf, "%g", value);
3524 // } else {
3525 // sprintf(buf, "%d", (int) rint(value));
3526 // }
3527 // XmTextSetString(spinp->text, buf);
3529 void SetSpinChoice(SpinStructure *spinp, double value)
3531 QLineEdit *spinBox = (QLineEdit*) spinp->text;
3532 char buf[64];
3534 if (value < spinp->min) {
3535 QApplication::beep();
3536 value = spinp->min;
3537 } else if (value > spinp->max) {
3538 QApplication::beep();
3539 value = spinp->max;
3542 if (spinp->type == SPIN_TYPE_FLOAT) {
3543 sprintf(buf, "%g", value);
3544 } else {
3545 sprintf(buf, "%d", (int) rint(value));
3547 spinBox->setText(buf);
3550 double GetSpinChoice(SpinStructure *spinp)
3552 double retval;
3554 xv_evalexpr(spinp->text, &retval);
3555 if (retval < spinp->min) {
3556 errmsg("Input value below min limit in GetSpinChoice()");
3557 retval = spinp->min;
3558 SetSpinChoice(spinp, retval);
3559 } else if (retval > spinp->max) {
3560 errmsg("Input value above max limit in GetSpinChoice()");
3561 retval = spinp->max;
3562 SetSpinChoice(spinp, retval);
3565 if (spinp->type == SPIN_TYPE_INT) {
3566 return rint(retval);
3567 } else {
3568 return retval;
3572 //TextStructure *CreateTextInput(Widget parent, char *s)
3574 // TextStructure *retval;
3575 // XmString str;
3577 // retval = xmalloc(sizeof(TextStructure));
3578 // retval->form = XtVaCreateWidget("form", xmFormWidgetClass, parent, NULL);
3580 // str = XmStringCreateLocalized(s);
3581 // retval->label = XtVaCreateManagedWidget("label",
3582 // xmLabelWidgetClass, retval->form,
3583 // XmNlabelString, str,
3584 // XmNtopAttachment, XmATTACH_FORM,
3585 // XmNbottomAttachment, XmATTACH_FORM,
3586 // XmNleftAttachment, XmATTACH_FORM,
3587 // XmNrightAttachment, XmATTACH_NONE,
3588 // NULL);
3589 // XmStringFree(str);
3591 // retval->text = XtVaCreateManagedWidget("cstext",
3592 // xmTextWidgetClass, retval->form,
3593 // XmNtraversalOn, True,
3594 // XmNtopAttachment, XmATTACH_FORM,
3595 // XmNbottomAttachment, XmATTACH_FORM,
3596 // XmNleftAttachment, XmATTACH_WIDGET,
3597 // XmNleftWidget, retval->label,
3598 // XmNrightAttachment, XmATTACH_FORM,
3599 // NULL);
3601 // XtManageChild(retval->form);
3603 // return retval;
3605 TextStructure *CreateTextInput(Widget parent, char *s)
3607 TextStructure *retval;
3609 retval = (TextStructure*) xmalloc(sizeof(TextStructure));
3611 QWidget *widget = new QWidget(parent);
3612 retval->form = widget;
3614 QLabel *label = new QLabel(widget);
3615 label->setText(s);
3616 retval->label = label;
3618 QLineEdit *lineEdit = new QLineEdit(widget);
3619 retval->text = lineEdit;
3621 QVBoxLayout *vLayout = new QVBoxLayout;
3622 vLayout->setContentsMargins(0,0,0,0);
3623 vLayout->addWidget(label);
3624 vLayout->addWidget(lineEdit);
3626 widget->setLayout(vLayout);
3628 QLayout *layout = parent->layout();
3629 if (layout != 0) {
3630 layout->addWidget(widget);
3633 return retval;
3636 ///*
3637 // * create a multiline editable window
3638 // * parent = parent widget
3639 // * nrows = number of lines in the window
3640 // * s = label for window
3641 // */
3642 //TextStructure *CreateScrolledTextInput(Widget parent, char *s, int nrows)
3644 // TextStructure *retval;
3645 // XmString str;
3646 // Arg args[3];
3647 // int ac;
3649 // retval = xmalloc(sizeof(TextStructure));
3650 // retval->form = XtVaCreateWidget("form", xmFormWidgetClass, parent, NULL);
3652 // str = XmStringCreateLocalized(s);
3653 // retval->label = XtVaCreateManagedWidget("label",
3654 // xmLabelWidgetClass, retval->form,
3655 // XmNlabelString, str,
3656 // XmNtopAttachment, XmATTACH_FORM,
3657 // XmNleftAttachment, XmATTACH_FORM,
3658 // XmNrightAttachment, XmATTACH_FORM,
3659 // NULL);
3660 // XmStringFree(str);
3662 // ac = 0;
3663 // if (nrows > 0) {
3664 // XtSetArg(args[ac], XmNrows, nrows); ac++;
3665 // }
3666 // XtSetArg(args[ac], XmNeditMode, XmMULTI_LINE_EDIT); ac++;
3667 // XtSetArg(args[ac], XmNvisualPolicy, XmVARIABLE); ac++;
3668 // retval->text = XmCreateScrolledText(retval->form, "text", args, ac);
3669 // XtVaSetValues(XtParent(retval->text),
3670 // XmNtopAttachment, XmATTACH_WIDGET,
3671 // XmNtopWidget, retval->label,
3672 // XmNleftAttachment, XmATTACH_FORM,
3673 // XmNrightAttachment, XmATTACH_FORM,
3674 // XmNbottomAttachment, XmATTACH_FORM,
3675 // NULL);
3676 // XtManageChild(retval->text);
3678 // XtManageChild(retval->form);
3679 // return retval;
3681 TextStructure *CreateScrolledTextInput(Widget parent, char *s, int nrows)
3683 TextStructure *retval;
3685 retval = (TextStructure*) xmalloc(sizeof(TextStructure));
3687 retval->form = parent;
3689 QWidget *widget = new QWidget(parent);
3691 QLabel *label = new QLabel(widget);
3692 label->setText(s);
3693 retval->label = label;
3695 QPlainTextEdit *pTextEdit = new QPlainTextEdit(widget);
3696 if (nrows > 0) {
3697 QFontMetrics fm = pTextEdit->fontMetrics();
3698 int fontHeight = fm.height();
3700 int topMargin, bottomMargin;
3701 pTextEdit->getContentsMargins(0, &topMargin, 0, &bottomMargin);
3702 int frameWidth = pTextEdit->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, 0);
3703 int frameWidth2 = pTextEdit->frameWidth();
3704 int height = fontHeight * nrows
3705 + topMargin + bottomMargin
3706 + 2*frameWidth
3707 + 2*frameWidth2 + 1;
3708 pTextEdit->setFixedHeight(height);
3711 retval->text = pTextEdit;
3713 QVBoxLayout *vLayout = new QVBoxLayout;
3714 vLayout->setContentsMargins(0,0,0,0);
3715 vLayout->addWidget(label);
3716 vLayout->addWidget(pTextEdit);
3718 widget->setLayout(vLayout);
3720 QLayout *layout = parent->layout();
3721 if (layout != 0) {
3722 layout->addWidget(widget);
3725 return retval;
3728 //void SetTextInputLength(TextStructure *cst, int len)
3730 // XtVaSetValues(cst->text, XmNcolumns, len, NULL);
3732 void SetTextInputLength(TextStructure *cst, int len)
3734 if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(cst->text)) {
3735 lineEdit->setMaxLength(len);
3736 } else {
3737 qDebug("this should not happen SetTextInputLength");
3741 //static void cstext_edit_action(Widget w, XEvent *e, String *par, Cardinal *npar)
3743 // TextStructure *cst = (TextStructure *) GetUserData(w);
3744 // create_fonttool(cst);
3747 //static char cstext_translation_table[] = "\
3748 // Ctrl<Key>E: cstext_edit_action()";
3750 //TextStructure *CreateCSText(Widget parent, char *s)
3752 // TextStructure *retval;
3754 // retval = CreateTextInput(parent, s);
3755 // SetUserData(retval->text, retval);
3756 // XtOverrideTranslations(retval->text,
3757 // XtParseTranslationTable(cstext_translation_table));
3759 // return retval;
3762 static void cstext_edit_action(Widget w, XtPointer client_data, XtPointer call_data)
3764 TextStructure *cst = (TextStructure *) client_data;
3765 create_fonttool(cst);
3768 TextStructure *CreateCSText(Widget parent, char *s)
3770 TextStructure *retval;
3771 QShortcut *shortcut;
3773 retval = CreateTextInput(parent, s);
3775 shortcut = new QShortcut(QKeySequence("Ctrl+E"), retval->text,
3776 0, 0, Qt::WidgetShortcut);
3778 QtAddCallback(shortcut, SIGNAL(activated()),
3779 cstext_edit_action, retval);
3781 return retval;
3784 //TextStructure *CreateScrolledCSText(Widget parent, char *s, int nrows)
3786 // TextStructure *retval;
3788 // retval = CreateScrolledTextInput(parent, s, nrows);
3789 // SetUserData(retval->text, retval);
3790 // XtOverrideTranslations(retval->text,
3791 // XtParseTranslationTable(cstext_translation_table));
3793 // return retval;
3795 TextStructure *CreateScrolledCSText(Widget parent, char *s, int nrows)
3797 TextStructure *retval;
3798 QShortcut *shortcut;
3800 retval = CreateScrolledTextInput(parent, s, nrows);
3802 shortcut = new QShortcut(QKeySequence("Ctrl+E"), retval->text,
3803 0, 0, Qt::WidgetShortcut);
3805 QtAddCallback(shortcut, SIGNAL(activated()),
3806 cstext_edit_action, retval);
3808 return retval;
3811 //char *GetTextString(TextStructure *cst)
3813 // char *s, *buf;
3815 // s = XmTextGetString(cst->text);
3816 // buf = copy_string(NULL, s);
3817 // XtFree(s);
3819 // return buf;
3821 char *GetTextString(TextStructure *cst)
3823 char *buf;
3825 if (QPlainTextEdit *plainText = qobject_cast<QPlainTextEdit *>(cst->text)) {
3826 QByteArray ba = plainText->toPlainText().toAscii();
3827 buf = copy_string(NULL, ba.data());
3830 if (QLineEdit *text = qobject_cast<QLineEdit *>(cst->text)) {
3831 QByteArray ba = text->text().toAscii();
3832 buf = copy_string(NULL, ba.data());
3835 return buf;
3838 //void SetTextString(TextStructure *cst, char *s)
3840 // cst->locked = TRUE;
3842 // XmTextSetString(cst->text, s ? s : "");
3843 // XmTextSetInsertionPosition(cst->text, s ? strlen(s):0);
3845 void SetTextString(TextStructure *cst, char *s)
3847 cst->locked = TRUE;
3849 if (QPlainTextEdit *plainText = qobject_cast<QPlainTextEdit *>(cst->text)) {
3850 plainText->setPlainText(s ? s : "");
3853 if (QLineEdit *text = qobject_cast<QLineEdit *>(cst->text)) {
3854 text->setText(s ? s : "");
3858 //typedef struct {
3859 // TextStructure *cst;
3860 // Text_CBProc cbproc;
3861 // void *anydata;
3862 // Widget w;
3863 // XtIntervalId timeout_id;
3864 //} Text_CBdata;
3865 typedef struct {
3866 TextStructure *cst;
3867 Text_CBProc cbproc;
3868 void *anydata;
3869 Widget w;
3870 } Text_CBdata;
3872 //static void text_timer_proc(XtPointer client_data, XtIntervalId *id)
3874 // char *s;
3875 // Text_CBdata *cbdata = (Text_CBdata *) client_data;
3877 // s = XmTextGetString(cbdata->w);
3878 // cbdata->cbproc(cbdata->cst, s, cbdata->anydata);
3879 // XtFree(s);
3880 // cbdata->timeout_id = (XtIntervalId) 0;
3883 ///* Text input timeout [ms] */
3884 //#define TEXT_TIMEOUT 0
3886 //static void text_int_mv_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
3888 // Text_CBdata *cbdata = (Text_CBdata *) client_data;
3890 // if (cbdata->cst->locked) {
3891 // cbdata->cst->locked = FALSE;
3892 // return;
3893 // }
3894 // cbdata->w = w;
3895 // /* we count elapsed time since the last event, so first remove
3896 // an existing timeout, if there is one */
3897 // if (cbdata->timeout_id) {
3898 // XtRemoveTimeOut(cbdata->timeout_id);
3899 // }
3901 // if (TEXT_TIMEOUT) {
3902 // cbdata->timeout_id = XtAppAddTimeOut(app_con,
3903 // TEXT_TIMEOUT, text_timer_proc, client_data);
3904 // }
3906 static void text_int_mv_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
3908 Text_CBdata *cbdata = (Text_CBdata *) client_data;
3910 if (cbdata->cst->locked) {
3911 cbdata->cst->locked = FALSE;
3912 return;
3916 //static void text_int_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
3918 // char *s;
3919 // Text_CBdata *cbdata = (Text_CBdata *) client_data;
3920 // s = XmTextGetString(w);
3921 // cbdata->cbproc(cbdata->cst, s, cbdata->anydata);
3922 // XtFree(s);
3924 static void text_int_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
3926 QByteArray ba;
3927 char *s;
3928 Text_CBdata *cbdata = (Text_CBdata *) client_data;
3930 if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(w)) {
3931 ba = lineEdit->text().toAscii();
3933 if (QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(w)) {
3934 ba = plainTextEdit->toPlainText().toAscii();
3937 s = ba.data();
3939 cbdata->cbproc(cbdata->cst, s, cbdata->anydata);
3942 //void AddTextInputCB(TextStructure *cst, Text_CBProc cbproc, void *data)
3944 // Text_CBdata *cbdata;
3946 // cbdata = xmalloc(sizeof(Text_CBdata));
3947 // cbdata->cst = cst;
3948 // cbdata->anydata = data;
3949 // cbdata->cbproc = cbproc;
3950 // cbdata->timeout_id = (XtIntervalId) 0;
3951 // cbdata->cst->locked = FALSE;
3953 // XtAddCallback(cst->text,
3954 // XmNactivateCallback, text_int_cb_proc, (XtPointer) cbdata);
3955 // XtAddCallback(cst->text,
3956 // XmNmodifyVerifyCallback, text_int_mv_cb_proc, (XtPointer) cbdata);
3958 void AddTextInputCB(TextStructure *cst, Text_CBProc cbproc, void *data)
3960 Text_CBdata *cbdata;
3962 cbdata = (Text_CBdata*) xmalloc(sizeof(Text_CBdata));
3963 cbdata->cst = cst;
3964 cbdata->anydata = data;
3965 cbdata->cbproc = cbproc;
3966 cbdata->cst->locked = FALSE;
3968 if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(cst->text)) {
3969 QtAddCallback(lineEdit, SIGNAL(returnPressed()),
3970 text_int_cb_proc, (XtPointer) cbdata);
3971 QtAddCallback(lineEdit, SIGNAL(textChanged(const QString &)),
3972 text_int_mv_cb_proc, (XtPointer) cbdata);
3974 if (QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(cst->text)) {
3975 QtAddCallback(plainTextEdit, SIGNAL(textChanged()),
3976 text_int_mv_cb_proc, (XtPointer) cbdata);
3980 Validator::Validator(TextValidate_CBData *cbdata, QWidget *parent)
3981 : QValidator(parent)
3983 this->cbdata = cbdata;
3986 QValidator::State Validator::validate(QString &input, int &pos) const
3988 static bool skip = false;
3989 static QString last_input = "";
3990 static int last_pos = 0;
3991 int len;
3993 if (text) {
3994 len = strlen(text);
3997 if (!QString::compare(input, last_input) && (pos != last_pos)) return Acceptable;
3999 last_input = input;
4000 last_pos = pos;
4002 if (skip) {
4003 skip = false;
4004 } else {
4005 if (cbdata->cbproc(&text, &len, cbdata->anydata)) {
4006 QString oldinput = input;
4007 input.remove(pos - 1, 1);
4008 input.insert(pos - 1, text);
4009 pos = pos - 1 + len;
4010 if (QString::compare(oldinput, input)) {
4011 skip = true;
4016 return Acceptable;
4019 KeyPressListener::KeyPressListener(QObject *parent)
4020 : QObject(parent)
4024 bool KeyPressListener::eventFilter(QObject *obj, QEvent *event)
4026 if (event->type() == QEvent::KeyPress) {
4027 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
4028 qDebug() << "Listened key press " << keyEvent->text();
4029 QByteArray ba = keyEvent->text().toAscii();
4030 Validator::text = copy_string(Validator::text, ba.data());
4031 return false;
4032 } else {
4033 // standard event processing
4034 return QObject::eventFilter(obj, event);
4038 void AddTextValidateCB(Widget w, TextValidate_CBProc cbproc, void *anydata)
4040 TextValidate_CBData *cbdata;
4042 cbdata = (TextValidate_CBData *) xmalloc(sizeof(TextValidate_CBData));
4043 cbdata->w = w;
4044 cbdata->cbproc = cbproc;
4045 cbdata->anydata = anydata;
4047 QLineEdit *lineEdit = qobject_cast<QLineEdit *>(w);
4048 lineEdit->setValidator(new Validator(cbdata, w));
4050 KeyPressListener *keyPressListener = new KeyPressListener(w);
4051 lineEdit->installEventFilter(keyPressListener);
4054 //int GetTextCursorPos(TextStructure *cst)
4056 // return XmTextGetInsertionPosition(cst->text);
4058 int GetTextCursorPos(TextStructure *cst)
4060 int pos = 0;
4062 if (QPlainTextEdit *text = qobject_cast<QPlainTextEdit *>(cst->text)) {
4063 QTextCursor textCursor = text->textCursor();
4064 pos = textCursor.position();
4067 if (QLineEdit *text = qobject_cast<QLineEdit *>(cst->text)) {
4068 pos = text->cursorPosition();
4071 return pos;
4074 //void SetTextCursorPos(TextStructure *cst, int pos)
4076 // XmTextSetInsertionPosition(cst->text, pos);
4078 void SetTextCursorPos(TextStructure *cst, int pos)
4080 if (QPlainTextEdit *text = qobject_cast<QPlainTextEdit *>(cst->text)) {
4081 QTextCursor textCursor = text->textCursor();
4082 textCursor.setPosition(pos);
4083 text->setTextCursor(textCursor);
4086 if (QLineEdit *text = qobject_cast<QLineEdit *>(cst->text)) {
4087 text->setCursorPosition(pos);
4091 int GetTextLastPosition(TextStructure *cst)
4093 return QTextCursor::End;
4096 //void TextInsert(TextStructure *cst, int pos, char *s)
4098 // XmTextInsert(cst->text, pos, s);
4101 char *Validator::text = 0;
4102 int Validator::pos = 0;
4104 void TextInsertString(TextStructure *cst, int pos, char *s)
4106 if (QPlainTextEdit *plainText = qobject_cast<QPlainTextEdit *>(cst->text)) {
4107 QTextCursor textCursor = plainText->textCursor();
4108 if (pos == QTextCursor::End) {
4109 textCursor.movePosition(QTextCursor::End);
4111 textCursor.insertText(s);
4112 plainText->setTextCursor(textCursor);
4115 if (QLineEdit *text = qobject_cast<QLineEdit *>(cst->text)) {
4116 Validator::text = copy_string(Validator::text, s);
4117 Validator::pos = pos;
4118 text->setCursorPosition(pos);
4119 text->insert(s);
4123 //void SetTextEditable(TextStructure *cst, int onoff)
4125 // XtVaSetValues(cst->text, XmNeditable, onoff? True:False, NULL);
4127 void SetTextEditable(TextStructure *cst, int onoff)
4129 QPlainTextEdit *text = (QPlainTextEdit*) cst->text;
4130 text->setReadOnly(onoff ? false : true);
4133 //static char *GetStringSimple(XmString xms)
4135 // char *s;
4137 // if (XmStringGetLtoR(xms, charset, &s)) {
4138 // return s;
4139 // } else {
4140 // return NULL;
4141 // }
4144 typedef struct {
4145 Widget but;
4146 Button_CBProc cbproc;
4147 void *anydata;
4148 } Button_CBdata;
4150 //Widget CreateButton(Widget parent, char *label)
4152 // Widget button;
4153 // XmString xmstr;
4155 // xmstr = XmStringCreateLocalized(label);
4156 // button = XtVaCreateManagedWidget("button",
4157 // xmPushButtonWidgetClass, parent,
4158 // XmNalignment, XmALIGNMENT_CENTER,
4159 // XmNlabelString, xmstr,
4160 ///*
4161 // * XmNmarginLeft, 5,
4162 // * XmNmarginRight, 5,
4163 // * XmNmarginTop, 3,
4164 // * XmNmarginBottom, 2,
4165 // */
4166 // NULL);
4167 // XmStringFree(xmstr);
4169 // return button;
4171 Widget CreateButton(Widget parent, char *label)
4173 Widget button;
4175 button = new QPushButton(label, parent);
4177 QLayout *layout = parent->layout();
4178 if (layout != 0) {
4179 layout->addWidget(button);
4182 return button;
4185 //Widget CreateBitmapButton(Widget parent,
4186 // int width, int height, const unsigned char *bits)
4188 // X11Stuff *xstuff = gapp->gui->xstuff;
4189 // Widget button;
4190 // Pixmap pm;
4191 // Pixel fg, bg;
4193 // button = XtVaCreateManagedWidget("button",
4194 // xmPushButtonWidgetClass, parent,
4195 // XmNlabelType, XmPIXMAP,
4196 // NULL);
4198 ///*
4199 // * We need to get right fore- and background colors for pixmap.
4200 // */
4201 // XtVaGetValues(button,
4202 // XmNforeground, &fg,
4203 // XmNbackground, &bg,
4204 // NULL);
4205 // pm = XCreatePixmapFromBitmapData(xstuff->disp,
4206 // xstuff->root, (char *) bits, width, height, fg, bg, xstuff->depth);
4207 // XtVaSetValues(button, XmNlabelPixmap, pm, NULL);
4209 // return button;
4211 Widget CreateBitmapButton(Widget parent,
4212 int width, int height, const unsigned char *bits)
4214 QToolBar *toolBar = (QToolBar*) parent;
4216 QAction *action = new QAction(parent);
4218 action->setIcon(QIcon(QBitmap::fromData(QSize(width, height),
4219 bits,
4220 QImage::Format_MonoLSB)));
4221 toolBar->addAction(action);
4223 return (QWidget*)action;
4226 static void button_int_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
4228 Button_CBdata *cbdata = (Button_CBdata *) client_data;
4229 cbdata->cbproc(cbdata->but, cbdata->anydata);
4232 //void AddButtonCB(Widget button, Button_CBProc cbproc, void *data)
4234 // Button_CBdata *cbdata;
4236 // cbdata = xmalloc(sizeof(Button_CBdata));
4237 // cbdata->but = button;
4238 // cbdata->anydata = data;
4239 // cbdata->cbproc = cbproc;
4240 // XtAddCallback(button,
4241 // XmNactivateCallback, button_int_cb_proc, (XtPointer) cbdata);
4243 void AddButtonCB(Widget button, Button_CBProc cbproc, void *data)
4245 Button_CBdata *cbdata;
4247 cbdata = (Button_CBdata*) xmalloc(sizeof(Button_CBdata));
4248 cbdata->but = button;
4249 cbdata->anydata = data;
4250 cbdata->cbproc = cbproc;
4252 if (QPushButton *pb = qobject_cast<QPushButton *>(button)) {
4253 QtAddCallback(button, SIGNAL(clicked()),
4254 button_int_cb_proc, (XtPointer) cbdata);
4256 if (QAction *ac = qobject_cast<QAction *>(button)) {
4257 QtAddCallback(button, SIGNAL(triggered()),
4258 button_int_cb_proc, (XtPointer) cbdata);
4263 * generic unmanage popup routine, used elswhere
4265 //static void destroy_dialog(Widget w, XtPointer client_data, XtPointer call_data)
4267 // XtUnmanageChild((Widget) client_data);
4271 * same for AddButtonCB
4273 //void destroy_dialog_cb(Widget but, void *data)
4275 // XtUnmanageChild((Widget) data);
4277 void destroy_dialog_cb(Widget but, void *data)
4279 ((Widget) data)->close();
4282 //static void fsb_setcwd_cb(Widget but, void *data)
4284 // char *bufp;
4285 // XmString directory;
4286 // Widget fsb = (Widget) data;
4288 // XtVaGetValues(fsb, XmNdirectory, &directory, NULL);
4289 // bufp = GetStringSimple(directory);
4290 // XmStringFree(directory);
4291 // if (bufp != NULL) {
4292 // set_workingdir(gapp, bufp);
4293 // XtFree(bufp);
4294 // }
4297 //#define FSB_CWD 0
4298 //#define FSB_HOME 1
4299 //#define FSB_ROOT 2
4300 //#define FSB_CYGDRV 3
4302 //static void fsb_cd_cb(OptionStructure *opt, int value, void *data)
4304 // char *bufp;
4305 // XmString dir, pattern, dirmask;
4306 // Widget FSB = (Widget) data;
4308 // switch (value) {
4309 // case FSB_CWD:
4310 // bufp = get_workingdir(gapp);
4311 // break;
4312 // case FSB_HOME:
4313 // bufp = grace_get_userhome(gapp->grace);
4314 // break;
4315 // case FSB_ROOT:
4316 // bufp = "/";
4317 // break;
4318 // case FSB_CYGDRV:
4319 // bufp = "/cygdrive/";
4320 // break;
4321 // default:
4322 // return;
4323 // }
4325 // XtVaGetValues(FSB, XmNpattern, &pattern, NULL);
4327 // dir = XmStringCreateLocalized(bufp);
4328 // dirmask = XmStringConcatAndFree(dir, pattern);
4330 // XmFileSelectionDoSearch(FSB, dirmask);
4331 // XmStringFree(dirmask);
4334 //static OptionItem fsb_items[] = {
4335 // {FSB_CWD, "Cwd"},
4336 // {FSB_HOME, "Home"},
4337 // {FSB_ROOT, "/"}
4338 //#ifdef __CYGWIN__
4339 // ,{FSB_CYGDRV, "My Computer"}
4340 //#endif
4341 //};
4343 //#define FSB_ITEMS_NUM sizeof(fsb_items)/sizeof(OptionItem)
4345 //#if XmVersion >= 2000
4346 //static void show_hidden_cb(Widget but, int onoff, void *data)
4348 // FSBStructure *fsb = (FSBStructure *) data;
4349 // XtVaSetValues(fsb->FSB, XmNfileFilterStyle,
4350 // onoff ? XmFILTER_NONE:XmFILTER_HIDDEN_FILES, NULL);
4352 //#endif
4354 //FSBStructure *CreateFileSelectionBox(Widget parent, char *s)
4356 // FSBStructure *retval;
4357 // OptionStructure *opt;
4358 // Widget fr, form, button;
4359 // XmString xmstr;
4360 // char *bufp, *resname;
4362 // retval = xmalloc(sizeof(FSBStructure));
4363 // resname = label_to_resname(s, "FSB");
4364 // retval->FSB = XmCreateFileSelectionDialog(parent, resname, NULL, 0);
4365 // xfree(resname);
4366 // retval->dialog = XtParent(retval->FSB);
4367 // handle_close(retval->dialog);
4368 // bufp = copy_string(NULL, "Grace: ");
4369 // bufp = concat_strings(bufp, s);
4370 // XtVaSetValues(retval->dialog, XmNtitle, bufp, NULL);
4371 // xfree(bufp);
4373 // xmstr = XmStringCreateLocalized(get_workingdir(gapp));
4374 // XtVaSetValues(retval->FSB, XmNdirectory, xmstr, NULL);
4375 // XmStringFree(xmstr);
4377 // XtAddCallback(retval->FSB,
4378 // XmNcancelCallback, destroy_dialog, retval->dialog);
4379 // AddHelpCB(retval->FSB, "doc/UsersGuide.html#FS-dialog");
4381 // retval->rc = XmCreateRowColumn(retval->FSB, "rc", NULL, 0);
4382 //#if XmVersion >= 2000
4383 // button = CreateToggleButton(retval->rc, "Show hidden files");
4384 // AddToggleButtonCB(button, show_hidden_cb, retval);
4385 // XtVaSetValues(retval->FSB, XmNfileFilterStyle, XmFILTER_HIDDEN_FILES, NULL);
4386 //#endif
4387 // fr = CreateFrame(retval->rc, NULL);
4388 // form = XtVaCreateWidget("form", xmFormWidgetClass, fr, NULL);
4389 // opt = CreateOptionChoice(form, "Chdir to:", 1, FSB_ITEMS_NUM, fsb_items);
4390 // AddOptionChoiceCB(opt, fsb_cd_cb, (void *) retval->FSB);
4391 // button = CreateButton(form, "Set as cwd");
4392 // AddButtonCB(button, fsb_setcwd_cb, (void *) retval->FSB);
4394 // XtVaSetValues(opt->menu,
4395 // XmNleftAttachment, XmATTACH_FORM,
4396 // XmNtopAttachment, XmATTACH_FORM,
4397 // XmNbottomAttachment, XmATTACH_FORM,
4398 // XmNrightAttachment, XmATTACH_NONE,
4399 // NULL);
4400 // XtVaSetValues(button,
4401 // XmNleftAttachment, XmATTACH_NONE,
4402 // XmNtopAttachment, XmATTACH_FORM,
4403 // XmNbottomAttachment, XmATTACH_FORM,
4404 // XmNrightAttachment, XmATTACH_FORM,
4405 // NULL);
4406 // XtManageChild(form);
4408 // XtManageChild(retval->rc);
4410 // return retval;
4412 FSBStructure *CreateFSBDialog(Widget parent, char *s)
4414 FSBStructure *retval;
4415 char *bufp;
4417 retval = (FSBStructure*) xmalloc(sizeof(FSBStructure));
4419 FileSelectionDialog *fileSelectionDialog = new FileSelectionDialog(mainWin);
4421 retval->FSB = fileSelectionDialog;
4422 retval->dialog = fileSelectionDialog;
4423 QWidget *widget = new QWidget(fileSelectionDialog);
4424 retval->rc = widget;
4426 QVBoxLayout *vBoxLayout = new QVBoxLayout;
4427 vBoxLayout->setContentsMargins(0,0,0,0);
4428 widget->setLayout(vBoxLayout);
4430 if (QBoxLayout *layout = qobject_cast<QBoxLayout *>(fileSelectionDialog->layout())) {
4431 layout->insertWidget(4, widget);
4434 bufp = copy_string(NULL, "Grace: ");
4435 bufp = concat_strings(bufp, s);
4436 fileSelectionDialog->setWindowTitle(bufp);
4437 xfree(bufp);
4439 fileSelectionDialog->setDirectory(get_workingdir(gapp));
4441 AddHelpCB(fileSelectionDialog->ui.helpPushButton,
4442 "doc/UsersGuide.html#FS-dialog");
4443 return retval;
4446 typedef struct {
4447 FSBStructure *fsb;
4448 FSB_CBProc cbproc;
4449 void *anydata;
4450 } FSB_CBdata;
4452 //static void fsb_int_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
4454 // char *s;
4455 // int ok;
4457 // FSB_CBdata *cbdata = (FSB_CBdata *) client_data;
4458 // XmFileSelectionBoxCallbackStruct *cbs =
4459 // (XmFileSelectionBoxCallbackStruct *) call_data;
4461 // s = GetStringSimple(cbs->value);
4462 // if (s == NULL) {
4463 // errmsg("Error converting XmString to char string");
4464 // return;
4465 // }
4467 // set_wait_cursor();
4469 // ok = cbdata->cbproc(cbdata->fsb, s, cbdata->anydata);
4470 // XtFree(s);
4471 // if (ok) {
4472 // XtUnmanageChild(cbdata->fsb->dialog);
4473 // }
4474 // unset_wait_cursor();
4476 static void fsb_int_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
4478 char *s;
4479 int ok;
4481 FSB_CBdata *cbdata = (FSB_CBdata *) client_data;
4482 FileSelectionDialog *fileSelectionDialog = (FileSelectionDialog*) cbdata->fsb->FSB;
4483 QLineEdit *lineEdit = fileSelectionDialog->ui.selectionLineEdit;
4484 QString str = lineEdit->text();
4486 QByteArray ba = str.toAscii();
4487 s = ba.data();
4488 qDebug(s);
4490 set_wait_cursor();
4492 ok = cbdata->cbproc(cbdata->fsb, s, cbdata->anydata);
4494 if (ok) {
4495 fileSelectionDialog->close();
4497 unset_wait_cursor();
4500 //void AddFileSelectionBoxCB(FSBStructure *fsb, FSB_CBProc cbproc, void *anydata)
4502 // FSB_CBdata *cbdata;
4504 // cbdata = xmalloc(sizeof(FSB_CBdata));
4505 // cbdata->fsb = fsb;
4506 // cbdata->cbproc = (FSB_CBProc) cbproc;
4507 // cbdata->anydata = anydata;
4508 // XtAddCallback(fsb->FSB,
4509 // XmNokCallback, fsb_int_cb_proc, (XtPointer) cbdata);
4511 void AddFSBDialogCB(FSBStructure *fsb, FSB_CBProc cbproc, void *anydata)
4513 FSB_CBdata *cbdata;
4515 cbdata = (FSB_CBdata*) xmalloc(sizeof(FSB_CBdata));
4516 cbdata->fsb = fsb;
4517 cbdata->cbproc = (FSB_CBProc) cbproc;
4518 cbdata->anydata = anydata;
4520 FileSelectionDialog *fileSelectionDialog = (FileSelectionDialog*) fsb->FSB;
4521 QPushButton *pushButton = fileSelectionDialog->ui.okPushButton;
4523 QtAddCallback(pushButton, SIGNAL(clicked()),
4524 fsb_int_cb_proc, (XtPointer) cbdata);
4527 //void SetFileSelectionBoxPattern(FSBStructure *fsb, char *pattern)
4529 // XmString xmstr;
4531 // if (pattern != NULL) {
4532 // xmstr = XmStringCreateLocalized(pattern);
4533 // XtVaSetValues(fsb->FSB, XmNpattern, xmstr, NULL);
4534 // XmStringFree(xmstr);
4535 // }
4537 void FSBDialogSetPattern(FSBStructure *fsb, char *pattern)
4539 FileSelectionDialog *fileSelectionDialog = (FileSelectionDialog*) fsb->FSB;
4541 if (pattern != NULL) {
4542 fileSelectionDialog->setNameFilter(pattern);
4546 //Widget CreateLabel(Widget parent, char *s)
4548 // Widget label;
4550 // label = XtVaCreateManagedWidget(s ? s:"",
4551 // xmLabelWidgetClass, parent,
4552 // XmNalignment, XmALIGNMENT_BEGINNING,
4553 // XmNrecomputeSize, True,
4554 // NULL);
4555 // return label;
4557 Widget CreateLabel(Widget parent, char *s)
4559 QLabel *label = new QLabel(s ? s:"", parent);
4561 QLayout *layout = parent->layout();
4562 if (layout != 0) {
4563 layout->addWidget(label);
4566 return label;
4569 //void AlignLabel(Widget w, int alignment)
4571 // unsigned char xm_alignment;
4573 // switch(alignment) {
4574 // case ALIGN_BEGINNING:
4575 // xm_alignment = XmALIGNMENT_BEGINNING;
4576 // break;
4577 // case ALIGN_CENTER:
4578 // xm_alignment = XmALIGNMENT_CENTER;
4579 // break;
4580 // case ALIGN_END:
4581 // xm_alignment = XmALIGNMENT_END;
4582 // break;
4583 // default:
4584 // errmsg("Internal error in AlignLabel()");
4585 // return;
4586 // break;
4587 // }
4588 // XtVaSetValues(w,
4589 // XmNalignment, xm_alignment,
4590 // NULL);
4592 void AlignLabel(Widget w, int alignment)
4594 unsigned int xm_alignment;
4596 switch(alignment) {
4597 case ALIGN_BEGINNING:
4598 xm_alignment = Qt::AlignLeft;
4599 break;
4600 case ALIGN_CENTER:
4601 xm_alignment = Qt::AlignHCenter;
4602 break;
4603 case ALIGN_END:
4604 xm_alignment = Qt::AlignRight;
4605 break;
4606 default:
4607 errmsg("Internal error in AlignLabel()");
4608 return;
4609 break;
4612 QLayout *layout = w->parentWidget()->layout();
4613 if (layout != 0) {
4614 layout->setAlignment(w, (Qt::Alignment) xm_alignment);
4618 static OptionItem *settype_option_items;
4619 static OptionItem *fmt_option_items;
4620 static OptionItem *frametype_option_items;
4621 static BitmapOptionItem *pattern_option_items;
4622 static BitmapOptionItem *lines_option_items;
4624 #define LINES_BM_HEIGHT 15
4625 #define LINES_BM_WIDTH 64
4627 //static void init_xvlibcolors(void)
4629 // X11Stuff *xstuff = gapp->gui->xstuff;
4630 // Project *pr = project_get_data(gproject_get_top(gapp->gp));
4631 // unsigned int i;
4633 // if (!pr) {
4634 // return;
4635 // }
4637 // xvlibcolors = xrealloc(xvlibcolors, pr->ncolors*sizeof(unsigned long));
4638 // if (!xvlibcolors) {
4639 // return;
4640 // }
4642 // for (i = 0; i < pr->ncolors; i++) {
4643 // long pixel;
4644 // Colordef *c = &pr->colormap[i];
4646 // pixel = x11_allocate_color(gapp->gui, &c->rgb);
4648 // if (pixel >= 0) {
4649 // xvlibcolors[c->id] = pixel;
4650 // } else {
4651 // xvlibcolors[c->id] = BlackPixel(xstuff->disp, xstuff->screennumber);
4652 // }
4653 // }
4655 static void init_xvlibcolors(void)
4660 //int init_option_menus(void) {
4661 // unsigned int i, j, k, l, n;
4663 // init_xvlibcolors();
4665 // n = number_of_patterns(canvas);
4666 // if (n) {
4667 // pattern_option_items = xmalloc(n*sizeof(BitmapOptionItem));
4668 // if (pattern_option_items == NULL) {
4669 // errmsg("Malloc error in init_option_menus()");
4670 // return RETURN_FAILURE;
4671 // }
4672 // for (i = 0; i < n; i++) {
4673 // pattern_option_items[i].value = i;
4674 // if (i == 0) {
4675 // pattern_option_items[i].bitmap = NULL;
4676 // } else {
4677 // Pattern *pat = canvas_get_pattern(canvas, i);
4678 // pattern_option_items[i].bitmap = pat->bits;
4679 // }
4680 // }
4681 // }
4683 // n = number_of_linestyles(canvas);
4684 // if (n) {
4685 // lines_option_items = xmalloc(n*sizeof(BitmapOptionItem));
4686 // if (lines_option_items == NULL) {
4687 // errmsg("Malloc error in init_option_menus()");
4688 // xfree(pattern_option_items);
4689 // return RETURN_FAILURE;
4690 // }
4691 // for (i = 0; i < n; i++) {
4692 // LineStyle *linestyle = canvas_get_linestyle(canvas, i);
4693 // lines_option_items[i].value = i;
4694 // if (i == 0) {
4695 // lines_option_items[i].bitmap = NULL;
4696 // continue;
4697 // }
4699 // lines_option_items[i].bitmap =
4700 // xcalloc(LINES_BM_HEIGHT*LINES_BM_WIDTH/8/SIZEOF_CHAR, SIZEOF_CHAR);
4702 // k = LINES_BM_WIDTH*(LINES_BM_HEIGHT/2);
4703 // while (k < LINES_BM_WIDTH*(LINES_BM_HEIGHT/2 + 1)) {
4704 // for (j = 0; j < linestyle->length; j++) {
4705 // for (l = 0; l < linestyle->array[j]; l++) {
4706 // if (k < LINES_BM_WIDTH*(LINES_BM_HEIGHT/2 + 1)) {
4707 // if (j % 2 == 0) {
4708 // /* black */
4709 // lines_option_items[i].bitmap[k/8] |= 1 << k % 8;
4710 // }
4711 // k++;
4712 // }
4713 // }
4714 // }
4715 // }
4716 // }
4717 // }
4719 // settype_option_items = xmalloc(NUMBER_OF_SETTYPES*sizeof(OptionItem));
4720 // if (settype_option_items == NULL) {
4721 // errmsg("Malloc error in init_option_menus()");
4722 // return RETURN_FAILURE;
4723 // }
4724 // for (i = 0; i < NUMBER_OF_SETTYPES; i++) {
4725 // settype_option_items[i].value = i;
4726 // settype_option_items[i].label = copy_string(NULL,
4727 // set_type_descr(gapp->grace, i));
4728 // }
4730 // fmt_option_items = xmalloc(NUMBER_OF_FORMATTYPES*sizeof(OptionItem));
4731 // if (fmt_option_items == NULL) {
4732 // errmsg("Malloc error in init_option_menus()");
4733 // return RETURN_FAILURE;
4734 // }
4735 // for (i = 0; i < NUMBER_OF_FORMATTYPES; i++) {
4736 // fmt_option_items[i].value = i;
4737 // fmt_option_items[i].label = copy_string(NULL,
4738 // format_type_descr(gapp->grace, i));
4739 // }
4741 // frametype_option_items = xmalloc(NUMBER_OF_FRAMETYPES*sizeof(OptionItem));
4742 // if (frametype_option_items == NULL) {
4743 // errmsg("Malloc error in init_option_menus()");
4744 // return RETURN_FAILURE;
4745 // }
4746 // for (i = 0; i < NUMBER_OF_FRAMETYPES; i++) {
4747 // frametype_option_items[i].value = i;
4748 // frametype_option_items[i].label = copy_string(NULL,
4749 // frame_type_descr(gapp->grace, i));
4750 // }
4752 // return RETURN_SUCCESS;
4754 int init_option_menus(void) {
4755 unsigned int i, j, k, l, n;
4756 Canvas *canvas = grace_get_canvas(gapp->grace);
4758 // init_xvlibcolors();
4760 n = number_of_patterns(canvas);
4761 if (n) {
4762 pattern_option_items = (BitmapOptionItem *) xmalloc(n*sizeof(BitmapOptionItem));
4763 if (pattern_option_items == NULL) {
4764 errmsg("Malloc error in init_option_menus()");
4765 return RETURN_FAILURE;
4767 for (i = 0; i < n; i++) {
4768 pattern_option_items[i].value = i;
4769 if (i == 0) {
4770 pattern_option_items[i].bitmap = NULL;
4771 } else {
4772 Pattern *pat = canvas_get_pattern(canvas, i);
4773 pattern_option_items[i].bitmap = pat->bits;
4778 n = number_of_linestyles(canvas);
4779 if (n) {
4780 lines_option_items = (BitmapOptionItem *) xmalloc(n*sizeof(BitmapOptionItem));
4781 if (lines_option_items == NULL) {
4782 errmsg("Malloc error in init_option_menus()");
4783 xfree(pattern_option_items);
4784 return RETURN_FAILURE;
4786 for (i = 0; i < n; i++) {
4787 LineStyle *linestyle = canvas_get_linestyle(canvas, i);
4788 lines_option_items[i].value = i;
4789 if (i == 0) {
4790 lines_option_items[i].bitmap = NULL;
4791 continue;
4794 lines_option_items[i].bitmap =
4795 (unsigned char *) xcalloc(LINES_BM_HEIGHT*LINES_BM_WIDTH/8/SIZEOF_CHAR, SIZEOF_CHAR);
4797 k = LINES_BM_WIDTH*(LINES_BM_HEIGHT/2);
4798 while (k < LINES_BM_WIDTH*(LINES_BM_HEIGHT/2 + 1)) {
4799 for (j = 0; j < linestyle->length; j++) {
4800 for (l = 0; l < linestyle->array[j]; l++) {
4801 if (k < LINES_BM_WIDTH*(LINES_BM_HEIGHT/2 + 1)) {
4802 if (j % 2 == 0) {
4803 /* black */
4804 lines_option_items[i].bitmap[k/8] |= 1 << k % 8;
4806 k++;
4814 settype_option_items = (OptionItem*) xmalloc(NUMBER_OF_SETTYPES*sizeof(OptionItem));
4815 if (settype_option_items == NULL) {
4816 errmsg("Malloc error in init_option_menus()");
4817 return RETURN_FAILURE;
4819 for (i = 0; i < NUMBER_OF_SETTYPES; i++) {
4820 settype_option_items[i].value = i;
4821 settype_option_items[i].label = copy_string(NULL,
4822 set_type_descr(gapp->grace, (SetType) i));
4825 fmt_option_items = (OptionItem *) xmalloc(NUMBER_OF_FORMATTYPES*sizeof(OptionItem));
4826 if (fmt_option_items == NULL) {
4827 errmsg("Malloc error in init_option_menus()");
4828 return RETURN_FAILURE;
4830 for (i = 0; i < NUMBER_OF_FORMATTYPES; i++) {
4831 fmt_option_items[i].value = i;
4832 fmt_option_items[i].label = copy_string(NULL,
4833 format_type_descr(gapp->grace, (FormatType) i));
4836 frametype_option_items = (OptionItem *) xmalloc(NUMBER_OF_FRAMETYPES*sizeof(OptionItem));
4837 if (frametype_option_items == NULL) {
4838 errmsg("Malloc error in init_option_menus()");
4839 return RETURN_FAILURE;
4841 for (i = 0; i < NUMBER_OF_FRAMETYPES; i++) {
4842 frametype_option_items[i].value = i;
4843 frametype_option_items[i].label = copy_string(NULL,
4844 frame_type_descr(gapp->grace, (FrameType) i));
4847 return RETURN_SUCCESS;
4850 static OptionItem *font_option_items = NULL;
4851 static unsigned int nfont_option_items = 0;
4852 static OptionStructure **font_selectors = NULL;
4853 static unsigned int nfont_selectors = 0;
4855 //void update_font_selectors(void)
4857 // unsigned int i;
4858 // Project *pr = project_get_data(gproject_get_top(gapp->gp));
4860 // nfont_option_items = pr->nfonts;
4861 // font_option_items =
4862 // xrealloc(font_option_items, nfont_option_items*sizeof(OptionItem));
4864 // for (i = 0; i < nfont_option_items; i++) {
4865 // Fontdef *f = &pr->fontmap[i];
4866 // font_option_items[i].value = f->id;
4867 // font_option_items[i].label = f->fontname;
4868 // }
4870 // for (i = 0; i < nfont_selectors; i++) {
4871 // UpdateOptionChoice(font_selectors[i],
4872 // nfont_option_items, font_option_items);
4873 // }
4875 void update_font_selectors(void)
4877 unsigned int i;
4878 Project *pr = project_get_data(gproject_get_top(gapp->gp));
4880 nfont_option_items = pr->nfonts;
4881 font_option_items =
4882 (OptionItem *) xrealloc(font_option_items, nfont_option_items*sizeof(OptionItem));
4884 for (i = 0; i < nfont_option_items; i++) {
4885 Fontdef *f = &pr->fontmap[i];
4886 font_option_items[i].value = f->id;
4887 font_option_items[i].label = f->fontname;
4890 for (i = 0; i < nfont_selectors; i++) {
4891 UpdateOptionChoice(font_selectors[i],
4892 nfont_option_items, font_option_items);
4896 //OptionStructure *CreateFontChoice(Widget parent, char *s)
4898 // OptionStructure *retvalp = NULL;
4900 // nfont_selectors++;
4901 // font_selectors = xrealloc(font_selectors,
4902 // nfont_selectors*sizeof(OptionStructure *));
4903 // if (font_selectors == NULL) {
4904 // errmsg("Malloc failed in CreateFontChoice()");
4905 // return retvalp;
4906 // }
4908 // retvalp = CreateOptionChoice(parent, s, 0,
4909 // nfont_option_items, font_option_items);
4911 // font_selectors[nfont_selectors - 1] = retvalp;
4913 // return retvalp;
4915 OptionStructure *CreateFontChoice(Widget parent, char *s)
4917 OptionStructure *retvalp = NULL;
4919 nfont_selectors++;
4920 font_selectors = (OptionStructure **) xrealloc(font_selectors,
4921 nfont_selectors*sizeof(OptionStructure *));
4922 if (font_selectors == NULL) {
4923 errmsg("Malloc failed in CreateFontChoice()");
4924 return retvalp;
4927 retvalp = CreateOptionChoice(parent, s, 0,
4928 nfont_option_items, font_option_items);
4930 font_selectors[nfont_selectors - 1] = retvalp;
4932 return retvalp;
4935 OptionStructure *CreatePatternChoice(Widget parent, char *s)
4937 Canvas *canvas = grace_get_canvas(gapp->grace);
4939 return (CreateBitmapOptionChoice(parent, s, 4, number_of_patterns(canvas),
4940 16, 16, pattern_option_items));
4943 OptionStructure *CreateLineStyleChoice(Widget parent, char *s)
4945 Canvas *canvas = grace_get_canvas(gapp->grace);
4947 return (CreateBitmapOptionChoice(parent, s, 0, number_of_linestyles(canvas),
4948 LINES_BM_WIDTH, LINES_BM_HEIGHT, lines_option_items));
4951 OptionStructure *CreateSetTypeChoice(Widget parent, char *s)
4953 return (CreateOptionChoice(parent,
4954 s, 0, NUMBER_OF_SETTYPES, settype_option_items));
4957 OptionStructure *CreateFrameTypeChoice(Widget parent, char *s)
4959 return (CreateOptionChoice(parent,
4960 s, 0, NUMBER_OF_FRAMETYPES, frametype_option_items));
4963 static BitmapOptionItem text_just_option_items[12] =
4965 {JUST_LEFT |JUST_BLINE , j_lm_o_bits},
4966 {JUST_CENTER|JUST_BLINE , j_cm_o_bits},
4967 {JUST_RIGHT |JUST_BLINE , j_rm_o_bits},
4968 {JUST_LEFT |JUST_BOTTOM, j_lb_b_bits},
4969 {JUST_CENTER|JUST_BOTTOM, j_cb_b_bits},
4970 {JUST_RIGHT |JUST_BOTTOM, j_rb_b_bits},
4971 {JUST_LEFT |JUST_MIDDLE, j_lm_b_bits},
4972 {JUST_CENTER|JUST_MIDDLE, j_cm_b_bits},
4973 {JUST_RIGHT |JUST_MIDDLE, j_rm_b_bits},
4974 {JUST_LEFT |JUST_TOP , j_lt_b_bits},
4975 {JUST_CENTER|JUST_TOP , j_ct_b_bits},
4976 {JUST_RIGHT |JUST_TOP , j_rt_b_bits}
4979 OptionStructure *CreateTextJustChoice(Widget parent, char *s)
4981 return (CreateBitmapOptionChoice(parent, s, 4,
4982 12, JBITMAP_WIDTH, JBITMAP_HEIGHT, text_just_option_items));
4985 static BitmapOptionItem just_option_items[9] =
4987 {JUST_LEFT |JUST_BOTTOM, j_lb_b_bits},
4988 {JUST_CENTER|JUST_BOTTOM, j_cb_b_bits},
4989 {JUST_RIGHT |JUST_BOTTOM, j_rb_b_bits},
4990 {JUST_LEFT |JUST_MIDDLE, j_lm_b_bits},
4991 {JUST_CENTER|JUST_MIDDLE, j_cm_b_bits},
4992 {JUST_RIGHT |JUST_MIDDLE, j_rm_b_bits},
4993 {JUST_LEFT |JUST_TOP , j_lt_b_bits},
4994 {JUST_CENTER|JUST_TOP , j_ct_b_bits},
4995 {JUST_RIGHT |JUST_TOP , j_rt_b_bits}
4998 OptionStructure *CreateJustChoice(Widget parent, char *s)
5000 return (CreateBitmapOptionChoice(parent, s, 3,
5001 9, JBITMAP_WIDTH, JBITMAP_HEIGHT, just_option_items));
5004 //RestrictionStructure *CreateRestrictionChoice(Widget parent, char *s)
5006 // RestrictionStructure *retval;
5007 // Widget rc;
5008 // OptionItem restr_items[7];
5010 // restr_items[0].value = RESTRICT_NONE;
5011 // restr_items[0].label = "None";
5012 // restr_items[1].value = RESTRICT_REG0;
5013 // restr_items[1].label = "Region 0";
5014 // restr_items[2].value = RESTRICT_REG1;
5015 // restr_items[2].label = "Region 1";
5016 // restr_items[3].value = RESTRICT_REG2;
5017 // restr_items[3].label = "Region 2";
5018 // restr_items[4].value = RESTRICT_REG3;
5019 // restr_items[4].label = "Region 3";
5020 // restr_items[5].value = RESTRICT_REG4;
5021 // restr_items[5].label = "Region 4";
5022 // restr_items[6].value = RESTRICT_WORLD;
5023 // restr_items[6].label = "Inside graph";
5025 // retval = xmalloc(sizeof(RestrictionStructure));
5027 // retval->frame = CreateFrame(parent, s);
5028 // rc = XtVaCreateWidget("rc",
5029 // xmRowColumnWidgetClass, retval->frame,
5030 // XmNorientation, XmHORIZONTAL,
5031 // NULL);
5033 // retval->r_sel = CreateOptionChoice(rc,
5034 // "Restriction:", 1, 7, restr_items);
5035 // retval->negate = CreateToggleButton(rc, "Negated");
5036 // XtManageChild(rc);
5038 // return retval;
5040 RestrictionStructure *CreateRestrictionChoice(Widget parent, char *s)
5042 RestrictionStructure *retval;
5043 OptionItem restr_items[7];
5045 restr_items[0].value = RESTRICT_NONE;
5046 restr_items[0].label = "None";
5047 restr_items[1].value = RESTRICT_REG0;
5048 restr_items[1].label = "Region 0";
5049 restr_items[2].value = RESTRICT_REG1;
5050 restr_items[2].label = "Region 1";
5051 restr_items[3].value = RESTRICT_REG2;
5052 restr_items[3].label = "Region 2";
5053 restr_items[4].value = RESTRICT_REG3;
5054 restr_items[4].label = "Region 3";
5055 restr_items[5].value = RESTRICT_REG4;
5056 restr_items[5].label = "Region 4";
5057 restr_items[6].value = RESTRICT_WORLD;
5058 restr_items[6].label = "Inside graph";
5060 retval = (RestrictionStructure*) xmalloc(sizeof(RestrictionStructure));
5062 QWidget *rc = CreateFrame(parent, s);
5063 retval->frame = rc;
5065 retval->r_sel = CreateOptionChoice(rc,
5066 "Restriction:", 1, 7, restr_items);
5067 retval->negate = CreateToggleButton(rc, "Negated");
5069 return retval;
5072 #define PEN_CHOICE_WIDTH 64
5073 #define PEN_CHOICE_HEIGHT 16
5075 typedef struct {
5076 Pen pen;
5077 Widget color_popup;
5078 Widget pattern_popup;
5080 Pen_CBProc cb_proc;
5081 void *cb_data;
5082 } Button_PData;
5084 //static GC gc_pen;
5086 //static void SetPenChoice_int(Widget button, Pen *pen, int call_cb)
5088 // X11Stuff *xstuff = gapp->gui->xstuff;
5089 // Pixel bg, fg;
5090 // Pixmap pixtile, pixmap;
5091 // Button_PData *pdata;
5092 // Pattern *pat;
5094 // /* Safety checks */
5095 // if (!button || !pen ||
5096 // (pen->pattern < 0 || pen->pattern >= number_of_patterns(canvas)) ||
5097 // (pen->color < 0 || pen->color >= number_of_colors(canvas))) {
5098 // return;
5099 // }
5101 // pdata = GetUserData(button);
5102 // pdata->pen = *pen;
5104 // if (!gc_pen) {
5105 // gc_pen = XCreateGC(xstuff->disp, xstuff->root, 0, NULL);
5106 // XSetFillStyle(xstuff->disp, gc_pen, FillTiled);
5107 // }
5109 // fg = xvlibcolors[pen->color];
5110 // bg = xvlibcolors[getbgcolor(canvas)];
5112 // pat = canvas_get_pattern(canvas, pen->pattern);
5113 // pixtile = XCreatePixmapFromBitmapData(xstuff->disp, xstuff->root,
5114 // (char *) pat->bits, pat->width, pat->height, fg, bg, xstuff->depth);
5116 // XSetTile(xstuff->disp, gc_pen, pixtile);
5118 // pixmap = XCreatePixmap(xstuff->disp, xstuff->root, PEN_CHOICE_WIDTH, PEN_CHOICE_HEIGHT, xstuff->depth);
5119 // XFillRectangle(xstuff->disp, pixmap, gc_pen, 0, 0, PEN_CHOICE_WIDTH, PEN_CHOICE_HEIGHT);
5121 // XtVaSetValues(button, XmNlabelPixmap, pixmap, NULL);
5123 // XFreePixmap(xstuff->disp, pixtile);
5125 // if (call_cb && pdata->cb_proc) {
5126 // pdata->cb_proc(button, pen, pdata->cb_data);
5127 // }
5129 static void SetPenChoice_int(Widget button, Pen *pen, int call_cb)
5131 QPushButton *pushButton = (QPushButton *) button;
5132 Canvas *canvas = grace_get_canvas(gapp->grace);
5133 RGB bg_rgb, fg_rgb;
5134 Button_PData *pdata;
5135 Pattern *pat;
5137 /* Safety checks */
5138 if (!button || !pen ||
5139 (pen->pattern < 0 || pen->pattern >= number_of_patterns(canvas)) ||
5140 (pen->color < 0 || pen->color >= number_of_colors(canvas))) {
5141 return;
5144 pdata = (Button_PData *) WidgetGetUserData(button);
5145 pdata->pen = *pen;
5147 get_rgb(canvas, pen->color, &fg_rgb);
5148 get_rgb(canvas, getbgcolor(canvas), &bg_rgb);
5150 pat = canvas_get_pattern(canvas, pen->pattern);
5152 QBitmap bitmap = QBitmap::fromData(QSize(pat->width, pat->height),
5153 pat->bits, QImage::Format_MonoLSB);
5155 QPixmap pixmap(PEN_CHOICE_WIDTH, PEN_CHOICE_HEIGHT);
5156 pixmap.fill(QColor(bg_rgb.red, bg_rgb.green, bg_rgb.blue));
5158 QPainter painter(&pixmap);
5159 painter.setPen(QColor(fg_rgb.red, fg_rgb.green, fg_rgb.blue));
5160 painter.drawTiledPixmap(0, 0, PEN_CHOICE_WIDTH, PEN_CHOICE_HEIGHT, bitmap);
5162 pushButton->setIcon(QIcon(pixmap));
5163 pushButton->setIconSize(QSize(PEN_CHOICE_WIDTH, PEN_CHOICE_HEIGHT));
5165 if (call_cb && pdata->cb_proc) {
5166 pdata->cb_proc(button, pen, pdata->cb_data);
5170 void SetPenChoice(Widget button, Pen *pen)
5172 SetPenChoice_int(button, pen, FALSE);
5175 //static void pen_popup(Widget parent,
5176 // XtPointer closure, XEvent *event, Boolean *cont)
5178 // XButtonPressedEvent *e = (XButtonPressedEvent *) event;
5179 // Button_PData *pdata;
5180 // Widget popup;
5182 // if (e->button != 3) {
5183 // return;
5184 // }
5186 // pdata = GetUserData(parent);
5188 // if (e->state & ShiftMask) {
5189 // popup = pdata->pattern_popup;
5190 // } else {
5191 // popup = pdata->color_popup;
5192 // }
5194 // SetUserData(popup, parent);
5196 // XmMenuPosition(popup, e);
5197 // XtManageChild(popup);
5199 static void pen_popup(Widget w, XtPointer client_data, XtPointer call_data)
5201 qDebug("Button pressed");
5202 Button_PData *pdata;
5203 Widget popup;
5205 pdata = (Button_PData *) WidgetGetUserData(w);
5207 // if (e->state & ShiftMask) {
5208 // popup = pdata->pattern_popup;
5209 // } else {
5210 popup = pdata->color_popup;
5211 // }
5213 QMenu *menu = (QMenu *) popup->parentWidget();
5214 WidgetSetUserData(popup, w);
5216 menu->popup(QCursor::pos());
5219 //static void cc_cb(Widget w, XtPointer client_data, XtPointer call_data)
5221 // Pen pen;
5222 // Widget button = GetUserData(GetParent(w));
5223 // Button_PData *pdata;
5225 // pdata = GetUserData(button);
5226 // pen = pdata->pen;
5227 // pen.color = (long) client_data;
5229 // SetPenChoice_int(button, &pen, TRUE);
5231 static void cc_cb(Widget w, XtPointer client_data, XtPointer call_data)
5233 QTableWidget *tableWidget = (QTableWidget *) w;
5234 QTableWidgetItem *item = tableWidget->currentItem();
5235 QPushButton *button = (QPushButton *) WidgetGetUserData(tableWidget);
5236 QMenu *menu = (QMenu *) tableWidget->parentWidget();
5237 Pen pen;
5238 Button_PData *pdata;
5240 pdata = (Button_PData *) WidgetGetUserData(button);
5241 pen = pdata->pen;
5242 pen.color = item->data(Qt::UserRole).toInt();
5244 SetPenChoice_int(button, &pen, TRUE);
5246 tableWidget->setCurrentItem(0);
5247 menu->hide();
5250 //void update_color_choice_popup(void)
5252 // X11Stuff *xstuff = gapp->gui->xstuff;
5253 // Project *pr = project_get_data(gproject_get_top(gapp->gp));
5254 // unsigned int ci;
5256 // if (pr && color_choice_popup) {
5257 // int ncols = 4;
5258 // Widget *ws = NULL;
5259 // Cardinal nw_old = 0, nw_new = pr->ncolors;
5261 // XtVaGetValues(color_choice_popup,
5262 // XtNnumChildren, &nw_old,
5263 // XtNchildren, &ws,
5264 // NULL);
5266 // /* Delete extra button widgets, if any */
5267 // if (nw_new < nw_old) {
5268 // XtUnmanageChildren(ws + nw_new, nw_old - nw_new);
5270 // for (ci = nw_new; ci < nw_old; ci++) {
5271 // XtDestroyWidget(ws[ci]);
5272 // }
5273 // }
5275 // /* Don't create too tall pulldowns */
5276 // if (nw_new > MAX_PULLDOWN_LENGTH*ncols) {
5277 // ncols = (nw_new + MAX_PULLDOWN_LENGTH - 1)/MAX_PULLDOWN_LENGTH;
5278 // }
5280 // XtVaSetValues(color_choice_popup,
5281 // XmNnumColumns, ncols,
5282 // XmNpacking, XmPACK_COLUMN,
5283 // NULL);
5285 // /* Create new buttons, if needed */
5286 // for (ci = nw_old; ci < nw_new; ci++) {
5287 // Widget cb;
5288 // cb = XmCreatePushButton(color_choice_popup, "cb", NULL, 0);
5289 // }
5291 // XtVaGetValues(color_choice_popup,
5292 // XtNchildren, &ws,
5293 // NULL);
5295 // /* Manage newly added widgets */
5296 // if (nw_new > nw_old) {
5297 // XtManageChildren(ws + nw_old, nw_new - nw_old);
5298 // }
5300 // /* Paint/label new buttons */
5301 // for (ci = 0; ci < pr->ncolors; ci++) {
5302 // Colordef *c = &pr->colormap[ci];
5303 // long bg, fg;
5304 // long color = c->id;
5305 // Widget cb = ws[ci];
5306 // XmString str;
5308 // bg = xvlibcolors[color];
5309 // if (get_rgb_intensity(&c->rgb) < 0.5) {
5310 // fg = WhitePixel(xstuff->disp, xstuff->screennumber);
5311 // } else {
5312 // fg = BlackPixel(xstuff->disp, xstuff->screennumber);
5313 // }
5315 // XtRemoveAllCallbacks(cb, XmNactivateCallback);
5316 // XtAddCallback(cb, XmNactivateCallback, cc_cb, (XtPointer) color);
5318 // str = XmStringCreateLocalized(c->cname);
5319 // XtVaSetValues(cb,
5320 // XmNlabelString, str,
5321 // XmNbackground, bg,
5322 // XmNforeground, fg,
5323 // NULL);
5324 // XmStringFree(str);
5325 // }
5326 // }
5328 void update_color_choice_popup(void)
5330 Project *pr = project_get_data(gproject_get_top(gapp->gp));
5331 unsigned int ci;
5333 if (pr && color_choice_popup) {
5334 QTableWidget *tableWidget = (QTableWidget *) color_choice_popup;
5335 int ncols = 4;
5337 tableWidget->clear();
5339 /* Don't create too tall pulldowns */
5340 if (pr->ncolors > MAX_PULLDOWN_LENGTH*ncols) {
5341 ncols = (pr->ncolors + MAX_PULLDOWN_LENGTH - 1)/MAX_PULLDOWN_LENGTH;
5344 int row = 0;
5345 int col = 0;
5346 int nrows = (int) ceil(pr->ncolors/ncols);
5348 tableWidget->setRowCount(nrows);
5349 tableWidget->setColumnCount(ncols);
5351 for (ci = 0; ci < pr->ncolors; ci++) {
5352 Colordef *c = &pr->colormap[ci];
5353 QTableWidgetItem *item = new QTableWidgetItem(c->cname);
5354 item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
5356 QColor bg_color(c->rgb.red, c->rgb.green, c->rgb.blue);
5357 item->setBackground(QBrush(bg_color));
5359 if (get_rgb_intensity(&c->rgb) < 0.5) {
5360 item->setForeground(Qt::white);
5361 } else {
5362 item->setForeground(Qt::black);
5365 item->setData(Qt::UserRole, QVariant(c->id));
5366 tableWidget->setItem(row, col, item);
5367 row++;
5368 if (row == nrows) {
5369 row = 0;
5370 col++;
5374 tableWidget->resizeColumnsToContents();
5375 int max = 0;
5376 for (int i = 0; i < ncols; i++) {
5377 int size = tableWidget->horizontalHeader()->sectionSize(i);
5378 if (size > max) max = size;
5380 tableWidget->horizontalHeader()->setDefaultSectionSize(max);
5381 tableWidget->horizontalHeader()->resizeSections(QHeaderView::Fixed);
5382 tableWidget->resizeRowsToContents();
5383 tableWidget->setFixedWidth(tableWidget->horizontalHeader()->length());
5384 tableWidget->setFixedHeight(tableWidget->verticalHeader()->length());
5388 //static Widget CreateColorChoicePopup(Widget button)
5390 // if (!color_choice_popup) {
5391 // color_choice_popup =
5392 // XmCreatePopupMenu(button, "colorPopupMenu", NULL, 0);
5393 // update_color_choice_popup();
5394 // } else {
5395 // XmAddToPostFromList(color_choice_popup, button);
5396 // }
5398 // return color_choice_popup;
5400 static Widget CreateColorChoicePopup(Widget button)
5402 if (!color_choice_popup) {
5403 QMenu *menu = new QMenu(button);
5405 QTableWidget *tableWidget = new QTableWidget(menu);
5406 tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
5407 tableWidget->horizontalHeader()->setVisible(false);
5408 tableWidget->verticalHeader()->setVisible(false);
5409 tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
5410 tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
5411 tableWidget->setFrameStyle(QFrame::NoFrame);
5412 QtAddCallback(tableWidget, SIGNAL(cellClicked(int, int)),
5413 cc_cb, (XtPointer) NULL);
5415 QWidgetAction *action = new QWidgetAction(menu);
5416 action->setDefaultWidget(tableWidget);
5418 menu->addAction(action);
5420 color_choice_popup = tableWidget;
5422 update_color_choice_popup();
5425 return color_choice_popup;
5428 //static Widget CreatePatternChoicePopup(Widget button)
5430 // Widget popup;
5432 // popup = XmCreatePopupMenu(button, "patternPopupMenu", NULL, 0);
5433 // CreateMenuLabel(popup, "Pattern:");
5434 // CreateMenuSeparator(popup);
5436 // return popup;
5439 typedef struct {
5440 Widget top;
5441 OptionStructure *color;
5442 OptionStructure *pattern;
5444 Widget pen_button;
5445 } PenChoiceDialog;
5447 static int pen_choice_aac(void *data)
5449 PenChoiceDialog *ui = (PenChoiceDialog *) data;
5451 if (ui->pen_button) {
5452 Pen pen;
5453 pen.color = GetOptionChoice(ui->color);
5454 pen.pattern = GetOptionChoice(ui->pattern);
5456 SetPenChoice_int(ui->pen_button, &pen, TRUE);
5459 return RETURN_SUCCESS;
5462 //static void define_pen_choice_dialog(Widget but, void *data)
5464 // static PenChoiceDialog *ui = NULL;
5466 // set_wait_cursor();
5468 // if (!ui) {
5469 // Widget fr, rc;
5471 // ui = xmalloc(sizeof(PenChoiceDialog));
5473 // ui->top = CreateDialogForm(app_shell, "Pen properties");
5475 // fr = CreateFrame(ui->top, "Pen");
5476 // rc = CreateVContainer(fr);
5477 // ui->color = CreateColorChoice(rc, "Color");
5478 // ui->pattern = CreatePatternChoice(rc, "Pattern");
5480 // CreateAACDialog(ui->top, fr, pen_choice_aac, ui);
5481 // }
5483 // ui->pen_button = (Widget) data;
5485 // if (ui->pen_button) {
5486 // Button_PData *pdata;
5487 // Pen pen;
5489 // pdata = GetUserData(ui->pen_button);
5491 // pen = pdata->pen;
5493 // SetOptionChoice(ui->color, pen.color);
5494 // SetOptionChoice(ui->pattern, pen.pattern);
5495 // }
5497 // RaiseWindow(GetParent(ui->top));
5498 // unset_wait_cursor();
5500 static void define_pen_choice_dialog(Widget but, void *data)
5502 static PenChoiceDialog *ui = NULL;
5504 set_wait_cursor();
5506 if (!ui) {
5507 Widget fr, rc;
5509 ui = (PenChoiceDialog *) xmalloc(sizeof(PenChoiceDialog));
5511 ui->top = CreateDialog(app_shell, "Pen properties");
5513 fr = CreateFrame(ui->top, "Pen");
5514 rc = CreateVContainer(fr);
5515 ui->color = CreateColorChoice(rc, "Color");
5516 ui->pattern = CreatePatternChoice(rc, "Pattern");
5518 CreateAACDialog(ui->top, fr, pen_choice_aac, ui);
5521 ui->pen_button = (Widget) data;
5523 if (ui->pen_button) {
5524 Button_PData *pdata;
5525 Pen pen;
5527 pdata = (Button_PData *) WidgetGetUserData(ui->pen_button);
5529 pen = pdata->pen;
5531 SetOptionChoice(ui->color, pen.color);
5532 SetOptionChoice(ui->pattern, pen.pattern);
5535 RaiseWindow(GetParent(ui->top));
5536 unset_wait_cursor();
5539 //Widget CreatePenChoice(Widget parent, char *s)
5541 // Widget rc, button;
5542 // Button_PData *pdata;
5543 // Pen pen;
5545 // pdata = xmalloc(sizeof(Button_PData));
5546 // memset(pdata, 0, sizeof(Button_PData));
5548 // rc = CreateHContainer(parent);
5549 // CreateLabel(rc, s);
5550 // button = XtVaCreateWidget("penButton",
5551 // xmPushButtonWidgetClass, rc,
5552 // XmNlabelType, XmPIXMAP,
5553 // XmNuserData, pdata,
5554 // NULL);
5556 // AddHelpCB(button, "doc/UsersGuide.html#pen-chooser");
5558 // AddButtonCB(button, define_pen_choice_dialog, button);
5560 // pdata->color_popup = CreateColorChoicePopup(button);
5561 // pdata->pattern_popup = CreatePatternChoicePopup(button);
5563 // XtAddEventHandler(button, ButtonPressMask, False, pen_popup, NULL);
5565 // pen.color = 0;
5566 // pen.pattern = 0;
5567 // SetPenChoice_int(button, &pen, FALSE);
5569 // XtManageChild(button);
5571 // return button;
5573 Widget CreatePenChoice(Widget parent, char *s)
5575 Button_PData *pdata;
5576 Pen pen;
5578 pdata = (Button_PData *) xmalloc(sizeof(Button_PData));
5579 memset(pdata, 0, sizeof(Button_PData));
5581 QLabel *label = new QLabel(parent);
5582 label->setText(s);
5584 QPushButton *button = new QPushButton(parent);
5586 WidgetSetUserData(button, pdata);
5588 AddHelpCB(button, "doc/UsersGuide.html#pen-chooser");
5590 AddButtonCB(button, define_pen_choice_dialog, button);
5592 pdata->color_popup = CreateColorChoicePopup(button);
5593 //TODO:
5594 // pdata->pattern_popup = CreatePatternChoicePopup(button);
5596 button->setContextMenuPolicy(Qt::CustomContextMenu);
5597 QtAddCallback(button, SIGNAL(customContextMenuRequested(const QPoint)),
5598 pen_popup, NULL);
5600 pen.color = 0;
5601 pen.pattern = 0;
5602 SetPenChoice_int(button, &pen, FALSE);
5604 QWidget *widget = new QWidget(parent);
5606 QHBoxLayout *hLayout = new QHBoxLayout;
5607 hLayout->setContentsMargins(0,0,0,0);
5608 hLayout->addWidget(label);
5609 hLayout->addWidget(button);
5610 widget->setLayout(hLayout);
5612 QLayout *layout = parent->layout();
5613 if (layout != 0) {
5614 layout->addWidget(widget);
5617 return button;
5620 //int GetPenChoice(Widget pen_button, Pen *pen)
5622 // Button_PData *pdata = GetUserData(pen_button);
5623 // if (pdata) {
5624 // *pen = pdata->pen;
5625 // return RETURN_SUCCESS;
5626 // } else {
5627 // return RETURN_FAILURE;
5628 // }
5630 int GetPenChoice(Widget pen_button, Pen *pen)
5632 Button_PData *pdata = (Button_PData *) WidgetGetUserData(pen_button);
5633 if (pdata) {
5634 *pen = pdata->pen;
5635 return RETURN_SUCCESS;
5636 } else {
5637 return RETURN_FAILURE;
5641 //void AddPenChoiceCB(Widget button, Pen_CBProc cbproc, void *anydata)
5643 // Button_PData *pdata = GetUserData(button);
5645 // if (pdata->cb_proc) {
5646 // errmsg("AddPenChoiceCB: only one callback is supported");
5647 // } else {
5648 // pdata->cb_proc = cbproc;
5649 // pdata->cb_data = anydata;
5650 // }
5652 void AddPenChoiceCB(Widget button, Pen_CBProc cbproc, void *anydata)
5654 Button_PData *pdata = (Button_PData *) WidgetGetUserData(button);
5656 if (pdata->cb_proc) {
5657 errmsg("AddPenChoiceCB: only one callback is supported");
5658 } else {
5659 pdata->cb_proc = cbproc;
5660 pdata->cb_data = anydata;
5664 SpinStructure *CreateViewCoordInput(Widget parent, char *s)
5666 return CreateSpinChoice(parent, s, 6, SPIN_TYPE_FLOAT, -10.0, 10.0, 0.05);
5669 static StorageStructure **ssd_selectors = NULL;
5670 static int nssd_selectors = 0;
5672 static char *ssd_labeling(Quark *q, unsigned int *rid)
5674 char *buf;
5676 if (!q) {
5677 return NULL;
5680 buf = (char *) xmalloc(strlen(QIDSTR(q)) + 128);
5681 if (!buf) {
5682 return NULL;
5685 if (quark_fid_get(q) == QFlavorSSD) {
5686 sprintf(buf, "SSD \"%s\" (%d x %d)", QIDSTR(q),
5687 ssd_get_ncols(q), ssd_get_nrows(q));
5689 (*rid)++;
5691 return buf;
5692 } else {
5693 return NULL;
5697 StorageStructure *CreateSSDChoice(Widget parent, char *labelstr, int type)
5699 StorageStructure *ss;
5700 int nvisible;
5702 nvisible = (type == LIST_TYPE_SINGLE) ? 4 : 6;
5704 ss = CreateStorageChoice(parent, labelstr, type, nvisible);
5705 SetStorageChoiceLabeling(ss, ssd_labeling);
5706 SetStorageChoiceQuark(ss, gproject_get_top(gapp->gp));
5708 nssd_selectors++;
5709 ssd_selectors =
5710 (StorageStructure**) xrealloc(ssd_selectors, nssd_selectors*sizeof(StorageStructure *));
5711 ssd_selectors[nssd_selectors - 1] = ss;
5713 AddHelpCB(ss->rc, "doc/UsersGuide.html#ssd-selector");
5715 return ss;
5718 int GetSSDColChoices(SSDColStructure *sc, Quark **ssd, int **cols)
5720 if (GetSingleStorageChoice(sc->ssd_sel, ssd) != RETURN_SUCCESS) {
5721 return -1;
5722 } else {
5723 return GetListChoices(sc->col_sel, cols);
5727 void update_ssd_selectors(Quark *pr)
5729 int i;
5730 for (i = 0; i < nssd_selectors; i++) {
5731 StorageStructure *ss = ssd_selectors[i];
5732 if (!ss->q && pr) {
5733 ss->q = pr;
5734 } else
5735 if (!pr) {
5736 ss->q = NULL;
5738 UpdateStorageChoice(ss);
5743 static StorageStructure **graph_selectors = NULL;
5744 static int ngraph_selectors = 0;
5746 #define GSS_FOCUS_CB 0
5748 typedef struct {
5749 Widget focus_bt;
5750 } GSSData;
5752 static void gss_any_cb(void *udata, int cbtype)
5754 StorageStructure *ss = (StorageStructure *) udata;
5755 int i, n;
5756 Quark **values;
5758 n = GetStorageChoices(ss, &values);
5760 for (i = 0; i < n; i ++) {
5761 Quark *gr = values[i];
5763 switch (cbtype) {
5764 case GSS_FOCUS_CB:
5765 switch_current_graph(gr);
5766 break;
5770 if (n > 0) {
5771 xfree(values);
5772 update_all();
5773 xdrawgraph(gapp->gp);
5777 static void g_focus_cb(Widget but, void *udata)
5779 gss_any_cb(udata, GSS_FOCUS_CB);
5782 static void g_popup_cb(StorageStructure *ss, int nselected)
5784 GSSData *gssdata = (GSSData *) ss->data;
5786 WidgetSetSensitive(gssdata->focus_bt, (nselected == 1));
5789 static void g_new_cb(Widget but, void *udata)
5791 graph_next(gproject_get_top(gapp->gp));
5792 snapshot_and_update(gapp->gp, TRUE);
5795 //static char *graph_labeling(Quark *q, unsigned int *rid)
5797 // char buf[128];
5799 // if (quark_fid_get(q) == QFlavorGraph) {
5800 // sprintf(buf, "Graph \"%s\" (type: %s, sets: %d)",
5801 // QIDSTR(q),
5802 // graph_types(gapp->grace, graph_get_type(q)), quark_get_number_of_descendant_sets(q));
5804 // (*rid)++;
5806 // return copy_string(NULL, buf);
5807 // } else {
5808 // return NULL;
5809 // }
5811 static char *graph_labeling(Quark *q, unsigned int *rid)
5813 char *buf;
5815 if (!q) {
5816 return NULL;
5819 buf = (char *) xmalloc(strlen(QIDSTR(q)) + 128);
5820 if (!buf) {
5821 return NULL;
5824 if (quark_fid_get(q) == QFlavorGraph) {
5825 sprintf(buf, "Graph \"%s\" (type: %s, sets: %d)",
5826 QIDSTR(q),
5827 graph_types(gapp->grace, (GraphType) graph_get_type(q)),
5828 quark_get_number_of_descendant_sets(q));
5830 (*rid)++;
5832 return buf;
5833 } else {
5834 return NULL;
5838 //StorageStructure *CreateGraphChoice(Widget parent, char *labelstr, int type)
5840 // StorageStructure *ss;
5841 // GSSData *gssdata;
5842 // Widget popup;
5843 // int nvisible;
5845 // nvisible = (type == LIST_TYPE_SINGLE) ? 2 : 4;
5846 // ss = CreateStorageChoice(parent, labelstr, type, nvisible);
5847 // SetStorageChoiceLabeling(ss, graph_labeling);
5848 // SetStorageChoiceQuark(ss, gproject_get_top(gapp->gp));
5849 // AddHelpCB(ss->rc, "doc/UsersGuide.html#graph-selector");
5851 // ngraph_selectors++;
5852 // graph_selectors =
5853 // xrealloc(graph_selectors, ngraph_selectors*sizeof(StorageStructure *));
5854 // graph_selectors[ngraph_selectors - 1] = ss;
5856 // gssdata = xmalloc(sizeof(GSSData));
5857 // ss->data = gssdata;
5858 // ss->popup_cb = g_popup_cb;
5860 // popup = ss->popup;
5862 // CreateMenuSeparator(popup);
5864 // CreateMenuButton(popup, "Create new", '\0', g_new_cb, ss);
5866 // CreateMenuSeparator(popup);
5868 // gssdata->focus_bt =
5869 // CreateMenuButton(popup, "Focus to selected", '\0', g_focus_cb, ss);
5871 // return ss;
5873 StorageStructure *CreateGraphChoice(Widget parent, char *labelstr, int type)
5875 StorageStructure *ss;
5876 GSSData *gssdata;
5877 Widget popup;
5878 int nvisible;
5880 nvisible = (type == LIST_TYPE_SINGLE) ? 2 : 4;
5881 ss = CreateStorageChoice(parent, labelstr, type, nvisible);
5882 SetStorageChoiceLabeling(ss, graph_labeling);
5883 SetStorageChoiceQuark(ss, gproject_get_top(gapp->gp));
5884 AddHelpCB(ss->rc, "doc/UsersGuide.html#graph-selector");
5886 ngraph_selectors++;
5887 graph_selectors =
5888 (StorageStructure**) xrealloc(graph_selectors,
5889 ngraph_selectors*sizeof(StorageStructure *));
5890 graph_selectors[ngraph_selectors - 1] = ss;
5892 gssdata = (GSSData*) xmalloc(sizeof(GSSData));
5893 ss->data = gssdata;
5894 ss->popup_cb = g_popup_cb;
5896 popup = ss->popup;
5898 CreateMenuSeparator(popup);
5900 CreateMenuButton(popup, "Create new", '\0', g_new_cb, ss);
5902 CreateMenuSeparator(popup);
5904 gssdata->focus_bt =
5905 CreateMenuButton(popup, "Focus to selected", '\0', g_focus_cb, ss);
5907 return ss;
5910 void update_graph_selectors(Quark *pr)
5912 int i;
5913 for (i = 0; i < ngraph_selectors; i++) {
5914 StorageStructure *ss = graph_selectors[i];
5915 if (!ss->q && pr) {
5916 ss->q = pr;
5917 } else
5918 if (!pr) {
5919 ss->q = NULL;
5921 UpdateStorageChoice(ss);
5925 void graph_set_selectors(Quark *gr)
5927 int i;
5929 for (i = 0; i < ngraph_selectors; i++) {
5930 SelectStorageChoice(graph_selectors[i], gr);
5934 static StorageStructure **frame_selectors = NULL;
5935 static int nframe_selectors = 0;
5937 static char *frame_labeling(Quark *q, unsigned int *rid)
5939 char *buf;
5941 if (!q) {
5942 return NULL;
5945 buf = (char *) xmalloc(strlen(QIDSTR(q)) + 128);
5946 if (!buf) {
5947 return NULL;
5950 if (quark_fid_get(q) == QFlavorFrame) {
5951 sprintf(buf, "Frame \"%s\"", QIDSTR(q));
5953 (*rid)++;
5955 return buf;
5956 } else {
5957 return NULL;
5961 StorageStructure *CreateFrameChoice(Widget parent, char *labelstr, int type)
5963 StorageStructure *ss;
5964 Widget popup;
5965 int nvisible;
5967 nvisible = (type == LIST_TYPE_SINGLE) ? 2 : 4;
5968 ss = CreateStorageChoice(parent, labelstr, type, nvisible);
5969 SetStorageChoiceLabeling(ss, frame_labeling);
5970 SetStorageChoiceQuark(ss, gproject_get_top(gapp->gp));
5971 AddHelpCB(ss->rc, "doc/UsersGuide.html#frame-selector");
5973 nframe_selectors++;
5974 frame_selectors =
5975 (StorageStructure **) xrealloc(frame_selectors, nframe_selectors*sizeof(StorageStructure *));
5976 frame_selectors[nframe_selectors - 1] = ss;
5978 popup = ss->popup;
5980 CreateMenuSeparator(popup);
5982 CreateMenuButton(popup, "Create new", '\0', g_new_cb, ss);
5984 CreateMenuSeparator(popup);
5986 return ss;
5989 void update_frame_selectors(Quark *pr)
5991 int i;
5992 for (i = 0; i < nframe_selectors; i++) {
5993 StorageStructure *ss = frame_selectors[i];
5994 if (!ss->q && pr) {
5995 ss->q = pr;
5996 } else
5997 if (!pr) {
5998 ss->q = NULL;
6000 UpdateStorageChoice(ss);
6004 /* Set selectors */
6005 static StorageStructure **set_selectors = NULL;
6006 static int nset_selectors = 0;
6009 #define SSS_NEWF_CB 1
6011 typedef struct {
6012 StorageStructure *graphss;
6013 } SSSData;
6015 Quark *get_set_choice_gr(StorageStructure *ss)
6017 Quark *gr;
6018 SSSData *sdata = (SSSData *) ss->data;
6020 if (sdata->graphss) {
6021 if (GetSingleStorageChoice(sdata->graphss, &gr) != RETURN_SUCCESS) {
6022 gr = NULL;
6024 } else {
6025 gr = NULL;
6028 return gr;
6031 static void sss_any_cb(void *udata, int cbtype)
6033 StorageStructure *ss = (StorageStructure *) udata;
6034 Quark *gr = get_set_choice_gr(ss);
6036 switch (cbtype) {
6037 case SSS_NEWF_CB:
6038 create_leval_frame(NULL, gr);
6039 break;
6042 snapshot_and_update(gapp->gp, TRUE);
6045 static void s_newF_cb(Widget but, void *udata)
6047 sss_any_cb(udata, SSS_NEWF_CB);
6050 static char *set_labeling(Quark *q, unsigned int *rid)
6052 char *buf;
6054 if (!q) {
6055 return NULL;
6058 buf = (char *) xmalloc(strlen(QIDSTR(q)) + 128);
6059 if (!buf) {
6060 return NULL;
6063 if (quark_fid_get(q) == QFlavorSet) {
6064 set *p = set_get_data(q);
6066 sprintf(buf, "Set \"%s\" (type: %s, length: %d)",
6067 QIDSTR(q), set_type_descr(gapp->grace, (SetType) p->type),
6068 set_get_length(q));
6070 (*rid)++;
6072 return buf;
6073 } else {
6074 return NULL;
6078 StorageStructure *CreateSetChoice(Widget parent,
6079 char *labelstr, int type, StorageStructure *graphss)
6081 StorageStructure *ss;
6082 SSSData *sssdata;
6083 Widget popup, submenupane;
6084 int nvisible;
6086 nvisible = (type == LIST_TYPE_SINGLE) ? 4 : 8;
6087 ss = CreateStorageChoice(parent, labelstr, type, nvisible);
6088 SetStorageChoiceLabeling(ss, set_labeling);
6089 AddHelpCB(ss->rc, "doc/UsersGuide.html#set-selector");
6091 nset_selectors++;
6092 set_selectors =
6093 (StorageStructure**) xrealloc(set_selectors, nset_selectors*sizeof(StorageStructure *));
6094 set_selectors[nset_selectors - 1] = ss;
6096 sssdata = (SSSData*) xmalloc(sizeof(SSSData));
6097 ss->data = sssdata;
6098 sssdata->graphss = graphss;
6100 popup = ss->popup;
6102 CreateMenuSeparator(popup);
6104 submenupane = CreateMenu(popup, "Create new", '\0', FALSE);
6105 CreateMenuButton(submenupane, "By formula", '\0', s_newF_cb, ss);
6107 UpdateSetChoice(ss);
6109 return ss;
6112 void UpdateSetChoice(StorageStructure *ss)
6114 Quark *gr;
6116 gr = get_set_choice_gr(ss);
6118 SetStorageChoiceQuark(ss, gr);
6122 void update_set_selectors(Quark *gr)
6124 int i;
6126 if (gr) {
6127 update_graph_selectors(get_parent_project(gr));
6130 for (i = 0; i < nset_selectors; i++) {
6131 Quark *cg;
6133 cg = get_set_choice_gr(set_selectors[i]);
6134 if (!gr || cg == gr) {
6135 UpdateSetChoice(set_selectors[i]);
6140 static void update_sets_cb(StorageStructure *ss, int n, Quark **values, void *data)
6142 GraphSetStructure *gs = (GraphSetStructure *) data;
6144 UpdateSetChoice(gs->set_sel);
6147 //GraphSetStructure *CreateGraphSetSelector(Widget parent, char *s, int sel_type)
6149 // GraphSetStructure *retval;
6150 // Widget rc;
6152 // retval = xmalloc(sizeof(GraphSetStructure));
6153 // retval->frame = CreateFrame(parent, s);
6154 // rc = XtVaCreateWidget("rc", xmRowColumnWidgetClass, retval->frame, NULL);
6155 // retval->graph_sel = CreateGraphChoice(rc, "Graph:", LIST_TYPE_SINGLE);
6156 // retval->set_sel = CreateSetChoice(rc, "Set:", sel_type, retval->graph_sel);
6157 // AddStorageChoiceCB(retval->graph_sel, update_sets_cb, (void *) retval);
6158 // UpdateSetChoice(retval->set_sel);
6159 // retval->set_sel->governor = retval->graph_sel;
6160 // XtManageChild(rc);
6162 // return retval;
6164 GraphSetStructure *CreateGraphSetSelector(Widget parent, char *s, int sel_type)
6166 GraphSetStructure *retval;
6168 retval = (GraphSetStructure*) xmalloc(sizeof(GraphSetStructure));
6169 QWidget *rc = CreateFrame(parent, s);
6170 retval->frame = rc;
6171 retval->graph_sel = CreateGraphChoice(rc, "Graph:", LIST_TYPE_SINGLE);
6172 retval->set_sel = CreateSetChoice(rc, "Set:", sel_type, retval->graph_sel);
6173 AddStorageChoiceCB(retval->graph_sel, update_sets_cb, (void *) retval);
6174 UpdateSetChoice(retval->set_sel);
6175 retval->set_sel->governor = retval->graph_sel;
6177 return retval;
6181 //SSDSetStructure *CreateSSDSetSelector(Widget parent, char *s, int sel_type)
6183 // SSDSetStructure *retval;
6184 // Widget rc;
6186 // retval = xmalloc(sizeof(SSDSetStructure));
6187 // retval->frame = CreateFrame(parent, s);
6188 // rc = XtVaCreateWidget("rc", xmRowColumnWidgetClass, retval->frame, NULL);
6189 // retval->ssd_sel = CreateSSDChoice(rc, "SSD:", LIST_TYPE_SINGLE);
6190 // retval->set_sel = CreateSetChoice(rc, "Set:", sel_type, retval->ssd_sel);
6191 // AddStorageChoiceCB(retval->ssd_sel, update_sets_cb, (void *) retval);
6192 // UpdateSetChoice(retval->set_sel);
6193 // retval->set_sel->governor = retval->ssd_sel;
6194 // XtManageChild(rc);
6196 // return retval;
6198 SSDSetStructure *CreateSSDSetSelector(Widget parent, char *s, int sel_type)
6200 SSDSetStructure *retval;
6202 retval = (SSDSetStructure*) xmalloc(sizeof(SSDSetStructure));
6203 QWidget *rc = CreateFrame(parent, s);
6204 retval->frame = rc;
6205 retval->ssd_sel = CreateSSDChoice(rc, "SSD:", LIST_TYPE_SINGLE);
6206 retval->set_sel = CreateSetChoice(rc, "Set:", sel_type, retval->ssd_sel);
6207 AddStorageChoiceCB(retval->ssd_sel, update_sets_cb, (void *) retval);
6208 UpdateSetChoice(retval->set_sel);
6209 retval->set_sel->governor = retval->ssd_sel;
6211 return retval;
6216 ListStructure *CreateColChoice(Widget parent, char *labelstr, int type)
6218 int nvisible;
6219 ListStructure *retval;
6221 nvisible = 6;
6223 retval = CreateListChoice(parent, labelstr, type, nvisible, 0, NULL);
6225 return retval;
6228 //void UpdateColChoice(ListStructure *sel, const Quark *ssd)
6230 // unsigned int i, ncols;
6231 // OptionItem *items;
6233 // if (ssd) {
6234 // ncols = ssd_get_ncols(ssd);
6235 // items = xmalloc(ncols*sizeof(OptionItem));
6236 // for (i = 0; i < ncols; i++) {
6237 // char *label, *s, buf[32];
6238 // items[i].value = i;
6239 // label = ssd_get_col_label(ssd, i);
6240 // if (string_is_empty(label)) {
6241 // sprintf(buf, "#%d", i + 1);
6242 // s = copy_string(NULL, buf);
6243 // } else {
6244 // s = copy_string(NULL, label);
6245 // }
6246 // items[i].label = s;
6247 // }
6248 // } else {
6249 // ncols = 0;
6250 // items = NULL;
6251 // }
6252 // UpdateListChoice(sel, ncols, items);
6254 // for (i = 0; i < ncols; i++) {
6255 // xfree(items[i].label);
6256 // }
6257 // xfree(items);
6259 // sel->anydata = (void *) ssd;
6262 void UpdateColChoice(ListStructure *sel, const Quark *ssd)
6264 unsigned int i, ncols;
6265 OptionItem *items;
6267 if (ssd) {
6268 ncols = ssd_get_ncols(ssd);
6269 items = (OptionItem*) xmalloc(ncols*sizeof(OptionItem));
6270 for (i = 0; i < ncols; i++) {
6271 char *label, *s, buf[32];
6272 items[i].value = i;
6273 label = ssd_get_col_label(ssd, i);
6274 if (string_is_empty(label)) {
6275 sprintf(buf, "#%d", i + 1);
6276 s = copy_string(NULL, buf);
6277 } else {
6278 s = copy_string(NULL, label);
6280 items[i].label = s;
6282 } else {
6283 ncols = 0;
6284 items = NULL;
6286 UpdateListChoice(sel, ncols, items);
6288 for (i = 0; i < ncols; i++) {
6289 xfree(items[i].label);
6291 xfree(items);
6293 sel->anydata = (void *) ssd;
6296 static void update_ssd_cb(StorageStructure *ss, int n, Quark **values, void *data)
6298 SSDColStructure *gs = (SSDColStructure *) data;
6299 Quark *ssd;
6301 if (n == 1) {
6302 ssd = values[0];
6303 } else {
6304 ssd = NULL;
6307 UpdateColChoice(gs->col_sel, ssd);
6310 //SSDColStructure *CreateSSDColSelector(Widget parent, char *s, int sel_type)
6312 // SSDColStructure *retval;
6313 // Widget rc;
6315 // retval = xmalloc(sizeof(SSDColStructure));
6316 // retval->frame = CreateFrame(parent, s);
6317 // rc = XtVaCreateWidget("rc", xmRowColumnWidgetClass, retval->frame, NULL);
6318 // retval->ssd_sel = CreateSSDChoice(rc, "SSData:", LIST_TYPE_SINGLE);
6319 // retval->col_sel = CreateColChoice(rc,
6320 // sel_type == LIST_TYPE_SINGLE ? "Column:" : "Column(s):", sel_type);
6321 // AddStorageChoiceCB(retval->ssd_sel, update_ssd_cb, (void *) retval);
6323 // XtManageChild(rc);
6325 // return retval;
6327 SSDColStructure *CreateSSDColSelector(Widget parent, char *s, int sel_type)
6329 SSDColStructure *retval;
6330 char *str;
6332 retval = (SSDColStructure*) xmalloc(sizeof(SSDColStructure));
6333 QWidget *frame = CreateFrame(parent, s);
6334 retval->frame = frame;
6336 retval->ssd_sel = CreateSSDChoice(frame, "SSData:", LIST_TYPE_SINGLE);
6338 if (sel_type == LIST_TYPE_SINGLE) {
6339 str = "Column:";
6340 } else {
6341 str = "Column(s):";
6343 retval->col_sel = CreateColChoice(frame, str, sel_type);
6344 AddStorageChoiceCB(retval->ssd_sel, update_ssd_cb, (void *) retval);
6346 return retval;
6351 //SrcDestStructure *CreateSrcDestSelector(Widget parent, int sel_type)
6353 // SrcDestStructure *retval;
6355 // retval = xmalloc(sizeof(SrcDestStructure));
6357 // retval->form = XtVaCreateWidget("form",
6358 // xmFormWidgetClass, parent,
6359 // XmNfractionBase, 2,
6360 // NULL);
6361 // retval->src = CreateSSDSetSelector(retval->form, "Source", sel_type);
6362 // retval->dest = CreateSSDSetSelector(retval->form, "Destination", sel_type);
6363 // XtVaSetValues(retval->src->frame,
6364 // XmNtopAttachment, XmATTACH_FORM,
6365 // XmNbottomAttachment, XmATTACH_FORM,
6366 // XmNleftAttachment, XmATTACH_FORM,
6367 // XmNrightAttachment, XmATTACH_POSITION,
6368 // XmNrightPosition, 1,
6369 // NULL);
6371 // XtVaSetValues(retval->dest->frame,
6372 // XmNtopAttachment, XmATTACH_FORM,
6373 // XmNbottomAttachment, XmATTACH_FORM,
6374 // XmNleftAttachment, XmATTACH_POSITION,
6375 // XmNleftPosition, 1,
6376 // XmNrightAttachment, XmATTACH_FORM,
6377 // NULL);
6379 // XtManageChild(retval->form);
6381 // return retval;
6383 SrcDestStructure *CreateSrcDestSelector(Widget parent, int sel_type)
6385 SrcDestStructure *retval;
6387 retval = (SrcDestStructure*) xmalloc(sizeof(SrcDestStructure));
6389 QWidget *groupBox = new QWidget(parent);
6390 QHBoxLayout *vLayout = new QHBoxLayout;
6391 vLayout->setContentsMargins(0,0,0,0);
6392 groupBox->setLayout(vLayout);
6394 QLayout *layout = parent->layout();
6395 if (layout != 0) {
6396 layout->addWidget(groupBox);
6399 retval->form = groupBox;
6401 retval->src = CreateSSDSetSelector(retval->form, "Source", sel_type);
6402 retval->dest = CreateSSDSetSelector(retval->form, "Destination", sel_type);
6405 WidgetManage(retval->form);
6407 return retval;
6410 //void paint_color_selector(OptionStructure *optp)
6412 // X11Stuff *xstuff = gapp->gui->xstuff;
6413 // unsigned int i;
6414 // long bg, fg;
6415 // Project *pr = project_get_data(gproject_get_top(gapp->gp));
6417 // if (!pr) {
6418 // return;
6419 // }
6421 // for (i = 0; i < pr->ncolors; i++) {
6422 // Colordef *c = &pr->colormap[i];
6423 // bg = xvlibcolors[c->id];
6424 // if (get_rgb_intensity(&c->rgb) < 0.5) {
6425 // fg = WhitePixel(xstuff->disp, xstuff->screennumber);
6426 // } else {
6427 // fg = BlackPixel(xstuff->disp, xstuff->screennumber);
6428 // }
6429 // XtVaSetValues(optp->options[i].widget,
6430 // XmNbackground, bg,
6431 // XmNforeground, fg,
6432 // NULL);
6433 // }
6435 void paint_color_selector(OptionStructure *optp)
6437 Project *pr = project_get_data(gproject_get_top(gapp->gp));
6438 unsigned int i;
6440 if (!pr) {
6441 return;
6444 for (i = 0; i < pr->ncolors; i++) {
6445 Colordef *c = &pr->colormap[i];
6446 QStandardItem *item = (QStandardItem *) optp->options[i].widget;
6448 QColor bg_color(c->rgb.red, c->rgb.green, c->rgb.blue);
6449 item->setBackground(QBrush(bg_color));
6451 if (get_rgb_intensity(&c->rgb) < 0.5) {
6452 item->setForeground(Qt::white);
6453 } else {
6454 item->setForeground(Qt::black);
6460 //void update_color_selectors(void)
6462 // unsigned int i;
6463 // Project *pr = project_get_data(gproject_get_top(gapp->gp));
6465 // ncolor_option_items = pr->ncolors;
6467 // color_option_items = xrealloc(color_option_items,
6468 // ncolor_option_items*sizeof(OptionItem));
6469 // for (i = 0; i < pr->ncolors; i++) {
6470 // Colordef *c = &pr->colormap[i];
6471 // color_option_items[i].value = c->id;
6472 // color_option_items[i].label = c->cname;
6473 // }
6475 // for (i = 0; i < ncolor_selectors; i++) {
6476 // UpdateOptionChoice(color_selectors[i],
6477 // ncolor_option_items, color_option_items);
6478 // paint_color_selector(color_selectors[i]);
6479 // }
6481 // update_color_choice_popup();
6483 void update_color_selectors(void)
6485 unsigned int i;
6486 Project *pr = project_get_data(gproject_get_top(gapp->gp));
6488 ncolor_option_items = pr->ncolors;
6490 color_option_items = (OptionItem *) xrealloc(color_option_items,
6491 ncolor_option_items*sizeof(OptionItem));
6492 for (i = 0; i < pr->ncolors; i++) {
6493 Colordef *c = &pr->colormap[i];
6494 color_option_items[i].value = c->id;
6495 color_option_items[i].label = c->cname;
6498 for (i = 0; i < ncolor_selectors; i++) {
6499 UpdateOptionChoice(color_selectors[i],
6500 ncolor_option_items, color_option_items);
6501 paint_color_selector(color_selectors[i]);
6504 update_color_choice_popup();
6507 OptionStructure *CreateColorChoice(Widget parent, char *s)
6509 OptionStructure *retvalp = NULL;
6511 ncolor_selectors++;
6512 color_selectors = (OptionStructure **) xrealloc(color_selectors,
6513 ncolor_selectors*sizeof(OptionStructure *));
6514 if (color_selectors == NULL) {
6515 errmsg("Malloc failed in CreateColorChoice()");
6516 return retvalp;
6519 retvalp = CreateOptionChoice(parent, s, 4,
6520 ncolor_option_items, color_option_items);
6522 color_selectors[ncolor_selectors - 1] = retvalp;
6524 paint_color_selector(retvalp);
6526 return retvalp;
6529 SpinStructure *CreateLineWidthChoice(Widget parent, char *s)
6531 return CreateSpinChoice(parent, s, 3, SPIN_TYPE_FLOAT, 0.0, MAX_LINEWIDTH, 0.5);
6535 //OptionStructure *CreatePanelChoice(Widget parent, char *labelstr, ...)
6537 // OptionStructure *retval;
6538 // int nchoices = 0;
6539 // OptionItem *oi = NULL;
6540 // va_list var;
6541 // char *s;
6543 // va_start(var, labelstr);
6544 // while ((s = va_arg(var, char *)) != NULL) {
6545 // nchoices++;
6546 // oi = xrealloc(oi, nchoices*sizeof(OptionItem));
6547 // oi[nchoices - 1].value = nchoices - 1;
6548 // oi[nchoices - 1].label = copy_string(NULL, s);
6549 // }
6550 // va_end(var);
6552 // retval = CreateOptionChoice(parent, labelstr, 1, nchoices, oi);
6554 // while (nchoices) {
6555 // nchoices--;
6556 // xfree(oi[nchoices].label);
6557 // }
6558 // xfree(oi);
6560 // return retval;
6562 OptionStructure *CreatePanelChoice(Widget parent, char *labelstr, ...)
6564 OptionStructure *retval;
6565 int nchoices = 0;
6566 OptionItem *oi = NULL;
6567 va_list var;
6568 char *s;
6570 va_start(var, labelstr);
6571 while ((s = va_arg(var, char *)) != NULL) {
6572 nchoices++;
6573 oi = (OptionItem *) xrealloc(oi, nchoices*sizeof(OptionItem));
6574 oi[nchoices - 1].value = nchoices - 1;
6575 oi[nchoices - 1].label = copy_string(NULL, s);
6577 va_end(var);
6579 retval = CreateOptionChoice(parent, labelstr, 1, nchoices, oi);
6581 while (nchoices) {
6582 nchoices--;
6583 xfree(oi[nchoices].label);
6585 xfree(oi);
6587 return retval;
6590 //static void format_call_cb(FormatStructure *fstr)
6592 // if (fstr->cb_proc) {
6593 // Format format;
6594 // format.type = GetOptionChoice(fstr->type);
6595 // format.prec = GetOptionChoice(fstr->prec);
6596 // format.fstring = GetTextString(fstr->fstring);
6598 // fstr->cb_proc(fstr, &format, fstr->cb_data);
6600 // xfree(format.fstring);
6601 // }
6603 static void format_call_cb(FormatStructure *fstr)
6605 if (fstr->cb_proc) {
6606 Format format;
6607 format.type = (FormatType) GetOptionChoice(fstr->type);
6608 format.prec = GetOptionChoice(fstr->prec);
6609 format.fstring = GetTextString(fstr->fstring);
6611 fstr->cb_proc(fstr, &format, fstr->cb_data);
6613 xfree(format.fstring);
6617 static void format_oc_cb(OptionStructure *opt, int a, void *data)
6619 FormatStructure *fstr = (FormatStructure *) data;
6620 if (!fstr) {
6621 return;
6624 if (opt == fstr->type) {
6625 WidgetSetSensitive(fstr->fstring->form,
6626 a == FORMAT_DATETIME || a == FORMAT_GEOGRAPHIC);
6629 format_call_cb(fstr);
6632 static void format_text_cb(TextStructure *cst, char *s, void *data)
6634 FormatStructure *fstr = (FormatStructure *) data;
6635 if (!fstr) {
6636 return;
6639 format_call_cb(fstr);
6642 //FormatStructure *CreateFormatChoice(Widget parent)
6644 // FormatStructure *retval;
6645 // Widget rc, rc1;
6647 // retval = xmalloc(sizeof(FormatStructure));
6649 // rc = CreateVContainer(parent);
6650 // rc1 = CreateHContainer(rc);
6651 // retval->type = CreateOptionChoice(rc1, "Type:",
6652 // 1, NUMBER_OF_FORMATTYPES, fmt_option_items);
6653 // AddOptionChoiceCB(retval->type, format_oc_cb, retval);
6654 // retval->prec = CreatePrecisionChoice(rc1, "Precision:");
6655 // AddOptionChoiceCB(retval->prec, format_oc_cb, retval);
6656 // retval->fstring = CreateTextInput(rc, "Format string:");
6657 // AddTextInputCB(retval->fstring, format_text_cb, retval);
6659 // return retval;
6661 FormatStructure *CreateFormatChoice(Widget parent)
6663 FormatStructure *retval;
6664 Widget rc, rc1;
6666 retval = (FormatStructure *) xmalloc(sizeof(FormatStructure));
6668 rc = CreateVContainer(parent);
6669 rc1 = CreateHContainer(rc);
6670 retval->type = CreateOptionChoice(rc1, "Type:",
6671 1, NUMBER_OF_FORMATTYPES, fmt_option_items);
6672 AddOptionChoiceCB(retval->type, format_oc_cb, retval);
6673 retval->prec = CreatePrecisionChoice(rc1, "Precision:");
6674 AddOptionChoiceCB(retval->prec, format_oc_cb, retval);
6675 retval->fstring = CreateTextInput(rc, "Format string:");
6676 AddTextInputCB(retval->fstring, format_text_cb, retval);
6678 return retval;
6681 void SetFormatChoice(FormatStructure *fstr, const Format *format)
6683 SetOptionChoice(fstr->type, format->type);
6684 SetOptionChoice(fstr->prec, format->prec);
6685 SetTextString(fstr->fstring, format->fstring);
6686 WidgetSetSensitive(fstr->fstring->form,
6687 format->type == FORMAT_DATETIME || format->type == FORMAT_GEOGRAPHIC);
6690 //Format *GetFormatChoice(FormatStructure *fstr)
6692 // Format *format = format_new();
6693 // if (format) {
6694 // format->type = GetOptionChoice(fstr->type);
6695 // format->prec = GetOptionChoice(fstr->prec);
6696 // format->fstring = GetTextString(fstr->fstring);
6697 // }
6699 // return format;
6701 Format *GetFormatChoice(FormatStructure *fstr)
6703 Format *format = format_new();
6704 if (format) {
6705 format->type = (FormatType) GetOptionChoice(fstr->type);
6706 format->prec = GetOptionChoice(fstr->prec);
6707 format->fstring = GetTextString(fstr->fstring);
6710 return format;
6713 void AddFormatChoiceCB(FormatStructure *fstr, Format_CBProc cbproc, void *data)
6715 fstr->cb_proc = cbproc;
6716 fstr->cb_data = data;
6720 static OptionItem as_option_items[4] =
6722 {AUTOSCALE_NONE, "None"},
6723 {AUTOSCALE_X, "X"},
6724 {AUTOSCALE_Y, "Y"},
6725 {AUTOSCALE_XY, "XY"}
6728 OptionStructure *CreateASChoice(Widget parent, char *s)
6730 OptionStructure *retval;
6732 retval = CreateOptionChoice(parent, s, 1, 4, as_option_items);
6733 /* As init value, use this */
6734 SetOptionChoice(retval, gapp->rt->autoscale_onread);
6736 return(retval);
6739 OptionStructure *CreatePrecisionChoice(Widget parent, char *s)
6741 return CreateOptionChoiceVA(parent, s,
6742 "0", 0,
6743 "1", 1,
6744 "2", 2,
6745 "3", 3,
6746 "4", 4,
6747 "5", 5,
6748 "6", 6,
6749 "7", 7,
6750 "8", 8,
6751 "9", 9,
6752 NULL);
6755 OptionStructure *CreatePaperOrientationChoice(Widget parent, char *s)
6757 return CreateOptionChoiceVA(parent, s,
6758 "Landscape", PAGE_ORIENT_LANDSCAPE,
6759 "Portrait", PAGE_ORIENT_PORTRAIT,
6760 NULL);
6763 OptionStructure *CreatePaperFormatChoice(Widget parent, char *s)
6765 return CreateOptionChoiceVA(parent, s,
6766 "Custom", PAGE_FORMAT_CUSTOM,
6767 "Letter", PAGE_FORMAT_USLETTER,
6768 "A4", PAGE_FORMAT_A4,
6769 NULL);
6773 //Widget CreateScale(Widget parent, char *s, int min, int max, int delta)
6775 // Widget w;
6776 // XmString str;
6778 // str = XmStringCreateLocalized(s);
6780 // w = XtVaCreateManagedWidget("scroll",
6781 // xmScaleWidgetClass, parent,
6782 // XmNtitleString, str,
6783 // XmNminimum, min,
6784 // XmNmaximum, max,
6785 // XmNscaleMultiple, delta,
6786 // XmNvalue, 0,
6787 // XmNshowValue, True,
6788 // XmNprocessingDirection, XmMAX_ON_RIGHT,
6789 // XmNorientation, XmHORIZONTAL,
6790 //#if XmVersion >= 2000
6791 // XmNsliderMark, XmROUND_MARK,
6792 //#endif
6793 // NULL);
6795 // XmStringFree(str);
6797 // return w;
6799 Widget CreateScale(Widget parent, char *s, int min, int max, int delta)
6801 QSlider *slider = new QSlider(Qt::Horizontal, parent);
6803 slider->setRange(min, max);
6804 slider->setPageStep(delta);
6806 QLCDNumber *lcd = new QLCDNumber(parent);
6807 QObject::connect(slider, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)));
6809 QLabel *label = new QLabel(parent);
6810 label->setText(s);
6812 QWidget *widget = new QWidget(parent);
6814 QHBoxLayout *hLayout = new QHBoxLayout;
6815 hLayout->setContentsMargins(0,0,0,0);
6816 hLayout->addWidget(label);
6817 hLayout->addWidget(lcd);
6818 hLayout->addWidget(slider);
6819 widget->setLayout(hLayout);
6821 QLayout *layout = parent->layout();
6822 if (layout != 0) {
6823 layout->addWidget(widget);
6826 return slider;
6829 //void scale_int_cb_proc( Widget w, XtPointer client_data, XtPointer call_data)
6831 // Scale_CBdata *cbdata = (Scale_CBdata *) client_data;
6833 // cbdata->cbproc(cbdata->scale, GetScaleValue(cbdata->scale), cbdata->anydata);
6836 //void AddScaleCB(Widget w, Scale_CBProc cbproc, void *anydata)
6838 // Scale_CBdata *cbdata;
6840 // cbdata = xmalloc(sizeof(Scale_CBdata));
6842 // cbdata->scale = w;
6843 // cbdata->cbproc = cbproc;
6844 // cbdata->anydata = anydata;
6845 // XtAddCallback(w,
6846 // XmNvalueChangedCallback, scale_int_cb_proc, (XtPointer) cbdata);
6850 //void SetScaleValue(Widget w, int value)
6852 // XtVaSetValues(w, XmNvalue, value, NULL);
6854 void SetScaleValue(Widget w, int value)
6856 QSlider *slider = (QSlider*) w;
6857 slider->setValue(value);
6860 //int GetScaleValue(Widget w)
6862 // int value;
6863 // XtVaGetValues(w, XmNvalue, &value, NULL);
6864 // return value;
6866 int GetScaleValue(Widget w)
6868 QSlider *slider = (QSlider*) w;
6870 return slider->value();
6873 //void SetScaleWidth(Widget w, int width)
6875 // XtVaSetValues(w, XmNscaleWidth, (Dimension) width, NULL);
6878 SpinStructure *CreateAngleChoice(Widget parent, char *s)
6880 return CreateSpinChoice(parent, s, 5, SPIN_TYPE_FLOAT, -360.0, 360.0, 10.0);
6883 double GetAngleChoice(SpinStructure *sp)
6885 return GetSpinChoice(sp);
6888 void SetAngleChoice(SpinStructure *sp, double angle)
6890 if (angle < -360.0 || angle > 360.0) {
6891 angle = fmod(angle, 360.0);
6893 SetSpinChoice(sp, angle);
6896 SpinStructure *CreateCharSizeChoice(Widget parent, char *s)
6898 return CreateSpinChoice(parent, s, 4, SPIN_TYPE_FLOAT, 0.0, 100.0, 0.25);
6902 //Widget CreateToggleButton(Widget parent, char *s)
6904 // return (XtVaCreateManagedWidget(s, xmToggleButtonWidgetClass, parent, NULL));
6906 Widget CreateToggleButton(Widget parent, char *s)
6908 QCheckBox *cb = new QCheckBox(s, parent);
6910 QLayout *layout = parent->layout();
6911 if (layout != 0) {
6912 layout->addWidget(cb);
6915 return cb;
6918 //int GetToggleButtonState(Widget w)
6920 // if (!w) {
6921 // errmsg("Internal error: GetToggleButtonState() called with NULL widget");
6922 // return 0;
6923 // } else {
6924 // return XmToggleButtonGetState(w);
6925 // }
6927 int ToggleButtonGetState(Widget w)
6929 if (!w) {
6930 errmsg("Internal error: GetToggleButtonState() called with NULL widget");
6931 return 0;
6932 } else {
6933 if (QCheckBox *checkBox = qobject_cast<QCheckBox *>(w)) {
6934 if (checkBox->isChecked()) {
6935 return TRUE;
6936 } else {
6937 return FALSE;
6942 if (QAction *action = qobject_cast<QAction *>(w)) {
6943 if (action->isChecked()) {
6944 return TRUE;
6945 } else {
6946 return FALSE;
6950 return 0;
6954 //void SetToggleButtonState(Widget w, int value)
6956 // if (w == NULL) {
6957 // return;
6958 // }
6959 // XmToggleButtonSetState(w, value ? True:False, False);
6961 // return;
6963 void ToggleButtonSetState(Widget w, int value)
6965 if (w == NULL) {
6966 return;
6969 QCheckBox *cb = qobject_cast<QCheckBox *>(w);
6970 if (cb != 0) {
6971 cb->blockSignals(true);
6972 cb->setChecked(value ? true : false);
6973 cb->blockSignals(false);
6976 QAction *ac = qobject_cast<QAction *>(w);
6977 if (ac != 0) {
6978 ac->blockSignals(true);
6979 ac->setChecked(value ? true : false);
6980 ac->blockSignals(false);
6983 return;
6986 typedef struct {
6987 Widget tbut;
6988 TB_CBProc cbproc;
6989 void *anydata;
6990 } TB_CBdata;
6992 static void tb_int_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
6994 int onoff;
6996 TB_CBdata *cbdata = (TB_CBdata *) client_data;
6998 onoff = ToggleButtonGetState(w);
6999 cbdata->cbproc(cbdata->tbut, onoff, cbdata->anydata);
7002 //void AddToggleButtonCB(Widget w, TB_CBProc cbproc, void *anydata)
7004 // TB_CBdata *cbdata;
7006 // cbdata = xmalloc(sizeof(TB_CBdata));
7008 // cbdata->tbut = w;
7009 // cbdata->cbproc = cbproc;
7010 // cbdata->anydata = anydata;
7011 // XtAddCallback(w,
7012 // XmNvalueChangedCallback, tb_int_cb_proc, (XtPointer) cbdata);
7014 void AddToggleButtonCB(Widget w, TB_CBProc cbproc, void *anydata)
7016 TB_CBdata *cbdata;
7018 cbdata = (TB_CBdata*) xmalloc(sizeof(TB_CBdata));
7020 cbdata->tbut = w;
7021 cbdata->cbproc = cbproc;
7022 cbdata->anydata = anydata;
7024 QtAddCallback(w, SIGNAL(toggled(bool)),
7025 tb_int_cb_proc, (XtPointer) cbdata);
7028 //void CreatePixmaps(ExplorerUI *eui)
7030 // Pixel bg;
7031 // XpmColorSymbol transparent;
7032 // XpmAttributes attrib;
7034 // XtVaGetValues(app_shell, XtNbackground, &bg, NULL);
7035 // transparent.name = NULL;
7036 // transparent.value = "None";
7037 // transparent.pixel = bg;
7038 // attrib.colorsymbols = &transparent;
7039 // attrib.valuemask = XpmColorSymbols;
7040 // attrib.numsymbols = 1;
7041 // XpmCreatePixmapFromData(xstuff->disp, xstuff->root,
7042 // active_xpm, &eui->a_icon, NULL, &attrib);
7043 // XpmCreatePixmapFromData(xstuff->disp, xstuff->root,
7044 // hidden_xpm, &eui->h_icon, NULL, &attrib);
7046 void XpmToPixmap(ExplorerUI *eui)
7048 eui->a_icon = (Pixmap) new QIcon(active_xpm);
7049 eui->h_icon = (Pixmap) new QIcon(hidden_xpm);
7052 //Widget CreateForm(Widget parent)
7054 // return XmCreateForm(parent, s, NULL, 0);
7056 Widget CreateForm(Widget parent)
7058 QWidget *widget = new QWidget(parent);
7059 // // width for explorer
7060 // widget->setMaximumWidth(250);
7061 // widget->setMinimumWidth(250);
7063 QVBoxLayout *vLayout = new QVBoxLayout;
7064 vLayout->setContentsMargins(3,3,3,3);
7065 widget->setLayout(vLayout);
7067 QLayout *layout = parent->layout();
7068 if (layout != 0) {
7069 layout->addWidget(widget);
7072 return widget;
7075 //Widget CreateDialogForm(Widget parent, const char *s)
7077 // X11Stuff *xstuff = gapp->gui->xstuff;
7078 // Widget dialog, w;
7079 // char *bufp;
7080 // int standalone;
7082 // if (parent == NULL) {
7083 // standalone = TRUE;
7084 // parent = XtAppCreateShell("XMgapp", "XMgapp",
7085 // topLevelShellWidgetClass, xstuff->disp,
7086 // NULL, 0);
7087 // } else {
7088 // standalone = FALSE;
7089 // }
7090 // bufp = label_to_resname(s, "Dialog");
7091 // dialog = XmCreateDialogShell(parent, bufp, NULL, 0);
7092 // xfree(bufp);
7094 // if (standalone) {
7095 // RegisterEditRes(dialog);
7096 // }
7098 // handle_close(dialog);
7100 // bufp = copy_string(NULL, "Grace: ");
7101 // bufp = concat_strings(bufp, s);
7102 // XtVaSetValues(dialog,
7103 // XmNtitle, bufp,
7104 // NULL);
7105 // xfree(bufp);
7107 // w = XmCreateForm(dialog, "form", NULL, 0);
7109 // return w;
7111 Widget CreateDialog(Widget parent, const char *s)
7113 char *bufp;
7115 bufp = copy_string(NULL, "Grace: ");
7116 bufp = concat_strings(bufp, s);
7118 QDialog *w = new QDialog(mainWin);
7119 w->setWindowTitle(bufp);
7120 xfree(bufp);
7122 QVBoxLayout *mainLayout = new QVBoxLayout;
7123 mainLayout->setContentsMargins(3,3,3,3);
7124 w->setLayout(mainLayout);
7126 return w;
7129 //void SetDialogFormResizable(Widget form, int onoff)
7131 // XtVaSetValues(form,
7132 // XmNresizePolicy, onoff ? XmRESIZE_ANY:XmRESIZE_NONE,
7133 // NULL);
7134 // XtVaSetValues(XtParent(form),
7135 // XmNallowShellResize, onoff ? True:False,
7136 // NULL);
7138 void SetDialogFormResizable(Widget form, int onoff)
7140 //TODO
7143 //void AddDialogFormChild(Widget form, Widget child)
7145 // Widget last_widget;
7147 // last_widget = GetUserData(form);
7148 // if (last_widget) {
7149 // XtVaSetValues(child,
7150 // XmNtopAttachment, XmATTACH_WIDGET,
7151 // XmNtopWidget, last_widget,
7152 // NULL);
7153 // XtVaSetValues(last_widget,
7154 // XmNbottomAttachment, XmATTACH_NONE,
7155 // NULL);
7156 // } else {
7157 // XtVaSetValues(child,
7158 // XmNtopAttachment, XmATTACH_FORM,
7159 // NULL);
7160 // }
7161 // XtVaSetValues(child,
7162 // XmNleftAttachment, XmATTACH_FORM,
7163 // XmNrightAttachment, XmATTACH_FORM,
7164 // XmNbottomAttachment, XmATTACH_FORM,
7165 // NULL);
7166 // SetUserData(form, child);
7168 void AddDialogFormChild(Widget form, Widget child)
7170 // DialogForm allways has layout.
7171 // It is created in CreateDialogForm
7172 QLayout *layout = form->layout();
7174 if (QMenuBar *menuBar = qobject_cast<QMenuBar *>(child)) {
7175 layout->setMenuBar(menuBar);
7176 } else {
7177 layout->addWidget(child);
7181 //void FixateDialogFormChild(Widget w)
7183 // Widget prev;
7184 // XtVaGetValues(w, XmNtopWidget, &prev, NULL);
7185 // XtVaSetValues(w, XmNtopAttachment, XmATTACH_NONE, NULL);
7186 // XtVaSetValues(prev, XmNbottomAttachment, XmATTACH_WIDGET,
7187 // XmNbottomWidget, w,
7188 // NULL);
7190 void FixateDialogFormChild(Widget w)
7194 //static Widget CreateCommandButtons(Widget parent, int n, Widget * buts, char **l)
7196 // int i;
7197 // Widget form;
7198 // Dimension h;
7200 // form = XtVaCreateWidget("form", xmFormWidgetClass, parent,
7201 // XmNfractionBase, n,
7202 // NULL);
7204 // for (i = 0; i < n; i++) {
7205 // buts[i] = XtVaCreateManagedWidget(l[i],
7206 // xmPushButtonWidgetClass, form,
7207 // XmNtopAttachment, XmATTACH_FORM,
7208 // XmNbottomAttachment, XmATTACH_FORM,
7209 // XmNleftAttachment, XmATTACH_POSITION,
7210 // XmNleftPosition, i,
7211 // XmNrightAttachment, XmATTACH_POSITION,
7212 // XmNrightPosition, i + 1,
7213 // XmNdefaultButtonShadowThickness, 1,
7214 // XmNshowAsDefault, (i == 0) ? True : False,
7215 // NULL);
7216 // }
7217 // XtManageChild(form);
7218 // XtVaGetValues(buts[0], XmNheight, &h, NULL);
7219 // XtVaSetValues(form, XmNpaneMaximum, h, XmNpaneMinimum, h, NULL);
7221 // return form;
7223 Widget CreateCommandButtons(Widget parent, int n, Widget *buts, char **l)
7225 int i;
7227 QPushButton *pushButton;
7229 QWidget *form = new QWidget(parent);
7230 form->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
7232 QHBoxLayout *hLayout = new QHBoxLayout;
7233 hLayout->setContentsMargins(3,3,3,3);
7234 form->setLayout(hLayout);
7236 for (i = 0; i < n; i++) {
7237 pushButton = new QPushButton(l[i], form);
7238 pushButton->setAutoDefault(false);
7239 hLayout->addWidget(pushButton);
7240 buts[i] = pushButton;
7243 return form;
7246 typedef struct {
7247 Widget form;
7248 int close;
7249 AACDialog_CBProc cbproc;
7250 void *anydata;
7251 } AACDialog_CBdata;
7253 //void aacdialog_int_cb_proc(Widget but, void *data)
7255 // AACDialog_CBdata *cbdata;
7256 // int retval;
7258 // set_wait_cursor();
7260 // cbdata = (AACDialog_CBdata *) data;
7262 // retval = cbdata->cbproc(cbdata->anydata);
7264 // if (cbdata->close && retval == RETURN_SUCCESS) {
7265 // XtUnmanageChild(XtParent(cbdata->form));
7266 // }
7268 // unset_wait_cursor();
7270 void aacdialog_int_cb_proc(Widget but, void *data)
7272 AACDialog_CBdata *cbdata;
7273 int retval;
7275 set_wait_cursor();
7277 cbdata = (AACDialog_CBdata *) data;
7279 retval = cbdata->cbproc(cbdata->anydata);
7281 if (cbdata->close && retval == RETURN_SUCCESS) {
7282 cbdata->form->close();
7285 unset_wait_cursor();
7288 //WidgetList CreateAACDialog(Widget form,
7289 // Widget container, AACDialog_CBProc cbproc, void *data)
7291 // Widget fr;
7292 // WidgetList aacbut;
7293 // AACDialog_CBdata *cbdata_accept, *cbdata_apply;
7294 // char *aaclab[3] = {"Apply", "Accept", "Close"};
7296 // aacbut = (WidgetList) XtMalloc(3*sizeof(Widget));
7298 // fr = CreateFrame(form, NULL);
7299 // XtVaSetValues(fr,
7300 // XmNtopAttachment, XmATTACH_NONE,
7301 // XmNleftAttachment, XmATTACH_FORM,
7302 // XmNrightAttachment, XmATTACH_FORM,
7303 // XmNbottomAttachment, XmATTACH_FORM,
7304 // NULL);
7305 // CreateCommandButtons(fr, 3, aacbut, aaclab);
7307 // AddDialogFormChild(form, container);
7308 // XtVaSetValues(container,
7309 // XmNbottomAttachment, XmATTACH_WIDGET,
7310 // XmNbottomWidget, fr,
7311 // NULL);
7313 // XtVaSetValues(form, XmNcancelButton, aacbut[2], NULL);
7315 // cbdata_accept = xmalloc(sizeof(AACDialog_CBdata));
7316 // cbdata_accept->form = form;
7317 // cbdata_accept->anydata = data;
7318 // cbdata_accept->cbproc = cbproc;
7319 // cbdata_accept->close = TRUE;
7321 // cbdata_apply = xmalloc(sizeof(AACDialog_CBdata));
7322 // cbdata_apply->form = form;
7323 // cbdata_apply->anydata = data;
7324 // cbdata_apply->cbproc = cbproc;
7325 // cbdata_apply->close = FALSE;
7327 // AddButtonCB(aacbut[0], aacdialog_int_cb_proc, cbdata_apply);
7328 // AddButtonCB(aacbut[1], aacdialog_int_cb_proc, cbdata_accept);
7329 // AddButtonCB(aacbut[2], destroy_dialog_cb, XtParent(form));
7331 // XtManageChild(container);
7332 // XtManageChild(form);
7334 // return aacbut;
7336 WidgetList CreateAACDialog(Widget form,
7337 Widget container, AACDialog_CBProc cbproc, void *data)
7339 Widget fr;
7340 WidgetList aacbut;
7341 AACDialog_CBdata *cbdata_accept, *cbdata_apply;
7342 char *aaclab[3] = {"Apply", "Accept", "Close"};
7344 aacbut = (WidgetList) xmalloc(3*sizeof(Widget));
7346 fr = CreateCommandButtons(form, 3, aacbut, aaclab);
7348 AddDialogFormChild(form, container);
7349 AddDialogFormChild(form, fr);
7351 cbdata_accept = (AACDialog_CBdata*) xmalloc(sizeof(AACDialog_CBdata));
7352 cbdata_accept->form = form;
7353 cbdata_accept->anydata = data;
7354 cbdata_accept->cbproc = cbproc;
7355 cbdata_accept->close = TRUE;
7357 cbdata_apply = (AACDialog_CBdata*) xmalloc(sizeof(AACDialog_CBdata));
7358 cbdata_apply->form = form;
7359 cbdata_apply->anydata = data;
7360 cbdata_apply->cbproc = cbproc;
7361 cbdata_apply->close = FALSE;
7363 AddButtonCB(aacbut[0], aacdialog_int_cb_proc, cbdata_apply);
7364 AddButtonCB(aacbut[1], aacdialog_int_cb_proc, cbdata_accept);
7365 AddButtonCB(aacbut[2], destroy_dialog_cb, form);
7367 return aacbut;
7370 int td_cb(void *data)
7372 int res, i, nssrc, error;
7373 Quark **srcsets, **destsets;
7374 TransformStructure *tdialog = (TransformStructure *) data;
7375 void *tddata;
7377 res = GetTransformDialogSettings(tdialog, &nssrc, &srcsets, &destsets);
7379 if (res != RETURN_SUCCESS) {
7380 return RETURN_FAILURE;
7383 error = FALSE;
7385 tddata = tdialog->get_cb(tdialog->gui);
7386 if (!tddata) {
7387 error = TRUE;
7390 if (!error) {
7391 for (i = 0; i < nssrc; i++) {
7392 Quark *psrc, *pdest;
7393 psrc = srcsets[i];
7394 pdest = destsets[i];
7396 res = tdialog->run_cb(psrc, pdest, tddata);
7397 if (res != RETURN_SUCCESS) {
7398 error = TRUE;
7399 break;
7404 if (nssrc > 0) {
7405 xfree(srcsets);
7406 xfree(destsets);
7409 if (tddata) {
7410 tdialog->free_cb(tddata);
7413 snapshot_and_update(gapp->gp, TRUE);
7415 if (error == FALSE) {
7416 return RETURN_SUCCESS;
7417 } else {
7418 return RETURN_FAILURE;
7423 TransformStructure *CreateTransformDialogForm(Widget parent,
7424 const char *s, int sel_type, int exclusive, const TD_CBProcs *cbs)
7426 TransformStructure *retval;
7428 set_wait_cursor();
7430 retval = (TransformStructure *) xmalloc(sizeof(TransformStructure));
7431 memset(retval, 0, sizeof(TransformStructure));
7433 retval->exclusive = exclusive;
7435 retval->build_cb = cbs->build_cb;
7436 retval->get_cb = cbs->get_cb;
7437 retval->run_cb = cbs->run_cb;
7438 retval->free_cb = cbs->free_cb;
7440 retval->form = CreateDialog(parent, s);
7442 retval->menubar = CreateMenuBar(retval->form);
7443 AddDialogFormChild(retval->form, retval->menubar);
7445 retval->srcdest = CreateSrcDestSelector(retval->form, sel_type);
7446 AddDialogFormChild(retval->form, retval->srcdest->form);
7448 retval->frame = CreateFrame(retval->form, NULL);
7449 retval->gui = retval->build_cb(retval);
7452 * retval->restr = CreateRestrictionChoice(retval->form, "Source data filtering");
7453 * AddDialogFormChild(retval->form, retval->restr->frame);
7456 CreateAACDialog(retval->form, retval->frame, td_cb, retval);
7458 /* FixateDialogFormChild(retval->frame); */
7460 unset_wait_cursor();
7462 return retval;
7465 int GetTransformDialogSettings(TransformStructure *tdialog,
7466 int *nssrc, Quark ***srcsets, Quark ***destsets)
7468 int i, nsdest;
7469 Quark *srcssd, *destssd;
7471 if (GetSingleStorageChoice(tdialog->srcdest->src->ssd_sel, &srcssd)
7472 != RETURN_SUCCESS) {
7473 errmsg("No source SSD selected");
7474 return RETURN_FAILURE;
7477 *nssrc = GetStorageChoices(tdialog->srcdest->src->set_sel, srcsets);
7478 if (*nssrc == 0) {
7479 errmsg("No source sets selected");
7480 return RETURN_FAILURE;
7483 nsdest = GetStorageChoices(tdialog->srcdest->dest->set_sel, destsets);
7484 if (nsdest != 0 && *nssrc != nsdest) {
7485 errmsg("Different number of source and destination sets");
7486 xfree(*srcsets);
7487 xfree(*destsets);
7488 return RETURN_FAILURE;
7491 if (GetSingleStorageChoice(tdialog->srcdest->dest->ssd_sel, &destssd)
7492 != RETURN_SUCCESS) {
7493 destssd = gapp_ssd_new(quark_parent_get(srcssd));
7494 if (!destssd) {
7495 xfree(*srcsets);
7496 errmsg("Cannot create new SSD");
7497 return RETURN_FAILURE;
7499 } else {
7500 /* check for mutually exclusive selections */
7501 if (tdialog->exclusive && destssd == srcssd) {
7502 xfree(*srcsets);
7503 if (nsdest) {
7504 xfree(*destsets);
7506 errmsg("Source and destination SSD's are the same");
7507 return RETURN_FAILURE;
7511 if (nsdest == 0) {
7512 ssd_set_indexed(destssd, TRUE);
7513 if (!ssd_is_indexed(destssd)) {
7514 if (!ssd_add_col(destssd, FFORMAT_NUMBER)) {
7515 return RETURN_FAILURE;
7519 *destsets = (Quark **) xmalloc((*nssrc)*sizeof(Quark *));
7520 for (i = 0; i < *nssrc; i++) {
7521 if (ssd_add_col(destssd, FFORMAT_NUMBER)) {
7522 Dataset *dsp;
7523 (*destsets)[i] = gapp_set_new(destssd);
7524 dsp = set_get_dataset((*destsets)[i]);
7525 dsp->cols[0] = 0;
7526 dsp->cols[1] = ssd_get_ncols(destssd) - 1;
7530 update_ssd_selectors(gproject_get_top(gapp->gp));
7532 SelectStorageChoice(tdialog->srcdest->dest->ssd_sel, destssd);
7533 SelectStorageChoices(tdialog->srcdest->dest->set_sel, *nssrc, *destsets);
7536 return RETURN_SUCCESS;
7539 void RaiseTransformationDialog(TransformStructure *tdialog)
7541 RaiseWindow(GetParent(tdialog->form));
7544 //Widget CreateVContainer(Widget parent)
7546 // Widget rc;
7548 // rc = XmCreateRowColumn(parent, "VContainer", NULL, 0);
7549 // XtManageChild(rc);
7551 // return rc;
7553 Widget CreateVContainer(Widget parent)
7555 QLayout *vLayout = new QVBoxLayout;
7556 vLayout->setContentsMargins(3,3,3,3);
7557 vLayout->setSizeConstraint(QLayout::SetFixedSize);
7558 vLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
7560 QLayout *layout = parent->layout();
7561 if (layout != 0) {
7562 QWidget *widget = new QWidget(parent);
7563 widget->setLayout(vLayout);
7564 layout->addWidget(widget);
7565 return widget;
7566 } else {
7567 parent->setLayout(vLayout);
7568 return parent;
7572 //Widget CreateHContainer(Widget parent)
7574 // Widget rc;
7576 // rc = XmCreateRowColumn(parent, "HContainer", NULL, 0);
7577 // XtVaSetValues(rc, XmNorientation, XmHORIZONTAL, NULL);
7578 // XtManageChild(rc);
7580 // return rc;
7582 Widget CreateHContainer(Widget parent)
7584 QLayout *hLayout = new QHBoxLayout;
7585 hLayout->setContentsMargins(3,3,3,3);
7586 hLayout->setSizeConstraint(QLayout::SetFixedSize);
7587 hLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
7589 QLayout *layout = parent->layout();
7590 if (layout != 0) {
7591 QWidget *widget = new QWidget(parent);
7592 widget->setLayout(hLayout);
7593 layout->addWidget(widget);
7594 return widget;
7595 } else {
7596 parent->setLayout(hLayout);
7597 return parent;
7602 //Widget CreateFrame(Widget parent, char *s)
7604 // Widget fr;
7606 // fr = XtVaCreateManagedWidget("frame", xmFrameWidgetClass, parent, NULL);
7607 // if (s != NULL) {
7608 // XtVaCreateManagedWidget(s, xmLabelGadgetClass, fr,
7609 // XmNchildType, XmFRAME_TITLE_CHILD,
7610 // NULL);
7611 // }
7613 // return (fr);
7615 Widget CreateFrame(Widget parent, char *s)
7617 QGroupBox *groupBox = new QGroupBox(parent);
7618 QVBoxLayout *vLayout = new QVBoxLayout;
7619 vLayout->setContentsMargins(0,0,0,0);
7620 groupBox->setLayout(vLayout);
7622 if (s != NULL) {
7623 groupBox->setTitle(s);
7626 QLayout *layout = parent->layout();
7627 if (layout != 0) {
7628 layout->addWidget(groupBox);
7631 return groupBox;
7635 //typedef struct {
7636 // int ncols;
7637 // int nrows;
7638 //} GridData;
7640 //Widget CreateGrid(Widget parent, int ncols, int nrows)
7642 // Widget w;
7643 // int nfractions;
7644 // GridData *gd;
7646 // if (ncols <= 0 || nrows <= 0) {
7647 // errmsg("Wrong call to CreateGrid()");
7648 // ncols = 1;
7649 // nrows = 1;
7650 // }
7652 // nfractions = 0;
7653 // do {
7654 // nfractions++;
7655 // } while (nfractions % ncols || nfractions % nrows);
7657 // gd = xmalloc(sizeof(GridData));
7658 // gd->ncols = ncols;
7659 // gd->nrows = nrows;
7661 // w = XmCreateForm(parent, "grid_form", NULL, 0);
7662 // XtVaSetValues(w,
7663 // XmNfractionBase, nfractions,
7664 // XmNuserData, gd,
7665 // NULL);
7667 // XtManageChild(w);
7668 // return w;
7670 Widget CreateGrid(Widget parent, int ncols, int nrows)
7672 QWidget *widget = new QWidget(parent);
7674 QGridLayout *gridLayout = new QGridLayout;
7675 gridLayout->setContentsMargins(3,3,3,3);
7676 widget->setLayout(gridLayout);
7678 QLayout *layout = parent->layout();
7679 if (layout != 0) {
7680 layout->addWidget(widget);
7683 return widget;
7686 //void PlaceGridChild(Widget grid, Widget w, int col, int row)
7688 // int nfractions, w1, h1;
7689 // GridData *gd;
7691 // XtVaGetValues(grid,
7692 // XmNfractionBase, &nfractions,
7693 // XmNuserData, &gd,
7694 // NULL);
7696 // if (gd == NULL) {
7697 // errmsg("PlaceGridChild() called with a non-grid widget");
7698 // return;
7699 // }
7700 // if (col < 0 || col >= gd->ncols) {
7701 // errmsg("PlaceGridChild() called with wrong `col' argument");
7702 // return;
7703 // }
7704 // if (row < 0 || row >= gd->nrows) {
7705 // errmsg("PlaceGridChild() called with wrong `row' argument");
7706 // return;
7707 // }
7709 // w1 = nfractions/gd->ncols;
7710 // h1 = nfractions/gd->nrows;
7712 // XtVaSetValues(w,
7713 // XmNleftAttachment , XmATTACH_POSITION,
7714 // XmNleftPosition , col*w1 ,
7715 // XmNrightAttachment , XmATTACH_POSITION,
7716 // XmNrightPosition , (col + 1)*w1 ,
7717 // XmNtopAttachment , XmATTACH_POSITION,
7718 // XmNtopPosition , row*h1 ,
7719 // XmNbottomAttachment, XmATTACH_POSITION,
7720 // XmNbottomPosition , (row + 1)*h1 ,
7721 // NULL);
7723 void PlaceGridChild(Widget grid, Widget w, int col, int row)
7725 if (QGridLayout *gridLayout = qobject_cast<QGridLayout *>(grid->layout())) {
7726 // scrollArea for explorer
7727 if (QScrollArea *scrollArea = qobject_cast<QScrollArea *>(w->parent()->parent())) {
7728 gridLayout->addWidget(scrollArea, row, col);
7729 } else {
7730 gridLayout->addWidget(w, row, col);
7736 //Widget CreateTab(Widget parent)
7738 // Widget tab;
7740 // tab = XtVaCreateManagedWidget("tab", xmTabWidgetClass, parent, NULL);
7742 // return (tab);
7744 Widget CreateTab(Widget parent)
7746 QTabWidget *tab = new QTabWidget(parent);
7747 tab->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
7749 QLayout *layout = parent->layout();
7750 if (layout != 0) {
7751 layout->addWidget(tab);
7754 return tab;
7757 //Widget CreateTabPage(Widget parent, char *s)
7759 // Widget w;
7760 // XmString str;
7762 // w = XmCreateRowColumn(parent, "tabPage", NULL, 0);
7763 // str = XmStringCreateLocalized(s);
7764 // XtVaSetValues(w, XmNtabLabel, str, NULL);
7765 // XmStringFree(str);
7766 // XtManageChild(w);
7768 // return (w);
7770 Widget CreateTabPage(Widget parent, char *s)
7772 QTabWidget *tabWidget = (QTabWidget *) parent;
7774 QWidget *widget2 = new QWidget(parent);
7775 QLayout *vLayout2 = new QVBoxLayout;
7776 vLayout2->setContentsMargins(0,0,0,0);
7778 QWidget *widget = new QWidget(widget2);
7779 QLayout *vLayout = new QVBoxLayout;
7780 vLayout->setContentsMargins(3,3,3,3);
7781 widget->setLayout(vLayout);
7783 vLayout2->addWidget(widget);
7785 QSpacerItem *vSpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
7787 vLayout2->addItem(vSpacer);
7788 widget2->setLayout(vLayout2);
7790 tabWidget->addTab(widget2, s);
7792 return widget;
7795 //void SelectTabPage(Widget tab, Widget w)
7797 // XmTabSetTabWidget(tab, w, True);
7799 void SelectTabPage(Widget tab, Widget w)
7801 QTabWidget *tabWidget = (QTabWidget *) tab;
7803 tabWidget->setCurrentWidget(w);
7806 //Widget CreateTextItem(Widget parent, int len, char *s)
7808 // Widget w;
7809 // Widget rc;
7810 // XmString str;
7811 // rc = XmCreateRowColumn(parent, "rc", NULL, 0);
7812 // XtVaSetValues(rc, XmNorientation, XmHORIZONTAL, NULL);
7813 // str = XmStringCreateLocalized(s);
7814 // XtVaCreateManagedWidget("label", xmLabelWidgetClass, rc,
7815 // XmNlabelString, str,
7816 // NULL);
7817 // XmStringFree(str);
7818 // w = XtVaCreateManagedWidget("text", xmTextWidgetClass, rc,
7819 // XmNtraversalOn, True,
7820 // XmNcolumns, len,
7821 // NULL);
7822 // XtManageChild(rc);
7823 // return w;
7825 Widget CreateTextItem(Widget parent, int len, char *s)
7827 QWidget *widget = new QWidget(parent);
7829 QLabel *label = new QLabel(widget);
7830 label->setText(s);
7832 QLineEdit *lineEdit = new QLineEdit(widget);
7833 SetLineEditWidth(lineEdit, len);
7835 QHBoxLayout *hBoxLayout = new QHBoxLayout;
7836 hBoxLayout->setContentsMargins(0,0,0,0);
7837 hBoxLayout->addWidget(label);
7838 hBoxLayout->addWidget(lineEdit);
7839 widget->setLayout(hBoxLayout);
7841 QLayout *layout = parent->layout();
7842 if (layout != 0) {
7843 layout->addWidget(widget);
7846 return lineEdit;
7849 typedef struct {
7850 TItem_CBProc cbproc;
7851 void *anydata;
7852 } TItem_CBdata;
7854 //static void titem_int_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
7856 // char *s;
7857 // TItem_CBdata *cbdata = (TItem_CBdata *) client_data;
7858 // s = XmTextGetString(w);
7859 // cbdata->cbproc(w, s, cbdata->anydata);
7860 // XtFree(s);
7862 static void titem_int_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
7864 char *s;
7865 TItem_CBdata *cbdata = (TItem_CBdata *) client_data;
7867 QLineEdit *lineEdit = qobject_cast<QLineEdit *>(w);
7868 QByteArray ba = lineEdit->text().toAscii();
7869 s = ba.data();
7870 cbdata->cbproc(w, s, cbdata->anydata);
7874 //void AddTextItemCB(Widget ti, TItem_CBProc cbproc, void *data)
7876 // TItem_CBdata *cbdata;
7878 // cbdata = xmalloc(sizeof(TItem_CBdata));
7879 // cbdata->anydata = data;
7880 // cbdata->cbproc = cbproc;
7881 // XtAddCallback(ti, XmNactivateCallback, titem_int_cb_proc, (XtPointer) cbdata);
7883 void AddTextItemCB(Widget ti, TItem_CBProc cbproc, void *data)
7885 TItem_CBdata *cbdata;
7887 cbdata = (TItem_CBdata *) xmalloc(sizeof(TItem_CBdata));
7888 cbdata->anydata = data;
7889 cbdata->cbproc = cbproc;
7891 QtAddCallback(ti, SIGNAL(returnPressed()),
7892 titem_int_cb_proc, (XtPointer) cbdata);
7895 ///* FIXME: get rid of xv_getstr()!!! */
7896 //#define MAX_STRING_LENGTH 512
7897 //char *xv_getstr(Widget w)
7898 ///*
7899 // * return the string from a text widget
7900 // *
7901 // * NB - newlines are converted to spaces
7902 // */
7904 // char *s;
7905 // int i;
7906 // static char buf[MAX_STRING_LENGTH];
7908 // strncpy(buf, s = XmTextGetString(w), MAX_STRING_LENGTH - 1);
7909 // XtFree(s);
7911 // i=strlen(buf);
7912 // for (i--; i >= 0; i--) {
7913 // if (buf[i] == '\n') {
7914 // buf[i] = ' ';
7915 // }
7916 // }
7917 // return buf;
7919 char *xv_getstr(Widget w)
7921 * return the string from a text widget
7923 * NB - newlines are converted to spaces
7926 //TODO: do I need convert new lines to spaces?
7927 static char *buf;
7929 QLineEdit *lineEdit = (QLineEdit*) w;
7930 QString str = lineEdit->text();
7931 QByteArray ba = str.toAscii();
7932 buf = copy_string(buf, ba.data());
7934 return buf;
7939 * xv_evalexpr - take a text field and pass it to the parser to evaluate
7941 //int xv_evalexpr(Widget w, double *answer)
7943 // int retval;
7944 // char *s;
7946 // s = XmTextGetString(w);
7948 // retval = graal_eval_expr(grace_get_graal(gapp->grace),
7949 // s, answer, gproject_get_top(gapp->gp));
7951 // XtFree(s);
7953 // return retval;
7955 int xv_evalexpr(Widget w, double *answer)
7957 int retval;
7958 char *s;
7960 QLineEdit *lineEdit = (QLineEdit*) w;
7961 QString str = lineEdit->text();
7962 QByteArray ba = str.toAscii();
7963 s = ba.data();
7965 retval = graal_eval_expr(grace_get_graal(gapp->grace),
7966 s, answer, gproject_get_top(gapp->gp));
7968 return retval;
7971 ///*
7972 // * xv_evalexpri - as xv_evalexpr, but for integers
7973 // */
7974 int xv_evalexpri(Widget w, int *answer)
7976 int retval;
7977 double buf;
7979 retval = xv_evalexpr(w, &buf);
7981 *answer = rint(buf);
7983 return retval;
7987 //void xv_setstr(Widget w, char *s)
7989 // if (w != NULL) {
7990 // XmTextSetString(w, s ? s : "");
7991 // }
7993 void xv_setstr(Widget w, char *s)
7995 QLineEdit *lineEdit = (QLineEdit*) w;
7997 if (w != NULL) {
7998 lineEdit->setText(s ? s : "");
8002 ///* if user tried to close from WM */
8003 //static void wm_exit_cb(Widget w, XtPointer client_data, XtPointer call_data)
8005 // bailout(gapp);
8008 //static Widget *savewidgets = NULL;
8009 //static int nsavedwidgets = 0;
8011 //static void savewidget(Widget w)
8013 // int i;
8015 // for (i = 0; i < nsavedwidgets; i++) {
8016 // if (w == savewidgets[i]) {
8017 // return;
8018 // }
8019 // }
8021 // savewidgets = xrealloc(savewidgets, (nsavedwidgets + 1)*sizeof(Widget));
8022 // savewidgets[nsavedwidgets] = w;
8023 // nsavedwidgets++;
8026 //#if 0
8027 //static void deletewidget(Widget w)
8029 // int i;
8031 // for (i = 0; i < nsavedwidgets; i++) {
8032 // if (w == savewidgets[i]) {
8033 // nsavedwidgets--;
8034 // for (; i < nsavedwidgets; i++) {
8035 // savewidgets[i] = savewidgets[i + 1];
8036 // }
8037 // savewidgets = xrealloc(savewidgets, nsavedwidgets*sizeof(Widget));
8038 // XtDestroyWidget(w);
8039 // return;
8040 // }
8041 // }
8044 //#endif
8046 ///*
8047 // * handle the close item on the WM menu
8048 // */
8049 //void handle_close(Widget w)
8051 // X11Stuff *xstuff = gapp->gui->xstuff;
8052 // Atom WM_DELETE_WINDOW;
8054 // XtVaSetValues(w, XmNdeleteResponse, XmDO_NOTHING, NULL);
8055 // WM_DELETE_WINDOW = XmInternAtom(xstuff->disp, "WM_DELETE_WINDOW", False);
8056 // XmAddProtocolCallback(w,
8057 // XM_WM_PROTOCOL_ATOM(w), WM_DELETE_WINDOW,
8058 // (w == app_shell) ? wm_exit_cb : destroy_dialog, w);
8060 // savewidget(w);
8063 ///*
8064 // * Manage and raise
8065 // */
8066 //void RaiseWindow(Widget w)
8068 // XtManageChild(w);
8069 // XMapRaised(XtDisplay(w), XtWindow(w));
8071 void RaiseWindow(Widget w)
8073 w->show();
8077 //void DefineDialogCursor(Cursor c)
8079 // X11Stuff *xstuff = gapp->gui->xstuff;
8080 // int i;
8082 // for (i = 0; i < nsavedwidgets; i++) {
8083 // XDefineCursor(xstuff->disp, XtWindow(savewidgets[i]), c);
8084 // }
8085 // XFlush(xstuff->disp);
8088 //void UndefineDialogCursor(void)
8090 // X11Stuff *xstuff = gapp->gui->xstuff;
8091 // int i;
8093 // for (i = 0; i < nsavedwidgets; i++) {
8094 // XUndefineCursor(xstuff->disp, XtWindow(savewidgets[i]));
8095 // }
8096 // XFlush(xstuff->disp);
8099 //Widget CreateSeparator(Widget parent)
8101 // Widget sep;
8103 // sep = XmCreateSeparator(parent, "sep", NULL, 0);
8104 // XtManageChild(sep);
8105 // return sep;
8107 Widget CreateSeparator(Widget parent)
8109 QToolBar *toolBar = (QToolBar*) parent;
8111 QAction *action = toolBar->addSeparator();
8113 return (QWidget*)action;
8116 //Widget CreateMenuSeparator(Widget parent)
8118 // return CreateSeparator(parent);
8120 Widget CreateMenuSeparator(Widget parent)
8122 QMenu *menu = (QMenu*)parent;
8124 QAction *action = menu->addSeparator();
8126 return (QWidget*)action;
8129 //Widget CreatePopupMenu(Widget parent)
8131 // return XmCreatePopupMenu(parent, "popupMenu", NULL, 0);
8133 Widget CreatePopupMenu(Widget parent)
8135 return new QMenu(parent);
8138 //Widget CreateMenuBar(Widget parent)
8140 // Widget menubar;
8142 // menubar = XmCreateMenuBar(parent, "menuBar", NULL, 0);
8143 // return menubar;
8145 Widget CreateMenuBar(Widget parent)
8147 QMenuBar *menuBar = new QMenuBar(parent);
8149 return menuBar;
8152 //Widget CreateMenu(Widget parent, char *label, char mnemonic, int help)
8154 // Widget menupane, cascade;
8155 // XmString str;
8156 // char *name, ms[2];
8158 // name = label_to_resname(label, "Menu");
8159 // menupane = XmCreatePulldownMenu(parent, name, NULL, 0);
8160 // xfree(name);
8162 // ms[0] = mnemonic;
8163 // ms[1] = '\0';
8165 // str = XmStringCreateLocalized(label);
8166 // cascade = XtVaCreateManagedWidget("cascade",
8167 // xmCascadeButtonGadgetClass, parent,
8168 // XmNsubMenuId, menupane,
8169 // XmNlabelString, str,
8170 // XmNmnemonic, XStringToKeysym(ms),
8171 // NULL);
8172 // XmStringFree(str);
8174 // if (help) {
8175 // XtVaSetValues(parent, XmNmenuHelpWidget, cascade, NULL);
8176 // CreateMenuButton(menupane, "On context", 'x',
8177 // ContextHelpCB, NULL);
8178 // CreateSeparator(menupane);
8179 // }
8181 // SetUserData(menupane, cascade);
8183 // return menupane;
8185 Widget CreateMenu(Widget parent, char *label, char mnemonic, int help)
8187 QMenuBar *menuBar = (QMenuBar*)parent;
8189 QString l(label);
8190 int index = l.indexOf(mnemonic);
8191 l.insert(index, "&");
8193 QMenu *menu = new QMenu(l, menuBar);
8194 menu->setTearOffEnabled(true);
8196 if (help) {
8197 menuBar->addSeparator();
8198 CreateMenuButton(menu, "On context", 'x',
8199 ContextHelpCB, NULL);
8200 CreateSeparator(menu);
8203 menuBar->addAction(menu->menuAction());
8205 return menu;
8208 //void ManageMenu(Widget menupane)
8210 // Widget cascade = GetUserData(menupane);
8211 // XtManageChild(cascade);
8214 //void UnmanageMenu(Widget menupane)
8216 // Widget cascade = GetUserData(menupane);
8217 // XtUnmanageChild(cascade);
8220 //Widget CreateMenuButton(Widget parent, char *label, char mnemonic,
8221 // Button_CBProc cb, void *data)
8223 // Widget button;
8224 // XmString str;
8225 // char *name, ms[2];
8227 // ms[0] = mnemonic;
8228 // ms[1] = '\0';
8230 // str = XmStringCreateLocalized(label);
8231 // name = label_to_resname(label, "Button");
8232 // button = XtVaCreateManagedWidget(name,
8233 // xmPushButtonWidgetClass, parent,
8234 // XmNlabelString, str,
8235 // XmNmnemonic, XStringToKeysym(ms),
8236 // NULL);
8237 // xfree(name);
8238 // XmStringFree(str);
8240 // AddButtonCB(button, cb, data);
8242 // return button;
8244 Widget CreateMenuButton(Widget parent, char *label, char mnemonic,
8245 Button_CBProc cb, void *data)
8247 QMenu *menu = (QMenu*)parent;
8249 QString l(label);
8250 int index = l.indexOf(mnemonic);
8251 l.insert(index, "&");
8253 QAction *action = new QAction(l, parent);
8255 AddButtonCB((QWidget*)action, cb, data);
8257 menu->addAction(action);
8259 return (QWidget*)action;
8262 //Widget CreateMenuButtonA(Widget parent, char *label, char mnemonic,
8263 // char *accelerator, Button_CBProc cb, void *data)
8265 // return CreateMenuButton(parent, label, mnemonic, cb, data);
8267 Widget CreateMenuButtonA(Widget parent, char *label, char mnemonic,
8268 char *accelerator, Button_CBProc cb, void *data)
8270 QAction *action = (QAction*)
8271 CreateMenuButton(parent, label, mnemonic, cb, data);
8273 action->setShortcut( QKeySequence(accelerator) );
8275 return (QWidget*)action;
8278 //Widget CreateMenuCloseButton(Widget parent, Widget form)
8280 // Widget wbut;
8281 // XmString str;
8283 // wbut = CreateMenuButton(parent,
8284 // "Close", 'C', destroy_dialog_cb, XtParent(form));
8285 // str = XmStringCreateLocalized("Esc");
8286 // XtVaSetValues(wbut, XmNacceleratorText, str, NULL);
8287 // XmStringFree(str);
8288 // XtVaSetValues(form, XmNcancelButton, wbut, NULL);
8290 // return wbut;
8292 Widget CreateMenuCloseButton(Widget parent, Widget form)
8294 Widget wbut;
8296 wbut = CreateMenuButtonA(parent,
8297 "Close", 'C', "Esc", destroy_dialog_cb, form);
8299 return wbut;
8302 //Widget CreateMenuHelpButton(Widget parent, char *label, char mnemonic,
8303 // Widget form, char *ha)
8305 // Widget wbut;
8307 // wbut = CreateMenuButton(parent, label, mnemonic, HelpCB, ha);
8308 // AddHelpCB(form, ha);
8310 // return wbut;
8312 Widget CreateMenuHelpButton(Widget parent, char *label, char mnemonic,
8313 Widget form, char *ha)
8315 Widget wbut;
8317 wbut = CreateMenuButton(parent, label, mnemonic, HelpCB, ha);
8319 return wbut;
8322 //Widget CreateMenuToggle(Widget parent, char *label, char mnemonic,
8323 // TB_CBProc cb, void *data)
8325 // Widget button;
8326 // XmString str;
8327 // char *name, ms[2];
8329 // ms[0] = mnemonic;
8330 // ms[1] = '\0';
8332 // str = XmStringCreateLocalized(label);
8333 // name = label_to_resname(label, NULL);
8334 // button = XtVaCreateManagedWidget(name,
8335 // xmToggleButtonWidgetClass, parent,
8336 // XmNlabelString, str,
8337 // XmNmnemonic, XStringToKeysym(ms),
8338 // XmNvisibleWhenOff, True,
8339 // XmNindicatorOn, True,
8340 // NULL);
8341 // xfree(name);
8342 // XmStringFree(str);
8344 // if (cb) {
8345 // AddToggleButtonCB(button, cb, data);
8346 // }
8348 // return button;
8350 Widget CreateMenuToggle(Widget parent, char *label, char mnemonic,
8351 TB_CBProc cb, void *data)
8353 QMenu *menu = (QMenu*)parent;
8355 QString l(label);
8356 int index = l.indexOf(mnemonic);
8357 l.insert(index, "&");
8359 QAction *action = new QAction(l, parent);
8360 action->setCheckable(true);
8362 if (cb) {
8363 AddToggleButtonCB((QWidget*)action, cb, data);
8366 menu->addAction(action);
8368 return (QWidget*)action;
8371 //Widget CreateMenuLabel(Widget parent, char *name)
8373 // Widget lab;
8375 // lab = XmCreateLabel(parent, name, NULL, 0);
8376 // XtManageChild(lab);
8377 // return lab;
8379 Widget CreateMenuLabel(Widget parent, char *name)
8381 QMenu *popup = (QMenu*) parent;
8383 QAction *action = new QAction(popup);
8384 popup->addAction(action);
8386 return (QWidget*) action;
8389 //static void help_int_cb(Widget w, XtPointer client_data, XtPointer call_data)
8391 // HelpCB(w, client_data);
8393 static void help_int_cb(Widget w, XtPointer client_data, XtPointer call_data)
8395 HelpCB(w, client_data);
8398 //void AddHelpCB(Widget w, char *ha)
8400 // if (XtHasCallbacks(w, XmNhelpCallback) == XtCallbackHasSome) {
8401 // /* allow only one help callback */
8402 // XtRemoveAllCallbacks(w, XmNhelpCallback);
8403 // }
8405 // XtAddCallback(w, XmNhelpCallback, help_int_cb, (XtPointer) ha);
8407 WhatsThisListener::WhatsThisListener(QObject *parent)
8408 : QObject(parent)
8412 bool WhatsThisListener::eventFilter(QObject *obj, QEvent *event)
8414 if (event->type() == QEvent::WhatsThis) {
8415 emit whatsThis();
8416 return false;
8417 } else {
8418 // standard event processing
8419 return QObject::eventFilter(obj, event);
8423 void AddHelpCB(Widget w, char *ha)
8425 WhatsThisListener *listener = new WhatsThisListener(w);
8426 w->installEventFilter(listener);
8427 QtAddCallback(listener, SIGNAL(whatsThis()), help_int_cb, (XtPointer) ha);
8430 //void ContextHelpCB(Widget but, void *data)
8432 // X11Stuff *xstuff = gapp->gui->xstuff;
8433 // Widget whelp;
8434 // Cursor cursor;
8435 // int ok = FALSE;
8437 // cursor = XCreateFontCursor(xstuff->disp, XC_question_arrow);
8438 // whelp = XmTrackingLocate(app_shell, cursor, False);
8439 // while (whelp != NULL) {
8440 // if (XtHasCallbacks(whelp, XmNhelpCallback) == XtCallbackHasSome) {
8441 // XtCallCallbacks(whelp, XmNhelpCallback, NULL);
8442 // ok = TRUE;
8443 // break;
8444 // } else {
8445 // whelp = GetParent(whelp);
8446 // }
8447 // }
8448 // if (!ok) {
8449 // HelpCB(but, NULL);
8450 // }
8451 // XFreeCursor(xstuff->disp, cursor);
8453 void ContextHelpCB(Widget but, void *data)
8455 // X11Stuff *xstuff = gapp->gui->xstuff;
8456 // Widget whelp;
8457 // Cursor cursor;
8458 int ok = FALSE;
8460 QWhatsThis::enterWhatsThisMode();
8461 // QWidget::event()
8462 // cursor = XCreateFontCursor(xstuff->disp, XC_question_arrow);
8463 // whelp = XmTrackingLocate(app_shell, cursor, False);
8464 // while (whelp != NULL) {
8465 // if (XtHasCallbacks(whelp, XmNhelpCallback) == XtCallbackHasSome) {
8466 // XtCallCallbacks(whelp, XmNhelpCallback, NULL);
8467 // ok = TRUE;
8468 // break;
8469 // } else {
8470 // whelp = GetParent(whelp);
8471 // }
8472 // }
8473 // if (!ok) {
8474 // HelpCB(but, NULL);
8475 // }
8476 // XFreeCursor(xstuff->disp, cursor);
8480 //static int yesno_retval = FALSE;
8481 //static Boolean keep_grab = True;
8483 //void yesnoCB(Widget w, XtPointer client_data, XtPointer call_data)
8485 // XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call_data;
8486 // int why = cbs->reason;
8488 // keep_grab = False;
8490 // XtRemoveGrab(XtParent(w));
8491 // XtUnmanageChild(w);
8492 // switch (why) {
8493 // case XmCR_OK:
8494 // yesno_retval = TRUE;
8495 // /* process ok action */
8496 // break;
8497 // case XmCR_CANCEL:
8498 // yesno_retval = FALSE;
8499 // /* process cancel action */
8500 // break;
8501 // }
8504 //int yesnowin(char *msg, char *s1, char *s2, char *help_anchor)
8506 // static Widget dialog = NULL;
8507 // XEvent event;
8508 // static char *ha = NULL;
8509 // Widget but;
8510 // XmString str;
8512 // ha = help_anchor;
8514 // keep_grab = True;
8516 // if (dialog == NULL) {
8517 // dialog = XmCreateErrorDialog(app_shell, "warningDialog", NULL, 0);
8519 // str = XmStringCreateLocalized("Grace: Warning");
8520 // XtVaSetValues(dialog, XmNdialogTitle, str, NULL);
8521 // XmStringFree(str);
8523 // XtAddCallback(dialog, XmNokCallback, yesnoCB, NULL);
8524 // XtAddCallback(dialog, XmNcancelCallback, yesnoCB, NULL);
8526 // but = XtNameToWidget(dialog, "Help");
8527 // AddButtonCB(but, HelpCB, ha);
8528 // }
8530 // if (msg != NULL) {
8531 // str = XmStringCreateLocalized(msg);
8532 // } else {
8533 // str = XmStringCreateLocalized("Warning");
8534 // }
8535 // XtVaSetValues(dialog, XmNmessageString, str, NULL);
8536 // XmStringFree(str);
8538 // but = XtNameToWidget(dialog, "OK");
8539 // if (s1) {
8540 // SetLabel(but, s1);
8541 // } else {
8542 // SetLabel(but, "OK");
8543 // }
8545 // but = XtNameToWidget(dialog, "Cancel");
8546 // if (s2) {
8547 // SetLabel(but, s2);
8548 // } else {
8549 // SetLabel(but, "Cancel");
8550 // }
8552 // but = XtNameToWidget(dialog, "Help");
8553 // if (ha) {
8554 // XtManageChild(but);
8555 // } else {
8556 // XtUnmanageChild(but);
8557 // }
8559 // RaiseWindow(dialog);
8561 // XtAddGrab(XtParent(dialog), True, False);
8562 // while (keep_grab || XtAppPending(app_con)) {
8563 // XtAppNextEvent(app_con, &event);
8564 // XtDispatchEvent(&event);
8565 // }
8566 // return yesno_retval;
8568 int yesnowin(char *msg, char *s1, char *s2, char *help_anchor)
8570 QMessageBox msgBox(mainWin);
8571 msgBox.setWindowTitle("Grace: Warning");
8572 msgBox.setIcon(QMessageBox::Question);
8573 if (msg != NULL) {
8574 msgBox.setText(msg);
8575 } else {
8576 msgBox.setText("Warning");
8579 if (help_anchor) {
8580 msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel | QMessageBox::Help);
8581 } else {
8582 msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
8585 if (s1) {
8586 msgBox.button(QMessageBox::Ok)->setText(s1);
8589 if (s2) {
8590 msgBox.button(QMessageBox::Cancel)->setText(s2);
8593 msgBox.setDefaultButton(QMessageBox::Cancel);
8594 msgBox.setEscapeButton(QMessageBox::Cancel);
8595 int yesno_retval = FALSE;
8596 int ret = msgBox.exec();
8597 switch (ret) {
8598 case QMessageBox::Ok:
8599 yesno_retval = TRUE;
8600 break;
8601 case QMessageBox::Cancel:
8602 yesno_retval = FALSE;
8603 break;
8604 case QMessageBox::Help:
8605 HelpCB(NULL, help_anchor);
8606 // help was clicked
8607 break;
8608 default:
8609 // should never be reached
8610 break;
8613 return yesno_retval;
8617 //void SetLabel(Widget w, char *s)
8619 // XmString str;
8621 // str = XmStringCreateLocalized(s);
8622 // XtVaSetValues(w, XmNlabelString, str, NULL);
8623 // XmStringFree(str);
8625 void LabelSetString(Widget w, char *s)
8627 //qDebug("SetLabel %s", s);
8628 if (QAction *action = qobject_cast<QAction *>(w)) {
8629 action->setText(s);
8630 } else {
8631 QLabel *label = (QLabel*) w;
8632 label->setText(s);
8636 //void SetFixedFont(Widget w)
8638 // X11Stuff *xstuff = gapp->gui->xstuff;
8639 // XFontStruct *f;
8640 // XmFontList xmf;
8642 // f = XLoadQueryFont(xstuff->disp, "fixed");
8643 // xmf = XmFontListCreate(f, charset);
8644 // if (xmf == NULL) {
8645 // errmsg("Can't load font \"fixed\"");
8646 // return;
8647 // } else {
8648 // XtVaSetValues(w, XmNfontList, xmf, NULL);
8649 // XmFontListFree(xmf);
8650 // }
8653 void update_set_lists(Quark *gr)
8655 update_set_selectors(gr);
8657 snapshot_and_update(gapp->gp, FALSE);
8660 void update_all(void)
8662 if (!gapp->gui->inwin) {
8663 return;
8666 if (gui_is_page_free(gapp->gui)) {
8667 sync_canvas_size(gapp);
8670 update_ssd_selectors(gproject_get_top(gapp->gp));
8671 update_frame_selectors(gproject_get_top(gapp->gp));
8672 update_graph_selectors(gproject_get_top(gapp->gp));
8673 update_set_selectors(NULL);
8675 if (gapp->gui->need_colorsel_update == TRUE) {
8676 init_xvlibcolors();
8677 update_color_selectors();
8678 gapp->gui->need_colorsel_update = FALSE;
8681 if (gapp->gui->need_fontsel_update == TRUE) {
8682 update_font_selectors();
8683 gapp->gui->need_fontsel_update = FALSE;
8686 update_undo_buttons(gapp->gp);
8687 update_props_items();
8688 set_left_footer(NULL);
8689 update_app_title(gapp->gp);
8692 //int clean_graph_selectors(Quark *pr, int etype, void *data)
8694 // if (etype == QUARK_ETYPE_DELETE) {
8695 // int i;
8696 // for (i = 0; i < ngraph_selectors; i++) {
8697 // SetStorageChoiceQuark(graph_selectors[i], NULL);
8698 // }
8699 // for (i = 0; i < nssd_selectors; i++) {
8700 // SetStorageChoiceQuark(ssd_selectors[i], NULL);
8701 // }
8702 // } else
8703 // if (etype == QUARK_ETYPE_MODIFY) {
8704 // /* update_graph_selectors(pr); */
8705 // }
8707 // return RETURN_SUCCESS;
8709 int clean_graph_selectors(Quark *pr, int etype, void *data)
8711 if (etype == QUARK_ETYPE_DELETE) {
8712 int i;
8713 for (i = 0; i < ngraph_selectors; i++) {
8714 SetStorageChoiceQuark(graph_selectors[i], NULL);
8716 for (i = 0; i < nssd_selectors; i++) {
8717 SetStorageChoiceQuark(ssd_selectors[i], NULL);
8719 } else
8720 if (etype == QUARK_ETYPE_MODIFY) {
8721 /* update_graph_selectors(pr); */
8724 return RETURN_SUCCESS;
8727 //int clean_frame_selectors(Quark *pr, int etype, void *data)
8729 // if (etype == QUARK_ETYPE_DELETE) {
8730 // int i;
8731 // for (i = 0; i < nframe_selectors; i++) {
8732 // SetStorageChoiceQuark(frame_selectors[i], NULL);
8733 // }
8734 // } else
8735 // if (etype == QUARK_ETYPE_MODIFY) {
8736 // /* update_frame_selectors(pr); */
8737 // }
8739 // return RETURN_SUCCESS;
8741 int clean_frame_selectors(Quark *pr, int etype, void *data)
8743 if (etype == QUARK_ETYPE_DELETE) {
8744 int i;
8745 for (i = 0; i < nframe_selectors; i++) {
8746 SetStorageChoiceQuark(frame_selectors[i], NULL);
8748 } else
8749 if (etype == QUARK_ETYPE_MODIFY) {
8750 /* update_frame_selectors(pr); */
8753 return RETURN_SUCCESS;
8756 //int clean_set_selectors(Quark *gr, int etype, void *data)
8758 // if (etype == QUARK_ETYPE_DELETE) {
8759 // int i;
8760 // for (i = 0; i < nset_selectors; i++) {
8761 // Quark *cg;
8762 // StorageStructure *ss = set_selectors[i];
8764 // cg = get_set_choice_gr(ss);
8765 // if (!gr || cg == gr) {
8766 // SetStorageChoiceQuark(ss, NULL);
8767 // }
8768 // }
8769 // }
8771 // return RETURN_SUCCESS;
8774 /* what a mess... */
8775 void unlink_ssd_ui(Quark *q)
8777 GUI *gui = gui_from_quark(q);
8778 if (gui && gui->eui && gui->eui->ssd_ui) {
8779 if (gui->eui->ssd_ui->q == q) {
8780 gui->eui->ssd_ui->q = NULL;
8782 if (gui->eui->ssd_ui->col_sel->anydata == q) {
8783 gui->eui->ssd_ui->col_sel->anydata = NULL;
8790 * action routines, to be used with translations
8793 /* This is for buggy Motif-2.1 that crashes with Ctrl+<Btn1Down> */
8794 //static void do_nothing_action(Widget w, XEvent *e, String *par, Cardinal *npar)
8798 //static XtActionsRec dummy_actions[] = {
8799 // {"do_nothing", do_nothing_action}
8800 //};
8802 //static XtActionsRec list_select_actions[] = {
8803 // {"list_activate_action", list_activate_action },
8804 // {"list_selectall_action", list_selectall_action },
8805 // {"list_unselectall_action", list_unselectall_action },
8806 // {"list_invertselection_action", list_invertselection_action}
8807 //};
8809 //static XtActionsRec cstext_actions[] = {
8810 // {"cstext_edit_action", cstext_edit_action}
8811 //};
8813 //void InitWidgets(void)
8815 // XtAppAddActions(app_con, dummy_actions, XtNumber(dummy_actions));
8816 // XtAppAddActions(app_con, list_select_actions, XtNumber(list_select_actions));
8817 // XtAppAddActions(app_con, cstext_actions, XtNumber(cstext_actions));
8820 //void set_title(char *title, char *icon_name)
8822 // XtVaSetValues(app_shell, XtNtitle, title, XtNiconName, icon_name, NULL);
8824 void set_title(char *title, char *icon_name)
8826 mainWin->setWindowTitle(title);
8829 /* Tree Widget */
8831 TreeView::TreeView(QWidget *parent)
8832 : QTreeView(parent)
8834 setEditTriggers(QAbstractItemView::NoEditTriggers);
8835 setAcceptDrops(true);
8837 drop_cbdata = 0;
8838 wasSelected = false;
8841 void TreeView::mousePressEvent(QMouseEvent *event)
8843 QPoint pos = event->pos();
8844 QItemSelectionModel *model = selectionModel();
8846 if (event->button() == Qt::MidButton) {
8847 dragStartPosition = pos;
8848 } else {
8849 wasSelected = model->isSelected(indexAt(pos));
8850 QTreeView::mousePressEvent(event);
8854 void TreeView::mouseReleaseEvent(QMouseEvent *event)
8856 QTreeView::mouseReleaseEvent(event);
8858 if (event->button() == Qt::RightButton) {
8859 if (!wasSelected) {
8860 emit released();
8862 emit releasedRMB();
8863 } else {
8864 emit released();
8868 void TreeView::mouseMoveEvent(QMouseEvent *event)
8870 QItemSelectionModel *model = selectionModel();
8872 if (event->buttons() & Qt::MidButton) {
8874 if ((event->pos() - dragStartPosition).manhattanLength()
8875 < QApplication::startDragDistance()) return;
8877 if (!model->isSelected(indexAt(dragStartPosition))) return;
8879 QDrag *drag = new QDrag(this);
8880 drag->setMimeData(new QMimeData);
8881 drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::MoveAction);
8882 } else {
8883 QTreeView::mouseMoveEvent(event);
8887 void TreeView::dragEnterEvent(QDragEnterEvent *event)
8889 qDebug("xxxx");
8890 event->accept();
8893 void TreeView::dropEvent(QDropEvent *event)
8895 qDebug("yyyy");
8896 QPersistentModelIndex index = indexAt(event->pos());
8898 if (drop_cbdata && index.isValid()) {
8899 TreeEvent e;
8900 QStandardItemModel *model = (QStandardItemModel *) this->model();
8902 e.w = drop_cbdata->w;
8903 e.anydata = drop_cbdata->anydata;
8904 e.udata = model->itemFromIndex(index);
8906 switch (event->dropAction()) {
8907 case Qt::MoveAction:
8908 e.drop_action = DROP_ACTION_MOVE;
8909 qDebug("DROP_ACTION_MOVE");
8910 break;
8911 case Qt::CopyAction:
8912 e.drop_action = DROP_ACTION_COPY;
8913 qDebug("DROP_ACTION_COPY");
8914 break;
8915 default:
8916 qDebug("DROP_ACTION_UKNOWN");
8917 event->ignore();
8918 return;
8921 if (drop_cbdata->cbproc(&e)) {
8922 event->accept();
8923 return;
8927 event->ignore();
8930 void TreeView::dragMoveEvent(QDragMoveEvent *event)
8932 event->acceptProposedAction();
8935 Widget CreateTree(Widget parent)
8937 TreeView *treeView = new TreeView(parent);
8938 QStandardItemModel *model = new QStandardItemModel;
8939 treeView->setModel(model);
8941 treeView->setHeaderHidden(true);
8942 treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
8943 treeView->header()->setResizeMode(QHeaderView::ResizeToContents);
8944 treeView->header()->setStretchLastSection(false);
8945 treeView->setAutoScroll(false);
8947 QLayout *layout = parent->layout();
8948 if (layout != 0) {
8949 layout->addWidget(treeView);
8952 return treeView;
8955 TreeItem *TreeInsertItem(Widget w, TreeItem *parent, Quark *q, int row)
8957 TreeView *treeView = (TreeView *) w;
8958 QStandardItemModel *model = (QStandardItemModel *) treeView->model();
8960 QStandardItem *item;
8961 QStandardItem *parentItem;
8963 if (parent) {
8964 parentItem = (QStandardItem *) parent;
8965 } else {
8966 parentItem = model->invisibleRootItem();
8969 item = new QStandardItem;
8971 item->setData(qVariantFromValue((void *) q));
8973 if (row < 0) {
8974 parentItem->insertRow(parentItem->rowCount() + row + 1, item);
8975 } else {
8976 parentItem->insertRow(row, item);
8979 return item;
8982 void TreeDeleteItem(Widget w, TreeItem *item)
8984 TreeView *treeView = (TreeView *) w;
8985 QStandardItemModel *model = (QStandardItemModel *) treeView->model();
8986 QStandardItem *treeItem = (QStandardItem *) item;
8988 if (item) {
8989 int row = treeItem->row();
8990 QStandardItem *parent = treeItem->parent();
8991 if (!parent) {
8992 parent = model->invisibleRootItem();
8994 parent->removeRow(row);
8995 } else {
8996 model->clear();
9000 void TreeSetItemOpen(Widget w, TreeItem *item, int open)
9002 TreeView *treeView = (TreeView *) w;
9003 QStandardItemModel *model = (QStandardItemModel *) treeView->model();
9004 QStandardItem *treeItem = (QStandardItem *) item;
9006 treeView->setExpanded(model->indexFromItem(treeItem), open);
9009 void TreeSetItemText(Widget w, TreeItem *item, char *text)
9011 QStandardItem *treeItem = (QStandardItem *) item;
9013 treeItem->setText(text);
9016 void TreeSetItemPixmap(Widget w, TreeItem *item, Pixmap pixmap)
9018 QStandardItem *treeItem = (QStandardItem *) item;
9019 QIcon *icon = (QIcon *) pixmap;
9021 treeItem->setIcon(*icon);
9024 Quark *TreeGetQuark(TreeItem *item)
9026 QStandardItem *treeItem = (QStandardItem *) item;
9028 QVariant v = treeItem->data();
9029 Quark *q = (Quark *) v.value<void *>();
9031 return q;
9034 void TreeGetHighlighted(Widget w, TreeItemList *items)
9036 TreeView *treeView = (TreeView *) w;
9037 QStandardItemModel *model = (QStandardItemModel *) treeView->model();
9038 QItemSelectionModel *selectionModel = treeView->selectionModel();
9040 QList<QModelIndex> list = selectionModel->selectedIndexes();
9041 items->count = list.size();
9042 items->items = (TreeItem **) xmalloc(items->count*sizeof(TreeItem *));
9043 for (int i = 0; i < items->count; i++) {
9044 items->items[i] = (TreeItem *) model->itemFromIndex(list.at(i));
9048 void TreeHighlightItem(Widget w, TreeItem *item)
9050 TreeView *treeView = (TreeView *) w;
9051 QStandardItemModel *model = (QStandardItemModel *) treeView->model();
9052 QItemSelectionModel *selectionModel = treeView->selectionModel();
9053 QStandardItem *treeItem = (QStandardItem *) item;
9055 if (!item) {
9056 treeItem = model->invisibleRootItem()->child(0);
9058 QModelIndex index = model->indexFromItem(treeItem);
9059 selectionModel->setCurrentIndex(index, QItemSelectionModel::Select);
9061 QMetaObject::invokeMethod(treeView, "released", Qt::QueuedConnection);
9064 void TreeClearSelection(Widget w)
9066 TreeView *treeView = (TreeView *) w;
9068 treeView->clearSelection();
9071 void TreeScrollToItem(Widget w, TreeItem *item)
9073 TreeView *treeView = (TreeView *) w;
9074 QStandardItemModel *model = (QStandardItemModel *) treeView->model();
9075 QStandardItem *treeItem = (QStandardItem *) item;
9077 treeView->scrollTo(model->indexFromItem(treeItem));
9080 void TreeRefresh(Widget w)
9085 static void tree_context_menu_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
9087 Tree_CBData *cbdata = (Tree_CBData *) client_data;
9089 TreeEvent event;
9090 event.w = cbdata->w;
9091 event.anydata = cbdata->anydata;
9093 QPoint point = QCursor::pos();
9094 event.udata = &point;
9096 cbdata->cbproc(&event);
9099 void AddTreeContextMenuCB(Widget w, Tree_CBProc cbproc, void *anydata)
9101 Tree_CBData *cbdata;
9103 cbdata = (Tree_CBData *) xmalloc(sizeof(Tree_CBData));
9104 cbdata->w = w;
9105 cbdata->cbproc = cbproc;
9106 cbdata->anydata = anydata;
9108 QtAddCallback(w, SIGNAL(releasedRMB()),
9109 tree_context_menu_cb_proc, cbdata);
9112 static void tree_highlight_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
9114 Tree_CBData *cbdata = (Tree_CBData *) client_data;
9116 TreeEvent event;
9117 event.w = cbdata->w;
9118 event.anydata = cbdata->anydata;
9120 cbdata->cbproc(&event);
9123 void AddTreeHighlightItemsCB(Widget w, Tree_CBProc cbproc, void *anydata)
9125 Tree_CBData *cbdata;
9127 cbdata = (Tree_CBData *) xmalloc(sizeof(Tree_CBData));
9128 cbdata->w = w;
9129 cbdata->cbproc = cbproc;
9130 cbdata->anydata = anydata;
9132 QtAddCallback(w, SIGNAL(released()),
9133 tree_highlight_cb_proc, (XtPointer) cbdata);
9136 void AddTreeDropItemsCB(Widget w, Tree_CBProc cbproc, void *anydata)
9138 Tree_CBData *cbdata;
9140 cbdata = (Tree_CBData *) xmalloc(sizeof(Tree_CBData));
9141 cbdata->w = w;
9142 cbdata->cbproc = cbproc;
9143 cbdata->anydata = anydata;
9145 TreeView *view = (TreeView *) cbdata->w;
9146 view->setDropCallback(cbdata);
9150 /* Table Widget */
9152 TableModel::TableModel(QObject *parent)
9153 : QAbstractTableModel(parent)
9155 nrows = 0;
9156 ncols = 0;
9157 defaultColumnAlignment = Qt::AlignLeft | Qt::AlignVCenter;
9158 defaultColumnLabelAlignment = Qt::AlignLeft | Qt::AlignVCenter;
9159 defaultRowLabelAlignment = Qt::AlignLeft | Qt::AlignVCenter;
9160 cbdata = 0;
9163 void TableModel::setRowCount(int rows)
9165 if (rows > cells.size()) {
9166 cells.resize(rows);
9167 for (int row = 0; row < rows; ++row) {
9168 cells[row].resize(this->ncols);
9172 this->nrows = rows;
9173 emit nRowsOrColsChanged();
9174 reset();
9177 void TableModel::setColumnCount(int cols)
9179 for (int row = 0; row < this->nrows; ++row) {
9180 if (cells[row].size() < cols)
9181 cells[row].resize(cols);
9184 this->ncols = cols;
9185 emit nRowsOrColsChanged();
9186 reset();
9189 int TableModel::rowCount(const QModelIndex & /* parent */) const
9191 return nrows;
9194 int TableModel::columnCount(const QModelIndex & /* parent */) const
9196 return ncols;
9199 QVariant TableModel::data(const QModelIndex &index, int role) const
9201 TableEvent event;
9203 if (!index.isValid())
9204 return QVariant();
9206 if (role == Qt::TextAlignmentRole)
9207 return int(defaultColumnAlignment);
9209 if (cbdata == 0) {
9210 if (role == Qt::DisplayRole) {
9211 return QString::fromAscii(cells[index.row()][index.column()]);
9212 } else if (role == Qt::EditRole) {
9213 return QVariant::fromValue<void *>(cells[index.row()][index.column()]);
9214 } else {
9215 return QVariant();
9219 event.w = cbdata->w;
9220 event.row = index.row();
9221 event.col = index.column();
9222 event.anydata = cbdata->anydata;
9223 event.pixmap = 0;
9225 cbdata->cbproc(&event);
9227 if (role == Qt::DisplayRole) {
9228 if (event.value_type == TABLE_CELL_STRING) {
9229 return QString::fromAscii(event.value);
9233 if (role == Qt::EditRole) {
9234 if (event.value_type == TABLE_CELL_STRING) {
9235 return QVariant::fromValue<void *>(event.value);
9239 if (role == Qt::DecorationRole) {
9240 if (event.value_type == TABLE_CELL_PIXMAP) {
9241 QPixmap *pixmap = (QPixmap *) event.pixmap;
9242 return QVariant(*pixmap);
9246 return QVariant();
9249 QVariant TableModel::headerData(int section,
9250 Qt::Orientation orientation,
9251 int role) const
9253 if (role == Qt::TextAlignmentRole) {
9254 if (orientation == Qt::Horizontal) {
9255 return int(defaultColumnLabelAlignment);
9257 if (orientation == Qt::Vertical) {
9258 return int(defaultRowLabelAlignment);
9263 if (role == Qt::DisplayRole) {
9264 if (orientation == Qt::Horizontal) {
9265 if (columnLabels.size() > section) {
9266 return columnLabels[section];
9267 } else {
9268 return QVariant();
9270 } else {
9271 if (rowLabels.size() > section) {
9272 return rowLabels[section];
9273 } else {
9274 return QVariant();
9279 return QVariant();
9282 void TableModel::setDefaultColumnAlignment(Qt::Alignment align)
9284 this->defaultColumnAlignment = align | Qt::AlignVCenter;
9287 void TableModel::setDefaultColumnLabelAlignment(Qt::Alignment align)
9289 this->defaultColumnLabelAlignment = align | Qt::AlignVCenter;
9292 void TableModel::setDefaultRowLabelAlignment(Qt::Alignment align)
9294 this->defaultRowLabelAlignment = align | Qt::AlignVCenter;
9297 void TableModel::setRowLabels(char **labels)
9299 int rc = rowCount();
9301 rowLabels.clear();
9303 for (int i = 0; i < rc; i++) {
9304 rowLabels.append(labels[i]);
9308 void TableModel::setColumnLabels(char **labels)
9310 int cc = columnCount();
9312 columnLabels.clear();
9314 for (int i = 0; i < cc; i++) {
9315 columnLabels.append(labels[i]);
9319 void TableModel::setDrawCellCallback(Table_CBData *cbdata)
9321 this->cbdata = cbdata;
9325 TableView::TableView(QAbstractItemModel *model, QWidget *parent)
9326 : QTableView(parent)
9328 this->setModel(model);
9330 connect(model, SIGNAL(nRowsOrColsChanged()), this, SLOT(closeEditor()));
9332 lineEditor = 0;
9334 enter_cbdata = 0;
9335 leave_cbdata = 0;
9337 previous_row = -1;
9338 previous_col = -1;
9341 void TableView::closeEditor()
9343 TableModel *tm = (TableModel *) model();
9345 closeEditor(tm->newIndex(previous_row, previous_col));
9346 qDebug() << "closeEditor";
9349 void TableView::commitEdit()
9351 jumpToCell();
9354 void TableView::setEditorMaxLengths(int *maxlengths)
9356 int cc = model()->columnCount();
9358 editLengths.clear();
9360 for (int i = 0; i < cc; i++) {
9361 editLengths.append(maxlengths[i]);
9365 void TableView::mousePressEvent(QMouseEvent *event)
9367 QModelIndex index = indexAt(event->pos());
9369 if (index.isValid()) {
9370 row = index.row();
9371 col = index.column();
9372 jumpToCell();
9376 void TableView::jumpToCell()
9378 TableModel *tm = (TableModel *) model();
9380 if (leaveCellEvent(previous_row, previous_col)) {
9381 closeEditor(tm->newIndex(previous_row, previous_col));
9382 if (enterCellEvent(row, col)) {
9383 previous_row = row;
9384 previous_col = col;
9385 openEditor(tm->newIndex(row, col));
9390 int TableView::leaveCellEvent(int row, int col)
9392 if (leave_cbdata) {
9393 TableEvent event;
9394 int ok;
9396 if (row != -1 && col != -1) {
9397 if (lineEditor) {
9398 QString str = lineEditor->text();
9399 qDebug() << "getEditorData from lineEdit" << str;
9400 QByteArray ba = str.toAscii();
9401 char *text = copy_string(NULL, ba.data());
9402 qDebug() << "leave cb" << "row" << row << "col" << col << "value" << text;
9403 event.w = leave_cbdata->w;
9404 event.row = row;
9405 event.col = col;
9406 event.value = text;
9407 event.anydata = leave_cbdata->anydata;
9408 ok = leave_cbdata->cbproc(&event);
9409 xfree(text);
9411 return ok;
9412 } else {
9413 qDebug() << "leaveCellEvent index invalid";
9414 return TRUE;
9416 } else {
9417 return TRUE;
9419 } else {
9420 return TRUE;
9424 int TableView::enterCellEvent(int row, int col)
9426 if (enter_cbdata) {
9427 TableEvent event;
9428 int ok;
9430 if (row != -1 && col != -1) {
9431 qDebug() << "enter cb" << "row" << row << "col" << col;
9432 event.w = enter_cbdata->w;
9433 event.row = row;
9434 event.col = col;
9435 event.anydata = enter_cbdata->anydata;
9436 ok = enter_cbdata->cbproc(&event);
9438 return ok;
9439 } else {
9440 qDebug() << "enterCellEvent index invalid";
9441 return TRUE;
9443 } else {
9444 return TRUE;
9448 void TableView::openEditor(QModelIndex index)
9450 if (index.isValid()) {
9451 QVariant v = model()->data(index, Qt::DisplayRole);
9452 lineEditor = new QLineEdit(v.toString());
9453 if (editLengths.size() == model()->columnCount()) {
9454 qDebug() << "openEditor at column" << index.column();
9455 lineEditor->setMaxLength(editLengths.at(index.column()));
9457 setIndexWidget(index, lineEditor);
9458 lineEditor->setFocus();
9459 qDebug() << "openEditor";
9463 void TableView::closeEditor(QModelIndex index)
9465 setIndexWidget(index, 0);
9466 lineEditor = 0;
9467 qDebug() << "closeEditor(index)";
9470 typedef struct {
9471 int font_width;
9472 int frame_width;
9473 int default_col_width;
9474 int nrows_visible;
9475 int ncols_visible;
9476 } TableData;
9478 Widget CreateTable(char *name, Widget parent, int nrows, int ncols, int nrows_visible, int ncols_visible)
9480 TableData *td;
9482 TableModel *model = new TableModel(parent);
9483 model->setRowCount(nrows);
9484 model->setColumnCount(ncols);
9486 TableView *view = new TableView(model, parent);
9488 QHeaderView *hHeader = new HeaderView(Qt::Horizontal);
9489 view->setHorizontalHeader(hHeader);
9490 QHeaderView *vHeader = new HeaderView(Qt::Vertical);
9491 view->setVerticalHeader(vHeader);
9492 QFontMetrics fm = view->fontMetrics();
9494 int margin = view->style()->pixelMetric(QStyle::PM_HeaderMargin, 0, view);
9495 int frame = view->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, 0);
9496 int frameWidth = margin + frame;
9497 int fontWidth = fm.width(QLatin1Char('0'));
9498 int fontHeight = fm.height() + 2*frameWidth;
9500 hHeader->setResizeMode(QHeaderView::Fixed);
9501 vHeader->setResizeMode(QHeaderView::Fixed);
9503 vHeader->setDefaultSectionSize(fontHeight);
9505 td = (TableData*) xmalloc(sizeof(TableData));
9506 td->font_width = fontWidth;
9507 td->frame_width = frameWidth;
9508 td->default_col_width = 5;
9509 td->nrows_visible = nrows_visible;
9510 td->ncols_visible = ncols_visible;
9512 WidgetSetUserData(view, td);
9514 view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
9515 view->setEditTriggers(QAbstractItemView::NoEditTriggers);
9516 view->setSelectionMode(QAbstractItemView::NoSelection);
9518 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
9519 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
9521 QLayout *layout = parent->layout();
9522 if (layout != 0) {
9523 layout->addWidget(view);
9526 return view;
9529 void TableSSDInit(Widget w)
9531 QTableView *view = (QTableView*) w;
9533 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
9534 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
9537 void TableFontInit(Widget w)
9539 QTableView *view = (QTableView*) w;
9541 view->verticalHeader()->hide();
9542 view->horizontalHeader()->hide();
9543 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
9544 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
9547 void TableDataSetPropInit(Widget w)
9549 QTableView *view = (QTableView*) w;
9551 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
9552 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
9555 void TableLevalInit(Widget w)
9557 QTableView *view = (QTableView*) w;
9559 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
9560 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
9562 view->horizontalHeader()->hide();
9565 int TableGetNrows(Widget w)
9567 QTableView *view = (QTableView*) w;
9568 TableModel *model = (TableModel *) view->model();
9569 int nr;
9571 nr = model->rowCount();
9573 return nr;
9576 int TableGetNcols(Widget w)
9578 QTableView *view = (QTableView*) w;
9579 TableModel *model = (TableModel *) view->model();
9580 int nc;
9582 nc = model->columnCount();
9584 return nc;
9587 void TableAddRows(Widget w, int nrows)
9589 QTableView *view = (QTableView*) w;
9590 TableModel *model = (TableModel *) view->model();
9591 int rc;
9593 rc = TableGetNrows(w);
9595 model->setRowCount(rc + nrows);
9598 void TableDeleteRows(Widget w, int nrows)
9600 QTableView *view = (QTableView*) w;
9601 TableModel *model = (TableModel *) view->model();
9602 int rc;
9604 rc = TableGetNrows(w);
9606 model->setRowCount(rc - nrows);
9609 void TableAddCols(Widget w, int ncols)
9611 TableView *view = (TableView*) w;
9612 TableModel *model = (TableModel *) view->model();
9613 TableData *td;
9614 int cc;
9616 cc = TableGetNcols(w);
9618 model->setColumnCount(cc + ncols);
9620 td = (TableData*) WidgetGetUserData(w);
9621 TableSetDefaultColWidth(w, td->default_col_width);
9624 void TableDeleteCols(Widget w, int ncols)
9626 TableView *view = (TableView*) w;
9627 TableModel *model = (TableModel *) view->model();
9628 int cc;
9630 cc = TableGetNcols(w);
9632 model->setColumnCount(cc - ncols);
9635 void TableGetCellDimentions(Widget w, int *cwidth, int *cheight)
9637 QTableView *view = (QTableView*) w;
9639 *cwidth = view->columnWidth(0);
9640 printf("cell width %d\n", *cwidth);
9641 *cheight = view->rowHeight(0);
9642 printf("cell height %d\n", *cheight);
9645 void TableSetColWidths(Widget w, int *widths)
9647 QTableView *view = (QTableView*) w;
9648 TableData *td;
9649 int i, cc = TableGetNcols(w);
9650 QHeaderView *hHeader = view->horizontalHeader();
9652 td = (TableData*) WidgetGetUserData(w);
9654 for (i = 0; i < cc; i++) {
9655 hHeader->resizeSection(i, widths[i] * td->font_width + 2*td->frame_width);
9659 void TableSetDefaultRowLabelWidth(Widget w, int width)
9661 QTableView *view = (QTableView*) w;
9662 QHeaderView *vHeader = view->verticalHeader();
9663 TableData *td = (TableData*) WidgetGetUserData(w);
9665 vHeader->setFixedWidth(width * td->font_width + 2*td->frame_width);
9668 void TableSetDefaultRowLabelAlignment(Widget w, int align)
9670 QTableView *view = (QTableView*) w;
9671 TableModel *model = (TableModel *) view->model();
9673 switch (align) {
9674 case ALIGN_BEGINNING:
9675 model->setDefaultRowLabelAlignment(Qt::AlignLeft);
9676 break;
9677 case ALIGN_CENTER:
9678 model->setDefaultRowLabelAlignment(Qt::AlignHCenter);
9679 break;
9680 case ALIGN_END:
9681 model->setDefaultRowLabelAlignment(Qt::AlignRight);
9682 break;
9686 void TableSetDefaultColWidth(Widget w, int width)
9688 QTableView *view = (QTableView*) w;
9689 TableData *td;
9690 int i, cc = TableGetNcols(w);
9691 QHeaderView *hHeader = view->horizontalHeader();
9693 td = (TableData*) WidgetGetUserData(w);
9695 td->default_col_width = width;
9697 for (i = 0; i < cc; i++) {
9698 hHeader->resizeSection(i, td->default_col_width * td->font_width + 2*td->frame_width);
9702 void TableSetDefaultColAlignment(Widget w, int align)
9704 QTableView *view = (QTableView*) w;
9705 TableModel *model = (TableModel *) view->model();
9707 switch (align) {
9708 case ALIGN_BEGINNING:
9709 model->setDefaultColumnAlignment(Qt::AlignLeft);
9710 break;
9711 case ALIGN_CENTER:
9712 model->setDefaultColumnAlignment(Qt::AlignHCenter);
9713 break;
9714 case ALIGN_END:
9715 model->setDefaultColumnAlignment(Qt::AlignRight);
9716 break;
9720 void TableSetDefaultColLabelAlignment(Widget w, int align)
9722 QTableView *view = (QTableView*) w;
9723 TableModel *model = (TableModel *) view->model();
9725 switch (align) {
9726 case ALIGN_BEGINNING:
9727 model->setDefaultColumnLabelAlignment(Qt::AlignLeft);
9728 break;
9729 case ALIGN_CENTER:
9730 model->setDefaultColumnLabelAlignment(Qt::AlignHCenter);
9731 break;
9732 case ALIGN_END:
9733 model->setDefaultColumnLabelAlignment(Qt::AlignRight);
9734 break;
9738 void TableSetColMaxlengths(Widget w, int *maxlengths)
9740 TableView *view = (TableView*) w;
9742 view->setEditorMaxLengths(maxlengths);
9745 void TableSetRowLabels(Widget w, char **labels)
9747 QTableView *view = (QTableView*) w;
9748 TableModel *model = (TableModel *) view->model();
9750 model->setRowLabels(labels);
9753 void TableSetColLabels(Widget w, char **labels)
9755 QTableView *view = (QTableView*) w;
9756 TableModel *model = (TableModel *) view->model();
9758 model->setColumnLabels(labels);
9761 void TableSetFixedCols(Widget w, int nfixed_cols)
9763 QTableWidget *tableWidget = (QTableWidget*) w;
9764 //TODO:
9765 //Two views side by side
9768 void TableUpdateVisibleRowsCols(Widget w)
9770 TableData *td;
9771 int height = 0;
9772 int width = 0;
9773 QTableView *view = (QTableView*) w;
9774 QHeaderView *hHeader = view->horizontalHeader();
9775 QHeaderView *vHeader = view->verticalHeader();
9777 td = (TableData*) WidgetGetUserData(w);
9779 if (!hHeader->isHidden()) {
9780 height = qMax(hHeader->minimumHeight(), hHeader->sizeHint().height());
9781 height = qMin(height, hHeader->maximumHeight());
9783 for (int i = 0; i < td->nrows_visible; i++) {
9784 height += view->rowHeight(i);
9786 height += view->contentsMargins().top();
9787 height += view->contentsMargins().bottom();
9788 if (view->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOn)
9789 height += view->horizontalScrollBar()->sizeHint().height();
9790 view->setFixedHeight(height);
9792 if (!vHeader->isHidden()) {
9793 width = qMax(vHeader->minimumWidth(), vHeader->sizeHint().width());
9794 width = qMin(width, vHeader->maximumWidth());
9796 for (int i = 0; i < td->ncols_visible; i++) {
9797 width += view->columnWidth(i);
9799 width += view->contentsMargins().left();
9800 width += view->contentsMargins().right();
9801 if (view->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOn)
9802 width += view->verticalScrollBar()->sizeHint().width();
9803 view->setFixedWidth(width);
9806 void TableCommitEdit(Widget w, int close)
9808 TableView *view = (TableView*) w;
9810 view->commitEdit();
9811 if (close) {
9812 view->closeEditor();
9816 void TableSetCells(Widget w, char ***cells)
9818 QTableView *view = (QTableView*) w;
9819 TableModel *model = (TableModel *) view->model();
9820 int ncols = TableGetNcols(w);
9821 int nrows = TableGetNrows(w);
9823 for (int row = 0; row < nrows; row++) {
9824 for (int col = 0; col < ncols; col++) {
9825 model->cells[row][col] = copy_string(model->cells[row][col], cells[row][col]);
9828 TableUpdate(w);
9831 void TableSetCell(Widget w, int row, int col, char *value)
9833 QTableView *view = (QTableView*) w;
9834 TableModel *model = (TableModel *) view->model();
9836 qDebug() << "TableSetCell" << "row" << row << "col" << col << "value" << value;
9838 model->cells[row][col] = copy_string(model->cells[row][col], value);
9841 char *TableGetCell(Widget w, int row, int col)
9843 QTableView *view = (QTableView*) w;
9844 TableModel *model = (TableModel *) view->model();
9846 char *value = model->cells.value(row).value(col);
9847 qDebug() << "TableGetCell:value" << value;
9849 return value;
9852 void TableSelectCell(Widget w, int row, int col)
9854 QTableView *view = (QTableView*) w;
9855 QModelIndex index = view->model()->index(row, col);
9856 view->selectionModel()->select(index, QItemSelectionModel::Select);
9859 void TableDeselectCell(Widget w, int row, int col)
9861 QTableView *view = (QTableView*) w;
9862 QModelIndex index = view->model()->index(row, col);
9863 view->selectionModel()->select(index, QItemSelectionModel::Deselect);
9866 void TableSelectRow(Widget w, int row)
9868 QTableView *view = (QTableView*) w;
9869 TableModel *model = (TableModel *) view->model();
9871 QModelIndex topLeft = view->model()->index(row, 0);
9872 QModelIndex bottomRight = view->model()->index(row, model->columnCount()-1);
9874 view->selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Select);
9877 void TableDeselectRow(Widget w, int row)
9879 QTableView *view = (QTableView*) w;
9880 TableModel *model = (TableModel *) view->model();
9882 QModelIndex topLeft = view->model()->index(row, 0);
9883 QModelIndex bottomRight = view->model()->index(row, model->columnCount()-1);
9885 view->selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Deselect);
9888 void TableSelectCol(Widget w, int col)
9890 QTableView *view = (QTableView*) w;
9891 TableModel *model = (TableModel *) view->model();
9893 QModelIndex topLeft = view->model()->index(0, col);
9894 QModelIndex bottomRight = view->model()->index(model->rowCount()-1, col);
9896 view->selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Select);
9899 void TableDeselectCol(Widget w, int col)
9901 QTableView *view = (QTableView*) w;
9902 TableModel *model = (TableModel *) view->model();
9904 QModelIndex topLeft = view->model()->index(0, col);
9905 QModelIndex bottomRight = view->model()->index(model->rowCount()-1, col);
9907 view->selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Deselect);
9910 void TableDeselectAllCells(Widget w)
9912 QTableView *view = (QTableView*) w;
9914 view->clearSelection();
9917 int TableIsRowSelected(Widget w, int row)
9919 QTableView *view = (QTableView*) w;
9921 return view->selectionModel()->isRowSelected(row, QModelIndex());
9924 int TableIsColSelected(Widget w, int col)
9926 QTableView *view = (QTableView*) w;
9928 return view->selectionModel()->isColumnSelected(col, QModelIndex());
9931 void TableUpdate(Widget w)
9933 QTableView *view = (QTableView*) w;
9935 view->reset();
9938 void AddTableDrawCellCB(Widget w, Table_CBProc cbproc, void *anydata)
9940 QTableView *view = (QTableView*) w;
9941 TableModel *model = (TableModel *) view->model();
9943 Table_CBData *cbdata;
9945 cbdata = (Table_CBData *) xmalloc(sizeof(Table_CBData));
9946 cbdata->w = w;
9947 cbdata->cbproc = cbproc;
9948 cbdata->anydata = anydata;
9950 model->setDrawCellCallback(cbdata);
9953 void AddTableEnterCellCB(Widget w, Table_CBProc cbproc, void *anydata)
9955 Table_CBData *cbdata;
9957 cbdata = (Table_CBData *) xmalloc(sizeof(Table_CBData));
9958 cbdata->w = w;
9959 cbdata->cbproc = cbproc;
9960 cbdata->anydata = anydata;
9962 TableView *view = (TableView*) cbdata->w;
9963 view->setEnterCellCallback(cbdata);
9967 void AddTableLeaveCellCB(Widget w, Table_CBProc cbproc, void *anydata)
9969 Table_CBData *cbdata;
9971 cbdata = (Table_CBData *) xmalloc(sizeof(Table_CBData));
9972 cbdata->w = w;
9973 cbdata->cbproc = cbproc;
9974 cbdata->anydata = anydata;
9976 TableView *view = (TableView*) cbdata->w;
9977 view->setLeaveCellCallback(cbdata);
9980 bool HeaderView::event(QEvent *e)
9982 if (cbdata != 0) {
9983 QMouseEvent *xbe;
9985 TableEvent event;
9986 event.button = NO_BUTTON;
9987 event.modifiers = NO_MODIFIER;
9988 event.anydata = cbdata->anydata;
9990 event.w = cbdata->w;
9992 switch (e->type()) {
9993 case QEvent::MouseButtonDblClick:
9994 case QEvent::MouseButtonPress:
9995 event.type = MOUSE_PRESS;
9996 qDebug("HeaderView mouse press");
9997 break;
9998 default:
9999 return QAbstractItemView::event(e);
10002 xbe = (QMouseEvent*) e;
10003 QPoint point = xbe->globalPos();
10004 event.udata = &point;
10005 switch (xbe->button()) {
10006 case Qt::LeftButton:
10007 event.button = event.button ^ LEFT_BUTTON;
10008 break;
10009 case Qt::RightButton:
10010 event.button = event.button ^ RIGHT_BUTTON;
10011 break;
10013 if (xbe->modifiers() & Qt::ControlModifier) {
10014 event.modifiers = event.modifiers ^ CONTROL_MODIFIER;
10016 if (xbe->modifiers() & Qt::ShiftModifier) {
10017 event.modifiers = event.modifiers ^ SHIFT_MODIFIER;
10020 int pos = orientation() == Qt::Horizontal ? xbe->x() : xbe->y();
10021 int section = logicalIndexAt(pos);
10022 event.row = section;
10023 event.col = section;
10024 event.row_label = (orientation() == Qt::Vertical);
10026 cbdata->cbproc(&event);
10028 return true;
10029 } else {
10030 return QHeaderView::event(e);
10034 void AddTableLabelActivateCB(Widget w, Table_CBProc cbproc, void *anydata)
10036 Table_CBData *cbdata;
10038 cbdata = (Table_CBData *) xmalloc(sizeof(Table_CBData));
10039 cbdata->w = w;
10040 cbdata->cbproc = cbproc;
10041 cbdata->anydata = anydata;
10043 QTableView *view = (QTableView*) cbdata->w;
10044 HeaderView *hHeader = (HeaderView*) view->horizontalHeader();
10045 hHeader->setCallBackData(cbdata);
10046 HeaderView *vHeader = (HeaderView*) view->verticalHeader();
10047 vHeader->setCallBackData(cbdata);
10050 /* ScrollBar */
10051 void GetScrollBarValues(Widget w, int *value, int *maxvalue, int *slider_size, int *increment)
10053 QScrollBar *scrollBar = (QScrollBar*) w;
10055 // TODO: fix "+ 10" and "if max is 0 in case of axis_ui on the firt run"
10056 if (value) *value = scrollBar->value();
10057 if (maxvalue) *maxvalue = scrollBar->maximum() + 10;
10058 if (slider_size) *slider_size = 10;
10059 if (increment) *increment = scrollBar->singleStep();
10062 void SetScrollBarValue(Widget w, int value)
10064 QScrollBar *scrollBar = (QScrollBar*) w;
10066 scrollBar->setValue(value);
10069 void SetScrollBarIncrement(Widget w, int increment)
10071 QScrollBar *scrollBar = (QScrollBar*) w;
10073 scrollBar->setSingleStep(increment);
10076 Widget GetHorizontalScrollBar(Widget w)
10078 QScrollArea *scrollArea;
10080 if (!(scrollArea = qobject_cast<QScrollArea *>(w))) {
10081 scrollArea = qobject_cast<QScrollArea *>(w->parent()->parent());
10084 return scrollArea->horizontalScrollBar();
10087 Widget GetVerticalScrollBar(Widget w)
10089 QScrollArea *scrollArea;
10091 if (!(scrollArea = qobject_cast<QScrollArea *>(w))) {
10092 scrollArea = qobject_cast<QScrollArea *>(w->parent()->parent());
10095 return scrollArea->verticalScrollBar();
10098 void WidgetSetFocus(Widget w)
10100 w->setFocus();