2 * Grace - GRaphing, Advanced Computation and Exploration of data
4 * Home page: http://plasma-gate.weizmann.ac.il/Grace/
6 * Copyright (c) 1991-1995 Paul J Turner, Portland, OR
7 * Copyright (c) 1996-2010 Grace Development Team
9 * Maintained by Evgeny Stambulchik
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.
35 #define CANVAS_BACKEND_API
39 #include <QApplication>
40 #include <QMainWindow>
42 #include <QGridLayout>
43 #include <QScrollArea>
47 #include <QWidgetAction>
50 #include <QAbstractButton>
51 #include <QMessageBox>
55 #include <QPushButton>
56 #include <QSignalMapper>
59 #include <QDoubleSpinBox>
61 #include <QPlainTextEdit>
63 #include <QListWidget>
65 #include <QTableWidget>
66 #include <QStandardItemModel>
71 #include <mainwindow.h>
72 #include <canvaswidget.h>
73 #include <fileselectiondialog.h>
88 //#define canvas grace_get_canvas(gapp->grace)
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();
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,
134 // xstuff->canvas = XtVaCreateManagedWidget("canvas",
135 // xmDrawingAreaWidgetClass,
136 // mwui->drawing_window,
139 // xstuff->canvas = XtVaCreateManagedWidget("canvas",
140 // xmDrawingAreaWidgetClass, form,
142 // mwui->drawing_window = xstuff->canvas;
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"
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"
161 QMenuBar
*menuBar
= (QMenuBar
*) CreateMainMenuBar(mainWin
);
162 mainWin
->setMenuBar(menuBar
);
164 CreateToolBar(mainWin
->ui
.toolBar
);
166 * initialize some option menus
171 * initialize the tool bars
175 set_tracker_string(NULL
);
176 // set_left_footer(NULL);
181 mainWin
->setWindowIcon(QPixmap(gapp_icon_xpm
));
183 gapp
->gui
->inwin
= TRUE
;
188 // update_app_title(gapp->gp);
190 xdrawgraph(gapp
->gp
);
193 //XtAppMainLoop(app_con);
195 qDebug("startup_gui end");
200 int initialize_gui(int *argc
, char **argv
)
202 qDebug("initialize_gui start");
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");
251 encoding
= copy_string(encoding
, "ISO 8859-1");
253 QTextCodec::setCodecForCStrings(QTextCodec::codecForName(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];
273 // xstuff->disp = XOpenDisplay(display_name);
274 // if (xstuff->disp == NULL) {
275 // errmsg("Can't open display");
276 // return RETURN_FAILURE;
279 // screen = DefaultScreenOfDisplay(xstuff->disp);
280 // if (HeightOfScreen(screen) < 740) {
284 // n_common = sizeof(fallbackResourcesCommon)/sizeof(String) - 1;
286 // n_resol = sizeof(fallbackResourcesLowRes)/sizeof(String) - 1;
287 // resolResources = fallbackResourcesLowRes;
289 // n_resol = sizeof(fallbackResourcesHighRes)/sizeof(String) - 1;
290 // resolResources = fallbackResourcesHighRes;
292 // allResources = xmalloc((n_common + n_resol + 1)*sizeof(String));
293 // for (i = 0; i < n_common; i++) {
294 // allResources[i] = fallbackResourcesCommon[i];
296 // for (i = 0; i < n_resol; i++) {
297 // allResources[n_common + i] = resolResources[i];
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;
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
;
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
;
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;
363 // if (gapp->gui->invert) {
364 // gc_val.function = GXinvert;
366 // gc_val.function = GXxor;
368 // gcxor = XCreateGC(xstuff->disp, xstuff->root, GCFunction, &gc_val);
370 // /* XExtendedMaxRequestSize() appeared in X11R6 */
371 //#if XlibSpecificationRelease > 5
372 // mrsize = XExtendedMaxRequestSize(xstuff->disp);
376 // if (mrsize <= 0) {
377 // mrsize = XMaxRequestSize(xstuff->disp);
379 // max_path_limit = (mrsize - 3)/2;
380 // if (max_path_limit < get_max_path_limit(grace_get_canvas(gapp->grace))) {
383 // "Setting max drawing path length to %d (limited by the X server)",
386 // set_max_path_limit(grace_get_canvas(gapp->grace), max_path_limit);
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
;
399 int x11_get_pixelsize(const GUI
*gui
)
401 // Screen *screen = DefaultScreenOfDisplay(gui->xstuff->disp);
403 // XPixmapFormatValues *pmf;
404 // int pixel_size = 0;
406 // pmf = XListPixmapFormats(DisplayOfScreen(screen), &n);
408 // for (i = 0; i < n; i++) {
409 // if (pmf[i].depth == PlanesOfScreen(screen)) {
410 // pixel_size = pmf[i].bits_per_pixel/8;
414 // XFree((char *) pmf);
417 // return pixel_size;
422 void xunregister_rti(const Input_buffer
*ib
)
427 void xregister_rti(Input_buffer
*ib
)
431 void QtAddCallback(const QObject
*sender
,
433 void (*callback
)(Widget
, XtPointer
, XtPointer
),
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);
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);
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);
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
;
524 void xdrawgrid(X11Stuff
*xstuff
)
530 double w
= canvasWidget
->width();
531 double h
= canvasWidget
->height();
533 QImage
*pixmap
= (QImage
*) xstuff
->bufpixmap
;
535 QPainter
painter(pixmap
);
538 pen
.setColor(Qt::black
);
540 pen
.setStyle(Qt::SolidLine
);
541 pen
.setCapStyle(Qt::FlatCap
);
542 pen
.setJoinStyle(Qt::MiterJoin
);
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
++) {
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);
573 void move_pointer(short x
, short y
)
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);
591 void set_cursor(GUI
*gui
, int c
)
593 X11Stuff
*xstuff
= gui
->xstuff
;
595 if (xstuff
->cur_cursor
== c
) {
599 // XUndefineCursor(xstuff->disp, xstuff->xwin);
600 canvasWidget
->unsetCursor();
601 xstuff
->cur_cursor
= c
;
604 canvasWidget
->setCursor(Qt::CrossCursor
);
605 //XDefineCursor(xstuff->disp, xstuff->xwin, xstuff->line_cursor);
609 canvasWidget
->setCursor(Qt::CrossCursor
);
610 // XDefineCursor(xstuff->disp, xstuff->xwin, xstuff->find_cursor);
613 canvasWidget
->setCursor(Qt::IBeamCursor
);
614 // XDefineCursor(xstuff->disp, xstuff->xwin, xstuff->text_cursor);
618 canvasWidget
->setCursor(Qt::CrossCursor
);
619 // XDefineCursor(xstuff->disp, xstuff->xwin, xstuff->kill_cursor);
622 canvasWidget
->setCursor(Qt::SizeAllCursor
);
623 // XDefineCursor(xstuff->disp, xstuff->xwin, xstuff->move_cursor);
626 canvasWidget
->setCursor(Qt::PointingHandCursor
);
627 // XDefineCursor(xstuff->disp, xstuff->xwin, xstuff->drag_cursor);
630 xstuff
->cur_cursor
= -1;
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
);
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
);
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
);
681 ToggleButtonSetState(mwui
->windowbarw
[0], FALSE
);
682 WidgetUnmanage(mwui
->frtop
);
686 //Widget CreateScrolledWindow(Widget parent)
688 // return XtVaCreateManagedWidget("ui->sw",
689 // xmScrolledWindowWidgetClass, parent,
691 // XmNscrollingPolicy, XmAUTOMATIC,
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();
714 layout
->addWidget(scrollArea
);
720 Widget
CreatePanedWindow(Widget parent
)
722 QSplitter
*splitter
= new QSplitter(parent
);
723 splitter
->setChildrenCollapsible(false);
725 QLayout
*layout
= parent
->layout();
727 layout
->addWidget(splitter
);
740 //#include <config.h>
742 //#include <stdlib.h>
744 //#include <stdarg.h>
747 //#include <X11/Xatom.h>
748 //#include <X11/cursorfont.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>
774 //#if XmVersion < 2000
775 //# define XmStringConcatAndFree(a, b) XmStringConcat(a, b); XmStringFree(a); XmStringFree(b)
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"
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);
814 // if (isalnum(*s)) {
815 // if (capitalize == TRUE) {
816 // *rs = toupper(*s);
817 // capitalize = FALSE;
819 // *rs = tolower(*s);
823 // capitalize = TRUE;
828 // if (suffix != NULL) {
829 // retval = concat_strings(retval, suffix);
837 // XBell(xstuff->disp, 50);
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
;
857 //void ManageChild(Widget w)
861 void WidgetManage(Widget w
)
863 if (QAction
*action
= qobject_cast
<QAction
*>(w
)) {
864 action
->setVisible(true);
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);
883 //int IsManaged(Widget w)
885 // return (XtIsManaged(w) == True) ? TRUE:FALSE;
887 int WidgetIsManaged(Widget w
)
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);
901 w
->setEnabled(onoff
? true : false);
905 //Widget GetParent(Widget w)
908 // return (XtParent(w));
910 // errmsg("Internal error: GetParent() called with NULL widget");
914 Widget
GetParent(Widget w
)
917 //return (XtParent(w));
920 errmsg("Internal error: GetParent() called with NULL widget");
925 //void RegisterEditRes(Widget shell)
927 //#ifdef WITH_EDITRES
928 // XtAddEventHandler(shell, (EventMask) 0, True, _XEditResCheckMessages, NULL);
932 void WidgetSetHeight(Widget w
, unsigned int height
)
934 if (QScrollArea
*scrollArea
= qobject_cast
<QScrollArea
*>(w
->parent()->parent())) {
935 scrollArea
->setMinimumHeight(height
);
937 w
->resize(w
->size().width(), height
);
941 //void SetDimensions(Widget w, unsigned int width, unsigned int height)
944 // XmNwidth, (Dimension) width,
945 // XmNheight, (Dimension) height,
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)
962 // *width = (unsigned int) ww;
963 // *height = (unsigned int) wh;
965 void WidgetGetSize(Widget w
, unsigned int *width
, unsigned int *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);
988 void *WidgetGetUserData(Widget w
)
991 udata
= w
->userData(0);
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)
1013 // OptionStructure *retval;
1015 // retval = xcalloc(1, sizeof(OptionStructure));
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);
1039 OptionStructure
*CreateOptionChoice(Widget parent
, char *labelstr
,
1040 int ncols
, int nchoices
, OptionItem
*items
)
1042 OptionStructure
*retval
;
1044 retval
= (OptionStructure
*) xcalloc(1, sizeof(OptionStructure
));
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();
1078 layout
->addWidget(widget
);
1084 //OptionStructure *CreateOptionChoiceVA(Widget parent, char *labelstr, ...)
1086 // OptionStructure *retval;
1087 // int nchoices = 0;
1088 // OptionItem *oi = NULL;
1093 // va_start(var, labelstr);
1094 // while ((s = va_arg(var, char *)) != NULL) {
1095 // value = va_arg(var, int);
1097 // oi = xrealloc(oi, nchoices*sizeof(OptionItem));
1098 // oi[nchoices - 1].value = value;
1099 // oi[nchoices - 1].label = copy_string(NULL, s);
1103 // retval = CreateOptionChoice(parent, labelstr, 1, nchoices, oi);
1105 // while (nchoices) {
1107 // xfree(oi[nchoices].label);
1113 OptionStructure
*CreateOptionChoiceVA(Widget parent
, char *labelstr
, ...)
1115 OptionStructure
*retval
;
1117 OptionItem
*oi
= NULL
;
1122 va_start(var
, labelstr
);
1123 while ((s
= va_arg(var
, char *)) != NULL
) {
1124 value
= va_arg(var
, int);
1126 oi
= (OptionItem
*) xrealloc(oi
, nchoices
*sizeof(OptionItem
));
1127 oi
[nchoices
- 1].value
= value
;
1128 oi
[nchoices
- 1].label
= copy_string(NULL
, s
);
1132 retval
= CreateOptionChoice(parent
, labelstr
, 1, nchoices
, oi
);
1136 xfree(oi
[nchoices
].label
);
1143 static void oc_int_cb_proc(Widget w
, XtPointer client_data
, XtPointer call_data
)
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;
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;
1168 // for (i = 0; i < opt->nchoices; i++) {
1169 // XtAddCallback(opt->options[i].widget, XmNactivateCallback,
1170 // oc_int_cb_proc, (XtPointer) cbdata);
1173 void AddOptionChoiceCB(OptionStructure
*opt
, OC_CBProc cbproc
, void *anydata
)
1177 cbdata
= (OC_CBdata
*) xmalloc(sizeof(OC_CBdata
));
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
;
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;
1196 // nold = optp->nchoices;
1198 // if (optp->ncols == 0) {
1201 // ncols = optp->ncols;
1204 // /* Don't create too tall pulldowns */
1205 // if (nchoices > MAX_PULLDOWN_LENGTH*ncols) {
1206 // ncols = (nchoices + MAX_PULLDOWN_LENGTH - 1)/MAX_PULLDOWN_LENGTH;
1209 // XtVaSetValues(optp->pulldown, XmNnumColumns, ncols, NULL);
1211 // nw = nold - nchoices;
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;
1218 // XtUnmanageChildren(wlist, nw);
1221 // for (i = nchoices; i < nold; i++) {
1222 // XtDestroyWidget(optp->options[i].widget);
1226 // optp->options = xrealloc(optp->options, nchoices*sizeof(OptionWidgetItem));
1227 // optp->nchoices = nchoices;
1229 // for (i = nold; i < nchoices; i++) {
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);
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);
1249 // XmStringFree(str);
1253 // nw = nchoices - nold;
1255 // wlist = xmalloc(nw*sizeof(Widget));
1256 // for (i = nold; i < nchoices; i++) {
1257 // wlist[i - nold] = optp->options[i].widget;
1259 // XtManageChildren(wlist, nw);
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) {
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
;
1285 for (i
= nchoices
; i
< nold
; i
++) {
1287 // delete optp->options[i].widget;
1291 optp
->options
= (OptionWidgetItem
*) xrealloc(optp
->options
, nchoices
*sizeof(OptionWidgetItem
));
1292 optp
->nchoices
= nchoices
;
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
);
1308 comboBox
->setModelColumn(0);
1309 comboBox
->setCurrentIndex(0);
1311 tableView
->resizeColumnsToContents();
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
)
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) {
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
;
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
));
1358 item
= new QStandardItem("None");
1360 item
->setData(QVariant(items
[i
].value
));
1361 model
->setItem(row
, col
, item
);
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;
1385 // OptionStructure *retval;
1389 // retval = xcalloc(1, sizeof(OptionStructure));
1393 // retval->nchoices = nchoices;
1394 // retval->options = xmalloc(nchoices*sizeof(OptionWidgetItem));
1395 // if (retval->options == NULL) {
1396 // errmsg("Malloc error in CreateBitmapOptionChoice()");
1402 // retval->pulldown = XmCreatePulldownMenu(parent, "pulldownMenu", NULL, 0);
1403 // XtVaSetValues(retval->pulldown,
1404 // XmNentryAlignment, XmALIGNMENT_CENTER,
1408 // XtVaSetValues(retval->pulldown,
1409 // XmNpacking, XmPACK_COLUMN,
1410 // XmNnumColumns, ncols,
1414 // XtVaGetValues(retval->pulldown,
1415 // XmNforeground, &fg,
1416 // XmNbackground, &bg,
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,
1432 // retval->options[i].widget =
1433 // XmCreatePushButton(retval->pulldown, "None", NULL, 0);
1437 // for (i = 0; i < nchoices; i++) {
1438 // XtManageChild(retval->options[i].widget);
1441 // retval->menu = XmCreateOptionMenu(parent, "optionMenu", NULL, 0);
1442 // str = XmStringCreateLocalized(labelstr);
1443 // XtVaSetValues(retval->menu,
1444 // XmNlabelString, str,
1445 // XmNsubMenuId, retval->pulldown,
1447 // XmStringFree(str);
1448 // XtManageChild(retval->menu);
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
));
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();
1494 layout
->addWidget(widget
);
1500 //void UpdateCharOptionChoice(OptionStructure *opt, int 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);
1512 // *old_font = font;
1515 void UpdateCharOptionChoice(OptionStructure
*opt
, int font
)
1518 old_font
= (int *) WidgetGetUserData(opt
->menu
);
1519 if (*old_font
!= font
) {
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
);
1525 item
->setIcon(QIcon(*pixmap
));
1527 item
->setEnabled(pixmap
? true:false);
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;
1542 // int ncols = 16, nchoices = 256;
1544 // OptionStructure *retval;
1549 // retval = xcalloc(1, sizeof(OptionStructure));
1550 // if (retval == NULL) {
1551 // errmsg("Malloc error in CreateBitmapOptionChoice()");
1553 // retval->nchoices = nchoices;
1554 // retval->options = xmalloc(nchoices*sizeof(OptionWidgetItem));
1555 // if (retval->options == NULL) {
1556 // errmsg("Malloc error in CreateBitmapOptionChoice()");
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,
1569 // XtVaGetValues(retval->pulldown,
1570 // XmNforeground, &fg,
1571 // XmNbackground, &bg,
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,
1585 // for (i = 0; i < nchoices; i++) {
1586 // XtManageChild(retval->options[i].widget);
1589 // retval->menu = XmCreateOptionMenu(parent, "optionMenu", NULL, 0);
1590 // str = XmStringCreateLocalized(s);
1591 // XtVaSetValues(retval->menu,
1592 // XmNlabelString, str,
1593 // XmNsubMenuId, retval->pulldown,
1595 // XmStringFree(str);
1596 // XtManageChild(retval->menu);
1598 // fontid = xmalloc(SIZEOF_INT);
1600 // SetUserData(retval->menu, fontid);
1604 OptionStructure
*CreateCharOptionChoice(Widget parent
, char *s
)
1606 int ncols
= 16, nchoices
= 256;
1607 OptionStructure
*retval
;
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()");
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
;
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
;
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
);
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();
1678 layout
->addWidget(widget
);
1681 fontid
= (int *) xmalloc(SIZEOF_INT
);
1683 WidgetSetUserData(retval
->menu
, fontid
);
1688 //void SetOptionChoice(OptionStructure *opt, int value)
1693 // if (opt->options == NULL || opt->nchoices <= 0) {
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);
1705 // errmsg("Value not found in SetOptionChoice()");
1707 void SetOptionChoice(OptionStructure
*opt
, int value
)
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) {
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
);
1741 errmsg("Value not found in SetOptionChoice()");
1744 //int GetOptionChoice(OptionStructure *opt)
1750 // if (opt->options == NULL || opt->nchoices <= 0) {
1751 // errmsg("Internal error in GetOptionChoice()");
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);
1763 // errmsg("Internal error in GetOptionChoice()");
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);
1782 errmsg("Internal error in GetOptionChoice()");
1787 // SpinStructure *spin;
1788 // Spin_CBProc cbproc;
1790 // XtIntervalId timeout_id;
1793 SpinStructure
*spin
;
1800 // Scale_CBProc cbproc;
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;
1835 // unsigned char selection_type_save;
1837 // XtVaGetValues(list,
1838 // XmNselectionPolicy, &selection_type_save,
1839 // XmNitemCount, &n,
1841 // if (selection_type_save == XmSINGLE_SELECT) {
1842 // XBell(xstuff->disp, 50);
1846 // XtVaSetValues(list, XmNselectionPolicy, XmMULTIPLE_SELECT, NULL);
1847 // for (i = 0; i < n; i++) {
1848 // XmListSelectPos(list, i, False);
1850 // XtVaSetValues(list, XmNselectionPolicy, selection_type_save, NULL);
1852 static void list_invertselection(Widget list
)
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();
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)
1879 //#if XmVersion < 2000
1881 // if (XmListGetSelectedPos(list, &selected, &n) != True) {
1887 // XtVaGetValues(list, XmNselectedPositionCount, &n, NULL);
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,
1916 // list_invertselection(w);
1919 //ListStructure *CreateListChoice(Widget parent, char *labelstr, int type,
1920 // int nvisible, int nchoices, OptionItem *items)
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);
1938 // XtSetArg(args[2], XmNselectionPolicy, XmEXTENDED_SELECT);
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);
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
);
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();
2002 layout
->addWidget(widget
);
2008 //void UpdateListChoice(ListStructure *listp, int nchoices, OptionItem *items)
2014 // if (listp == NULL) {
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;
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);
2032 // SelectListChoices(listp, nsel, selvalues);
2034 // xfree(selvalues);
2037 void UpdateListChoice(ListStructure
*listp
, int nchoices
, OptionItem
*items
)
2042 if (listp
== NULL
) {
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
);
2068 //int SelectListChoice(ListStructure *listp, int choice)
2070 // int top, visible;
2073 // while (i < listp->nchoices && listp->values[i] != choice) {
2076 // if (i < listp->nchoices) {
2078 // XmListDeselectAllItems(listp->list);
2079 // XmListSelectPos(listp->list, i, True);
2080 // XtVaGetValues(listp->list, XmNtopItemPosition, &top,
2081 // XmNvisibleItemCount, &visible,
2084 // XmListSetPos(listp->list, i);
2085 // } else if (i >= top + visible) {
2086 // XmListSetBottomPos(listp->list, i);
2089 // return RETURN_SUCCESS;
2091 // return RETURN_FAILURE;
2094 int SelectListChoice(ListStructure
*listp
, int choice
)
2098 QListWidgetItem
*item
;
2100 QListWidget
*listWidget
= (QListWidget
*) listp
->list
;
2102 while (i
< listp
->nchoices
&& listp
->values
[i
] != choice
) {
2105 if (i
< listp
->nchoices
) {
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,
2117 // XmListSetPos(listp->list, i);
2118 // } else if (i >= top + visible) {
2119 // XmListSetBottomPos(listp->list, i);
2122 return RETURN_SUCCESS
;
2124 return RETURN_FAILURE
;
2128 //void SelectListChoices(ListStructure *listp, int nchoices, int *choices)
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++) {
2140 // while (i < listp->nchoices && listp->values[i] != choices[j]) {
2143 // if (i < listp->nchoices) {
2145 // XmListSelectPos(listp->list, i, True);
2149 // if (nchoices > 0) {
2150 // /* Rewind list so the last choice is always visible */
2151 // XtVaGetValues(listp->list, XmNtopItemPosition, &bottom,
2152 // XmNvisibleItemCount, &visible,
2154 // if (i > bottom) {
2155 // XmListSetBottomPos(listp->list, i);
2156 // } else if (i <= bottom - visible) {
2157 // XmListSetPos(listp->list, i);
2161 // XtVaSetValues(listp->list, XmNselectionPolicy, selection_type_save, NULL);
2163 void SelectListChoices(ListStructure
*listp
, int nchoices
, int *choices
)
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
++) {
2181 while (i
< listp
->nchoices
&& listp
->values
[i
] != choices
[j
]) {
2184 if (i
< listp
->nchoices
) {
2185 item
= listWidget
->item(i
);
2186 item
->setSelected(true);
2189 //XmListSelectPos(listp->list, i, True);
2194 //if (nchoices > 0) {
2195 /* Rewind list so the last choice is always visible */
2196 //XtVaGetValues(listp->list, XmNtopItemPosition, &bottom,
2197 // XmNvisibleItemCount, &visible,
2199 // if (i > bottom) {
2200 // XmListSetBottomPos(listp->list, i);
2201 // } else if (i <= bottom - visible) {
2202 // XmListSetPos(listp->list, i);
2206 listWidget
->setSelectionMode(selection_type_save
);
2207 //XtVaSetValues(listp->list, XmNselectionPolicy, selection_type_save, NULL);
2210 //int GetListChoices(ListStructure *listp, int **values)
2214 // if (XmListGetSelectedPos(listp->list, values, &n) != True) {
2218 // for (i = 0; i < n; i++) {
2219 // (*values)[i] = listp->values[(*values)[i] - 1];
2224 int GetListChoices(ListStructure
*listp
, int **values
)
2228 QListWidget
*listWidget
= (QListWidget
*) listp
->list
;
2229 QList
<QListWidgetItem
*> list
= listWidget
->selectedItems();
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
];
2245 int GetSingleListChoice(ListStructure
*listp
, int *value
)
2247 int n
, *values
, retval
;
2249 n
= GetListChoices(listp
, &values
);
2252 retval
= RETURN_SUCCESS
;
2254 retval
= RETURN_FAILURE
;
2262 //int GetListSelectedCount(ListStructure *listp)
2265 // XtVaGetValues(listp->list, XmNselectedItemCount, &count, NULL);
2271 ListStructure
*listp
;
2276 static void list_int_cb_proc(Widget w
, XtPointer client_data
, XtPointer call_data
)
2279 List_CBdata
*cbdata
= (List_CBdata
*) client_data
;
2281 n
= GetListChoices(cbdata
->listp
, &values
);
2283 cbdata
->cbproc(cbdata
->listp
, n
, values
, cbdata
->anydata
);
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");
2338 buf
= (char *) xmalloc(strlen(QIDSTR(q
)) + 128);
2343 sprintf(buf
, "Quark \"%s\"", QIDSTR(q
));
2351 StorageStructure
*ss
;
2353 } storage_traverse_data
;
2355 //static int traverse_hook(Quark *q, void *udata, QTraverseClosure *closure)
2358 // storage_traverse_data *stdata = (storage_traverse_data *) udata;
2359 // StorageStructure *ss = stdata->ss;
2361 // s = ss->labeling_proc(q, &stdata->rid);
2363 // char buf[16], *sbuf;
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);
2374 // str = XmStringCreateLocalized(sbuf);
2377 // XmListAddItemUnselected(ss->list, str, 0);
2378 // XmStringFree(str);
2383 static int traverse_hook(Quark
*q
, void *udata
, QTraverseClosure
*closure
)
2386 storage_traverse_data
*stdata
= (storage_traverse_data
*) udata
;
2387 StorageStructure
*ss
= stdata
->ss
;
2389 s
= ss
->labeling_proc(q
, &stdata
->rid
);
2391 char buf
[16], *sbuf
;
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
);
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);
2409 //XmListAddItemUnselected(ss->list, str, 0);
2410 //XmStringFree(str);
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;
2424 // if (e->button != 3) {
2428 // /* don't post menu if governor selection isn't single */
2429 // if (ss->governor && list_get_selected_count(ss->governor->list) != 1) {
2433 // n = list_get_selected_count(ss->list);
2438 // selected = FALSE;
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);
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
;
2465 //if (e->button != 3) {
2469 /* don't post menu if governor selection isn't single */
2470 if (ss
->governor
&& list_get_selected_count(ss
->governor
->list
) != 1) {
2474 n
= list_get_selected_count(ss
->list
);
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);
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
)
2508 n
= GetStorageChoices(ss
, &values
);
2510 for (i
= 0; i
< n
; i
++) {
2514 case SS_SEND_TO_BACK_CB
:
2516 q
= values
[n
- i
- 1];
2525 quark_set_active(q
, FALSE
);
2528 quark_set_active(q
, TRUE
);
2533 case SS_BRING_TO_FRONT_CB
:
2534 quark_push(q
, TRUE
);
2536 case SS_SEND_TO_BACK_CB
:
2537 quark_push(q
, FALSE
);
2540 quark_move(q
, TRUE
);
2542 case SS_MOVE_DOWN_CB
:
2543 quark_move(q
, FALSE
);
2545 case SS_DUPLICATE_CB
:
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
;
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);
2645 // XtVaSetValues(popup, XmNpopupEnabled, False, NULL);
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
);
2698 #if XmVersion >= 2000
2699 // XtVaSetValues(popup, XmNpopupEnabled, XmPOPUP_DISABLED, NULL);
2701 // XtVaSetValues(popup, XmNpopupEnabled, False, NULL);
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)
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);
2770 // XtSetArg(args[2], XmNselectionPolicy, XmEXTENDED_SELECT);
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);
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
);
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();
2844 layout
->addWidget(widget
);
2850 void SetStorageChoiceLabeling(StorageStructure
*ss
, Storage_LabelingProc proc
)
2852 ss
->labeling_proc
= proc
;
2855 //int GetStorageSelectedCount(StorageStructure *ss)
2858 // XtVaGetValues(ss->list, XmNselectedItemCount, &count, NULL);
2862 //int GetStorageChoices(StorageStructure *ss, Quark ***values)
2867 // if (XmListGetSelectedPos(ss->list, &selected, &n) != True) {
2871 // *values = xmalloc(n*SIZEOF_VOID_P);
2872 // for (i = 0; i < n; i++) {
2873 // (*values)[i] = ss->values[selected[i] - 1];
2877 // XtFree((char *) selected);
2882 int GetStorageChoices(StorageStructure
*ss
, Quark
***values
)
2886 QListWidget
*listWidget
= (QListWidget
*) ss
->list
;
2887 QList
<QListWidgetItem
*> list
= listWidget
->selectedItems();
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
];
2904 int GetSingleStorageChoice(StorageStructure
*ss
, Quark
**value
)
2909 n
= GetStorageChoices(ss
, &values
);
2912 retval
= RETURN_SUCCESS
;
2914 retval
= RETURN_FAILURE
;
2925 //int SelectStorageChoices(StorageStructure *ss, int nchoices, Quark **choices)
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++) {
2937 // while (i < ss->nchoices && ss->values[i] != choices[j]) {
2940 // if (i < ss->nchoices) {
2942 // XmListSelectPos(ss->list, i, True);
2946 // if (nchoices > 0) {
2947 // /* Rewind list so the last choice is always visible */
2948 // XtVaGetValues(ss->list, XmNtopItemPosition, &bottom,
2949 // XmNvisibleItemCount, &visible,
2951 // if (i > bottom) {
2952 // XmListSetBottomPos(ss->list, i);
2953 // } else if (i <= bottom - visible) {
2954 // XmListSetPos(ss->list, i);
2958 // XtVaSetValues(ss->list, XmNselectionPolicy, selection_type_save, NULL);
2960 // return RETURN_SUCCESS;
2962 int SelectStorageChoices(StorageStructure
*ss
, int nchoices
, Quark
**choices
)
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
++) {
2980 while (i
< ss
->nchoices
&& ss
->values
[i
] != choices
[j
]) {
2983 if (i
< ss
->nchoices
) {
2984 item
= listWidget
->item(i
);
2985 item
->setSelected(true);
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,
2996 // if (i > bottom) {
2997 //XmListSetBottomPos(ss->list, i);
2998 // } else if (i <= bottom - visible) {
2999 //XmListSetPos(ss->list, i);
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;
3020 // nsel = GetStorageChoices(ss, &selvalues);
3022 // XmListDeleteAllItems(ss->list);
3024 // ss->nchoices = 0;
3028 // quark_traverse(ss->q, traverse_hook, &stdata);
3030 // SelectStorageChoices(ss, nsel, selvalues);
3034 // xfree(selvalues);
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);
3044 void UpdateStorageChoice(StorageStructure
*ss
)
3047 storage_traverse_data stdata
;
3050 nsel
= GetStorageChoices(ss
, &selvalues
);
3052 QListWidget
*listWidget
= (QListWidget
*) ss
->list
;
3054 listWidget
->clear();
3055 //XmListDeleteAllItems(ss->list);
3061 quark_traverse(ss
->q
, traverse_hook
, &stdata
);
3063 SelectStorageChoices(ss
, nsel
, 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);
3078 void SetStorageChoiceQuark(StorageStructure
*ss
, Quark
*q
)
3081 UpdateStorageChoice(ss
);
3086 StorageStructure
*ss
;
3087 Storage_CBProc cbproc
;
3092 StorageStructure
*ss
;
3093 Storage_DCCBProc cbproc
;
3097 static void storage_int_cb_proc(Widget w
,
3098 XtPointer client_data
, XtPointer call_data
)
3102 Storage_CBdata
*cbdata
= (Storage_CBdata
*) client_data
;
3104 n
= GetStorageChoices(cbdata
->ss
, &values
);
3106 cbdata
->cbproc(cbdata
->ss
, n
, values
, cbdata
->anydata
);
3113 //void AddStorageChoiceCB(StorageStructure *ss,
3114 // Storage_CBProc cbproc, void *anydata)
3116 // Storage_CBdata *cbdata;
3118 // cbdata = xmalloc(sizeof(Storage_CBdata));
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
));
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)
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
)
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));
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
));
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
;
3207 spinp
= (SpinStructure
*) client_data
;
3208 value
= GetSpinChoice(spinp
);
3211 if (w
== spinp
->arrow_up
) {
3213 } else if (w
== spinp
->arrow_down
) {
3214 incr
= -spinp
->incr
;
3216 errmsg("Wrong call to spin_arrow_cb()");
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);
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);
3261 // cbdata->timeout_id = XtAppAddTimeOut(app_con,
3262 // 250 /* 0.25 second */, sp_timer_proc, client_data);
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
);
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;
3316 // if (e->button == 5) {
3317 // incr = -spinp->incr;
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;
3332 // if (min >= max) {
3333 // errmsg("min >= max in CreateSpinChoice()!");
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,
3347 // str = XmStringCreateLocalized(s);
3348 // XtVaCreateManagedWidget("label", xmLabelWidgetClass, retval->rc,
3349 // XmNlabelString, str,
3351 // XmStringFree(str);
3352 // fr = XtVaCreateWidget("fr", xmFrameWidgetClass, retval->rc,
3353 // XmNshadowType, XmSHADOW_ETCHED_OUT,
3355 // form = XtVaCreateWidget("form", xmFormWidgetClass, fr,
3357 // retval->text = XtVaCreateWidget("text", xmTextWidgetClass, form,
3358 // XmNtraversalOn, True,
3362 // XtAddEventHandler(retval->text, ButtonPressMask, False, spin_updown, retval);
3364 // retval->arrow_up = XtVaCreateWidget("form", xmArrowButtonGadgetClass, form,
3365 // XmNarrowDirection, XmARROW_UP,
3367 // XtAddCallback(retval->arrow_up, XmNactivateCallback,
3368 // spin_arrow_cb, (XtPointer) retval);
3369 // retval->arrow_down = XtVaCreateWidget("form", xmArrowButtonGadgetClass, form,
3370 // XmNarrowDirection, XmARROW_DOWN,
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,
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,
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,
3395 // XtManageChild(retval->text);
3396 // XtManageChild(retval->arrow_up);
3397 // XtManageChild(retval->arrow_down);
3398 // XtManageChild(form);
3399 // XtManageChild(fr);
3400 // XtManageChild(retval->rc);
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
));
3447 SpinStructure
*CreateSpinChoice(Widget parent
, char *s
, int len
,
3448 int type
, double min
, double max
, double incr
)
3450 SpinStructure
*retval
;
3453 errmsg("min >= max in CreateSpinChoice()!");
3457 retval
= (SpinStructure
*) xmalloc(sizeof(SpinStructure
));
3459 retval
->type
= type
;
3462 retval
->incr
= incr
;
3464 QWidget
*widget
= new QWidget(parent
);
3465 retval
->rc
= widget
;
3467 QLabel
*label
= new QLabel(widget
);
3470 QLineEdit
*lineEdit
= new QLineEdit(widget
);
3471 SetLineEditWidth(lineEdit
, len
);
3472 retval
->text
= lineEdit
;
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();
3503 layout
->addWidget(widget
);
3509 //void SetSpinChoice(SpinStructure *spinp, double value)
3511 // X11Stuff *xstuff = gapp->gui->xstuff;
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;
3522 // if (spinp->type == SPIN_TYPE_FLOAT) {
3523 // sprintf(buf, "%g", value);
3525 // sprintf(buf, "%d", (int) rint(value));
3527 // XmTextSetString(spinp->text, buf);
3529 void SetSpinChoice(SpinStructure
*spinp
, double value
)
3531 QLineEdit
*spinBox
= (QLineEdit
*) spinp
->text
;
3534 if (value
< spinp
->min
) {
3535 QApplication::beep();
3537 } else if (value
> spinp
->max
) {
3538 QApplication::beep();
3542 if (spinp
->type
== SPIN_TYPE_FLOAT
) {
3543 sprintf(buf
, "%g", value
);
3545 sprintf(buf
, "%d", (int) rint(value
));
3547 spinBox
->setText(buf
);
3550 double GetSpinChoice(SpinStructure
*spinp
)
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
);
3572 //TextStructure *CreateTextInput(Widget parent, char *s)
3574 // TextStructure *retval;
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,
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,
3601 // XtManageChild(retval->form);
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
);
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();
3630 layout
->addWidget(widget
);
3637 // * create a multiline editable window
3638 // * parent = parent widget
3639 // * nrows = number of lines in the window
3640 // * s = label for window
3642 //TextStructure *CreateScrolledTextInput(Widget parent, char *s, int nrows)
3644 // TextStructure *retval;
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,
3660 // XmStringFree(str);
3664 // XtSetArg(args[ac], XmNrows, nrows); ac++;
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,
3676 // XtManageChild(retval->text);
3678 // XtManageChild(retval->form);
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
);
3693 retval
->label
= label
;
3695 QPlainTextEdit
*pTextEdit
= new QPlainTextEdit(widget
);
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
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();
3722 layout
->addWidget(widget
);
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
);
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));
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
);
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));
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
);
3811 //char *GetTextString(TextStructure *cst)
3815 // s = XmTextGetString(cst->text);
3816 // buf = copy_string(NULL, s);
3821 char *GetTextString(TextStructure
*cst
)
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());
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
)
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
: "");
3859 // TextStructure *cst;
3860 // Text_CBProc cbproc;
3863 // XtIntervalId timeout_id;
3872 //static void text_timer_proc(XtPointer client_data, XtIntervalId *id)
3875 // Text_CBdata *cbdata = (Text_CBdata *) client_data;
3877 // s = XmTextGetString(cbdata->w);
3878 // cbdata->cbproc(cbdata->cst, s, cbdata->anydata);
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;
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);
3901 // if (TEXT_TIMEOUT) {
3902 // cbdata->timeout_id = XtAppAddTimeOut(app_con,
3903 // TEXT_TIMEOUT, text_timer_proc, client_data);
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
;
3916 //static void text_int_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
3919 // Text_CBdata *cbdata = (Text_CBdata *) client_data;
3920 // s = XmTextGetString(w);
3921 // cbdata->cbproc(cbdata->cst, s, cbdata->anydata);
3924 static void text_int_cb_proc(Widget w
, XtPointer client_data
, XtPointer call_data
)
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();
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
));
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;
3997 if (!QString::compare(input
, last_input
) && (pos
!= last_pos
)) return Acceptable
;
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
)) {
4019 KeyPressListener::KeyPressListener(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());
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
));
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
)
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();
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
);
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)
4137 // if (XmStringGetLtoR(xms, charset, &s)) {
4146 Button_CBProc cbproc
;
4150 //Widget CreateButton(Widget parent, char *label)
4155 // xmstr = XmStringCreateLocalized(label);
4156 // button = XtVaCreateManagedWidget("button",
4157 // xmPushButtonWidgetClass, parent,
4158 // XmNalignment, XmALIGNMENT_CENTER,
4159 // XmNlabelString, xmstr,
4161 // * XmNmarginLeft, 5,
4162 // * XmNmarginRight, 5,
4163 // * XmNmarginTop, 3,
4164 // * XmNmarginBottom, 2,
4167 // XmStringFree(xmstr);
4171 Widget
CreateButton(Widget parent
, char *label
)
4175 button
= new QPushButton(label
, parent
);
4177 QLayout
*layout
= parent
->layout();
4179 layout
->addWidget(button
);
4185 //Widget CreateBitmapButton(Widget parent,
4186 // int width, int height, const unsigned char *bits)
4188 // X11Stuff *xstuff = gapp->gui->xstuff;
4193 // button = XtVaCreateManagedWidget("button",
4194 // xmPushButtonWidgetClass, parent,
4195 // XmNlabelType, XmPIXMAP,
4199 // * We need to get right fore- and background colors for pixmap.
4201 // XtVaGetValues(button,
4202 // XmNforeground, &fg,
4203 // XmNbackground, &bg,
4205 // pm = XCreatePixmapFromBitmapData(xstuff->disp,
4206 // xstuff->root, (char *) bits, width, height, fg, bg, xstuff->depth);
4207 // XtVaSetValues(button, XmNlabelPixmap, pm, NULL);
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
),
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)
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);
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)
4305 // XmString dir, pattern, dirmask;
4306 // Widget FSB = (Widget) data;
4310 // bufp = get_workingdir(gapp);
4313 // bufp = grace_get_userhome(gapp->grace);
4319 // bufp = "/cygdrive/";
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"},
4339 // ,{FSB_CYGDRV, "My Computer"}
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);
4354 //FSBStructure *CreateFileSelectionBox(Widget parent, char *s)
4356 // FSBStructure *retval;
4357 // OptionStructure *opt;
4358 // Widget fr, form, button;
4360 // char *bufp, *resname;
4362 // retval = xmalloc(sizeof(FSBStructure));
4363 // resname = label_to_resname(s, "FSB");
4364 // retval->FSB = XmCreateFileSelectionDialog(parent, resname, NULL, 0);
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);
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);
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,
4400 // XtVaSetValues(button,
4401 // XmNleftAttachment, XmATTACH_NONE,
4402 // XmNtopAttachment, XmATTACH_FORM,
4403 // XmNbottomAttachment, XmATTACH_FORM,
4404 // XmNrightAttachment, XmATTACH_FORM,
4406 // XtManageChild(form);
4408 // XtManageChild(retval->rc);
4412 FSBStructure
*CreateFSBDialog(Widget parent
, char *s
)
4414 FSBStructure
*retval
;
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
);
4439 fileSelectionDialog
->setDirectory(get_workingdir(gapp
));
4441 AddHelpCB(fileSelectionDialog
->ui
.helpPushButton
,
4442 "doc/UsersGuide.html#FS-dialog");
4452 //static void fsb_int_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
4457 // FSB_CBdata *cbdata = (FSB_CBdata *) client_data;
4458 // XmFileSelectionBoxCallbackStruct *cbs =
4459 // (XmFileSelectionBoxCallbackStruct *) call_data;
4461 // s = GetStringSimple(cbs->value);
4463 // errmsg("Error converting XmString to char string");
4467 // set_wait_cursor();
4469 // ok = cbdata->cbproc(cbdata->fsb, s, cbdata->anydata);
4472 // XtUnmanageChild(cbdata->fsb->dialog);
4474 // unset_wait_cursor();
4476 static void fsb_int_cb_proc(Widget w
, XtPointer client_data
, XtPointer call_data
)
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();
4492 ok
= cbdata
->cbproc(cbdata
->fsb
, s
, cbdata
->anydata
);
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
)
4515 cbdata
= (FSB_CBdata
*) xmalloc(sizeof(FSB_CBdata
));
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)
4531 // if (pattern != NULL) {
4532 // xmstr = XmStringCreateLocalized(pattern);
4533 // XtVaSetValues(fsb->FSB, XmNpattern, xmstr, NULL);
4534 // XmStringFree(xmstr);
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)
4550 // label = XtVaCreateManagedWidget(s ? s:"",
4551 // xmLabelWidgetClass, parent,
4552 // XmNalignment, XmALIGNMENT_BEGINNING,
4553 // XmNrecomputeSize, True,
4557 Widget
CreateLabel(Widget parent
, char *s
)
4559 QLabel
*label
= new QLabel(s
? s
:"", parent
);
4561 QLayout
*layout
= parent
->layout();
4563 layout
->addWidget(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;
4577 // case ALIGN_CENTER:
4578 // xm_alignment = XmALIGNMENT_CENTER;
4581 // xm_alignment = XmALIGNMENT_END;
4584 // errmsg("Internal error in AlignLabel()");
4589 // XmNalignment, xm_alignment,
4592 void AlignLabel(Widget w
, int alignment
)
4594 unsigned int xm_alignment
;
4597 case ALIGN_BEGINNING
:
4598 xm_alignment
= Qt::AlignLeft
;
4601 xm_alignment
= Qt::AlignHCenter
;
4604 xm_alignment
= Qt::AlignRight
;
4607 errmsg("Internal error in AlignLabel()");
4612 QLayout
*layout
= w
->parentWidget()->layout();
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));
4637 // xvlibcolors = xrealloc(xvlibcolors, pr->ncolors*sizeof(unsigned long));
4638 // if (!xvlibcolors) {
4642 // for (i = 0; i < pr->ncolors; i++) {
4644 // Colordef *c = &pr->colormap[i];
4646 // pixel = x11_allocate_color(gapp->gui, &c->rgb);
4648 // if (pixel >= 0) {
4649 // xvlibcolors[c->id] = pixel;
4651 // xvlibcolors[c->id] = BlackPixel(xstuff->disp, xstuff->screennumber);
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);
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;
4672 // for (i = 0; i < n; i++) {
4673 // pattern_option_items[i].value = i;
4675 // pattern_option_items[i].bitmap = NULL;
4677 // Pattern *pat = canvas_get_pattern(canvas, i);
4678 // pattern_option_items[i].bitmap = pat->bits;
4683 // n = number_of_linestyles(canvas);
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;
4691 // for (i = 0; i < n; i++) {
4692 // LineStyle *linestyle = canvas_get_linestyle(canvas, i);
4693 // lines_option_items[i].value = i;
4695 // lines_option_items[i].bitmap = NULL;
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) {
4709 // lines_option_items[i].bitmap[k/8] |= 1 << k % 8;
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;
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));
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;
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));
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;
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));
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
);
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
;
4770 pattern_option_items
[i
].bitmap
= NULL
;
4772 Pattern
*pat
= canvas_get_pattern(canvas
, i
);
4773 pattern_option_items
[i
].bitmap
= pat
->bits
;
4778 n
= number_of_linestyles(canvas
);
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
;
4790 lines_option_items
[i
].bitmap
= NULL
;
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)) {
4804 lines_option_items
[i
].bitmap
[k
/8] |= 1 << k
% 8;
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)
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;
4870 // for (i = 0; i < nfont_selectors; i++) {
4871 // UpdateOptionChoice(font_selectors[i],
4872 // nfont_option_items, font_option_items);
4875 void update_font_selectors(void)
4878 Project
*pr
= project_get_data(gproject_get_top(gapp
->gp
));
4880 nfont_option_items
= pr
->nfonts
;
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()");
4908 // retvalp = CreateOptionChoice(parent, s, 0,
4909 // nfont_option_items, font_option_items);
4911 // font_selectors[nfont_selectors - 1] = retvalp;
4915 OptionStructure
*CreateFontChoice(Widget parent
, char *s
)
4917 OptionStructure
*retvalp
= NULL
;
4920 font_selectors
= (OptionStructure
**) xrealloc(font_selectors
,
4921 nfont_selectors
*sizeof(OptionStructure
*));
4922 if (font_selectors
== NULL
) {
4923 errmsg("Malloc failed in CreateFontChoice()");
4927 retvalp
= CreateOptionChoice(parent
, s
, 0,
4928 nfont_option_items
, font_option_items
);
4930 font_selectors
[nfont_selectors
- 1] = 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;
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,
5033 // retval->r_sel = CreateOptionChoice(rc,
5034 // "Restriction:", 1, 7, restr_items);
5035 // retval->negate = CreateToggleButton(rc, "Negated");
5036 // XtManageChild(rc);
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
);
5065 retval
->r_sel
= CreateOptionChoice(rc
,
5066 "Restriction:", 1, 7, restr_items
);
5067 retval
->negate
= CreateToggleButton(rc
, "Negated");
5072 #define PEN_CHOICE_WIDTH 64
5073 #define PEN_CHOICE_HEIGHT 16
5078 Widget pattern_popup
;
5086 //static void SetPenChoice_int(Widget button, Pen *pen, int call_cb)
5088 // X11Stuff *xstuff = gapp->gui->xstuff;
5090 // Pixmap pixtile, pixmap;
5091 // Button_PData *pdata;
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))) {
5101 // pdata = GetUserData(button);
5102 // pdata->pen = *pen;
5105 // gc_pen = XCreateGC(xstuff->disp, xstuff->root, 0, NULL);
5106 // XSetFillStyle(xstuff->disp, gc_pen, FillTiled);
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);
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
);
5134 Button_PData
*pdata
;
5138 if (!button
|| !pen
||
5139 (pen
->pattern
< 0 || pen
->pattern
>= number_of_patterns(canvas
)) ||
5140 (pen
->color
< 0 || pen
->color
>= number_of_colors(canvas
))) {
5144 pdata
= (Button_PData
*) WidgetGetUserData(button
);
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;
5182 // if (e->button != 3) {
5186 // pdata = GetUserData(parent);
5188 // if (e->state & ShiftMask) {
5189 // popup = pdata->pattern_popup;
5191 // popup = pdata->color_popup;
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
;
5205 pdata
= (Button_PData
*) WidgetGetUserData(w
);
5207 // if (e->state & ShiftMask) {
5208 // popup = pdata->pattern_popup;
5210 popup
= pdata
->color_popup
;
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)
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();
5238 Button_PData
*pdata
;
5240 pdata
= (Button_PData
*) WidgetGetUserData(button
);
5242 pen
.color
= item
->data(Qt::UserRole
).toInt();
5244 SetPenChoice_int(button
, &pen
, TRUE
);
5246 tableWidget
->setCurrentItem(0);
5250 //void update_color_choice_popup(void)
5252 // X11Stuff *xstuff = gapp->gui->xstuff;
5253 // Project *pr = project_get_data(gproject_get_top(gapp->gp));
5256 // if (pr && color_choice_popup) {
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,
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]);
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;
5280 // XtVaSetValues(color_choice_popup,
5281 // XmNnumColumns, ncols,
5282 // XmNpacking, XmPACK_COLUMN,
5285 // /* Create new buttons, if needed */
5286 // for (ci = nw_old; ci < nw_new; ci++) {
5288 // cb = XmCreatePushButton(color_choice_popup, "cb", NULL, 0);
5291 // XtVaGetValues(color_choice_popup,
5292 // XtNchildren, &ws,
5295 // /* Manage newly added widgets */
5296 // if (nw_new > nw_old) {
5297 // XtManageChildren(ws + nw_old, nw_new - nw_old);
5300 // /* Paint/label new buttons */
5301 // for (ci = 0; ci < pr->ncolors; ci++) {
5302 // Colordef *c = &pr->colormap[ci];
5304 // long color = c->id;
5305 // Widget cb = ws[ci];
5308 // bg = xvlibcolors[color];
5309 // if (get_rgb_intensity(&c->rgb) < 0.5) {
5310 // fg = WhitePixel(xstuff->disp, xstuff->screennumber);
5312 // fg = BlackPixel(xstuff->disp, xstuff->screennumber);
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,
5324 // XmStringFree(str);
5328 void update_color_choice_popup(void)
5330 Project
*pr
= project_get_data(gproject_get_top(gapp
->gp
));
5333 if (pr
&& color_choice_popup
) {
5334 QTableWidget
*tableWidget
= (QTableWidget
*) color_choice_popup
;
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
;
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
);
5362 item
->setForeground(Qt::black
);
5365 item
->setData(Qt::UserRole
, QVariant(c
->id
));
5366 tableWidget
->setItem(row
, col
, item
);
5374 tableWidget
->resizeColumnsToContents();
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();
5395 // XmAddToPostFromList(color_choice_popup, button);
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)
5432 // popup = XmCreatePopupMenu(button, "patternPopupMenu", NULL, 0);
5433 // CreateMenuLabel(popup, "Pattern:");
5434 // CreateMenuSeparator(popup);
5441 OptionStructure
*color
;
5442 OptionStructure
*pattern
;
5447 static int pen_choice_aac(void *data
)
5449 PenChoiceDialog
*ui
= (PenChoiceDialog
*) data
;
5451 if (ui
->pen_button
) {
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();
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);
5483 // ui->pen_button = (Widget) data;
5485 // if (ui->pen_button) {
5486 // Button_PData *pdata;
5489 // pdata = GetUserData(ui->pen_button);
5491 // pen = pdata->pen;
5493 // SetOptionChoice(ui->color, pen.color);
5494 // SetOptionChoice(ui->pattern, pen.pattern);
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
;
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
;
5527 pdata
= (Button_PData
*) WidgetGetUserData(ui
->pen_button
);
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;
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,
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);
5567 // SetPenChoice_int(button, &pen, FALSE);
5569 // XtManageChild(button);
5573 Widget
CreatePenChoice(Widget parent
, char *s
)
5575 Button_PData
*pdata
;
5578 pdata
= (Button_PData
*) xmalloc(sizeof(Button_PData
));
5579 memset(pdata
, 0, sizeof(Button_PData
));
5581 QLabel
*label
= new QLabel(parent
);
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
);
5594 // pdata->pattern_popup = CreatePatternChoicePopup(button);
5596 button
->setContextMenuPolicy(Qt::CustomContextMenu
);
5597 QtAddCallback(button
, SIGNAL(customContextMenuRequested(const QPoint
)),
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();
5614 layout
->addWidget(widget
);
5620 //int GetPenChoice(Widget pen_button, Pen *pen)
5622 // Button_PData *pdata = GetUserData(pen_button);
5624 // *pen = pdata->pen;
5625 // return RETURN_SUCCESS;
5627 // return RETURN_FAILURE;
5630 int GetPenChoice(Widget pen_button
, Pen
*pen
)
5632 Button_PData
*pdata
= (Button_PData
*) WidgetGetUserData(pen_button
);
5635 return RETURN_SUCCESS
;
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");
5648 // pdata->cb_proc = cbproc;
5649 // pdata->cb_data = anydata;
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");
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
)
5680 buf
= (char *) xmalloc(strlen(QIDSTR(q
)) + 128);
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
));
5697 StorageStructure
*CreateSSDChoice(Widget parent
, char *labelstr
, int type
)
5699 StorageStructure
*ss
;
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
));
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");
5718 int GetSSDColChoices(SSDColStructure
*sc
, Quark
**ssd
, int **cols
)
5720 if (GetSingleStorageChoice(sc
->ssd_sel
, ssd
) != RETURN_SUCCESS
) {
5723 return GetListChoices(sc
->col_sel
, cols
);
5727 void update_ssd_selectors(Quark
*pr
)
5730 for (i
= 0; i
< nssd_selectors
; i
++) {
5731 StorageStructure
*ss
= ssd_selectors
[i
];
5738 UpdateStorageChoice(ss
);
5743 static StorageStructure
**graph_selectors
= NULL
;
5744 static int ngraph_selectors
= 0;
5746 #define GSS_FOCUS_CB 0
5752 static void gss_any_cb(void *udata
, int cbtype
)
5754 StorageStructure
*ss
= (StorageStructure
*) udata
;
5758 n
= GetStorageChoices(ss
, &values
);
5760 for (i
= 0; i
< n
; i
++) {
5761 Quark
*gr
= values
[i
];
5765 switch_current_graph(gr
);
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)
5799 // if (quark_fid_get(q) == QFlavorGraph) {
5800 // sprintf(buf, "Graph \"%s\" (type: %s, sets: %d)",
5802 // graph_types(gapp->grace, graph_get_type(q)), quark_get_number_of_descendant_sets(q));
5806 // return copy_string(NULL, buf);
5811 static char *graph_labeling(Quark
*q
, unsigned int *rid
)
5819 buf
= (char *) xmalloc(strlen(QIDSTR(q
)) + 128);
5824 if (quark_fid_get(q
) == QFlavorGraph
) {
5825 sprintf(buf
, "Graph \"%s\" (type: %s, sets: %d)",
5827 graph_types(gapp
->grace
, (GraphType
) graph_get_type(q
)),
5828 quark_get_number_of_descendant_sets(q
));
5838 //StorageStructure *CreateGraphChoice(Widget parent, char *labelstr, int type)
5840 // StorageStructure *ss;
5841 // GSSData *gssdata;
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);
5873 StorageStructure
*CreateGraphChoice(Widget parent
, char *labelstr
, int type
)
5875 StorageStructure
*ss
;
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");
5888 (StorageStructure
**) xrealloc(graph_selectors
,
5889 ngraph_selectors
*sizeof(StorageStructure
*));
5890 graph_selectors
[ngraph_selectors
- 1] = ss
;
5892 gssdata
= (GSSData
*) xmalloc(sizeof(GSSData
));
5894 ss
->popup_cb
= g_popup_cb
;
5898 CreateMenuSeparator(popup
);
5900 CreateMenuButton(popup
, "Create new", '\0', g_new_cb
, ss
);
5902 CreateMenuSeparator(popup
);
5905 CreateMenuButton(popup
, "Focus to selected", '\0', g_focus_cb
, ss
);
5910 void update_graph_selectors(Quark
*pr
)
5913 for (i
= 0; i
< ngraph_selectors
; i
++) {
5914 StorageStructure
*ss
= graph_selectors
[i
];
5921 UpdateStorageChoice(ss
);
5925 void graph_set_selectors(Quark
*gr
)
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
)
5945 buf
= (char *) xmalloc(strlen(QIDSTR(q
)) + 128);
5950 if (quark_fid_get(q
) == QFlavorFrame
) {
5951 sprintf(buf
, "Frame \"%s\"", QIDSTR(q
));
5961 StorageStructure
*CreateFrameChoice(Widget parent
, char *labelstr
, int type
)
5963 StorageStructure
*ss
;
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");
5975 (StorageStructure
**) xrealloc(frame_selectors
, nframe_selectors
*sizeof(StorageStructure
*));
5976 frame_selectors
[nframe_selectors
- 1] = ss
;
5980 CreateMenuSeparator(popup
);
5982 CreateMenuButton(popup
, "Create new", '\0', g_new_cb
, ss
);
5984 CreateMenuSeparator(popup
);
5989 void update_frame_selectors(Quark
*pr
)
5992 for (i
= 0; i
< nframe_selectors
; i
++) {
5993 StorageStructure
*ss
= frame_selectors
[i
];
6000 UpdateStorageChoice(ss
);
6005 static StorageStructure
**set_selectors
= NULL
;
6006 static int nset_selectors
= 0;
6009 #define SSS_NEWF_CB 1
6012 StorageStructure
*graphss
;
6015 Quark
*get_set_choice_gr(StorageStructure
*ss
)
6018 SSSData
*sdata
= (SSSData
*) ss
->data
;
6020 if (sdata
->graphss
) {
6021 if (GetSingleStorageChoice(sdata
->graphss
, &gr
) != RETURN_SUCCESS
) {
6031 static void sss_any_cb(void *udata
, int cbtype
)
6033 StorageStructure
*ss
= (StorageStructure
*) udata
;
6034 Quark
*gr
= get_set_choice_gr(ss
);
6038 create_leval_frame(NULL
, gr
);
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
)
6058 buf
= (char *) xmalloc(strlen(QIDSTR(q
)) + 128);
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
),
6078 StorageStructure
*CreateSetChoice(Widget parent
,
6079 char *labelstr
, int type
, StorageStructure
*graphss
)
6081 StorageStructure
*ss
;
6083 Widget popup
, submenupane
;
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");
6093 (StorageStructure
**) xrealloc(set_selectors
, nset_selectors
*sizeof(StorageStructure
*));
6094 set_selectors
[nset_selectors
- 1] = ss
;
6096 sssdata
= (SSSData
*) xmalloc(sizeof(SSSData
));
6098 sssdata
->graphss
= graphss
;
6102 CreateMenuSeparator(popup
);
6104 submenupane
= CreateMenu(popup
, "Create new", '\0', FALSE
);
6105 CreateMenuButton(submenupane
, "By formula", '\0', s_newF_cb
, ss
);
6107 UpdateSetChoice(ss
);
6112 void UpdateSetChoice(StorageStructure
*ss
)
6116 gr
= get_set_choice_gr(ss
);
6118 SetStorageChoiceQuark(ss
, gr
);
6122 void update_set_selectors(Quark
*gr
)
6127 update_graph_selectors(get_parent_project(gr
));
6130 for (i
= 0; i
< nset_selectors
; i
++) {
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;
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);
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
);
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
;
6181 //SSDSetStructure *CreateSSDSetSelector(Widget parent, char *s, int sel_type)
6183 // SSDSetStructure *retval;
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);
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
);
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
;
6216 ListStructure
*CreateColChoice(Widget parent
, char *labelstr
, int type
)
6219 ListStructure
*retval
;
6223 retval
= CreateListChoice(parent
, labelstr
, type
, nvisible
, 0, NULL
);
6228 //void UpdateColChoice(ListStructure *sel, const Quark *ssd)
6230 // unsigned int i, ncols;
6231 // OptionItem *items;
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);
6244 // s = copy_string(NULL, label);
6246 // items[i].label = s;
6252 // UpdateListChoice(sel, ncols, items);
6254 // for (i = 0; i < ncols; i++) {
6255 // xfree(items[i].label);
6259 // sel->anydata = (void *) ssd;
6262 void UpdateColChoice(ListStructure
*sel
, const Quark
*ssd
)
6264 unsigned int i
, ncols
;
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];
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
);
6278 s
= copy_string(NULL
, label
);
6286 UpdateListChoice(sel
, ncols
, items
);
6288 for (i
= 0; i
< ncols
; i
++) {
6289 xfree(items
[i
].label
);
6293 sel
->anydata
= (void *) ssd
;
6296 static void update_ssd_cb(StorageStructure
*ss
, int n
, Quark
**values
, void *data
)
6298 SSDColStructure
*gs
= (SSDColStructure
*) data
;
6307 UpdateColChoice(gs
->col_sel
, ssd
);
6310 //SSDColStructure *CreateSSDColSelector(Widget parent, char *s, int sel_type)
6312 // SSDColStructure *retval;
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);
6327 SSDColStructure
*CreateSSDColSelector(Widget parent
, char *s
, int sel_type
)
6329 SSDColStructure
*retval
;
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
) {
6343 retval
->col_sel
= CreateColChoice(frame
, str
, sel_type
);
6344 AddStorageChoiceCB(retval
->ssd_sel
, update_ssd_cb
, (void *) 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,
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,
6371 // XtVaSetValues(retval->dest->frame,
6372 // XmNtopAttachment, XmATTACH_FORM,
6373 // XmNbottomAttachment, XmATTACH_FORM,
6374 // XmNleftAttachment, XmATTACH_POSITION,
6375 // XmNleftPosition, 1,
6376 // XmNrightAttachment, XmATTACH_FORM,
6379 // XtManageChild(retval->form);
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();
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
);
6410 //void paint_color_selector(OptionStructure *optp)
6412 // X11Stuff *xstuff = gapp->gui->xstuff;
6415 // Project *pr = project_get_data(gproject_get_top(gapp->gp));
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);
6427 // fg = BlackPixel(xstuff->disp, xstuff->screennumber);
6429 // XtVaSetValues(optp->options[i].widget,
6430 // XmNbackground, bg,
6431 // XmNforeground, fg,
6435 void paint_color_selector(OptionStructure
*optp
)
6437 Project
*pr
= project_get_data(gproject_get_top(gapp
->gp
));
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
);
6454 item
->setForeground(Qt::black
);
6460 //void update_color_selectors(void)
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;
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]);
6481 // update_color_choice_popup();
6483 void update_color_selectors(void)
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
;
6512 color_selectors
= (OptionStructure
**) xrealloc(color_selectors
,
6513 ncolor_selectors
*sizeof(OptionStructure
*));
6514 if (color_selectors
== NULL
) {
6515 errmsg("Malloc failed in CreateColorChoice()");
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
);
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;
6543 // va_start(var, labelstr);
6544 // while ((s = va_arg(var, char *)) != NULL) {
6546 // oi = xrealloc(oi, nchoices*sizeof(OptionItem));
6547 // oi[nchoices - 1].value = nchoices - 1;
6548 // oi[nchoices - 1].label = copy_string(NULL, s);
6552 // retval = CreateOptionChoice(parent, labelstr, 1, nchoices, oi);
6554 // while (nchoices) {
6556 // xfree(oi[nchoices].label);
6562 OptionStructure
*CreatePanelChoice(Widget parent
, char *labelstr
, ...)
6564 OptionStructure
*retval
;
6566 OptionItem
*oi
= NULL
;
6570 va_start(var
, labelstr
);
6571 while ((s
= va_arg(var
, char *)) != NULL
) {
6573 oi
= (OptionItem
*) xrealloc(oi
, nchoices
*sizeof(OptionItem
));
6574 oi
[nchoices
- 1].value
= nchoices
- 1;
6575 oi
[nchoices
- 1].label
= copy_string(NULL
, s
);
6579 retval
= CreateOptionChoice(parent
, labelstr
, 1, nchoices
, oi
);
6583 xfree(oi
[nchoices
].label
);
6590 //static void format_call_cb(FormatStructure *fstr)
6592 // if (fstr->cb_proc) {
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);
6603 static void format_call_cb(FormatStructure
*fstr
)
6605 if (fstr
->cb_proc
) {
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
;
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
;
6639 format_call_cb(fstr
);
6642 //FormatStructure *CreateFormatChoice(Widget parent)
6644 // FormatStructure *retval;
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);
6661 FormatStructure
*CreateFormatChoice(Widget parent
)
6663 FormatStructure
*retval
;
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
);
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();
6694 // format->type = GetOptionChoice(fstr->type);
6695 // format->prec = GetOptionChoice(fstr->prec);
6696 // format->fstring = GetTextString(fstr->fstring);
6701 Format
*GetFormatChoice(FormatStructure
*fstr
)
6703 Format
*format
= format_new();
6705 format
->type
= (FormatType
) GetOptionChoice(fstr
->type
);
6706 format
->prec
= GetOptionChoice(fstr
->prec
);
6707 format
->fstring
= GetTextString(fstr
->fstring
);
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"},
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
);
6739 OptionStructure
*CreatePrecisionChoice(Widget parent
, char *s
)
6741 return CreateOptionChoiceVA(parent
, s
,
6755 OptionStructure
*CreatePaperOrientationChoice(Widget parent
, char *s
)
6757 return CreateOptionChoiceVA(parent
, s
,
6758 "Landscape", PAGE_ORIENT_LANDSCAPE
,
6759 "Portrait", PAGE_ORIENT_PORTRAIT
,
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
,
6773 //Widget CreateScale(Widget parent, char *s, int min, int max, int delta)
6778 // str = XmStringCreateLocalized(s);
6780 // w = XtVaCreateManagedWidget("scroll",
6781 // xmScaleWidgetClass, parent,
6782 // XmNtitleString, str,
6785 // XmNscaleMultiple, delta,
6787 // XmNshowValue, True,
6788 // XmNprocessingDirection, XmMAX_ON_RIGHT,
6789 // XmNorientation, XmHORIZONTAL,
6790 //#if XmVersion >= 2000
6791 // XmNsliderMark, XmROUND_MARK,
6795 // XmStringFree(str);
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
);
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();
6823 layout
->addWidget(widget
);
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;
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)
6863 // XtVaGetValues(w, XmNvalue, &value, NULL);
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();
6912 layout
->addWidget(cb
);
6918 //int GetToggleButtonState(Widget w)
6921 // errmsg("Internal error: GetToggleButtonState() called with NULL widget");
6924 // return XmToggleButtonGetState(w);
6927 int ToggleButtonGetState(Widget w
)
6930 errmsg("Internal error: GetToggleButtonState() called with NULL widget");
6933 if (QCheckBox
*checkBox
= qobject_cast
<QCheckBox
*>(w
)) {
6934 if (checkBox
->isChecked()) {
6942 if (QAction
*action
= qobject_cast
<QAction
*>(w
)) {
6943 if (action
->isChecked()) {
6954 //void SetToggleButtonState(Widget w, int value)
6959 // XmToggleButtonSetState(w, value ? True:False, False);
6963 void ToggleButtonSetState(Widget w
, int value
)
6969 QCheckBox
*cb
= qobject_cast
<QCheckBox
*>(w
);
6971 cb
->blockSignals(true);
6972 cb
->setChecked(value
? true : false);
6973 cb
->blockSignals(false);
6976 QAction
*ac
= qobject_cast
<QAction
*>(w
);
6978 ac
->blockSignals(true);
6979 ac
->setChecked(value
? true : false);
6980 ac
->blockSignals(false);
6992 static void tb_int_cb_proc(Widget w
, XtPointer client_data
, XtPointer call_data
)
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;
7012 // XmNvalueChangedCallback, tb_int_cb_proc, (XtPointer) cbdata);
7014 void AddToggleButtonCB(Widget w
, TB_CBProc cbproc
, void *anydata
)
7018 cbdata
= (TB_CBdata
*) xmalloc(sizeof(TB_CBdata
));
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)
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();
7069 layout
->addWidget(widget
);
7075 //Widget CreateDialogForm(Widget parent, const char *s)
7077 // X11Stuff *xstuff = gapp->gui->xstuff;
7078 // Widget dialog, w;
7082 // if (parent == NULL) {
7083 // standalone = TRUE;
7084 // parent = XtAppCreateShell("XMgapp", "XMgapp",
7085 // topLevelShellWidgetClass, xstuff->disp,
7088 // standalone = FALSE;
7090 // bufp = label_to_resname(s, "Dialog");
7091 // dialog = XmCreateDialogShell(parent, bufp, NULL, 0);
7094 // if (standalone) {
7095 // RegisterEditRes(dialog);
7098 // handle_close(dialog);
7100 // bufp = copy_string(NULL, "Grace: ");
7101 // bufp = concat_strings(bufp, s);
7102 // XtVaSetValues(dialog,
7107 // w = XmCreateForm(dialog, "form", NULL, 0);
7111 Widget
CreateDialog(Widget parent
, const char *s
)
7115 bufp
= copy_string(NULL
, "Grace: ");
7116 bufp
= concat_strings(bufp
, s
);
7118 QDialog
*w
= new QDialog(mainWin
);
7119 w
->setWindowTitle(bufp
);
7122 QVBoxLayout
*mainLayout
= new QVBoxLayout
;
7123 mainLayout
->setContentsMargins(3,3,3,3);
7124 w
->setLayout(mainLayout
);
7129 //void SetDialogFormResizable(Widget form, int onoff)
7131 // XtVaSetValues(form,
7132 // XmNresizePolicy, onoff ? XmRESIZE_ANY:XmRESIZE_NONE,
7134 // XtVaSetValues(XtParent(form),
7135 // XmNallowShellResize, onoff ? True:False,
7138 void SetDialogFormResizable(Widget form
, int onoff
)
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,
7153 // XtVaSetValues(last_widget,
7154 // XmNbottomAttachment, XmATTACH_NONE,
7157 // XtVaSetValues(child,
7158 // XmNtopAttachment, XmATTACH_FORM,
7161 // XtVaSetValues(child,
7162 // XmNleftAttachment, XmATTACH_FORM,
7163 // XmNrightAttachment, XmATTACH_FORM,
7164 // XmNbottomAttachment, XmATTACH_FORM,
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
);
7177 layout
->addWidget(child
);
7181 //void FixateDialogFormChild(Widget w)
7184 // XtVaGetValues(w, XmNtopWidget, &prev, NULL);
7185 // XtVaSetValues(w, XmNtopAttachment, XmATTACH_NONE, NULL);
7186 // XtVaSetValues(prev, XmNbottomAttachment, XmATTACH_WIDGET,
7187 // XmNbottomWidget, w,
7190 void FixateDialogFormChild(Widget w
)
7194 //static Widget CreateCommandButtons(Widget parent, int n, Widget * buts, char **l)
7200 // form = XtVaCreateWidget("form", xmFormWidgetClass, parent,
7201 // XmNfractionBase, n,
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,
7217 // XtManageChild(form);
7218 // XtVaGetValues(buts[0], XmNheight, &h, NULL);
7219 // XtVaSetValues(form, XmNpaneMaximum, h, XmNpaneMinimum, h, NULL);
7223 Widget
CreateCommandButtons(Widget parent
, int n
, Widget
*buts
, char **l
)
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
;
7249 AACDialog_CBProc cbproc
;
7253 //void aacdialog_int_cb_proc(Widget but, void *data)
7255 // AACDialog_CBdata *cbdata;
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));
7268 // unset_wait_cursor();
7270 void aacdialog_int_cb_proc(Widget but
, void *data
)
7272 AACDialog_CBdata
*cbdata
;
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)
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,
7305 // CreateCommandButtons(fr, 3, aacbut, aaclab);
7307 // AddDialogFormChild(form, container);
7308 // XtVaSetValues(container,
7309 // XmNbottomAttachment, XmATTACH_WIDGET,
7310 // XmNbottomWidget, fr,
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);
7336 WidgetList
CreateAACDialog(Widget form
,
7337 Widget container
, AACDialog_CBProc cbproc
, void *data
)
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
);
7370 int td_cb(void *data
)
7372 int res
, i
, nssrc
, error
;
7373 Quark
**srcsets
, **destsets
;
7374 TransformStructure
*tdialog
= (TransformStructure
*) data
;
7377 res
= GetTransformDialogSettings(tdialog
, &nssrc
, &srcsets
, &destsets
);
7379 if (res
!= RETURN_SUCCESS
) {
7380 return RETURN_FAILURE
;
7385 tddata
= tdialog
->get_cb(tdialog
->gui
);
7391 for (i
= 0; i
< nssrc
; i
++) {
7392 Quark
*psrc
, *pdest
;
7394 pdest
= destsets
[i
];
7396 res
= tdialog
->run_cb(psrc
, pdest
, tddata
);
7397 if (res
!= RETURN_SUCCESS
) {
7410 tdialog
->free_cb(tddata
);
7413 snapshot_and_update(gapp
->gp
, TRUE
);
7415 if (error
== FALSE
) {
7416 return RETURN_SUCCESS
;
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
;
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();
7465 int GetTransformDialogSettings(TransformStructure
*tdialog
,
7466 int *nssrc
, Quark
***srcsets
, Quark
***destsets
)
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
);
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");
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
));
7496 errmsg("Cannot create new SSD");
7497 return RETURN_FAILURE
;
7500 /* check for mutually exclusive selections */
7501 if (tdialog
->exclusive
&& destssd
== srcssd
) {
7506 errmsg("Source and destination SSD's are the same");
7507 return RETURN_FAILURE
;
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
)) {
7523 (*destsets
)[i
] = gapp_set_new(destssd
);
7524 dsp
= set_get_dataset((*destsets
)[i
]);
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)
7548 // rc = XmCreateRowColumn(parent, "VContainer", NULL, 0);
7549 // XtManageChild(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();
7562 QWidget
*widget
= new QWidget(parent
);
7563 widget
->setLayout(vLayout
);
7564 layout
->addWidget(widget
);
7567 parent
->setLayout(vLayout
);
7572 //Widget CreateHContainer(Widget parent)
7576 // rc = XmCreateRowColumn(parent, "HContainer", NULL, 0);
7577 // XtVaSetValues(rc, XmNorientation, XmHORIZONTAL, NULL);
7578 // XtManageChild(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();
7591 QWidget
*widget
= new QWidget(parent
);
7592 widget
->setLayout(hLayout
);
7593 layout
->addWidget(widget
);
7596 parent
->setLayout(hLayout
);
7602 //Widget CreateFrame(Widget parent, char *s)
7606 // fr = XtVaCreateManagedWidget("frame", xmFrameWidgetClass, parent, NULL);
7608 // XtVaCreateManagedWidget(s, xmLabelGadgetClass, fr,
7609 // XmNchildType, XmFRAME_TITLE_CHILD,
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
);
7623 groupBox
->setTitle(s
);
7626 QLayout
*layout
= parent
->layout();
7628 layout
->addWidget(groupBox
);
7640 //Widget CreateGrid(Widget parent, int ncols, int nrows)
7646 // if (ncols <= 0 || nrows <= 0) {
7647 // errmsg("Wrong call to CreateGrid()");
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);
7663 // XmNfractionBase, nfractions,
7667 // XtManageChild(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();
7680 layout
->addWidget(widget
);
7686 //void PlaceGridChild(Widget grid, Widget w, int col, int row)
7688 // int nfractions, w1, h1;
7691 // XtVaGetValues(grid,
7692 // XmNfractionBase, &nfractions,
7693 // XmNuserData, &gd,
7696 // if (gd == NULL) {
7697 // errmsg("PlaceGridChild() called with a non-grid widget");
7700 // if (col < 0 || col >= gd->ncols) {
7701 // errmsg("PlaceGridChild() called with wrong `col' argument");
7704 // if (row < 0 || row >= gd->nrows) {
7705 // errmsg("PlaceGridChild() called with wrong `row' argument");
7709 // w1 = nfractions/gd->ncols;
7710 // h1 = nfractions/gd->nrows;
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 ,
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
);
7730 gridLayout
->addWidget(w
, row
, col
);
7736 //Widget CreateTab(Widget parent)
7740 // tab = XtVaCreateManagedWidget("tab", xmTabWidgetClass, parent, NULL);
7744 Widget
CreateTab(Widget parent
)
7746 QTabWidget
*tab
= new QTabWidget(parent
);
7747 tab
->setSizePolicy(QSizePolicy::Fixed
, QSizePolicy::Fixed
);
7749 QLayout
*layout
= parent
->layout();
7751 layout
->addWidget(tab
);
7757 //Widget CreateTabPage(Widget parent, char *s)
7762 // w = XmCreateRowColumn(parent, "tabPage", NULL, 0);
7763 // str = XmStringCreateLocalized(s);
7764 // XtVaSetValues(w, XmNtabLabel, str, NULL);
7765 // XmStringFree(str);
7766 // XtManageChild(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
);
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)
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,
7817 // XmStringFree(str);
7818 // w = XtVaCreateManagedWidget("text", xmTextWidgetClass, rc,
7819 // XmNtraversalOn, True,
7822 // XtManageChild(rc);
7825 Widget
CreateTextItem(Widget parent
, int len
, char *s
)
7827 QWidget
*widget
= new QWidget(parent
);
7829 QLabel
*label
= new QLabel(widget
);
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();
7843 layout
->addWidget(widget
);
7850 TItem_CBProc cbproc
;
7854 //static void titem_int_cb_proc(Widget w, XtPointer client_data, XtPointer call_data)
7857 // TItem_CBdata *cbdata = (TItem_CBdata *) client_data;
7858 // s = XmTextGetString(w);
7859 // cbdata->cbproc(w, s, cbdata->anydata);
7862 static void titem_int_cb_proc(Widget w
, XtPointer client_data
, XtPointer call_data
)
7865 TItem_CBdata
*cbdata
= (TItem_CBdata
*) client_data
;
7867 QLineEdit
*lineEdit
= qobject_cast
<QLineEdit
*>(w
);
7868 QByteArray ba
= lineEdit
->text().toAscii();
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)
7899 // * return the string from a text widget
7901 // * NB - newlines are converted to spaces
7906 // static char buf[MAX_STRING_LENGTH];
7908 // strncpy(buf, s = XmTextGetString(w), MAX_STRING_LENGTH - 1);
7912 // for (i--; i >= 0; i--) {
7913 // if (buf[i] == '\n') {
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?
7929 QLineEdit
*lineEdit
= (QLineEdit
*) w
;
7930 QString str
= lineEdit
->text();
7931 QByteArray ba
= str
.toAscii();
7932 buf
= copy_string(buf
, ba
.data());
7939 * xv_evalexpr - take a text field and pass it to the parser to evaluate
7941 //int xv_evalexpr(Widget w, double *answer)
7946 // s = XmTextGetString(w);
7948 // retval = graal_eval_expr(grace_get_graal(gapp->grace),
7949 // s, answer, gproject_get_top(gapp->gp));
7955 int xv_evalexpr(Widget w
, double *answer
)
7960 QLineEdit
*lineEdit
= (QLineEdit
*) w
;
7961 QString str
= lineEdit
->text();
7962 QByteArray ba
= str
.toAscii();
7965 retval
= graal_eval_expr(grace_get_graal(gapp
->grace
),
7966 s
, answer
, gproject_get_top(gapp
->gp
));
7972 // * xv_evalexpri - as xv_evalexpr, but for integers
7974 int xv_evalexpri(Widget w
, int *answer
)
7979 retval
= xv_evalexpr(w
, &buf
);
7981 *answer
= rint(buf
);
7987 //void xv_setstr(Widget w, char *s)
7990 // XmTextSetString(w, s ? s : "");
7993 void xv_setstr(Widget w
, char *s
)
7995 QLineEdit
*lineEdit
= (QLineEdit
*) w
;
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)
8008 //static Widget *savewidgets = NULL;
8009 //static int nsavedwidgets = 0;
8011 //static void savewidget(Widget w)
8015 // for (i = 0; i < nsavedwidgets; i++) {
8016 // if (w == savewidgets[i]) {
8021 // savewidgets = xrealloc(savewidgets, (nsavedwidgets + 1)*sizeof(Widget));
8022 // savewidgets[nsavedwidgets] = w;
8027 //static void deletewidget(Widget w)
8031 // for (i = 0; i < nsavedwidgets; i++) {
8032 // if (w == savewidgets[i]) {
8034 // for (; i < nsavedwidgets; i++) {
8035 // savewidgets[i] = savewidgets[i + 1];
8037 // savewidgets = xrealloc(savewidgets, nsavedwidgets*sizeof(Widget));
8038 // XtDestroyWidget(w);
8047 // * handle the close item on the WM menu
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);
8064 // * Manage and raise
8066 //void RaiseWindow(Widget w)
8068 // XtManageChild(w);
8069 // XMapRaised(XtDisplay(w), XtWindow(w));
8071 void RaiseWindow(Widget w
)
8077 //void DefineDialogCursor(Cursor c)
8079 // X11Stuff *xstuff = gapp->gui->xstuff;
8082 // for (i = 0; i < nsavedwidgets; i++) {
8083 // XDefineCursor(xstuff->disp, XtWindow(savewidgets[i]), c);
8085 // XFlush(xstuff->disp);
8088 //void UndefineDialogCursor(void)
8090 // X11Stuff *xstuff = gapp->gui->xstuff;
8093 // for (i = 0; i < nsavedwidgets; i++) {
8094 // XUndefineCursor(xstuff->disp, XtWindow(savewidgets[i]));
8096 // XFlush(xstuff->disp);
8099 //Widget CreateSeparator(Widget parent)
8103 // sep = XmCreateSeparator(parent, "sep", NULL, 0);
8104 // XtManageChild(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)
8142 // menubar = XmCreateMenuBar(parent, "menuBar", NULL, 0);
8145 Widget
CreateMenuBar(Widget parent
)
8147 QMenuBar
*menuBar
= new QMenuBar(parent
);
8152 //Widget CreateMenu(Widget parent, char *label, char mnemonic, int help)
8154 // Widget menupane, cascade;
8156 // char *name, ms[2];
8158 // name = label_to_resname(label, "Menu");
8159 // menupane = XmCreatePulldownMenu(parent, name, NULL, 0);
8162 // ms[0] = mnemonic;
8165 // str = XmStringCreateLocalized(label);
8166 // cascade = XtVaCreateManagedWidget("cascade",
8167 // xmCascadeButtonGadgetClass, parent,
8168 // XmNsubMenuId, menupane,
8169 // XmNlabelString, str,
8170 // XmNmnemonic, XStringToKeysym(ms),
8172 // XmStringFree(str);
8175 // XtVaSetValues(parent, XmNmenuHelpWidget, cascade, NULL);
8176 // CreateMenuButton(menupane, "On context", 'x',
8177 // ContextHelpCB, NULL);
8178 // CreateSeparator(menupane);
8181 // SetUserData(menupane, cascade);
8185 Widget
CreateMenu(Widget parent
, char *label
, char mnemonic
, int help
)
8187 QMenuBar
*menuBar
= (QMenuBar
*)parent
;
8190 int index
= l
.indexOf(mnemonic
);
8191 l
.insert(index
, "&");
8193 QMenu
*menu
= new QMenu(l
, menuBar
);
8194 menu
->setTearOffEnabled(true);
8197 menuBar
->addSeparator();
8198 CreateMenuButton(menu
, "On context", 'x',
8199 ContextHelpCB
, NULL
);
8200 CreateSeparator(menu
);
8203 menuBar
->addAction(menu
->menuAction());
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)
8225 // char *name, ms[2];
8227 // ms[0] = mnemonic;
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),
8238 // XmStringFree(str);
8240 // AddButtonCB(button, cb, data);
8244 Widget
CreateMenuButton(Widget parent
, char *label
, char mnemonic
,
8245 Button_CBProc cb
, void *data
)
8247 QMenu
*menu
= (QMenu
*)parent
;
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)
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);
8292 Widget
CreateMenuCloseButton(Widget parent
, Widget form
)
8296 wbut
= CreateMenuButtonA(parent
,
8297 "Close", 'C', "Esc", destroy_dialog_cb
, form
);
8302 //Widget CreateMenuHelpButton(Widget parent, char *label, char mnemonic,
8303 // Widget form, char *ha)
8307 // wbut = CreateMenuButton(parent, label, mnemonic, HelpCB, ha);
8308 // AddHelpCB(form, ha);
8312 Widget
CreateMenuHelpButton(Widget parent
, char *label
, char mnemonic
,
8313 Widget form
, char *ha
)
8317 wbut
= CreateMenuButton(parent
, label
, mnemonic
, HelpCB
, ha
);
8322 //Widget CreateMenuToggle(Widget parent, char *label, char mnemonic,
8323 // TB_CBProc cb, void *data)
8327 // char *name, ms[2];
8329 // ms[0] = mnemonic;
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,
8342 // XmStringFree(str);
8345 // AddToggleButtonCB(button, cb, data);
8350 Widget
CreateMenuToggle(Widget parent
, char *label
, char mnemonic
,
8351 TB_CBProc cb
, void *data
)
8353 QMenu
*menu
= (QMenu
*)parent
;
8356 int index
= l
.indexOf(mnemonic
);
8357 l
.insert(index
, "&");
8359 QAction
*action
= new QAction(l
, parent
);
8360 action
->setCheckable(true);
8363 AddToggleButtonCB((QWidget
*)action
, cb
, data
);
8366 menu
->addAction(action
);
8368 return (QWidget
*)action
;
8371 //Widget CreateMenuLabel(Widget parent, char *name)
8375 // lab = XmCreateLabel(parent, name, NULL, 0);
8376 // XtManageChild(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);
8405 // XtAddCallback(w, XmNhelpCallback, help_int_cb, (XtPointer) ha);
8407 WhatsThisListener::WhatsThisListener(QObject
*parent
)
8412 bool WhatsThisListener::eventFilter(QObject
*obj
, QEvent
*event
)
8414 if (event
->type() == QEvent::WhatsThis
) {
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;
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);
8445 // whelp = GetParent(whelp);
8449 // HelpCB(but, NULL);
8451 // XFreeCursor(xstuff->disp, cursor);
8453 void ContextHelpCB(Widget but
, void *data
)
8455 // X11Stuff *xstuff = gapp->gui->xstuff;
8460 QWhatsThis::enterWhatsThisMode();
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);
8470 // whelp = GetParent(whelp);
8474 // HelpCB(but, NULL);
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);
8494 // yesno_retval = TRUE;
8495 // /* process ok action */
8497 // case XmCR_CANCEL:
8498 // yesno_retval = FALSE;
8499 // /* process cancel action */
8504 //int yesnowin(char *msg, char *s1, char *s2, char *help_anchor)
8506 // static Widget dialog = NULL;
8508 // static char *ha = NULL;
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);
8530 // if (msg != NULL) {
8531 // str = XmStringCreateLocalized(msg);
8533 // str = XmStringCreateLocalized("Warning");
8535 // XtVaSetValues(dialog, XmNmessageString, str, NULL);
8536 // XmStringFree(str);
8538 // but = XtNameToWidget(dialog, "OK");
8540 // SetLabel(but, s1);
8542 // SetLabel(but, "OK");
8545 // but = XtNameToWidget(dialog, "Cancel");
8547 // SetLabel(but, s2);
8549 // SetLabel(but, "Cancel");
8552 // but = XtNameToWidget(dialog, "Help");
8554 // XtManageChild(but);
8556 // XtUnmanageChild(but);
8559 // RaiseWindow(dialog);
8561 // XtAddGrab(XtParent(dialog), True, False);
8562 // while (keep_grab || XtAppPending(app_con)) {
8563 // XtAppNextEvent(app_con, &event);
8564 // XtDispatchEvent(&event);
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
);
8574 msgBox
.setText(msg
);
8576 msgBox
.setText("Warning");
8580 msgBox
.setStandardButtons(QMessageBox::Ok
| QMessageBox::Cancel
| QMessageBox::Help
);
8582 msgBox
.setStandardButtons(QMessageBox::Ok
| QMessageBox::Cancel
);
8586 msgBox
.button(QMessageBox::Ok
)->setText(s1
);
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();
8598 case QMessageBox::Ok
:
8599 yesno_retval
= TRUE
;
8601 case QMessageBox::Cancel
:
8602 yesno_retval
= FALSE
;
8604 case QMessageBox::Help
:
8605 HelpCB(NULL
, help_anchor
);
8609 // should never be reached
8613 return yesno_retval
;
8617 //void SetLabel(Widget w, char *s)
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
)) {
8631 QLabel
*label
= (QLabel
*) w
;
8636 //void SetFixedFont(Widget w)
8638 // X11Stuff *xstuff = gapp->gui->xstuff;
8642 // f = XLoadQueryFont(xstuff->disp, "fixed");
8643 // xmf = XmFontListCreate(f, charset);
8644 // if (xmf == NULL) {
8645 // errmsg("Can't load font \"fixed\"");
8648 // XtVaSetValues(w, XmNfontList, xmf, NULL);
8649 // XmFontListFree(xmf);
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
) {
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
) {
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) {
8696 // for (i = 0; i < ngraph_selectors; i++) {
8697 // SetStorageChoiceQuark(graph_selectors[i], NULL);
8699 // for (i = 0; i < nssd_selectors; i++) {
8700 // SetStorageChoiceQuark(ssd_selectors[i], NULL);
8703 // if (etype == QUARK_ETYPE_MODIFY) {
8704 // /* update_graph_selectors(pr); */
8707 // return RETURN_SUCCESS;
8709 int clean_graph_selectors(Quark
*pr
, int etype
, void *data
)
8711 if (etype
== QUARK_ETYPE_DELETE
) {
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
);
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) {
8731 // for (i = 0; i < nframe_selectors; i++) {
8732 // SetStorageChoiceQuark(frame_selectors[i], NULL);
8735 // if (etype == QUARK_ETYPE_MODIFY) {
8736 // /* update_frame_selectors(pr); */
8739 // return RETURN_SUCCESS;
8741 int clean_frame_selectors(Quark
*pr
, int etype
, void *data
)
8743 if (etype
== QUARK_ETYPE_DELETE
) {
8745 for (i
= 0; i
< nframe_selectors
; i
++) {
8746 SetStorageChoiceQuark(frame_selectors
[i
], NULL
);
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) {
8760 // for (i = 0; i < nset_selectors; i++) {
8762 // StorageStructure *ss = set_selectors[i];
8764 // cg = get_set_choice_gr(ss);
8765 // if (!gr || cg == gr) {
8766 // SetStorageChoiceQuark(ss, NULL);
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}
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}
8809 //static XtActionsRec cstext_actions[] = {
8810 // {"cstext_edit_action", cstext_edit_action}
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
);
8831 TreeView::TreeView(QWidget
*parent
)
8834 setEditTriggers(QAbstractItemView::NoEditTriggers
);
8835 setAcceptDrops(true);
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
;
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
) {
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
);
8883 QTreeView::mouseMoveEvent(event
);
8887 void TreeView::dragEnterEvent(QDragEnterEvent
*event
)
8893 void TreeView::dropEvent(QDropEvent
*event
)
8896 QPersistentModelIndex index
= indexAt(event
->pos());
8898 if (drop_cbdata
&& index
.isValid()) {
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");
8911 case Qt::CopyAction
:
8912 e
.drop_action
= DROP_ACTION_COPY
;
8913 qDebug("DROP_ACTION_COPY");
8916 qDebug("DROP_ACTION_UKNOWN");
8921 if (drop_cbdata
->cbproc(&e
)) {
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();
8949 layout
->addWidget(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
;
8964 parentItem
= (QStandardItem
*) parent
;
8966 parentItem
= model
->invisibleRootItem();
8969 item
= new QStandardItem
;
8971 item
->setData(qVariantFromValue((void *) q
));
8974 parentItem
->insertRow(parentItem
->rowCount() + row
+ 1, item
);
8976 parentItem
->insertRow(row
, item
);
8982 void TreeDeleteItem(Widget w
, TreeItem
*item
)
8984 TreeView
*treeView
= (TreeView
*) w
;
8985 QStandardItemModel
*model
= (QStandardItemModel
*) treeView
->model();
8986 QStandardItem
*treeItem
= (QStandardItem
*) item
;
8989 int row
= treeItem
->row();
8990 QStandardItem
*parent
= treeItem
->parent();
8992 parent
= model
->invisibleRootItem();
8994 parent
->removeRow(row
);
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 *>();
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
;
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
;
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
));
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
;
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
));
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
));
9142 cbdata
->cbproc
= cbproc
;
9143 cbdata
->anydata
= anydata
;
9145 TreeView
*view
= (TreeView
*) cbdata
->w
;
9146 view
->setDropCallback(cbdata
);
9152 TableModel::TableModel(QObject
*parent
)
9153 : QAbstractTableModel(parent
)
9157 defaultColumnAlignment
= Qt::AlignLeft
| Qt::AlignVCenter
;
9158 defaultColumnLabelAlignment
= Qt::AlignLeft
| Qt::AlignVCenter
;
9159 defaultRowLabelAlignment
= Qt::AlignLeft
| Qt::AlignVCenter
;
9163 void TableModel::setRowCount(int rows
)
9165 if (rows
> cells
.size()) {
9167 for (int row
= 0; row
< rows
; ++row
) {
9168 cells
[row
].resize(this->ncols
);
9173 emit
nRowsOrColsChanged();
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
);
9185 emit
nRowsOrColsChanged();
9189 int TableModel::rowCount(const QModelIndex
& /* parent */) const
9194 int TableModel::columnCount(const QModelIndex
& /* parent */) const
9199 QVariant
TableModel::data(const QModelIndex
&index
, int role
) const
9203 if (!index
.isValid())
9206 if (role
== Qt::TextAlignmentRole
)
9207 return int(defaultColumnAlignment
);
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()]);
9219 event
.w
= cbdata
->w
;
9220 event
.row
= index
.row();
9221 event
.col
= index
.column();
9222 event
.anydata
= cbdata
->anydata
;
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
);
9249 QVariant
TableModel::headerData(int section
,
9250 Qt::Orientation orientation
,
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
];
9271 if (rowLabels
.size() > section
) {
9272 return rowLabels
[section
];
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();
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()));
9341 void TableView::closeEditor()
9343 TableModel
*tm
= (TableModel
*) model();
9345 closeEditor(tm
->newIndex(previous_row
, previous_col
));
9346 qDebug() << "closeEditor";
9349 void TableView::commitEdit()
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()) {
9371 col
= index
.column();
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
)) {
9385 openEditor(tm
->newIndex(row
, col
));
9390 int TableView::leaveCellEvent(int row
, int col
)
9396 if (row
!= -1 && col
!= -1) {
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
;
9407 event
.anydata
= leave_cbdata
->anydata
;
9408 ok
= leave_cbdata
->cbproc(&event
);
9413 qDebug() << "leaveCellEvent index invalid";
9424 int TableView::enterCellEvent(int row
, int col
)
9430 if (row
!= -1 && col
!= -1) {
9431 qDebug() << "enter cb" << "row" << row
<< "col" << col
;
9432 event
.w
= enter_cbdata
->w
;
9435 event
.anydata
= enter_cbdata
->anydata
;
9436 ok
= enter_cbdata
->cbproc(&event
);
9440 qDebug() << "enterCellEvent index invalid";
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);
9467 qDebug() << "closeEditor(index)";
9473 int default_col_width
;
9478 Widget
CreateTable(char *name
, Widget parent
, int nrows
, int ncols
, int nrows_visible
, int ncols_visible
)
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();
9523 layout
->addWidget(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();
9571 nr
= model
->rowCount();
9576 int TableGetNcols(Widget w
)
9578 QTableView
*view
= (QTableView
*) w
;
9579 TableModel
*model
= (TableModel
*) view
->model();
9582 nc
= model
->columnCount();
9587 void TableAddRows(Widget w
, int nrows
)
9589 QTableView
*view
= (QTableView
*) w
;
9590 TableModel
*model
= (TableModel
*) view
->model();
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();
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();
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();
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
;
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();
9674 case ALIGN_BEGINNING
:
9675 model
->setDefaultRowLabelAlignment(Qt::AlignLeft
);
9678 model
->setDefaultRowLabelAlignment(Qt::AlignHCenter
);
9681 model
->setDefaultRowLabelAlignment(Qt::AlignRight
);
9686 void TableSetDefaultColWidth(Widget w
, int width
)
9688 QTableView
*view
= (QTableView
*) w
;
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();
9708 case ALIGN_BEGINNING
:
9709 model
->setDefaultColumnAlignment(Qt::AlignLeft
);
9712 model
->setDefaultColumnAlignment(Qt::AlignHCenter
);
9715 model
->setDefaultColumnAlignment(Qt::AlignRight
);
9720 void TableSetDefaultColLabelAlignment(Widget w
, int align
)
9722 QTableView
*view
= (QTableView
*) w
;
9723 TableModel
*model
= (TableModel
*) view
->model();
9726 case ALIGN_BEGINNING
:
9727 model
->setDefaultColumnLabelAlignment(Qt::AlignLeft
);
9730 model
->setDefaultColumnLabelAlignment(Qt::AlignHCenter
);
9733 model
->setDefaultColumnLabelAlignment(Qt::AlignRight
);
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
;
9765 //Two views side by side
9768 void TableUpdateVisibleRowsCols(Widget w
)
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
;
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
]);
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
;
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
;
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
));
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
));
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
));
9973 cbdata
->cbproc
= cbproc
;
9974 cbdata
->anydata
= anydata
;
9976 TableView
*view
= (TableView
*) cbdata
->w
;
9977 view
->setLeaveCellCallback(cbdata
);
9980 bool HeaderView::event(QEvent
*e
)
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");
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
;
10009 case Qt::RightButton
:
10010 event
.button
= event
.button
^ RIGHT_BUTTON
;
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
);
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
));
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
);
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
)