Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / Examples / fontl.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/*
2 * WINGs demo: font lister
6830b057 dan2004-10-12 21:28:27 +00003 *
4153e2fd dan2003-01-16 23:30:45 +00004 * Copyright (c) 1998-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00005 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00006 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
6830b057 dan2004-10-12 21:28:27 +000018 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000019 * USA.
20 */
21
9d2e6ef9 scottc1998-09-29 22:36:29 +000022#include <stdlib.h>
23#include <stdio.h>
06f59b99 Carlos R. Mafra2008-11-06 01:37:44 +010024#include <stdint.h>
a20aebde dan2001-01-18 19:21:56 +000025#include <WINGs/WINGs.h>
26#include <WINGs/WUtil.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000027
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020028void wAbort()
9d2e6ef9 scottc1998-09-29 22:36:29 +000029{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020030 exit(0);
9d2e6ef9 scottc1998-09-29 22:36:29 +000031}
32
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020033void show(WMWidget * self, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +000034{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020035 char buf[60];
36 void *d;
37 WMLabel *l = (WMLabel *) data;
38 d = WMGetHangedData(self);
39 sprintf(buf, "%i - 0x%x - 0%o", (int)(uintptr_t) d, (int)(uintptr_t) d, (int)(uintptr_t) d);
40 WMSetLabelText(l, buf);
9d2e6ef9 scottc1998-09-29 22:36:29 +000041}
42
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020043void quit(WMWidget * self, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +000044{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020045 exit(0);
9d2e6ef9 scottc1998-09-29 22:36:29 +000046}
47
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020048int main(int argc, char **argv)
9d2e6ef9 scottc1998-09-29 22:36:29 +000049{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020050 Display *dpy;
51 WMWindow *win;
52 WMScreen *scr;
53 WMButton *lab, *l0 = NULL;
54 WMLabel *pos;
55 int x, y, c;
56 char buf[20];
9d2e6ef9 scottc1998-09-29 22:36:29 +000057
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020058 WMInitializeApplication("FontView", &argc, argv);
9d2e6ef9 scottc1998-09-29 22:36:29 +000059
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020060 dpy = XOpenDisplay("");
61 if (!dpy) {
62 wfatal("cant open display");
63 exit(0);
64 }
6830b057 dan2004-10-12 21:28:27 +000065
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020066 scr = WMCreateSimpleApplicationScreen(dpy);
9d2e6ef9 scottc1998-09-29 22:36:29 +000067
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020068 win = WMCreateWindow(scr, "main");
69 WMResizeWidget(win, 20 * 33, 20 + 20 * 9);
70 WMSetWindowTitle(win, "Font Chars");
71 WMSetWindowCloseAction(win, quit, NULL);
72 pos = WMCreateLabel(win);
73 WMResizeWidget(pos, 20 * 33, 20);
74 WMMoveWidget(pos, 10, 5);
9d2e6ef9 scottc1998-09-29 22:36:29 +000075
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020076 c = 0;
77 for (y = 0; y < 8; y++) {
78 for (x = 0; x < 32; x++, c++) {
79 lab = WMCreateCustomButton(win, WBBStateLightMask);
80 WMResizeWidget(lab, 20, 20);
81 WMMoveWidget(lab, 10 + x * 20, 30 + y * 20);
82 sprintf(buf, "%c", c);
83 WMSetButtonText(lab, buf);
84 WMSetButtonAction(lab, show, pos);
85 WMHangData(lab, (void *)(uintptr_t) c);
86 if (c > 0) {
87 WMGroupButtons(l0, lab);
88 } else {
89 l0 = lab;
90 }
91 }
92 }
93 WMRealizeWidget(win);
94 WMMapSubwidgets(win);
95 WMMapWidget(win);
96 WMScreenMainLoop(scr);
97 return 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +000098}