]> git.saurik.com Git - wxWidgets.git/blame - demos/forty/playerdg.cpp
extended wxSizerFlags docs
[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 ) :
40 wxDialog(parent, wxID_ANY, _T("Player Selection"), wxDefaultPosition),
41 m_scoreFile(file)
63cafd27 42{
2a21ac15
DS
43 wxStaticText* msg = new wxStaticText(this, wxID_ANY, _T("Please select a name or type a new one:"));
44
45 wxListBox* list = new wxListBox(
46 this, ID_LISTBOX,
47 wxDefaultPosition, wxDefaultSize,
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();
63cafd27
JS
79}
80
cb43b372 81void PlayerSelectionDialog::OnSize(wxSizeEvent& WXUNUSED(event))
63cafd27 82{
2a21ac15 83 Layout();
63cafd27
JS
84}
85
86const wxString& PlayerSelectionDialog::GetPlayersName()
87{
7b5408ea 88/*
2a21ac15
DS
89 m_player = wxEmptyString;
90 Show(true);
7b5408ea 91*/
2a21ac15 92 return m_player;
63cafd27
JS
93}
94
babd36de 95void PlayerSelectionDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
63cafd27 96{
2a21ac15 97 m_player = wxEmptyString;
e3065973 98 EndModal(wxID_CANCEL);
63cafd27
JS
99}
100
101void PlayerSelectionDialog::SelectCallback(wxCommandEvent& event)
102{
2a21ac15
DS
103 if (event.GetEventType() == wxEVT_COMMAND_LISTBOX_SELECTED)
104 {
105// if (event.IsSelection())
106 m_textField->SetValue(event.GetString());
107 }
63cafd27
JS
108}
109
110void PlayerSelectionDialog::ButtonCallback(wxCommandEvent& event)
111{
2a21ac15
DS
112 if (event.GetId() == wxID_OK)
113 {
114 wxString name = m_textField->GetValue();
115 if (!name.IsNull() && name.Length() > 0)
116 {
117 if (name.Contains(_T('@')))
118 {
119 wxMessageBox(_T("Names should not contain the '@' character"), _T("Forty Thieves"));
120 }
121 else
122 {
123 m_player = name;
124 EndModal(wxID_OK);
125 }
126 }
127 else
128 {
129 wxMessageBox(_T("Please enter your name"), _T("Forty Thieves"));
130 }
131 }
132 else
133 {
134 m_player = wxEmptyString;
135 EndModal(wxID_CANCEL);
136 }
63cafd27 137}