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