home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia: Special Games / INFESPGAMES.mdf / os2 / spl / src / spldlgs.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-26  |  9.1 KB  |  347 lines

  1. /* spldlgs.cpp:  dialog procedures for spl program
  2.  
  3.     Copyright (C) 1993, 1994 John-Marc Chandonia
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #define VERSION "1.73, 7/26/94"
  21.  
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include "spl.hpp"
  26. #include "general.hpp"
  27. #include "spldlg.h"
  28. #include "bookwin.hpp"
  29. #include "splwin.hpp"
  30. #include "spldlgs.hpp"
  31.  
  32. // from bookwin module:
  33. extern bookwindow *first;
  34.  
  35. // defined in main module:
  36. extern HWND hwndhelp;
  37.  
  38. // dialog procedure for select boxes:
  39. MRESULT EXPENTRY select_dlg_func(HWND hwnd, ULONG msg,
  40.                  MPARAM mp1, MPARAM mp2) {
  41.     SHORT w,h,x,y;
  42.     SWP swp;
  43.  
  44.     switch (msg) {
  45.     case WM_INITDLG:
  46.     // turn on default buttons.
  47.     WinSendMsg(WinWindowFromID(hwnd,DLG_AND),
  48.            BM_SETCHECK,
  49.            (MPARAM)1,
  50.            0);
  51.     WinSendMsg(WinWindowFromID(hwnd,DLG_DES_OR),
  52.            BM_SETCHECK,
  53.            (MPARAM)1,
  54.            0);
  55.     WinSendMsg(WinWindowFromID(hwnd,DLG_CASE),
  56.            BM_SETCHECK,
  57.            (MPARAM)1,
  58.            0);
  59.  
  60.     // center box
  61.     w = WinQuerySysValue(HWND_DESKTOP,SV_CXSCREEN);
  62.     h = WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN);
  63.     WinQueryWindowPos(hwnd,&swp);
  64.     x = (SHORT)((w-swp.cx)/2);
  65.     y = (SHORT)((h-swp.cy)/2);
  66.     WinSetWindowPos(hwnd,HWND_TOP,x,y,0,0,SWP_MOVE);
  67.     break;
  68.  
  69.     case WM_USER_ACK:
  70.     WinDismissDlg(hwnd,TRUE);
  71.     return (MRESULT)TRUE;
  72.     break;
  73.  
  74.     case WM_COMMAND: 
  75.     switch (SHORT1FROMMP(mp1)) {
  76.     case DLG_OK:
  77.         HWND hwndparent;
  78.         hwndparent=WinQueryWindow(hwnd,QW_OWNER);    
  79.         // search list of bookwindows for frame who owns this dlg.
  80.         // if found, create subset window.
  81.         boolean subset_found;
  82.         bookwindow *x;    
  83.         subset_found=false;
  84.         for (x=first; x!=NULL; x=x->next) 
  85.         if (x->hwndframe==hwndparent) 
  86.             WinPostMsg(x->hwnd,
  87.                    WM_USER_CREATE_SUBSET,
  88.                    (MPARAM)hwnd,
  89.                    0);
  90.         return (MRESULT)TRUE;
  91.         break;
  92.        
  93.     case DLG_CANCEL:
  94.         WinDismissDlg(hwnd,TRUE);
  95.         return (MRESULT)FALSE;
  96.         break;
  97.  
  98.     case DLG_HELP:
  99.         WinSendMsg(hwndhelp,
  100.                HM_DISPLAY_HELP,
  101.                MPFROMSHORT(19),
  102.                HM_RESOURCEID);
  103.         return (MRESULT)TRUE;
  104.         break;
  105.     }
  106.     break;
  107.     }
  108.     return (WinDefDlgProc(hwnd,msg,mp1,mp2));
  109. }
  110.  
  111. // dialog procedure for renaming spellbook
  112. MRESULT EXPENTRY rename_dlg_func(HWND hwnd, ULONG msg,
  113.                  MPARAM mp1, MPARAM mp2) {
  114.     int i;
  115.  
  116.     switch (msg) {
  117.     case WM_COMMAND: 
  118.     switch (SHORT1FROMMP(mp1)) {
  119.     case DLG_OK:
  120.         HWND hwndparent;
  121.         hwndparent=WinQueryWindow(hwnd,QW_OWNER);    
  122.         // search list of bookwindows for frame who owns this dlg.
  123.         // if found, rename it
  124.         bookwindow *x;    
  125.         for (x=first; x!=NULL; x=x->next) 
  126.         if (x->hwndframe==hwndparent) {
  127.             i=WinQueryDlgItemTextLength(hwnd,DLG_NEWNAME);
  128.             if (i>0) {
  129.             delete (x->sb->name);
  130.             x->sb->name=new char[i+1];
  131.             WinQueryDlgItemText(hwnd,DLG_NEWNAME,i+1,(PSZ)(x->sb->name));
  132.             WinSetWindowText(x->hwndframe,(PSZ)(x->sb->name));
  133.             x->saved=false;
  134.             }
  135.         }
  136.         WinDismissDlg(hwnd,TRUE);
  137.         return (MRESULT)TRUE;
  138.         break;
  139.  
  140.     case DLG_CANCEL:
  141.         WinDismissDlg(hwnd,TRUE);
  142.         return (MRESULT)FALSE;
  143.         break;
  144.     }
  145.     break;
  146.     }
  147.     return (WinDefDlgProc(hwnd,msg,mp1,mp2));
  148. }
  149.  
  150. // dialog procedure for about box
  151. MRESULT EXPENTRY about_dlg_func(HWND hwnd, ULONG msg,
  152.                 MPARAM mp1, MPARAM mp2) {
  153.     char buffer[256];
  154.     short w,h,x,y;
  155.     SWP swp;
  156.  
  157.     switch (msg) {
  158.     case WM_INITDLG:
  159.     // set version number
  160.      sprintf(buffer,"spl version %s",VERSION);
  161.     WinSetDlgItemText(hwnd,ABOUT_VERSION,buffer);
  162.  
  163.     // center box
  164.     w = WinQuerySysValue(HWND_DESKTOP,SV_CXSCREEN);
  165.     h = WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN);
  166.     WinQueryWindowPos(hwnd,&swp);
  167.     x = (SHORT)((w-swp.cx)/2);
  168.     y = (SHORT)((h-swp.cy)/2);
  169.     WinSetWindowPos(hwnd,HWND_TOP,x,y,0,0,SWP_MOVE);
  170.     break;
  171.  
  172.     case WM_COMMAND: 
  173.     WinDismissDlg(hwnd,TRUE);
  174.     return(MRESULT)FALSE;
  175.     }
  176.     return (WinDefDlgProc(hwnd,msg,mp1,mp2));
  177. }
  178.  
  179. // dialog procedure for which detailed fields to show
  180. MRESULT EXPENTRY fields_dlg_func(HWND hwnd, ULONG msg,
  181.                  MPARAM mp1, MPARAM mp2) {
  182.     SHORT w,h,x,y;
  183.     SWP swp;
  184.     static bookwindow *owner;
  185.     ULONG fields;
  186.  
  187.     switch (msg) {
  188.     case WM_INITDLG:
  189.     // center box
  190.     w = WinQuerySysValue(HWND_DESKTOP,SV_CXSCREEN);
  191.     h = WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN);
  192.     WinQueryWindowPos(hwnd,&swp);
  193.     x = (SHORT)((w-swp.cx)/2);
  194.     y = (SHORT)((h-swp.cy)/2);
  195.     WinSetWindowPos(hwnd,HWND_TOP,x,y,0,0,SWP_MOVE);
  196.  
  197.     // save owner
  198.     owner = (bookwindow *)mp2;
  199.  
  200.     // turn on appropriate buttons.
  201.     fields = owner->details_fields;
  202.     if (fields & FL_LEVEL)
  203.         WinSendMsg(WinWindowFromID(hwnd,F_LEVEL),BM_SETCHECK,(MPARAM)1,0);
  204.     if (fields & FL_CAST)
  205.         WinSendMsg(WinWindowFromID(hwnd,F_CAST),BM_SETCHECK,(MPARAM)1,0);
  206.     if (fields & FL_RANGE)
  207.         WinSendMsg(WinWindowFromID(hwnd,F_RANGE),BM_SETCHECK,(MPARAM)1,0);
  208.     if (fields & FL_DURATION)
  209.         WinSendMsg(WinWindowFromID(hwnd,F_DURATION),
  210.                BM_SETCHECK,(MPARAM)1,0);
  211.     if (fields & FL_AREA)
  212.         WinSendMsg(WinWindowFromID(hwnd,F_AREA),BM_SETCHECK,(MPARAM)1,0);
  213.     if (fields & FL_SPHERESCHOOL)
  214.         WinSendMsg(WinWindowFromID(hwnd,F_SPHERESCHOOL),
  215.                BM_SETCHECK,(MPARAM)1,0);
  216.     if (fields & FL_COMPONENTS)
  217.         WinSendMsg(WinWindowFromID(hwnd,F_COMPONENTS),
  218.                BM_SETCHECK,(MPARAM)1,0);
  219.     if (fields & FL_SAVE)
  220.         WinSendMsg(WinWindowFromID(hwnd,F_SAVE),BM_SETCHECK,(MPARAM)1,0);
  221.     break;
  222.  
  223.     case WM_COMMAND: 
  224.     switch (SHORT1FROMMP(mp1)) {
  225.     case DLG_OK:
  226.         fields = 0;
  227.         if (WinQueryButtonCheckstate(hwnd,F_LEVEL)==1)
  228.         fields |= FL_LEVEL;
  229.         if (WinQueryButtonCheckstate(hwnd,F_CAST)==1)
  230.         fields |= FL_CAST;
  231.         if (WinQueryButtonCheckstate(hwnd,F_RANGE)==1)
  232.         fields |= FL_RANGE;
  233.         if (WinQueryButtonCheckstate(hwnd,F_DURATION)==1)
  234.         fields |= FL_DURATION;
  235.         if (WinQueryButtonCheckstate(hwnd,F_AREA)==1)
  236.         fields |= FL_AREA;
  237.         if (WinQueryButtonCheckstate(hwnd,F_SPHERESCHOOL)==1)
  238.         fields |= FL_SPHERESCHOOL;
  239.         if (WinQueryButtonCheckstate(hwnd,F_COMPONENTS)==1)
  240.         fields |= FL_COMPONENTS;
  241.         if (WinQueryButtonCheckstate(hwnd,F_SAVE)==1)
  242.         fields |= FL_SAVE;  
  243.         WinPostMsg(owner->hwnd,
  244.                WM_USER_DETAILS_FIELDS,
  245.                (MPARAM)fields,
  246.                0);
  247.         WinDismissDlg(hwnd,TRUE);
  248.         return (MRESULT)TRUE;
  249.         break;
  250.        
  251.     case DLG_CANCEL:
  252.         WinDismissDlg(hwnd,TRUE);
  253.         return (MRESULT)FALSE;
  254.         break;
  255.  
  256.     case DLG_HELP:
  257.         WinSendMsg(hwndhelp,
  258.                HM_DISPLAY_HELP,
  259.                MPFROMSHORT(19),
  260.                HM_RESOURCEID);
  261.         return (MRESULT)TRUE;
  262.         break;
  263.     }
  264.     break;
  265.     }
  266.     return (WinDefDlgProc(hwnd,msg,mp1,mp2));
  267. }
  268.  
  269. // dialog procedure for how to sort spellbook
  270. MRESULT EXPENTRY sort_dlg_func(HWND hwnd, ULONG msg,
  271.                    MPARAM mp1, MPARAM mp2) {
  272.     SHORT w,h,x,y;
  273.     SWP swp;
  274.     static bookwindow *owner;
  275.     const PCHAR sortnames[7] = {"None",
  276.                 "Caster Type",
  277.                 "Name of Spell",
  278.                 "Spell Level",
  279.                 "School/Sphere",
  280.                 "Components",
  281.                 "Save"};
  282.     int sortby[5] = {1,2,0,0,0};
  283.     ULONG sortorder = 0;
  284.     int i,j;
  285.  
  286.     switch (msg) {
  287.     case WM_INITDLG:
  288.     // center box
  289.     w = WinQuerySysValue(HWND_DESKTOP,SV_CXSCREEN);
  290.     h = WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN);
  291.     WinQueryWindowPos(hwnd,&swp);
  292.     x = (SHORT)((w-swp.cx)/2);
  293.     y = (SHORT)((h-swp.cy)/2);
  294.     WinSetWindowPos(hwnd,HWND_TOP,x,y,0,0,SWP_MOVE);
  295.  
  296.     // save owner
  297.     owner = (bookwindow *)mp2;
  298.  
  299.     // fill in combo boxes w/ choices
  300.     for (i=0; i<5; i++) {
  301.         HWND hwndlbox = WinWindowFromID(hwnd,S_1+i);
  302.         for (j=0; j<7; j++)
  303.         WinInsertLboxItem(hwndlbox,LIT_END,sortnames[j]);
  304.         WinSendMsg(hwndlbox,
  305.                LM_SELECTITEM,
  306.                (MPARAM)sortby[i],
  307.                (MPARAM)TRUE);
  308.     }
  309.  
  310.     break;
  311.  
  312.     case WM_COMMAND: 
  313.     switch (SHORT1FROMMP(mp1)) {
  314.     case DLG_OK:
  315.         // figure out what the user wants to sort by:
  316.         for (i=4; i>=0; i--) {
  317.         HWND hwndlbox = WinWindowFromID(hwnd,S_1+i);
  318.         sortorder += WinQueryLboxSelectedItem(hwndlbox);
  319.         sortorder *= 7;
  320.         }
  321.         // tell owner to sort with these criteria
  322.         WinPostMsg(owner->hwnd,
  323.                WM_USER_SORT,
  324.                (MPARAM)sortorder,
  325.                0);
  326.         WinDismissDlg(hwnd,TRUE);
  327.         return (MRESULT)TRUE;
  328.         break;
  329.        
  330.     case DLG_CANCEL:
  331.         WinDismissDlg(hwnd,TRUE);
  332.         return (MRESULT)FALSE;
  333.         break;
  334.  
  335.     case DLG_HELP:
  336.         WinSendMsg(hwndhelp,
  337.                HM_DISPLAY_HELP,
  338.                MPFROMSHORT(19),
  339.                HM_RESOURCEID);
  340.         return (MRESULT)TRUE;
  341.         break;
  342.     }
  343.     break;
  344.     }
  345.     return (WinDefDlgProc(hwnd,msg,mp1,mp2));
  346. }
  347.