File: McCheckBox.c

package info (click to toggle)
mctools-lite 970129-5
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 1,672 kB
  • ctags: 1,658
  • sloc: ansic: 16,032; sh: 165; makefile: 71
file content (116 lines) | stat: -rw-r--r-- 3,666 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* Copyright (C) 1994 - 1996 
            Olav Woelfelschneider (wosch@rbg.informatik.th-darmstadt.de)

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Library General Public License as
  published by the Free Software Foundation; either version 2 of the
  License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Library General Public License for more details.

  You should have received a copy of the GNU Library General Public
  License along with this library; see the file COPYING.LIB.  If
  not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  Cambridge, MA 02139, USA.
*/


#include <X11/keysym.h>
#include <X11/cursorfont.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "McApp.h"
#include "McGadget.h"
#include "McCheckBox.h"

/**************************************************************************/

static unsigned char checkbox_bits[] = {
  0x63, 0x77, 0x3e, 0x1c, 0x3e, 0x77, 0x63,
};

#define MAKEPIX(x) \
  x=XCreateBitmapFromData(app->display, RootWindow(app->display, app->screen),\
			  x##_bits, 12, 12)

static void MakePixmaps(McApp *app) {

  if (app->checkbox_on) return;

  app->checkbox_on=
    XCreateBitmapFromData(app->display, RootWindow(app->display, app->screen),
			  checkbox_bits, 7, 7);
}

/**************************************************************************/

McSpecialInfo *McCreateCheckBox(McApp *app) {
  McCheckBox *CheckBox = (McCheckBox *) calloc(sizeof(McCheckBox), 1);
  CheckBox->specialInfo.updateProc = McCheckBoxUpdate;
  MakePixmaps(app);
  return (McSpecialInfo *)CheckBox;
}

/**************************************************************************/

void McCheckBoxUpdate(McGadget *gadget, int busy, int all) {
  McWindow *mcw=gadget->mcw;
  McApp *app=mcw->app;
  int y=(gadget->height-12)>>1;

  if (gadget->flags & GAD_3D)
    McAppDrawbox(mcw, gadget->win, BW+2, BW+y, 9, 9, _3D_IN);
  else
    XDrawRectangle(app->display, gadget->win, app->gc[GC_NORMAL],
		   3, y+1, 10, 10);

  XFillRectangle(app->display, gadget->win, app->gc[GC_BRIGHT],
		 BW+2, y+BW, 9, 9);

  if (gadget->flags&GAD_SELECTED) {
    XSetBackground(app->display, app->gc[GC_NORMAL],
		   app->colors[COL_BRIGHT]);
    XCopyPlane(app->display, app->checkbox_on, gadget->win, app->gc[GC_NORMAL],
	      0, 0, 7, 7, BW+3, y+BW+1, 1);
    XSetBackground(app->display, app->gc[GC_NORMAL],
		   app->colors[COL_BACKGROUND]);
  }
  McDrawFocusMark(gadget, COL_BACKGROUND);
}

/**************************************************************************/

McGadget *MakeCheckBox(McWindow *mcw, int x, int y, int w, int h,
		    int id,
		    const char *str, void (*callback)(struct McGadget *)) {

  McGadget *gadget;
  McText *txt;

  if (!str) str="CheckBox";
  txt = McCreateText(mcw, (unsigned char *)str, mcw->app->gc[GC_NORMAL],
		     mcw->app->defaultFont, 16, 0);
  if (w<=0) w=16+txt->width+(BW<<2);
  if (h<=0) h=txt->height+BW+BW;

  if (x==0) x=(mcw->w>>1)-(w>>1);	/* Center */
  if (y==0) y=(mcw->h>>1)-(h>>1);
  if (x<0) x=mcw->w+x-w-BW-BW-BW;	/* Right justify */
  if (y<0) y=mcw->h+y-h-BW-BW-BW;

  gadget = McCreateGadget(mcw,
			  GAD_3D | GAD_HNONE | GAD_ACTIVE | GAD_NOFILL|
			  GAD_NOSTIPPLE | GAD_TOGGLE,
			  CHECKBOXGADGET, x, y, w, h);
  txt->y = ((gadget->height - txt->height)>>1);
  gadget->normalLabel = txt;
  gadget->specialInfo = McCreateCheckBox(mcw->app);
  gadget->callbackUp = callback;
  return gadget;
}