choicdgg.cpp
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C++ 代码 · 共 522 行 · 第 1/2 页
CPP
522 行
// ----------------------------------------------------------------------------
// wxAnyChoiceDialog
// ----------------------------------------------------------------------------
bool wxAnyChoiceDialog::Create(wxWindow *parent,
const wxString& message,
const wxString& caption,
int n, const wxString *choices,
long styleDlg,
const wxPoint& pos,
long styleLbox)
{
#if defined(__SMARTPHONE__) || defined(__POCKETPC__)
styleDlg &= ~wxBORDER_MASK;
styleDlg &= ~wxRESIZE_BORDER;
styleDlg &= ~wxCAPTION;
#endif
#ifdef __WXMAC__
if ( !wxDialog::Create(parent, wxID_ANY, caption, pos, wxDefaultSize, styleDlg & (~wxCANCEL) ) )
return false;
#else
if ( !wxDialog::Create(parent, wxID_ANY, caption, pos, wxDefaultSize, styleDlg) )
return false;
#endif
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
// 1) text message
#ifdef __WXMAC__
// align text and list at least on mac
topsizer->Add( CreateTextSizer( message ), 0, wxALL, wxLARGESMALL(15,0) );
#else
topsizer->Add( CreateTextSizer( message ), 0, wxALL, wxLARGESMALL(10,0) );
#endif
// 2) list box
m_listbox = new wxListBox( this, wxID_LISTBOX,
wxDefaultPosition, wxDefaultSize,
n, choices,
styleLbox );
if ( n > 0 )
m_listbox->SetSelection(0);
topsizer->Add( m_listbox, 1, wxEXPAND|wxLEFT|wxRIGHT, wxLARGESMALL(15,0) );
// smart phones does not support or do not waste space for wxButtons
#ifdef __SMARTPHONE__
SetRightMenu(wxID_CANCEL, _("Cancel"));
#else // __SMARTPHONE__/!__SMARTPHONE__
// Mac Human Interface Guidelines recommend not to use static lines as grouping elements
#ifndef __WXMAC__
#if wxUSE_STATLINE
// 3) static line
topsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
#endif
#endif
// 4) buttons
topsizer->Add( CreateButtonSizer( styleDlg & (wxOK|wxCANCEL) ), 0, wxEXPAND | wxALL, 10 );
#endif // !__SMARTPHONE__
SetSizer( topsizer );
#if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
topsizer->SetSizeHints( this );
topsizer->Fit( this );
if ( styleDlg & wxCENTRE )
Centre(wxBOTH);
#endif
m_listbox->SetFocus();
return true;
}
bool wxAnyChoiceDialog::Create(wxWindow *parent,
const wxString& message,
const wxString& caption,
const wxArrayString& choices,
long styleDlg,
const wxPoint& pos,
long styleLbox)
{
wxCArrayString chs(choices);
return Create(parent, message, caption, chs.GetCount(), chs.GetStrings(),
styleDlg, pos, styleLbox);
}
// ----------------------------------------------------------------------------
// wxSingleChoiceDialog
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxSingleChoiceDialog, wxDialog)
EVT_BUTTON(wxID_OK, wxSingleChoiceDialog::OnOK)
EVT_LISTBOX_DCLICK(wxID_LISTBOX, wxSingleChoiceDialog::OnListBoxDClick)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxSingleChoiceDialog, wxDialog)
wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent,
const wxString& message,
const wxString& caption,
int n,
const wxString *choices,
char **clientData,
long style,
const wxPoint& WXUNUSED(pos))
{
Create(parent, message, caption, n, choices, clientData, style);
}
wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent,
const wxString& message,
const wxString& caption,
const wxArrayString& choices,
char **clientData,
long style,
const wxPoint& WXUNUSED(pos))
{
Create(parent, message, caption, choices, clientData, style);
}
bool wxSingleChoiceDialog::Create( wxWindow *parent,
const wxString& message,
const wxString& caption,
int n,
const wxString *choices,
char **clientData,
long style,
const wxPoint& pos )
{
if ( !wxAnyChoiceDialog::Create(parent, message, caption,
n, choices,
style, pos) )
return false;
m_selection = n > 0 ? 0 : -1;
if (clientData)
{
for (int i = 0; i < n; i++)
m_listbox->SetClientData(i, clientData[i]);
}
return true;
}
bool wxSingleChoiceDialog::Create( wxWindow *parent,
const wxString& message,
const wxString& caption,
const wxArrayString& choices,
char **clientData,
long style,
const wxPoint& pos )
{
wxCArrayString chs(choices);
return Create( parent, message, caption, chs.GetCount(), chs.GetStrings(),
clientData, style, pos );
}
// Set the selection
void wxSingleChoiceDialog::SetSelection(int sel)
{
m_listbox->SetSelection(sel);
m_selection = sel;
}
void wxSingleChoiceDialog::OnOK(wxCommandEvent& WXUNUSED(event))
{
m_selection = m_listbox->GetSelection();
m_stringSelection = m_listbox->GetStringSelection();
if ( m_listbox->HasClientUntypedData() )
SetClientData(m_listbox->GetClientData(m_selection));
EndModal(wxID_OK);
}
void wxSingleChoiceDialog::OnListBoxDClick(wxCommandEvent& WXUNUSED(event))
{
m_selection = m_listbox->GetSelection();
m_stringSelection = m_listbox->GetStringSelection();
if ( m_listbox->HasClientUntypedData() )
SetClientData(m_listbox->GetClientData(m_selection));
EndModal(wxID_OK);
}
// ----------------------------------------------------------------------------
// wxMultiChoiceDialog
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMultiChoiceDialog, wxDialog)
bool wxMultiChoiceDialog::Create( wxWindow *parent,
const wxString& message,
const wxString& caption,
int n,
const wxString *choices,
long style,
const wxPoint& pos )
{
if ( !wxAnyChoiceDialog::Create(parent, message, caption,
n, choices,
style, pos,
wxLB_ALWAYS_SB | wxLB_EXTENDED) )
return false;
return true;
}
bool wxMultiChoiceDialog::Create( wxWindow *parent,
const wxString& message,
const wxString& caption,
const wxArrayString& choices,
long style,
const wxPoint& pos )
{
wxCArrayString chs(choices);
return Create( parent, message, caption, chs.GetCount(),
chs.GetStrings(), style, pos );
}
void wxMultiChoiceDialog::SetSelections(const wxArrayInt& selections)
{
// first clear all currently selected items
size_t n,
count = m_listbox->GetCount();
for ( n = 0; n < count; ++n )
{
m_listbox->Deselect(n);
}
// now select the ones which should be selected
count = selections.GetCount();
for ( n = 0; n < count; n++ )
{
m_listbox->Select(selections[n]);
}
}
bool wxMultiChoiceDialog::TransferDataFromWindow()
{
m_selections.Empty();
size_t count = m_listbox->GetCount();
for ( size_t n = 0; n < count; n++ )
{
if ( m_listbox->IsSelected(n) )
m_selections.Add(n);
}
return true;
}
#endif // wxUSE_CHOICEDLG
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?