I am trying to use XbaeMatrix to display tabular/matrix data but I do not want the cells to be editable.
I can not find how to achieve that.
This is what I have tried:
/*
* xbae_example.c
* Minimal XbaeMatrix demo (C89-compatible)
*/
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xbae/Matrix.h>
int main(int argc, char *argv[])
{
XtAppContext app;
Widget toplevel, form, matrix;
static String column_labels[] = { "A", "B", "C" };
static String row0[] = { "1", "2", "3" };
static String row1[] = { "4", "5", "6" };
static String row2[] = { "7", "8", "9" };
static String *rows[] = { row0, row1, row2 };
toplevel = XtVaAppInitialize(&app, "XbaeDemo", NULL, 0,
&argc, argv, NULL, NULL);
form = XtVaCreateManagedWidget("form",
xmFormWidgetClass, toplevel,
NULL);
matrix = XtVaCreateManagedWidget("matrix",
xbaeMatrixWidgetClass, form,
XmNrows, 3,
XmNcolumns, 3,
XmNrowLabels, NULL,
XmNcolumnLabels, column_labels,
XmNcells, rows,
XmNeditable, False,
XmNcellHighlightThickness, 0,
XmNtraversalOn, False,
NULL);
XtRealizeWidget(toplevel);
XtAppMainLoop(app);
return 0;
}
# Simple Makefile for xbae_example
CC = cc
CFLAGS = -I/usr/local/include -Wall
LDFLAGS = -L/usr/local/lib -lXbae -lXm -lXt -lX11
xbae_example: xbae_example.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
in particular this is the resource tried to make the matrix not editable:
XmNeditable, False,
but the XbaeMatrix cells remain editable, while my intention is them being non editable.
any help/hint is welcomed.
Some of the comments focus on phrasing rather than the technical issue itself. For completeness, here’s the working solution to the Motif/Xbae problem:
The right mechanism for making cells non-editable is the XmNenterCellCallback which is invoked immediately before a cell is to be edited. It receives a structure with a field named doit
Setting doit=False for a given (row,column) prevents editing of that cell.
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xbae/Matrix.h>
/* Callback: called before a cell is edited */
void block_all_cells(Widget w, XtPointer client, XtPointer call)
{
XbaeMatrixEnterCellCallbackStruct *cbs =
(XbaeMatrixEnterCellCallbackStruct *)call;
/* make every cell non-editable */
cbs->doit = False;
}
int main(int argc, char *argv[])
{
XtAppContext app;
Widget toplevel, form, matrix;
static String col_labels[] = { "A", "B", "C" };
static String row0[] = { "1", "2", "3" };
static String row1[] = { "4", "5", "6" };
static String row2[] = { "7", "8", "9" };
static String *rows[] = { row0, row1, row2 };
toplevel = XtVaAppInitialize(&app, "XbaeDemo", NULL, 0, &argc, argv, NULL, NULL);
form = XtVaCreateManagedWidget("form", xmFormWidgetClass, toplevel, NULL);
matrix = XtVaCreateManagedWidget(
"matrix", xbaeMatrixWidgetClass, form,
XmNrows, 3,
XmNcolumns, 3,
XmNcolumnLabels, col_labels,
XmNcells, rows,
NULL
);
/* attach callback to block edits */
XtAddCallback(matrix, XmNenterCellCallback, block_all_cells, NULL);
XtRealizeWidget(toplevel);
XtAppMainLoop(app);
return 0;
}