Completely get rid of unused m4/ directory
[shogivar/ydirson.git] / menus.c
blobffacf9ca8352063ee5de343c640f43c457b1f647
1 /*
2 * menus.c -- platform-indendent menu handling code for ShogiVar (adapted from XBoard)
4 * Copyright 1991 by Digital Equipment Corporation, Maynard,
5 * Massachusetts.
7 * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
8 * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
10 * The following terms apply to Digital Equipment Corporation's copyright
11 * interest in XBoard:
12 * ------------------------------------------------------------------------
13 * All Rights Reserved
15 * Permission to use, copy, modify, and distribute this software and its
16 * documentation for any purpose and without fee is hereby granted,
17 * provided that the above copyright notice appear in all copies and that
18 * both that copyright notice and this permission notice appear in
19 * supporting documentation, and that the name of Digital not be
20 * used in advertising or publicity pertaining to distribution of the
21 * software without specific, written prior permission.
23 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
24 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
25 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
26 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
27 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
28 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
29 * SOFTWARE.
30 * ------------------------------------------------------------------------
32 * The following terms apply to the enhanced version of XBoard
33 * distributed by the Free Software Foundation:
34 * ------------------------------------------------------------------------
36 * GNU XBoard is free software: you can redistribute it and/or modify
37 * it under the terms of the GNU General Public License as published by
38 * the Free Software Foundation, either version 3 of the License, or (at
39 * your option) any later version.
41 * GNU XBoard is distributed in the hope that it will be useful, but
42 * WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
44 * General Public License for more details.
46 * You should have received a copy of the GNU General Public License
47 * along with this program. If not, see http://www.gnu.org/licenses/. *
49 *------------------------------------------------------------------------
50 ** See the file ChangeLog for a revision history. */
52 #define HIGHDRAG 1
54 #include "config.h"
56 #include <stdio.h>
57 #include <ctype.h>
58 #include <string.h>
59 #include <signal.h>
60 #include <errno.h>
61 #include <sys/types.h>
62 #include <sys/stat.h>
63 #include <pwd.h>
64 #include <math.h>
66 #if STDC_HEADERS
67 # include <stdlib.h>
68 # include <string.h>
69 #else /* not STDC_HEADERS */
70 extern char *getenv();
71 # if HAVE_STRING_H
72 # include <string.h>
73 # else /* not HAVE_STRING_H */
74 # include <strings.h>
75 # endif /* not HAVE_STRING_H */
76 #endif /* not STDC_HEADERS */
78 #if HAVE_UNISTD_H
79 # include <unistd.h>
80 #endif
82 #if ENABLE_NLS
83 #include <locale.h>
84 #endif
86 // [HGM] bitmaps: put before incuding the bitmaps / pixmaps, to know how many piece types there are.
88 #include "common.h"
89 #include "backend.h"
90 #include "frontend.h"
91 #include "menus.h"
92 #include "dialogs.h"
93 #include "gettext.h"
95 #ifdef ENABLE_NLS
96 # define _(s) gettext (s)
97 # define N_(s) gettext_noop (s)
98 #else
99 # define _(s) (s)
100 # define N_(s) s
101 #endif
104 * Button/menu procedures
108 int shiftKey, controlKey;
109 char *gameCopyFilename, *gamePasteFilename;
111 void
112 DoChange ()
114 Destroy(BoardDlg);
115 Main();
118 void
119 ChangeGameProc ()
121 Board.Timer1.Enabled = False;
122 ChangeGame();
123 ScheduleDelayedEvent(&DoChange, 500);
126 void
127 SaveGameProc ()
129 if(FileNamePopUpWrapper("Save Game", "", "*.gam", NULL, 0, "w", Board.CMSave.Filename, NULL))
130 SaveGame();
133 void
134 DiagramProc ()
136 if(FileNamePopUpWrapper("Create Text Diagram", "", "*.txt", NULL, 0, "w", Board.CMDiagram.Filename, NULL))
137 DiagramFile();
140 void
141 SmallProc ()
143 if(FileNamePopUpWrapper("Create Small Text Diagram", "", "*.txt", NULL, 0, "w", Board.CMDiagram.Filename, NULL))
144 DiagramSmall();
147 void
148 LoadGameProc ()
150 if(FileNamePopUpWrapper("Load Game", "", "*.gam", NULL, 0, "r", Board.CMSave.Filename, NULL))
151 LoadGame();
152 DrawBoard();
155 void
156 QuitProc ()
158 // Unload Start;
159 ConfigSave();
160 exit(0);
163 void
164 ClearProc ()
166 EndSetup();
167 ClearBoard();
168 DrawBoard();
171 void
172 RotateProc ()
174 Rotate();
175 DrawBoard();
178 void
179 AddBlackProc ()
181 strcpy(ExtraPiece, "Black"); CheckAdd();
184 void
185 AddWhiteProc ()
187 strcpy(ExtraPiece, "White"); CheckAdd();
190 void
191 RemoveProc ()
193 EndSetup();
194 Reduce = 1; SetHandicap();
197 void
198 TurnProc ()
200 if(strcmp(Turn, "White") ) strcpy(Turn, "White"); else strcpy(Turn, "Black");
201 MarkMenuItem("Setup.Turn", !strcpy(Turn, "White"));
204 void
205 MovePieceProc ()
207 EndSetup();
208 MovePieces();
211 void
212 ForceProc ()
214 EndMove = 1;
217 void
218 NewGameProc ()
220 if(LegalMoves == 0) {
221 NewGame = 1;
222 SetPieces();
224 DrawBoard();
227 void
228 PieceHelpProc ()
230 // PieceHelp.Show();
231 LoadPieceHelp();
234 void
235 HandicapProc ()
237 EndSetup(); SetHandicap();
240 void
241 NothingProc ()
243 return;
246 # define MARK_MENU_ITEM(X,Y) MarkMenuItem(X, Y)
248 void
249 ShowLegalProc ()
251 SeeMove = !SeeMove;
252 SeeMoves();
253 MARK_MENU_ITEM("Moves.ShowLegal", SeeMove);
256 void
257 ShowThreatsProc ()
259 strcpy(Threat, strcmp(Threat, "On") ? "On" : "Off");
260 SetThreat();
261 MARK_MENU_ITEM("Moves.ShowTheat", !strcmp(Threat, "On"));
264 void
265 EvaluateProc ()
267 Eval = !Eval;
268 if (!Eval) strcpy(Board.Caption, Cap);
269 strcpy(Board.PieceID.Caption, Eval ? "Evaluation On" : "Evaluation Off");
270 SetEval();
271 MARK_MENU_ITEM("Moves.Evaluate", Eval);
274 void
275 CompWhiteProc ()
277 int w; // white is a computer player
278 if(!strcmp(Computer, "White")) w = 0, strcpy( Computer, "None"); else
279 if(!strcmp(Computer, "Both")) w = 0, strcpy( Computer, "Black"); else
280 if(!strcmp(Computer, "Black")) w = 1, strcpy( Computer, "Both"); else
281 if(!strcmp(Computer, "None")) w = 1, strcpy( Computer, "White");
282 SetWhitePlayer();
283 MARK_MENU_ITEM("Setup.CompWhite", w);
284 if (w && !strcmp(Turn, "White")) CompMain();
287 void
288 CompBlackProc ()
290 int b; // black is a computer player
291 if(!strcmp(Computer, "Black")) b = 0, strcpy( Computer, "None"); else
292 if(!strcmp(Computer, "Both")) b = 0, strcpy( Computer, "White"); else
293 if(!strcmp(Computer, "White")) b = 1, strcpy( Computer, "Both"); else
294 if(!strcmp(Computer, "None")) b = 1, strcpy( Computer, "Black");
295 SetBlackPlayer();
296 MARK_MENU_ITEM("Setup.CompBlack", b);
297 if (b && !strcmp(Turn, "Black")) CompMain();
300 void
301 LevelProc ()
302 { // Toggle between Weak and Less Weak
303 strcpy(Grade, strcmp(Grade, "LessWeak") ? "LessWeak": "Weak");
304 SetDifficulty();
305 MARK_MENU_ITEM("Setup.LessWeak", !strcmp(Grade, "LessWeak"));
308 void
309 NotateProc ()
311 Notate = !Notate;
312 Notation();
313 DrawBoard();
314 MARK_MENU_ITEM("Setup.Notate", !Notate);
317 void
318 FlashProc ()
320 ShowLast = !ShowLast;
321 SetLastMove();
322 MARK_MENU_ITEM("Moves.Flash", ShowLast);
325 void
326 AutoPromProc ()
328 AutoPromote = !AutoPromote;
329 SetAutoPromote();
330 MARK_MENU_ITEM("Setup.AutoProm", AutoPromote);
333 void
334 ClocksProc ()
336 Timing = !Timing;
337 if(Timing) ClocksOff(); else ClocksOn();
338 MARK_MENU_ITEM("Setup.Clocks", !Timing);
339 if(Board.Timer1.Enabled) StartClockTimer(1000);
343 void
344 PiecesProc ()
346 static int western;
347 western = !western;
348 MARK_MENU_ITEM("Setup.Japanese", !western);
351 void
352 LionHawkProc ()
354 int v; char c;
355 if(LionHawkVer == 2) LionHawkVer = 1, v = 42, c = 'L';
356 else LionHawkVer = 2, v = 26, c = 'D';
357 Pieces[47].Value = Pieces[64].Value = Pieces[18].PrValue = v;
358 Pieces[47].special = Pieces[64].special = c;
359 SetLionHawk();
360 MARK_MENU_ITEM("Setup.LionHawk", LionHawkVer == 2);
364 * Menu definition tables
367 MenuItem gameMenu[] = {
368 {N_("New Game"), "<Ctrl>n", "NewGame", NewGameProc },
369 {N_("Load Game"), "<Ctrl>o", "LoadGame", LoadGameProc },
370 {N_("Save Game"), "<Ctrl>s", "SaveGame", SaveGameProc },
371 {N_("Change Game"), "<Ctrl>s", "ChangeGame", ChangeGameProc },
372 {"----", NULL, NULL, NothingProc },
373 {N_("Quit "), "<Ctrl>q", "Quit", QuitProc },
374 {NULL, NULL, NULL, NULL}
377 MenuItem movesMenu[] = {
378 {N_("Show Legal Moves"), NULL, "ShowLegal", ShowLegalProc, CHECK },
379 {N_("Show Influence/Threats"), "<ctrl>i", "ShowThreat", ShowThreatsProc, CHECK },
380 {N_("Flash Last Move"), NULL, "Flash", FlashProc, CHECK },
381 {"----", NULL, NULL, NothingProc },
382 {N_("Force Move"), "<ctrl>f", "ForceMove", ForceProc },
383 {"----", NULL, NULL, NothingProc },
384 {N_("Take Back"), "<ctrl>b", "TakeBack", TakeBack },
385 {N_("Take Back All"), "<shift>Delete", "BackAll", TakeAll },
386 {"----", NULL, NULL, NothingProc},
387 {N_("Replay"), "<ctrl>r", "Replay", Replay },
388 {N_("Replay All"), "<shift>Insert", "RepAll", ReplayAll },
389 {"----", NULL, NULL, NothingProc },
390 {N_("Suggest Move"), "<ctrl>m", "Suggest", SetSuggest },
391 {"----", NULL, NULL, NothingProc},
392 {N_("Evaluate"), "<ctrl>e", "Evaluate", EvaluateProc, CHECK },
393 {"----", NULL, NULL, NothingProc },
394 {N_("Print Moves"), "<ctrl>p", "PrintMoves", PrintScore },
395 {"----", NULL, NULL, NothingProc },
396 {N_("Create Text Score"), "<ctrl>t", "CreateLarge", DiagramProc },
397 {N_("Create Text Diagram"), "<ctrl>y" , "CreateSmall", SmallProc },
398 {NULL, NULL, NULL, NULL}
401 MenuItem setupMenu[] = {
402 {N_("Computer White"), NULL, "CompWhite", CompWhiteProc, CHECK },
403 {N_("Computer Black"), NULL, "CompBlack", CompBlackProc, CHECK },
404 {"----", NULL, NULL, NothingProc },
405 {N_("Rotate Board"), "<ctrl>w", "Rotate", RotateProc },
406 {"----", NULL, NULL, NothingProc },
407 {N_("Switch Sides"), "<ctrl>x", "SwitchSides", SwitchCompPlayer },
408 {"----", NULL, NULL, NothingProc },
409 {N_("Difficulty Less Weak"), "F6", "LessWeak", LevelProc, CHECK },
410 {"----", NULL, NULL, NothingProc },
411 {N_("Notation"), NULL, "Notation", NotateProc, CHECK },
412 {N_("Clocks"), NULL, "Clocks", ClocksProc, CHECK },
413 {N_("Auto Promotion"), "<ctrl>a", "AutoProm", AutoPromProc, CHECK },
414 {"----", NULL, NULL, NothingProc },
415 {N_("Clear Board"), NULL, "Clear", ClearProc },
416 {N_("Add Black Pieces"), NULL, "AddBlack", AddBlackProc },
417 {N_("Add White Pieces"), NULL, "AddWhite", AddWhiteProc },
418 {N_("Remove Pieces"), NULL, "Remove", RemoveProc },
419 {N_("Move Pieces"), NULL, "Setup", MovePieceProc },
420 {N_("White to Move"), NULL, "Turn", TurnProc, CHECK },
421 {N_("Set Handicap"), "<ctrl>h", "Handicap", HandicapProc },
422 {"----", NULL, NULL, NothingProc },
423 {N_("Japanese Pieces"), NULL, "Japanese", PiecesProc, CHECK },
424 {"----", NULL, NULL, NothingProc },
425 {N_("Lion Hawk Version 2"), NULL, "LionHawk", LionHawkProc, CHECK },
426 {NULL, NULL, NULL, NULL}
429 MenuItem helpMenu[] = {
430 {N_("About"), "F1", "About", AboutProc },
431 {"----", NULL, NULL, NothingProc},
432 {N_("General"), "F2", "General", SetGeneral },
433 {N_("Rules"), "F3", "Rules", SetRules },
434 {N_("Piece Help"), "F4", "PieceHelp", PieceHelpProc},
435 {NULL, NULL, NULL, NULL}
438 MenuItem noMenu[] = {
439 {NULL, NULL, NULL, NULL}
442 Menu menuBar[] = {
443 {N_("Game"), "Game", gameMenu},
444 {N_("Moves"), "Moves", movesMenu},
445 {N_("Set-Up"), "Setup", setupMenu},
446 {N_("Help"), "Help", helpMenu},
447 {NULL, NULL, NULL}
450 MenuItem *
451 MenuNameToItem (char *menuName)
453 int i=0;
454 char buf[512], *p;
455 MenuItem *menuTab;
456 static MenuItem a = { NULL, NULL, NULL, NothingProc };
457 extern Option mainOptions[];
458 strncpy(buf, menuName, 511);
459 p = strchr(buf, '.');
460 if(!p) menuTab = noMenu, p = menuName; else {
461 *p++ = '\0';
462 for(i=0; menuBar[i].name; i++)
463 if(!strcmp(buf, menuBar[i].ref)) break;
464 if(!menuBar[i].name) return NULL; // main menu not found
465 menuTab = menuBar[i].mi;
467 if(*p == '\0') { a.handle = mainOptions[i+1].handle; return &a; } // main menu bar
468 for(i=0; menuTab[i].string; i++)
469 if(menuTab[i].ref && !strcmp(p, menuTab[i].ref)) return menuTab + i;
470 return NULL; // item not found
473 Enables icsEnables[] = {
474 { "File.MailMove", False },
475 { NULL, False }
478 void
479 GreyRevert (Boolean grey)
481 EnableNamedMenuItem("Edit.Revert", !grey);
482 EnableNamedMenuItem("Edit.Annotate", !grey);
485 void
486 InitMenuMarkers()
488 MarkMenuItem("Setup.Japanese", True);
489 MarkMenuItem("Setup.Clocks", !Timing);
490 MarkMenuItem("Setup.Notation", !Notate);
491 MarkMenuItem("Moves.Flash", ShowLast);
492 MarkMenuItem("Moves.ShowLegal", SeeMove);
493 MarkMenuItem("Moves.Evaluate", Eval);
494 MarkMenuItem("Moves.ShowThreat", !strcmp(Threat, "On"));
495 MarkMenuItem("Setup.LessWeak", !strcmp(Grade, "LessWeak"));
496 MarkMenuItem("Setup.CompWhite", !strcmp(Computer, "White") || !strcmp(Computer, "Both"));
497 MarkMenuItem("Setup.CompBlack", !strcmp(Computer, "Black") || !strcmp(Computer, "Both"));
498 if(strcmp(Choice, "Tenjiku")) {
499 EnableNamedMenuItem("Setup.LionHawk", False);
500 } else {
501 EnableNamedMenuItem("Setup.LionHawk", True);
502 MarkMenuItem("Setup.LionHawk", LionHawkVer == 2);