home *** CD-ROM | disk | FTP | other *** search
/ Más de 2,500 Juegos / CD1.iso / ZIPDAT / 0153 / 0153.ZIP / SRC / DIALOGS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-08  |  16.2 KB  |  546 lines

  1. /*
  2.  * dialogs.c - C source for GNU CHESS
  3.  *
  4.  * Copyright (c) 1996 Conor McCarthy
  5.  * Some code derived from from Chess 3.21 by Daryl Baker
  6.  *
  7.  * This file is part of GNU CHESS.
  8.  *
  9.  * GNU Chess is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2, or (at your option)
  12.  * any later version.
  13.  *
  14.  * GNU Chess is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with GNU Chess; see the file COPYING.  If not, write to
  21.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23.  
  24. #include "gnuchess.h"
  25.  
  26. char *lpszTitle;
  27. tshort DlgInt1,DlgInt2,DlgInt3,DlgInt4,DlgInt5,DlgInt6;
  28. long size;
  29. extern HBRUSH hDlgBkgrnd;
  30.  
  31. BOOL CALLBACK ChangeWinDlgProc (HWND hDlg, UINT Message,
  32.                                   WPARAM wParam, LPARAM lParam)
  33. {
  34.    BOOL ok;
  35.    switch ( Message )
  36.     {
  37.       case WM_INITDIALOG:
  38.          SetWindowText (hDlg,CP[69]);
  39.          SetDlgItemText (hDlg, IDC_APROMPT, CP[11]);
  40.          SetDlgItemText (hDlg, IDC_BPROMPT, CP[12]);
  41.          SetDlgItemText (hDlg, IDC_XPROMPT, CP[38]);
  42.          SetDlgItemText (hDlg, IDC_WHITE, CP[40]);
  43.          SetDlgItemText (hDlg, IDC_BLACK, CP[41]);
  44.          SetDlgItemInt ( hDlg, IDC_WA, WAwindow, true);
  45.          SetDlgItemInt ( hDlg, IDC_WB, WBwindow, true);
  46.          SetDlgItemInt ( hDlg, IDC_WX, WXwindow, true);
  47.          SetDlgItemInt ( hDlg, IDC_BA, BAwindow, true);
  48.          SetDlgItemInt ( hDlg, IDC_BB, BBwindow, true);
  49.          SetDlgItemInt ( hDlg, IDC_BX, BXwindow, true);
  50.          return true;
  51.  
  52. #ifdef WIN32
  53.       case WM_CTLCOLORSTATIC:
  54.         SetBkMode((HDC)wParam,TRANSPARENT);
  55.       case WM_CTLCOLORDLG:
  56.         return hDlgBkgrnd;
  57. #else
  58.       case WM_CTLCOLOR:
  59.         switch(HIWORD(lParam))
  60.          {
  61.           case CTLCOLOR_STATIC:
  62.            SetBkMode((HDC)wParam,TRANSPARENT);
  63.           case CTLCOLOR_DLG:
  64.            return hDlgBkgrnd;
  65.          }
  66.       return true;
  67. #endif
  68.  
  69.       case WM_COMMAND:
  70.          switch (LOWORD(wParam))
  71.           {
  72.             case IDOK:
  73.                DlgInt1 = GetDlgItemInt (hDlg,IDC_WA,&ok,true);
  74.                if (ok) DlgInt2 = GetDlgItemInt (hDlg,IDC_WB,&ok,true);
  75.                if (ok) DlgInt3 = GetDlgItemInt (hDlg,IDC_WX,&ok,true);
  76.                if (ok) DlgInt4 = GetDlgItemInt (hDlg,IDC_BA,&ok,true);
  77.                if (ok) DlgInt5 = GetDlgItemInt (hDlg,IDC_BB,&ok,true);
  78.                if (ok) DlgInt6 = GetDlgItemInt (hDlg,IDC_BX,&ok,true);
  79.                if (ok) EndDialog ( hDlg, true);
  80.                return true;
  81.  
  82.             case IDCANCEL:
  83.                EndDialog ( hDlg, false);
  84.                return true;
  85.          }
  86.     }
  87.    return false;
  88. }
  89.  
  90. BOOL CALLBACK HashDepthDlgProc (HWND hDlg, UINT Message,
  91.                                   WPARAM wParam, LPARAM lParam)
  92. {
  93.    BOOL ok;
  94.    switch ( Message )
  95.     {
  96.       case WM_INITDIALOG:
  97.          SetWindowText(hDlg,CP[63]);
  98.          SetDlgItemText (hDlg, IDC_DPROMPT, CP[49]);
  99.          SetDlgItemText (hDlg, IDC_MLPROMPT, CP[29]);
  100.          SetDlgItemInt ( hDlg, IDC_DEPTH, HashDepth, true);
  101.          SetDlgItemInt ( hDlg, IDC_MOVELIM, HashMoveLimit, true);
  102.          return true;
  103.  
  104. #ifdef WIN32
  105.       case WM_CTLCOLORSTATIC:
  106.         SetBkMode((HDC)wParam,TRANSPARENT);
  107.       case WM_CTLCOLORDLG:
  108.         return hDlgBkgrnd;
  109. #else
  110.       case WM_CTLCOLOR:
  111.         switch(HIWORD(lParam))
  112.          {
  113.           case CTLCOLOR_STATIC:
  114.            SetBkMode((HDC)wParam,TRANSPARENT);
  115.           case CTLCOLOR_DLG:
  116.            return hDlgBkgrnd;
  117.          }
  118.       return true;
  119. #endif
  120.  
  121.       case WM_COMMAND:
  122.          switch (LOWORD(wParam))
  123.           {
  124.             case IDOK:
  125.                DlgInt1 = GetDlgItemInt (hDlg,IDC_DEPTH,&ok,true);
  126.                if (ok) DlgInt2 = GetDlgItemInt (hDlg,IDC_MOVELIM,&ok,true);
  127.                if (ok) EndDialog ( hDlg, true);
  128.                return true;
  129.  
  130.             case IDCANCEL:
  131.                EndDialog ( hDlg, false);
  132.                return true;
  133.          }
  134.     }
  135.    return false;
  136. }
  137.  
  138. BOOL CALLBACK GetNumDlgProc (HWND hDlg, UINT Message,
  139.                                   WPARAM wParam, LPARAM lParam)
  140. {
  141.    BOOL ok;
  142.    switch ( Message )
  143.     {
  144.       case WM_INITDIALOG:
  145.          SetWindowText(hDlg,lpszTitle);
  146.          SetDlgItemText (hDlg, IDC_PROMPT, CP[lParam]);
  147.          SetDlgItemInt ( hDlg, IDC_NUM, DlgInt1, true);
  148.          return true;
  149.  
  150. #ifdef WIN32
  151.       case WM_CTLCOLORSTATIC:
  152.         SetBkMode((HDC)wParam,TRANSPARENT);
  153.       case WM_CTLCOLORDLG:
  154.         return hDlgBkgrnd;
  155. #else
  156.       case WM_CTLCOLOR:
  157.         switch(HIWORD(lParam))
  158.          {
  159.           case CTLCOLOR_STATIC:
  160.            SetBkMode((HDC)wParam,TRANSPARENT);
  161.           case CTLCOLOR_DLG:
  162.            return hDlgBkgrnd;
  163.          }
  164.       return true;
  165. #endif
  166.  
  167.       case WM_COMMAND:
  168.          switch (LOWORD(wParam))
  169.           {
  170.             case IDOK:
  171.                DlgInt1 = GetDlgItemInt (hDlg, IDC_NUM, &ok, true);
  172.                if (ok) EndDialog ( hDlg, true);
  173.                return true;
  174.  
  175.             case IDCANCEL:
  176.                EndDialog ( hDlg, false);
  177.                return true;
  178.          }
  179.     }
  180.    return false;
  181. }
  182.  
  183. BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT Message,
  184.                                   WPARAM wParam, LPARAM lParam)
  185. {
  186.    switch ( Message )
  187.     {
  188.       case WM_INITDIALOG:
  189.          return true;
  190.  
  191. #ifdef WIN32
  192.       case WM_CTLCOLORSTATIC:
  193.         SetBkMode((HDC)wParam,TRANSPARENT);
  194.       case WM_CTLCOLORDLG:
  195.         return hDlgBkgrnd;
  196. #else
  197.       case WM_CTLCOLOR:
  198.         switch(HIWORD(lParam))
  199.          {
  200.           case CTLCOLOR_STATIC:
  201.            SetBkMode((HDC)wParam,TRANSPARENT);
  202.           case CTLCOLOR_DLG:
  203.            return hDlgBkgrnd;
  204.          }
  205.       return true;
  206. #endif
  207.  
  208.       case WM_COMMAND:
  209.          if (LOWORD(wParam)==IDOK)
  210.            {
  211.              EndDialog ( hDlg, true);
  212.              return true;
  213.            }
  214.     }
  215.    return false;
  216. }
  217.  
  218. BOOL CALLBACK TimeDlgProc (HWND hDlg, UINT Message,
  219.                                   WPARAM wParam, LPARAM lParam)
  220. {
  221.    BOOL ok;
  222.    SHORT tXCmoves,tXCminutes,i;
  223.    switch ( Message )
  224.     {
  225.       case WM_INITDIALOG:
  226.          SetWindowText(hDlg,CP[65]);
  227.          SetDlgItemInt (hDlg, IDC_MOVES1, XCmoves[0],false);
  228.          SetDlgItemInt (hDlg, IDC_MINS1, XCminutes[0], false);
  229.          SetDlgItemInt (hDlg, IDC_MOVES2, XCmoves[1],false);
  230.          SetDlgItemInt (hDlg, IDC_MINS2, XCminutes[1], false);
  231.          SetDlgItemInt (hDlg, IDC_MOVES3, XCmoves[2],false);
  232.          SetDlgItemInt (hDlg, IDC_MINS3, XCminutes[2], false);
  233.          SetDlgItemInt (hDlg, IDC_MAXRT, MaxResponseTime/100, false);
  234.          for (i=0;i<3;i++)
  235.           {
  236.            SendDlgItemMessage(hDlg,IDC_MOVES1+i,CB_ADDSTRING,0,(long)"1");
  237.            SendDlgItemMessage(hDlg,IDC_MOVES1+i,CB_ADDSTRING,0,(long)"10");
  238.            SendDlgItemMessage(hDlg,IDC_MOVES1+i,CB_ADDSTRING,0,(long)"20");
  239.            SendDlgItemMessage(hDlg,IDC_MOVES1+i,CB_ADDSTRING,0,(long)"40");
  240.            SendDlgItemMessage(hDlg,IDC_MOVES1+i,CB_ADDSTRING,0,(long)"60");
  241.            SendDlgItemMessage(hDlg,IDC_MINS1+i,CB_ADDSTRING,0,(long)"5");
  242.            SendDlgItemMessage(hDlg,IDC_MINS1+i,CB_ADDSTRING,0,(long)"15");
  243.            SendDlgItemMessage(hDlg,IDC_MINS1+i,CB_ADDSTRING,0,(long)"30");
  244.            SendDlgItemMessage(hDlg,IDC_MINS1+i,CB_ADDSTRING,0,(long)"60");
  245.            SendDlgItemMessage(hDlg,IDC_MINS1+i,CB_ADDSTRING,0,(long)"600");
  246.           }
  247.          if (!XCmoves[0] || !XCminutes[0])
  248.           { EnableWindow(GetDlgItem(hDlg, IDC_MOVES2),false);
  249.             EnableWindow(GetDlgItem(hDlg, IDC_MOVES3),false);
  250.             EnableWindow(GetDlgItem(hDlg, IDC_MINS2),false);
  251.             EnableWindow(GetDlgItem(hDlg, IDC_MINS3),false);
  252.           }
  253.          else
  254.           { EnableWindow(GetDlgItem(hDlg, IDC_MAXRT),false);
  255.             EnableWindow(GetDlgItem(hDlg, IDC_MRTEXT),false);
  256.             EnableWindow(GetDlgItem(hDlg, IDC_MRSECS),!ok);
  257.             if (!XCmoves[1] || !XCminutes[0])
  258.              { EnableWindow(GetDlgItem(hDlg, IDC_MOVES3),false);
  259.                EnableWindow(GetDlgItem(hDlg, IDC_MINS3),false);
  260.              }
  261.           }
  262.          return true;
  263.  
  264. #ifdef WIN32
  265.       case WM_CTLCOLORSTATIC:
  266.         SetBkMode((HDC)wParam,TRANSPARENT);
  267.       case WM_CTLCOLORDLG:
  268.         return hDlgBkgrnd;
  269. #else
  270.       case WM_CTLCOLOR:
  271.         switch(HIWORD(lParam))
  272.          {
  273.           case CTLCOLOR_STATIC:
  274.            SetBkMode((HDC)wParam,TRANSPARENT);
  275.           case CTLCOLOR_DLG:
  276.            return hDlgBkgrnd;
  277.          }
  278.       return true;
  279. #endif
  280.  
  281.       case WM_COMMAND:
  282.          if (HIWORD(wParam)==CBN_EDITCHANGE||HIWORD(wParam)==CBN_SELCHANGE)
  283.            /*if these messages are processed here, the GetDlgItemInt
  284.              function will retrieve the old value, not the new one*/
  285.              PostMessage(hDlg,WM_USER+100,wParam,0);
  286.          else switch (LOWORD(wParam))
  287.           {
  288.             case IDOK:
  289.                for (i=0;i<3;i++)
  290.                 {
  291.                  XCmoves[i]=GetDlgItemInt (hDlg, IDC_MOVES1+i, &ok, false);
  292.                  XCminutes[i]=GetDlgItemInt (hDlg, IDC_MINS1+i, &ok, false);
  293.                 }
  294.                XC=0;
  295.                for (i=0;i<3;i++)
  296.                 {
  297.                  if (XCmoves[i] && XCminutes[i])XC++;
  298.                  else break;
  299.                 }
  300.                if (!XC)
  301.                 {
  302.                   MaxResponseTime=GetDlgItemInt (hDlg, IDC_MAXRT,
  303.                                   &ok, false)*100;
  304.                   if (!MaxResponseTime)
  305.                      MaxResponseTime=600;
  306.                   SetTimeControl();
  307.                   EndDialog(hDlg,true);
  308.                 }
  309.                else
  310.                 {
  311.                   XCmore=0;
  312.                   TimeControl.clock[white] = TimeControl.clock[black] = 0;
  313.                   SetTimeControl();
  314.                   EndDialog ( hDlg, true);
  315.                 }
  316.                return true;
  317.  
  318.             case IDCANCEL:
  319.                EndDialog ( hDlg, false);
  320.                return true;
  321.          }
  322.       case WM_USER+100:
  323.         switch(LOWORD(wParam))
  324.           {
  325.            case IDC_MOVES1:
  326.            case IDC_MINS1:
  327.              tXCmoves=GetDlgItemInt(hDlg,IDC_MOVES1,&ok,false);
  328.              tXCminutes=GetDlgItemInt(hDlg,IDC_MINS1,&ok,false);
  329.              if (!tXCmoves || !tXCminutes)ok=false;
  330.              else ok=true;
  331.              EnableWindow(GetDlgItem(hDlg, IDC_MAXRT),!ok);
  332.              EnableWindow(GetDlgItem(hDlg, IDC_MRTEXT),!ok);
  333.              EnableWindow(GetDlgItem(hDlg, IDC_MRSECS),!ok);
  334.              EnableWindow(GetDlgItem(hDlg, IDC_MOVES2),ok);
  335.              EnableWindow(GetDlgItem(hDlg, IDC_MINS2),ok);
  336.              if (!ok)
  337.               {
  338.                EnableWindow(GetDlgItem(hDlg, IDC_MOVES3),false);
  339.                EnableWindow(GetDlgItem(hDlg, IDC_MINS3),false);
  340.                break;
  341.               }
  342.            case IDC_MOVES2:
  343.            case IDC_MINS2:
  344.              tXCmoves=GetDlgItemInt(hDlg,IDC_MOVES2,&ok,false);
  345.              tXCminutes=GetDlgItemInt(hDlg,IDC_MINS2,&ok,false);
  346.              if (!tXCmoves || !tXCminutes)ok=false;
  347.              else ok=true;
  348.              EnableWindow(GetDlgItem(hDlg, IDC_MOVES3),ok);
  349.              EnableWindow(GetDlgItem(hDlg, IDC_MINS3),ok);
  350.              break;
  351.           }
  352.         return true;
  353.     }
  354.    return false;
  355. }
  356.  
  357. BOOL CALLBACK StatDlgProc ( HWND hDlg, UINT Message,
  358.                                WPARAM wParam, LPARAM lParam)
  359. {
  360.  
  361.    switch (Message)
  362.     {
  363.       case WM_INITDIALOG:
  364.          return (true);
  365.  
  366. #ifdef WIN32
  367.       case WM_CTLCOLORBTN:
  368.       case WM_CTLCOLORSTATIC:
  369.         SetBkMode((HDC)wParam,TRANSPARENT);
  370.       case WM_CTLCOLORDLG:
  371.         return hDlgBkgrnd;
  372. #else
  373.       case WM_CTLCOLOR:
  374.         switch(HIWORD(lParam))
  375.          {
  376.           case CTLCOLOR_BTN:
  377.           case CTLCOLOR_STATIC:
  378.            SetBkMode((HDC)wParam,TRANSPARENT);
  379.           case CTLCOLOR_DLG:
  380.            return hDlgBkgrnd;
  381.          }
  382.       return true;
  383. #endif
  384.  
  385.       case WM_COMMAND:
  386.          if (LOWORD(wParam)==IDOK)
  387.           {
  388. destroy:
  389.             DestroyWindow(hDlg);
  390.             flag.post=false;
  391.             return true;
  392.           }
  393.          break;
  394.  
  395.       case WM_SYSCOMMAND:
  396.          if ((wParam & 0xFFF0) == SC_CLOSE) goto destroy;
  397.          break;
  398.     }
  399.  
  400.     return (false);              /* Didn't process a message    */
  401. }
  402.  
  403. BOOL CALLBACK TypeMoveDlgProc (HWND hDlg, UINT Message,
  404.                                   WPARAM wParam, LPARAM lParam)
  405. {
  406.    switch (Message)
  407.     {
  408.      case WM_INITDIALOG:
  409.        SetWindowText(hDlg,szAppName);
  410.        SetDlgItemText(hDlg, IDC_PROMPT, CP[42]);
  411.        SendMessage ( GetDlgItem(hDlg, IDC_NUM), EM_LIMITTEXT, 5, 0);
  412.        return true;
  413.  
  414. #ifdef WIN32
  415.       case WM_CTLCOLORSTATIC:
  416.         SetBkMode((HDC)wParam,TRANSPARENT);
  417.       case WM_CTLCOLORDLG:
  418.         return hDlgBkgrnd;
  419. #else
  420.       case WM_CTLCOLOR:
  421.         switch(HIWORD(lParam))
  422.          {
  423.           case CTLCOLOR_STATIC:
  424.            SetBkMode((HDC)wParam,TRANSPARENT);
  425.           case CTLCOLOR_DLG:
  426.            return hDlgBkgrnd;
  427.          }
  428.       return true;
  429. #endif
  430.  
  431.      case WM_COMMAND:
  432.        switch (LOWORD(wParam))
  433.          {
  434.           case IDOK:
  435.             if (GetDlgItemText ( hDlg, IDC_NUM, move, 6))
  436.              {
  437.                EndDialog (hDlg, true);
  438.                break;
  439.              }
  440.           case IDCANCEL:
  441.             EndDialog (hDlg, false);
  442.             break;
  443.  
  444.           default: return false;
  445.          }
  446.        return true;
  447.     }
  448.    return false;
  449. }
  450.  
  451. BOOL CALLBACK PromoteDlgProc ( HWND hDlg, UINT Message,
  452.                                WPARAM wParam, LPARAM lParam)
  453. {
  454.  
  455.    switch (Message)
  456.     {
  457.       case WM_INITDIALOG:
  458.          SetWindowText(hDlg,CP[66]);
  459.          DlgInt1 = 5;
  460.          CheckRadioButton ( hDlg, 101, 104, 104);
  461.          return true;
  462.  
  463. #ifdef WIN32
  464.       case WM_CTLCOLORBTN:
  465.       case WM_CTLCOLORSTATIC:
  466.         SetBkMode((HDC)wParam,TRANSPARENT);
  467.       case WM_CTLCOLORDLG:
  468.         return hDlgBkgrnd;
  469. #else
  470.       case WM_CTLCOLOR:
  471.         switch(HIWORD(lParam))
  472.          {
  473.           case CTLCOLOR_BTN:
  474.           case CTLCOLOR_STATIC:
  475.            SetBkMode((HDC)wParam,TRANSPARENT);
  476.           case CTLCOLOR_DLG:
  477.            return hDlgBkgrnd;
  478.          }
  479.       return true;
  480. #endif
  481.  
  482.       case WM_COMMAND:
  483.          switch (LOWORD(wParam))
  484.           {
  485.             case IDOK:
  486.                EndDialog ( hDlg, DlgInt1);
  487.                return true;
  488.  
  489.             case 101:
  490.             case 102:
  491.             case 103:
  492.             case 104:
  493.                DlgInt1 = wParam-99;
  494.                CheckRadioButton ( hDlg, 101, 104, LOWORD(wParam));
  495.                return true;
  496.          }
  497.     }
  498.    return (false);               /* Didn't process a message    */
  499. }
  500.  
  501. BOOL CALLBACK CreateHashDlgProc (HWND hDlg, UINT Message,
  502.                                   WPARAM wParam, LPARAM lParam)
  503. {
  504.    char szsize[7];
  505.    switch ( Message )
  506.     {
  507.       case WM_INITDIALOG:
  508.          SetWindowText(hDlg,CP[67]);
  509.          SetDlgItemText (hDlg, IDC_PROMPT, CP[68]);
  510.          SendDlgItemMessage(hDlg,IDC_HFSIZE,EM_LIMITTEXT,6,0);
  511.          return true;
  512.  
  513. #ifdef WIN32
  514.       case WM_CTLCOLORSTATIC:
  515.         SetBkMode((HDC)wParam,TRANSPARENT);
  516.       case WM_CTLCOLORDLG:
  517.         return hDlgBkgrnd;
  518. #else
  519.       case WM_CTLCOLOR:
  520.         switch(HIWORD(lParam))
  521.          {
  522.           case CTLCOLOR_STATIC:
  523.            SetBkMode((HDC)wParam,TRANSPARENT);
  524.           case CTLCOLOR_DLG:
  525.            return hDlgBkgrnd;
  526.          }
  527.       return true;
  528. #endif
  529.  
  530.       case WM_COMMAND:
  531.          switch (LOWORD(wParam))
  532.           {
  533.             case IDOK:
  534.                GetDlgItemText (hDlg,IDC_HFSIZE,szsize,7);
  535.                size = strtol (szsize,0,10);
  536.                EndDialog ( hDlg, true);
  537.                return true;
  538.  
  539.             case IDCANCEL:
  540.                EndDialog ( hDlg, false);
  541.                return true;
  542.          }
  543.     }
  544.    return false;
  545. }
  546.