home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / slfinsta.zip / dw.c next >
C/C++ Source or Header  |  2000-03-27  |  36KB  |  1,311 lines

  1. /* $Id: dw.c,v 1.2 2000/03/27 19:04:07 bsmith Exp $ */
  2.  
  3. /*
  4.  * Dynamic Windows:
  5.  *          A GTK like implementation of the PM GUI
  6.  *
  7.  * (C) 2000 Brian Smith <dbsoft@technologist.com>
  8.  * (C) 2000 Achim Hasenmueller <achimha@innotek.de>
  9.  *
  10.  */
  11. #define INCL_DOS
  12. #define INCL_WIN
  13. #define INCL_GPI
  14.  
  15. #include <os2.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <stdio.h>
  19. #include <io.h>
  20. #include "dw.h"
  21.  
  22. #define QWP_USER 0
  23.  
  24. char ClassName[] = "dynamicwindows";
  25.  
  26. /* this is the callback handle for the window procedure */
  27. /* make sure you always match the calling convention! */
  28. int (* EXPENTRY filterfunc)(HWND, ULONG, MPARAM, MPARAM) = 0L;
  29.  
  30. HAB dwhab = 0;
  31. HMQ dwhmq = 0;
  32.  
  33. #ifdef DEBUG
  34. FILE *f;
  35.  
  36. void reopen(void)
  37. {
  38.     fclose(f);
  39.     f = fopen("dw.log", "at");
  40. }
  41. #endif
  42.  
  43. /* This function calculates how much space the widgets and boxes require
  44.  * and does expansion as necessary.
  45.  */
  46. int _resize_box(Box *thisbox, int *depth, int x, int y, int *usedx, int *usedy,
  47.                 int pass, int *usedpadx, int *usedpady)
  48. {
  49.     int z, currentx = 0, currenty = 0;
  50.     int vectorx = 0, vectory = 0;
  51.     int uymax = 0, uxmax = 0;
  52.     int upymax = 0, upxmax = 0;
  53.     /* Used for the SIZEEXPAND */
  54.     int nux = *usedx, nuy = *usedy;
  55.     int nupx = *usedpadx, nupy = *usedpady;
  56.  
  57.  
  58.     (*usedx) += (thisbox->pad * 2);
  59.     (*usedy) += (thisbox->pad * 2);
  60.  
  61.     for(z=0;z<thisbox->count;z++)
  62.     {
  63.         if(thisbox->items[z].type == TYPEBOX)
  64.         {
  65.             int initialx, initialy;
  66.             Box *tmp = WinQueryWindowPtr(thisbox->items[z].hwnd, QWP_USER);
  67.  
  68.             initialx = x - (*usedx);
  69.             initialy = y - (*usedy);
  70.  
  71.             if(tmp)
  72.             {
  73.                 int newx, newy;
  74.                 int nux = *usedx, nuy = *usedy;
  75.                 int upx = *usedpadx + (tmp->pad*2), upy = *usedpady + (tmp->pad*2);
  76.  
  77.                 /* On the second pass we know how big the box needs to be and how
  78.                  * much space we have, so we can calculate a ratio for the new box.
  79.                  */
  80.                 if(pass == 2)
  81.                 {
  82.                     int deep = *depth + 1;
  83.  
  84.                     _resize_box(tmp, &deep, x, y, &nux, &nuy, 1, &upx, &upy);
  85.  
  86.                     tmp->upx = upx - *usedpadx;
  87.                     tmp->upy = upy - *usedpady;
  88.  
  89.                     newx = x - nux;
  90.                     newy = y - nuy;
  91.  
  92.                     tmp->width = thisbox->items[z].width = initialx - newx;
  93.                     tmp->height = thisbox->items[z].height = initialy - newy;
  94.  
  95.                     tmp->parentxratio = thisbox->xratio;
  96.                     tmp->parentyratio = thisbox->yratio;
  97.  
  98.                     tmp->parentpad = tmp->pad;
  99.  
  100.                     /* Just in case */
  101.                     tmp->xratio = thisbox->xratio;
  102.                     tmp->yratio = thisbox->yratio;
  103.  
  104. #ifdef DEBUG
  105.                     if(pass > 1)
  106.                     {
  107.                         fprintf(f, "FARK! depth %d\r\nwidth = %d, height = %d, nux = %d, nuy = %d, upx = %d, upy = %d xratio = %f, yratio = %f\r\n\r\n",
  108.                                 *depth, thisbox->items[z].width, thisbox->items[z].height, nux, nuy, tmp->upx, tmp->upy, tmp->xratio, tmp->yratio);
  109.                         reopen();
  110.                     }
  111. #endif
  112.                     if(thisbox->type == BOXVERT)
  113.                     {
  114.                         if((thisbox->items[z].width-((thisbox->items[z].pad*2)+(tmp->pad*2)))!=0)
  115.                             tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-((thisbox->items[z].pad*2)+(tmp->pad*2))))/((float)(thisbox->items[z].width-((thisbox->items[z].pad*2)+(tmp->pad*2))));
  116.                     }
  117.                     else
  118.                     {
  119.                         if((thisbox->items[z].width-tmp->upx)!=0)
  120.                             tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-tmp->upx))/((float)(thisbox->items[z].width-tmp->upx));
  121.                     }
  122.                     if(thisbox->type == BOXHORZ)
  123.                     {
  124.                         if((thisbox->items[z].height-((thisbox->items[z].pad*2)+(tmp->pad*2)))!=0)
  125.                             tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-((thisbox->items[z].pad*2)+(tmp->pad*2))))/((float)(thisbox->items[z].height-((thisbox->items[z].pad*2)+(tmp->pad*2))));
  126.                     }
  127.                     else
  128.                     {
  129.                         if((thisbox->items[z].height-tmp->upy)!=0)
  130.                             tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmp->upy))/((float)(thisbox->items[z].height-tmp->upy));
  131.                     }
  132.  
  133.                     nux = *usedx; nuy = *usedy;
  134.                     upx = *usedpadx + (tmp->pad*2); upy = *usedpady + (tmp->pad*2);
  135.                 }
  136.  
  137.                 (*depth)++;
  138.  
  139. #ifdef DEBUG
  140.                 if(pass > 1)
  141.                 {
  142.                     fprintf(f, "Before Resize Box depth %d\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d xratio = %f, yratio = %f\r\n\r\n",
  143.                             *depth, x, y, *usedx, *usedy, *usedpadx, *usedpady, tmp->xratio, tmp->yratio);
  144.                     reopen();
  145.                 }
  146. #endif
  147.  
  148.                 _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &upx, &upy);
  149.  
  150.                 (*depth)--;
  151.  
  152.                 newx = x - nux;
  153.                 newy = y - nuy;
  154.  
  155.                 tmp->minwidth = thisbox->items[z].width = initialx - newx;
  156.                 tmp->minheight = thisbox->items[z].height = initialy - newy;
  157.  
  158. #ifdef DEBUG
  159.                 if(pass > 1)
  160.                 {
  161.                     fprintf(f, "After Resize Box depth %d\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d width = %d, height = %d\r\n\r\n",
  162.                             *depth, x, y, *usedx, *usedy, *usedpadx, *usedpady, thisbox->items[z].width, thisbox->items[z].height);
  163.                     reopen();
  164.                 }
  165. #endif
  166.             }
  167.         }
  168.  
  169.         if(pass > 1 && *depth > 0)
  170.         {
  171.             if(thisbox->type == BOXVERT)
  172.                 thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))))/((float)(thisbox->minwidth-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))));
  173.             else
  174.                 thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-thisbox->upx))/((float)(thisbox->minwidth-thisbox->upx));
  175.  
  176.             if(thisbox->type == BOXHORZ)
  177.                 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))))/((float)(thisbox->minheight-((thisbox->items[z].pad*2)+(thisbox->parentpad*2))));
  178.             else
  179.                 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-thisbox->upy))/((float)(thisbox->minheight-thisbox->upy));
  180. #ifdef DEBUG
  181.             fprintf(f, "RATIO- xratio = %f, yratio = %f, width = %d, height = %d, pad = %d, box xratio = %f, box yratio = %f, parent xratio = %f, parent yratio = %f, minwidth = %d, minheight = %d, width = %d, height = %d, upx = %d, upy = %d\r\n\r\n",
  182.                     thisbox->items[z].xratio, thisbox->items[z].yratio, thisbox->items[z].width, thisbox->items[z].height, thisbox->items[z].pad, thisbox->xratio, thisbox->yratio, thisbox->parentxratio, thisbox->parentyratio, thisbox->minwidth, thisbox->minheight, thisbox->width, thisbox->height, thisbox->upx, thisbox->upy);
  183.             reopen();
  184. #endif                                                                                                           
  185.         }
  186.         else
  187.         {
  188.             thisbox->items[z].xratio = thisbox->xratio;
  189.             thisbox->items[z].yratio = thisbox->yratio;
  190.         }
  191.  
  192.         if(thisbox->type == BOXVERT)
  193.         {
  194.             if((thisbox->items[z].width + (thisbox->items[z].pad*2)) > uxmax)
  195.                 uxmax = (thisbox->items[z].width + (thisbox->items[z].pad*2));
  196.             if(thisbox->items[z].size != SIZEEXPAND)
  197.             {
  198.                 if(((thisbox->items[z].pad*2) + thisbox->items[z].width) > upxmax)
  199.                     upxmax = (thisbox->items[z].pad*2) + thisbox->items[z].width;
  200.             }
  201.             else
  202.             {
  203.                 if(thisbox->items[z].pad*2 > upxmax)
  204.                     upxmax = thisbox->items[z].pad*2;
  205.             }
  206.         }
  207.         else
  208.         {
  209.             if(thisbox->items[z].width == -1)
  210.             {
  211.                 /* figure out how much space this item requires */
  212.                 /* thisbox->items[z].width = */
  213.             }
  214.             else
  215.             {
  216.                 (*usedx) += thisbox->items[z].width + (thisbox->items[z].pad*2);
  217.                 if(thisbox->items[z].size != SIZEEXPAND)
  218.                     (*usedpadx) += (thisbox->items[z].pad*2) + thisbox->items[z].width;
  219.                 else
  220.                     (*usedpadx) += thisbox->items[z].pad*2;
  221.             }
  222.         }
  223.         if(thisbox->type == BOXHORZ)
  224.         {
  225.             if((thisbox->items[z].height + (thisbox->items[z].pad*2)) > uymax)
  226.                 uymax = (thisbox->items[z].height + (thisbox->items[z].pad*2));
  227.             if(thisbox->items[z].size != SIZEEXPAND)
  228.             {
  229.                 if(((thisbox->items[z].pad*2) + thisbox->items[z].height) > upymax)
  230.                     upymax = (thisbox->items[z].pad*2) + thisbox->items[z].height;
  231.             }
  232.             else
  233.             {
  234.                 if(thisbox->items[z].pad*2 > upymax)
  235.                     upymax = thisbox->items[z].pad*2;
  236.             }
  237.         }
  238.         else
  239.         {
  240.             if(thisbox->items[z].height == -1)
  241.             {
  242.                 /* figure out how much space this item requires */
  243.                 /* thisbox->items[z].height = */
  244.             }
  245.             else
  246.             {
  247.                 (*usedy) += thisbox->items[z].height + (thisbox->items[z].pad*2);
  248.                 if(thisbox->items[z].size != SIZEEXPAND)
  249.                     (*usedpady) += (thisbox->items[z].pad*2) + thisbox->items[z].height;
  250.                 else
  251.                     (*usedpady) += thisbox->items[z].pad*2;
  252.             }
  253.         }
  254.     }
  255.  
  256.     (*usedx) += uxmax;
  257.     (*usedy) += uymax;
  258.     (*usedpadx) += upxmax;
  259.     (*usedpady) += upymax;
  260.  
  261.     currentx += thisbox->pad;
  262.     currenty += thisbox->pad;
  263.  
  264. #ifdef DEBUG
  265.     fprintf(f, "Done Calc depth %d\r\nusedx = %d, usedy = %d, usedpadx = %d, usedpady = %d, currentx = %d, currenty = %d, uxmax = %d, uymax = %d\r\n\r\n",
  266.             *depth, *usedx, *usedy, *usedpadx, *usedpady, currentx, currenty, uxmax, uymax);
  267.     reopen();
  268. #endif
  269.  
  270.     /* The second pass is for expansion and actual placement. */
  271.     if(pass > 1)
  272.     {
  273.         /* Any SIZEEXPAND items should be set to uxmax/uymax */
  274.         for(z=0;z<thisbox->count;z++)
  275.         {
  276.             if(thisbox->items[z].size == SIZEEXPAND)
  277.             {
  278.                 if(thisbox->type == BOXVERT)
  279.                     thisbox->items[z].width = uxmax-(thisbox->items[z].pad*2);
  280.                 if(thisbox->type == BOXHORZ)
  281.                     thisbox->items[z].height = uymax-(thisbox->items[z].pad*2);
  282.             }
  283.             /* Run this code segment again to finalize the sized after setting uxmax/uymax values. */
  284.             if(thisbox->items[z].type == TYPEBOX)
  285.             {
  286.                 Box *tmp = WinQueryWindowPtr(thisbox->items[z].hwnd, QWP_USER);
  287.  
  288.                 if(tmp)
  289.                 {
  290.                     if(*depth > 0)
  291.                     {
  292.                         if(thisbox->type == BOXVERT)
  293.                         {
  294.                             tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-((thisbox->items[z].pad*2)+(thisbox->pad*2))))/((float)(tmp->minwidth-((thisbox->items[z].pad*2)+(thisbox->pad*2))));
  295.                             tmp->width = thisbox->items[z].width;
  296.                         }
  297.                         if(thisbox->type == BOXHORZ)
  298.                         {
  299.                             tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-((thisbox->items[z].pad*2)+(thisbox->pad*2))))/((float)(tmp->minheight-((thisbox->items[z].pad*2)+(thisbox->pad*2))));
  300.                             tmp->height = thisbox->items[z].height;
  301.                         }
  302.                     }
  303.  
  304.                     (*depth)++;
  305.  
  306.                     /*tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-tmp->upx) )/((float)(tmp->minwidth-tmp->upx));
  307.                     tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmp->upy))/((float)(tmp->minheight-tmp->upy));*/
  308.  
  309. #ifdef DEBUG
  310.                     fprintf(f, "2- Resize Box depth %d\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d xratio = %f, yratio = %f,\r\nupx = %d, upy = %d, width = %d, height = %d, minwidth = %d, minheight = %d, box xratio = %f, box yratio = %f\r\n\r\n",
  311.                         *depth, x, y, *usedx, *usedy, *usedpadx, *usedpady, tmp->xratio, tmp->yratio, tmp->upx, tmp->upy, thisbox->items[z].width, thisbox->items[z].height, tmp->minwidth, tmp->minheight, thisbox->xratio, thisbox->yratio);
  312.                     reopen();
  313. #endif
  314.  
  315.                     _resize_box(tmp, depth, x, y, &nux, &nuy, 3, &nupx, &nupy);
  316.  
  317.                     (*depth)--;
  318.  
  319.                 }
  320.             }
  321.         }
  322.  
  323.         for(z=0;z<(thisbox->count);z++)
  324.         {
  325.             int height = thisbox->items[z].height;
  326.             int width = thisbox->items[z].width;
  327.             int pad = thisbox->items[z].pad;
  328.             HWND handle = thisbox->items[z].hwnd;
  329.  
  330.             /* When upxmax != pad*2 then ratios are incorrect. */
  331.             vectorx = (int)((width*thisbox->items[z].xratio)-width);
  332.             vectory = (int)((height*thisbox->items[z].yratio)-height);
  333.  
  334.             if(width > 0 && height > 0)
  335.             {
  336.                 /* This is a hack to fix rounding of the sizing */
  337.                 if (*depth == 0)
  338.                 {
  339.                     vectorx++;
  340.                     vectory++;
  341.                 }
  342.  
  343.                 /* If this item isn't going to expand... reset the vectors to 0 */
  344.                 if(thisbox->items[z].size != SIZEEXPAND)
  345.                 {
  346.                     vectorx = vectory = 0;
  347.                 }
  348.  
  349.                 WinSetWindowPos(handle, HWND_TOP, currentx + pad, currenty + pad,
  350.                                 width + vectorx, height + vectory, SWP_MOVE | SWP_SIZE | SWP_ZORDER);
  351.  
  352. #ifdef DEBUG
  353.                 fprintf(f, "Window Pos depth %d\r\ncurrentx = %d, currenty = %d, pad = %d, width = %d, height = %d, vectorx = %d, vectory = %d, Box type = %s\r\n\r\n",
  354.                         *depth, currentx, currenty, pad, width, height, vectorx, vectory,thisbox->type == BOXHORZ ? "Horizontal" : "Vertical");
  355.                 reopen();
  356. #endif
  357.  
  358.                 if(thisbox->type == BOXHORZ)
  359.                     currentx += width + vectorx + (pad * 2);
  360.                 if(thisbox->type == BOXVERT)
  361.                     currenty += height + vectory + (pad * 2);
  362.             }
  363.         }
  364.     }
  365.     return 0;
  366. }
  367.  
  368. /* The main window procedure for Dynamic Windows, all the resizing code is done here. */
  369. MRESULT EXPENTRY wndproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  370. {
  371.     int result = 0;
  372.  
  373.     if(filterfunc)
  374.         result = filterfunc(hWnd, msg, mp1, mp2);
  375.  
  376.     switch( msg )
  377.     {
  378.     case WM_PAINT:
  379.         {
  380.             HPS    hps;
  381.             RECTL  rc;
  382.  
  383.             hps = WinBeginPaint(hWnd, 0L, &rc);
  384.             WinEndPaint(hps);
  385.             break;
  386.         }
  387.     case WM_SIZE:
  388.         {
  389.             Box *thisbox = WinQueryWindowPtr(hWnd, QWP_USER);
  390.             int x, y, usedx = 0, usedy = 0, depth = 0;
  391.  
  392.             x=SHORT1FROMMP(mp2); y=SHORT2FROMMP(mp2);
  393.             if(x != 0 && y != 0) {
  394.                 if(thisbox)
  395.                 {
  396.                     int usedpadx = 0, usedpady = 0;
  397.  
  398.                     _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 1, &usedpadx, &usedpady);
  399.  
  400.                     thisbox->xratio = ((float)(x-usedpadx))/((float)(usedx-usedpadx));
  401.                     thisbox->yratio = ((float)(y-usedpady))/((float)(usedy-usedpady));
  402.  
  403. #ifdef DEBUG
  404.                     fprintf(f, "WM_SIZE Resize Box Pass 1\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d xratio = %f, yratio = %f\r\n\r\n",
  405.                             x, y, usedx, usedy, usedpadx, usedpady, thisbox->xratio, thisbox->yratio);
  406.                     reopen();
  407. #endif
  408.  
  409.                     usedpadx = usedpady = usedx = usedy = depth = 0;
  410.  
  411.                     _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 2, &usedpadx, &usedpady);
  412. #ifdef DEBUG
  413.                     fprintf(f, "WM_SIZE Resize Box Pass 2\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d\r\n",
  414.                             x, y, usedx, usedy, usedpadx, usedpady);
  415.                     reopen();
  416. #endif
  417.                 }
  418.             }
  419.         }
  420.         break;
  421.     case WM_QUIT:
  422.         {
  423.             /* Free memory before destroying */
  424.             HENUM henum;
  425.             HWND child;
  426.             void *tmp;
  427.  
  428.             henum = WinBeginEnumWindows(hWnd);
  429.             while((child = WinGetNextWindow(henum)) != NULLHANDLE)
  430.             {
  431.                 tmp = WinQueryWindowPtr(child, QWP_USER);
  432.                 if(tmp)
  433.                     free(tmp);
  434.             }
  435.             WinEndEnumWindows(henum);
  436.             tmp = WinQueryWindowPtr(hWnd, QWP_USER);
  437.             if(tmp)
  438.                 free(tmp);
  439.         }
  440.         break;
  441.     }
  442.  
  443.     if(filterfunc && result != -1)
  444.         return (MRESULT)result;
  445.     else
  446.         return WinDefWindowProc(hWnd, msg, mp1, mp2);
  447. }
  448. /*
  449.  * Initializes the Dynamic Windows engine.
  450.  * Parameters:
  451.  *           newthread: True if this is the only thread.
  452.  *                      False if there is already a message loop running.
  453.  */
  454. int dw_init(int newthread)
  455. {
  456.     APIRET rc;
  457.  
  458.     if(newthread)
  459.     {
  460.         dwhab = WinInitialize(0);
  461.         dwhmq = WinCreateMsgQueue(dwhab, 0);
  462.     }
  463.  
  464.     rc = WinRegisterClass(dwhab, ClassName, wndproc, CS_SIZEREDRAW, 32);
  465.  
  466. #ifdef DEBUG
  467.     f = fopen("dw.log", "wt");
  468. #endif
  469.  
  470.  
  471.     return rc;
  472. }
  473.  
  474. /*
  475.  * Runs a message loop for Dynamic Windows.
  476.  * Parameters:
  477.  *           currenthab: The handle to the current anchor block
  478.  *                       or NULL if this DW is handling the message loop.
  479.  *           func: Function pointer to the message filter function.
  480.  */
  481. void dw_main(HAB currenthab, int (* EXPENTRY func)(HWND, ULONG, MPARAM, MPARAM))
  482. {
  483.     QMSG qmsg;
  484.     HAB habtouse;
  485.  
  486.     if(!currenthab)
  487.         habtouse = dwhab;
  488.     else
  489.         habtouse = currenthab;
  490.  
  491.     /* Setup the filter function */
  492.     filterfunc = func;
  493.  
  494.     while (WinGetMsg(habtouse, &qmsg, 0, 0, 0))
  495.         WinDispatchMsg(habtouse, &qmsg);
  496.  
  497. #ifdef DEBUG
  498.     fclose(f);
  499. #endif
  500.  
  501.     if(!currenthab)
  502.     {
  503.         WinDestroyMsgQueue(dwhmq);
  504.         WinTerminate(dwhab);
  505.     }
  506. }
  507.  
  508. /*
  509.  * Makes the window visible.
  510.  * Parameters:
  511.  *           handle: The window handle to make visible.
  512.  */
  513. int dw_window_show(HWND handle)
  514. {
  515.     WinSetFocus(HWND_DESKTOP, handle);
  516.     return WinSetWindowPos(handle, NULLHANDLE, 0, 0, 0, 0, SWP_SHOW);
  517. }
  518.  
  519. /*
  520.  * Makes the window invisible.
  521.  * Parameters:
  522.  *           handle: The window handle to make visible.
  523.  */
  524. int dw_window_hide(HWND handle)
  525. {
  526.     return WinShowWindow(handle, FALSE);
  527. }
  528.  
  529. /*
  530.  * Destroys a window and all of it's children.
  531.  * Parameters:
  532.  *           handle: The window handle to destroy.
  533.  */
  534. int dw_window_destroy(HWND handle)
  535. {
  536.     return WinDestroyWindow(handle);
  537. }
  538.  
  539. /*
  540.  * Sets the font used by a specified window (widget) handle.
  541.  * Parameters:
  542.  *          handle: The window (widget) handle.
  543.  *          fontname: Name and size of the font in the form "size.fontname"
  544.  */
  545. int dw_window_set_font(HWND handle, char *fontname)
  546. {
  547.     return WinSetPresParam(handle, PP_FONTNAMESIZE, strlen(fontname)+1, fontname);
  548. }
  549.  
  550. /*
  551.  * Sets the colors used by a specified window (widget) handle.
  552.  * Parameters:
  553.  *          handle: The window (widget) handle.
  554.  *          fore: Foreground color in RGB format.
  555.  *          back: Background color in RGB format.
  556.  */
  557. int dw_window_set_color(HWND handle, ULONG fore, ULONG back)
  558. {
  559.     return (WinSetPresParam(handle, PP_FOREGROUNDCOLORINDEX, sizeof(ULONG), &fore) |
  560.             WinSetPresParam(handle, PP_BACKGROUNDCOLORINDEX, sizeof(ULONG), &back));
  561. }
  562.  
  563. /*
  564.  * Create a new Window Frame.
  565.  * Parameters:
  566.  *       owner: The Owner's window handle or HWND_DESKTOP.
  567.  *       title: The Window title.
  568.  *       flStyle: Style flags, see the PM reference.
  569.  */
  570. HWND dw_window_new(HWND hwndOwner, PSZ title, ULONG flStyle)
  571. {
  572.     HWND hwndclient = 0, hwndframe;
  573.     Box *newbox = malloc(sizeof(Box));
  574.  
  575.     newbox->pad = 0;
  576.     newbox->type = BOXVERT;
  577.     newbox->count = 0;
  578.  
  579.     hwndframe = WinCreateStdWindow(hwndOwner, 0L, &flStyle, ClassName, title, 0L, NULLHANDLE, 0L, &hwndclient);
  580.     WinSetWindowPtr(hwndclient, QWP_USER, newbox);
  581.  
  582.     return hwndframe;
  583. }
  584.  
  585. /*
  586.  * Create a new Box to be packed.
  587.  * Parameters:
  588.  *       type: Either BOXVERT (vertical) or BOXHORZ (horizontal).
  589.  *       pad: Number of pixels to pad around the box.
  590.  */
  591. HWND dw_box_new(int type, int pad)
  592. {
  593.     Box *newbox = malloc(sizeof(Box));
  594.     HWND hwndframe;
  595.  
  596.     newbox->pad = pad;
  597.     newbox->type = type;
  598.     newbox->count = 0;
  599.  
  600.     hwndframe = WinCreateWindow(HWND_OBJECT,
  601.                                 WC_FRAME,
  602.                                 NULL,
  603.                                 WS_VISIBLE,
  604.                                 0, 0, 2000, 1000,
  605.                                 NULLHANDLE,
  606.                                 HWND_TOP,
  607.                                 0L,
  608.                                 NULL,
  609.                                 NULL);
  610.  
  611.     WinSetWindowPtr(hwndframe, QWP_USER, newbox);
  612.     return hwndframe;
  613. }
  614.  
  615. /*
  616.  * Create a new Group Box to be packed.
  617.  * Parameters:
  618.  *       type: Either BOXVERT (vertical) or BOXHORZ (horizontal).
  619.  *       pad: Number of pixels to pad around the box.
  620.  */
  621. HWND dw_groupbox_new(int type, int pad)
  622. {
  623.     Box *newbox = malloc(sizeof(Box));
  624.     HWND hwndframe;
  625.  
  626.     newbox->pad = pad;
  627.     newbox->type = type;
  628.     newbox->count = 0;
  629.  
  630.     hwndframe = WinCreateWindow(HWND_OBJECT,
  631.                                 WC_STATIC,
  632.                                 NULL,
  633.                                 WS_VISIBLE | SS_GROUPBOX,
  634.                                 0, 0, 2000, 1000,
  635.                                 NULLHANDLE,
  636.                                 HWND_TOP,
  637.                                 0L,
  638.                                 NULL,
  639.                                 NULL);
  640.  
  641.     WinSetWindowPtr(hwndframe, QWP_USER, newbox);
  642.     return hwndframe;
  643. }
  644.  
  645. /*
  646.  * Create a bitmap object to be packed.
  647.  * Parameters:
  648.  *       id: An ID to be used for getting the resource from the
  649.  *           resource file.
  650.  */
  651. HWND dw_bitmap_new(ULONG id)
  652. {
  653.     return WinCreateWindow(HWND_OBJECT,
  654.                            WC_STATIC,
  655.                            NULL,
  656.                            WS_VISIBLE | SS_TEXT,
  657.                            0, 0, 2000, 1000,
  658.                            NULLHANDLE,
  659.                            HWND_TOP,
  660.                            id,
  661.                            NULL,
  662.                            NULL);
  663. }
  664.  
  665. /*
  666.  * Create a container object to be packed.
  667.  * Parameters:
  668.  *       id: An ID to be used for getting the resource from the
  669.  *           resource file.
  670.  */
  671. HWND dw_container_new(ULONG id)
  672. {
  673.     return WinCreateWindow(HWND_OBJECT,
  674.                            WC_CONTAINER,
  675.                            NULL,
  676.                            WS_VISIBLE | CCS_READONLY |
  677.                            CCS_SINGLESEL | CCS_AUTOPOSITION,
  678.                            0, 0, 2000, 1000,
  679.                            NULLHANDLE,
  680.                            HWND_TOP,
  681.                            id,
  682.                            NULL,
  683.                            NULL);
  684. }
  685. /*
  686.  * Create a new static text window (widget) to be packed.
  687.  * Parameters:
  688.  *       text: The text to be display by the static text widget.
  689.  *       id: An ID to be used with WinWindowFromID() or 0L.
  690.  */
  691. HWND dw_text_new(char *text, ULONG id)
  692. {
  693.     return WinCreateWindow(HWND_OBJECT,
  694.                            WC_STATIC,
  695.                            text,
  696.                            WS_VISIBLE | SS_TEXT,
  697.                            0,0,2000,1000,
  698.                            NULLHANDLE,
  699.                            HWND_TOP,
  700.                            id,
  701.                            NULL,
  702.                            NULL);
  703. }
  704.  
  705. /*
  706.  * Create a new Multiline Editbox window (widget) to be packed.
  707.  * Parameters:
  708.  *       id: An ID to be used with WinWindowFromID() or 0L.
  709.  */
  710. HWND dw_mle_new(ULONG id)
  711. {
  712.     return WinCreateWindow(HWND_OBJECT,
  713.                            WC_MLE,
  714.                            "",
  715.                            WS_VISIBLE |
  716.                            MLS_BORDER | MLS_IGNORETAB |
  717.                            MLS_READONLY | MLS_VSCROLL |
  718.                            MLS_WORDWRAP | WS_TABSTOP,
  719.                            0,0,2000,1000,
  720.                            NULLHANDLE,
  721.                            HWND_TOP,
  722.                            id,
  723.                            NULL,
  724.                            NULL);
  725. }
  726.  
  727. /*
  728.  * Create a new Entryfield window (widget) to be packed.
  729.  * Parameters:
  730.  *       text: The default text to be in the entryfield widget.
  731.  *       id: An ID to be used with WinWindowFromID() or 0L.
  732.  */
  733. HWND dw_entryfield_new(char *text, ULONG id)
  734. {
  735.     return WinCreateWindow(HWND_OBJECT,
  736.                            WC_ENTRYFIELD,
  737.                            text,
  738.                            WS_VISIBLE | ES_MARGIN |
  739.                            ES_AUTOSCROLL | WS_TABSTOP,
  740.                            0,0,2000,1000,
  741.                            NULLHANDLE,
  742.                            HWND_TOP,
  743.                            id,
  744.                            NULL,
  745.                            NULL);
  746. }
  747.  
  748. /*
  749.  * Create a new Combobox window (widget) to be packed.
  750.  * Parameters:
  751.  *       text: The default text to be in the combpbox widget.
  752.  *       id: An ID to be used with WinWindowFromID() or 0L.
  753.  */
  754. HWND dw_combobox_new(char *text, ULONG id)
  755. {
  756.     return WinCreateWindow(HWND_OBJECT,
  757.                            WC_COMBOBOX,
  758.                            text,
  759.                            WS_VISIBLE,
  760.                            0,0,2000,1000,
  761.                            NULLHANDLE,
  762.                            HWND_TOP,
  763.                            id,
  764.                            NULL,
  765.                            NULL);
  766. }
  767.  
  768. /*
  769.  * Create a new button window (widget) to be packed.
  770.  * Parameters:
  771.  *       text: The text to be display by the static text widget.
  772.  *       id: An ID to be used with WinWindowFromID() or 0L.
  773.  */
  774. HWND dw_button_new(char *text, ULONG id)
  775. {
  776.     return WinCreateWindow(HWND_OBJECT,
  777.                            WC_BUTTON,
  778.                            text,
  779.                            WS_VISIBLE,
  780.                            0,0,2000,1000,
  781.                            NULLHANDLE,
  782.                            HWND_TOP,
  783.                            id,
  784.                            NULL,
  785.                            NULL);
  786. }
  787.  
  788. /*
  789.  * Create a new spinbutton window (widget) to be packed.
  790.  * Parameters:
  791.  *       text: The text to be display by the static text widget.
  792.  *       id: An ID to be used with WinWindowFromID() or 0L.
  793.  */
  794. HWND dw_spinbutton_new(char *text, ULONG id)
  795. {
  796.     return WinCreateWindow(HWND_OBJECT,
  797.                            WC_SPINBUTTON,
  798.                            text,
  799.                            WS_VISIBLE,
  800.                            0,0,2000,1000,
  801.                            NULLHANDLE,
  802.                            HWND_TOP,
  803.                            id,
  804.                            NULL,
  805.                            NULL);
  806. }
  807.  
  808. /*
  809.  * Create a new slider window (widget) to be packed.
  810.  * Parameters:
  811.  *       id: An ID to be used with WinWindowFromID() or 0L.
  812.  */
  813. HWND dw_slider_new(ULONG id)
  814. {
  815.     return WinCreateWindow(HWND_OBJECT,
  816.                            WC_SLIDER,
  817.                            NULL,
  818.                            WS_VISIBLE,
  819.                            0,0,2000,1000,
  820.                            NULLHANDLE,
  821.                            HWND_TOP,
  822.                            id,
  823.                            NULL,
  824.                            NULL);
  825. }
  826.  
  827. /*
  828.  * Create a new checkbox window (widget) to be packed.
  829.  * Parameters:
  830.  *       text: The text to be display by the static text widget.
  831.  *       id: An ID to be used with WinWindowFromID() or 0L.
  832.  */
  833. HWND dw_checkbox_new(char *text, ULONG id)
  834. {
  835.     return WinCreateWindow(HWND_OBJECT,
  836.                            WC_BUTTON,
  837.                            text,
  838.                            WS_VISIBLE | BS_AUTOCHECKBOX,
  839.                            0,0,2000,1000,
  840.                            NULLHANDLE,
  841.                            HWND_TOP,
  842.                            id,
  843.                            NULL,
  844.                            NULL);
  845. }
  846.  
  847. /*
  848.  * Create a new listbox window (widget) to be packed.
  849.  * Parameters:
  850.  *       id: An ID to be used with WinWindowFromID() or 0L.
  851.  */
  852. HWND dw_listbox_new(ULONG id)
  853. {
  854.     return WinCreateWindow(HWND_OBJECT,
  855.                            WC_LISTBOX,
  856.                            NULL,
  857.                            WS_VISIBLE,
  858.                            0,0,2000,1000,
  859.                            NULLHANDLE,
  860.                            HWND_TOP,
  861.                            0L,
  862.                            NULL,
  863.                            NULL);
  864. }
  865.  
  866. /*
  867.  * Sets the icon used for a given window.
  868.  * Parameters:
  869.  *       handle: Handle to the window.
  870.  *       id: An ID to be used to specify the icon.
  871.  */
  872. void dw_window_set_icon(HWND handle, ULONG id)
  873. {
  874.     HPOINTER icon;
  875.  
  876.     icon = WinLoadPointer(HWND_DESKTOP,NULLHANDLE,id);
  877.     WinSendMsg(handle, WM_SETICON, (MPARAM)icon, 0);
  878. }
  879.  
  880. /*
  881.  * Sets the bitmap used for a given static window.
  882.  * Parameters:
  883.  *       handle: Handle to the window.
  884.  *       id: An ID to be used to specify the icon.
  885.  */
  886. void dw_window_set_bitmap(HWND handle, ULONG id)
  887. {
  888.     HBITMAP hbm;
  889.     HPS     hps = WinGetPS(handle);
  890.  
  891.     hbm = GpiLoadBitmap(hps, NULLHANDLE, id, 0, 0);
  892.     WinSetWindowBits(handle,QWL_STYLE,SS_BITMAP,SS_BITMAP | 0x7f);
  893.     WinSendMsg( handle, SM_SETHANDLE, MPFROMP(hbm), NULL );
  894.     /*WinSetWindowULong( hwndDlg, QWL_USER, (ULONG) hbm );*/
  895.     WinReleasePS(hps);
  896. }
  897.  
  898. /*
  899.  * Sets the text used for a given window.
  900.  * Parameters:
  901.  *       handle: Handle to the window.
  902.  *       text: The text associsated with a given window.
  903.  */
  904. void dw_window_set_text(HWND handle, char *text)
  905. {
  906.     WinSetWindowText(handle, text);
  907. }
  908.  
  909. /*
  910.  * Disables given window (widget).
  911.  * Parameters:
  912.  *       handle: Handle to the window.
  913.  */
  914. void dw_window_disable(HWND handle)
  915. {
  916.     WinEnableWindow(handle, FALSE);
  917. }
  918.  
  919. /*
  920.  * Enables given window (widget).
  921.  * Parameters:
  922.  *       handle: Handle to the window.
  923.  */
  924. void dw_window_enable(HWND handle)
  925. {
  926.     WinEnableWindow(handle, TRUE);
  927. }
  928.  
  929. /*
  930.  * Pack windows (widgets) into a box from the end (or bottom).
  931.  * Parameters:
  932.  *       box: Window handle of the box to be packed into.
  933.  *       item: Window handle of the item to be back.
  934.  *       width: Width in pixels of the item or -1 to be self determined.
  935.  *       height: Height in pixels of the item or -1 to be self determined.
  936.  *       size: TRUE if the window (widget) should expand to fill space given.
  937.  *       pad: Number of pixels of padding around the item.
  938.  */
  939. void dw_box_pack_end(HWND box, HWND item, int width, int height, int size, int pad)
  940. {
  941.     Box *thisbox;
  942.  
  943.     thisbox = WinQueryWindowPtr(box, QWP_USER);
  944.     if(!thisbox)
  945.     {
  946.         box = WinWindowFromID(box, FID_CLIENT);
  947.         if(box)
  948.             thisbox = WinQueryWindowPtr(box, QWP_USER);
  949.     }
  950.     if(thisbox)
  951.     {
  952.         if(thisbox->type == BOXHORZ)
  953.             dw_box_pack_start_stub(box, item, width, height, size, pad);
  954.         else
  955.             dw_box_pack_end_stub(box, item, width, height, size, pad);
  956.     }
  957. }
  958.  
  959. void dw_box_pack_end_stub(HWND box, HWND item, int width, int height, int size, int pad)
  960. {
  961.     HWND boxowner = NULLHANDLE;
  962.     Box *thisbox;
  963.  
  964.     thisbox = WinQueryWindowPtr(box, QWP_USER);
  965.     if(!thisbox)
  966.     {
  967.         box = WinWindowFromID(box, FID_CLIENT);
  968.         if(box)
  969.             thisbox = WinQueryWindowPtr(box, QWP_USER);
  970.     }
  971.     if(thisbox)
  972.     {
  973.         int z;
  974.         Item *tmpitem, *thisitem = thisbox->items;
  975.         char tmpbuf[100];
  976.  
  977.         tmpitem = malloc(sizeof(Item)*(thisbox->count+1));
  978.  
  979.         for(z=0;z<thisbox->count;z++)
  980.         {
  981.             tmpitem[z] = thisitem[z];
  982.         }
  983.  
  984.         WinQueryClassName(item, 99, tmpbuf);
  985.  
  986.         if(strncmp(tmpbuf, "#1", 2)==0)
  987.             tmpitem[thisbox->count].type = TYPEBOX;
  988.         else
  989.             tmpitem[thisbox->count].type = TYPEITEM;
  990.  
  991.         tmpitem[thisbox->count].hwnd = item;
  992.         tmpitem[thisbox->count].width = width;
  993.         tmpitem[thisbox->count].height = height;
  994.         tmpitem[thisbox->count].pad = pad;
  995.         if(size)
  996.             tmpitem[thisbox->count].size = SIZEEXPAND;
  997.         else
  998.             tmpitem[thisbox->count].size = SIZESTATIC;
  999.  
  1000.         thisbox->items = tmpitem;
  1001.  
  1002.         if(thisbox->count)
  1003.             free(thisitem);
  1004.  
  1005.         thisbox->count++;
  1006.  
  1007.         /* Don't set the ownership if it's an entryfield */
  1008.         WinQueryClassName(item, 99, tmpbuf);
  1009.         if(strncmp(tmpbuf, "#6", 2)!=0)
  1010.         {
  1011.             if((boxowner = WinQueryWindow(box, QW_OWNER)))
  1012.                 WinSetOwner(item, boxowner);
  1013.             else
  1014.                 WinSetOwner(item, box);
  1015.         }
  1016.         WinSetParent(item, box, FALSE);
  1017.     }
  1018. }
  1019.  
  1020. /*
  1021.  * Sets the size of a given window (widget).
  1022.  * Parameters:
  1023.  *          handle: Window (widget) handle.
  1024.  *          width: New width in pixels.
  1025.  *          height: New height in pixels.
  1026.  */
  1027. void dw_window_set_usize(HWND handle, ULONG width, ULONG height)
  1028. {
  1029.     WinSetWindowPos(handle, NULLHANDLE, 0, 0, width, height, SWP_SHOW | SWP_SIZE);
  1030. }
  1031.  
  1032. /*
  1033.  * Returns the width of the screen.
  1034.  */
  1035. int dw_screen_width(void)
  1036. {
  1037.     return WinQuerySysValue(HWND_DESKTOP,SV_CXSCREEN);
  1038. }
  1039.  
  1040. /*
  1041.  * Returns the height of the screen.
  1042.  */
  1043. int dw_screen_height(void)
  1044. {
  1045.     return WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN);
  1046. }
  1047.  
  1048. /*
  1049.  * Sets the position of a given window (widget).
  1050.  * Parameters:
  1051.  *          handle: Window (widget) handle.
  1052.  *          x: X location from the bottom left.
  1053.  *          y: Y location from the bottom left.
  1054.  */
  1055. void dw_window_set_pos(HWND handle, ULONG x, ULONG y)
  1056. {
  1057.     WinSetWindowPos(handle, NULLHANDLE, x, y, 0, 0, SWP_MOVE);
  1058. }
  1059.  
  1060. /*
  1061.  * Sets the position and size of a given window (widget).
  1062.  * Parameters:
  1063.  *          handle: Window (widget) handle.
  1064.  *          x: X location from the bottom left.
  1065.  *          y: Y location from the bottom left.
  1066.  *          width: Width of the widget.
  1067.  *          height: Height of the widget.
  1068.  */
  1069. void dw_window_set_pos_size(HWND handle, ULONG x, ULONG y, ULONG width, ULONG height)
  1070. {
  1071.     WinSetWindowPos(handle, NULLHANDLE, x, y, width, height, SWP_MOVE | SWP_SIZE | SWP_SHOW);
  1072. }
  1073.  
  1074. /*
  1075.  * Sets the style of a given window (widget).
  1076.  * Parameters:
  1077.  *          handle: Window (widget) handle.
  1078.  *          width: New width in pixels.
  1079.  *          height: New height in pixels.
  1080.  */
  1081. void dw_window_set_style(HWND handle, ULONG style, ULONG mask)
  1082. {
  1083.     WinSetWindowBits(handle, QWL_STYLE, style, mask);
  1084. }
  1085.  
  1086. /*
  1087.  * Pack windows (widgets) into a box from the start (or top).
  1088.  * Parameters:
  1089.  *       box: Window handle of the box to be packed into.
  1090.  *       item: Window handle of the item to be back.
  1091.  *       width: Width in pixels of the item or -1 to be self determined.
  1092.  *       height: Height in pixels of the item or -1 to be self determined.
  1093.  *       size: TRUE if the window (widget) should expand to fill space given.
  1094.  *       pad: Number of pixels of padding around the item.
  1095.  */
  1096. void dw_box_pack_start(HWND box, HWND item, int width, int height, int size, int pad)
  1097. {
  1098.     Box *thisbox;
  1099.  
  1100.     thisbox = WinQueryWindowPtr(box, QWP_USER);
  1101.     if(!thisbox)
  1102.     {
  1103.         box = WinWindowFromID(box, FID_CLIENT);
  1104.         if(box)
  1105.             thisbox = WinQueryWindowPtr(box, QWP_USER);
  1106.     }
  1107.     if(thisbox)
  1108.     {
  1109.         if(thisbox->type == BOXHORZ)
  1110.             dw_box_pack_end_stub(box, item, width, height, size, pad);
  1111.         else
  1112.             dw_box_pack_start_stub(box, item, width, height, size, pad);
  1113.     }
  1114. }
  1115.  
  1116. void dw_box_pack_start_stub(HWND box, HWND item, int width, int height, int size, int pad)
  1117. {
  1118.     HWND boxowner = NULLHANDLE;
  1119.     Box *thisbox;
  1120.  
  1121.     thisbox = WinQueryWindowPtr(box, QWP_USER);
  1122.     if(!thisbox)
  1123.     {
  1124.         box = WinWindowFromID(box, FID_CLIENT);
  1125.         if(box)
  1126.             thisbox = WinQueryWindowPtr(box, QWP_USER);
  1127.     }
  1128.     if(thisbox)
  1129.     {
  1130.         int z;
  1131.         Item *tmpitem, *thisitem = thisbox->items;
  1132.         char tmpbuf[100];
  1133.  
  1134.         tmpitem = malloc(sizeof(Item)*(thisbox->count+1));
  1135.  
  1136.         for(z=0;z<thisbox->count;z++)
  1137.         {
  1138.             tmpitem[z+1] = thisitem[z];
  1139.         }
  1140.  
  1141.         WinQueryClassName(item, 99, tmpbuf);
  1142.  
  1143.         if(strncmp(tmpbuf, "#1", 2)==0)
  1144.             tmpitem[0].type = TYPEBOX;
  1145.         else
  1146.             tmpitem[0].type = TYPEITEM;
  1147.  
  1148.         tmpitem[0].hwnd = item;
  1149.         tmpitem[0].width = width;
  1150.         tmpitem[0].height = height;
  1151.         tmpitem[0].pad = pad;
  1152.         if(size)
  1153.             tmpitem[0].size = SIZEEXPAND;
  1154.         else
  1155.             tmpitem[0].size = SIZESTATIC;
  1156.  
  1157.         thisbox->items = tmpitem;
  1158.  
  1159.         if(thisbox->count)
  1160.             free(thisitem);
  1161.  
  1162.         thisbox->count++;
  1163.  
  1164.         WinQueryClassName(item, 99, tmpbuf);
  1165.         /* Don't set the ownership if it's an entryfield */
  1166.         if(strncmp(tmpbuf, "#6", 2)!=0)
  1167.         {
  1168.             if((boxowner = WinQueryWindow(box, QW_OWNER)))
  1169.                 WinSetOwner(item, boxowner);
  1170.             else
  1171.                 WinSetOwner(item, box);
  1172.         }
  1173.         WinSetParent(item, box, FALSE);
  1174.     }
  1175. }
  1176.  
  1177. #ifdef TEST
  1178. HWND mainwindow,
  1179.      listbox,
  1180.      okbutton,
  1181.      cancelbutton,
  1182.      lbbox,
  1183.      stext,
  1184.      buttonbox,
  1185.      testwindow,
  1186.      testbox,
  1187.      testok,
  1188.      testcancel,
  1189.      testbox2,
  1190.      testok2,
  1191.      testcancel2;
  1192.  
  1193. /* Do any handling you need in the filter function */
  1194. LONG testfilter(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  1195. {
  1196.     switch(msg)
  1197.     {
  1198.     case WM_COMMAND:
  1199.         switch (COMMANDMSG(&msg)->cmd)
  1200.         {
  1201.         case 1001L:
  1202.         case 1002L:
  1203.             dw_window_destroy(mainwindow);;
  1204.             break;
  1205.         case 1003L:
  1206.         case 1004L:
  1207.             dw_window_destroy(testwindow);;
  1208.             break;
  1209.         }
  1210.         break;
  1211.     }
  1212.     /* Return -1 to allow the default handlers to return. */
  1213.     return -1;
  1214. }
  1215.  
  1216. /*
  1217.  * Let's demonstrate the functionality of this library. :)
  1218.  */
  1219. int main(void)
  1220. {
  1221.     ULONG flStyle = FCF_SYSMENU | FCF_TITLEBAR |
  1222.         FCF_SHELLPOSITION | FCF_TASKLIST | FCF_DLGBORDER;
  1223.  
  1224.     dw_init(TRUE);
  1225.  
  1226.     /* Try a little server dialog. :) */
  1227.     mainwindow = dw_window_new(HWND_DESKTOP, "Server", flStyle | FCF_SIZEBORDER | FCF_MINMAX);
  1228.  
  1229.     lbbox = dw_box_new(BOXVERT, 10);
  1230.  
  1231.     dw_box_pack_start(mainwindow, lbbox, 0, 0, TRUE, 0);
  1232.  
  1233.     stext = dw_text_new("Choose a server:", 0);
  1234.  
  1235.     dw_window_set_style(stext, DT_VCENTER, DT_VCENTER);
  1236.  
  1237.     dw_box_pack_start(lbbox, stext, 130, 10, FALSE, 10);
  1238.  
  1239.     listbox = dw_listbox_new(100L);
  1240.  
  1241.     dw_box_pack_start(lbbox, listbox, 130, 200, TRUE, 10);
  1242.  
  1243.     buttonbox = dw_box_new(BOXHORZ, 0);
  1244.  
  1245.     dw_box_pack_start(lbbox, buttonbox, 0, 0, TRUE, 0);
  1246.  
  1247.     okbutton = dw_button_new("Ok", 1001L);
  1248.  
  1249.     dw_box_pack_start(buttonbox, okbutton, 50, 30, TRUE, 5);
  1250.  
  1251.     cancelbutton = dw_button_new("Cancel", 1002L);
  1252.  
  1253.     dw_box_pack_start(buttonbox, cancelbutton, 50, 30, TRUE, 5);
  1254.  
  1255.     /* Set some nice fonts and colors */
  1256.     dw_window_set_color(lbbox, CLR_PALEGRAY, CLR_PALEGRAY);
  1257.     dw_window_set_color(buttonbox, CLR_PALEGRAY, CLR_PALEGRAY);
  1258.     dw_window_set_font(stext, "9.WarpSans");
  1259.     dw_window_set_color(stext, CLR_BLACK, CLR_PALEGRAY);
  1260.     dw_window_set_font(listbox, "9.WarpSans");
  1261.     dw_window_set_font(okbutton, "9.WarpSans");
  1262.     dw_window_set_font(cancelbutton, "9.WarpSans");
  1263.  
  1264.     dw_window_show(mainwindow);
  1265.  
  1266.     dw_window_set_usize(mainwindow, 170, 340);
  1267.  
  1268.     /* Another small example */
  1269.     flStyle |= FCF_MINMAX | FCF_SIZEBORDER;
  1270.  
  1271.     testwindow = dw_window_new(HWND_DESKTOP, "Wow a test dialog! :) yay!", flStyle);
  1272.  
  1273.     testbox = dw_box_new(BOXVERT, 10);
  1274.  
  1275.     dw_box_pack_start(testwindow, testbox, 0, 0, TRUE, 0);
  1276.  
  1277.     testok = dw_button_new("Ok", 1003L);
  1278.  
  1279.     dw_box_pack_start(testbox, testok, 60, 40, TRUE, 10);
  1280.  
  1281.     testcancel = dw_button_new("Cancel", 1004L);
  1282.  
  1283.     dw_box_pack_start(testbox, testcancel, 60, 40, TRUE, 10);
  1284.  
  1285.     testbox2 = dw_box_new(BOXHORZ, 0);
  1286.  
  1287.     dw_box_pack_start(testbox, testbox2, 0, 0, TRUE, 0);
  1288.  
  1289.     testok2 = dw_button_new("Ok", 1003L);
  1290.  
  1291.     dw_box_pack_start(testbox2, testok2, 60, 40, TRUE, 10);
  1292.  
  1293.     testcancel2 = dw_button_new("Cancel", 1004L);
  1294.  
  1295.     dw_box_pack_start(testbox2, testcancel2, 60, 40, TRUE, 10);
  1296.  
  1297.     /* Set some nice fonts and colors */
  1298.     dw_window_set_color(testbox, CLR_PALEGRAY, CLR_PALEGRAY);
  1299.     dw_window_set_color(testbox2, CLR_PALEGRAY, CLR_PALEGRAY);
  1300.     dw_window_set_font(testok, "9.WarpSans");
  1301.     dw_window_set_font(testcancel, "9.WarpSans");
  1302.     dw_window_set_font(testok2, "9.WarpSans");
  1303.     dw_window_set_font(testcancel2, "9.WarpSans");
  1304.  
  1305.     dw_window_show(testwindow);
  1306.  
  1307.     dw_main(0L, (void *)testfilter);
  1308.  
  1309.     return 0;
  1310. }
  1311. #endif