]> git.saurik.com Git - wxWidgets.git/blame - demos/forty/playerdg.cpp
Don't use gtk_file_chooser_set_filename() for save file dialogs.
[wxWidgets.git] / demos / forty / playerdg.cpp
CommitLineData
63cafd27
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: playerdg.cpp
3// Purpose: Forty Thieves patience game
4// Author: Chris Breeze
5// Modified by:
6// Created: 21/07/97
7// RCS-ID: $Id$
8// Copyright: (c) 1993-1998 Chris Breeze
2a21ac15 9// Licence: wxWindows licence
63cafd27
JS
10/////////////////////////////////////////////////////////////////////////////
11
63cafd27
JS
12// For compilers that support precompilation, includes "wx/wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20#include "wx/wx.h"
21#endif
22
23#include "scorefil.h"
24#include "playerdg.h"
25
26const int ID_LISTBOX = 101;
27
28BEGIN_EVENT_TABLE(PlayerSelectionDialog, wxDialog)
2a21ac15
DS
29 EVT_SIZE(PlayerSelectionDialog::OnSize)
30 EVT_BUTTON(wxID_OK, PlayerSelectionDialog::ButtonCallback)
31 EVT_BUTTON(wxID_CANCEL, PlayerSelectionDialog::ButtonCallback)
32 EVT_LISTBOX(ID_LISTBOX, PlayerSelectionDialog::SelectCallback)
e3065973 33 EVT_CLOSE(PlayerSelectionDialog::OnCloseWindow)
63cafd27
JS
34END_EVENT_TABLE()
35
36PlayerSelectionDialog::PlayerSelectionDialog(
2a21ac15
DS
37 wxWindow* parent,
38 ScoreFile* file
39 ) :
9a83f860 40 wxDialog(parent, wxID_ANY, wxT("Player Selection"), wxDefaultPosition),
2a21ac15 41 m_scoreFile(file)
63cafd27 42{
9a83f860 43 wxStaticText* msg = new wxStaticText(this, wxID_ANY, wxT("Please select a name or type a new one:"));
2a21ac15
DS
44
45 wxListBox* list = new wxListBox(
46 this, ID_LISTBOX,
68ca12fe 47 wxDefaultPosition, wxSize(-1, 150),
2a21ac15
DS
48 0, 0,
49 wxLB_SINGLE
50 );
51
52 wxArrayString players;
53 m_scoreFile->GetPlayerList(players);
54 for (unsigned int i = 0; i < players.Count(); i++)
55 {
56 list->Append(players[i]);
57 }
58
59 m_textField = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize);
60
5d2ac6b8
WS
61 m_OK = new wxButton(this, wxID_OK);
62 m_cancel = new wxButton(this, wxID_CANCEL);
2a21ac15
DS
63
64 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
65 button_sizer->Add( m_OK, 0, wxALL, 10 );
66 button_sizer->Add( m_cancel, 0, wxALL, 10 );
67
68 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
69 topsizer->Add( msg, 0, wxALL , 10 );
70 topsizer->Add( list, 1, wxEXPAND | wxLEFT | wxRIGHT, 10 );
71 topsizer->Add( m_textField, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10 );
72 topsizer->Add( button_sizer, 0, wxALIGN_LEFT );
73
74 SetSizer( topsizer );
75
76 topsizer->SetSizeHints( this );
77
82ea63e6 78 CentreOnParent();
68ca12fe
JS
79
80 m_OK->SetDefault();
63cafd27
JS
81}
82
cb43b372 83void PlayerSelectionDialog::OnSize(wxSizeEvent& WXUNUSED(event))
63cafd27 84{
2a21ac15 85 Layout();
63cafd27
JS
86}
87
88const wxString& PlayerSelectionDialog::GetPlayersName()
89{
7b5408ea 90/*
2a21ac15
DS
91 m_player = wxEmptyString;
92 Show(true);
7b5408ea 93*/
2a21ac15 94 return m_player;
63cafd27
JS
95}
96
babd36de 97void PlayerSelectionDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
63cafd27 98{
2a21ac15 99 m_player = wxEmptyString;
e3065973 100 EndModal(wxID_CANCEL);
63cafd27
JS
101}
102
103void PlayerSelectionDialog::SelectCallback(wxCommandEvent& event)
104{
ce7fe42e 105 if (event.GetEventType() == wxEVT_LISTBOX)
2a21ac15
DS
106 {
107// if (event.IsSelection())
108 m_textField->SetValue(event.GetString());
109 }
63cafd27
JS
110}
111
112void PlayerSelectionDialog::ButtonCallback(wxCommandEvent& event)
113{
2a21ac15
DS
114 if (event.GetId() == wxID_OK)
115 {
116 wxString name = m_textField->GetValue();
6636ef8d 117 if ( !name.empty() )
2a21ac15 118 {
9a83f860 119 if (name.Contains(wxT('@')))
2a21ac15 120 {
9a83f860 121 wxMessageBox(wxT("Names should not contain the '@' character"), wxT("Forty Thieves"));
2a21ac15
DS
122 }
123 else
124 {
125 m_player = name;
126 EndModal(wxID_OK);
127 }
128 }
129 else
130 {
9a83f860 131 wxMessageBox(wxT("Please enter your name"), wxT("Forty Thieves"));
2a21ac15
DS
132 }
133 }
134 else
135 {
136 m_player = wxEmptyString;
137 EndModal(wxID_CANCEL);
138 }
63cafd27 139}