1 /*
2  * Copyright(c) 1992 Bell Communications Research, Inc. (Bellcore)
3  *                        All rights reserved
4  *
5  * Copyright � 2001 by the LessTif Developers
6  *
7  * Permission to use, copy, modify and distribute this material for
8  * any purpose and without fee is hereby granted, provided that the
9  * above copyright notice and this permission notice appear in all
10  * copies, and that the name of Bellcore not be used in advertising
11  * or publicity pertaining to this material without the specific,
12  * prior written permission of an authorized representative of
13  * Bellcore.
14  *
15  * BELLCORE MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES, EX-
16  * PRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE, INCLUDING, BUT
17  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18  * FITNESS FOR ANY PARTICULAR PURPOSE, AND THE WARRANTY AGAINST IN-
19  * FRINGEMENT OF PATENTS OR OTHER INTELLECTUAL PROPERTY RIGHTS.  THE
20  * SOFTWARE IS PROVIDED "AS IS", AND IN NO EVENT SHALL BELLCORE OR
21  * ANY OF ITS AFFILIATES BE LIABLE FOR ANY DAMAGES, INCLUDING ANY
22  * LOST PROFITS OR OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES RELAT-
23  * ING TO THE SOFTWARE.
24  *
25  * $Id: matrix.c,v 1.8 2006/05/15 15:57:04 tobiasoed Exp $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <XbaeConfig.h>
30 #endif
31 #include <stdlib.h>
32 #ifdef USE_EDITRES
33 #include <X11/Intrinsic.h>
34 #include <X11/Xmu/Editres.h>
35 #endif
36 #include <Xbae/Matrix.h>
37 
38 static String fallback[] = {
39 	"Matrix*mw.rowLabels:		1, 2, 3, 4, 5, 6",
40 	"Matrix*mw.columns:		5",
41 	"Matrix*mw.rows:		6",
42 	"Matrix*mw.columnWidths:	8, 3, 10, 10, 10",
43 	"Matrix*mw.allowColumnResize:	True",
44 	"Matrix*mw.cells:		Orange, 12, Rough, Inches, Large\\n"
45 	"				Blue, 323, Smooth, Feet, Medium\\n"
46 	"				Yellow, 456, Bristly, Meters, Large\\n"
47 	"				Green, 1, Knobby, Miles, Small\\n"
48 	"				Pink, 33, Hairy, Quarts, Small\\n"
49 	"				Black, 7, Silky, Gallons, Small",
50 	"Matrix*mw.cellBackgrounds:	white, antiquewhite, white, white, antiquewhite\\n"
51 	"				white, antiquewhite, white, white, antiquewhite\\n"
52 	"				white, antiquewhite, white, white, antiquewhite\\n"
53 	"				white, antiquewhite, white, white, antiquewhite\\n"
54 	"				white, antiquewhite, white, white, antiquewhite\\n"
55 	"				white, antiquewhite, white, white, antiquewhite",
56 	"Matrix*mw.colors: 		blue, black, blue, blue, black\\n"
57 	"				blue, black, blue, blue, black\\n"
58 	"				blue, black, blue, blue, black\\n"
59 	"				blue, black, blue, blue, black\\n"
60 	"				blue, black, blue, blue, black\\n"
61 	"				blue, black, blue, blue, black",
62 	"Matrix*mw.columnLabels:	Color, #, Texture, Measure, Size",
63 	"Matrix*mw.columnLabelAlignments:alignment_beginning, alignment_center,"
64 	"				alignment_beginning, alignment_beginning,"
65 	"				alignment_beginning",
66 	"Matrix*mw.columnAlignments:	alignment_beginning, alignment_end,"
67 	"				alignment_beginning, alignment_beginning,"
68 	"				alignment_beginning",
69 	"Matrix*labelFont:		-*-helvetica-bold-r-*-*-14-*-*-*-*-*-*-*",
70 	"Matrix*fontList:		-*-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*",
71 	"Matrix*cellHighlightThickness: 2",
72 	"Matrix*cellShadowThickness:	2",
73 	"Matrix*cellMarginWidth:	0",
74 	"Matrix*cellMarginHeight:	3",
75 	"Matrix*gridType:		grid_cell_shadow",
76 	"Matrix*cellShadowType:		shadow_in",
77 	"Matrix*rowLabelColor:		Red",
78 	"Matrix*columnLabelColor:	Blue",
79 	"Matrix*mw.buttonLabels:	True",
80 	"Matrix*mw.allowColumnResize:	True",
81 	NULL
82 };
83 
84 void
labelCB(Widget mw,XtPointer cd,XtPointer cb)85 labelCB(Widget mw, XtPointer cd, XtPointer cb)
86 {
87     XbaeMatrixLabelActivateCallbackStruct *cbs =
88 	( XbaeMatrixLabelActivateCallbackStruct * )cb;
89 
90     if( cbs->row_label )
91 	if( XbaeMatrixIsRowSelected( mw, cbs->row ) )
92 	    XbaeMatrixDeselectRow( mw, cbs->row );
93 	else
94 	    XbaeMatrixSelectRow( mw, cbs->row );
95     else
96 	if( XbaeMatrixIsColumnSelected( mw, cbs->column ) )
97 	    XbaeMatrixDeselectColumn( mw, cbs->column );
98 	else
99 	    XbaeMatrixSelectColumn( mw, cbs->column );
100 }
101 
102 /*
103  * Simple example of loaded Matrix
104  */
105 
106 int
main(int argc,char * argv[])107 main(int argc, char *argv[])
108 {
109     Widget toplevel, mw;
110     XtAppContext app;
111 
112     toplevel = XtVaAppInitialize(&app, "Matrix",
113 				 NULL, 0,
114 				 &argc, argv,
115 				 fallback,
116 				 NULL);
117 #ifdef USE_EDITRES
118     XtAddEventHandler( toplevel, (EventMask)0, True,
119                        _XEditResCheckMessages, NULL);
120 #endif
121 
122     XFontStruct *plain_font = XLoadQueryFont(
123 		XtDisplay(toplevel),
124 		"-*-helvetica-medium-o-*-*-10-*-*-*-*-*-*-*");
125 
126 #if 1
127     XmFontListEntry font_list_entry = XmFontListEntryCreate(
128         XmFONTLIST_DEFAULT_TAG,
129         XmFONT_IS_FONT,
130         plain_font);
131 
132     XmFontList plain_font_list = XmFontListAppendEntry(
133 		NULL,
134 		font_list_entry);
135 #else
136     XmFontList plain_font_list = XmFontListCreate(
137 		plain_font,
138 		XmSTRING_DEFAULT_CHARSET);
139 #endif
140 
141     printf("plain font: %d plain font list %d\n",plain_font == NULL, plain_font_list == NULL);
142 
143     mw = XtVaCreateManagedWidget("mw",
144 				 xbaeMatrixWidgetClass, toplevel,
145                  XmNlabelFont,	    plain_font_list,
146 	             XmNfontList,	    plain_font_list,
147 				 NULL);
148 
149     XmFontListEntryFree(&font_list_entry);
150     XmFontListFree(plain_font_list);
151 
152     XtAddCallback(mw, XmNlabelActivateCallback, labelCB, NULL);
153 
154     XtRealizeWidget(toplevel);
155     XtAppMainLoop(app);
156 
157     /*NOTREACHED*/
158     return 0;
159 }
160 
161