Change to the linux kernel coding style
authorCarlos R. Mafra <crmafra@gmail.com>
Wed, 19 Aug 2009 22:59:40 +0000 (20 00:59 +0200)
committerCarlos R. Mafra <crmafra@gmail.com>
Wed, 19 Aug 2009 22:59:40 +0000 (20 00:59 +0200)
    for arq in `git ls-files *.c`; do
    echo $arq;
    indent -linux -l115 $arq;
    done

The different line break at 115 columns is because
I use a widescreen monitor :-)

209 files changed:
WINGs/Examples/colorpick.c
WINGs/Examples/connect.c
WINGs/Examples/fontl.c
WINGs/Examples/puzzle.c
WINGs/Examples/server.c
WINGs/Extras/test.c
WINGs/Extras/wtabledelegates.c
WINGs/Extras/wtableview.c
WINGs/Tests/mywidget.c
WINGs/Tests/testmywidget.c
WINGs/Tests/wmfile.c
WINGs/Tests/wmquery.c
WINGs/Tests/wtest.c
WINGs/array.c
WINGs/bagtree.c
WINGs/configuration.c
WINGs/connection.c
WINGs/data.c
WINGs/dragcommon.c
WINGs/dragdestination.c
WINGs/dragsource.c
WINGs/error.c
WINGs/findfile.c
WINGs/handlers.c
WINGs/hashtable.c
WINGs/host.c
WINGs/international.c
WINGs/memory.c
WINGs/misc.c
WINGs/notification.c
WINGs/proplist.c
WINGs/puzzle.c
WINGs/selection.c
WINGs/snprintf.c
WINGs/string.c
WINGs/tree.c
WINGs/userdefaults.c
WINGs/usleep.c
WINGs/wapplication.c
WINGs/wappresource.c
WINGs/wballoon.c
WINGs/wbox.c
WINGs/wbrowser.c
WINGs/wbutton.c
WINGs/wcolor.c
WINGs/wcolorpanel.c
WINGs/wcolorwell.c
WINGs/wevent.c
WINGs/wfilepanel.c
WINGs/wfont.c
WINGs/wfont_noxft.c
WINGs/wfont_wchar.c
WINGs/wfontpanel.c
WINGs/wframe.c
WINGs/widgets.c
WINGs/winputmethod.c
WINGs/wlabel.c
WINGs/wlist.c
WINGs/wmenuitem.c
WINGs/wmisc.c
WINGs/wpanel.c
WINGs/wpixmap.c
WINGs/wpopupbutton.c
WINGs/wprogressindicator.c
WINGs/wruler.c
WINGs/wscroller.c
WINGs/wscrollview.c
WINGs/wslider.c
WINGs/wsplitview.c
WINGs/wtabview.c
WINGs/wtext.c
WINGs/wtextfield.c
WINGs/wutil.c
WINGs/wview.c
WINGs/wwindow.c
WPrefs.app/Appearance.c
WPrefs.app/Configurations.c
WPrefs.app/Expert.c
WPrefs.app/Focus.c
WPrefs.app/Font.c
WPrefs.app/FontSimple.c
WPrefs.app/Icons.c
WPrefs.app/KeyboardSettings.c
WPrefs.app/KeyboardShortcuts.c
WPrefs.app/Menu.c
WPrefs.app/MenuPreferences.c
WPrefs.app/MouseSettings.c
WPrefs.app/Paths.c
WPrefs.app/Preferences.c
WPrefs.app/TexturePanel.c
WPrefs.app/Themes.c
WPrefs.app/WPrefs.c
WPrefs.app/WindowHandling.c
WPrefs.app/Workspace.c
WPrefs.app/double.c
WPrefs.app/editmenu.c
WPrefs.app/imagebrowser.c
WPrefs.app/main.c
WPrefs.app/xmodifier.c
plugins/libwmfun/bilinear.c
plugins/libwmfun/fade.c
plugins/libwmfun/generic.c
plugins/libwmfun/getopt.c
plugins/libwmfun/getopt1.c
plugins/libwmfun/wave.c
src/actions.c
src/appicon.c
src/application.c
src/appmenu.c
src/balloon.c
src/client.c
src/colormap.c
src/cycling.c
src/defaults.c
src/dialog.c
src/dock.c
src/dockedapp.c
src/event.c
src/framewin.c
src/geomview.c
src/icon.c
src/main.c
src/menu.c
src/menureader.c
src/misc.c
src/monitor.c
src/motif.c
src/moveres.c
src/pixmap.c
src/placement.c
src/properties.c
src/resources.c
src/rootmenu.c
src/screen.c
src/session.c
src/shutdown.c
src/stacking.c
src/startup.c
src/superfluous.c
src/switchmenu.c
src/switchpanel.c
src/text.c
src/texture.c
src/usermenu.c
src/wcore.c
src/wdefaults.c
src/window.c
src/winmenu.c
src/winspector.c
src/wmspec.c
src/workspace.c
src/wsmap.c
src/wsound.c
src/xdnd.c
src/xinerama.c
src/xmodifier.c
src/xutil.c
test/notest.c
test/wtest.c
util/convertfonts.c
util/directjpeg.c
util/fontconv.c
util/geticonset.c
util/getstyle.c
util/seticons.c
util/setstyle.c
util/wdread.c
util/wdwrite.c
util/wmagnify.c
util/wmsetbg.c
util/wmsetup.c
util/wxcopy.c
util/wxpaste.c
wmlib/app.c
wmlib/command.c
wmlib/event.c
wmlib/menu.c
wrlib/CmapAlloc.c
wrlib/CrCmap.c
wrlib/DelCmap.c
wrlib/LookupCmap.c
wrlib/StdCmap.c
wrlib/alloca.c
wrlib/color.c
wrlib/context.c
wrlib/convert.c
wrlib/convolve.c
wrlib/draw.c
wrlib/gif.c
wrlib/gradient.c
wrlib/jpeg.c
wrlib/load.c
wrlib/misc.c
wrlib/nxpm.c
wrlib/png.c
wrlib/ppm.c
wrlib/raster.c
wrlib/rotate.c
wrlib/save.c
wrlib/scale.c
wrlib/tests/testdraw.c
wrlib/tests/testgrad.c
wrlib/tests/testrot.c
wrlib/tests/view.c
wrlib/tiff.c
wrlib/x86_specific.c
wrlib/xpixmap.c
wrlib/xpm.c
wrlib/xutil.c

dissimilarity index 78%
index ae1695e..24daa2c 100644 (file)
@@ -1,42 +1,39 @@
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <WINGs/WINGs.h>
-
-
-
-void showSelectedColor(void *self, void *cdata)
-{
-    WMColorPanel *panel= (WMColorPanel*)self;
-
-    printf("Selected Color: %s\n", WMGetColorRGBDescription(WMGetColorPanelColor(panel)));
-}
-
-
-int main(int argc, char **argv)
-{
-    Display *dpy;
-    WMScreen *scr;
-
-    WMInitializeApplication("wmcolorpick", &argc, argv);
-
-    dpy = XOpenDisplay("");
-    if (!dpy) {
-        printf("could not open display\n");
-        exit(1);
-    }
-
-    scr = WMCreateScreen(dpy, DefaultScreen(dpy));
-
-    {
-        WMColorPanel *panel= WMGetColorPanel(scr);
-
-        WMSetColorPanelAction(panel, showSelectedColor, NULL);
-
-        WMShowColorPanel(panel);
-    }
-
-    WMScreenMainLoop(scr);
-
-    return 0;
-}
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <WINGs/WINGs.h>
+
+void showSelectedColor(void *self, void *cdata)
+{
+       WMColorPanel *panel = (WMColorPanel *) self;
+
+       printf("Selected Color: %s\n", WMGetColorRGBDescription(WMGetColorPanelColor(panel)));
+}
+
+int main(int argc, char **argv)
+{
+       Display *dpy;
+       WMScreen *scr;
+
+       WMInitializeApplication("wmcolorpick", &argc, argv);
+
+       dpy = XOpenDisplay("");
+       if (!dpy) {
+               printf("could not open display\n");
+               exit(1);
+       }
+
+       scr = WMCreateScreen(dpy, DefaultScreen(dpy));
+
+       {
+               WMColorPanel *panel = WMGetColorPanel(scr);
+
+               WMSetColorPanelAction(panel, showSelectedColor, NULL);
+
+               WMShowColorPanel(panel);
+       }
+
+       WMScreenMainLoop(scr);
+
+       return 0;
+}
dissimilarity index 90%
index 14a2174..9b4b93a 100644 (file)
-/*
- *  WINGs connect.c: example how to create a network client using WMConnection
- *
- *  Copyright (c) 1999-2003 Dan Pascu
- *
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include <WINGs/WINGs.h>
-
-
-
-static int initialized = 0;
-
-
-
-static void didReceiveInput(ConnectionDelegate *self, WMConnection *cPtr);
-
-static void connectionDidDie(ConnectionDelegate *self, WMConnection *cPtr);
-
-static void didInitialize(ConnectionDelegate *self, WMConnection *cPtr);
-
-
-
-static ConnectionDelegate socketDelegate = {
-    NULL,              /* data */
-    NULL,              /* canResumeSending */
-    NULL,              /* didCatchException */
-    connectionDidDie,  /* didDie */
-    didInitialize,     /* didInitialize */
-    didReceiveInput,   /* didReceiveInput */
-    NULL               /* didTimeout */
-};
-
-
-
-void
-wAbort(Bool foo)
-{
-    exit(1);
-}
-
-
-static char*
-getMessage(WMConnection *cPtr)
-{
-    char *buffer;
-    WMData *aData;
-    int length;
-
-    aData = WMGetConnectionAvailableData(cPtr);
-    if (!aData)
-        return NULL;
-    if ((length=WMGetDataLength(aData))==0) {
-        WMReleaseData(aData);
-        return NULL;
-    }
-
-    buffer = (char*)wmalloc(length+1);
-    WMGetDataBytes(aData, buffer);
-    buffer[length]= '\0';
-    WMReleaseData(aData);
-
-    return buffer;
-}
-
-
-static void
-inputHandler(int fd, int mask, void *clientData)
-{
-    WMConnection *cPtr = (WMConnection*)clientData;
-    WMData *aData;
-    char buf[4096];
-    int n;
-
-    if (!initialized)
-        return;
-
-    n = read(fd, buf, 4096);
-    if (n>0) {
-        aData = WMCreateDataWithBytes(buf, n);
-        WMSendConnectionData(cPtr, aData);
-        WMReleaseData(aData);
-    }
-}
-
-
-static void
-didReceiveInput(ConnectionDelegate *self, WMConnection *cPtr)
-{
-    char *buffer;
-
-    buffer = getMessage(cPtr);
-    if (!buffer) {
-        fprintf(stderr, "Connection closed by peer.\n");
-        exit(0);
-    }
-
-    printf("%s", buffer);
-
-    wfree(buffer);
-}
-
-
-static void
-connectionDidDie(ConnectionDelegate *self, WMConnection *cPtr)
-{
-    WMCloseConnection(cPtr);
-
-    fprintf(stderr, "Connection closed by peer.\n");
-    exit(0);
-}
-
-
-static void
-didInitialize(ConnectionDelegate *self, WMConnection *cPtr)
-{
-    int state = WMGetConnectionState(cPtr);
-    WMHost *host;
-
-    if (state == WCConnected) {
-        host = WMGetHostWithAddress(WMGetConnectionAddress(cPtr));
-        fprintf(stderr, "connected to '%s:%s'\n",
-                host?WMGetHostName(host):WMGetConnectionAddress(cPtr),
-                WMGetConnectionService(cPtr));
-        initialized = 1;
-        if (host)
-            WMReleaseHost(host);
-        return;
-    } else {
-        wsyserrorwithcode(WCErrorCode, "Unable to connect");
-        exit(1);
-    }
-}
-
-
-int
-main(int argc, char **argv)
-{
-    char *ProgName, *host, *port;
-    int i;
-    WMConnection *sPtr;
-
-    wsetabort(wAbort);
-
-    WMInitializeApplication("connect", &argc, argv);
-
-    ProgName = strrchr(argv[0],'/');
-    if (!ProgName)
-        ProgName = argv[0];
-    else
-        ProgName++;
-
-    host = NULL;
-    port = "34567";
-
-    if (argc>1) {
-        for (i=1; i<argc; i++) {
-            if (strcmp(argv[i], "--help")==0 || strcmp(argv[i], "-h")==0) {
-                printf("usage: %s [host [port]]\n\n", ProgName);
-                exit(0);
-            } else {
-                if (!host)
-                    host = argv[i];
-                else
-                    port = argv[i];
-            }
-        }
-    }
-
-    printf("Trying to make connection to '%s:%s'\n",
-           host?host:"localhost", port);
-
-    sPtr = WMCreateConnectionToAddressAndNotify(host, port, NULL);
-    if (!sPtr) {
-        wfatal("could not create connection. exiting");
-        exit(1);
-    }
-
-    WMSetConnectionDelegate(sPtr, &socketDelegate);
-
-    /* watch what user types and send it over the connection */
-    WMAddInputHandler(0, WIReadMask, inputHandler, sPtr);
-
-    while (1) {
-        WHandleEvents();
-    }
-
-    return 0;
-
-}
-
-
+/*
+ *  WINGs connect.c: example how to create a network client using WMConnection
+ *
+ *  Copyright (c) 1999-2003 Dan Pascu
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <WINGs/WINGs.h>
+
+static int initialized = 0;
+
+static void didReceiveInput(ConnectionDelegate * self, WMConnection * cPtr);
+
+static void connectionDidDie(ConnectionDelegate * self, WMConnection * cPtr);
+
+static void didInitialize(ConnectionDelegate * self, WMConnection * cPtr);
+
+static ConnectionDelegate socketDelegate = {
+       NULL,                   /* data */
+       NULL,                   /* canResumeSending */
+       NULL,                   /* didCatchException */
+       connectionDidDie,       /* didDie */
+       didInitialize,          /* didInitialize */
+       didReceiveInput,        /* didReceiveInput */
+       NULL                    /* didTimeout */
+};
+
+void wAbort(Bool foo)
+{
+       exit(1);
+}
+
+static char *getMessage(WMConnection * cPtr)
+{
+       char *buffer;
+       WMData *aData;
+       int length;
+
+       aData = WMGetConnectionAvailableData(cPtr);
+       if (!aData)
+               return NULL;
+       if ((length = WMGetDataLength(aData)) == 0) {
+               WMReleaseData(aData);
+               return NULL;
+       }
+
+       buffer = (char *)wmalloc(length + 1);
+       WMGetDataBytes(aData, buffer);
+       buffer[length] = '\0';
+       WMReleaseData(aData);
+
+       return buffer;
+}
+
+static void inputHandler(int fd, int mask, void *clientData)
+{
+       WMConnection *cPtr = (WMConnection *) clientData;
+       WMData *aData;
+       char buf[4096];
+       int n;
+
+       if (!initialized)
+               return;
+
+       n = read(fd, buf, 4096);
+       if (n > 0) {
+               aData = WMCreateDataWithBytes(buf, n);
+               WMSendConnectionData(cPtr, aData);
+               WMReleaseData(aData);
+       }
+}
+
+static void didReceiveInput(ConnectionDelegate * self, WMConnection * cPtr)
+{
+       char *buffer;
+
+       buffer = getMessage(cPtr);
+       if (!buffer) {
+               fprintf(stderr, "Connection closed by peer.\n");
+               exit(0);
+       }
+
+       printf("%s", buffer);
+
+       wfree(buffer);
+}
+
+static void connectionDidDie(ConnectionDelegate * self, WMConnection * cPtr)
+{
+       WMCloseConnection(cPtr);
+
+       fprintf(stderr, "Connection closed by peer.\n");
+       exit(0);
+}
+
+static void didInitialize(ConnectionDelegate * self, WMConnection * cPtr)
+{
+       int state = WMGetConnectionState(cPtr);
+       WMHost *host;
+
+       if (state == WCConnected) {
+               host = WMGetHostWithAddress(WMGetConnectionAddress(cPtr));
+               fprintf(stderr, "connected to '%s:%s'\n",
+                       host ? WMGetHostName(host) : WMGetConnectionAddress(cPtr), WMGetConnectionService(cPtr));
+               initialized = 1;
+               if (host)
+                       WMReleaseHost(host);
+               return;
+       } else {
+               wsyserrorwithcode(WCErrorCode, "Unable to connect");
+               exit(1);
+       }
+}
+
+int main(int argc, char **argv)
+{
+       char *ProgName, *host, *port;
+       int i;
+       WMConnection *sPtr;
+
+       wsetabort(wAbort);
+
+       WMInitializeApplication("connect", &argc, argv);
+
+       ProgName = strrchr(argv[0], '/');
+       if (!ProgName)
+               ProgName = argv[0];
+       else
+               ProgName++;
+
+       host = NULL;
+       port = "34567";
+
+       if (argc > 1) {
+               for (i = 1; i < argc; i++) {
+                       if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
+                               printf("usage: %s [host [port]]\n\n", ProgName);
+                               exit(0);
+                       } else {
+                               if (!host)
+                                       host = argv[i];
+                               else
+                                       port = argv[i];
+                       }
+               }
+       }
+
+       printf("Trying to make connection to '%s:%s'\n", host ? host : "localhost", port);
+
+       sPtr = WMCreateConnectionToAddressAndNotify(host, port, NULL);
+       if (!sPtr) {
+               wfatal("could not create connection. exiting");
+               exit(1);
+       }
+
+       WMSetConnectionDelegate(sPtr, &socketDelegate);
+
+       /* watch what user types and send it over the connection */
+       WMAddInputHandler(0, WIReadMask, inputHandler, sPtr);
+
+       while (1) {
+               WHandleEvents();
+       }
+
+       return 0;
+
+}
dissimilarity index 63%
index ad9957a..4e1f642 100644 (file)
-/*
- * WINGs demo: font lister
- *
- *  Copyright (c) 1998-2003 Alfredo K. Kojima
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program 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 General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
- *  USA.
- */
-
-
-
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <WINGs/WINGs.h>
-#include <WINGs/WUtil.h>
-
-void
-wAbort()
-{
-    exit(0);
-}
-
-void show(WMWidget *self, void *data)
-{
-    char buf[60];
-    void *d;
-    WMLabel *l = (WMLabel*)data;
-    d = WMGetHangedData(self);
-    sprintf(buf, "%i -  0x%x - 0%o", (int)(uintptr_t)d, (int)(uintptr_t)d, 
-           (int)(uintptr_t)d);
-    WMSetLabelText(l, buf);
-}
-
-void quit(WMWidget *self, void *data)
-{
-    exit(0);
-}
-
-
-int
-main(int argc, char **argv)
-{
-    Display *dpy;
-    WMWindow *win;
-    WMScreen *scr;
-    WMButton *lab, *l0=NULL;
-    WMLabel *pos;
-    int x, y, c;
-    char buf[20];
-
-    WMInitializeApplication("FontView", &argc, argv);
-
-    dpy = XOpenDisplay("");
-    if (!dpy) {
-        wfatal("cant open display");
-        exit(0);
-    }
-
-    scr = WMCreateSimpleApplicationScreen(dpy);
-
-    win = WMCreateWindow(scr, "main");
-    WMResizeWidget(win, 20*33, 20+20*9);
-    WMSetWindowTitle(win, "Font Chars");
-    WMSetWindowCloseAction(win, quit, NULL);
-    pos = WMCreateLabel(win);
-    WMResizeWidget(pos, 20*33, 20);
-    WMMoveWidget(pos, 10, 5);
-
-    c = 0;
-    for (y=0; y<8; y++) {
-        for (x=0; x<32; x++, c++) {
-            lab = WMCreateCustomButton(win, WBBStateLightMask);
-            WMResizeWidget(lab, 20, 20);
-            WMMoveWidget(lab, 10+x*20, 30+y*20);
-            sprintf(buf, "%c", c);
-            WMSetButtonText(lab, buf);
-            WMSetButtonAction(lab, show, pos);
-            WMHangData(lab, (void*)(uintptr_t)c);
-            if (c>0) {
-                WMGroupButtons(l0, lab);
-            } else {
-                l0 = lab;
-            }
-        }
-    }
-    WMRealizeWidget(win);
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-    WMScreenMainLoop(scr);
-    return 0;
-}
-
+/*
+ * WINGs demo: font lister
+ *
+ *  Copyright (c) 1998-2003 Alfredo K. Kojima
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <WINGs/WINGs.h>
+#include <WINGs/WUtil.h>
+
+void wAbort()
+{
+       exit(0);
+}
+
+void show(WMWidget * self, void *data)
+{
+       char buf[60];
+       void *d;
+       WMLabel *l = (WMLabel *) data;
+       d = WMGetHangedData(self);
+       sprintf(buf, "%i -  0x%x - 0%o", (int)(uintptr_t) d, (int)(uintptr_t) d, (int)(uintptr_t) d);
+       WMSetLabelText(l, buf);
+}
+
+void quit(WMWidget * self, void *data)
+{
+       exit(0);
+}
+
+int main(int argc, char **argv)
+{
+       Display *dpy;
+       WMWindow *win;
+       WMScreen *scr;
+       WMButton *lab, *l0 = NULL;
+       WMLabel *pos;
+       int x, y, c;
+       char buf[20];
+
+       WMInitializeApplication("FontView", &argc, argv);
+
+       dpy = XOpenDisplay("");
+       if (!dpy) {
+               wfatal("cant open display");
+               exit(0);
+       }
+
+       scr = WMCreateSimpleApplicationScreen(dpy);
+
+       win = WMCreateWindow(scr, "main");
+       WMResizeWidget(win, 20 * 33, 20 + 20 * 9);
+       WMSetWindowTitle(win, "Font Chars");
+       WMSetWindowCloseAction(win, quit, NULL);
+       pos = WMCreateLabel(win);
+       WMResizeWidget(pos, 20 * 33, 20);
+       WMMoveWidget(pos, 10, 5);
+
+       c = 0;
+       for (y = 0; y < 8; y++) {
+               for (x = 0; x < 32; x++, c++) {
+                       lab = WMCreateCustomButton(win, WBBStateLightMask);
+                       WMResizeWidget(lab, 20, 20);
+                       WMMoveWidget(lab, 10 + x * 20, 30 + y * 20);
+                       sprintf(buf, "%c", c);
+                       WMSetButtonText(lab, buf);
+                       WMSetButtonAction(lab, show, pos);
+                       WMHangData(lab, (void *)(uintptr_t) c);
+                       if (c > 0) {
+                               WMGroupButtons(l0, lab);
+                       } else {
+                               l0 = lab;
+                       }
+               }
+       }
+       WMRealizeWidget(win);
+       WMMapSubwidgets(win);
+       WMMapWidget(win);
+       WMScreenMainLoop(scr);
+       return 0;
+}
dissimilarity index 92%
index 21e6910..7e8b799 100644 (file)
-
-
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <WINGs/WINGs.h>
-#include <stdint.h>
-
-
-#define MAX_SIZE       10*10
-
-
-WMWindow *win;
-WMButton *Button[MAX_SIZE];
-char Map[MAX_SIZE];
-int Size = 4;
-int MoveCount;
-
-#define MAP(x,y)  Map[(x)+(y)*Size]
-
-int WinSize = 120;
-
-
-Bool
-CheckWin(void)
-{
-    int i;
-
-    for (i = 0; i < Size*Size-1; i++) {
-        if (Map[i] != i)
-            return False;
-    }
-
-    return True;
-}
-
-
-void
-MoveButton(int button, int x, int y)
-{
-    WMMoveWidget(Button[button], x*(WinSize/Size), y*(WinSize/Size));
-}
-
-
-Bool
-SlideButton(int button)
-{
-    int x=0, y=0, done = 0;
-
-    /* locate the button */
-    for (y = 0; y < Size; y++) {
-        for (x = 0; x < Size; x++) {
-            if (MAP(x,y) == button) {
-                done = 1;
-                break;
-            }
-        }
-        if (done)
-            break;
-    }
-
-    if (x > 0 && MAP(x-1, y) < 0) {
-        MAP(x,y) = -1;
-        MoveButton(button, x-1, y);
-        MAP(x-1,y) = button;
-    } else if (x < Size-1 && MAP(x+1, y) < 0) {
-        MAP(x,y) = -1;
-        MoveButton(button, x+1, y);
-        MAP(x+1,y) = button;
-    } else if (y > 0 && MAP(x, y-1) < 0) {
-        MAP(x,y) = -1;
-        MoveButton(button, x, y-1);
-        MAP(x,y-1) = button;
-    } else if (y < Size-1 && MAP(x, y+1) < 0) {
-        MAP(x,y) = -1;
-        MoveButton(button, x, y+1);
-        MAP(x,y+1) = button;
-    } else {
-        return False;
-    }
-    return True;
-}
-
-
-#define SWAP(a,b) {int tmp; tmp=a; a=b; b=tmp;}
-
-void ResetGame(void)
-{
-    int i, x, y, ox, oy;
-
-
-    MoveCount = 0;
-
-    for (i = 0; i < Size*Size-1; i++) {
-        Map[i] = i;
-    }
-    Map[i] = -1;
-    ox = x = Size-1;
-    oy = y = Size-1;
-    for (i = 0; i < 1000; i++) {
-        int ok;
-        ok = 1;
-        switch (rand()%4) {
-        case 0:
-            if (x > 0) x--; else ok = 0;
-            break;
-        case 2:
-            if (x < Size-1) x++; else ok = 0;
-            break;
-        case 1:
-            if (y > 0) y--; else ok = 0;
-            break;
-        case 3:
-            if (y < Size-1) y++; else ok = 0;
-            break;
-        }
-        if (ok) {
-            MoveButton(MAP(x,y), ox, oy);
-
-            SWAP(MAP(ox, oy), MAP(x, y));
-
-            while (XPending(WMScreenDisplay(WMWidgetScreen(win)))) {
-                XEvent ev;
-                WMNextEvent(WMScreenDisplay(WMWidgetScreen(win)), &ev);
-                WMHandleEvent(&ev);
-            }
-            ox = x;
-            oy = y;
-        }
-    }
-}
-
-
-void buttonClick(WMWidget *w, void *ptr)
-{
-    char buffer[300];
-
-    if (SlideButton((int)(uintptr_t)ptr)) {
-        MoveCount++;
-
-        if (CheckWin()) {
-            sprintf(buffer, "You finished the game in %i moves.", MoveCount);
-
-            if (WMRunAlertPanel(WMWidgetScreen(w), win, "You Won!", buffer,
-                                "Wee!", "Gah! Lemme retry!", NULL) == WAPRDefault) {
-                exit(0);
-            }
-
-            ResetGame();
-        }
-    }
-}
-
-
-static void resizeObserver(void *self, WMNotification *notif)
-{
-    WMSize size = WMGetViewSize(WMWidgetView(win));
-    int x, y;
-
-    WinSize = size.width;
-    for (y = 0; y < Size; y++) {
-        for (x = 0; x < Size; x++) {
-            if (MAP(x,y) >= 0) {
-                WMResizeWidget(Button[(int)MAP(x,y)],
-                               WinSize/Size, WinSize/Size);
-                WMMoveWidget(Button[(int)MAP(x,y)],
-                             x*(WinSize/Size), y*(WinSize/Size));
-            }
-        }
-    }
-
-}
-
-
-int main(int argc, char **argv)
-{
-    Display *dpy;
-    WMScreen *scr;
-    int x, y, i;
-
-    WMInitializeApplication("Puzzle", &argc, argv);
-
-
-    dpy = XOpenDisplay("");
-    if (!dpy) {
-        printf("could not open display\n");
-        exit(1);
-    }
-
-    scr = WMCreateScreen(dpy, DefaultScreen(dpy));
-
-    win = WMCreateWindow(scr, "puzzle");
-    WMResizeWidget(win, WinSize, WinSize);
-    WMSetWindowTitle(win, "zuPzel");
-    WMSetWindowMinSize(win, 80, 80);
-    WMSetWindowAspectRatio(win, 2, 2, 2, 2);
-    WMSetWindowResizeIncrements(win, Size, Size);
-    WMSetViewNotifySizeChanges(WMWidgetView(win), True);
-    WMAddNotificationObserver(resizeObserver, NULL,
-                              WMViewSizeDidChangeNotification,
-                              WMWidgetView(win));
-
-
-
-    for (i = y = 0; y < Size && i < Size*Size-1; y++) {
-        for (x = 0; x < Size && i < Size*Size-1; x++) {
-            char buf[32];
-            WMColor *color;
-            RColor col;
-            RHSVColor hsv;
-
-            hsv.hue = i*360/(Size*Size-1);
-            hsv.saturation = 120;
-            hsv.value = 200;
-
-            RHSVtoRGB(&hsv, &col);
-
-            color = WMCreateRGBColor(scr, col.red<<8, col.green<<8,
-                                     col.blue<<8, False);
-
-            MAP(x,y) = i;
-            Button[i] = WMCreateButton(win, WBTMomentaryLight);
-            WMSetWidgetBackgroundColor(Button[i], color);
-            WMReleaseColor(color);
-            WMSetButtonAction(Button[i], buttonClick, (void*)(uintptr_t)i);
-            WMResizeWidget(Button[i], WinSize/Size, WinSize/Size);
-            WMMoveWidget(Button[i], x*(WinSize/Size), y*(WinSize/Size));
-            sprintf(buf, "%i", i+1);
-            WMSetButtonText(Button[i], buf);
-            WMSetButtonTextAlignment(Button[i], WACenter);
-            i++;
-        }
-    }
-
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-    WMRealizeWidget(win);
-
-    ResetGame();
-
-    WMScreenMainLoop(scr);
-
-    return 0;
-}
-
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <WINGs/WINGs.h>
+#include <stdint.h>
+
+#define MAX_SIZE       10*10
+
+WMWindow *win;
+WMButton *Button[MAX_SIZE];
+char Map[MAX_SIZE];
+int Size = 4;
+int MoveCount;
+
+#define MAP(x,y)  Map[(x)+(y)*Size]
+
+int WinSize = 120;
+
+Bool CheckWin(void)
+{
+       int i;
+
+       for (i = 0; i < Size * Size - 1; i++) {
+               if (Map[i] != i)
+                       return False;
+       }
+
+       return True;
+}
+
+void MoveButton(int button, int x, int y)
+{
+       WMMoveWidget(Button[button], x * (WinSize / Size), y * (WinSize / Size));
+}
+
+Bool SlideButton(int button)
+{
+       int x = 0, y = 0, done = 0;
+
+       /* locate the button */
+       for (y = 0; y < Size; y++) {
+               for (x = 0; x < Size; x++) {
+                       if (MAP(x, y) == button) {
+                               done = 1;
+                               break;
+                       }
+               }
+               if (done)
+                       break;
+       }
+
+       if (x > 0 && MAP(x - 1, y) < 0) {
+               MAP(x, y) = -1;
+               MoveButton(button, x - 1, y);
+               MAP(x - 1, y) = button;
+       } else if (x < Size - 1 && MAP(x + 1, y) < 0) {
+               MAP(x, y) = -1;
+               MoveButton(button, x + 1, y);
+               MAP(x + 1, y) = button;
+       } else if (y > 0 && MAP(x, y - 1) < 0) {
+               MAP(x, y) = -1;
+               MoveButton(button, x, y - 1);
+               MAP(x, y - 1) = button;
+       } else if (y < Size - 1 && MAP(x, y + 1) < 0) {
+               MAP(x, y) = -1;
+               MoveButton(button, x, y + 1);
+               MAP(x, y + 1) = button;
+       } else {
+               return False;
+       }
+       return True;
+}
+
+#define SWAP(a,b) {int tmp; tmp=a; a=b; b=tmp;}
+
+void ResetGame(void)
+{
+       int i, x, y, ox, oy;
+
+       MoveCount = 0;
+
+       for (i = 0; i < Size * Size - 1; i++) {
+               Map[i] = i;
+       }
+       Map[i] = -1;
+       ox = x = Size - 1;
+       oy = y = Size - 1;
+       for (i = 0; i < 1000; i++) {
+               int ok;
+               ok = 1;
+               switch (rand() % 4) {
+               case 0:
+                       if (x > 0)
+                               x--;
+                       else
+                               ok = 0;
+                       break;
+               case 2:
+                       if (x < Size - 1)
+                               x++;
+                       else
+                               ok = 0;
+                       break;
+               case 1:
+                       if (y > 0)
+                               y--;
+                       else
+                               ok = 0;
+                       break;
+               case 3:
+                       if (y < Size - 1)
+                               y++;
+                       else
+                               ok = 0;
+                       break;
+               }
+               if (ok) {
+                       MoveButton(MAP(x, y), ox, oy);
+
+                       SWAP(MAP(ox, oy), MAP(x, y));
+
+                       while (XPending(WMScreenDisplay(WMWidgetScreen(win)))) {
+                               XEvent ev;
+                               WMNextEvent(WMScreenDisplay(WMWidgetScreen(win)), &ev);
+                               WMHandleEvent(&ev);
+                       }
+                       ox = x;
+                       oy = y;
+               }
+       }
+}
+
+void buttonClick(WMWidget * w, void *ptr)
+{
+       char buffer[300];
+
+       if (SlideButton((int)(uintptr_t) ptr)) {
+               MoveCount++;
+
+               if (CheckWin()) {
+                       sprintf(buffer, "You finished the game in %i moves.", MoveCount);
+
+                       if (WMRunAlertPanel(WMWidgetScreen(w), win, "You Won!", buffer,
+                                           "Wee!", "Gah! Lemme retry!", NULL) == WAPRDefault) {
+                               exit(0);
+                       }
+
+                       ResetGame();
+               }
+       }
+}
+
+static void resizeObserver(void *self, WMNotification * notif)
+{
+       WMSize size = WMGetViewSize(WMWidgetView(win));
+       int x, y;
+
+       WinSize = size.width;
+       for (y = 0; y < Size; y++) {
+               for (x = 0; x < Size; x++) {
+                       if (MAP(x, y) >= 0) {
+                               WMResizeWidget(Button[(int)MAP(x, y)], WinSize / Size, WinSize / Size);
+                               WMMoveWidget(Button[(int)MAP(x, y)], x * (WinSize / Size), y * (WinSize / Size));
+                       }
+               }
+       }
+
+}
+
+int main(int argc, char **argv)
+{
+       Display *dpy;
+       WMScreen *scr;
+       int x, y, i;
+
+       WMInitializeApplication("Puzzle", &argc, argv);
+
+       dpy = XOpenDisplay("");
+       if (!dpy) {
+               printf("could not open display\n");
+               exit(1);
+       }
+
+       scr = WMCreateScreen(dpy, DefaultScreen(dpy));
+
+       win = WMCreateWindow(scr, "puzzle");
+       WMResizeWidget(win, WinSize, WinSize);
+       WMSetWindowTitle(win, "zuPzel");
+       WMSetWindowMinSize(win, 80, 80);
+       WMSetWindowAspectRatio(win, 2, 2, 2, 2);
+       WMSetWindowResizeIncrements(win, Size, Size);
+       WMSetViewNotifySizeChanges(WMWidgetView(win), True);
+       WMAddNotificationObserver(resizeObserver, NULL, WMViewSizeDidChangeNotification, WMWidgetView(win));
+
+       for (i = y = 0; y < Size && i < Size * Size - 1; y++) {
+               for (x = 0; x < Size && i < Size * Size - 1; x++) {
+                       char buf[32];
+                       WMColor *color;
+                       RColor col;
+                       RHSVColor hsv;
+
+                       hsv.hue = i * 360 / (Size * Size - 1);
+                       hsv.saturation = 120;
+                       hsv.value = 200;
+
+                       RHSVtoRGB(&hsv, &col);
+
+                       color = WMCreateRGBColor(scr, col.red << 8, col.green << 8, col.blue << 8, False);
+
+                       MAP(x, y) = i;
+                       Button[i] = WMCreateButton(win, WBTMomentaryLight);
+                       WMSetWidgetBackgroundColor(Button[i], color);
+                       WMReleaseColor(color);
+                       WMSetButtonAction(Button[i], buttonClick, (void *)(uintptr_t) i);
+                       WMResizeWidget(Button[i], WinSize / Size, WinSize / Size);
+                       WMMoveWidget(Button[i], x * (WinSize / Size), y * (WinSize / Size));
+                       sprintf(buf, "%i", i + 1);
+                       WMSetButtonText(Button[i], buf);
+                       WMSetButtonTextAlignment(Button[i], WACenter);
+                       i++;
+               }
+       }
+
+       WMMapSubwidgets(win);
+       WMMapWidget(win);
+       WMRealizeWidget(win);
+
+       ResetGame();
+
+       WMScreenMainLoop(scr);
+
+       return 0;
+}
dissimilarity index 94%
index d0d0e45..e747a1f 100644 (file)
-/*
- *  WINGs server.c: example how to create a network server using WMConnection
- *
- *  Copyright (c) 2001-2003 Dan Pascu
- *
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include <WINGs/WINGs.h>
-
-
-#define _(P)         P
-#define MAXCMD_SIZE  512
-
-
-char *SEConnectionShouldBeRemovedNotification = "SEConnectionShouldBeRemovedNotification";
-
-
-
-
-static void didReceiveInput(ConnectionDelegate *self, WMConnection *cPtr);
-
-static void connectionDidDie(ConnectionDelegate *self, WMConnection *cPtr);
-
-static void connectionDidTimeout(ConnectionDelegate *self, WMConnection *cPtr);
-
-
-extern char *SEConnectionShouldBeRemovedNotification;
-
-static WMUserDefaults *timeDB = NULL;
-static char *ServerAddress = NULL;
-static char *ServerPort = NULL;
-static WMArray *allowedHostList = NULL;
-static WMArray *clientConnections = NULL;
-static WMConnection *serverPtr = NULL;
-
-
-
-static ConnectionDelegate socketDelegate = {
-    NULL,                 /* client data */
-    NULL,                 /* canResumeSending */
-    NULL,                 /* didCatchException */
-    connectionDidDie,     /* didDie */
-    NULL,                 /* didInitialize */
-    didReceiveInput,      /* didReceiveInput */
-    connectionDidTimeout  /* didTimeout */
-};
-
-
-
-void
-wAbort(Bool foo)
-{
-    exit(1);
-}
-
-
-static void
-printHelp(char *progname)
-{
-    printf(_("usage: %s [options]\n\n"), progname);
-    puts(_(" --help                            print this message"));
-    puts(_(" --listen [address:]port   only listen on the specified address/port"));
-    puts(_(" --allow host1[,host2...]  only allow connections from listed hosts\n"));
-    puts(_(" By default server listens on all interfaces and port 34567, unless"
-           " something\nelse is specified with the --listen option. If address is"
-           " omitted or the keyword\n'Any' is used, it will listen on all interfaces else"
-           " only on the specified one.\n\nFor example --listen localhost: will"
-           " listen on the default port 34567, but only\non connections comming"
-           " in through the loopback interface.\n\n Also by default the server"
-           " listens to incoming connections from any host,\nunless a list of"
-           " hosts is given with the --allow option, in which case it will\nreject"
-           " connections not comming from those hosts.\nThe list of hosts is comma"
-           " separated and should NOT contain ANY spaces."));
-}
-
-
-static void
-enqueueConnectionForRemoval(WMConnection *cPtr)
-{
-    WMNotification *notif;
-
-    /*don't release notif here. it will be released by queue after processing */
-    notif = WMCreateNotification(SEConnectionShouldBeRemovedNotification,
-                                 cPtr, NULL);
-    WMEnqueueNotification(WMGetDefaultNotificationQueue(), notif, WMPostASAP);
-}
-
-
-static int
-sendMessage(WMConnection *cPtr, char *message)
-{
-    WMData *aData;
-    int res;
-
-    if (WMGetConnectionState(cPtr)!=WCConnected)
-        return -1;
-
-    aData = WMCreateDataWithBytes(message, strlen(message));
-    res = WMSendConnectionData(cPtr, aData);
-    WMReleaseData(aData);
-
-    return res;
-}
-
-
-static Bool
-enqueueMessage(WMConnection *cPtr, char *message)
-{
-    WMData *aData;
-    Bool res;
-
-    if (WMGetConnectionState(cPtr)!=WCConnected)
-        return False;
-
-    aData = WMCreateDataWithBytes(message, strlen(message));
-    res = WMEnqueueConnectionData(cPtr, aData);
-    WMReleaseData(aData);
-
-    return res;
-}
-
-
-static char*
-findDelimiter(char *data, const char *endPtr)
-{
-    wassertrv(data < endPtr, NULL);
-
-    while (data<endPtr && *data!='\n' && *data!='\r' && *data!=';' && *data!='\0')
-        data++;
-
-    if (data < endPtr)
-        return data;
-
-    return NULL;
-}
-
-
-static WMArray*
-getAvailableMessages(WMConnection *cPtr)
-{
-    char *ptr, *crtPos, *buffer;
-    const char *bytes, *endPtr;
-    WMData *aData, *receivedData, *holdData;
-    WMRange range;
-    WMArray *messages;
-    int length;
-
-    receivedData = WMGetConnectionAvailableData(cPtr);
-    if (!receivedData)
-        return NULL;
-    if ((length=WMGetDataLength(receivedData))==0) {
-        WMReleaseData(receivedData);
-        return NULL;
-    }
-
-    holdData = (WMData*)WMGetConnectionClientData(cPtr);
-    if (holdData) {
-        WMAppendData(holdData, receivedData);
-        WMReleaseData(receivedData);
-        WMSetConnectionClientData(cPtr, NULL);
-        aData = holdData;
-    } else {
-        aData = receivedData;
-    }
-
-    length = WMGetDataLength(aData);
-    bytes = (char*)WMDataBytes(aData);
-    endPtr = bytes + length;
-
-    messages = WMCreateArrayWithDestructor(1, wfree);
-    crtPos = (char*)bytes;
-    while (crtPos<endPtr && (ptr = findDelimiter(crtPos, endPtr))!=NULL) {
-        range.position = (crtPos - bytes);
-        range.count = (ptr - crtPos);
-        if (range.count > MAXCMD_SIZE) {
-            /* Hmmm... The message is too long. Possibly that someone is
-             * flooding us, or there is a dumb client which do not know
-             * who is talking to. */
-            sendMessage(cPtr, "Command too long\n\r");
-            WMFreeArray(messages);
-            WMReleaseData(aData);
-            WMCloseConnection(cPtr);
-            enqueueConnectionForRemoval(cPtr);
-            return NULL;
-        }
-        buffer = wmalloc(range.count+1);
-        WMGetDataBytesWithRange(aData, buffer, range);
-        buffer[range.count] = '\0';
-        WMAddToArray(messages, buffer);
-        crtPos = ptr;
-        while (crtPos<endPtr && (*crtPos=='\n' || *crtPos=='\r' ||
-                                 *crtPos=='\t' || *crtPos=='\0' ||
-                                 *crtPos==';' || *crtPos==' ')) {
-            crtPos++;
-        }
-    }
-
-    if (crtPos<endPtr) {
-        range.position = (crtPos - bytes);
-        range.count = (endPtr - crtPos);
-        if (range.count > MAXCMD_SIZE) {
-            /* Flooooooding!!!! */
-            sendMessage(cPtr, "Message too long\n\r");
-            WMFreeArray(messages);
-            WMReleaseData(aData);
-            WMCloseConnection(cPtr);
-            enqueueConnectionForRemoval(cPtr);
-            return NULL;
-        }
-        holdData = WMGetSubdataWithRange(aData, range);
-        WMSetConnectionClientData(cPtr, holdData);
-    }
-    WMReleaseData(aData);
-
-    if (WMGetArrayItemCount(messages)==0) {
-        WMFreeArray(messages);
-        messages = NULL;
-    }
-    return messages;
-}
-
-
-
-static void
-complainAboutBadArgs(WMConnection *cPtr, char *cmdName, char *badArgs)
-{
-    char *buf = wmalloc(strlen(cmdName) + strlen(badArgs) + 100);
-
-    sprintf(buf, _("Invalid parameters '%s' for command %s. Use HELP for"
-                   " a list of commands.\n"), badArgs, cmdName);
-    sendMessage(cPtr, buf);
-    wfree(buf);
-}
-
-
-static void
-sendUpdateMessage(WMConnection *cPtr, char *id, int time)
-{
-    char *buf = wmalloc(strlen(id) + 100);
-
-    sprintf(buf, "%s has %i minutes left\n", id, time);
-    sendMessage(cPtr, buf);
-    wfree(buf);
-}
-
-
-static void
-showId(WMConnection *cPtr)
-{
-    sendMessage(cPtr, "Server example based on WMConnection\n");
-}
-
-
-static void
-showHelp(WMConnection *cPtr)
-{
-    char *buf = wmalloc(strlen(WMGetApplicationName()) + 16);
-
-    sprintf(buf, _("%s commands:\n\n"), WMGetApplicationName());
-
-    enqueueMessage(cPtr, _("\n"));
-    enqueueMessage(cPtr, buf);
-    enqueueMessage(cPtr, _("GET <id>\t- return time left (in minutes) "
-                           "for user with id <id>\n"));
-    enqueueMessage(cPtr, _("SET <id> <time>\t- set time limit to <time> "
-                           "minutes for user with id <id>\n"));
-    enqueueMessage(cPtr, _("ADD <id> <time>\t- add <time> minutes "
-                           "for user with id <id>\n"));
-    enqueueMessage(cPtr, _("SUB <id> <time>\t- subtract <time> minutes "
-                           "for user with id <id>\n"));
-    enqueueMessage(cPtr, _("REMOVE <id>\t- remove time limitations for "
-                           "user with id <id>\n"));
-    enqueueMessage(cPtr, _("LIST\t\t- list all users and their "
-                           "corresponding time limit\n"));
-    enqueueMessage(cPtr, _("ID\t\t- returns the Time Manager "
-                           "identification string\n"));
-    enqueueMessage(cPtr, _("EXIT\t\t- exits session\n"));
-    enqueueMessage(cPtr, _("QUIT\t\t- exits session\n"));
-    enqueueMessage(cPtr, _("HELP\t\t- show this message\n\n"));
-    /* Just flush the queue we made before */
-    WMFlushConnection(cPtr);
-    wfree(buf);
-}
-
-
-static void
-listUsers(WMConnection *cPtr)
-{
-    WMPropList *userList;
-    char *id;
-    int i, time;
-
-    userList = WMGetUDKeys(timeDB);
-
-    for (i=0; i<WMGetPropListItemCount(userList); i++) {
-        id = WMGetFromPLString(WMGetFromPLArray(userList, i));
-        time = WMGetUDIntegerForKey(timeDB, id);
-        sendUpdateMessage(cPtr, id, time);
-    }
-
-    WMReleasePropList(userList);
-}
-
-
-static void
-setTimeForUser(WMConnection *cPtr, char *cmdArgs)
-{
-    char *id;
-    int i, time;
-
-    id = wmalloc(strlen(cmdArgs));
-    if (sscanf(cmdArgs, "%s %d", id, &time)!=2) {
-        complainAboutBadArgs(cPtr, "SET", cmdArgs);
-        wfree(id);
-        return;
-    }
-    if (time<0)
-        time = 0;
-
-    WMSetUDIntegerForKey(timeDB, time, id);
-
-    for (i=0; i<WMGetArrayItemCount(clientConnections); i++) {
-        cPtr = WMGetFromArray(clientConnections, i);
-        sendUpdateMessage(cPtr, id, time);
-    }
-    wfree(id);
-}
-
-
-static void
-addTimeToUser(WMConnection *cPtr, char *cmdArgs)
-{
-    char *id;
-    int i, time, newTime;
-
-    id = wmalloc(strlen(cmdArgs));
-    if (sscanf(cmdArgs, "%s %d", id, &time)!=2) {
-        complainAboutBadArgs(cPtr, "ADD", cmdArgs);
-        wfree(id);
-        return;
-    }
-
-    newTime = WMGetUDIntegerForKey(timeDB, id) + time;
-    if (newTime<0)
-        newTime = 0;
-
-    WMSetUDIntegerForKey(timeDB, newTime, id);
-
-    for (i=0; i<WMGetArrayItemCount(clientConnections); i++) {
-        cPtr = WMGetFromArray(clientConnections, i);
-        sendUpdateMessage(cPtr, id, newTime);
-    }
-    wfree(id);
-}
-
-
-static void
-subTimeFromUser(WMConnection *cPtr, char *cmdArgs)
-{
-    char *id;
-    int i, time, newTime;
-
-    id = wmalloc(strlen(cmdArgs));
-    if (sscanf(cmdArgs, "%s %d", id, &time)!=2) {
-        complainAboutBadArgs(cPtr, "SUB", cmdArgs);
-        wfree(id);
-        return;
-    }
-
-    newTime = WMGetUDIntegerForKey(timeDB, id) - time;
-    if (newTime<0)
-        newTime = 0;
-
-    WMSetUDIntegerForKey(timeDB, newTime, id);
-
-    for (i=0; i<WMGetArrayItemCount(clientConnections); i++) {
-        cPtr = WMGetFromArray(clientConnections, i);
-        sendUpdateMessage(cPtr, id, newTime);
-    }
-    wfree(id);
-}
-
-
-static void
-removeTimeForUser(WMConnection *cPtr, char *cmdArgs)
-{
-    char *ptr;
-    int i;
-
-    if (cmdArgs[0]=='\0') {
-        sendMessage(cPtr, _("Missing parameter for command REMOVE."
-                            " Use HELP for a list of commands.\n"));
-        return;
-    }
-
-    ptr = cmdArgs;
-    while (*ptr && *ptr!=' ' && *ptr!='\t')
-        ptr++;
-    *ptr = '\0';
-
-    WMRemoveUDObjectForKey(timeDB, cmdArgs);
-
-    for (i=0; i<WMGetArrayItemCount(clientConnections); i++) {
-        cPtr = WMGetFromArray(clientConnections, i);
-        sendUpdateMessage(cPtr, cmdArgs, -1);
-    }
-}
-
-
-static void
-getTimeForUser(WMConnection *cPtr, char *cmdArgs)
-{
-    char *ptr;
-    int time;
-
-    if (cmdArgs[0]=='\0') {
-        sendMessage(cPtr, _("Missing parameter for command GET."
-                            " Use HELP for a list of commands.\n"));
-        return;
-    }
-
-    ptr = cmdArgs;
-    while (*ptr && *ptr!=' ' && *ptr!='\t')
-        ptr++;
-    *ptr = '\0';
-
-    if (WMGetUDObjectForKey(timeDB, cmdArgs)!=NULL)
-        time = WMGetUDIntegerForKey(timeDB, cmdArgs);
-    else
-        time = -1;
-
-    sendUpdateMessage(cPtr, cmdArgs, time);
-}
-
-
-static void
-handleConnection(WMConnection *cPtr)
-{
-    char *command, *ptr, *cmdArgs, *buffer;
-    WMArray *commands;
-    int i;
-
-    commands = getAvailableMessages(cPtr);
-    if (!commands)
-        return;
-
-    for (i=0; i<WMGetArrayItemCount(commands); i++) {
-        command = WMGetFromArray(commands, i);
-        while (*command && (*command==' ' || *command=='\t'))
-            command++;
-        ptr = command;
-        while(*ptr && *ptr!=' ' && *ptr!='\t')
-            ptr++;
-        if (*ptr) {
-            *ptr = '\0';
-            ptr++;
-        }
-        while (*ptr && (*ptr==' ' || *ptr=='\t'))
-            ptr++;
-
-        cmdArgs = ptr;
-
-        fprintf(stderr, "Command: '%s', args: '%s'\n", command, cmdArgs);
-
-        if (strcasecmp(command, "quit")==0 || strcasecmp(command, "exit")==0) {
-            sendMessage(cPtr, "Bye\n");
-            WMCloseConnection(cPtr);
-            enqueueConnectionForRemoval(cPtr);
-            WMFreeArray(commands);
-            return;
-        } else if (strcasecmp(command, "id")==0) {
-            showId(cPtr);
-        } else if (strcasecmp(command, "help")==0) {
-            showHelp(cPtr);
-        } else if (strcasecmp(command, "list")==0) {
-            listUsers(cPtr);
-        } else if (strcasecmp(command, "set")==0) {
-            setTimeForUser(cPtr, cmdArgs);
-        } else if (strcasecmp(command, "add")==0) {
-            addTimeToUser(cPtr, cmdArgs);
-        } else if (strcasecmp(command, "sub")==0) {
-            subTimeFromUser(cPtr, cmdArgs);
-        } else if (strcasecmp(command, "remove")==0) {
-            removeTimeForUser(cPtr, cmdArgs);
-        } else if (strcasecmp(command, "get")==0) {
-            getTimeForUser(cPtr, cmdArgs);
-        } else {
-            buffer = wmalloc(strlen(command) + 100);
-            sprintf(buffer, _("Unknown command '%s'. Try HELP for"
-                              " a list of commands.\n"), command);
-            sendMessage(cPtr, buffer);
-            wfree(buffer);
-        }
-    }
-
-    WMFreeArray(commands);
-}
-
-
-static Bool
-isAllowedToConnect(WMConnection *cPtr)
-{
-    WMHost *hPtr;
-    int i;
-
-    if (allowedHostList == NULL)
-        return True; /* No list. Allow all by default */
-
-    hPtr = WMGetHostWithAddress(WMGetConnectionAddress(cPtr));
-    for (i=0; i<WMGetArrayItemCount(allowedHostList); i++) {
-        if (WMIsHostEqualToHost(hPtr, WMGetFromArray(allowedHostList, i))) {
-            WMReleaseHost(hPtr);
-            return True;
-        }
-    }
-
-    WMReleaseHost(hPtr);
-
-    return False;
-}
-
-
-static void
-didReceiveInput(ConnectionDelegate *self, WMConnection *cPtr)
-{
-    if (cPtr == serverPtr) {
-        WMConnection *newPtr = WMAcceptConnection(cPtr);
-
-        if (newPtr) {
-            if (isAllowedToConnect(newPtr)) {
-                WMSetConnectionDelegate(newPtr, &socketDelegate);
-                WMSetConnectionSendTimeout(newPtr, 120);
-                WMAddToArray(clientConnections, newPtr);
-            } else {
-                sendMessage(newPtr, "Sorry, you are not allowed to connect.\n");
-                WMDestroyConnection(newPtr);
-            }
-        }
-    } else {
-        /* Data arriving on an already-connected socket */
-        handleConnection(cPtr);
-    }
-}
-
-
-static void
-connectionDidTimeout(ConnectionDelegate *self, WMConnection *cPtr)
-{
-    WMHost *hPtr;
-
-    if (cPtr == serverPtr) {
-        wfatal(_("The server listening socket did timeout. Exiting."));
-        exit(1);
-    }
-
-    hPtr = WMGetHostWithAddress(WMGetConnectionAddress(cPtr));
-    wwarning(_("Connection with %s did timeout. Closing connection."),
-             WMGetHostName(hPtr));
-    WMReleaseHost(hPtr);
-
-    enqueueConnectionForRemoval(cPtr);
-}
-
-
-static void
-connectionDidDie(ConnectionDelegate *self, WMConnection *cPtr)
-{
-    if (cPtr == serverPtr) {
-        /* trouble. server listening port itself died!!! */
-        wfatal(_("The server listening socket died. Exiting."));
-        exit(1);
-    }
-
-    enqueueConnectionForRemoval(cPtr);
-}
-
-
-static void
-removeConnection(void *observer, WMNotification *notification)
-{
-    WMConnection *cPtr = (WMConnection*)WMGetNotificationObject(notification);
-    WMData *data;
-
-    WMRemoveFromArray(clientConnections, cPtr);
-    if ((data = (WMData*)WMGetConnectionClientData(cPtr))!=NULL)
-        WMReleaseData(data);
-    WMDestroyConnection(cPtr);
-}
-
-static void
-updatedDomain(void *observer, WMNotification *notification)
-{
-    wmessage("defaults domain file changed on disk. synchronizing.");
-}
-
-
-#if 0
-static Bool
-isDifferent(char *str1, char *str2)
-{
-    if ((!str1 && !str2) || (str1 && str2 && strcmp(str1, str2)==0))
-        return False;
-
-    return True;
-}
-#endif
-
-
-int
-main(int argc, char **argv)
-{
-    int i;
-
-    wsetabort(wAbort);
-
-    WMInitializeApplication("server", &argc, argv);
-
-    if (argc>1) {
-        for (i=1; i<argc; i++) {
-            if (strcmp(argv[i], "--help")==0) {
-                printHelp(argv[0]);
-                exit(0);
-            } else if (strcmp(argv[i], "--listen")==0) {
-                char *p;
-
-                if ((p = strchr(argv[++i], ':')) != NULL) {
-                    *p = 0;
-                    ServerAddress = wstrdup(argv[i]);
-                    ServerPort = wstrdup(p+1);
-                    *p = ':';
-                    if (ServerAddress[0] == 0) {
-                        wfree(ServerAddress);
-                        ServerAddress = NULL;
-                    }
-                    if (ServerPort[0] == 0) {
-                        wfree(ServerPort);
-                        ServerPort = "34567";
-                    }
-                } else if (argv[i][0]!=0) {
-                    ServerPort = argv[i];
-                }
-            } else if (strcmp(argv[i], "--allow")==0) {
-                char *p, *ptr;
-                int done;
-                WMHost *hPtr;
-
-                ptr = argv[++i];
-                done = 0;
-                while (!done) {
-                    if ((p = strchr(ptr, ',')) != NULL) {
-                        *p = 0;
-                    }
-                    if (*ptr != 0) {
-                        hPtr = WMGetHostWithName(ptr);
-                        if (hPtr) {
-                            if (!allowedHostList)
-                                allowedHostList = WMCreateArray(4);
-                            WMAddToArray(allowedHostList, hPtr);
-                        } else {
-                            wwarning(_("Unknown host '%s'. Ignored."), ptr);
-                        }
-                    }
-
-                    if (p!=NULL) {
-                        *p = ',';
-                        ptr = p+1;
-                    } else {
-                        done = 1;
-                    }
-                }
-            } else {
-                printf(_("%s: invalid argument '%s'\n"), argv[0], argv[i]);
-                printf(_("Try '%s --help' for more information\n"), argv[0]);
-                exit(1);
-            }
-        }
-    }
-
-    timeDB = WMGetDefaultsFromPath("./UserTime.plist");
-    WMAddNotificationObserver(updatedDomain, NULL,
-                              WMUserDefaultsDidChangeNotification, NULL);
-
-    clientConnections = WMCreateArray(4);
-
-    /* A NULL ServerAddress means to listen on any address the host has.
-     * Else if ServerAddress points to a specific address (like "localhost",
-     * "host.domain.com" or "192.168.1.1"), then it will only listen on that
-     * interface and ignore incoming connections on the others. */
-    if (ServerAddress && strcasecmp(ServerAddress, "Any")==0)
-        ServerAddress = NULL;
-    if (ServerPort==NULL)
-        ServerPort = "34567";
-
-    printf("Server will listen on '%s:%s'\n", ServerAddress?ServerAddress:"Any",
-           ServerPort);
-    printf("This server will allow connections from:");
-    if (allowedHostList) {
-        int i;
-        char *hName;
-
-        for (i=0; i<WMGetArrayItemCount(allowedHostList); i++) {
-            hName = WMGetHostName(WMGetFromArray(allowedHostList, i));
-            printf("%s'%s'", i==0?" ":", ", hName);
-        }
-        printf(".\n");
-    } else {
-        printf(" any host.\n");
-    }
-
-    serverPtr = WMCreateConnectionAsServerAtAddress(ServerAddress, ServerPort,
-                                                    NULL);
-
-    if (!serverPtr) {
-        wfatal("could not create server on `%s:%s`. Exiting.",
-               ServerAddress ? ServerAddress : "localhost", ServerPort);
-        exit(1);
-    }
-
-    WMSetConnectionDelegate(serverPtr, &socketDelegate);
-
-    WMAddNotificationObserver(removeConnection, NULL,
-                              SEConnectionShouldBeRemovedNotification, NULL);
-
-    while (1) {
-        /* The ASAP notification queue is called at the end of WHandleEvents()
-         * There's where died connections we get while running through
-         * WHandleEvents() get removed. */
-        WHandleEvents();
-    }
-
-    return 0;
-}
-
-
+/*
+ *  WINGs server.c: example how to create a network server using WMConnection
+ *
+ *  Copyright (c) 2001-2003 Dan Pascu
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <WINGs/WINGs.h>
+
+#define _(P)         P
+#define MAXCMD_SIZE  512
+
+char *SEConnectionShouldBeRemovedNotification = "SEConnectionShouldBeRemovedNotification";
+
+static void didReceiveInput(ConnectionDelegate * self, WMConnection * cPtr);
+
+static void connectionDidDie(ConnectionDelegate * self, WMConnection * cPtr);
+
+static void connectionDidTimeout(ConnectionDelegate * self, WMConnection * cPtr);
+
+extern char *SEConnectionShouldBeRemovedNotification;
+
+static WMUserDefaults *timeDB = NULL;
+static char *ServerAddress = NULL;
+static char *ServerPort = NULL;
+static WMArray *allowedHostList = NULL;
+static WMArray *clientConnections = NULL;
+static WMConnection *serverPtr = NULL;
+
+static ConnectionDelegate socketDelegate = {
+       NULL,                   /* client data */
+       NULL,                   /* canResumeSending */
+       NULL,                   /* didCatchException */
+       connectionDidDie,       /* didDie */
+       NULL,                   /* didInitialize */
+       didReceiveInput,        /* didReceiveInput */
+       connectionDidTimeout    /* didTimeout */
+};
+
+void wAbort(Bool foo)
+{
+       exit(1);
+}
+
+static void printHelp(char *progname)
+{
+       printf(_("usage: %s [options]\n\n"), progname);
+       puts(_(" --help                         print this message"));
+       puts(_(" --listen [address:]port        only listen on the specified address/port"));
+       puts(_(" --allow host1[,host2...]       only allow connections from listed hosts\n"));
+       puts(_(" By default server listens on all interfaces and port 34567, unless"
+              " something\nelse is specified with the --listen option. If address is"
+              " omitted or the keyword\n'Any' is used, it will listen on all interfaces else"
+              " only on the specified one.\n\nFor example --listen localhost: will"
+              " listen on the default port 34567, but only\non connections comming"
+              " in through the loopback interface.\n\n Also by default the server"
+              " listens to incoming connections from any host,\nunless a list of"
+              " hosts is given with the --allow option, in which case it will\nreject"
+              " connections not comming from those hosts.\nThe list of hosts is comma"
+              " separated and should NOT contain ANY spaces."));
+}
+
+static void enqueueConnectionForRemoval(WMConnection * cPtr)
+{
+       WMNotification *notif;
+
+       /*don't release notif here. it will be released by queue after processing */
+       notif = WMCreateNotification(SEConnectionShouldBeRemovedNotification, cPtr, NULL);
+       WMEnqueueNotification(WMGetDefaultNotificationQueue(), notif, WMPostASAP);
+}
+
+static int sendMessage(WMConnection * cPtr, char *message)
+{
+       WMData *aData;
+       int res;
+
+       if (WMGetConnectionState(cPtr) != WCConnected)
+               return -1;
+
+       aData = WMCreateDataWithBytes(message, strlen(message));
+       res = WMSendConnectionData(cPtr, aData);
+       WMReleaseData(aData);
+
+       return res;
+}
+
+static Bool enqueueMessage(WMConnection * cPtr, char *message)
+{
+       WMData *aData;
+       Bool res;
+
+       if (WMGetConnectionState(cPtr) != WCConnected)
+               return False;
+
+       aData = WMCreateDataWithBytes(message, strlen(message));
+       res = WMEnqueueConnectionData(cPtr, aData);
+       WMReleaseData(aData);
+
+       return res;
+}
+
+static char *findDelimiter(char *data, const char *endPtr)
+{
+       wassertrv(data < endPtr, NULL);
+
+       while (data < endPtr && *data != '\n' && *data != '\r' && *data != ';' && *data != '\0')
+               data++;
+
+       if (data < endPtr)
+               return data;
+
+       return NULL;
+}
+
+static WMArray *getAvailableMessages(WMConnection * cPtr)
+{
+       char *ptr, *crtPos, *buffer;
+       const char *bytes, *endPtr;
+       WMData *aData, *receivedData, *holdData;
+       WMRange range;
+       WMArray *messages;
+       int length;
+
+       receivedData = WMGetConnectionAvailableData(cPtr);
+       if (!receivedData)
+               return NULL;
+       if ((length = WMGetDataLength(receivedData)) == 0) {
+               WMReleaseData(receivedData);
+               return NULL;
+       }
+
+       holdData = (WMData *) WMGetConnectionClientData(cPtr);
+       if (holdData) {
+               WMAppendData(holdData, receivedData);
+               WMReleaseData(receivedData);
+               WMSetConnectionClientData(cPtr, NULL);
+               aData = holdData;
+       } else {
+               aData = receivedData;
+       }
+
+       length = WMGetDataLength(aData);
+       bytes = (char *)WMDataBytes(aData);
+       endPtr = bytes + length;
+
+       messages = WMCreateArrayWithDestructor(1, wfree);
+       crtPos = (char *)bytes;
+       while (crtPos < endPtr && (ptr = findDelimiter(crtPos, endPtr)) != NULL) {
+               range.position = (crtPos - bytes);
+               range.count = (ptr - crtPos);
+               if (range.count > MAXCMD_SIZE) {
+                       /* Hmmm... The message is too long. Possibly that someone is
+                        * flooding us, or there is a dumb client which do not know
+                        * who is talking to. */
+                       sendMessage(cPtr, "Command too long\n\r");
+                       WMFreeArray(messages);
+                       WMReleaseData(aData);
+                       WMCloseConnection(cPtr);
+                       enqueueConnectionForRemoval(cPtr);
+                       return NULL;
+               }
+               buffer = wmalloc(range.count + 1);
+               WMGetDataBytesWithRange(aData, buffer, range);
+               buffer[range.count] = '\0';
+               WMAddToArray(messages, buffer);
+               crtPos = ptr;
+               while (crtPos < endPtr && (*crtPos == '\n' || *crtPos == '\r' ||
+                                          *crtPos == '\t' || *crtPos == '\0' ||
+                                          *crtPos == ';' || *crtPos == ' ')) {
+                       crtPos++;
+               }
+       }
+
+       if (crtPos < endPtr) {
+               range.position = (crtPos - bytes);
+               range.count = (endPtr - crtPos);
+               if (range.count > MAXCMD_SIZE) {
+                       /* Flooooooding!!!! */
+                       sendMessage(cPtr, "Message too long\n\r");
+                       WMFreeArray(messages);
+                       WMReleaseData(aData);
+                       WMCloseConnection(cPtr);
+                       enqueueConnectionForRemoval(cPtr);
+                       return NULL;
+               }
+               holdData = WMGetSubdataWithRange(aData, range);
+               WMSetConnectionClientData(cPtr, holdData);
+       }
+       WMReleaseData(aData);
+
+       if (WMGetArrayItemCount(messages) == 0) {
+               WMFreeArray(messages);
+               messages = NULL;
+       }
+       return messages;
+}
+
+static void complainAboutBadArgs(WMConnection * cPtr, char *cmdName, char *badArgs)
+{
+       char *buf = wmalloc(strlen(cmdName) + strlen(badArgs) + 100);
+
+       sprintf(buf, _("Invalid parameters '%s' for command %s. Use HELP for"
+                      " a list of commands.\n"), badArgs, cmdName);
+       sendMessage(cPtr, buf);
+       wfree(buf);
+}
+
+static void sendUpdateMessage(WMConnection * cPtr, char *id, int time)
+{
+       char *buf = wmalloc(strlen(id) + 100);
+
+       sprintf(buf, "%s has %i minutes left\n", id, time);
+       sendMessage(cPtr, buf);
+       wfree(buf);
+}
+
+static void showId(WMConnection * cPtr)
+{
+       sendMessage(cPtr, "Server example based on WMConnection\n");
+}
+
+static void showHelp(WMConnection * cPtr)
+{
+       char *buf = wmalloc(strlen(WMGetApplicationName()) + 16);
+
+       sprintf(buf, _("%s commands:\n\n"), WMGetApplicationName());
+
+       enqueueMessage(cPtr, _("\n"));
+       enqueueMessage(cPtr, buf);
+       enqueueMessage(cPtr, _("GET <id>\t- return time left (in minutes) " "for user with id <id>\n"));
+       enqueueMessage(cPtr, _("SET <id> <time>\t- set time limit to <time> " "minutes for user with id <id>\n"));
+       enqueueMessage(cPtr, _("ADD <id> <time>\t- add <time> minutes " "for user with id <id>\n"));
+       enqueueMessage(cPtr, _("SUB <id> <time>\t- subtract <time> minutes " "for user with id <id>\n"));
+       enqueueMessage(cPtr, _("REMOVE <id>\t- remove time limitations for " "user with id <id>\n"));
+       enqueueMessage(cPtr, _("LIST\t\t- list all users and their " "corresponding time limit\n"));
+       enqueueMessage(cPtr, _("ID\t\t- returns the Time Manager " "identification string\n"));
+       enqueueMessage(cPtr, _("EXIT\t\t- exits session\n"));
+       enqueueMessage(cPtr, _("QUIT\t\t- exits session\n"));
+       enqueueMessage(cPtr, _("HELP\t\t- show this message\n\n"));
+       /* Just flush the queue we made before */
+       WMFlushConnection(cPtr);
+       wfree(buf);
+}
+
+static void listUsers(WMConnection * cPtr)
+{
+       WMPropList *userList;
+       char *id;
+       int i, time;
+
+       userList = WMGetUDKeys(timeDB);
+
+       for (i = 0; i < WMGetPropListItemCount(userList); i++) {
+               id = WMGetFromPLString(WMGetFromPLArray(userList, i));
+               time = WMGetUDIntegerForKey(timeDB, id);
+               sendUpdateMessage(cPtr, id, time);
+       }
+
+       WMReleasePropList(userList);
+}
+
+static void setTimeForUser(WMConnection * cPtr, char *cmdArgs)
+{
+       char *id;
+       int i, time;
+
+       id = wmalloc(strlen(cmdArgs));
+       if (sscanf(cmdArgs, "%s %d", id, &time) != 2) {
+               complainAboutBadArgs(cPtr, "SET", cmdArgs);
+               wfree(id);
+               return;
+       }
+       if (time < 0)
+               time = 0;
+
+       WMSetUDIntegerForKey(timeDB, time, id);
+
+       for (i = 0; i < WMGetArrayItemCount(clientConnections); i++) {
+               cPtr = WMGetFromArray(clientConnections, i);
+               sendUpdateMessage(cPtr, id, time);
+       }
+       wfree(id);
+}
+
+static void addTimeToUser(WMConnection * cPtr, char *cmdArgs)
+{
+       char *id;
+       int i, time, newTime;
+
+       id = wmalloc(strlen(cmdArgs));
+       if (sscanf(cmdArgs, "%s %d", id, &time) != 2) {
+               complainAboutBadArgs(cPtr, "ADD", cmdArgs);
+               wfree(id);
+               return;
+       }
+
+       newTime = WMGetUDIntegerForKey(timeDB, id) + time;
+       if (newTime < 0)
+               newTime = 0;
+
+       WMSetUDIntegerForKey(timeDB, newTime, id);
+
+       for (i = 0; i < WMGetArrayItemCount(clientConnections); i++) {
+               cPtr = WMGetFromArray(clientConnections, i);
+               sendUpdateMessage(cPtr, id, newTime);
+       }
+       wfree(id);
+}
+
+static void subTimeFromUser(WMConnection * cPtr, char *cmdArgs)
+{
+       char *id;
+       int i, time, newTime;
+
+       id = wmalloc(strlen(cmdArgs));
+       if (sscanf(cmdArgs, "%s %d", id, &time) != 2) {
+               complainAboutBadArgs(cPtr, "SUB", cmdArgs);
+               wfree(id);
+               return;
+       }
+
+       newTime = WMGetUDIntegerForKey(timeDB, id) - time;
+       if (newTime < 0)
+               newTime = 0;
+
+       WMSetUDIntegerForKey(timeDB, newTime, id);
+
+       for (i = 0; i < WMGetArrayItemCount(clientConnections); i++) {
+               cPtr = WMGetFromArray(clientConnections, i);
+               sendUpdateMessage(cPtr, id, newTime);
+       }
+       wfree(id);
+}
+
+static void removeTimeForUser(WMConnection * cPtr, char *cmdArgs)
+{
+       char *ptr;
+       int i;
+
+       if (cmdArgs[0] == '\0') {
+               sendMessage(cPtr, _("Missing parameter for command REMOVE."
+                                   " Use HELP for a list of commands.\n"));
+               return;
+       }
+
+       ptr = cmdArgs;
+       while (*ptr && *ptr != ' ' && *ptr != '\t')
+               ptr++;
+       *ptr = '\0';
+
+       WMRemoveUDObjectForKey(timeDB, cmdArgs);
+
+       for (i = 0; i < WMGetArrayItemCount(clientConnections); i++) {
+               cPtr = WMGetFromArray(clientConnections, i);
+               sendUpdateMessage(cPtr, cmdArgs, -1);
+       }
+}
+
+static void getTimeForUser(WMConnection * cPtr, char *cmdArgs)
+{
+       char *ptr;
+       int time;
+
+       if (cmdArgs[0] == '\0') {
+               sendMessage(cPtr, _("Missing parameter for command GET." " Use HELP for a list of commands.\n"));
+               return;
+       }
+
+       ptr = cmdArgs;
+       while (*ptr && *ptr != ' ' && *ptr != '\t')
+               ptr++;
+       *ptr = '\0';
+
+       if (WMGetUDObjectForKey(timeDB, cmdArgs) != NULL)
+               time = WMGetUDIntegerForKey(timeDB, cmdArgs);
+       else
+               time = -1;
+
+       sendUpdateMessage(cPtr, cmdArgs, time);
+}
+
+static void handleConnection(WMConnection * cPtr)
+{
+       char *command, *ptr, *cmdArgs, *buffer;
+       WMArray *commands;
+       int i;
+
+       commands = getAvailableMessages(cPtr);
+       if (!commands)
+               return;
+
+       for (i = 0; i < WMGetArrayItemCount(commands); i++) {
+               command = WMGetFromArray(commands, i);
+               while (*command && (*command == ' ' || *command == '\t'))
+                       command++;
+               ptr = command;
+               while (*ptr && *ptr != ' ' && *ptr != '\t')
+                       ptr++;
+               if (*ptr) {
+                       *ptr = '\0';
+                       ptr++;
+               }
+               while (*ptr && (*ptr == ' ' || *ptr == '\t'))
+                       ptr++;
+
+               cmdArgs = ptr;
+
+               fprintf(stderr, "Command: '%s', args: '%s'\n", command, cmdArgs);
+
+               if (strcasecmp(command, "quit") == 0 || strcasecmp(command, "exit") == 0) {
+                       sendMessage(cPtr, "Bye\n");
+                       WMCloseConnection(cPtr);
+                       enqueueConnectionForRemoval(cPtr);
+                       WMFreeArray(commands);
+                       return;
+               } else if (strcasecmp(command, "id") == 0) {
+                       showId(cPtr);
+               } else if (strcasecmp(command, "help") == 0) {
+                       showHelp(cPtr);
+               } else if (strcasecmp(command, "list") == 0) {
+                       listUsers(cPtr);
+               } else if (strcasecmp(command, "set") == 0) {
+                       setTimeForUser(cPtr, cmdArgs);
+               } else if (strcasecmp(command, "add") == 0) {
+                       addTimeToUser(cPtr, cmdArgs);
+               } else if (strcasecmp(command, "sub") == 0) {
+                       subTimeFromUser(cPtr, cmdArgs);
+               } else if (strcasecmp(command, "remove") == 0) {
+                       removeTimeForUser(cPtr, cmdArgs);
+               } else if (strcasecmp(command, "get") == 0) {
+                       getTimeForUser(cPtr, cmdArgs);
+               } else {
+                       buffer = wmalloc(strlen(command) + 100);
+                       sprintf(buffer, _("Unknown command '%s'. Try HELP for" " a list of commands.\n"), command);
+                       sendMessage(cPtr, buffer);
+                       wfree(buffer);
+               }
+       }
+
+       WMFreeArray(commands);
+}
+
+static Bool isAllowedToConnect(WMConnection * cPtr)
+{
+       WMHost *hPtr;
+       int i;
+
+       if (allowedHostList == NULL)
+               return True;    /* No list. Allow all by default */
+
+       hPtr = WMGetHostWithAddress(WMGetConnectionAddress(cPtr));
+       for (i = 0; i < WMGetArrayItemCount(allowedHostList); i++) {
+               if (WMIsHostEqualToHost(hPtr, WMGetFromArray(allowedHostList, i))) {
+                       WMReleaseHost(hPtr);
+                       return True;
+               }
+       }
+
+       WMReleaseHost(hPtr);
+
+       return False;
+}
+
+static void didReceiveInput(ConnectionDelegate * self, WMConnection * cPtr)
+{
+       if (cPtr == serverPtr) {
+               WMConnection *newPtr = WMAcceptConnection(cPtr);
+
+               if (newPtr) {
+                       if (isAllowedToConnect(newPtr)) {
+                               WMSetConnectionDelegate(newPtr, &socketDelegate);
+                               WMSetConnectionSendTimeout(newPtr, 120);
+                               WMAddToArray(clientConnections, newPtr);
+                       } else {
+                               sendMessage(newPtr, "Sorry, you are not allowed to connect.\n");
+                               WMDestroyConnection(newPtr);
+                       }
+               }
+       } else {
+               /* Data arriving on an already-connected socket */
+               handleConnection(cPtr);
+       }
+}
+
+static void connectionDidTimeout(ConnectionDelegate * self, WMConnection * cPtr)
+{
+       WMHost *hPtr;
+
+       if (cPtr == serverPtr) {
+               wfatal(_("The server listening socket did timeout. Exiting."));
+               exit(1);
+       }
+
+       hPtr = WMGetHostWithAddress(WMGetConnectionAddress(cPtr));
+       wwarning(_("Connection with %s did timeout. Closing connection."), WMGetHostName(hPtr));
+       WMReleaseHost(hPtr);
+
+       enqueueConnectionForRemoval(cPtr);
+}
+
+static void connectionDidDie(ConnectionDelegate * self, WMConnection * cPtr)
+{
+       if (cPtr == serverPtr) {
+               /* trouble. server listening port itself died!!! */
+               wfatal(_("The server listening socket died. Exiting."));
+               exit(1);
+       }
+
+       enqueueConnectionForRemoval(cPtr);
+}
+
+static void removeConnection(void *observer, WMNotification * notification)
+{
+       WMConnection *cPtr = (WMConnection *) WMGetNotificationObject(notification);
+       WMData *data;
+
+       WMRemoveFromArray(clientConnections, cPtr);
+       if ((data = (WMData *) WMGetConnectionClientData(cPtr)) != NULL)
+               WMReleaseData(data);
+       WMDestroyConnection(cPtr);
+}
+
+static void updatedDomain(void *observer, WMNotification * notification)
+{
+       wmessage("defaults domain file changed on disk. synchronizing.");
+}
+
+#if 0
+static Bool isDifferent(char *str1, char *str2)
+{
+       if ((!str1 && !str2) || (str1 && str2 && strcmp(str1, str2) == 0))
+               return False;
+
+       return True;
+}
+#endif
+
+int main(int argc, char **argv)
+{
+       int i;
+
+       wsetabort(wAbort);
+
+       WMInitializeApplication("server", &argc, argv);
+
+       if (argc > 1) {
+               for (i = 1; i < argc; i++) {
+                       if (strcmp(argv[i], "--help") == 0) {
+                               printHelp(argv[0]);
+                               exit(0);
+                       } else if (strcmp(argv[i], "--listen") == 0) {
+                               char *p;
+
+                               if ((p = strchr(argv[++i], ':')) != NULL) {
+                                       *p = 0;
+                                       ServerAddress = wstrdup(argv[i]);
+                                       ServerPort = wstrdup(p + 1);
+                                       *p = ':';
+                                       if (ServerAddress[0] == 0) {
+                                               wfree(ServerAddress);
+                                               ServerAddress = NULL;
+                                       }
+                                       if (ServerPort[0] == 0) {
+                                               wfree(ServerPort);
+                                               ServerPort = "34567";
+                                       }
+                               } else if (argv[i][0] != 0) {
+                                       ServerPort = argv[i];
+                               }
+                       } else if (strcmp(argv[i], "--allow") == 0) {
+                               char *p, *ptr;
+                               int done;
+                               WMHost *hPtr;
+
+                               ptr = argv[++i];
+                               done = 0;
+                               while (!done) {
+                                       if ((p = strchr(ptr, ',')) != NULL) {
+                                               *p = 0;
+                                       }
+                                       if (*ptr != 0) {
+                                               hPtr = WMGetHostWithName(ptr);
+                                               if (hPtr) {
+                                                       if (!allowedHostList)
+                                                               allowedHostList = WMCreateArray(4);
+                                                       WMAddToArray(allowedHostList, hPtr);
+                                               } else {
+                                                       wwarning(_("Unknown host '%s'. Ignored."), ptr);
+                                               }
+                                       }
+
+                                       if (p != NULL) {
+                                               *p = ',';
+                                               ptr = p + 1;
+                                       } else {
+                                               done = 1;
+                                       }
+                               }
+                       } else {
+                               printf(_("%s: invalid argument '%s'\n"), argv[0], argv[i]);
+                               printf(_("Try '%s --help' for more information\n"), argv[0]);
+                               exit(1);
+                       }
+               }
+       }
+
+       timeDB = WMGetDefaultsFromPath("./UserTime.plist");
+       WMAddNotificationObserver(updatedDomain, NULL, WMUserDefaultsDidChangeNotification, NULL);
+
+       clientConnections = WMCreateArray(4);
+
+       /* A NULL ServerAddress means to listen on any address the host has.
+        * Else if ServerAddress points to a specific address (like "localhost",
+        * "host.domain.com" or "192.168.1.1"), then it will only listen on that
+        * interface and ignore incoming connections on the others. */
+       if (ServerAddress && strcasecmp(ServerAddress, "Any") == 0)
+               ServerAddress = NULL;
+       if (ServerPort == NULL)
+               ServerPort = "34567";
+
+       printf("Server will listen on '%s:%s'\n", ServerAddress ? ServerAddress : "Any", ServerPort);
+       printf("This server will allow connections from:");
+       if (allowedHostList) {
+               int i;
+               char *hName;
+
+               for (i = 0; i < WMGetArrayItemCount(allowedHostList); i++) {
+                       hName = WMGetHostName(WMGetFromArray(allowedHostList, i));
+                       printf("%s'%s'", i == 0 ? " " : ", ", hName);
+               }
+               printf(".\n");
+       } else {
+               printf(" any host.\n");
+       }
+
+       serverPtr = WMCreateConnectionAsServerAtAddress(ServerAddress, ServerPort, NULL);
+
+       if (!serverPtr) {
+               wfatal("could not create server on `%s:%s`. Exiting.",
+                      ServerAddress ? ServerAddress : "localhost", ServerPort);
+               exit(1);
+       }
+
+       WMSetConnectionDelegate(serverPtr, &socketDelegate);
+
+       WMAddNotificationObserver(removeConnection, NULL, SEConnectionShouldBeRemovedNotification, NULL);
+
+       while (1) {
+               /* The ASAP notification queue is called at the end of WHandleEvents()
+                * There's where died connections we get while running through
+                * WHandleEvents() get removed. */
+               WHandleEvents();
+       }
+
+       return 0;
+}
dissimilarity index 91%
index e37b11e..e3c4d6b 100644 (file)
-
-
-#include <WINGs/WINGs.h>
-#include <stdio.h>
-#include <stdint.h>
-#include "wtableview.h"
-#include "wtabledelegates.h"
-
-
-static char *col1[20] = {0};
-static int col2[20];
-
-
-static char *options[] = {
-    "Option1",
-    "Option2",
-    "Option3",
-    "Option4",
-    "Option5"
-};
-
-
-int
-numberOfRows(WMTableViewDelegate *self, WMTableView *table)
-{
-    return 20;
-}
-
-
-void*
-valueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row)
-{
-    /*WMTableView *table = (WMTableView*)WMGetTableColumnTableView(column);*/
-    int i;
-    if (col1[0] == 0) {
-        for (i = 0; i < 20; i++) {
-            char buf[128];
-
-            sprintf(buf, "Test row %i", i);
-
-            col1[i] = wstrdup(buf);
-            col2[i] = 0;
-        }
-    }
-    if ((int)(uintptr_t)WMGetTableColumnId(column) == 1)
-        return col1[row];
-    else
-        return (void*)(uintptr_t)col2[row];
-}
-
-
-void
-setValueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row,
-                void *data)
-{
-    if ((int)(uintptr_t)WMGetTableColumnId(column) == 1)
-        col1[row] = data;
-    else
-        col2[row] = (int)(uintptr_t)data;
-}
-
-
-static WMTableViewDelegate delegate = {
-    NULL,
-    numberOfRows,
-    valueForCell,
-    setValueForCell
-};
-
-
-
-void
-clickedTable(WMWidget *w, void *self)
-{
-    int row = WMGetTableViewClickedRow((WMTableView*)self);
-
-    WMEditTableViewRow(self, row);
-}
-
-
-
-int
-main(int argc, char **argv)
-{
-    WMScreen *scr;
-    WMWindow *win;
-    WMTableView *table;
-    WMTableColumn *col;
-    WMTableColumnDelegate *colDeleg;
-
-    WMInitializeApplication("test", &argc, argv);
-
-    scr = WMOpenScreen(NULL);
-
-    XSynchronize(WMScreenDisplay(scr), 1);
-
-    win = WMCreateWindow(scr, "eweq");
-    WMResizeWidget(win, 400, 200);
-    WMMapWidget(win);
-
-    table = WMCreateTableView(win);
-    WMSetTableViewHasHorizontalScroller(table, 0);
-    WMSetViewExpandsToParent(WMWidgetView(table), 10, 10, 10, 10);
-    WMSetTableViewBackgroundColor(table, WMWhiteColor(scr));
-    /*WMSetTableViewGridColor(table, WMGrayColor(scr));*/
-    WMSetTableViewHeaderHeight(table, 20);
-    WMSetTableViewDelegate(table, &delegate);
-    WMSetTableViewAction(table, clickedTable, table);
-
-    colDeleg = WTCreateStringEditorDelegate(table);
-
-    col = WMCreateTableColumn("Group");
-    WMSetTableColumnWidth(col, 180);
-    WMAddTableViewColumn(table, col);
-    WMSetTableColumnDelegate(col, colDeleg);
-    WMSetTableColumnId(col, (void*)1);
-
-    colDeleg = WTCreateEnumSelectorDelegate(table);
-    WTSetEnumSelectorOptions(colDeleg, options, 5);
-
-    col = WMCreateTableColumn("Package");
-    WMSetTableColumnWidth(col, 140);
-    WMAddTableViewColumn(table, col);
-    WMSetTableColumnDelegate(col, colDeleg);
-    WMSetTableColumnId(col, (void*)2);
-
-    colDeleg = WTCreateBooleanSwitchDelegate(table);
-
-    col = WMCreateTableColumn("Bool");
-    WMSetTableColumnWidth(col, 50);
-    WMAddTableViewColumn(table, col);
-    WMSetTableColumnDelegate(col, colDeleg);
-    WMSetTableColumnId(col, (void*)2);
-
-    WMMapWidget(table);
-    WMRealizeWidget(win);
-    WMScreenMainLoop(scr);
-
-    return 0;
-}
-
+
+#include <WINGs/WINGs.h>
+#include <stdio.h>
+#include <stdint.h>
+#include "wtableview.h"
+#include "wtabledelegates.h"
+
+static char *col1[20] = { 0 };
+
+static int col2[20];
+
+static char *options[] = {
+       "Option1",
+       "Option2",
+       "Option3",
+       "Option4",
+       "Option5"
+};
+
+int numberOfRows(WMTableViewDelegate * self, WMTableView * table)
+{
+       return 20;
+}
+
+void *valueForCell(WMTableViewDelegate * self, WMTableColumn * column, int row)
+{
+       /*WMTableView *table = (WMTableView*)WMGetTableColumnTableView(column); */
+       int i;
+       if (col1[0] == 0) {
+               for (i = 0; i < 20; i++) {
+                       char buf[128];
+
+                       sprintf(buf, "Test row %i", i);
+
+                       col1[i] = wstrdup(buf);
+                       col2[i] = 0;
+               }
+       }
+       if ((int)(uintptr_t) WMGetTableColumnId(column) == 1)
+               return col1[row];
+       else
+               return (void *)(uintptr_t) col2[row];
+}
+
+void setValueForCell(WMTableViewDelegate * self, WMTableColumn * column, int row, void *data)
+{
+       if ((int)(uintptr_t) WMGetTableColumnId(column) == 1)
+               col1[row] = data;
+       else
+               col2[row] = (int)(uintptr_t) data;
+}
+
+static WMTableViewDelegate delegate = {
+       NULL,
+       numberOfRows,
+       valueForCell,
+       setValueForCell
+};
+
+void clickedTable(WMWidget * w, void *self)
+{
+       int row = WMGetTableViewClickedRow((WMTableView *) self);
+
+       WMEditTableViewRow(self, row);
+}
+
+int main(int argc, char **argv)
+{
+       WMScreen *scr;
+       WMWindow *win;
+       WMTableView *table;
+       WMTableColumn *col;
+       WMTableColumnDelegate *colDeleg;
+
+       WMInitializeApplication("test", &argc, argv);
+
+       scr = WMOpenScreen(NULL);
+
+       XSynchronize(WMScreenDisplay(scr), 1);
+
+       win = WMCreateWindow(scr, "eweq");
+       WMResizeWidget(win, 400, 200);
+       WMMapWidget(win);
+
+       table = WMCreateTableView(win);
+       WMSetTableViewHasHorizontalScroller(table, 0);
+       WMSetViewExpandsToParent(WMWidgetView(table), 10, 10, 10, 10);
+       WMSetTableViewBackgroundColor(table, WMWhiteColor(scr));
+       /*WMSetTableViewGridColor(table, WMGrayColor(scr)); */
+       WMSetTableViewHeaderHeight(table, 20);
+       WMSetTableViewDelegate(table, &delegate);
+       WMSetTableViewAction(table, clickedTable, table);
+
+       colDeleg = WTCreateStringEditorDelegate(table);
+
+       col = WMCreateTableColumn("Group");
+       WMSetTableColumnWidth(col, 180);
+       WMAddTableViewColumn(table, col);
+       WMSetTableColumnDelegate(col, colDeleg);
+       WMSetTableColumnId(col, (void *)1);
+
+       colDeleg = WTCreateEnumSelectorDelegate(table);
+       WTSetEnumSelectorOptions(colDeleg, options, 5);
+
+       col = WMCreateTableColumn("Package");
+       WMSetTableColumnWidth(col, 140);
+       WMAddTableViewColumn(table, col);
+       WMSetTableColumnDelegate(col, colDeleg);
+       WMSetTableColumnId(col, (void *)2);
+
+       colDeleg = WTCreateBooleanSwitchDelegate(table);
+
+       col = WMCreateTableColumn("Bool");
+       WMSetTableColumnWidth(col, 50);
+       WMAddTableViewColumn(table, col);
+       WMSetTableColumnDelegate(col, colDeleg);
+       WMSetTableColumnId(col, (void *)2);
+
+       WMMapWidget(table);
+       WMRealizeWidget(win);
+       WMScreenMainLoop(scr);
+
+       return 0;
+}
dissimilarity index 94%
index c7c3d74..5b6e461 100644 (file)
-
-#include <stdint.h>
-#include <WINGs/WINGsP.h>
-
-#include "wtableview.h"
-
-#include "wtabledelegates.h"
-
-typedef struct {
-    WMTableView *table;
-    WMFont *font;
-    GC gc;
-    GC selGC;
-    WMColor *textColor;
-} StringData;
-
-
-typedef struct {
-    WMTableView *table;
-    GC selGc;
-} PixmapData;
-
-
-
-typedef struct {
-    WMTextField *widget;
-    WMTableView *table;
-    WMFont *font;
-    GC gc;
-    GC selGC;
-    WMColor *textColor;
-} StringEditorData;
-
-
-typedef struct {
-    WMPopUpButton *widget;
-    WMTableView *table;
-    WMFont *font;
-    char **options;
-    int count;
-    GC gc;
-    GC selGC;
-    WMColor *textColor;
-} EnumSelectorData;
-
-
-typedef struct {
-    WMButton *widget;
-    WMTableView *table;
-    Bool state;
-    GC gc;
-    GC selGC;
-} BooleanSwitchData;
-
-
-static char *SelectionColor = "#bbbbcc";
-
-
-
-static void
-stringDraw(WMScreen *scr, Drawable d, GC gc, GC sgc, WMColor *textColor,
-           WMFont *font, void *data, WMRect rect, Bool selected)
-{
-    int x, y;
-    XRectangle rects[1];
-    Display *dpy = WMScreenDisplay(scr);
-
-    x = rect.pos.x + 5;
-    y = rect.pos.y + (rect.size.height - WMFontHeight(font))/2;
-
-    rects[0].x = rect.pos.x+1;
-    rects[0].y = rect.pos.y+1;
-    rects[0].width = rect.size.width-1;
-    rects[0].height = rect.size.height-1;
-    XSetClipRectangles(dpy, gc, 0, 0, rects, 1, YXSorted);
-
-    if (!selected) {
-        XFillRectangles(dpy, d, gc, rects, 1);
-
-        WMDrawString(scr, d, textColor, font, x, y,
-                     data, strlen(data));
-    } else {
-        XFillRectangles(dpy, d, sgc, rects, 1);
-
-        WMDrawString(scr, d, textColor, font, x, y,
-                     data, strlen(data));
-    }
-
-    XSetClipMask(dpy, gc, None);
-}
-
-
-
-static void
-pixmapDraw(WMScreen *scr, Drawable d, GC gc, GC sgc, WMPixmap *pixmap,
-           WMRect rect, Bool selected)
-{
-    int x, y;
-    XRectangle rects[1];
-    Display *dpy = WMScreenDisplay(scr);
-    WMSize size;
-
-    rects[0].x = rect.pos.x+1;
-    rects[0].y = rect.pos.y+1;
-    rects[0].width = rect.size.width-1;
-    rects[0].height = rect.size.height-1;
-    XSetClipRectangles(dpy, gc, 0, 0, rects, 1, YXSorted);
-
-    if (!selected) {
-        XFillRectangles(dpy, d, gc, rects, 1);
-
-        if (pixmap) {
-            size = WMGetPixmapSize(pixmap);
-            x = rect.pos.x + (rect.size.width - size.width) / 2;
-            y = rect.pos.y + (rect.size.height - size.height) / 2;
-
-            WMDrawPixmap(pixmap, d, x, y);
-        }
-    } else {
-        XFillRectangles(dpy, d, sgc, rects, 1);
-
-        if (pixmap) {
-            size = WMGetPixmapSize(pixmap);
-            x = rect.pos.x + (rect.size.width - size.width) / 2;
-            y = rect.pos.y + (rect.size.height - size.height) / 2;
-
-            WMDrawPixmap(pixmap, d, x, y);
-        }
-    }
-
-    XSetClipMask(dpy, gc, None);
-}
-
-
-/* ---------------------------------------------------------------------- */
-
-
-
-static void
-SECellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
-              int row, Drawable d)
-{
-    StringEditorData *strdata = (StringEditorData*)self->data;
-    WMTableView *table = WMGetTableColumnTableView(column);
-
-    stringDraw(WMWidgetScreen(table), d,
-               strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
-               WMTableViewDataForCell(table, column, row),
-               WMTableViewRectForCell(table, column, row),
-               False);
-}
-
-
-static void
-selectedSECellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
-                      int row, Drawable d)
-{
-    StringEditorData *strdata = (StringEditorData*)self->data;
-    WMTableView *table = WMGetTableColumnTableView(column);
-
-    stringDraw(WMWidgetScreen(table), d,
-               strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
-               WMTableViewDataForCell(table, column, row),
-               WMTableViewRectForCell(table, column, row),
-               True);
-}
-
-
-static void
-beginSECellEdit(WMTableColumnDelegate *self, WMTableColumn *column, int row)
-{
-    StringEditorData *strdata = (StringEditorData*)self->data;
-    WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
-    void *data = WMTableViewDataForCell(strdata->table, column, row);
-
-    WMSetTextFieldText(strdata->widget, (char*)data);
-    WMMoveWidget(strdata->widget, rect.pos.x, rect.pos.y);
-    WMResizeWidget(strdata->widget, rect.size.width+1, rect.size.height+1);
-
-    WMMapWidget(strdata->widget);
-}
-
-
-static void
-endSECellEdit(WMTableColumnDelegate *self, WMTableColumn *column, int row)
-{
-    StringEditorData *strdata = (StringEditorData*)self->data;
-    char *text;
-
-    WMUnmapWidget(strdata->widget);
-
-    text = WMGetTextFieldText(strdata->widget);
-    WMSetTableViewDataForCell(strdata->table, column, row, (void*)text);
-}
-
-
-WMTableColumnDelegate*
-WTCreateStringEditorDelegate(WMTableView *parent)
-{
-    WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
-    WMScreen *scr = WMWidgetScreen(parent);
-    StringEditorData *data = wmalloc(sizeof(StringEditorData));
-
-    data->widget = WMCreateTextField(parent);
-    W_ReparentView(WMWidgetView(data->widget),
-                   WMGetTableViewDocumentView(parent),
-                   0, 0);
-    data->table = parent;
-    data->font = WMSystemFontOfSize(scr, 12);
-    data->gc = WMColorGC(WMWhiteColor(scr));
-    data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
-    data->textColor = WMBlackColor(scr);
-
-    delegate->data = data;
-    delegate->drawCell = SECellPainter;
-    delegate->drawSelectedCell = selectedSECellPainter;
-    delegate->beginCellEdit = beginSECellEdit;
-    delegate->endCellEdit = endSECellEdit;
-
-    return delegate;
-}
-
-
-
-/* ---------------------------------------------------------------------- */
-
-
-static void
-ESCellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
-              int row, Drawable d)
-{
-    EnumSelectorData *strdata = (EnumSelectorData*)self->data;
-    WMTableView *table = WMGetTableColumnTableView(column);
-    int i = (int)(uintptr_t)WMTableViewDataForCell(table, column, row);
-
-    stringDraw(WMWidgetScreen(table), d,
-               strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
-               strdata->options[i],
-               WMTableViewRectForCell(table, column, row),
-               False);
-}
-
-
-static void
-selectedESCellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
-                      int row, Drawable d)
-{
-    EnumSelectorData *strdata = (EnumSelectorData*)self->data;
-    WMTableView *table = WMGetTableColumnTableView(column);
-    int i = (int)(uintptr_t)WMTableViewDataForCell(table, column, row);
-
-    stringDraw(WMWidgetScreen(table), d,
-               strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
-               strdata->options[i],
-               WMTableViewRectForCell(table, column, row),
-               True);
-}
-
-
-static void
-beginESCellEdit(WMTableColumnDelegate *self, WMTableColumn *column, int row)
-{
-    EnumSelectorData *strdata = (EnumSelectorData*)self->data;
-    WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
-    int data = (int)(uintptr_t)WMTableViewDataForCell(strdata->table, column, row);
-
-    wassertr(data < strdata->count);
-
-    WMSetPopUpButtonSelectedItem(strdata->widget, data);
-
-    WMMoveWidget(strdata->widget, rect.pos.x, rect.pos.y);
-    WMResizeWidget(strdata->widget, rect.size.width, rect.size.height+1);
-
-    WMMapWidget(strdata->widget);
-}
-
-
-static void
-endESCellEdit(WMTableColumnDelegate *self, WMTableColumn *column, int row)
-{
-    EnumSelectorData *strdata = (EnumSelectorData*)self->data;
-    int option;
-
-    WMUnmapWidget(strdata->widget);
-
-    option = WMGetPopUpButtonSelectedItem(strdata->widget);
-    WMSetTableViewDataForCell(strdata->table, column, row, (void*)(uintptr_t)option);
-}
-
-
-WMTableColumnDelegate*
-WTCreateEnumSelectorDelegate(WMTableView *parent)
-{
-    WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
-    WMScreen *scr = WMWidgetScreen(parent);
-    EnumSelectorData *data = wmalloc(sizeof(EnumSelectorData));
-
-    data->widget = WMCreatePopUpButton(parent);
-    W_ReparentView(WMWidgetView(data->widget),
-                   WMGetTableViewDocumentView(parent),
-                   0, 0);
-    data->table = parent;
-    data->font = WMSystemFontOfSize(scr, 12);
-    data->gc = WMColorGC(WMWhiteColor(scr));
-    data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
-    data->textColor = WMBlackColor(scr);
-    data->count = 0;
-    data->options = NULL;
-
-    delegate->data = data;
-    delegate->drawCell = ESCellPainter;
-    delegate->drawSelectedCell = selectedESCellPainter;
-    delegate->beginCellEdit = beginESCellEdit;
-    delegate->endCellEdit = endESCellEdit;
-
-    return delegate;
-}
-
-
-void
-WTSetEnumSelectorOptions(WMTableColumnDelegate *delegate, char **options,
-                         int count)
-{
-    EnumSelectorData *data = (EnumSelectorData*)delegate->data;
-    int i;
-
-    for (i = 0;
-         i < WMGetPopUpButtonNumberOfItems(data->widget);
-         i++) {
-        WMRemovePopUpButtonItem(data->widget, 0);
-    }
-
-    data->options = options;
-    data->count = count;
-
-    for (i = 0; i < count; i++) {
-        WMAddPopUpButtonItem(data->widget, options[i]);
-    }
-}
-
-
-
-/* ---------------------------------------------------------------------- */
-
-static void
-BSCellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
-              int row, Drawable d)
-{
-    BooleanSwitchData *strdata = (BooleanSwitchData*)self->data;
-    WMTableView *table = WMGetTableColumnTableView(column);
-    int i = (int)(uintptr_t)WMTableViewDataForCell(table, column, row);
-    WMScreen *scr = WMWidgetScreen(table);
-
-    if (i) {
-        pixmapDraw(scr, d,
-                   strdata->gc, strdata->selGC, WMGetSystemPixmap(scr, WSICheckMark),
-                   WMTableViewRectForCell(table, column, row), False);
-    } else {
-        pixmapDraw(scr, d,
-                   strdata->gc, strdata->selGC, NULL,
-                   WMTableViewRectForCell(table, column, row), False);
-    }
-}
-
-
-static void
-selectedBSCellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
-                      int row, Drawable d)
-{
-    BooleanSwitchData *strdata = (BooleanSwitchData*)self->data;
-    WMTableView *table = WMGetTableColumnTableView(column);
-    int i = (int)(uintptr_t)WMTableViewDataForCell(table, column, row);
-    WMScreen *scr = WMWidgetScreen(table);
-
-    if (i) {
-        pixmapDraw(scr, d,
-                   strdata->gc, strdata->selGC, WMGetSystemPixmap(scr, WSICheckMark),
-                   WMTableViewRectForCell(table, column, row), True);
-    } else {
-        pixmapDraw(scr, d,
-                   strdata->gc, strdata->selGC, NULL,
-                   WMTableViewRectForCell(table, column, row), True);
-    }
-}
-
-
-
-static void
-beginBSCellEdit(WMTableColumnDelegate *self, WMTableColumn *column, int row)
-{
-    BooleanSwitchData *strdata = (BooleanSwitchData*)self->data;
-    WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
-    int data = (int)(uintptr_t)WMTableViewDataForCell(strdata->table, column, row);
-
-    WMSetButtonSelected(strdata->widget, data);
-    WMMoveWidget(strdata->widget, rect.pos.x+1, rect.pos.y+1);
-    WMResizeWidget(strdata->widget, rect.size.width-1, rect.size.height-1);
-
-    WMMapWidget(strdata->widget);
-}
-
-
-static void
-endBSCellEdit(WMTableColumnDelegate *self, WMTableColumn *column, int row)
-{
-    BooleanSwitchData *strdata = (BooleanSwitchData*)self->data;
-    int value;
-
-    value = WMGetButtonSelected(strdata->widget);
-    WMSetTableViewDataForCell(strdata->table, column, row, (void*)(uintptr_t)value);
-    WMUnmapWidget(strdata->widget);
-}
-
-
-WMTableColumnDelegate*
-WTCreateBooleanSwitchDelegate(WMTableView *parent)
-{
-    WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
-    WMScreen *scr = WMWidgetScreen(parent);
-    BooleanSwitchData *data = wmalloc(sizeof(BooleanSwitchData));
-    WMColor *color;
-
-    data->widget = WMCreateSwitchButton(parent);
-    W_ReparentView(WMWidgetView(data->widget),
-                   WMGetTableViewDocumentView(parent),
-                   0, 0);
-    WMSetButtonText(data->widget, NULL);
-    WMSetButtonImagePosition(data->widget, WIPImageOnly);
-    WMSetButtonImage(data->widget, NULL);
-    WMSetButtonAltImage(data->widget, WMGetSystemPixmap(scr, WSICheckMark));
-
-    data->table = parent;
-    color = WMCreateNamedColor(scr, SelectionColor, False);
-    WMSetWidgetBackgroundColor(data->widget, color);
-    data->gc = WMColorGC(WMWhiteColor(scr));
-    data->selGC = WMColorGC(color);
-
-    delegate->data = data;
-    delegate->drawCell = BSCellPainter;
-    delegate->drawSelectedCell = selectedBSCellPainter;
-    delegate->beginCellEdit = beginBSCellEdit;
-    delegate->endCellEdit = endBSCellEdit;
-
-    return delegate;
-}
-
-
-/* ---------------------------------------------------------------------- */
-
-
-static void
-SCellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
-             int row, Drawable d)
-{
-    StringData *strdata = (StringData*)self->data;
-    WMTableView *table = WMGetTableColumnTableView(column);
-
-    stringDraw(WMWidgetScreen(table), d,
-               strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
-               WMTableViewDataForCell(table, column, row),
-               WMTableViewRectForCell(table, column, row),
-               False);
-}
-
-
-static void
-selectedSCellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
-                     int row, Drawable d)
-{
-    StringData *strdata = (StringData*)self->data;
-    WMTableView *table = WMGetTableColumnTableView(column);
-
-    stringDraw(WMWidgetScreen(table), d,
-               strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
-               WMTableViewDataForCell(table, column, row),
-               WMTableViewRectForCell(table, column, row),
-               True);
-}
-
-
-WMTableColumnDelegate*
-WTCreateStringDelegate(WMTableView *parent)
-{
-    WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
-    WMScreen *scr = WMWidgetScreen(parent);
-    StringData *data = wmalloc(sizeof(StringData));
-
-    data->table = parent;
-    data->font = WMSystemFontOfSize(scr, 12);
-    data->gc = WMColorGC(WMWhiteColor(scr));
-    data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
-    data->textColor = WMBlackColor(scr);
-
-    delegate->data = data;
-    delegate->drawCell = SCellPainter;
-    delegate->drawSelectedCell = selectedSCellPainter;
-    delegate->beginCellEdit = NULL;
-    delegate->endCellEdit = NULL;
-
-    return delegate;
-}
-
-
-/* ---------------------------------------------------------------------- */
-
-
-static void
-PCellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
-             int row, Drawable d)
-{
-    StringData *strdata = (StringData*)self->data;
-    WMTableView *table = WMGetTableColumnTableView(column);
-
-    pixmapDraw(WMWidgetScreen(table), d,
-               strdata->gc, strdata->selGC,
-               (WMPixmap*)WMTableViewDataForCell(table, column, row),
-               WMTableViewRectForCell(table, column, row),
-               False);
-}
-
-
-static void
-selectedPCellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
-                     int row, Drawable d)
-{
-    StringData *strdata = (StringData*)self->data;
-    WMTableView *table = WMGetTableColumnTableView(column);
-
-    pixmapDraw(WMWidgetScreen(table), d,
-               strdata->gc, strdata->selGC,
-               (WMPixmap*)WMTableViewDataForCell(table, column, row),
-               WMTableViewRectForCell(table, column, row),
-               True);
-}
-
-
-WMTableColumnDelegate*
-WTCreatePixmapDelegate(WMTableView *table)
-{
-    WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
-    WMScreen *scr = WMWidgetScreen(table);
-    StringData *data = wmalloc(sizeof(StringData));
-
-    data->table = table;
-    data->gc = WMColorGC(WMWhiteColor(scr));
-    data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
-
-    delegate->data = data;
-    delegate->drawCell = PCellPainter;
-    delegate->drawSelectedCell = selectedPCellPainter;
-    delegate->beginCellEdit = NULL;
-    delegate->endCellEdit = NULL;
-
-    return delegate;
-}
-
-
-/* ---------------------------------------------------------------------- */
-
-
-static void
-drawPSCell(WMTableColumnDelegate *self, Drawable d, WMTableColumn *column,
-           int row, Bool selected)
-{
-    StringData *strdata = (StringData*)self->data;
-    WMTableView *table = WMGetTableColumnTableView(column);
-    void **data;
-    WMPixmap *pix;
-    char *str;
-    WMRect rect;
-    WMSize size;
-
-    data = WMTableViewDataForCell(table, column, row);
-
-    str = (char*)data[0];
-    pix = (WMPixmap*)data[1];
-
-    rect = WMTableViewRectForCell(table, column, row);
-
-    if (pix) {
-        int owidth = rect.size.width;
-
-        size = WMGetPixmapSize(pix);
-        rect.size.width = size.width;
-
-        pixmapDraw(WMWidgetScreen(table),
-                   WMViewXID(WMGetTableViewDocumentView(table)),
-                   strdata->gc, strdata->selGC, pix, rect,
-                   selected);
-
-        rect.pos.x += size.width-1;
-        rect.size.width = owidth-size.width+1;
-    }
-
-    stringDraw(WMWidgetScreen(table), d, strdata->gc, strdata->selGC,
-               strdata->textColor, strdata->font, str, rect, selected);
-}
-
-
-static void
-PSCellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
-              int row, Drawable d)
-{
-    drawPSCell(self, d, column, row, False);
-}
-
-
-static void
-selectedPSCellPainter(WMTableColumnDelegate *self, WMTableColumn *column,
-                      int row, Drawable d)
-{
-    drawPSCell(self, d, column, row, True);
-}
-
-
-WMTableColumnDelegate*
-WTCreatePixmapStringDelegate(WMTableView *parent)
-{
-    WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
-    WMScreen *scr = WMWidgetScreen(parent);
-    StringData *data = wmalloc(sizeof(StringData));
-
-    data->table = parent;
-    data->font = WMSystemFontOfSize(scr, 12);
-    data->gc = WMColorGC(WMWhiteColor(scr));
-    data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
-    data->textColor = WMBlackColor(scr);
-
-    delegate->data = data;
-    delegate->drawCell = PSCellPainter;
-    delegate->drawSelectedCell = selectedPSCellPainter;
-    delegate->beginCellEdit = NULL;
-    delegate->endCellEdit = NULL;
-
-    return delegate;
-}
-
-
+
+#include <stdint.h>
+#include <WINGs/WINGsP.h>
+
+#include "wtableview.h"
+
+#include "wtabledelegates.h"
+
+typedef struct {
+       WMTableView *table;
+       WMFont *font;
+       GC gc;
+       GC selGC;
+       WMColor *textColor;
+} StringData;
+
+typedef struct {
+       WMTableView *table;
+       GC selGc;
+} PixmapData;
+
+typedef struct {
+       WMTextField *widget;
+       WMTableView *table;
+       WMFont *font;
+       GC gc;
+       GC selGC;
+       WMColor *textColor;
+} StringEditorData;
+
+typedef struct {
+       WMPopUpButton *widget;
+       WMTableView *table;
+       WMFont *font;
+       char **options;
+       int count;
+       GC gc;
+       GC selGC;
+       WMColor *textColor;
+} EnumSelectorData;
+
+typedef struct {
+       WMButton *widget;
+       WMTableView *table;
+       Bool state;
+       GC gc;
+       GC selGC;
+} BooleanSwitchData;
+
+static char *SelectionColor = "#bbbbcc";
+
+static void
+stringDraw(WMScreen * scr, Drawable d, GC gc, GC sgc, WMColor * textColor,
+          WMFont * font, void *data, WMRect rect, Bool selected)
+{
+       int x, y;
+       XRectangle rects[1];
+       Display *dpy = WMScreenDisplay(scr);
+
+       x = rect.pos.x + 5;
+       y = rect.pos.y + (rect.size.height - WMFontHeight(font)) / 2;
+
+       rects[0].x = rect.pos.x + 1;
+       rects[0].y = rect.pos.y + 1;
+       rects[0].width = rect.size.width - 1;
+       rects[0].height = rect.size.height - 1;
+       XSetClipRectangles(dpy, gc, 0, 0, rects, 1, YXSorted);
+
+       if (!selected) {
+               XFillRectangles(dpy, d, gc, rects, 1);
+
+               WMDrawString(scr, d, textColor, font, x, y, data, strlen(data));
+       } else {
+               XFillRectangles(dpy, d, sgc, rects, 1);
+
+               WMDrawString(scr, d, textColor, font, x, y, data, strlen(data));
+       }
+
+       XSetClipMask(dpy, gc, None);
+}
+
+static void pixmapDraw(WMScreen * scr, Drawable d, GC gc, GC sgc, WMPixmap * pixmap, WMRect rect, Bool selected)
+{
+       int x, y;
+       XRectangle rects[1];
+       Display *dpy = WMScreenDisplay(scr);
+       WMSize size;
+
+       rects[0].x = rect.pos.x + 1;
+       rects[0].y = rect.pos.y + 1;
+       rects[0].width = rect.size.width - 1;
+       rects[0].height = rect.size.height - 1;
+       XSetClipRectangles(dpy, gc, 0, 0, rects, 1, YXSorted);
+
+       if (!selected) {
+               XFillRectangles(dpy, d, gc, rects, 1);
+
+               if (pixmap) {
+                       size = WMGetPixmapSize(pixmap);
+                       x = rect.pos.x + (rect.size.width - size.width) / 2;
+                       y = rect.pos.y + (rect.size.height - size.height) / 2;
+
+                       WMDrawPixmap(pixmap, d, x, y);
+               }
+       } else {
+               XFillRectangles(dpy, d, sgc, rects, 1);
+
+               if (pixmap) {
+                       size = WMGetPixmapSize(pixmap);
+                       x = rect.pos.x + (rect.size.width - size.width) / 2;
+                       y = rect.pos.y + (rect.size.height - size.height) / 2;
+
+                       WMDrawPixmap(pixmap, d, x, y);
+               }
+       }
+
+       XSetClipMask(dpy, gc, None);
+}
+
+/* ---------------------------------------------------------------------- */
+
+static void SECellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
+{
+       StringEditorData *strdata = (StringEditorData *) self->data;
+       WMTableView *table = WMGetTableColumnTableView(column);
+
+       stringDraw(WMWidgetScreen(table), d,
+                  strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
+                  WMTableViewDataForCell(table, column, row), WMTableViewRectForCell(table, column, row), False);
+}
+
+static void selectedSECellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
+{
+       StringEditorData *strdata = (StringEditorData *) self->data;
+       WMTableView *table = WMGetTableColumnTableView(column);
+
+       stringDraw(WMWidgetScreen(table), d,
+                  strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
+                  WMTableViewDataForCell(table, column, row), WMTableViewRectForCell(table, column, row), True);
+}
+
+static void beginSECellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
+{
+       StringEditorData *strdata = (StringEditorData *) self->data;
+       WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
+       void *data = WMTableViewDataForCell(strdata->table, column, row);
+
+       WMSetTextFieldText(strdata->widget, (char *)data);
+       WMMoveWidget(strdata->widget, rect.pos.x, rect.pos.y);
+       WMResizeWidget(strdata->widget, rect.size.width + 1, rect.size.height + 1);
+
+       WMMapWidget(strdata->widget);
+}
+
+static void endSECellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
+{
+       StringEditorData *strdata = (StringEditorData *) self->data;
+       char *text;
+
+       WMUnmapWidget(strdata->widget);
+
+       text = WMGetTextFieldText(strdata->widget);
+       WMSetTableViewDataForCell(strdata->table, column, row, (void *)text);
+}
+
+WMTableColumnDelegate *WTCreateStringEditorDelegate(WMTableView * parent)
+{
+       WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
+       WMScreen *scr = WMWidgetScreen(parent);
+       StringEditorData *data = wmalloc(sizeof(StringEditorData));
+
+       data->widget = WMCreateTextField(parent);
+       W_ReparentView(WMWidgetView(data->widget), WMGetTableViewDocumentView(parent), 0, 0);
+       data->table = parent;
+       data->font = WMSystemFontOfSize(scr, 12);
+       data->gc = WMColorGC(WMWhiteColor(scr));
+       data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
+       data->textColor = WMBlackColor(scr);
+
+       delegate->data = data;
+       delegate->drawCell = SECellPainter;
+       delegate->drawSelectedCell = selectedSECellPainter;
+       delegate->beginCellEdit = beginSECellEdit;
+       delegate->endCellEdit = endSECellEdit;
+
+       return delegate;
+}
+
+/* ---------------------------------------------------------------------- */
+
+static void ESCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
+{
+       EnumSelectorData *strdata = (EnumSelectorData *) self->data;
+       WMTableView *table = WMGetTableColumnTableView(column);
+       int i = (int)(uintptr_t) WMTableViewDataForCell(table, column, row);
+
+       stringDraw(WMWidgetScreen(table), d,
+                  strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
+                  strdata->options[i], WMTableViewRectForCell(table, column, row), False);
+}
+
+static void selectedESCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
+{
+       EnumSelectorData *strdata = (EnumSelectorData *) self->data;
+       WMTableView *table = WMGetTableColumnTableView(column);
+       int i = (int)(uintptr_t) WMTableViewDataForCell(table, column, row);
+
+       stringDraw(WMWidgetScreen(table), d,
+                  strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
+                  strdata->options[i], WMTableViewRectForCell(table, column, row), True);
+}
+
+static void beginESCellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
+{
+       EnumSelectorData *strdata = (EnumSelectorData *) self->data;
+       WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
+       int data = (int)(uintptr_t) WMTableViewDataForCell(strdata->table, column, row);
+
+       wassertr(data < strdata->count);
+
+       WMSetPopUpButtonSelectedItem(strdata->widget, data);
+
+       WMMoveWidget(strdata->widget, rect.pos.x, rect.pos.y);
+       WMResizeWidget(strdata->widget, rect.size.width, rect.size.height + 1);
+
+       WMMapWidget(strdata->widget);
+}
+
+static void endESCellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
+{
+       EnumSelectorData *strdata = (EnumSelectorData *) self->data;
+       int option;
+
+       WMUnmapWidget(strdata->widget);
+
+       option = WMGetPopUpButtonSelectedItem(strdata->widget);
+       WMSetTableViewDataForCell(strdata->table, column, row, (void *)(uintptr_t) option);
+}
+
+WMTableColumnDelegate *WTCreateEnumSelectorDelegate(WMTableView * parent)
+{
+       WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
+       WMScreen *scr = WMWidgetScreen(parent);
+       EnumSelectorData *data = wmalloc(sizeof(EnumSelectorData));
+
+       data->widget = WMCreatePopUpButton(parent);
+       W_ReparentView(WMWidgetView(data->widget), WMGetTableViewDocumentView(parent), 0, 0);
+       data->table = parent;
+       data->font = WMSystemFontOfSize(scr, 12);
+       data->gc = WMColorGC(WMWhiteColor(scr));
+       data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
+       data->textColor = WMBlackColor(scr);
+       data->count = 0;
+       data->options = NULL;
+
+       delegate->data = data;
+       delegate->drawCell = ESCellPainter;
+       delegate->drawSelectedCell = selectedESCellPainter;
+       delegate->beginCellEdit = beginESCellEdit;
+       delegate->endCellEdit = endESCellEdit;
+
+       return delegate;
+}
+
+void WTSetEnumSelectorOptions(WMTableColumnDelegate * delegate, char **options, int count)
+{
+       EnumSelectorData *data = (EnumSelectorData *) delegate->data;
+       int i;
+
+       for (i = 0; i < WMGetPopUpButtonNumberOfItems(data->widget); i++) {
+               WMRemovePopUpButtonItem(data->widget, 0);
+       }
+
+       data->options = options;
+       data->count = count;
+
+       for (i = 0; i < count; i++) {
+               WMAddPopUpButtonItem(data->widget, options[i]);
+       }
+}
+
+/* ---------------------------------------------------------------------- */
+
+static void BSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
+{
+       BooleanSwitchData *strdata = (BooleanSwitchData *) self->data;
+       WMTableView *table = WMGetTableColumnTableView(column);
+       int i = (int)(uintptr_t) WMTableViewDataForCell(table, column, row);
+       WMScreen *scr = WMWidgetScreen(table);
+
+       if (i) {
+               pixmapDraw(scr, d,
+                          strdata->gc, strdata->selGC, WMGetSystemPixmap(scr, WSICheckMark),
+                          WMTableViewRectForCell(table, column, row), False);
+       } else {
+               pixmapDraw(scr, d,
+                          strdata->gc, strdata->selGC, NULL, WMTableViewRectForCell(table, column, row), False);
+       }
+}
+
+static void selectedBSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
+{
+       BooleanSwitchData *strdata = (BooleanSwitchData *) self->data;
+       WMTableView *table = WMGetTableColumnTableView(column);
+       int i = (int)(uintptr_t) WMTableViewDataForCell(table, column, row);
+       WMScreen *scr = WMWidgetScreen(table);
+
+       if (i) {
+               pixmapDraw(scr, d,
+                          strdata->gc, strdata->selGC, WMGetSystemPixmap(scr, WSICheckMark),
+                          WMTableViewRectForCell(table, column, row), True);
+       } else {
+               pixmapDraw(scr, d,
+                          strdata->gc, strdata->selGC, NULL, WMTableViewRectForCell(table, column, row), True);
+       }
+}
+
+static void beginBSCellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
+{
+       BooleanSwitchData *strdata = (BooleanSwitchData *) self->data;
+       WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
+       int data = (int)(uintptr_t) WMTableViewDataForCell(strdata->table, column, row);
+
+       WMSetButtonSelected(strdata->widget, data);
+       WMMoveWidget(strdata->widget, rect.pos.x + 1, rect.pos.y + 1);
+       WMResizeWidget(strdata->widget, rect.size.width - 1, rect.size.height - 1);
+
+       WMMapWidget(strdata->widget);
+}
+
+static void endBSCellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
+{
+       BooleanSwitchData *strdata = (BooleanSwitchData *) self->data;
+       int value;
+
+       value = WMGetButtonSelected(strdata->widget);
+       WMSetTableViewDataForCell(strdata->table, column, row, (void *)(uintptr_t) value);
+       WMUnmapWidget(strdata->widget);
+}
+
+WMTableColumnDelegate *WTCreateBooleanSwitchDelegate(WMTableView * parent)
+{
+       WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
+       WMScreen *scr = WMWidgetScreen(parent);
+       BooleanSwitchData *data = wmalloc(sizeof(BooleanSwitchData));
+       WMColor *color;
+
+       data->widget = WMCreateSwitchButton(parent);
+       W_ReparentView(WMWidgetView(data->widget), WMGetTableViewDocumentView(parent), 0, 0);
+       WMSetButtonText(data->widget, NULL);
+       WMSetButtonImagePosition(data->widget, WIPImageOnly);
+       WMSetButtonImage(data->widget, NULL);
+       WMSetButtonAltImage(data->widget, WMGetSystemPixmap(scr, WSICheckMark));
+
+       data->table = parent;
+       color = WMCreateNamedColor(scr, SelectionColor, False);
+       WMSetWidgetBackgroundColor(data->widget, color);
+       data->gc = WMColorGC(WMWhiteColor(scr));
+       data->selGC = WMColorGC(color);
+
+       delegate->data = data;
+       delegate->drawCell = BSCellPainter;
+       delegate->drawSelectedCell = selectedBSCellPainter;
+       delegate->beginCellEdit = beginBSCellEdit;
+       delegate->endCellEdit = endBSCellEdit;
+
+       return delegate;
+}
+
+/* ---------------------------------------------------------------------- */
+
+static void SCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
+{
+       StringData *strdata = (StringData *) self->data;
+       WMTableView *table = WMGetTableColumnTableView(column);
+
+       stringDraw(WMWidgetScreen(table), d,
+                  strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
+                  WMTableViewDataForCell(table, column, row), WMTableViewRectForCell(table, column, row), False);
+}
+
+static void selectedSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
+{
+       StringData *strdata = (StringData *) self->data;
+       WMTableView *table = WMGetTableColumnTableView(column);
+
+       stringDraw(WMWidgetScreen(table), d,
+                  strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
+                  WMTableViewDataForCell(table, column, row), WMTableViewRectForCell(table, column, row), True);
+}
+
+WMTableColumnDelegate *WTCreateStringDelegate(WMTableView * parent)
+{
+       WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
+       WMScreen *scr = WMWidgetScreen(parent);
+       StringData *data = wmalloc(sizeof(StringData));
+
+       data->table = parent;
+       data->font = WMSystemFontOfSize(scr, 12);
+       data->gc = WMColorGC(WMWhiteColor(scr));
+       data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
+       data->textColor = WMBlackColor(scr);
+
+       delegate->data = data;
+       delegate->drawCell = SCellPainter;
+       delegate->drawSelectedCell = selectedSCellPainter;
+       delegate->beginCellEdit = NULL;
+       delegate->endCellEdit = NULL;
+
+       return delegate;
+}
+
+/* ---------------------------------------------------------------------- */
+
+static void PCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
+{
+       StringData *strdata = (StringData *) self->data;
+       WMTableView *table = WMGetTableColumnTableView(column);
+
+       pixmapDraw(WMWidgetScreen(table), d,
+                  strdata->gc, strdata->selGC,
+                  (WMPixmap *) WMTableViewDataForCell(table, column, row),
+                  WMTableViewRectForCell(table, column, row), False);
+}
+
+static void selectedPCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
+{
+       StringData *strdata = (StringData *) self->data;
+       WMTableView *table = WMGetTableColumnTableView(column);
+
+       pixmapDraw(WMWidgetScreen(table), d,
+                  strdata->gc, strdata->selGC,
+                  (WMPixmap *) WMTableViewDataForCell(table, column, row),
+                  WMTableViewRectForCell(table, column, row), True);
+}
+
+WMTableColumnDelegate *WTCreatePixmapDelegate(WMTableView * table)
+{
+       WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
+       WMScreen *scr = WMWidgetScreen(table);
+       StringData *data = wmalloc(sizeof(StringData));
+
+       data->table = table;
+       data->gc = WMColorGC(WMWhiteColor(scr));
+       data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
+
+       delegate->data = data;
+       delegate->drawCell = PCellPainter;
+       delegate->drawSelectedCell = selectedPCellPainter;
+       delegate->beginCellEdit = NULL;
+       delegate->endCellEdit = NULL;
+
+       return delegate;
+}
+
+/* ---------------------------------------------------------------------- */
+
+static void drawPSCell(WMTableColumnDelegate * self, Drawable d, WMTableColumn * column, int row, Bool selected)
+{
+       StringData *strdata = (StringData *) self->data;
+       WMTableView *table = WMGetTableColumnTableView(column);
+       void **data;
+       WMPixmap *pix;
+       char *str;
+       WMRect rect;
+       WMSize size;
+
+       data = WMTableViewDataForCell(table, column, row);
+
+       str = (char *)data[0];
+       pix = (WMPixmap *) data[1];
+
+       rect = WMTableViewRectForCell(table, column, row);
+
+       if (pix) {
+               int owidth = rect.size.width;
+
+               size = WMGetPixmapSize(pix);
+               rect.size.width = size.width;
+
+               pixmapDraw(WMWidgetScreen(table),
+                          WMViewXID(WMGetTableViewDocumentView(table)),
+                          strdata->gc, strdata->selGC, pix, rect, selected);
+
+               rect.pos.x += size.width - 1;
+               rect.size.width = owidth - size.width + 1;
+       }
+
+       stringDraw(WMWidgetScreen(table), d, strdata->gc, strdata->selGC,
+                  strdata->textColor, strdata->font, str, rect, selected);
+}
+
+static void PSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
+{
+       drawPSCell(self, d, column, row, False);
+}
+
+static void selectedPSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
+{
+       drawPSCell(self, d, column, row, True);
+}
+
+WMTableColumnDelegate *WTCreatePixmapStringDelegate(WMTableView * parent)
+{
+       WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
+       WMScreen *scr = WMWidgetScreen(parent);
+       StringData *data = wmalloc(sizeof(StringData));
+
+       data->table = parent;
+       data->font = WMSystemFontOfSize(scr, 12);
+       data->gc = WMColorGC(WMWhiteColor(scr));
+       data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
+       data->textColor = WMBlackColor(scr);
+
+       delegate->data = data;
+       delegate->drawCell = PSCellPainter;
+       delegate->drawSelectedCell = selectedPSCellPainter;
+       delegate->beginCellEdit = NULL;
+       delegate->endCellEdit = NULL;
+
+       return delegate;
+}
dissimilarity index 96%
index dd193a9..3241be8 100644 (file)
-
-
-#include <WINGs/WINGsP.h>
-#include <X11/cursorfont.h>
-#include <stdint.h>
-
-#include "wtableview.h"
-
-
-const char *WMTableViewSelectionDidChangeNotification = "WMTableViewSelectionDidChangeNotification";
-
-
-struct W_TableColumn {
-    WMTableView *table;
-    WMWidget *titleW;
-    char *title;
-    int width;
-    int minWidth;
-    int maxWidth;
-
-    void *id;
-
-    WMTableColumnDelegate *delegate;
-
-    unsigned resizable:1;
-    unsigned editable:1;
-};
-
-
-static void handleResize(W_ViewDelegate *self, WMView *view);
-
-static void rearrangeHeader(WMTableView *table);
-
-static WMRange rowsInRect(WMTableView *table, WMRect rect);
-
-
-WMTableColumn*
-WMCreateTableColumn(char *title)
-{
-    WMTableColumn *col = wmalloc(sizeof(WMTableColumn));
-
-    col->table = NULL;
-    col->titleW = NULL;
-    col->width = 50;
-    col->minWidth = 5;
-    col->maxWidth = 0;
-
-    col->id = NULL;
-
-    col->title = wstrdup(title);
-
-    col->delegate = NULL;
-
-    col->resizable = 1;
-    col->editable = 0;
-
-    return col;
-}
-
-
-void
-WMSetTableColumnId(WMTableColumn *column, void *id)
-{
-    column->id = id;
-}
-
-
-void*
-WMGetTableColumnId(WMTableColumn *column)
-{
-    return column->id;
-}
-
-
-void
-WMSetTableColumnWidth(WMTableColumn *column, unsigned width)
-{
-    if (column->maxWidth == 0)
-        column->width = WMAX(column->minWidth, width);
-    else
-        column->width = WMAX(column->minWidth, WMIN(column->maxWidth, width));
-
-    if (column->table) {
-        rearrangeHeader(column->table);
-    }
-}
-
-
-void
-WMSetTableColumnDelegate(WMTableColumn *column, WMTableColumnDelegate *delegate)
-{
-    column->delegate = delegate;
-}
-
-
-void
-WMSetTableColumnConstraints(WMTableColumn *column, unsigned minWidth,
-                            unsigned maxWidth)
-{
-    wassertr(maxWidth == 0 || minWidth <= maxWidth);
-
-    column->minWidth = minWidth;
-    column->maxWidth = maxWidth;
-
-    if (column->width < column->minWidth)
-        WMSetTableColumnWidth(column, column->minWidth);
-    else if (column->width > column->maxWidth && column->maxWidth != 0)
-        WMSetTableColumnWidth(column, column->maxWidth);
-}
-
-
-void
-WMSetTableColumnEditable(WMTableColumn *column, Bool flag)
-{
-    column->editable = ((flag==0) ? 0 : 1);
-}
-
-
-WMTableView*
-WMGetTableColumnTableView(WMTableColumn *column)
-{
-    return column->table;
-}
-
-
-
-struct W_TableView {
-    W_Class widgetClass;
-    WMView *view;
-
-    WMFrame *header;
-
-    WMLabel *corner;
-
-    WMScroller *hscroll;
-    WMScroller *vscroll;
-    WMView *tableView;
-
-    WMPixmap *viewBuffer;
-
-    WMArray *columns;
-    WMArray *splitters;
-
-    WMArray *selectedRows;
-
-    int tableWidth;
-
-    int rows;
-
-    WMColor *backColor;
-
-    GC gridGC;
-    WMColor *gridColor;
-
-    Cursor splitterCursor;
-
-    void *dataSource;
-
-    WMTableViewDelegate *delegate;
-
-    WMAction *action;
-    void *clientData;
-
-    void *clickedColumn;
-    int clickedRow;
-
-    int editingRow;
-
-    unsigned headerHeight;
-
-    unsigned rowHeight;
-
-    unsigned dragging:1;
-    unsigned drawsGrid:1;
-    unsigned canSelectRow:1;
-    unsigned canSelectMultiRows:1;
-    unsigned canDeselectRow:1;
-
-    unsigned int hasVScroller:1;
-    unsigned int hasHScroller:1;
-};
-
-static W_Class tableClass = 0;
-
-
-static W_ViewDelegate viewDelegate = {
-    NULL,
-    NULL,
-    handleResize,
-    NULL,
-    NULL
-};
-
-
-
-static void reorganizeInterior(WMTableView *table);
-
-
-static void handleEvents(XEvent *event, void *data);
-static void handleTableEvents(XEvent *event, void *data);
-static void repaintTable(WMTableView *table);
-
-static WMSize
-getTotalSize(WMTableView *table)
-{
-    WMSize size;
-    int i;
-
-    /* get width from columns */
-    size.width = 0;
-    for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
-        WMTableColumn *column;
-
-        column = WMGetFromArray(table->columns, i);
-
-        size.width += column->width;
-    }
-
-    /* get height from rows */
-    size.height = table->rows * table->rowHeight;
-
-    return size;
-}
-
-
-static WMRect
-getVisibleRect(WMTableView *table)
-{
-    WMSize size = getTotalSize(table);
-    WMRect rect;
-
-    if (table->vscroll) {
-        rect.size.height = size.height * WMGetScrollerKnobProportion(table->vscroll);
-        rect.pos.y = (size.height - rect.size.height) * WMGetScrollerValue(table->vscroll);
-    } else {
-        rect.size.height = size.height;
-        rect.pos.y = 0;
-    }
-
-    if (table->hscroll) {
-        rect.size.width = size.width * WMGetScrollerKnobProportion(table->hscroll);
-        rect.pos.x = (size.width - rect.size.width) * WMGetScrollerValue(table->hscroll);
-    } else {
-        rect.size.width = size.width;
-        rect.pos.x = 0;
-    }
-
-    return rect;
-}
-
-
-static void
-scrollToPoint(WMTableView *table, int x, int y)
-{
-    WMSize size = getTotalSize(table);
-    int i;
-    float value, prop;
-
-    if (table->hscroll) {
-        if (size.width > W_VIEW_WIDTH(table->tableView)) {
-            prop = (float)W_VIEW_WIDTH(table->tableView) / (float)size.width;
-            value = (float)x / (float)(size.width - W_VIEW_WIDTH(table->tableView));
-        } else {
-            prop = 1.0;
-            value = 0.0;
-        }
-        WMSetScrollerParameters(table->hscroll, value, prop);
-    }
-
-    if (table->vscroll) {
-        if (size.height > W_VIEW_HEIGHT(table->tableView)) {
-            prop = (float)W_VIEW_HEIGHT(table->tableView) / (float)size.height;
-            value = (float)y / (float)(size.height - W_VIEW_HEIGHT(table->tableView));
-        } else {
-            prop = 1.0;
-            value = 0.0;
-        }
-
-        WMSetScrollerParameters(table->vscroll, value, prop);
-    }
-
-
-    if (table->editingRow >= 0) {
-        for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
-            WMTableColumn *column;
-
-            column = WMGetFromArray(table->columns, i);
-
-            if (column->delegate && column->delegate->beginCellEdit)
-                (*column->delegate->beginCellEdit)(column->delegate, column,
-                                                   table->editingRow);
-        }
-    }
-
-    repaintTable(table);
-}
-
-
-static void
-adjustScrollers(WMTableView *table)
-{
-    WMSize size = getTotalSize(table);
-    WMSize vsize = WMGetViewSize(table->tableView);
-    float prop, value;
-    float oprop, ovalue;
-
-    if (table->hscroll) {
-        if (size.width <= vsize.width) {
-            value = 0.0;
-            prop = 1.0;
-        } else {
-            oprop = WMGetScrollerKnobProportion(table->hscroll);
-            if (oprop == 0.0)
-                oprop = 1.0;
-            ovalue = WMGetScrollerValue(table->hscroll);
-
-            prop = (float)vsize.width/(float)size.width;
-            value = prop*ovalue / oprop;
-        }
-        WMSetScrollerParameters(table->hscroll, value, prop);
-    }
-
-    if (table->vscroll) {
-        if (size.height <= vsize.height) {
-            value = 0.0;
-            prop = 1.0;
-        } else {
-            oprop = WMGetScrollerKnobProportion(table->vscroll);
-            if (oprop == 0.0)
-                oprop = 1.0;
-            ovalue = WMGetScrollerValue(table->vscroll);
-
-            prop = (float)vsize.height/(float)size.height;
-            value = prop*ovalue / oprop;
-        }
-        WMSetScrollerParameters(table->vscroll, value, prop);
-    }
-}
-
-
-static void
-doScroll(WMWidget *self, void *data)
-{
-    WMTableView *table = (WMTableView*)data;
-    float value;
-    float vpsize;
-    float size;
-    WMSize ts = getTotalSize(table);
-
-    value = WMGetScrollerValue(self);
-
-    if (table->hscroll == (WMScroller *)self) {
-        vpsize = W_VIEW_WIDTH(table->tableView);
-        size = ts.width;
-    } else {
-        vpsize = W_VIEW_HEIGHT(table->tableView);
-        size = ts.height;
-    }
-
-    switch (WMGetScrollerHitPart(self)) {
-    case WSDecrementWheel:
-    case WSDecrementLine:
-        value -= (float)table->rowHeight / size;
-        if (value < 0)
-            value = 0.0;
-        WMSetScrollerParameters(self, value,
-                                WMGetScrollerKnobProportion(self));
-        repaintTable(table);
-        break;
-
-    case WSIncrementWheel:
-    case WSIncrementLine:
-        value += (float)table->rowHeight / size;
-        if (value > 1.0)
-            value = 1.0;
-        WMSetScrollerParameters(self, value,
-                                WMGetScrollerKnobProportion(self));
-        repaintTable(table);
-        break;
-
-    case WSKnob:
-        repaintTable(table);
-        break;
-
-    case WSDecrementPage:
-        value -= vpsize / size;
-        if (value < 0.0)
-            value = 0.0;
-        WMSetScrollerParameters(self, value,
-                                WMGetScrollerKnobProportion(self));
-        repaintTable(table);
-        break;
-
-    case WSIncrementPage:
-        value += vpsize / size;
-        if (value > 1.0)
-            value = 1.0;
-        WMSetScrollerParameters(self, value,
-                                WMGetScrollerKnobProportion(self));
-        repaintTable(table);
-        break;
-
-
-    case WSNoPart:
-    case WSKnobSlot:
-        break;
-    }
-
-    if (table->editingRow >= 0) {
-        int i;
-        for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
-            WMTableColumn *column;
-
-            column = WMGetFromArray(table->columns, i);
-
-            if (column->delegate && column->delegate->beginCellEdit)
-                (*column->delegate->beginCellEdit)(column->delegate, column,
-                                                   table->editingRow);
-        }
-    }
-
-
-    if (table->hscroll == self) {
-        int x = 0;
-        int i;
-        WMRect rect = getVisibleRect(table);
-
-        for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
-            WMTableColumn *column;
-            WMView *splitter;
-
-            column = WMGetFromArray(table->columns, i);
-
-            WMMoveWidget(column->titleW, x - rect.pos.x, 0);
-
-            x += W_VIEW_WIDTH(WMWidgetView(column->titleW)) + 1;
-
-            splitter = WMGetFromArray(table->splitters, i);
-            W_MoveView(splitter, x - rect.pos.x - 1, 0);
-        }
-    }
-}
-
-
-static void
-splitterHandler(XEvent *event, void *data)
-{
-    WMTableColumn *column = (WMTableColumn*)data;
-    WMTableView *table = column->table;
-    int done = 0;
-    int cx, ox, offsX;
-    WMPoint pos;
-    WMScreen *scr = WMWidgetScreen(table);
-    GC gc = scr->ixorGC;
-    Display *dpy = WMScreenDisplay(scr);
-    int h = WMWidgetHeight(table) - 22;
-    Window w = WMViewXID(table->view);
-
-    pos = WMGetViewPosition(WMWidgetView(column->titleW));
-
-    offsX = pos.x + column->width;
-
-    ox = cx = offsX;
-
-    XDrawLine(dpy, w, gc, cx+20, 0, cx+20, h);
-
-    while (!done) {
-        XEvent ev;
-
-        WMMaskEvent(dpy, ButtonMotionMask|ButtonReleaseMask, &ev);
-
-        switch (ev.type) {
-        case MotionNotify:
-            ox = cx;
-
-            if (column->width + ev.xmotion.x < column->minWidth)
-                cx = pos.x + column->minWidth;
-            else if (column->maxWidth > 0
-                     && column->width + ev.xmotion.x > column->maxWidth)
-                cx = pos.x + column->maxWidth;
-            else
-                cx = offsX + ev.xmotion.x;
-
-            XDrawLine(dpy, w, gc, ox+20, 0, ox+20, h);
-            XDrawLine(dpy, w, gc, cx+20, 0, cx+20, h);
-            break;
-
-        case ButtonRelease:
-            column->width = cx - pos.x;
-            done = 1;
-            break;
-        }
-    }
-
-    XDrawLine(dpy, w, gc, cx+20, 0, cx+20, h);
-    rearrangeHeader(table);
-    repaintTable(table);
-}
-
-
-static void
-realizeTable(void *data, WMNotification *notif)
-{
-    repaintTable(data);
-}
-
-
-WMTableView*
-WMCreateTableView(WMWidget *parent)
-{
-    WMTableView *table = wmalloc(sizeof(WMTableView));
-    WMScreen *scr = WMWidgetScreen(parent);
-
-    memset(table, 0, sizeof(WMTableView));
-
-    if (!tableClass) {
-        tableClass = W_RegisterUserWidget();
-    }
-    table->widgetClass = tableClass;
-
-    table->view = W_CreateView(W_VIEW(parent));
-    if (!table->view)
-        goto error;
-    table->view->self = table;
-
-    table->view->delegate = &viewDelegate;
-
-    table->headerHeight = 20;
-
-    table->hscroll = WMCreateScroller(table);
-    WMSetScrollerAction(table->hscroll, doScroll, table);
-    WMMoveWidget(table->hscroll, 1, 2+table->headerHeight);
-    WMMapWidget(table->hscroll);
-
-    table->hasHScroller = 1;
-
-    table->vscroll = WMCreateScroller(table);
-    WMSetScrollerArrowsPosition(table->vscroll, WSAMaxEnd);
-    WMSetScrollerAction(table->vscroll, doScroll, table);
-    WMMoveWidget(table->vscroll, 1, 2+table->headerHeight);
-    WMMapWidget(table->vscroll);
-
-    table->hasVScroller = 1;
-
-    table->header = WMCreateFrame(table);
-    WMMoveWidget(table->header, 22, 2);
-    WMMapWidget(table->header);
-    WMSetFrameRelief(table->header, WRFlat);
-
-    table->corner = WMCreateLabel(table);
-    WMResizeWidget(table->corner, 20, table->headerHeight);
-    WMMoveWidget(table->corner, 2, 2);
-    WMMapWidget(table->corner);
-    WMSetLabelRelief(table->corner, WRRaised);
-    WMSetWidgetBackgroundColor(table->corner, scr->darkGray);
-
-
-    table->tableView = W_CreateView(table->view);
-    if (!table->tableView)
-        goto error;
-    table->tableView->self = table;
-    W_MapView(table->tableView);
-
-    WMAddNotificationObserver(realizeTable, table, WMViewRealizedNotification,
-                              table->tableView);
-
-    table->tableView->flags.dontCompressExpose = 1;
-
-    table->gridColor = WMCreateNamedColor(scr, "#cccccc", False);
-    /*   table->gridColor = WMGrayColor(scr);*/
-
-    {
-        XGCValues gcv;
-
-        table->backColor = WMWhiteColor(scr);
-
-        gcv.foreground = WMColorPixel(table->gridColor);
-        gcv.dashes = 1;
-        gcv.line_style = LineOnOffDash;
-        table->gridGC = XCreateGC(WMScreenDisplay(scr), W_DRAWABLE(scr),
-                                  GCForeground, &gcv);
-    }
-
-    table->editingRow = -1;
-    table->clickedRow = -1;
-
-    table->drawsGrid = 1;
-    table->rowHeight = 16;
-
-    table->tableWidth = 1;
-
-    table->columns = WMCreateArray(4);
-    table->splitters = WMCreateArray(4);
-
-    table->selectedRows = WMCreateArray(16);
-
-    table->splitterCursor = XCreateFontCursor(WMScreenDisplay(scr),
-                                              XC_sb_h_double_arrow);
-
-    table->canSelectRow = 1;
-
-    WMCreateEventHandler(table->view, ExposureMask|StructureNotifyMask,
-                         handleEvents, table);
-
-    WMCreateEventHandler(table->tableView, ExposureMask|ButtonPressMask|
-                         ButtonReleaseMask|ButtonMotionMask,
-                         handleTableEvents, table);
-
-    WMResizeWidget(table, 50, 50);
-
-    return table;
-
-    error:
-        if (table->tableView)
-            W_DestroyView(table->tableView);
-        if (table->view)
-            W_DestroyView(table->view);
-        wfree(table);
-        return NULL;
-}
-
-
-void
-WMAddTableViewColumn(WMTableView *table, WMTableColumn *column)
-{
-    WMScreen *scr = WMWidgetScreen(table);
-
-    column->table = table;
-
-    WMAddToArray(table->columns, column);
-
-    if (!column->titleW) {
-        column->titleW = WMCreateLabel(table);
-        WMSetLabelRelief(column->titleW, WRRaised);
-        WMSetLabelFont(column->titleW, scr->boldFont);
-        WMSetLabelTextColor(column->titleW, scr->white);
-        WMSetWidgetBackgroundColor(column->titleW, scr->darkGray);
-        WMSetLabelText(column->titleW, column->title);
-        W_ReparentView(WMWidgetView(column->titleW),
-                       WMWidgetView(table->header), 0, 0);
-        if (W_VIEW_REALIZED(table->view))
-            WMRealizeWidget(column->titleW);
-        WMMapWidget(column->titleW);
-    }
-
-    {
-        WMView *splitter = W_CreateView(WMWidgetView(table->header));
-
-        W_SetViewBackgroundColor(splitter, WMWhiteColor(scr));
-
-        if (W_VIEW_REALIZED(table->view))
-            W_RealizeView(splitter);
-
-        W_ResizeView(splitter, 2, table->headerHeight);
-        W_MapView(splitter);
-
-        W_SetViewCursor(splitter, table->splitterCursor);
-        WMCreateEventHandler(splitter, ButtonPressMask|ButtonReleaseMask,
-                             splitterHandler, column);
-
-        WMAddToArray(table->splitters, splitter);
-    }
-
-    rearrangeHeader(table);
-}
-
-
-void
-WMSetTableViewHeaderHeight(WMTableView *table, unsigned height)
-{
-    table->headerHeight = height;
-
-    handleResize(NULL, table->view);
-}
-
-
-void
-WMSetTableViewDelegate(WMTableView *table, WMTableViewDelegate *delegate)
-{
-    table->delegate = delegate;
-}
-
-
-void
-WMSetTableViewAction(WMTableView *table, WMAction *action, void *clientData)
-{
-    table->action = action;
-
-    table->clientData = clientData;
-}
-
-
-void*
-WMGetTableViewClickedColumn(WMTableView *table)
-{
-    return table->clickedColumn;
-}
-
-
-int
-WMGetTableViewClickedRow(WMTableView *table)
-{
-    return table->clickedRow;
-}
-
-
-WMArray*
-WMGetTableViewSelectedRows(WMTableView *table)
-{
-    return table->selectedRows;
-}
-
-
-WMView*
-WMGetTableViewDocumentView(WMTableView *table)
-{
-    return table->tableView;
-}
-
-
-void*
-WMTableViewDataForCell(WMTableView *table, WMTableColumn *column, int row)
-{
-    return (*table->delegate->valueForCell)(table->delegate, column, row);
-}
-
-
-void
-WMSetTableViewDataForCell(WMTableView *table, WMTableColumn *column, int row,
-                          void *data)
-{
-    (*table->delegate->setValueForCell)(table->delegate, column, row, data);
-}
-
-
-WMRect
-WMTableViewRectForCell(WMTableView *table, WMTableColumn *column, int row)
-{
-    WMRect rect;
-    int i;
-
-    rect.pos.x = 0;
-    rect.pos.y = row * table->rowHeight;
-    rect.size.height = table->rowHeight;
-
-    for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
-        WMTableColumn *col;
-        col = WMGetFromArray(table->columns, i);
-
-        if (col == column) {
-            rect.size.width = col->width;
-            break;
-        }
-
-        rect.pos.x += col->width;
-    }
-
-    {
-        WMRect r = getVisibleRect(table);
-
-        rect.pos.y -= r.pos.y;
-        rect.pos.x -= r.pos.x;
-    }
-
-    return rect;
-}
-
-
-void
-WMSetTableViewDataSource(WMTableView *table, void *source)
-{
-    table->dataSource = source;
-}
-
-
-void*
-WMGetTableViewDataSource(WMTableView *table)
-{
-    return table->dataSource;
-}
-
-
-
-void
-WMSetTableViewHasHorizontalScroller(WMTableView *tPtr, Bool flag)
-{
-    if (flag) {
-        if (tPtr->hasHScroller)
-            return;
-        tPtr->hasHScroller = 1;
-
-        tPtr->hscroll = WMCreateScroller(tPtr);
-        WMSetScrollerAction(tPtr->hscroll, doScroll, tPtr);
-        WMSetScrollerArrowsPosition(tPtr->hscroll, WSAMaxEnd);
-        /* make it a horiz. scroller */
-        WMResizeWidget(tPtr->hscroll, 1, 2);
-
-        if (W_VIEW_REALIZED(tPtr->view)) {
-            WMRealizeWidget(tPtr->hscroll);
-        }
-
-        reorganizeInterior(tPtr);
-
-        WMMapWidget(tPtr->hscroll);
-    } else {
-        if (!tPtr->hasHScroller)
-            return;
-        tPtr->hasHScroller = 0;
-
-        WMUnmapWidget(tPtr->hscroll);
-        WMDestroyWidget(tPtr->hscroll);
-        tPtr->hscroll = NULL;
-
-        reorganizeInterior(tPtr);
-    }
-}
-
-#if 0
-/* not supported by now */
-void
-WMSetTableViewHasVerticalScroller(WMTableView *tPtr, Bool flag)
-{
-    if (flag) {
-        if (tPtr->hasVScroller)
-            return;
-        tPtr->hasVScroller = 1;
-
-        tPtr->vscroll = WMCreateScroller(tPtr);
-        WMSetScrollerAction(tPtr->vscroll, doScroll, tPtr);
-        WMSetScrollerArrowsPosition(tPtr->vscroll, WSAMaxEnd);
-        /* make it a vert. scroller */
-        WMResizeWidget(tPtr->vscroll, 1, 2);
-
-        if (W_VIEW_REALIZED(tPtr->view)) {
-            WMRealizeWidget(tPtr->vscroll);
-        }
-
-        reorganizeInterior(tPtr);
-
-        WMMapWidget(tPtr->vscroll);
-    } else {
-        if (!tPtr->hasVScroller)
-            return;
-        tPtr->hasVScroller = 0;
-
-        WMUnmapWidget(tPtr->vscroll);
-        WMDestroyWidget(tPtr->vscroll);
-        tPtr->vscroll = NULL;
-
-        reorganizeInterior(tPtr);
-    }
-}
-#endif
-
-void
-WMSetTableViewBackgroundColor(WMTableView *table, WMColor *color)
-{
-    W_SetViewBackgroundColor(table->tableView, color);
-
-    if (table->backColor)
-        WMReleaseColor(table->backColor);
-
-    table->backColor = WMRetainColor(color);
-
-    repaintTable(table);
-}
-
-
-void
-WMSetTableViewGridColor(WMTableView *table, WMColor *color)
-{
-    WMReleaseColor(table->gridColor);
-    table->gridColor = WMRetainColor(color);
-    XSetForeground(WMScreenDisplay(WMWidgetScreen(table)), table->gridGC,
-                   WMColorPixel(color));
-    repaintTable(table);
-}
-
-
-
-void
-WMSetTableViewRowHeight(WMTableView *table, int height)
-{
-    table->rowHeight = height;
-
-    repaintTable(table);
-}
-
-
-void
-WMScrollTableViewRowToVisible(WMTableView *table, int row)
-{
-    WMScroller *scroller;
-    WMRange range;
-    WMRect rect;
-    int newY, tmp;
-
-    rect = getVisibleRect(table);
-    range = rowsInRect(table, rect);
-
-    scroller = table->vscroll;
-
-    if (row < range.position) {
-        newY = row * table->rowHeight - rect.size.height / 2;
-    } else if (row >= range.position + range.count) {
-        newY = row * table->rowHeight - rect.size.height / 2;
-    } else {
-        return;
-    }
-    tmp = table->rows*table->rowHeight - rect.size.height;
-    newY = WMAX(0, WMIN(newY, tmp));
-
-    scrollToPoint(table, rect.pos.x, newY);
-}
-
-
-
-static void
-drawGrid(WMTableView *table, WMRect rect)
-{
-    WMScreen *scr = WMWidgetScreen(table);
-    Display *dpy = WMScreenDisplay(scr);
-    int i;
-    int y1, y2;
-    int x1, x2;
-    int xx;
-    Drawable d = WMGetPixmapXID(table->viewBuffer);
-    GC gc = table->gridGC;
-
-#if 0
-    char dashl[1] = {1};
-
-    XSetDashes(dpy, gc, 0, dashl, 1);
-
-    y1 = (rect.pos.y/table->rowHeight - 1)*table->rowHeight;
-    y2 = y1 + (rect.size.height/table->rowHeight+2)*table->rowHeight;
-#endif
-    y1 = 0;
-    y2 = W_VIEW_HEIGHT(table->tableView);
-
-    xx = -rect.pos.x;
-    for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
-        WMTableColumn *column;
-
-        XDrawLine(dpy, d, gc, xx, y1, xx, y2);
-
-        column = WMGetFromArray(table->columns, i);
-        xx += column->width;
-    }
-    XDrawLine(dpy, d, gc, xx, y1, xx, y2);
-
-    x1 = 0;
-    x2 = rect.size.width;
-
-    if (x2 <= x1)
-        return;
-#if 0
-    XSetDashes(dpy, gc, (rect.pos.x&1), dashl, 1);
-#endif
-
-    y1 = -rect.pos.y%table->rowHeight;
-    y2 = y1 + rect.size.height + table->rowHeight;
-
-    for (i = y1; i <= y2; i += table->rowHeight) {
-        XDrawLine(dpy, d, gc, x1, i, x2, i);
-    }
-}
-
-
-static WMRange
-columnsInRect(WMTableView *table, WMRect rect)
-{
-    WMTableColumn *column;
-    int pos;
-    int i, found;
-    int totalColumns = WMGetArrayItemCount(table->columns);
-    WMRange range;
-
-    pos = 0;
-    found = 0;
-    for (i = 0; i < totalColumns; i++) {
-        column = WMGetFromArray(table->columns, i);
-        if (!found) {
-            if (rect.pos.x >= pos && rect.pos.x < pos + column->width) {
-                range.position = i;
-                range.count = 1;
-                found = 1;
-            }
-        } else {
-            if (pos > rect.pos.x + rect.size.width) {
-                break;
-            }
-            range.count++;
-        }
-        pos += column->width;
-    }
-    range.count = WMAX(1, WMIN(range.count, totalColumns - range.position));
-    return range;
-}
-
-
-static WMRange
-rowsInRect(WMTableView *table, WMRect rect)
-{
-    WMRange range;
-    int rh = table->rowHeight;
-    int dif;
-
-    dif = rect.pos.y % rh;
-
-    range.position = WMAX(0, (rect.pos.y - dif) / rh);
-    range.count = WMAX(1, WMIN((rect.size.height + dif) / rh, table->rows));
-
-    return range;
-}
-
-
-static void
-drawRow(WMTableView *table, int row, WMRect clipRect)
-{
-    int i;
-    WMRange cols = columnsInRect(table, clipRect);
-    WMTableColumn *column;
-    Drawable d = WMGetPixmapXID(table->viewBuffer);
-
-    for (i = cols.position; i < cols.position+cols.count; i++) {
-        column = WMGetFromArray(table->columns, i);
-
-        if (!column->delegate || !column->delegate->drawCell)
-            continue;
-
-        if (WMFindInArray(table->selectedRows, NULL, (void*)(uintptr_t)row) != WANotFound)
-            (*column->delegate->drawSelectedCell)(column->delegate, column, row, d);
-        else
-            (*column->delegate->drawCell)(column->delegate, column, row, d);
-    }
-}
-
-
-#if 0
-static void
-drawFullRow(WMTableView *table, int row)
-{
-    int i;
-    WMTableColumn *column;
-    Drawable d = WMGetPixmapXID(table->viewBuffer);
-
-    for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
-        column = WMGetFromArray(table->columns, i);
-
-        if (!column->delegate || !column->delegate->drawCell)
-            continue;
-
-        if (WMFindInArray(table->selectedRows, NULL, (void*)row) != WANotFound)
-            (*column->delegate->drawSelectedCell)(column->delegate, column, row, d);
-        else
-            (*column->delegate->drawCell)(column->delegate, column, row, d);
-    }
-}
-#endif
-
-
-static void
-setRowSelected(WMTableView *table, unsigned row, Bool flag)
-{
-    int repaint = 0;
-
-    if (WMFindInArray(table->selectedRows, NULL, (void*)(uintptr_t)row) != WANotFound) {
-        if (!flag) {
-            WMRemoveFromArray(table->selectedRows, (void*)(uintptr_t)row);
-            repaint = 1;
-        }
-    } else {
-        if (flag) {
-            WMAddToArray(table->selectedRows, (void*)(uintptr_t)row);
-            repaint = 1;
-        }
-    }
-    if (repaint && row < table->rows) {
-        /*drawFullRow(table, row);*/
-        repaintTable(table);
-    }
-}
-
-
-static void
-repaintTable(WMTableView *table)
-{
-    WMRect rect;
-    WMRange rows;
-    WMScreen *scr = WMWidgetScreen(table);
-    int i;
-
-    if (!table->delegate || !W_VIEW_REALIZED(table->view))
-        return;
-
-    wassertr(table->delegate->numberOfRows);
-
-    if (!table->viewBuffer) {
-        table->viewBuffer = WMCreatePixmap(scr,
-                                           W_VIEW_WIDTH(table->tableView),
-                                           W_VIEW_HEIGHT(table->tableView),
-                                           WMScreenDepth(scr), 0);
-    }
-
-    XFillRectangle(scr->display,
-                   WMGetPixmapXID(table->viewBuffer),
-                   WMColorGC(table->backColor), 0, 0,
-                   W_VIEW_WIDTH(table->tableView),
-                   W_VIEW_HEIGHT(table->tableView));
-
-    rect = getVisibleRect(table);
-
-    if (table->drawsGrid) {
-        drawGrid(table, rect);
-    }
-
-    rows = rowsInRect(table, rect);
-    for (i = rows.position;
-         i < WMIN(rows.position+rows.count + 1, table->rows);
-         i++) {
-        drawRow(table, i, rect);
-    }
-
-    XSetWindowBackgroundPixmap(scr->display, table->tableView->window,
-                               WMGetPixmapXID(table->viewBuffer));
-    XClearWindow(scr->display, table->tableView->window);
-}
-
-
-static void
-stopRowEdit(WMTableView *table, int row)
-{
-    int i;
-    WMTableColumn *column;
-
-    table->editingRow = -1;
-    for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
-        column = WMGetFromArray(table->columns, i);
-
-        if (column->delegate && column->delegate->endCellEdit)
-            (*column->delegate->endCellEdit)(column->delegate, column, row);
-    }
-}
-
-
-
-void
-WMEditTableViewRow(WMTableView *table, int row)
-{
-    int i;
-    WMTableColumn *column;
-
-    if (table->editingRow >= 0) {
-        stopRowEdit(table, table->editingRow);
-    }
-
-    table->editingRow = row;
-
-    if (row < 0)
-        return;
-
-    for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
-        column = WMGetFromArray(table->columns, i);
-
-        if (column->delegate && column->delegate->beginCellEdit)
-            (*column->delegate->beginCellEdit)(column->delegate, column, row);
-    }
-}
-
-
-void
-WMSelectTableViewRow(WMTableView *table, int row)
-{
-    if (table->clickedRow >= 0)
-        setRowSelected(table, table->clickedRow, False);
-
-    if (row >= table->rows) {
-        return;
-    }
-
-    setRowSelected(table, row, True);
-    table->clickedRow = row;
-
-    if (table->action)
-        (*table->action)(table, table->clientData);
-    WMPostNotificationName(WMTableViewSelectionDidChangeNotification,
-                           table, NULL);
-}
-
-
-void
-WMReloadTableView(WMTableView *table)
-{
-    if (table->editingRow >= 0)
-        stopRowEdit(table, table->editingRow);
-
-    /* when this is called, nothing in the table can be assumed to be
-     * like the last time we accessed it (ie, rows might have disappeared) */
-
-    WMEmptyArray(table->selectedRows);
-
-    if (table->clickedRow >= 0) {
-        if (table->action)
-            (*table->action)(table, table->clientData);
-        WMPostNotificationName(WMTableViewSelectionDidChangeNotification,
-                               table, NULL);
-        table->clickedRow = -1;
-    }
-
-    if (table->delegate && table->delegate->numberOfRows) {
-        int rows;
-
-        rows = (*table->delegate->numberOfRows)(table->delegate, table);
-
-        if (rows != table->rows) {
-            table->rows = rows;
-            handleResize(table->view->delegate, table->view);
-        } else {
-            repaintTable(table);
-        }
-    }
-}
-
-
-void
-WMNoteTableViewNumberOfRowsChanged(WMTableView *table)
-{
-    WMReloadTableView(table);
-}
-
-
-static void
-handleTableEvents(XEvent *event, void *data)
-{
-    WMTableView *table = (WMTableView*)data;
-    int row;
-
-    switch (event->type) {
-    case ButtonPress:
-        if (event->xbutton.button == Button1) {
-            WMRect rect = getVisibleRect(table);
-
-            row = (event->xbutton.y + rect.pos.y)/table->rowHeight;
-            if (row != table->clickedRow) {
-                setRowSelected(table, table->clickedRow, False);
-                setRowSelected(table, row, True);
-                table->clickedRow = row;
-                table->dragging = 1;
-            } else {
-                table->dragging = 1;
-            }
-        }
-        break;
-
-    case MotionNotify:
-        if (table->dragging && event->xmotion.y >= 0) {
-            WMRect rect = getVisibleRect(table);
-
-            row = (event->xmotion.y + rect.pos.y)/table->rowHeight;
-            if (table->clickedRow != row && row >= 0 && row < table->rows) {
-                setRowSelected(table, table->clickedRow, False);
-                setRowSelected(table, row, True);
-                table->clickedRow = row;
-            }
-        }
-        break;
-
-    case ButtonRelease:
-        if (event->xbutton.button == Button1) {
-            if (table->action)
-                (*table->action)(table, table->clientData);
-            WMPostNotificationName(WMTableViewSelectionDidChangeNotification,
-                                   table, NULL);
-            table->dragging = 0;
-        }
-        break;
-    }
-}
-
-
-static void
-handleEvents(XEvent *event, void *data)
-{
-    WMTableView *table = (WMTableView*)data;
-    WMScreen *scr = WMWidgetScreen(table);
-
-    switch (event->type) {
-    case Expose:
-        W_DrawRelief(scr, W_VIEW_DRAWABLE(table->view), 0, 0,
-                     W_VIEW_WIDTH(table->view), W_VIEW_HEIGHT(table->view),
-                     WRSunken);
-        break;
-    }
-}
-
-
-static void
-handleResize(W_ViewDelegate *self, WMView *view)
-{
-    reorganizeInterior(view->self);
-}
-
-
-static void
-reorganizeInterior(WMTableView *table)
-{
-    int width;
-    int height;
-    WMSize size = getTotalSize(table);
-    WMView *view = table->view;
-    int vw, vh;
-    int hsThickness, vsThickness;
-
-    if (table->vscroll)
-        vsThickness = WMWidgetWidth(table->vscroll);
-    if (table->hscroll)
-        hsThickness = WMWidgetHeight(table->hscroll);
-
-    width = W_VIEW_WIDTH(view) - 2;
-    height = W_VIEW_HEIGHT(view) - 3;
-
-    height -= table->headerHeight; /* table header */
-
-    if (table->corner)
-        WMResizeWidget(table->corner, 20, table->headerHeight);
-
-    WMMoveWidget(table->vscroll, 1, table->headerHeight + 1);
-    WMResizeWidget(table->vscroll, 20, height + 1);
-
-    if (table->hscroll) {
-        WMMoveWidget(table->hscroll, vsThickness, W_VIEW_HEIGHT(view) - hsThickness - 1);
-        WMResizeWidget(table->hscroll, width-(vsThickness+1), hsThickness);
-    }
-
-    if (table->header)
-        WMResizeWidget(table->header, width-(vsThickness+1), table->headerHeight);
-
-    if (table->viewBuffer) {
-        WMReleasePixmap(table->viewBuffer);
-        table->viewBuffer = NULL;
-    }
-
-    width -= vsThickness;
-    height -= hsThickness;
-
-
-    vw = WMIN(size.width, width);
-    vh = WMIN(size.height, height);
-
-    W_MoveView(table->tableView, vsThickness+1, 1+table->headerHeight+1);
-    W_ResizeView(table->tableView, WMAX(vw, 1), WMAX(vh, 1)+1);
-
-    adjustScrollers(table);
-
-    repaintTable(table);
-}
-
-
-static void
-rearrangeHeader(WMTableView *table)
-{
-    int width;
-    int count;
-    int i;
-    /*WMRect rect = WMGetScrollViewVisibleRect(table->scrollView);*/
-
-    width = 0;
-
-    count = WMGetArrayItemCount(table->columns);
-    for (i = 0; i < count; i++) {
-        WMTableColumn *column = WMGetFromArray(table->columns, i);
-        WMView *splitter = WMGetFromArray(table->splitters, i);
-
-        WMMoveWidget(column->titleW, width, 0);
-        WMResizeWidget(column->titleW, column->width-1, table->headerHeight);
-
-        width += column->width;
-        W_MoveView(splitter, width-1, 0);
-    }
-
-    wassertr(table->delegate && table->delegate->numberOfRows);
-
-    table->rows = table->delegate->numberOfRows(table->delegate, table);
-
-    table->tableWidth = width + 1;
-
-    handleResize(table->view->delegate, table->view);
-}
-
+
+#include <WINGs/WINGsP.h>
+#include <X11/cursorfont.h>
+#include <stdint.h>
+
+#include "wtableview.h"
+
+const char *WMTableViewSelectionDidChangeNotification = "WMTableViewSelectionDidChangeNotification";
+
+struct W_TableColumn {
+       WMTableView *table;
+       WMWidget *titleW;
+       char *title;
+       int width;
+       int minWidth;
+       int maxWidth;
+
+       void *id;
+
+       WMTableColumnDelegate *delegate;
+
+       unsigned resizable:1;
+       unsigned editable:1;
+};
+
+static void handleResize(W_ViewDelegate * self, WMView * view);
+
+static void rearrangeHeader(WMTableView * table);
+
+static WMRange rowsInRect(WMTableView * table, WMRect rect);
+
+WMTableColumn *WMCreateTableColumn(char *title)
+{
+       WMTableColumn *col = wmalloc(sizeof(WMTableColumn));
+
+       col->table = NULL;
+       col->titleW = NULL;
+       col->width = 50;
+       col->minWidth = 5;
+       col->maxWidth = 0;
+
+       col->id = NULL;
+
+       col->title = wstrdup(title);
+
+       col->delegate = NULL;
+
+       col->resizable = 1;
+       col->editable = 0;
+
+       return col;
+}
+
+void WMSetTableColumnId(WMTableColumn * column, void *id)
+{
+       column->id = id;
+}
+
+void *WMGetTableColumnId(WMTableColumn * column)
+{
+       return column->id;
+}
+
+void WMSetTableColumnWidth(WMTableColumn * column, unsigned width)
+{
+       if (column->maxWidth == 0)
+               column->width = WMAX(column->minWidth, width);
+       else
+               column->width = WMAX(column->minWidth, WMIN(column->maxWidth, width));
+
+       if (column->table) {
+               rearrangeHeader(column->table);
+       }
+}
+
+void WMSetTableColumnDelegate(WMTableColumn * column, WMTableColumnDelegate * delegate)
+{
+       column->delegate = delegate;
+}
+
+void WMSetTableColumnConstraints(WMTableColumn * column, unsigned minWidth, unsigned maxWidth)
+{
+       wassertr(maxWidth == 0 || minWidth <= maxWidth);
+
+       column->minWidth = minWidth;
+       column->maxWidth = maxWidth;
+
+       if (column->width < column->minWidth)
+               WMSetTableColumnWidth(column, column->minWidth);
+       else if (column->width > column->maxWidth && column->maxWidth != 0)
+               WMSetTableColumnWidth(column, column->maxWidth);
+}
+
+void WMSetTableColumnEditable(WMTableColumn * column, Bool flag)
+{
+       column->editable = ((flag == 0) ? 0 : 1);
+}
+
+WMTableView *WMGetTableColumnTableView(WMTableColumn * column)
+{
+       return column->table;
+}
+
+struct W_TableView {
+       W_Class widgetClass;
+       WMView *view;
+
+       WMFrame *header;
+
+       WMLabel *corner;
+
+       WMScroller *hscroll;
+       WMScroller *vscroll;
+       WMView *tableView;
+
+       WMPixmap *viewBuffer;
+
+       WMArray *columns;
+       WMArray *splitters;
+
+       WMArray *selectedRows;
+
+       int tableWidth;
+
+       int rows;
+
+       WMColor *backColor;
+
+       GC gridGC;
+       WMColor *gridColor;
+
+       Cursor splitterCursor;
+
+       void *dataSource;
+
+       WMTableViewDelegate *delegate;
+
+       WMAction *action;
+       void *clientData;
+
+       void *clickedColumn;
+       int clickedRow;
+
+       int editingRow;
+
+       unsigned headerHeight;
+
+       unsigned rowHeight;
+
+       unsigned dragging:1;
+       unsigned drawsGrid:1;
+       unsigned canSelectRow:1;
+       unsigned canSelectMultiRows:1;
+       unsigned canDeselectRow:1;
+
+       unsigned int hasVScroller:1;
+       unsigned int hasHScroller:1;
+};
+
+static W_Class tableClass = 0;
+
+static W_ViewDelegate viewDelegate = {
+       NULL,
+       NULL,
+       handleResize,
+       NULL,
+       NULL
+};
+
+static void reorganizeInterior(WMTableView * table);
+
+static void handleEvents(XEvent * event, void *data);
+static void handleTableEvents(XEvent * event, void *data);
+static void repaintTable(WMTableView * table);
+
+static WMSize getTotalSize(WMTableView * table)
+{
+       WMSize size;
+       int i;
+
+       /* get width from columns */
+       size.width = 0;
+       for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
+               WMTableColumn *column;
+
+               column = WMGetFromArray(table->columns, i);
+
+               size.width += column->width;
+       }
+
+       /* get height from rows */
+       size.height = table->rows * table->rowHeight;
+
+       return size;
+}
+
+static WMRect getVisibleRect(WMTableView * table)
+{
+       WMSize size = getTotalSize(table);
+       WMRect rect;
+
+       if (table->vscroll) {
+               rect.size.height = size.height * WMGetScrollerKnobProportion(table->vscroll);
+               rect.pos.y = (size.height - rect.size.height) * WMGetScrollerValue(table->vscroll);
+       } else {
+               rect.size.height = size.height;
+               rect.pos.y = 0;
+       }
+
+       if (table->hscroll) {
+               rect.size.width = size.width * WMGetScrollerKnobProportion(table->hscroll);
+               rect.pos.x = (size.width - rect.size.width) * WMGetScrollerValue(table->hscroll);
+       } else {
+               rect.size.width = size.width;
+               rect.pos.x = 0;
+       }
+
+       return rect;
+}
+
+static void scrollToPoint(WMTableView * table, int x, int y)
+{
+       WMSize size = getTotalSize(table);
+       int i;
+       float value, prop;
+
+       if (table->hscroll) {
+               if (size.width > W_VIEW_WIDTH(table->tableView)) {
+                       prop = (float)W_VIEW_WIDTH(table->tableView) / (float)size.width;
+                       value = (float)x / (float)(size.width - W_VIEW_WIDTH(table->tableView));
+               } else {
+                       prop = 1.0;
+                       value = 0.0;
+               }
+               WMSetScrollerParameters(table->hscroll, value, prop);
+       }
+
+       if (table->vscroll) {
+               if (size.height > W_VIEW_HEIGHT(table->tableView)) {
+                       prop = (float)W_VIEW_HEIGHT(table->tableView) / (float)size.height;
+                       value = (float)y / (float)(size.height - W_VIEW_HEIGHT(table->tableView));
+               } else {
+                       prop = 1.0;
+                       value = 0.0;
+               }
+
+               WMSetScrollerParameters(table->vscroll, value, prop);
+       }
+
+       if (table->editingRow >= 0) {
+               for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
+                       WMTableColumn *column;
+
+                       column = WMGetFromArray(table->columns, i);
+
+                       if (column->delegate && column->delegate->beginCellEdit)
+                               (*column->delegate->beginCellEdit) (column->delegate, column, table->editingRow);
+               }
+       }
+
+       repaintTable(table);
+}
+
+static void adjustScrollers(WMTableView * table)
+{
+       WMSize size = getTotalSize(table);
+       WMSize vsize = WMGetViewSize(table->tableView);
+       float prop, value;
+       float oprop, ovalue;
+
+       if (table->hscroll) {
+               if (size.width <= vsize.width) {
+                       value = 0.0;
+                       prop = 1.0;
+               } else {
+                       oprop = WMGetScrollerKnobProportion(table->hscroll);
+                       if (oprop == 0.0)
+                               oprop = 1.0;
+                       ovalue = WMGetScrollerValue(table->hscroll);
+
+                       prop = (float)vsize.width / (float)size.width;
+                       value = prop * ovalue / oprop;
+               }
+               WMSetScrollerParameters(table->hscroll, value, prop);
+       }
+
+       if (table->vscroll) {
+               if (size.height <= vsize.height) {
+                       value = 0.0;
+                       prop = 1.0;
+               } else {
+                       oprop = WMGetScrollerKnobProportion(table->vscroll);
+                       if (oprop == 0.0)
+                               oprop = 1.0;
+                       ovalue = WMGetScrollerValue(table->vscroll);
+
+                       prop = (float)vsize.height / (float)size.height;
+                       value = prop * ovalue / oprop;
+               }
+               WMSetScrollerParameters(table->vscroll, value, prop);
+       }
+}
+
+static void doScroll(WMWidget * self, void *data)
+{
+       WMTableView *table = (WMTableView *) data;
+       float value;
+       float vpsize;
+       float size;
+       WMSize ts = getTotalSize(table);
+
+       value = WMGetScrollerValue(self);
+
+       if (table->hscroll == (WMScroller *) self) {
+               vpsize = W_VIEW_WIDTH(table->tableView);
+               size = ts.width;
+       } else {
+               vpsize = W_VIEW_HEIGHT(table->tableView);
+               size = ts.height;
+       }
+
+       switch (WMGetScrollerHitPart(self)) {
+       case WSDecrementWheel:
+       case WSDecrementLine:
+               value -= (float)table->rowHeight / size;
+               if (value < 0)
+                       value = 0.0;
+               WMSetScrollerParameters(self, value, WMGetScrollerKnobProportion(self));
+               repaintTable(table);
+               break;
+
+       case WSIncrementWheel:
+       case WSIncrementLine:
+               value += (float)table->rowHeight / size;
+               if (value > 1.0)
+                       value = 1.0;
+               WMSetScrollerParameters(self, value, WMGetScrollerKnobProportion(self));
+               repaintTable(table);
+               break;
+
+       case WSKnob:
+               repaintTable(table);
+               break;
+
+       case WSDecrementPage:
+               value -= vpsize / size;
+               if (value < 0.0)
+                       value = 0.0;
+               WMSetScrollerParameters(self, value, WMGetScrollerKnobProportion(self));
+               repaintTable(table);
+               break;
+
+       case WSIncrementPage:
+               value += vpsize / size;
+               if (value > 1.0)
+                       value = 1.0;
+               WMSetScrollerParameters(self, value, WMGetScrollerKnobProportion(self));
+               repaintTable(table);
+               break;
+
+       case WSNoPart:
+       case WSKnobSlot:
+               break;
+       }
+
+       if (table->editingRow >= 0) {
+               int i;
+               for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
+                       WMTableColumn *column;
+
+                       column = WMGetFromArray(table->columns, i);
+
+                       if (column->delegate && column->delegate->beginCellEdit)
+                               (*column->delegate->beginCellEdit) (column->delegate, column, table->editingRow);
+               }
+       }
+
+       if (table->hscroll == self) {
+               int x = 0;
+               int i;
+               WMRect rect = getVisibleRect(table);
+
+               for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
+                       WMTableColumn *column;
+                       WMView *splitter;
+
+                       column = WMGetFromArray(table->columns, i);
+
+                       WMMoveWidget(column->titleW, x - rect.pos.x, 0);
+
+                       x += W_VIEW_WIDTH(WMWidgetView(column->titleW)) + 1;
+
+                       splitter = WMGetFromArray(table->splitters, i);
+                       W_MoveView(splitter, x - rect.pos.x - 1, 0);
+               }
+       }
+}
+
+static void splitterHandler(XEvent * event, void *data)
+{
+       WMTableColumn *column = (WMTableColumn *) data;
+       WMTableView *table = column->table;
+       int done = 0;
+       int cx, ox, offsX;
+       WMPoint pos;
+       WMScreen *scr = WMWidgetScreen(table);
+       GC gc = scr->ixorGC;
+       Display *dpy = WMScreenDisplay(scr);
+       int h = WMWidgetHeight(table) - 22;
+       Window w = WMViewXID(table->view);
+
+       pos = WMGetViewPosition(WMWidgetView(column->titleW));
+
+       offsX = pos.x + column->width;
+
+       ox = cx = offsX;
+
+       XDrawLine(dpy, w, gc, cx + 20, 0, cx + 20, h);
+
+       while (!done) {
+               XEvent ev;
+
+               WMMaskEvent(dpy, ButtonMotionMask | ButtonReleaseMask, &ev);
+
+               switch (ev.type) {
+               case MotionNotify:
+                       ox = cx;
+
+                       if (column->width + ev.xmotion.x < column->minWidth)
+                               cx = pos.x + column->minWidth;
+                       else if (column->maxWidth > 0 && column->width + ev.xmotion.x > column->maxWidth)
+                               cx = pos.x + column->maxWidth;
+                       else
+                               cx = offsX + ev.xmotion.x;
+
+                       XDrawLine(dpy, w, gc, ox + 20, 0, ox + 20, h);
+                       XDrawLine(dpy, w, gc, cx + 20, 0, cx + 20, h);
+                       break;
+
+               case ButtonRelease:
+                       column->width = cx - pos.x;
+                       done = 1;
+                       break;
+               }
+       }
+
+       XDrawLine(dpy, w, gc, cx + 20, 0, cx + 20, h);
+       rearrangeHeader(table);
+       repaintTable(table);
+}
+
+static void realizeTable(void *data, WMNotification * notif)
+{
+       repaintTable(data);
+}
+
+WMTableView *WMCreateTableView(WMWidget * parent)
+{
+       WMTableView *table = wmalloc(sizeof(WMTableView));
+       WMScreen *scr = WMWidgetScreen(parent);
+
+       memset(table, 0, sizeof(WMTableView));
+
+       if (!tableClass) {
+               tableClass = W_RegisterUserWidget();
+       }
+       table->widgetClass = tableClass;
+
+       table->view = W_CreateView(W_VIEW(parent));
+       if (!table->view)
+               goto error;
+       table->view->self = table;
+
+       table->view->delegate = &viewDelegate;
+
+       table->headerHeight = 20;
+
+       table->hscroll = WMCreateScroller(table);
+       WMSetScrollerAction(table->hscroll, doScroll, table);
+       WMMoveWidget(table->hscroll, 1, 2 + table->headerHeight);
+       WMMapWidget(table->hscroll);
+
+       table->hasHScroller = 1;
+
+       table->vscroll = WMCreateScroller(table);
+       WMSetScrollerArrowsPosition(table->vscroll, WSAMaxEnd);
+       WMSetScrollerAction(table->vscroll, doScroll, table);
+       WMMoveWidget(table->vscroll, 1, 2 + table->headerHeight);
+       WMMapWidget(table->vscroll);
+
+       table->hasVScroller = 1;
+
+       table->header = WMCreateFrame(table);
+       WMMoveWidget(table->header, 22, 2);
+       WMMapWidget(table->header);
+       WMSetFrameRelief(table->header, WRFlat);
+
+       table->corner = WMCreateLabel(table);
+       WMResizeWidget(table->corner, 20, table->headerHeight);
+       WMMoveWidget(table->corner, 2, 2);
+       WMMapWidget(table->corner);
+       WMSetLabelRelief(table->corner, WRRaised);
+       WMSetWidgetBackgroundColor(table->corner, scr->darkGray);
+
+       table->tableView = W_CreateView(table->view);
+       if (!table->tableView)
+               goto error;
+       table->tableView->self = table;
+       W_MapView(table->tableView);
+
+       WMAddNotificationObserver(realizeTable, table, WMViewRealizedNotification, table->tableView);
+
+       table->tableView->flags.dontCompressExpose = 1;
+
+       table->gridColor = WMCreateNamedColor(scr, "#cccccc", False);
+       /*   table->gridColor = WMGrayColor(scr); */
+
+       {
+               XGCValues gcv;
+
+               table->backColor = WMWhiteColor(scr);
+
+               gcv.foreground = WMColorPixel(table->gridColor);
+               gcv.dashes = 1;
+               gcv.line_style = LineOnOffDash;
+               table->gridGC = XCreateGC(WMScreenDisplay(scr), W_DRAWABLE(scr), GCForeground, &gcv);
+       }
+
+       table->editingRow = -1;
+       table->clickedRow = -1;
+
+       table->drawsGrid = 1;
+       table->rowHeight = 16;
+
+       table->tableWidth = 1;
+
+       table->columns = WMCreateArray(4);
+       table->splitters = WMCreateArray(4);
+
+       table->selectedRows = WMCreateArray(16);
+
+       table->splitterCursor = XCreateFontCursor(WMScreenDisplay(scr), XC_sb_h_double_arrow);
+
+       table->canSelectRow = 1;
+
+       WMCreateEventHandler(table->view, ExposureMask | StructureNotifyMask, handleEvents, table);
+
+       WMCreateEventHandler(table->tableView, ExposureMask | ButtonPressMask |
+                            ButtonReleaseMask | ButtonMotionMask, handleTableEvents, table);
+
+       WMResizeWidget(table, 50, 50);
+
+       return table;
+
+ error:
+       if (table->tableView)
+               W_DestroyView(table->tableView);
+       if (table->view)
+               W_DestroyView(table->view);
+       wfree(table);
+       return NULL;
+}
+
+void WMAddTableViewColumn(WMTableView * table, WMTableColumn * column)
+{
+       WMScreen *scr = WMWidgetScreen(table);
+
+       column->table = table;
+
+       WMAddToArray(table->columns, column);
+
+       if (!column->titleW) {
+               column->titleW = WMCreateLabel(table);
+               WMSetLabelRelief(column->titleW, WRRaised);
+               WMSetLabelFont(column->titleW, scr->boldFont);
+               WMSetLabelTextColor(column->titleW, scr->white);
+               WMSetWidgetBackgroundColor(column->titleW, scr->darkGray);
+               WMSetLabelText(column->titleW, column->title);
+               W_ReparentView(WMWidgetView(column->titleW), WMWidgetView(table->header), 0, 0);
+               if (W_VIEW_REALIZED(table->view))
+                       WMRealizeWidget(column->titleW);
+               WMMapWidget(column->titleW);
+       }
+
+       {
+               WMView *splitter = W_CreateView(WMWidgetView(table->header));
+
+               W_SetViewBackgroundColor(splitter, WMWhiteColor(scr));
+
+               if (W_VIEW_REALIZED(table->view))
+                       W_RealizeView(splitter);
+
+               W_ResizeView(splitter, 2, table->headerHeight);
+               W_MapView(splitter);
+
+               W_SetViewCursor(splitter, table->splitterCursor);
+               WMCreateEventHandler(splitter, ButtonPressMask | ButtonReleaseMask, splitterHandler, column);
+
+               WMAddToArray(table->splitters, splitter);
+       }
+
+       rearrangeHeader(table);
+}
+
+void WMSetTableViewHeaderHeight(WMTableView * table, unsigned height)
+{
+       table->headerHeight = height;
+
+       handleResize(NULL, table->view);
+}
+
+void WMSetTableViewDelegate(WMTableView * table, WMTableViewDelegate * delegate)
+{
+       table->delegate = delegate;
+}
+
+void WMSetTableViewAction(WMTableView * table, WMAction * action, void *clientData)
+{
+       table->action = action;
+
+       table->clientData = clientData;
+}
+
+void *WMGetTableViewClickedColumn(WMTableView * table)
+{
+       return table->clickedColumn;
+}
+
+int WMGetTableViewClickedRow(WMTableView * table)
+{
+       return table->clickedRow;
+}
+
+WMArray *WMGetTableViewSelectedRows(WMTableView * table)
+{
+       return table->selectedRows;
+}
+
+WMView *WMGetTableViewDocumentView(WMTableView * table)
+{
+       return table->tableView;
+}
+
+void *WMTableViewDataForCell(WMTableView * table, WMTableColumn * column, int row)
+{
+       return (*table->delegate->valueForCell) (table->delegate, column, row);
+}
+
+void WMSetTableViewDataForCell(WMTableView * table, WMTableColumn * column, int row, void *data)
+{
+       (*table->delegate->setValueForCell) (table->delegate, column, row, data);
+}
+
+WMRect WMTableViewRectForCell(WMTableView * table, WMTableColumn * column, int row)
+{
+       WMRect rect;
+       int i;
+
+       rect.pos.x = 0;
+       rect.pos.y = row * table->rowHeight;
+       rect.size.height = table->rowHeight;
+
+       for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
+               WMTableColumn *col;
+               col = WMGetFromArray(table->columns, i);
+
+               if (col == column) {
+                       rect.size.width = col->width;
+                       break;
+               }
+
+               rect.pos.x += col->width;
+       }
+
+       {
+               WMRect r = getVisibleRect(table);
+
+               rect.pos.y -= r.pos.y;
+               rect.pos.x -= r.pos.x;
+       }
+
+       return rect;
+}
+
+void WMSetTableViewDataSource(WMTableView * table, void *source)
+{
+       table->dataSource = source;
+}
+
+void *WMGetTableViewDataSource(WMTableView * table)
+{
+       return table->dataSource;
+}
+
+void WMSetTableViewHasHorizontalScroller(WMTableView * tPtr, Bool flag)
+{
+       if (flag) {
+               if (tPtr->hasHScroller)
+                       return;
+               tPtr->hasHScroller = 1;
+
+               tPtr->hscroll = WMCreateScroller(tPtr);
+               WMSetScrollerAction(tPtr->hscroll, doScroll, tPtr);
+               WMSetScrollerArrowsPosition(tPtr->hscroll, WSAMaxEnd);
+               /* make it a horiz. scroller */
+               WMResizeWidget(tPtr->hscroll, 1, 2);
+
+               if (W_VIEW_REALIZED(tPtr->view)) {
+                       WMRealizeWidget(tPtr->hscroll);
+               }
+
+               reorganizeInterior(tPtr);
+
+               WMMapWidget(tPtr->hscroll);
+       } else {
+               if (!tPtr->hasHScroller)
+                       return;
+               tPtr->hasHScroller = 0;
+
+               WMUnmapWidget(tPtr->hscroll);
+               WMDestroyWidget(tPtr->hscroll);
+               tPtr->hscroll = NULL;
+
+               reorganizeInterior(tPtr);
+       }
+}
+
+#if 0
+/* not supported by now */
+void WMSetTableViewHasVerticalScroller(WMTableView * tPtr, Bool flag)
+{
+       if (flag) {
+               if (tPtr->hasVScroller)
+                       return;
+               tPtr->hasVScroller = 1;
+
+               tPtr->vscroll = WMCreateScroller(tPtr);
+               WMSetScrollerAction(tPtr->vscroll, doScroll, tPtr);
+               WMSetScrollerArrowsPosition(tPtr->vscroll, WSAMaxEnd);
+               /* make it a vert. scroller */
+               WMResizeWidget(tPtr->vscroll, 1, 2);
+
+               if (W_VIEW_REALIZED(tPtr->view)) {
+                       WMRealizeWidget(tPtr->vscroll);
+               }
+
+               reorganizeInterior(tPtr);
+
+               WMMapWidget(tPtr->vscroll);
+       } else {
+               if (!tPtr->hasVScroller)
+                       return;
+               tPtr->hasVScroller = 0;
+
+               WMUnmapWidget(tPtr->vscroll);
+               WMDestroyWidget(tPtr->vscroll);
+               tPtr->vscroll = NULL;
+
+               reorganizeInterior(tPtr);
+       }
+}
+#endif
+
+void WMSetTableViewBackgroundColor(WMTableView * table, WMColor * color)
+{
+       W_SetViewBackgroundColor(table->tableView, color);
+
+       if (table->backColor)
+               WMReleaseColor(table->backColor);
+
+       table->backColor = WMRetainColor(color);
+
+       repaintTable(table);
+}
+
+void WMSetTableViewGridColor(WMTableView * table, WMColor * color)
+{
+       WMReleaseColor(table->gridColor);
+       table->gridColor = WMRetainColor(color);
+       XSetForeground(WMScreenDisplay(WMWidgetScreen(table)), table->gridGC, WMColorPixel(color));
+       repaintTable(table);
+}
+
+void WMSetTableViewRowHeight(WMTableView * table, int height)
+{
+       table->rowHeight = height;
+
+       repaintTable(table);
+}
+
+void WMScrollTableViewRowToVisible(WMTableView * table, int row)
+{
+       WMScroller *scroller;
+       WMRange range;
+       WMRect rect;
+       int newY, tmp;
+
+       rect = getVisibleRect(table);
+       range = rowsInRect(table, rect);
+
+       scroller = table->vscroll;
+
+       if (row < range.position) {
+               newY = row * table->rowHeight - rect.size.height / 2;
+       } else if (row >= range.position + range.count) {
+               newY = row * table->rowHeight - rect.size.height / 2;
+       } else {
+               return;
+       }
+       tmp = table->rows * table->rowHeight - rect.size.height;
+       newY = WMAX(0, WMIN(newY, tmp));
+
+       scrollToPoint(table, rect.pos.x, newY);
+}
+
+static void drawGrid(WMTableView * table, WMRect rect)
+{
+       WMScreen *scr = WMWidgetScreen(table);
+       Display *dpy = WMScreenDisplay(scr);
+       int i;
+       int y1, y2;
+       int x1, x2;
+       int xx;
+       Drawable d = WMGetPixmapXID(table->viewBuffer);
+       GC gc = table->gridGC;
+
+#if 0
+       char dashl[1] = { 1 };
+
+       XSetDashes(dpy, gc, 0, dashl, 1);
+
+       y1 = (rect.pos.y / table->rowHeight - 1) * table->rowHeight;
+       y2 = y1 + (rect.size.height / table->rowHeight + 2) * table->rowHeight;
+#endif
+       y1 = 0;
+       y2 = W_VIEW_HEIGHT(table->tableView);
+
+       xx = -rect.pos.x;
+       for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
+               WMTableColumn *column;
+
+               XDrawLine(dpy, d, gc, xx, y1, xx, y2);
+
+               column = WMGetFromArray(table->columns, i);
+               xx += column->width;
+       }
+       XDrawLine(dpy, d, gc, xx, y1, xx, y2);
+
+       x1 = 0;
+       x2 = rect.size.width;
+
+       if (x2 <= x1)
+               return;
+#if 0
+       XSetDashes(dpy, gc, (rect.pos.x & 1), dashl, 1);
+#endif
+
+       y1 = -rect.pos.y % table->rowHeight;
+       y2 = y1 + rect.size.height + table->rowHeight;
+
+       for (i = y1; i <= y2; i += table->rowHeight) {
+               XDrawLine(dpy, d, gc, x1, i, x2, i);
+       }
+}
+
+static WMRange columnsInRect(WMTableView * table, WMRect rect)
+{
+       WMTableColumn *column;
+       int pos;
+       int i, found;
+       int totalColumns = WMGetArrayItemCount(table->columns);
+       WMRange range;
+
+       pos = 0;
+       found = 0;
+       for (i = 0; i < totalColumns; i++) {
+               column = WMGetFromArray(table->columns, i);
+               if (!found) {
+                       if (rect.pos.x >= pos && rect.pos.x < pos + column->width) {
+                               range.position = i;
+                               range.count = 1;
+                               found = 1;
+                       }
+               } else {
+                       if (pos > rect.pos.x + rect.size.width) {
+                               break;
+                       }
+                       range.count++;
+               }
+               pos += column->width;
+       }
+       range.count = WMAX(1, WMIN(range.count, totalColumns - range.position));
+       return range;
+}
+
+static WMRange rowsInRect(WMTableView * table, WMRect rect)
+{
+       WMRange range;
+       int rh = table->rowHeight;
+       int dif;
+
+       dif = rect.pos.y % rh;
+
+       range.position = WMAX(0, (rect.pos.y - dif) / rh);
+       range.count = WMAX(1, WMIN((rect.size.height + dif) / rh, table->rows));
+
+       return range;
+}
+
+static void drawRow(WMTableView * table, int row, WMRect clipRect)
+{
+       int i;
+       WMRange cols = columnsInRect(table, clipRect);
+       WMTableColumn *column;
+       Drawable d = WMGetPixmapXID(table->viewBuffer);
+
+       for (i = cols.position; i < cols.position + cols.count; i++) {
+               column = WMGetFromArray(table->columns, i);
+
+               if (!column->delegate || !column->delegate->drawCell)
+                       continue;
+
+               if (WMFindInArray(table->selectedRows, NULL, (void *)(uintptr_t) row) != WANotFound)
+                       (*column->delegate->drawSelectedCell) (column->delegate, column, row, d);
+               else
+                       (*column->delegate->drawCell) (column->delegate, column, row, d);
+       }
+}
+
+#if 0
+static void drawFullRow(WMTableView * table, int row)
+{
+       int i;
+       WMTableColumn *column;
+       Drawable d = WMGetPixmapXID(table->viewBuffer);
+
+       for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
+               column = WMGetFromArray(table->columns, i);
+
+               if (!column->delegate || !column->delegate->drawCell)
+                       continue;
+
+               if (WMFindInArray(table->selectedRows, NULL, (void *)row) != WANotFound)
+                       (*column->delegate->drawSelectedCell) (column->delegate, column, row, d);
+               else
+                       (*column->delegate->drawCell) (column->delegate, column, row, d);
+       }
+}
+#endif
+
+static void setRowSelected(WMTableView * table, unsigned row, Bool flag)
+{
+       int repaint = 0;
+
+       if (WMFindInArray(table->selectedRows, NULL, (void *)(uintptr_t) row) != WANotFound) {
+               if (!flag) {
+                       WMRemoveFromArray(table->selectedRows, (void *)(uintptr_t) row);
+                       repaint = 1;
+               }
+       } else {
+               if (flag) {
+                       WMAddToArray(table->selectedRows, (void *)(uintptr_t) row);
+                       repaint = 1;
+               }
+       }
+       if (repaint && row < table->rows) {
+               /*drawFullRow(table, row); */
+               repaintTable(table);
+       }
+}
+
+static void repaintTable(WMTableView * table)
+{
+       WMRect rect;
+       WMRange rows;
+       WMScreen *scr = WMWidgetScreen(table);
+       int i;
+
+       if (!table->delegate || !W_VIEW_REALIZED(table->view))
+               return;
+
+       wassertr(table->delegate->numberOfRows);
+
+       if (!table->viewBuffer) {
+               table->viewBuffer = WMCreatePixmap(scr,
+                                                  W_VIEW_WIDTH(table->tableView),
+                                                  W_VIEW_HEIGHT(table->tableView), WMScreenDepth(scr), 0);
+       }
+
+       XFillRectangle(scr->display,
+                      WMGetPixmapXID(table->viewBuffer),
+                      WMColorGC(table->backColor), 0, 0,
+                      W_VIEW_WIDTH(table->tableView), W_VIEW_HEIGHT(table->tableView));
+
+       rect = getVisibleRect(table);
+
+       if (table->drawsGrid) {
+               drawGrid(table, rect);
+       }
+
+       rows = rowsInRect(table, rect);
+       for (i = rows.position; i < WMIN(rows.position + rows.count + 1, table->rows); i++) {
+               drawRow(table, i, rect);
+       }
+
+       XSetWindowBackgroundPixmap(scr->display, table->tableView->window, WMGetPixmapXID(table->viewBuffer));
+       XClearWindow(scr->display, table->tableView->window);
+}
+
+static void stopRowEdit(WMTableView * table, int row)
+{
+       int i;
+       WMTableColumn *column;
+
+       table->editingRow = -1;
+       for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
+               column = WMGetFromArray(table->columns, i);
+
+               if (column->delegate && column->delegate->endCellEdit)
+                       (*column->delegate->endCellEdit) (column->delegate, column, row);
+       }
+}
+
+void WMEditTableViewRow(WMTableView * table, int row)
+{
+       int i;
+       WMTableColumn *column;
+
+       if (table->editingRow >= 0) {
+               stopRowEdit(table, table->editingRow);
+       }
+
+       table->editingRow = row;
+
+       if (row < 0)
+               return;
+
+       for (i = 0; i < WMGetArrayItemCount(table->columns); i++) {
+               column = WMGetFromArray(table->columns, i);
+
+               if (column->delegate && column->delegate->beginCellEdit)
+                       (*column->delegate->beginCellEdit) (column->delegate, column, row);
+       }
+}
+
+void WMSelectTableViewRow(WMTableView * table, int row)
+{
+       if (table->clickedRow >= 0)
+               setRowSelected(table, table->clickedRow, False);
+
+       if (row >= table->rows) {
+               return;
+       }
+
+       setRowSelected(table, row, True);
+       table->clickedRow = row;
+
+       if (table->action)
+               (*table->action) (table, table->clientData);
+       WMPostNotificationName(WMTableViewSelectionDidChangeNotification, table, NULL);
+}
+
+void WMReloadTableView(WMTableView * table)
+{
+       if (table->editingRow >= 0)
+               stopRowEdit(table, table->editingRow);
+
+       /* when this is called, nothing in the table can be assumed to be
+        * like the last time we accessed it (ie, rows might have disappeared) */
+
+       WMEmptyArray(table->selectedRows);
+
+       if (table->clickedRow >= 0) {
+               if (table->action)
+                       (*table->action) (table, table->clientData);
+               WMPostNotificationName(WMTableViewSelectionDidChangeNotification, table, NULL);
+               table->clickedRow = -1;
+       }
+
+       if (table->delegate && table->delegate->numberOfRows) {
+               int rows;
+
+               rows = (*table->delegate->numberOfRows) (table->delegate, table);
+
+               if (rows != table->rows) {
+                       table->rows = rows;
+                       handleResize(table->view->delegate, table->view);
+               } else {
+                       repaintTable(table);
+               }
+       }
+}
+
+void WMNoteTableViewNumberOfRowsChanged(WMTableView * table)
+{
+       WMReloadTableView(table);
+}
+
+static void handleTableEvents(XEvent * event, void *data)
+{
+       WMTableView *table = (WMTableView *) data;
+       int row;
+
+       switch (event->type) {
+       case ButtonPress:
+               if (event->xbutton.button == Button1) {
+                       WMRect rect = getVisibleRect(table);
+
+                       row = (event->xbutton.y + rect.pos.y) / table->rowHeight;
+                       if (row != table->clickedRow) {
+                               setRowSelected(table, table->clickedRow, False);
+                               setRowSelected(table, row, True);
+                               table->clickedRow = row;
+                               table->dragging = 1;
+                       } else {
+                               table->dragging = 1;
+                       }
+               }
+               break;
+
+       case MotionNotify:
+               if (table->dragging && event->xmotion.y >= 0) {
+                       WMRect rect = getVisibleRect(table);
+
+                       row = (event->xmotion.y + rect.pos.y) / table->rowHeight;
+                       if (table->clickedRow != row && row >= 0 && row < table->rows) {
+                               setRowSelected(table, table->clickedRow, False);
+                               setRowSelected(table, row, True);
+                               table->clickedRow = row;
+                       }
+               }
+               break;
+
+       case ButtonRelease:
+               if (event->xbutton.button == Button1) {
+                       if (table->action)
+                               (*table->action) (table, table->clientData);
+                       WMPostNotificationName(WMTableViewSelectionDidChangeNotification, table, NULL);
+                       table->dragging = 0;
+               }
+               break;
+       }
+}
+
+static void handleEvents(XEvent * event, void *data)
+{
+       WMTableView *table = (WMTableView *) data;
+       WMScreen *scr = WMWidgetScreen(table);
+
+       switch (event->type) {
+       case Expose:
+               W_DrawRelief(scr, W_VIEW_DRAWABLE(table->view), 0, 0,
+                            W_VIEW_WIDTH(table->view), W_VIEW_HEIGHT(table->view), WRSunken);
+               break;
+       }
+}
+
+static void handleResize(W_ViewDelegate * self, WMView * view)
+{
+       reorganizeInterior(view->self);
+}
+
+static void reorganizeInterior(WMTableView * table)
+{
+       int width;
+       int height;
+       WMSize size = getTotalSize(table);
+       WMView *view = table->view;
+       int vw, vh;
+       int hsThickness, vsThickness;
+
+       if (table->vscroll)
+               vsThickness = WMWidgetWidth(table->vscroll);
+       if (table->hscroll)
+               hsThickness = WMWidgetHeight(table->hscroll);
+
+       width = W_VIEW_WIDTH(view) - 2;
+       height = W_VIEW_HEIGHT(view) - 3;
+
+       height -= table->headerHeight;  /* table header */
+
+       if (table->corner)
+               WMResizeWidget(table->corner, 20, table->headerHeight);
+
+       WMMoveWidget(table->vscroll, 1, table->headerHeight + 1);
+       WMResizeWidget(table->vscroll, 20, height + 1);
+
+       if (table->hscroll) {
+               WMMoveWidget(table->hscroll, vsThickness, W_VIEW_HEIGHT(view) - hsThickness - 1);
+               WMResizeWidget(table->hscroll, width - (vsThickness + 1), hsThickness);
+       }
+
+       if (table->header)
+               WMResizeWidget(table->header, width - (vsThickness + 1), table->headerHeight);
+
+       if (table->viewBuffer) {
+               WMReleasePixmap(table->viewBuffer);
+               table->viewBuffer = NULL;
+       }
+
+       width -= vsThickness;
+       height -= hsThickness;
+
+       vw = WMIN(size.width, width);
+       vh = WMIN(size.height, height);
+
+       W_MoveView(table->tableView, vsThickness + 1, 1 + table->headerHeight + 1);
+       W_ResizeView(table->tableView, WMAX(vw, 1), WMAX(vh, 1) + 1);
+
+       adjustScrollers(table);
+
+       repaintTable(table);
+}
+
+static void rearrangeHeader(WMTableView * table)
+{
+       int width;
+       int count;
+       int i;
+       /*WMRect rect = WMGetScrollViewVisibleRect(table->scrollView); */
+
+       width = 0;
+
+       count = WMGetArrayItemCount(table->columns);
+       for (i = 0; i < count; i++) {
+               WMTableColumn *column = WMGetFromArray(table->columns, i);
+               WMView *splitter = WMGetFromArray(table->splitters, i);
+
+               WMMoveWidget(column->titleW, width, 0);
+               WMResizeWidget(column->titleW, column->width - 1, table->headerHeight);
+
+               width += column->width;
+               W_MoveView(splitter, width - 1, 0);
+       }
+
+       wassertr(table->delegate && table->delegate->numberOfRows);
+
+       table->rows = table->delegate->numberOfRows(table->delegate, table);
+
+       table->tableWidth = width + 1;
+
+       handleResize(table->view->delegate, table->view);
+}
dissimilarity index 80%
index 3bd78d7..9212fda 100644 (file)
-/*
- * Demo user widget for WINGs
- *
- * Author: Alfredo K. Kojima
- *
- * This file is in the public domain.
- *
- */
-
-
-/*
- *
- * Include the WINGs private data header.
- *
- *
- */
-#include <WINGs/WINGsP.h>
-
-/*
- * Our public header.
- */
-#include "mywidget.h"
-
-/*
- * Define the widget "class"
- */
-typedef struct W_MyWidget {
-    /* these two fields must be present in all your widgets in this
-     * exact position */
-    W_Class widgetClass;
-    WMView *view;
-
-    /* put your stuff here */
-    char *text;
-
-} _MyWidget;
-
-
-
-
-/* some forward declarations */
-
-static void destroyMyWidget(_MyWidget *mPtr);
-static void paintMyWidget(_MyWidget *mPtr);
-
-
-static void handleEvents(XEvent *event, void *data);
-static void handleActionEvents(XEvent *event, void *data);
-
-
-
-/*
- * Delegates
- * See the source for the other widgets to see how to use.
- * You won't need to use this most of the time.
- */
-static W_ViewDelegate _MyWidgetDelegate = {
-    NULL,
-    NULL,
-    NULL,
-    NULL,
-    NULL
-};
-
-
-/* our widget class ID */
-static W_Class myWidgetClass = 0;
-
-
-/*
- * Initializer for our widget. Must be called before creating any
- * instances of the widget.
- */
-W_Class
-InitMyWidget(WMScreen *scr)
-{
-    /* register our widget with WINGs and get our widget class ID */
-    if (!myWidgetClass) {
-        myWidgetClass = W_RegisterUserWidget();
-    }
-
-    return myWidgetClass;
-}
-
-
-/*
- * Our widget fabrication plant.
- */
-MyWidget*
-CreateMyWidget(WMWidget *parent)
-{
-    MyWidget *mPtr;
-
-    /* allocate some storage for our new widget instance */
-    mPtr = wmalloc(sizeof(MyWidget));
-    /* initialize it */
-    memset(mPtr, 0, sizeof(MyWidget));
-
-    /* set the class ID */
-    mPtr->widgetClass = myWidgetClass;
-
-    /*
-     * Create the view for our widget.
-     * Note: the Window for the view is only created after the view is
-     * realized with W_RealizeView()
-     *
-     * Consider the returned view as read-only.
-     */
-    mPtr->view = W_CreateView(W_VIEW(parent));
-    if (!mPtr->view) {
-        wfree(mPtr);
-        return NULL;
-    }
-    /* always do this */
-    mPtr->view->self = mPtr;
-
-    /* setup the delegates for the view */
-    mPtr->view->delegate = &_MyWidgetDelegate;
-
-    /*
-     * Intercept some events for our widget, so that we can handle them.
-     */
-    WMCreateEventHandler(mPtr->view, ExposureMask /* this allows us to know when we should paint */
-                         |StructureNotifyMask, /* this allows us to know things like when we are destroyed */
-                         handleEvents, mPtr);
-
-    /*
-     * Intercept some other events. This could be merged with the above
-     * call, but we separate for more organization.
-     */
-    WMCreateEventHandler(mPtr->view, ButtonPressMask,handleActionEvents, mPtr);
-
-    return mPtr;
-}
-
-
-
-/*
- * Paint our widget contents.
- */
-static void
-paintMyWidget(_MyWidget *mPtr)
-{
-    W_Screen *scr = mPtr->view->screen;
-    WMColor *color;
-
-
-    if (mPtr->text) {
-
-        color = WMWhiteColor(scr);
-
-        W_PaintText(mPtr->view, mPtr->view->window, scr->normalFont,  0, 0,
-                    mPtr->view->size.width, WACenter, color,
-                    False, mPtr->text, strlen(mPtr->text));
-
-        WMReleaseColor(color);
-    }
-}
-
-
-
-static void
-handleEvents(XEvent *event, void *data)
-{
-    _MyWidget *mPtr = (_MyWidget*)data;
-
-
-    switch (event->type) {
-    case Expose:
-        if (event->xexpose.count!=0)
-            break;
-        paintMyWidget(mPtr);
-        break;
-
-    case DestroyNotify:
-        destroyMyWidget(mPtr);
-        break;
-
-    }
-}
-
-
-static void
-handleActionEvents(XEvent *event, void *data)
-{
-    _MyWidget *mPtr = (_MyWidget*)data;
-
-    switch (event->type) {
-    case ButtonPress:
-        XBell(mPtr->view->screen->display, 100);
-        XBell(mPtr->view->screen->display, 100);
-        break;
-    }
-}
-
-
-void
-SetMyWidgetText(MyWidget *mPtr, char *text)
-{
-    CHECK_CLASS(mPtr, myWidgetClass);
-
-    if (mPtr->text)
-        wfree(mPtr->text);
-
-    mPtr->text = wstrdup(text);
-
-    if (W_VIEW_MAPPED(mPtr->view)) {
-        paintMyWidget(mPtr);
-    }
-}
-
-
-
-static void
-destroyMyWidget(_MyWidget *mPtr)
-{
-    /*
-     * Free all data we allocated for our widget.
-     */
-
-    if (mPtr->text)
-        wfree(mPtr->text);
-
-    wfree(mPtr);
-}
-
-
+/*
+ * Demo user widget for WINGs
+ *
+ * Author: Alfredo K. Kojima
+ *
+ * This file is in the public domain.
+ *
+ */
+
+/*
+ *
+ * Include the WINGs private data header.
+ *
+ *
+ */
+#include <WINGs/WINGsP.h>
+
+/*
+ * Our public header.
+ */
+#include "mywidget.h"
+
+/*
+ * Define the widget "class"
+ */
+typedef struct W_MyWidget {
+       /* these two fields must be present in all your widgets in this
+        * exact position */
+       W_Class widgetClass;
+       WMView *view;
+
+       /* put your stuff here */
+       char *text;
+
+} _MyWidget;
+
+/* some forward declarations */
+
+static void destroyMyWidget(_MyWidget * mPtr);
+static void paintMyWidget(_MyWidget * mPtr);
+
+static void handleEvents(XEvent * event, void *data);
+static void handleActionEvents(XEvent * event, void *data);
+
+/*
+ * Delegates
+ * See the source for the other widgets to see how to use.
+ * You won't need to use this most of the time.
+ */
+static W_ViewDelegate _MyWidgetDelegate = {
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL
+};
+
+/* our widget class ID */
+static W_Class myWidgetClass = 0;
+
+/*
+ * Initializer for our widget. Must be called before creating any
+ * instances of the widget.
+ */
+W_Class InitMyWidget(WMScreen * scr)
+{
+       /* register our widget with WINGs and get our widget class ID */
+       if (!myWidgetClass) {
+               myWidgetClass = W_RegisterUserWidget();
+       }
+
+       return myWidgetClass;
+}
+
+/*
+ * Our widget fabrication plant.
+ */
+MyWidget *CreateMyWidget(WMWidget * parent)
+{
+       MyWidget *mPtr;
+
+       /* allocate some storage for our new widget instance */
+       mPtr = wmalloc(sizeof(MyWidget));
+       /* initialize it */
+       memset(mPtr, 0, sizeof(MyWidget));
+
+       /* set the class ID */
+       mPtr->widgetClass = myWidgetClass;
+
+       /*
+        * Create the view for our widget.
+        * Note: the Window for the view is only created after the view is
+        * realized with W_RealizeView()
+        *
+        * Consider the returned view as read-only.
+        */
+       mPtr->view = W_CreateView(W_VIEW(parent));
+       if (!mPtr->view) {
+               wfree(mPtr);
+               return NULL;
+       }
+       /* always do this */
+       mPtr->view->self = mPtr;
+
+       /* setup the delegates for the view */
+       mPtr->view->delegate = &_MyWidgetDelegate;
+
+       /*
+        * Intercept some events for our widget, so that we can handle them.
+        */
+       WMCreateEventHandler(mPtr->view, ExposureMask   /* this allows us to know when we should paint */
+                            | StructureNotifyMask,     /* this allows us to know things like when we are destroyed */
+                            handleEvents, mPtr);
+
+       /*
+        * Intercept some other events. This could be merged with the above
+        * call, but we separate for more organization.
+        */
+       WMCreateEventHandler(mPtr->view, ButtonPressMask, handleActionEvents, mPtr);
+
+       return mPtr;
+}
+
+/*
+ * Paint our widget contents.
+ */
+static void paintMyWidget(_MyWidget * mPtr)
+{
+       W_Screen *scr = mPtr->view->screen;
+       WMColor *color;
+
+       if (mPtr->text) {
+
+               color = WMWhiteColor(scr);
+
+               W_PaintText(mPtr->view, mPtr->view->window, scr->normalFont, 0, 0,
+                           mPtr->view->size.width, WACenter, color, False, mPtr->text, strlen(mPtr->text));
+
+               WMReleaseColor(color);
+       }
+}
+
+static void handleEvents(XEvent * event, void *data)
+{
+       _MyWidget *mPtr = (_MyWidget *) data;
+
+       switch (event->type) {
+       case Expose:
+               if (event->xexpose.count != 0)
+                       break;
+               paintMyWidget(mPtr);
+               break;
+
+       case DestroyNotify:
+               destroyMyWidget(mPtr);
+               break;
+
+       }
+}
+
+static void handleActionEvents(XEvent * event, void *data)
+{
+       _MyWidget *mPtr = (_MyWidget *) data;
+
+       switch (event->type) {
+       case ButtonPress:
+               XBell(mPtr->view->screen->display, 100);
+               XBell(mPtr->view->screen->display, 100);
+               break;
+       }
+}
+
+void SetMyWidgetText(MyWidget * mPtr, char *text)
+{
+       CHECK_CLASS(mPtr, myWidgetClass);
+
+       if (mPtr->text)
+               wfree(mPtr->text);
+
+       mPtr->text = wstrdup(text);
+
+       if (W_VIEW_MAPPED(mPtr->view)) {
+               paintMyWidget(mPtr);
+       }
+}
+
+static void destroyMyWidget(_MyWidget * mPtr)
+{
+       /*
+        * Free all data we allocated for our widget.
+        */
+
+       if (mPtr->text)
+               wfree(mPtr->text);
+
+       wfree(mPtr);
+}
dissimilarity index 85%
index ad15868..3a271fd 100644 (file)
@@ -1,52 +1,46 @@
-
-
-#include <WINGs/WINGs.h>
-#include <stdlib.h>
-
-#include "mywidget.h"
-
-
-void
-wAbort()
-{
-    exit(1);
-}
-
-
-int main(int argc, char **argv)
-{
-    Display *dpy = XOpenDisplay("");
-    WMScreen *scr;
-    WMWindow *win;
-    MyWidget *thing;
-
-
-    WMInitializeApplication("Test", &argc, argv);
-
-    if (!dpy) {
-        wfatal("could not open display");
-        exit(1);
-    }
-
-    scr = WMCreateSimpleApplicationScreen(dpy);
-
-    /* init our widget */
-    InitMyWidget(scr);
-
-    win = WMCreateWindow(scr, "test");
-    WMResizeWidget(win, 150, 50);
-
-    thing = CreateMyWidget(win);
-    SetMyWidgetText(thing, "The Test");
-    WMResizeWidget(thing, 100, 20);
-    WMMoveWidget(thing, 10, 10);
-
-    WMRealizeWidget(win);
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-
-    WMScreenMainLoop(scr);
-
-    return 0;
-}
-
+
+#include <WINGs/WINGs.h>
+#include <stdlib.h>
+
+#include "mywidget.h"
+
+void wAbort()
+{
+       exit(1);
+}
+
+int main(int argc, char **argv)
+{
+       Display *dpy = XOpenDisplay("");
+       WMScreen *scr;
+       WMWindow *win;
+       MyWidget *thing;
+
+       WMInitializeApplication("Test", &argc, argv);
+
+       if (!dpy) {
+               wfatal("could not open display");
+               exit(1);
+       }
+
+       scr = WMCreateSimpleApplicationScreen(dpy);
+
+       /* init our widget */
+       InitMyWidget(scr);
+
+       win = WMCreateWindow(scr, "test");
+       WMResizeWidget(win, 150, 50);
+
+       thing = CreateMyWidget(win);
+       SetMyWidgetText(thing, "The Test");
+       WMResizeWidget(thing, 100, 20);
+       WMMoveWidget(thing, 10, 10);
+
+       WMRealizeWidget(win);
+       WMMapSubwidgets(win);
+       WMMapWidget(win);
+
+       WMScreenMainLoop(scr);
+
+       return 0;
+}
dissimilarity index 79%
index 1482ed5..f12362e 100644 (file)
-/*
- * Author: Len Trigg <trigg@cs.waikato.ac.nz>
- */
-
-/*
- Update: Franck Wolff <frawolff@club-internet.fr>
- -----------------------------------------------------------------------
- List of updated functions :
- - main :
- add -s option for a save panel...
- -----------------------------------------------------------------------
- */
-
-
-
-#include <WINGs/WINGs.h>
-
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "logo.xpm"
-
-
-
-
-void
-wAbort()
-{
-    exit(1);
-}
-
-char *ProgName;
-
-void usage(void)
-{
-    fprintf(stderr,
-            "usage:\n"
-            "\t%s [-options]\n"
-            "\n"
-            "options:\n"
-            "  -s\t\tSave panel (default open panel)\n"
-            "  -i <str>\tInitial directory (default /)\n"
-            "  -t <str>\tQuery window title (default none)\n"
-            "\n"
-            "information:\n"
-            "\t%s pops up a WindowMaker style file selection panel.\n"
-            "\n"
-            "version:\n"
-            "\t%s\n"
-            ,ProgName,ProgName,__DATE__
-           );
-    exit(0);
-}
-
-#define OPEN_PANEL_TYPE 0
-#define SAVE_PANEL_TYPE 1
-
-int main(int argc, char **argv)
-{
-    Display *dpy = XOpenDisplay("");
-    WMScreen *scr;
-    WMPixmap *pixmap;
-    WMOpenPanel *oPanel;
-    WMSavePanel *sPanel;
-    /*  RImage *image;*/
-    char *title = NULL;
-    char *initial = "/";
-    int ch;
-    int panelType = OPEN_PANEL_TYPE;
-    extern char *optarg;
-    extern int optind;
-
-    if (!dpy) {
-        puts("could not open display");
-        exit(1);
-    }
-
-    WMInitializeApplication("WMFile", &argc, argv);
-
-    ProgName = argv[0];
-
-    while((ch = getopt(argc, argv, "si:ht:")) != -1)
-        switch(ch)
-        {
-        case 's':
-            panelType = SAVE_PANEL_TYPE;
-            break;
-        case 'i':
-            initial = optarg;
-            break;
-        case 't':
-            title = optarg;
-            break;
-        default:
-            usage();
-        }
-
-    for(; optind <argc; optind++)
-        usage();
-
-    scr = WMCreateSimpleApplicationScreen(dpy);
-
-
-
-    pixmap = WMCreatePixmapFromXPMData(scr, GNUSTEP_XPM);
-    WMSetApplicationIconPixmap(scr, pixmap);
-    WMReleasePixmap(pixmap);
-    if (panelType == SAVE_PANEL_TYPE) {
-        sPanel = WMGetSavePanel(scr);
-        if (WMRunModalFilePanelForDirectory(sPanel, NULL, initial,
-                                            /*title*/ NULL, NULL) == True)
-            printf("%s\n", WMGetFilePanelFileName(sPanel));
-        else
-            printf("\n");
-    } else {
-        oPanel = WMGetOpenPanel(scr);
-        if (WMRunModalFilePanelForDirectory(oPanel, NULL, initial,
-                                            /*title*/ NULL, NULL) == True)
-            printf("%s\n", WMGetFilePanelFileName(oPanel));
-        else
-            printf("\n");
-    }
-    return 0;
-}
-
+/*
+ * Author: Len Trigg <trigg@cs.waikato.ac.nz>
+ */
+
+/*
+ Update: Franck Wolff <frawolff@club-internet.fr>
+ -----------------------------------------------------------------------
+ List of updated functions :
+ - main :
+ add -s option for a save panel...
+ -----------------------------------------------------------------------
+ */
+
+#include <WINGs/WINGs.h>
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "logo.xpm"
+
+void wAbort()
+{
+       exit(1);
+}
+
+char *ProgName;
+
+void usage(void)
+{
+       fprintf(stderr,
+               "usage:\n"
+               "\t%s [-options]\n"
+               "\n"
+               "options:\n"
+               "  -s\t\tSave panel (default open panel)\n"
+               "  -i <str>\tInitial directory (default /)\n"
+               "  -t <str>\tQuery window title (default none)\n"
+               "\n"
+               "information:\n"
+               "\t%s pops up a WindowMaker style file selection panel.\n"
+               "\n" "version:\n" "\t%s\n", ProgName, ProgName, __DATE__);
+       exit(0);
+}
+
+#define OPEN_PANEL_TYPE 0
+#define SAVE_PANEL_TYPE 1
+
+int main(int argc, char **argv)
+{
+       Display *dpy = XOpenDisplay("");
+       WMScreen *scr;
+       WMPixmap *pixmap;
+       WMOpenPanel *oPanel;
+       WMSavePanel *sPanel;
+       /*  RImage *image; */
+       char *title = NULL;
+       char *initial = "/";
+       int ch;
+       int panelType = OPEN_PANEL_TYPE;
+       extern char *optarg;
+       extern int optind;
+
+       if (!dpy) {
+               puts("could not open display");
+               exit(1);
+       }
+
+       WMInitializeApplication("WMFile", &argc, argv);
+
+       ProgName = argv[0];
+
+       while ((ch = getopt(argc, argv, "si:ht:")) != -1)
+               switch (ch) {
+               case 's':
+                       panelType = SAVE_PANEL_TYPE;
+                       break;
+               case 'i':
+                       initial = optarg;
+                       break;
+               case 't':
+                       title = optarg;
+                       break;
+               default:
+                       usage();
+               }
+
+       for (; optind < argc; optind++)
+               usage();
+
+       scr = WMCreateSimpleApplicationScreen(dpy);
+
+       pixmap = WMCreatePixmapFromXPMData(scr, GNUSTEP_XPM);
+       WMSetApplicationIconPixmap(scr, pixmap);
+       WMReleasePixmap(pixmap);
+       if (panelType == SAVE_PANEL_TYPE) {
+               sPanel = WMGetSavePanel(scr);
+               if (WMRunModalFilePanelForDirectory(sPanel, NULL, initial,
+                                                   /*title */ NULL, NULL) == True)
+                       printf("%s\n", WMGetFilePanelFileName(sPanel));
+               else
+                       printf("\n");
+       } else {
+               oPanel = WMGetOpenPanel(scr);
+               if (WMRunModalFilePanelForDirectory(oPanel, NULL, initial,
+                                                   /*title */ NULL, NULL) == True)
+                       printf("%s\n", WMGetFilePanelFileName(oPanel));
+               else
+                       printf("\n");
+       }
+       return 0;
+}
dissimilarity index 89%
index 22be0bb..dac7031 100644 (file)
-
-/*
- * Author: Len Trigg <trigg@cs.waikato.ac.nz>
- */
-
-
-#include <WINGs/WINGs.h>
-
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "logo.xpm"
-
-
-
-
-void
-wAbort()
-{
-    exit(1);
-}
-
-char *ProgName;
-
-void
-usage(void)
-{
-    fprintf(stderr,
-            "usage:\n"
-            "\t%s [-options]\n"
-            "\n"
-            "options:\n"
-            "  -i <str>\tInitial entry contents (default none)\n"
-            "  -p <str>\tPrompt message (default none)\n"
-            "  -t <str>\tQuery window title (default none)\n"
-            "\n"
-            "information:\n"
-            "\t%s pops up a WindowMaker style input panel.\n"
-            "\n"
-            "version:\n"
-            "\t%s\n"
-            ,ProgName,ProgName,__DATE__
-           );
-    exit(0);
-}
-
-int
-main(int argc, char **argv)
-{
-    Display *dpy = XOpenDisplay("");
-    WMScreen *scr;
-    WMPixmap *pixmap;
-    char *title = NULL;
-    char *prompt = NULL;
-    char *initial = NULL;
-    char *result = NULL;
-    int ch;
-    extern char *optarg;
-    extern int optind;
-
-    WMInitializeApplication("WMQuery", &argc, argv);
-
-    ProgName = argv[0];
-
-    if (!dpy) {
-        puts("could not open display");
-        exit(1);
-    }
-
-    while((ch = getopt(argc, argv, "i:hp:t:")) != -1)
-        switch(ch)
-        {
-        case 'i':
-            initial = optarg;
-            break;
-        case 'p':
-            prompt = optarg;
-            break;
-        case 't':
-            title = optarg;
-            break;
-        default:
-            usage();
-        }
-
-    for(; optind <argc; optind++)
-        usage();
-
-
-    scr = WMCreateSimpleApplicationScreen(dpy);
-
-    pixmap = WMCreatePixmapFromXPMData(scr, GNUSTEP_XPM);
-
-    WMSetApplicationIconPixmap(scr, pixmap); WMReleasePixmap(pixmap);
-
-    if ((result = WMRunInputPanel(scr, NULL, title, prompt, initial, "OK", "Cancel")) != NULL)
-        printf("%s\n", result);
-    else
-        printf("\n");
-    return 0;
-}
-
+
+/*
+ * Author: Len Trigg <trigg@cs.waikato.ac.nz>
+ */
+
+#include <WINGs/WINGs.h>
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "logo.xpm"
+
+void wAbort()
+{
+       exit(1);
+}
+
+char *ProgName;
+
+void usage(void)
+{
+       fprintf(stderr,
+               "usage:\n"
+               "\t%s [-options]\n"
+               "\n"
+               "options:\n"
+               "  -i <str>\tInitial entry contents (default none)\n"
+               "  -p <str>\tPrompt message (default none)\n"
+               "  -t <str>\tQuery window title (default none)\n"
+               "\n"
+               "information:\n"
+               "\t%s pops up a WindowMaker style input panel.\n"
+               "\n" "version:\n" "\t%s\n", ProgName, ProgName, __DATE__);
+       exit(0);
+}
+
+int main(int argc, char **argv)
+{
+       Display *dpy = XOpenDisplay("");
+       WMScreen *scr;
+       WMPixmap *pixmap;
+       char *title = NULL;
+       char *prompt = NULL;
+       char *initial = NULL;
+       char *result = NULL;
+       int ch;
+       extern char *optarg;
+       extern int optind;
+
+       WMInitializeApplication("WMQuery", &argc, argv);
+
+       ProgName = argv[0];
+
+       if (!dpy) {
+               puts("could not open display");
+               exit(1);
+       }
+
+       while ((ch = getopt(argc, argv, "i:hp:t:")) != -1)
+               switch (ch) {
+               case 'i':
+                       initial = optarg;
+                       break;
+               case 'p':
+                       prompt = optarg;
+                       break;
+               case 't':
+                       title = optarg;
+                       break;
+               default:
+                       usage();
+               }
+
+       for (; optind < argc; optind++)
+               usage();
+
+       scr = WMCreateSimpleApplicationScreen(dpy);
+
+       pixmap = WMCreatePixmapFromXPMData(scr, GNUSTEP_XPM);
+
+       WMSetApplicationIconPixmap(scr, pixmap);
+       WMReleasePixmap(pixmap);
+
+       if ((result = WMRunInputPanel(scr, NULL, title, prompt, initial, "OK", "Cancel")) != NULL)
+               printf("%s\n", result);
+       else
+               printf("\n");
+       return 0;
+}
dissimilarity index 94%
index 4ea87b7..bebef3b 100644 (file)
-/*
- * WINGs test application
- */
-
-#include <WINGs/WINGs.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-/*
- * You need to define this function to link any program to WINGs.
- * (this is no longer required as there is a default abort handler in WINGs)
- * This will be called when the application will be terminated because
- * of a fatal error (only for memory allocation failures ATM).
- */
-void
-wAbort()
-{
-    exit(1);
-}
-
-
-
-
-Display *dpy;
-
-int windowCount = 0;
-
-void
-closeAction(WMWidget *self, void *data)
-{
-    WMDestroyWidget(self);
-    windowCount--;
-    printf("window closed, window count = %d\n", windowCount);
-    if (windowCount < 1)
-        exit(0);
-}
-
-
-void
-testOpenFilePanel(WMScreen *scr)
-{
-    WMOpenPanel *panel;
-
-    /* windowCount++; */
-
-    /* get the shared Open File panel */
-    panel = WMGetOpenPanel(scr);
-
-    WMRunModalFilePanelForDirectory(panel, NULL, "/usr/local", NULL, NULL);
-
-    /* free the panel to save some memory. Not needed otherwise. */
-    WMFreeFilePanel(WMGetOpenPanel(scr));
-}
-
-
-void
-testFontPanel(WMScreen *scr)
-{
-    WMFontPanel *panel;
-
-    /*windowCount++;*/
-
-    panel = WMGetFontPanel(scr);
-
-    WMShowFontPanel(panel);
-
-    /*WMFreeFontPanel(panel);*/
-}
-
-
-
-void
-testFrame(WMScreen *scr)
-{
-    WMWindow *win;
-    WMFrame *frame;
-    int i;
-    static char* titles[] = {
-        "AboveTop",
-        "AtTop",
-        "BelowTop",
-        "AboveBottom",
-        "AtBottom",
-        "BelowBottom"
-    };
-    static WMTitlePosition pos[] = {
-        WTPAboveTop,
-        WTPAtTop,
-        WTPBelowTop,
-        WTPAboveBottom,
-        WTPAtBottom,
-        WTPBelowBottom
-    };
-
-    windowCount++;
-
-    win = WMCreateWindow(scr, "testFrame");
-    WMSetWindowTitle(win, "Frame");
-    WMSetWindowCloseAction(win, closeAction, NULL);
-    WMResizeWidget(win, 400, 300);
-
-    for (i = 0; i < 6; i++) {
-        frame = WMCreateFrame(win);
-        WMMoveWidget(frame, 8+(i%3)*130, 8+(i/3)*130);
-        WMResizeWidget(frame, 120, 120);
-        WMSetFrameTitle(frame, titles[i]);
-        WMSetFrameTitlePosition(frame, pos[i]);
-    }
-
-    WMRealizeWidget(win);
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-
-}
-
-
-/*static void
- resizedWindow(void *self, WMNotification *notif)
- {
- WMView *view = (WMView*)WMGetNotificationObject(notif);
- WMSize size = WMGetViewSize(view);
-
- WMResizeWidget((WMWidget*)self, size.width, size.height);
- }*/
-
-void
-testBox(WMScreen *scr)
-{
-    WMWindow *win;
-    WMBox *box, *hbox;
-    WMButton *btn;
-    WMPopUpButton *pop;
-    int i;
-
-    windowCount++;
-
-    win = WMCreateWindow(scr, "testBox");
-    WMSetWindowTitle(win, "Box");
-    WMSetWindowCloseAction(win, closeAction, NULL);
-    WMResizeWidget(win, 400, 300);
-
-    box = WMCreateBox(win);
-    WMSetBoxBorderWidth(box, 5);
-    WMSetViewExpandsToParent(WMWidgetView(box), 0, 0, 0, 0);
-
-    /*WMSetBoxHorizontal(box, True);*/
-    for (i = 0; i < 4; i++) {
-        btn = WMCreateCommandButton(box);
-        WMSetButtonText(btn, "bla");
-        WMMapWidget(btn);
-        WMAddBoxSubview(box, WMWidgetView(btn), i&1, True, 20, 0, 5);
-    }
-
-    pop = WMCreatePopUpButton(box);
-    WMAddPopUpButtonItem(pop, "ewqeq");
-    WMAddPopUpButtonItem(pop, "ewqeqrewrw");
-    WMAddBoxSubview(box, WMWidgetView(pop), False, True, 20, 0, 5);
-    WMMapWidget(pop);
-
-    hbox = WMCreateBox(box);
-    WMSetBoxHorizontal(hbox, True);
-    WMAddBoxSubview(box, WMWidgetView(hbox), False, True, 24, 0, 0);
-    WMMapWidget(hbox);
-
-    for (i = 0; i < 4; i++) {
-        btn = WMCreateCommandButton(hbox);
-        WMSetButtonText(btn, "bla");
-        WMMapWidget(btn);
-        WMAddBoxSubview(hbox, WMWidgetView(btn), 1, True, 60, 0, i<3?5:0);
-    }
-
-
-    WMRealizeWidget(win);
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-
-}
-
-
-
-static void
-singleClick(WMWidget *self, void *data)
-{
-}
-
-
-static void
-doubleClick(WMWidget *self, void *data)
-{
-    WMSelectAllListItems((WMList*)self);
-}
-
-
-static void
-listSelectionObserver(void *observer, WMNotification *notification)
-{
-    WMLabel *label = (WMLabel*)observer;
-    WMList *lPtr = (WMList*)WMGetNotificationObject(notification);
-    char buf[255];
-
-    sprintf(buf, "Selected items: %d",
-            WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));
-    WMSetLabelText(label, buf);
-}
-
-
-void
-testList(WMScreen *scr)
-{
-    WMWindow *win;
-    WMList *list;
-    WMList *mlist;
-    WMLabel *label;
-    WMLabel *mlabel;
-    WMLabel *title;
-    WMLabel *mtitle;
-    char text[100];
-    int i;
-
-    windowCount++;
-
-    win = WMCreateWindow(scr, "testList");
-    WMResizeWidget(win, 370, 250);
-    WMSetWindowTitle(win, "List");
-    WMSetWindowCloseAction(win, closeAction, NULL);
-
-    title = WMCreateLabel(win);
-    WMResizeWidget(title, 150, 20);
-    WMMoveWidget(title, 10, 10);
-    WMSetLabelRelief(title, WRRidge);
-    WMSetLabelText(title, "Single selection list");
-
-    mtitle = WMCreateLabel(win);
-    WMResizeWidget(mtitle, 150, 20);
-    WMMoveWidget(mtitle, 210, 10);
-    WMSetLabelRelief(mtitle, WRRidge);
-    WMSetLabelText(mtitle, "Multiple selection list");
-
-    list = WMCreateList(win);
-    /*WMSetListAllowEmptySelection(list, True);*/
-    WMMoveWidget(list, 10, 40);
-    for (i=0; i<105; i++) {
-        sprintf(text, "Item %i", i);
-        WMAddListItem(list, text);
-    }
-    mlist = WMCreateList(win);
-    WMSetListAllowMultipleSelection(mlist, True);
-    /*WMSetListAllowEmptySelection(mlist, True);*/
-    WMMoveWidget(mlist, 210, 40);
-    for (i=0; i<135; i++) {
-        sprintf(text, "Item %i", i);
-        WMAddListItem(mlist, text);
-    }
-
-    label = WMCreateLabel(win);
-    WMResizeWidget(label, 150, 40);
-    WMMoveWidget(label, 10, 200);
-    WMSetLabelRelief(label, WRRidge);
-    WMSetLabelText(label, "Selected items: 0");
-
-    mlabel = WMCreateLabel(win);
-    WMResizeWidget(mlabel, 150, 40);
-    WMMoveWidget(mlabel, 210, 200);
-    WMSetLabelRelief(mlabel, WRRidge);
-    WMSetLabelText(mlabel, "Selected items: 0");
-
-    WMSetListAction(list, singleClick, label);
-    WMSetListDoubleAction(list, doubleClick, label);
-    WMSetListAction(mlist, singleClick, mlabel);
-    WMSetListDoubleAction(mlist, doubleClick, mlabel);
-
-    WMAddNotificationObserver(listSelectionObserver, label,
-                              WMListSelectionDidChangeNotification, list);
-    WMAddNotificationObserver(listSelectionObserver, mlabel,
-                              WMListSelectionDidChangeNotification, mlist);
-
-
-    WMRealizeWidget(win);
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-}
-
-
-void
-testButton(WMScreen *scr)
-{
-    WMWindow *win;
-    int i;
-    char *types[] = {
-        "MomentaryPush",
-        "PushOnPushOff",
-        "Toggle",
-        "Switch",
-        "Radio",
-        "MomentaryChange",
-        "OnOff",
-        "MomentaryLigh"
-    };
-
-    windowCount++;
-
-    win = WMCreateWindow(scr, "testButton");
-    WMResizeWidget(win, 300, 300);
-    WMSetWindowTitle(win, "Buttons");
-
-    WMSetWindowCloseAction(win, closeAction, NULL);
-
-    for (i = 1; i < 9; i++) {
-        WMButton *b;
-        b = WMCreateButton(win, i);
-        WMResizeWidget(b, 150, 24);
-        WMMoveWidget(b, 20, i*30);
-        WMSetButtonText(b, types[i-1]);
-    }
-
-    WMRealizeWidget(win);
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-}
-
-
-void
-testGradientButtons(WMScreen *scr)
-{
-    WMWindow *win;
-    WMButton *btn;
-    WMPixmap *pix1, *pix2;
-    RImage *back;
-    RColor light, dark;
-    WMColor *color, *altColor;
-
-    windowCount++;
-
-    /* creates the top-level window */
-    win = WMCreateWindow(scr, "testGradientButtons");
-    WMSetWindowTitle(win, "Gradiented Button Demo");
-    WMResizeWidget(win, 300, 200);
-
-    WMSetWindowCloseAction(win, closeAction, NULL);
-
-
-    light.red = 0x90;
-    light.green = 0x85;
-    light.blue = 0x90;
-    dark.red = 0x35;
-    dark.green = 0x30;
-    dark.blue = 0x35;
-
-    color = WMCreateRGBColor(scr, 0x5900, 0x5100, 0x5900, True);
-    WMSetWidgetBackgroundColor(win, color);
-    WMReleaseColor(color);
-
-    back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
-    RBevelImage(back, RBEV_RAISED2);
-    pix1 = WMCreatePixmapFromRImage(scr, back, 0);
-    RReleaseImage(back);
-
-    back = RRenderGradient(60, 24, &dark, &light, RGRD_DIAGONAL);
-    RBevelImage(back, RBEV_SUNKEN);
-    pix2 = WMCreatePixmapFromRImage(scr, back, 0);
-    RReleaseImage(back);
-
-    color = WMWhiteColor(scr);
-    altColor = WMCreateNamedColor(scr, "red", True);
-
-    btn = WMCreateButton(win, WBTMomentaryChange);
-    WMResizeWidget(btn, 60, 24);
-    WMMoveWidget(btn, 20, 100);
-    WMSetButtonBordered(btn, False);
-    WMSetButtonImagePosition(btn, WIPOverlaps);
-    WMSetButtonImage(btn, pix1);
-    WMSetButtonAltImage(btn, pix2);
-    WMSetButtonText(btn, "Cool");
-    WMSetButtonTextColor(btn, color);
-    WMSetButtonAltTextColor(btn, altColor);
-
-    WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
-
-    btn = WMCreateButton(win, WBTMomentaryChange);
-    WMResizeWidget(btn, 60, 24);
-    WMMoveWidget(btn, 90, 100);
-    WMSetButtonBordered(btn, False);
-    WMSetButtonImagePosition(btn, WIPOverlaps);
-    WMSetButtonImage(btn, pix1);
-    WMSetButtonAltImage(btn, pix2);
-    WMSetButtonText(btn, "Button");
-    WMSetButtonTextColor(btn, color);
-
-    WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
-
-    WMReleaseColor(color);
-    color = WMCreateNamedColor(scr, "orange", True);
-
-    btn = WMCreateButton(win, WBTMomentaryChange);
-    WMResizeWidget(btn, 60, 24);
-    WMMoveWidget(btn, 160, 100);
-    WMSetButtonBordered(btn, False);
-    WMSetButtonImagePosition(btn, WIPOverlaps);
-    WMSetButtonImage(btn, pix1);
-    WMSetButtonAltImage(btn, pix2);
-    WMSetButtonText(btn, "Test");
-    WMSetButtonTextColor(btn, color);
-
-    WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
-                            WMWidgetView(btn));
-
-    WMReleaseColor(color);
-    WMReleaseColor(altColor);
-
-    WMRealizeWidget(win);
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-}
-
-
-void
-testScrollView(WMScreen *scr)
-{
-    WMWindow *win;
-    WMScrollView *sview;
-    WMFrame *f;
-    WMLabel *l;
-    char buffer[128];
-    int i;
-
-    windowCount++;
-
-    /* creates the top-level window */
-    win = WMCreateWindow(scr, "testScroll");
-    WMSetWindowTitle(win, "Scrollable View");
-
-    WMSetWindowCloseAction(win, closeAction, NULL);
-
-    /* set the window size */
-    WMResizeWidget(win, 300, 300);
-
-    /* creates a scrollable view inside the top-level window */
-    sview = WMCreateScrollView(win);
-    WMResizeWidget(sview, 200, 200);
-    WMMoveWidget(sview, 30, 30);
-    WMSetScrollViewRelief(sview, WRSunken);
-    WMSetScrollViewHasVerticalScroller(sview, True);
-    WMSetScrollViewHasHorizontalScroller(sview, True);
-
-    /* create a frame with a bunch of labels */
-    f = WMCreateFrame(win);
-    WMResizeWidget(f, 400, 400);
-    WMSetFrameRelief(f, WRFlat);
-
-    for (i=0; i<20; i++) {
-        l = WMCreateLabel(f);
-        WMResizeWidget(l, 50, 18);
-        WMMoveWidget(l, 10, 20*i);
-        sprintf(buffer, "Label %i", i);
-        WMSetLabelText(l, buffer);
-        WMSetLabelRelief(l, WRSimple);
-    }
-    WMMapSubwidgets(f);
-    WMMapWidget(f);
-
-    WMSetScrollViewContentView(sview, WMWidgetView(f));
-
-    /* make the windows of the widgets be actually created */
-    WMRealizeWidget(win);
-
-    /* Map all child widgets of the top-level be mapped.
-     * You must call this for each container widget (like frames),
-     * even if they are childs of the top-level window.
-     */
-    WMMapSubwidgets(win);
-
-    /* map the top-level window */
-    WMMapWidget(win);
-}
-
-
-void
-testColorWell(WMScreen *scr)
-{
-    WMWindow *win;
-    WMColorWell *well1, *well2;
-
-    windowCount++;
-
-    win = WMCreateWindow(scr, "testColor");
-    WMResizeWidget(win, 300, 300);
-    WMSetWindowCloseAction(win, closeAction, NULL);
-
-    well1 = WMCreateColorWell(win);
-    WMResizeWidget(well1, 60, 40);
-    WMMoveWidget(well1, 100, 100);
-    WMSetColorWellColor(well1, WMCreateRGBColor(scr, 0x8888, 0, 0x1111, True));
-    well2 = WMCreateColorWell(win);
-    WMResizeWidget(well2, 60, 40);
-    WMMoveWidget(well2, 200, 100);
-    WMSetColorWellColor(well2, WMCreateRGBColor(scr, 0, 0, 0x8888, True));
-
-    WMRealizeWidget(win);
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-}
-
-
-void
-testColorPanel(WMScreen *scr)
-{
-    WMColorPanel *panel = WMGetColorPanel(scr);
-
-    /*if (colorname) {
-     startcolor = WMCreateNamedColor(scr, colorname, False);
-     WMSetColorPanelColor(panel, startcolor);
-     WMReleaseColor(startcolor);
-     }*/
-
-    WMShowColorPanel(panel);
-}
-
-void
-sliderCallback(WMWidget *w, void *data)
-{
-    printf("SLIDER == %i\n", WMGetSliderValue(w));
-}
-
-
-void
-testSlider(WMScreen *scr)
-{
-    WMWindow *win;
-    WMSlider *s;
-
-    windowCount++;
-
-    win = WMCreateWindow(scr, "testSlider");
-    WMResizeWidget(win, 300, 300);
-    WMSetWindowTitle(win, "Sliders");
-
-    WMSetWindowCloseAction(win, closeAction, NULL);
-
-    s = WMCreateSlider(win);
-    WMResizeWidget(s, 16, 100);
-    WMMoveWidget(s, 100, 100);
-    WMSetSliderKnobThickness(s, 8);
-    WMSetSliderContinuous(s, False);
-    WMSetSliderAction(s, sliderCallback, s);
-
-    s = WMCreateSlider(win);
-    WMResizeWidget(s, 100, 16);
-    WMMoveWidget(s, 100, 10);
-    WMSetSliderKnobThickness(s, 8);
-
-    WMRealizeWidget(win);
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-}
-
-
-void
-testTextField(WMScreen *scr)
-{
-    WMWindow *win;
-    WMTextField *field, *field2;
-
-    windowCount++;
-
-    win = WMCreateWindow(scr, "testTextField");
-    WMResizeWidget(win, 400, 300);
-
-    WMSetWindowCloseAction(win, closeAction, NULL);
-
-    field = WMCreateTextField(win);
-    WMResizeWidget(field, 200, 20);
-    WMMoveWidget(field, 20, 20);
-    WMSetTextFieldText(field, "the little \xc2\xa9 sign");
-
-    field2 = WMCreateTextField(win);
-    WMResizeWidget(field2, 200, 20);
-    WMMoveWidget(field2, 20, 50);
-    WMSetTextFieldAlignment(field2, WARight);
-
-    WMRealizeWidget(win);
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-
-}
-
-
-void
-testText(WMScreen *scr)
-{
-    WMWindow *win;
-    WMText *text;
-    WMFont *font;
-    void *tb;
-    FILE *file = fopen("wm.html", "rb");
-
-    windowCount++;
-
-    win = WMCreateWindow(scr, "testText");
-    WMResizeWidget(win, 500, 300);
-
-    WMSetWindowCloseAction(win, closeAction, NULL);
-
-    text = WMCreateText(win);
-    WMResizeWidget(text, 480, 280);
-    WMMoveWidget(text, 10, 10);
-    WMSetTextHasVerticalScroller(text, True);
-    WMSetTextEditable(text, False);
-    WMSetTextIgnoresNewline(text, False);
-
-#define FNAME "Verdana,Luxi Sans:pixelsize=12"
-#define MSG \
-    "Window Maker is the GNU window manager for the " \
-    "X Window System. It was designed to emulate the " \
-    "look and feel of part of the NEXTSTEP(tm) GUI. It's " \
-    "supposed to be relatively fast and small, feature " \
-    "rich, easy to configure and easy to use, with a simple " \
-    "and elegant appearance borrowed from NEXTSTEP(tm)."
-
-    font = WMCreateFont(scr, FNAME":autohint=false");
-    WMSetTextDefaultFont(text, font);
-    WMReleaseFont(font);
-
-    if (0 && file) {
-        char buf[1024];
-
-        WMFreezeText(text);
-        while(fgets(buf, 1023, file))
-            WMAppendTextStream(text, buf);
-
-        fclose(file);
-        WMThawText(text);
-    } else {
-        WMAppendTextStream(text, "First paragraph has autohinting turned off, "
-                           "while the second has it turned on:");
-        WMAppendTextStream(text, "\n\n\n");
-        WMAppendTextStream(text, MSG);
-        WMAppendTextStream(text, "\n\n\n");
-        font = WMCreateFont(scr, FNAME":autohint=true");
-        tb = WMCreateTextBlockWithText(text, MSG, font, WMBlackColor(scr),
-                                       0, strlen(MSG));
-        WMAppendTextBlock(text, tb);
-        WMReleaseFont(font);
-    }
-
-    WMRealizeWidget(win);
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-}
-
-
-void
-testProgressIndicator(WMScreen *scr)
-{
-    WMWindow *win;
-    WMProgressIndicator *pPtr;
-
-    windowCount++;
-
-    win = WMCreateWindow(scr, "testProgressIndicator");
-    WMResizeWidget(win, 292, 32);
-
-    WMSetWindowCloseAction(win, closeAction, NULL);
-
-    pPtr = WMCreateProgressIndicator(win);
-    WMMoveWidget(pPtr, 8, 8);
-    WMSetProgressIndicatorValue(pPtr, 75);
-
-    WMRealizeWidget(win);
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-
-}
-
-
-void
-testPullDown(WMScreen *scr)
-{
-    WMWindow *win;
-    WMPopUpButton *pop, *pop2;
-
-    windowCount++;
-
-    win = WMCreateWindow(scr, "pullDown");
-    WMResizeWidget(win, 400, 300);
-
-    WMSetWindowCloseAction(win, closeAction, NULL);
-
-    pop = WMCreatePopUpButton(win);
-    WMResizeWidget(pop, 100, 20);
-    WMMoveWidget(pop, 50, 60);
-    WMSetPopUpButtonPullsDown(pop, True);
-    WMSetPopUpButtonText(pop, "Commands");
-    WMAddPopUpButtonItem(pop, "Add");
-    WMAddPopUpButtonItem(pop, "Remove");
-    WMAddPopUpButtonItem(pop, "Check");
-    WMAddPopUpButtonItem(pop, "Eat");
-
-    pop2 = WMCreatePopUpButton(win);
-    WMResizeWidget(pop2, 100, 20);
-    WMMoveWidget(pop2, 200, 60);
-    WMSetPopUpButtonText(pop2, "Select");
-    WMAddPopUpButtonItem(pop2, "Apples");
-    WMAddPopUpButtonItem(pop2, "Bananas");
-    WMAddPopUpButtonItem(pop2, "Strawberries");
-    WMAddPopUpButtonItem(pop2, "Blueberries");
-
-    WMRealizeWidget(win);
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-
-}
-
-
-void
-testTabView(WMScreen *scr)
-{
-    WMWindow *win;
-    WMTabView *tabv;
-    WMTabViewItem *tab;
-    WMFrame *frame;
-    WMLabel *label;
-
-    windowCount++;
-
-    win = WMCreateWindow(scr, "testTabs");
-    WMResizeWidget(win, 400, 300);
-
-    WMSetWindowCloseAction(win, closeAction, NULL);
-
-    tabv = WMCreateTabView(win);
-    WMMoveWidget(tabv, 50, 50);
-    WMResizeWidget(tabv, 300, 200);
-
-    frame = WMCreateFrame(win);
-    WMSetFrameRelief(frame, WRFlat);
-    label = WMCreateLabel(frame);
-    WMResizeWidget(label, 100, 100);
-    WMSetLabelText(label, "Label 1");
-    WMMapWidget(label);
-
-
-    tab = WMCreateTabViewItemWithIdentifier(0);
-    WMSetTabViewItemView(tab, WMWidgetView(frame));
-    WMAddItemInTabView(tabv, tab);
-    WMSetTabViewItemLabel(tab, "Instances");
-
-    frame = WMCreateFrame(win);
-    WMSetFrameRelief(frame, WRFlat);
-    label = WMCreateLabel(frame);
-    WMResizeWidget(label, 40, 50);
-    WMSetLabelText(label, "Label 2");
-    WMMapWidget(label);
-
-
-    tab = WMCreateTabViewItemWithIdentifier(0);
-    WMSetTabViewItemView(tab, WMWidgetView(frame));
-    WMAddItemInTabView(tabv, tab);
-    WMSetTabViewItemLabel(tab, "Classes");
-
-
-    frame = WMCreateFrame(win);
-    WMSetFrameRelief(frame, WRFlat);
-    label = WMCreateLabel(frame);
-    WMResizeWidget(label, 100, 100);
-    WMMoveWidget(label, 60, 40);
-    WMSetLabelText(label, "Label 3");
-    WMMapWidget(label);
-
-    tab = WMCreateTabViewItemWithIdentifier(0);
-    WMSetTabViewItemView(tab, WMWidgetView(frame));
-    WMAddItemInTabView(tabv, tab);
-    WMSetTabViewItemLabel(tab, "Something");
-
-
-    frame = WMCreateFrame(win);
-    WMSetFrameRelief(frame, WRFlat);
-    label = WMCreateLabel(frame);
-    WMResizeWidget(label, 100, 100);
-    WMMoveWidget(label, 160, 40);
-    WMSetLabelText(label, "Label 4");
-    WMMapWidget(label);
-
-    tab = WMCreateTabViewItemWithIdentifier(0);
-    WMSetTabViewItemView(tab, WMWidgetView(frame));
-    WMAddItemInTabView(tabv, tab);
-    WMSetTabViewItemLabel(tab, "Bla!");
-
-
-
-    frame = WMCreateFrame(win);
-    WMSetFrameRelief(frame, WRFlat);
-    label = WMCreateLabel(frame);
-    WMResizeWidget(label, 100, 100);
-    WMMoveWidget(label, 160, 40);
-    WMSetLabelText(label, "Label fjweqklrj qwl");
-    WMMapWidget(label);
-    tab = WMCreateTabViewItemWithIdentifier(0);
-    WMSetTabViewItemView(tab, WMWidgetView(frame));
-    WMAddItemInTabView(tabv, tab);
-    WMSetTabViewItemLabel(tab, "Weee!");
-
-
-    WMRealizeWidget(win);
-    WMMapSubwidgets(win);
-    WMMapWidget(win);
-}
-
-
-void
-splitViewConstrainProc(WMSplitView *sPtr, int indView,
-                       int *minSize, int *maxSize)
-{
-    switch (indView) {
-    case 0:
-        *minSize = 20;
-        break;
-    case 1:
-        *minSize = 40;
-        *maxSize = 80;
-        break;
-    case 2:
-        *maxSize = 60;
-        break;
-    default:
-        break;
-    }
-}
-
-
-static void
-resizeSplitView(XEvent *event, void *data)
-{
-    WMSplitView *sPtr = (WMSplitView*)data;
-
-    if (event->type == ConfigureNotify) {
-        int width = event->xconfigure.width - 10;
-
-        if (width < WMGetSplitViewDividerThickness(sPtr))
-            width = WMGetSplitViewDividerThickness(sPtr);
-
-        if (width != WMWidgetWidth(sPtr) ||
-            event->xconfigure.height != WMWidgetHeight(sPtr))
-            WMResizeWidget(sPtr, width, event->xconfigure.height - 55);
-    }
-}
-
-void
-appendSubviewButtonAction(WMWidget *self, void *data)
-{
-    WMSplitView *sPtr = (WMSplitView*)data;
-    char buf[64];
-    WMLabel *label = WMCreateLabel(sPtr);
-
-    sprintf(buf, "Subview %d", WMGetSplitViewSubviewsCount(sPtr) + 1);
-    WMSetLabelText(label, buf);
-    WMSetLabelRelief(label, WRSunken);
-    WMAddSplitViewSubview(sPtr, WMWidgetView(label));
-    WMRealizeWidget(label);
-    WMMapWidget(label);
-}
-
-void
-removeSubviewButtonAction(WMWidget *self, void *data)
-{
-    WMSplitView *sPtr = (WMSplitView*)d