3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
8 * Full author contact details are available in file CREDITS
17 #if defined(__cplusplus)
23 int nx, ny; /**< Dimensions of the table */
24 int dx, dy; /**< Size of each item */
25 int bx, by; /**< Bitmap's position */
26 int bw, bh; /**< Bitmap dimensions */
27 unsigned char const * bdata; /**< Bitmap data */
28 int maxi; /**< Number of items */
29 int i; /**< Current position */
30 int mousebut; /**< mouse button pushed */
31 Pixmap pix; /**< Pixmap from data (temporal) */
35 int handle_bitmaptable(FL_OBJECT * ob, int event, FL_Coord mx,
36 FL_Coord my, int key, void * xev);
39 FL_OBJECT * fl_create_bmtable(int type, FL_Coord x, FL_Coord y,
40 FL_Coord w, FL_Coord h, char const * label)
44 ob = fl_make_object(FL_BMTABLE, type, x, y, w, h, label, handle_bitmaptable);
45 ob->boxtype = FL_BMTABLE_BOXTYPE;
46 ob->spec = fl_calloc(1, sizeof(BMTABLE_SPEC));
47 ((BMTABLE_SPEC *)ob->spec)->pix = 0;
48 ((BMTABLE_SPEC *)ob->spec)->bdata = 0;
49 ((BMTABLE_SPEC *)ob->spec)->mousebut = -1;
54 FL_OBJECT *fl_add_bmtable(int type, FL_Coord x, FL_Coord y,
55 FL_Coord w, FL_Coord h, char const *label)
59 ob = fl_create_bmtable(type, x, y, w, h, label);
60 fl_add_object(fl_current_form, ob);
66 static void draw_bitmaptable(FL_OBJECT *ob)
70 FL_Coord xx, yy, ww, hh;
71 BMTABLE_SPEC * sp = (BMTABLE_SPEC *)ob->spec;
72 GC gc = fl_state[fl_get_vclass()].gc[0];
75 /* draw the bounding box first */
76 lx = sp->maxi % sp->nx;
77 fl_drw_box(ob->boxtype, ob->x, ob->y, ob->w, ob->h, ob->col1, ob->bw);
80 xx = ob->x + sp->dx * lx + i;
81 yy = ob->y + (sp->ny - 1) * sp->dy + i;
82 ww = ob->x + ob->w - xx - i;
83 hh = ob->y + ob->h - yy - i;
84 fl_drw_frame(FL_DOWN_FRAME, xx, yy, ww, hh, ob->col1, ob->bw);
85 fl_rectf(xx, yy, ww + i, hh + i, ob->col1);
88 /* draw the background bitmap */
91 sp->pix = XCreatePixmapFromBitmapData(fl_get_display(), fl_winget(),
94 fl_get_flcolor(ob->lcol), fl_get_flcolor(ob->col1),
95 /*DefaultDepth(fl_get_display(), DefaultScreen(fl_get_display()))*/ fl_state[fl_get_vclass()].depth);
96 XFlush(fl_get_display());
100 /* Adjust position */
101 if (sp->bx < FL_abs(ob->bw) + 1) {
102 xx = FL_abs(ob->bw) - sp->bx + 1;
103 mx = ob->x + FL_abs(ob->bw) + 1;
108 if (sp->by < FL_abs(ob->bw) + 1) {
109 yy = FL_abs(ob->bw) - sp->by + 1;
110 my = ob->y + FL_abs(ob->bw) + 1;
115 ww = (mx + sp->bw < ob->x + ob->w - FL_abs(ob->bw)) ?
116 sp->bw: ob->x + ob->w - FL_abs(ob->bw) - mx;
117 hh = (my + sp->bh < ob->y + ob->h - FL_abs(ob->bw)) ?
118 sp->bh: ob->y + ob->h - FL_abs(ob->bw) - my;
121 j = hh - ((lx) ? sp->dy+2*i: 0);
122 XCopyArea(fl_get_display(), sp->pix, fl_winget(), gc, xx, yy, ww, j, mx, my);
123 XFlush(fl_get_display());
125 XCopyArea(fl_get_display(), sp->pix, fl_winget(), gc, xx,
126 yy+j, lx*sp->dx-2*i, hh-j, mx, my+j);
127 XFlush(fl_get_display());
132 /* draw the grid if type > FLAT */
133 if (ob->type > FL_BMTABLE_FLAT) {
137 for (yy= ob->y; yy<= my; yy+= sp->dy) {
138 if (ob->boxtype!= FL_FLAT_BOX && (yy == ob->y || yy>my-sp->dy))
140 if (lx>0 && yy>= my-sp->dy - sp->dy/2)
142 fl_diagline(ob->x, yy, ww, 1, FL_BOTTOM_BCOL);
143 fl_diagline(ob->x, yy+1, ww-2, 1, FL_TOP_BCOL);
146 for (xx= ob->x; xx<= mx; xx+= sp->dx) {
147 if (ob->boxtype!= FL_FLAT_BOX && (xx == ob->x || xx>mx-sp->dx))
149 if (lx>0 && xx>= ob->x + lx * sp->dx)
150 hh = (sp->ny - 1) * sp->dy;
151 fl_diagline(xx, ob->y, 1, hh, FL_RIGHT_BCOL);
152 fl_diagline(xx+1, ob->y + 1, 1, hh - 2, FL_LEFT_BCOL);
156 /* Simulate a pushed button */
157 if (ob->pushed && 0 <= sp->i && sp->i < sp->maxi) {
160 ww = sp->dx-2*FL_abs(ob->bw);
161 hh = sp->dy-2*FL_abs(ob->bw);
162 xx = ob->x + sp->dx*i + FL_abs(ob->bw);
163 yy = ob->y + sp->dy*j + FL_abs(ob->bw);
164 fl_drw_frame(FL_DOWN_FRAME, xx, yy, ww, hh, ob->col1, ob->bw);
169 int handle_bitmaptable(FL_OBJECT * ob, int event, FL_Coord mx,
170 FL_Coord my, int key, void * xev)
172 /* Silence warning about unused parameter */
176 BMTABLE_SPEC * sp = (BMTABLE_SPEC *)ob->spec;
180 draw_bitmaptable(ob);
183 if (!ob->belowmouse) { /* This never happens. Why? */
185 fl_redraw_object(ob);
188 i = (mx - ob->x)/sp->dx; j = (my - ob->y)/sp->dy;
189 if (i>= 0 && i< sp->nx && j>= 0 && j< sp->ny) {
191 if (i >= sp->maxi) i = -1;
194 fl_redraw_object(ob);
200 i = (mx - ob->x)/sp->dx + ((my - ob->y)/sp->dy)*sp->nx;
201 if (0 <= i && i < sp->maxi) {
203 fl_redraw_object(ob);
208 fl_redraw_object(ob);
212 XFreePixmap(fl_get_display(), sp->pix);
213 XFlush(fl_get_display());
215 fl_free(((BMTABLE_SPEC*)ob->spec));
223 * The table has nx columns of dx width each and ny rows of dy height each.
224 * Initially the position of the firts item is supposed to be the same that
225 * the object position (x, y), and the number of items is supposed to be
228 * The user could change these later. See below.
230 void fl_set_bmtable_data(FL_OBJECT * ob, int nx, int ny, int bw, int bh,
231 unsigned char const * bdata)
233 BMTABLE_SPEC * sp = (BMTABLE_SPEC *)ob->spec;
237 sp->bx = FL_abs(ob->bw);
238 sp->by = FL_abs(ob->bw);
242 sp->maxi = sp->nx * sp->ny;
250 void fl_set_bmtable_pixmap_data(FL_OBJECT * ob, int nx, int ny,
253 BMTABLE_SPEC * sp = (BMTABLE_SPEC *)ob->spec;
255 Pixmap dummy_shapemask = 0;
256 XpmAttributes dumb_attributes;
259 sp->bx = FL_abs(ob->bw);
260 sp->by = FL_abs(ob->bw);
264 sp->maxi = sp->nx * sp->ny;
266 dumb_attributes.colormap = fl_state[fl_get_vclass()].colormap;
267 dumb_attributes.closeness = 30000;
268 dumb_attributes.valuemask = XpmColormap | XpmCloseness;
269 if (XCreatePixmapFromData(fl_get_display(), fl_winget(), pdata,
270 &(sp->pix), &dummy_shapemask,
271 &dumb_attributes) == XpmSuccess) {
272 sp->bw = dumb_attributes.width;
273 sp->bh = dumb_attributes.height;
274 XpmFreeAttributes(&dumb_attributes);
275 if (dummy_shapemask) {
276 XFreePixmap(fl_get_display(), dummy_shapemask);
284 * This function works only for X11R6 or later
286 #if XlibSpecificationRelease > 5
288 void fl_set_bmtable_file(FL_OBJECT * ob, int nx, int ny, char const * filename)
294 unsigned char * bdata;
296 if (XReadBitmapFileData(filename, &bw, &bh,
297 &bdata, &xh, &yh) == BitmapSuccess)
298 fl_set_bmtable_data(ob, nx, ny, bw, bh, bdata);
299 XFlush(fl_get_display());
304 void fl_set_bmtable_file(FL_OBJECT * ob, int nx, int ny, char const * filename)
306 fprintf(stderr, "Set bmtable file: Sorry, I need X11 release 6 to do "
314 void fl_set_bmtable_pixmap_file(FL_OBJECT *ob, int nx, int ny, char const *filename)
316 /* extern Colormap color_map; */
317 BMTABLE_SPEC *sp = (BMTABLE_SPEC *)ob->spec;
319 Pixmap dummy_shapemask = 0;
320 XpmAttributes dumb_attributes;
321 XpmColorSymbol xpm_col;
324 sp->bx = FL_abs(ob->bw);
325 sp->by = FL_abs(ob->bw);
329 sp->maxi = sp->nx * sp->ny;
333 xpm_col.value = "None";
334 xpm_col.pixel = fl_get_flcolor(ob->col1);
335 dumb_attributes.colormap = fl_state[fl_get_vclass()].colormap;
336 dumb_attributes.numsymbols = 1;
337 dumb_attributes.colorsymbols = &xpm_col;
338 dumb_attributes.closeness = 30000;
339 dumb_attributes.valuemask = XpmColormap | XpmCloseness | XpmColorSymbols;
341 if (XReadPixmapFile(fl_get_display(), fl_winget(), (char *)filename,
342 &(sp->pix), &dummy_shapemask,
343 &dumb_attributes) == XpmSuccess) {
344 sp->bw = dumb_attributes.width;
345 sp->bh = dumb_attributes.height;
346 XpmFreeAttributes(&dumb_attributes);
347 if (dummy_shapemask) {
348 XFreePixmap(fl_get_display(), dummy_shapemask);
351 /* XFlush(fl_get_display()); */
357 * This function allows to adjust the position of the first item and its
358 * size (dx, dy). The input values are incremental, not absolute.
360 void fl_set_bmtable_adjust(FL_OBJECT *ob, int px, int py, int dx, int dy)
362 BMTABLE_SPEC *sp = (BMTABLE_SPEC *)ob->spec;
372 * This function returns the table's selected position.
374 int fl_get_bmtable(FL_OBJECT *ob)
376 if ((BMTABLE_SPEC *)ob->spec)
377 return ((BMTABLE_SPEC *)ob->spec)->i;
384 * You can change the max number of items if you want.
386 void fl_set_bmtable_maxitems(FL_OBJECT * ob, int i)
388 if (i > 0 && (BMTABLE_SPEC *)ob->spec)
389 ((BMTABLE_SPEC *)ob->spec)->maxi = i;
393 int fl_get_bmtable_maxitems(FL_OBJECT * ob)
395 if ((BMTABLE_SPEC *)ob->spec)
396 return ((BMTABLE_SPEC *)ob->spec)->maxi;
402 void fl_replace_bmtable_item(FL_OBJECT * ob, int id, int cw, int ch, char * data)
404 /* Silence warnings about unused parameters */
411 fprintf(stderr, "Replace bmtable item: Sorry, not yet implemented!\n");
415 void fl_get_bmtable_item(FL_OBJECT * ob, int id, int * cw, int * ch, char * data)
417 /* Silence warnings about unused parameters */
424 fprintf(stderr, "Get bmtable item: Sorry, not yet implemented!\n");
427 void fl_set_bmtable(FL_OBJECT * ob, int pushed, int pos)
429 if ((BMTABLE_SPEC *)ob->spec)
430 ((BMTABLE_SPEC *)ob->spec)->i = (pushed) ? pos: -1;
434 int fl_get_bmtable_numb(FL_OBJECT *ob)
436 if ((BMTABLE_SPEC *)ob->spec)
437 return ((BMTABLE_SPEC *)ob->spec)->mousebut;
443 Pixmap fl_get_bmtable_pixmap(FL_OBJECT * ob)
445 if ((BMTABLE_SPEC *)ob->spec)
446 return ((BMTABLE_SPEC *)ob->spec)->pix;
452 void fl_draw_bmtable_item(FL_OBJECT * ob, int i, Drawable d, int xx, int yy)
458 GC gc = fl_state[fl_get_vclass()].gc[0];
459 BMTABLE_SPEC * sp = (BMTABLE_SPEC *)ob->spec;
462 x = (i % sp->nx)*sp->dx + FL_abs(ob->bw);
463 y = (i/sp->nx)*sp->dy + FL_abs(ob->bw);
464 w = sp->dx-2*FL_abs(ob->bw);
465 h = sp->dy-2*FL_abs(ob->bw);
466 XCopyArea(fl_get_display(), sp->pix, d, gc, x, y, w, h, xx, yy);
467 XFlush(fl_get_display());
471 /* Free the current bitmap and pixmap in preparation for installing a new one */
472 void fl_free_bmtable_bitmap(FL_OBJECT * ob)
474 BMTABLE_SPEC * sp = (BMTABLE_SPEC *)ob->spec;
476 /* dump the temporary pixmap */
478 XFreePixmap(fl_get_display(), sp->pix);
479 XFlush(fl_get_display());
483 /* and free the space taken by bdata etc. */
484 if (sp && sp->bdata) {
485 fl_free((void*)sp->bdata);
490 /* Free the current pixmap in preparation for installing a new one */
491 /* This is needed when using data instead of files to set bitmaps */
492 void fl_free_bmtable_pixmap(FL_OBJECT *ob)
494 BMTABLE_SPEC * sp = (BMTABLE_SPEC *)ob->spec;
496 /* dump the temporary pixmap */
498 XFreePixmap(fl_get_display(), sp->pix);
499 XFlush(fl_get_display());
504 #if defined(__cplusplus)