File: window_bids.c

package info (click to toggle)
tenace 0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,440 kB
  • ctags: 543
  • sloc: ansic: 5,303; sh: 3,683; makefile: 98
file content (107 lines) | stat: -rw-r--r-- 3,040 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 *  tenace - bridge hand viewer and editor
 *  Copyright (C) 2005-2007 Christoph Berg <cb@df7cb.de>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 */

#include <assert.h>
#include <string.h>

#include "bridge.h"
#include "functions.h"
#include "interface.h"
#include "support.h"

#include "window_board.h"

static GtkWidget *window_bids = 0;

static void
bid_clicked (GtkWidget *lab, int *bid)
{
	static GtkWidget *alert_entry = NULL;
	if (! alert_entry)
		alert_entry = lookup_widget (window_bids, "alert_entry");

	board *b = CUR_BOARD;
	int ret = board_append_bid (b, *bid, 1);

	if (!ret)
		return;

	PROTECT_BEGIN;
	const char *alert = gtk_entry_get_text (GTK_ENTRY (alert_entry));
	if (*alert) {
		board_set_alert (b, !strcmp (alert, "!") ? "" : alert);
		gtk_entry_set_text (GTK_ENTRY (alert_entry), "");
	}

	show_board (b, (ret == 2 ? REDRAW_FULL : REDRAW_BIDDING) | REDRAW_BIDDING_SCROLL);

	if (ret == 2) {
		char buf[50];
		snprintf (buf, sizeof (buf), _("Contract set to %s"),
			contract_string (b->level, b->trumps, b->declarer, b->doubled));
		board_statusbar (buf);
	}
	PROTECT_END;
}

void
window_bids_init ()
{
	if (window_bids)
		return;

	static int pass = bid_pass, x = bid_x, xx = bid_xx;
	static int bid[35];

	window_bids = create_window_bids ();
	gtk_widget_show (window_bids);
	GtkTable *bids_table = GTK_TABLE(lookup_widget(window_bids, "bids_table"));
	assert (bids_table);
	GtkWidget *lab;

	lab = gtk_button_new_with_label (_("PASS"));
	gtk_table_attach (bids_table, lab, 0, 3, 0, 1, GTK_FILL, 0, 0, 0);
	g_signal_connect (lab, "clicked", G_CALLBACK (bid_clicked), &pass);
	lab = gtk_button_new_with_label (_("X"));
	gtk_table_attach (bids_table, lab, 3, 4, 0, 1, GTK_FILL, 0, 0, 0);
	g_signal_connect (lab, "clicked", G_CALLBACK (bid_clicked), &x);
	lab = gtk_button_new_with_label (_("XX"));
	gtk_table_attach (bids_table, lab, 4, 5, 0, 1, GTK_FILL, 0, 0, 0);
	g_signal_connect (lab, "clicked", G_CALLBACK (bid_clicked), &xx);

	int d, l;
	for (l = 1; l <= 7; l++) {
		for (d = 0; d <= 4; d++) {
			GString *b = bid_string (5 * l + d, 0);
			lab = gtk_button_new_with_label (_(b->str));
			gtk_label_set_use_markup (GTK_LABEL (gtk_bin_get_child (GTK_BIN (lab))), TRUE);
			gtk_table_attach(bids_table, lab, d, d+1, l, l+1, GTK_FILL, 0, 0, 0);
			bid[5 * (l - 1) + d] = 5 * l + d;
			g_signal_connect (lab, "clicked",
					G_CALLBACK (bid_clicked), bid + (5 * (l - 1) + d));
		}
	}
	gtk_widget_show_all (window_bids);
}

void
window_bids_delete (void)
{
	if (!window_bids)
		return;

	gtk_widget_destroy (window_bids);
	window_bids = 0;
}