Insert() patch from John Labenski
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20564 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%% Name: ctrlsub.tex
|
||||
%% Purpose: wxControlWithItems documentation
|
||||
%% Author: Vadim Zeitlin
|
||||
@@ -7,7 +7,7 @@
|
||||
%% RCS-ID: $Id$
|
||||
%% Copyright: (c) 2003 Vadim Zeitlin
|
||||
%% License: wxWindows license
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
\section{\class{wxControlWithItems}}\label{wxcontrolwithitems}
|
||||
|
||||
@@ -218,6 +218,35 @@ selected.
|
||||
\helpref{GetSelection}{wxcontrolwithitemsgetselection}
|
||||
|
||||
|
||||
\membersection{wxControlWithItems::Insert}\label{wxcontrolwithitemsinsert}
|
||||
|
||||
\func{int}{Insert}{\param{const wxString\& }{ item}, \param{int }{pos}}
|
||||
|
||||
Inserts the item into the list before pos.
|
||||
Not valid for {\tt wxLB\_SORT} or {\tt wxCB\_SORT} styles, use Append instead.
|
||||
|
||||
\func{int}{Insert}{\param{const wxString\& }{ item}, \param{int }{pos}, \param{void *}{clientData}}
|
||||
|
||||
\func{int}{Insert}{\param{const wxString\& }{ item}, \param{int }{pos}, \param{wxClientData *}{clientData}}
|
||||
|
||||
Inserts the item into the list before pos, associating the given, typed or
|
||||
untyped, client data pointer with the item.
|
||||
Not valid for {\tt wxLB\_SORT} or {\tt wxCB\_SORT} styles, use Append instead.
|
||||
|
||||
\wxheading{Parameters}
|
||||
|
||||
\docparam{item}{String to add.}
|
||||
|
||||
\docparam{pos}{Position to insert item before, zero based.}
|
||||
|
||||
\docparam{clientData}{Client data to associate with the item.}
|
||||
|
||||
\wxheading{Return value}
|
||||
|
||||
The return value is the index of the newly inserted item. If the insertion failed
|
||||
for some reason, -1 is returned.
|
||||
|
||||
|
||||
\membersection{wxControlWithItems::IsEmpty}\label{wxcontrolwithitemsisempty}
|
||||
|
||||
\constfunc{bool}{IsEmpty}{\void}
|
||||
|
@@ -47,6 +47,11 @@ public:
|
||||
// append several items at once to the control
|
||||
void Append(const wxArrayString& strings);
|
||||
|
||||
int Insert(const wxString& item, int pos)
|
||||
{ return DoInsert(item, pos); }
|
||||
int Insert(const wxString& item, int pos, void *clientData);
|
||||
int Insert(const wxString& item, int pos, wxClientData *clientData);
|
||||
|
||||
// deleting items
|
||||
// --------------
|
||||
|
||||
@@ -94,6 +99,7 @@ public:
|
||||
|
||||
protected:
|
||||
virtual int DoAppend(const wxString& item) = 0;
|
||||
virtual int DoInsert(const wxString& item, int pos) = 0;
|
||||
|
||||
virtual void DoSetItemClientData(int n, void* clientData) = 0;
|
||||
virtual void* DoGetItemClientData(int n) const = 0;
|
||||
|
@@ -60,6 +60,7 @@ protected:
|
||||
|
||||
void ApplyWidgetStyle();
|
||||
virtual int DoAppend(const wxString& item);
|
||||
virtual int DoInsert(const wxString& item, int pos);
|
||||
|
||||
virtual void DoSetItemClientData( int n, void* clientData );
|
||||
virtual void* DoGetItemClientData( int n ) const;
|
||||
@@ -70,7 +71,7 @@ protected:
|
||||
|
||||
private:
|
||||
// common part of Create() and DoAppend()
|
||||
size_t GtkAppendHelper(GtkWidget *menu, const wxString& item);
|
||||
int GtkAddHelper(GtkWidget *menu, int pos, const wxString& item);
|
||||
|
||||
// this array is only used for controls with wxCB_SORT style, so only
|
||||
// allocate it if it's needed (hence using pointer)
|
||||
|
@@ -69,6 +69,10 @@ public:
|
||||
void Append( const wxString &item, void* clientData );
|
||||
void Append( const wxString &item, wxClientData* clientData );
|
||||
|
||||
void Insert( const wxString &item, int pos );
|
||||
void Insert( const wxString &item, int pos, void* clientData );
|
||||
void Insert( const wxString &item, int pos, wxClientData* clientData );
|
||||
|
||||
void SetClientData( int n, void* clientData );
|
||||
void* GetClientData( int n );
|
||||
void SetClientObject( int n, wxClientData* clientData );
|
||||
@@ -122,6 +126,7 @@ public:
|
||||
void DisableEvents();
|
||||
void EnableEvents();
|
||||
void AppendCommon( const wxString &item );
|
||||
void InsertCommon( const wxString &item, int pos );
|
||||
GtkWidget* GetConnectWidget();
|
||||
bool IsOwnGtkWindow( GdkWindow *window );
|
||||
void ApplyWidgetStyle();
|
||||
|
@@ -60,6 +60,7 @@ protected:
|
||||
|
||||
void ApplyWidgetStyle();
|
||||
virtual int DoAppend(const wxString& item);
|
||||
virtual int DoInsert(const wxString& item, int pos);
|
||||
|
||||
virtual void DoSetItemClientData( int n, void* clientData );
|
||||
virtual void* DoGetItemClientData( int n ) const;
|
||||
@@ -70,7 +71,7 @@ protected:
|
||||
|
||||
private:
|
||||
// common part of Create() and DoAppend()
|
||||
size_t GtkAppendHelper(GtkWidget *menu, const wxString& item);
|
||||
int GtkAddHelper(GtkWidget *menu, int pos, const wxString& item);
|
||||
|
||||
// this array is only used for controls with wxCB_SORT style, so only
|
||||
// allocate it if it's needed (hence using pointer)
|
||||
|
@@ -69,6 +69,10 @@ public:
|
||||
void Append( const wxString &item, void* clientData );
|
||||
void Append( const wxString &item, wxClientData* clientData );
|
||||
|
||||
void Insert( const wxString &item, int pos );
|
||||
void Insert( const wxString &item, int pos, void* clientData );
|
||||
void Insert( const wxString &item, int pos, wxClientData* clientData );
|
||||
|
||||
void SetClientData( int n, void* clientData );
|
||||
void* GetClientData( int n );
|
||||
void SetClientObject( int n, wxClientData* clientData );
|
||||
@@ -122,6 +126,7 @@ public:
|
||||
void DisableEvents();
|
||||
void EnableEvents();
|
||||
void AppendCommon( const wxString &item );
|
||||
void InsertCommon( const wxString &item, int pos );
|
||||
GtkWidget* GetConnectWidget();
|
||||
bool IsOwnGtkWindow( GdkWindow *window );
|
||||
void ApplyWidgetStyle();
|
||||
|
@@ -109,8 +109,8 @@ public:
|
||||
protected:
|
||||
// NB: due to wxGTK implementation details, DoInsert() is implemented
|
||||
// using DoInsertItems() and not the other way round
|
||||
void DoInsert(const wxString& item, int pos)
|
||||
{ InsertItems(1, &item, pos); }
|
||||
virtual int DoInsert(const wxString& item, int pos)
|
||||
{ InsertItems(1, &item, pos); return pos; }
|
||||
|
||||
// to be implemented in derived classes
|
||||
virtual void DoInsertItems(const wxArrayString& items, int pos) = 0;
|
||||
|
@@ -57,6 +57,7 @@ public:
|
||||
|
||||
// implement base class pure virtuals
|
||||
virtual int DoAppend(const wxString& item);
|
||||
virtual int DoInsert(const wxString& item, int pos);
|
||||
virtual void Delete(int n);
|
||||
virtual void Clear();
|
||||
|
||||
|
@@ -55,6 +55,7 @@ public:
|
||||
// implementation of wxControlWithItems
|
||||
virtual int GetCount() const;
|
||||
virtual int DoAppend(const wxString& item);
|
||||
virtual int DoInsert(const wxString& item, int pos);
|
||||
virtual void DoSetItemClientData(int n, void* clientData);
|
||||
virtual void* DoGetItemClientData(int n) const;
|
||||
virtual void DoSetItemClientObject(int n, wxClientData* clientData);
|
||||
|
@@ -55,6 +55,7 @@ public:
|
||||
|
||||
// implementation of wxControlWithItems
|
||||
virtual int DoAppend(const wxString& item);
|
||||
virtual int DoInsert(const wxString& item, int pos);
|
||||
virtual void Delete(int n);
|
||||
virtual void Clear();
|
||||
virtual int GetSelection() const ;
|
||||
|
@@ -52,6 +52,7 @@ public:
|
||||
|
||||
// implement base class pure virtuals
|
||||
virtual int DoAppend(const wxString& item);
|
||||
virtual int DoInsert(const wxString& item, int pos);
|
||||
virtual void Delete(int n);
|
||||
virtual void Clear();
|
||||
|
||||
|
@@ -59,6 +59,7 @@ public:
|
||||
// Implement base class virtuals
|
||||
//
|
||||
virtual int DoAppend(const wxString& rsItem);
|
||||
virtual int DoInsert(const wxString& rsItem, int pos);
|
||||
virtual void Delete(int n);
|
||||
virtual void Clear(void);
|
||||
|
||||
|
@@ -330,6 +330,7 @@ public:
|
||||
|
||||
protected:
|
||||
virtual int DoAppend(const wxString& item);
|
||||
virtual int DoInsert(const wxString& item, int pos);
|
||||
virtual void DoSetItemClientData(int n, void* clientData);
|
||||
virtual void* DoGetItemClientData(int n) const;
|
||||
virtual void DoSetItemClientObject(int n, wxClientData* clientData);
|
||||
|
@@ -54,6 +54,8 @@ enum
|
||||
{
|
||||
ComboPage_Reset = 100,
|
||||
ComboPage_CurText,
|
||||
ComboPage_Insert,
|
||||
ComboPage_InsertText,
|
||||
ComboPage_Add,
|
||||
ComboPage_AddText,
|
||||
ComboPage_AddSeveral,
|
||||
@@ -91,6 +93,7 @@ protected:
|
||||
void OnButtonDelete(wxCommandEvent& event);
|
||||
void OnButtonDeleteSel(wxCommandEvent& event);
|
||||
void OnButtonClear(wxCommandEvent& event);
|
||||
void OnButtonInsert(wxCommandEvent &event);
|
||||
void OnButtonAdd(wxCommandEvent& event);
|
||||
void OnButtonAddSeveral(wxCommandEvent& event);
|
||||
void OnButtonAddMany(wxCommandEvent& event);
|
||||
@@ -102,6 +105,7 @@ protected:
|
||||
|
||||
void OnUpdateUICurText(wxUpdateUIEvent& event);
|
||||
|
||||
void OnUpdateUIInsert(wxUpdateUIEvent& event);
|
||||
void OnUpdateUIAddSeveral(wxUpdateUIEvent& event);
|
||||
void OnUpdateUIClearButton(wxUpdateUIEvent& event);
|
||||
void OnUpdateUIDeleteButton(wxUpdateUIEvent& event);
|
||||
@@ -129,7 +133,8 @@ protected:
|
||||
wxSizer *m_sizerCombo;
|
||||
|
||||
// the text entries for "Add/change string" and "Delete" buttons
|
||||
wxTextCtrl *m_textAdd,
|
||||
wxTextCtrl *m_textInsert,
|
||||
*m_textAdd,
|
||||
*m_textChange,
|
||||
*m_textDelete;
|
||||
|
||||
@@ -148,16 +153,19 @@ BEGIN_EVENT_TABLE(ComboboxWidgetsPage, WidgetsPage)
|
||||
EVT_BUTTON(ComboPage_Delete, ComboboxWidgetsPage::OnButtonDelete)
|
||||
EVT_BUTTON(ComboPage_DeleteSel, ComboboxWidgetsPage::OnButtonDeleteSel)
|
||||
EVT_BUTTON(ComboPage_Clear, ComboboxWidgetsPage::OnButtonClear)
|
||||
EVT_BUTTON(ComboPage_Insert, ComboboxWidgetsPage::OnButtonInsert)
|
||||
EVT_BUTTON(ComboPage_Add, ComboboxWidgetsPage::OnButtonAdd)
|
||||
EVT_BUTTON(ComboPage_AddSeveral, ComboboxWidgetsPage::OnButtonAddSeveral)
|
||||
EVT_BUTTON(ComboPage_AddMany, ComboboxWidgetsPage::OnButtonAddMany)
|
||||
|
||||
EVT_TEXT_ENTER(ComboPage_InsertText, ComboboxWidgetsPage::OnButtonInsert)
|
||||
EVT_TEXT_ENTER(ComboPage_AddText, ComboboxWidgetsPage::OnButtonAdd)
|
||||
EVT_TEXT_ENTER(ComboPage_DeleteText, ComboboxWidgetsPage::OnButtonDelete)
|
||||
|
||||
EVT_UPDATE_UI(ComboPage_CurText, ComboboxWidgetsPage::OnUpdateUICurText)
|
||||
|
||||
EVT_UPDATE_UI(ComboPage_Reset, ComboboxWidgetsPage::OnUpdateUIResetButton)
|
||||
EVT_UPDATE_UI(ComboPage_Insert, ComboboxWidgetsPage::OnUpdateUIInsert)
|
||||
EVT_UPDATE_UI(ComboPage_AddSeveral, ComboboxWidgetsPage::OnUpdateUIAddSeveral)
|
||||
EVT_UPDATE_UI(ComboPage_Clear, ComboboxWidgetsPage::OnUpdateUIClearButton)
|
||||
EVT_UPDATE_UI(ComboPage_DeleteText, ComboboxWidgetsPage::OnUpdateUIClearButton)
|
||||
@@ -168,6 +176,7 @@ BEGIN_EVENT_TABLE(ComboboxWidgetsPage, WidgetsPage)
|
||||
|
||||
EVT_COMBOBOX(ComboPage_Combo, ComboboxWidgetsPage::OnComboBox)
|
||||
EVT_TEXT(ComboPage_Combo, ComboboxWidgetsPage::OnComboText)
|
||||
EVT_TEXT_ENTER(ComboPage_Combo, ComboboxWidgetsPage::OnComboText)
|
||||
|
||||
EVT_CHECKBOX(-1, ComboboxWidgetsPage::OnCheckOrRadioBox)
|
||||
EVT_RADIOBOX(-1, ComboboxWidgetsPage::OnCheckOrRadioBox)
|
||||
@@ -241,16 +250,22 @@ ComboboxWidgetsPage::ComboboxWidgetsPage(wxNotebook *notebook,
|
||||
|
||||
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
||||
|
||||
sizerRow = CreateSizerWithTextAndButton(ComboPage_Insert,
|
||||
_T("&Insert this string"),
|
||||
ComboPage_InsertText,
|
||||
&m_textInsert);
|
||||
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
||||
|
||||
sizerRow = CreateSizerWithTextAndButton(ComboPage_Add,
|
||||
_T("&Add this string"),
|
||||
ComboPage_AddText,
|
||||
&m_textAdd);
|
||||
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
||||
|
||||
btn = new wxButton(this, ComboPage_AddSeveral, _T("&Insert a few strings"));
|
||||
btn = new wxButton(this, ComboPage_AddSeveral, _T("&Append a few strings"));
|
||||
sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
|
||||
|
||||
btn = new wxButton(this, ComboPage_AddMany, _T("Add &many strings"));
|
||||
btn = new wxButton(this, ComboPage_AddMany, _T("Append &many strings"));
|
||||
sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
|
||||
|
||||
sizerRow = CreateSizerWithTextAndButton(ComboPage_Change,
|
||||
@@ -410,6 +425,21 @@ void ComboboxWidgetsPage::OnButtonClear(wxCommandEvent& event)
|
||||
m_combobox->Clear();
|
||||
}
|
||||
|
||||
void ComboboxWidgetsPage::OnButtonInsert(wxCommandEvent& event)
|
||||
{
|
||||
static unsigned int s_item = 0;
|
||||
|
||||
wxString s = m_textInsert->GetValue();
|
||||
if ( !m_textInsert->IsModified() )
|
||||
{
|
||||
// update the default string
|
||||
m_textInsert->SetValue(wxString::Format(_T("test item %u"), ++s_item));
|
||||
}
|
||||
|
||||
if (m_combobox->GetSelection() >= 0)
|
||||
m_combobox->Insert(s, m_combobox->GetSelection());
|
||||
}
|
||||
|
||||
void ComboboxWidgetsPage::OnButtonAdd(wxCommandEvent& event)
|
||||
{
|
||||
static unsigned int s_item = 0;
|
||||
@@ -452,6 +482,17 @@ void ComboboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
|
||||
event.Enable( m_chkSort->GetValue() || m_chkReadonly->GetValue() );
|
||||
}
|
||||
|
||||
void ComboboxWidgetsPage::OnUpdateUIInsert(wxUpdateUIEvent& event)
|
||||
{
|
||||
if (m_combobox)
|
||||
{
|
||||
bool enable = !(m_combobox->GetWindowStyle() & wxCB_SORT) &&
|
||||
(m_combobox->GetSelection() >= 0);
|
||||
|
||||
event.Enable(enable);
|
||||
}
|
||||
}
|
||||
|
||||
void ComboboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent& event)
|
||||
{
|
||||
if (m_combobox)
|
||||
@@ -490,6 +531,9 @@ void ComboboxWidgetsPage::OnComboText(wxCommandEvent& event)
|
||||
wxASSERT_MSG( s == m_combobox->GetValue(),
|
||||
_T("event and combobox values should be the same") );
|
||||
|
||||
if (event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER)
|
||||
wxLogMessage(_T("Combobox enter pressed (now '%s')"), s.c_str());
|
||||
else
|
||||
wxLogMessage(_T("Combobox text changed (now '%s')"), s.c_str());
|
||||
}
|
||||
|
||||
|
@@ -70,6 +70,25 @@ void wxItemContainer::Append(const wxArrayString& strings)
|
||||
}
|
||||
}
|
||||
|
||||
int wxItemContainer::Insert(const wxString& item, int pos, void *clientData)
|
||||
{
|
||||
int n = DoInsert(item, pos);
|
||||
if ( n != wxNOT_FOUND )
|
||||
SetClientData(n, clientData);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int
|
||||
wxItemContainer::Insert(const wxString& item, int pos, wxClientData *clientData)
|
||||
{
|
||||
int n = DoInsert(item, pos);
|
||||
if ( n != wxNOT_FOUND )
|
||||
SetClientObject(n, clientData);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// client data
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@@ -102,7 +102,7 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id,
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
GtkAppendHelper(menu, choices[i]);
|
||||
GtkAddHelper(menu, i, choices[i]);
|
||||
}
|
||||
|
||||
gtk_option_menu_set_menu( GTK_OPTION_MENU(m_widget), menu );
|
||||
@@ -136,7 +136,20 @@ int wxChoice::DoAppend( const wxString &item )
|
||||
|
||||
GtkWidget *menu = gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) );
|
||||
|
||||
return GtkAppendHelper(menu, item);
|
||||
return GtkAddHelper(menu, GetCount(), item);
|
||||
}
|
||||
|
||||
int wxChoice::DoInsert( const wxString &item, int pos )
|
||||
{
|
||||
wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid choice control") );
|
||||
wxCHECK_MSG( (pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
|
||||
|
||||
if (pos == GetCount())
|
||||
return DoAppend(item);
|
||||
|
||||
GtkWidget *menu = gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) );
|
||||
|
||||
return GtkAddHelper(menu, pos, item);
|
||||
}
|
||||
|
||||
void wxChoice::DoSetItemClientData( int n, void* clientData )
|
||||
@@ -388,8 +401,10 @@ void wxChoice::ApplyWidgetStyle()
|
||||
}
|
||||
}
|
||||
|
||||
size_t wxChoice::GtkAppendHelper(GtkWidget *menu, const wxString& item)
|
||||
int wxChoice::GtkAddHelper(GtkWidget *menu, int pos, const wxString& item)
|
||||
{
|
||||
wxCHECK_MSG((pos>=0) && (pos<=(int)m_clientList.GetCount()), -1, wxT("invalid index"));
|
||||
|
||||
GtkWidget *menu_item = gtk_menu_item_new_with_label( wxGTK_CONV( item ) );
|
||||
|
||||
size_t index;
|
||||
@@ -412,15 +427,23 @@ size_t wxChoice::GtkAppendHelper(GtkWidget *menu, const wxString& item)
|
||||
}
|
||||
else
|
||||
{
|
||||
// normal control, just append
|
||||
gtk_menu_append( GTK_MENU(menu), menu_item );
|
||||
|
||||
m_clientList.Append( (wxObject*) NULL );
|
||||
|
||||
// don't call wxChoice::GetCount() from here because it doesn't work
|
||||
// if we're called from ctor (and GtkMenuShell is still NULL)
|
||||
|
||||
// normal control, just append
|
||||
if (pos == (int)m_clientList.GetCount())
|
||||
{
|
||||
gtk_menu_append( GTK_MENU(menu), menu_item );
|
||||
m_clientList.Append( (wxObject*) NULL );
|
||||
index = m_clientList.GetCount() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_menu_insert( GTK_MENU(menu), menu_item, pos );
|
||||
m_clientList.Insert( pos, (wxObject*) NULL );
|
||||
index = pos;
|
||||
}
|
||||
}
|
||||
|
||||
if (GTK_WIDGET_REALIZED(m_widget))
|
||||
{
|
||||
|
@@ -269,6 +269,93 @@ void wxComboBox::Append( const wxString &item, wxClientData *clientData )
|
||||
AppendCommon( item );
|
||||
}
|
||||
|
||||
void wxComboBox::InsertCommon( const wxString &item, int pos )
|
||||
{
|
||||
wxCHECK_RET(!(GetWindowStyle() & wxCB_SORT), wxT("can't insert into sorted list"));
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
|
||||
|
||||
int count = GetCount();
|
||||
wxCHECK_RET((pos>=0) && (pos<=count), wxT("invalid index"));
|
||||
if (pos == count)
|
||||
{
|
||||
AppendCommon(item);
|
||||
return;
|
||||
}
|
||||
|
||||
DisableEvents();
|
||||
|
||||
GtkWidget *list = GTK_COMBO(m_widget)->list;
|
||||
|
||||
GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );
|
||||
|
||||
GList *gitem_list = g_list_alloc ();
|
||||
gitem_list->data = list_item;
|
||||
gtk_list_insert_items( GTK_LIST (list), gitem_list, pos );
|
||||
|
||||
if (GTK_WIDGET_REALIZED(m_widget))
|
||||
{
|
||||
gtk_widget_realize( list_item );
|
||||
gtk_widget_realize( GTK_BIN(list_item)->child );
|
||||
|
||||
if (m_widgetStyle) ApplyWidgetStyle();
|
||||
}
|
||||
|
||||
gtk_widget_show( list_item );
|
||||
|
||||
EnableEvents();
|
||||
}
|
||||
|
||||
void wxComboBox::Insert( const wxString &item, int pos )
|
||||
{
|
||||
wxCHECK_RET(!(GetWindowStyle() & wxCB_SORT), wxT("can't insert into sorted list"));
|
||||
int count = GetCount();
|
||||
wxCHECK_RET((pos>=0) && (pos<=count), wxT("invalid index"));
|
||||
if (pos == count)
|
||||
{
|
||||
Append(item);
|
||||
return;
|
||||
}
|
||||
|
||||
m_clientDataList.Insert( pos, (wxObject*) NULL );
|
||||
m_clientObjectList.Insert( pos, (wxObject*) NULL );
|
||||
|
||||
InsertCommon( item, pos );
|
||||
}
|
||||
|
||||
void wxComboBox::Insert( const wxString &item, int pos, void *clientData )
|
||||
{
|
||||
wxCHECK_RET(!(GetWindowStyle() & wxCB_SORT), wxT("can't insert into sorted list"));
|
||||
int count = GetCount();
|
||||
wxCHECK_RET((pos>=0) && (pos<=count), wxT("invalid index"));
|
||||
if (pos == count)
|
||||
{
|
||||
Append(item, clientData);
|
||||
return;
|
||||
}
|
||||
|
||||
m_clientDataList.Insert( pos, (wxObject*) clientData );
|
||||
m_clientObjectList.Insert( pos, (wxObject*)NULL );
|
||||
|
||||
InsertCommon( item, pos );
|
||||
}
|
||||
|
||||
void wxComboBox::Insert( const wxString &item, int pos, wxClientData *clientData )
|
||||
{
|
||||
wxCHECK_RET(!(GetWindowStyle() & wxCB_SORT), wxT("can't insert into sorted list"));
|
||||
int count = GetCount();
|
||||
wxCHECK_RET((pos>=0) && (pos<=count), wxT("invalid index"));
|
||||
if (pos == count)
|
||||
{
|
||||
Append(item, clientData);
|
||||
return;
|
||||
}
|
||||
|
||||
m_clientDataList.Insert( pos, (wxObject*) NULL );
|
||||
m_clientObjectList.Insert( pos, (wxObject*) clientData );
|
||||
|
||||
InsertCommon( item, pos );
|
||||
}
|
||||
|
||||
void wxComboBox::SetClientData( int n, void* clientData )
|
||||
{
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
|
||||
|
@@ -102,7 +102,7 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id,
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
GtkAppendHelper(menu, choices[i]);
|
||||
GtkAddHelper(menu, i, choices[i]);
|
||||
}
|
||||
|
||||
gtk_option_menu_set_menu( GTK_OPTION_MENU(m_widget), menu );
|
||||
@@ -136,7 +136,20 @@ int wxChoice::DoAppend( const wxString &item )
|
||||
|
||||
GtkWidget *menu = gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) );
|
||||
|
||||
return GtkAppendHelper(menu, item);
|
||||
return GtkAddHelper(menu, GetCount(), item);
|
||||
}
|
||||
|
||||
int wxChoice::DoInsert( const wxString &item, int pos )
|
||||
{
|
||||
wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid choice control") );
|
||||
wxCHECK_MSG( (pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
|
||||
|
||||
if (pos == GetCount())
|
||||
return DoAppend(item);
|
||||
|
||||
GtkWidget *menu = gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) );
|
||||
|
||||
return GtkAddHelper(menu, pos, item);
|
||||
}
|
||||
|
||||
void wxChoice::DoSetItemClientData( int n, void* clientData )
|
||||
@@ -388,8 +401,10 @@ void wxChoice::ApplyWidgetStyle()
|
||||
}
|
||||
}
|
||||
|
||||
size_t wxChoice::GtkAppendHelper(GtkWidget *menu, const wxString& item)
|
||||
int wxChoice::GtkAddHelper(GtkWidget *menu, int pos, const wxString& item)
|
||||
{
|
||||
wxCHECK_MSG((pos>=0) && (pos<=(int)m_clientList.GetCount()), -1, wxT("invalid index"));
|
||||
|
||||
GtkWidget *menu_item = gtk_menu_item_new_with_label( wxGTK_CONV( item ) );
|
||||
|
||||
size_t index;
|
||||
@@ -412,15 +427,23 @@ size_t wxChoice::GtkAppendHelper(GtkWidget *menu, const wxString& item)
|
||||
}
|
||||
else
|
||||
{
|
||||
// normal control, just append
|
||||
gtk_menu_append( GTK_MENU(menu), menu_item );
|
||||
|
||||
m_clientList.Append( (wxObject*) NULL );
|
||||
|
||||
// don't call wxChoice::GetCount() from here because it doesn't work
|
||||
// if we're called from ctor (and GtkMenuShell is still NULL)
|
||||
|
||||
// normal control, just append
|
||||
if (pos == (int)m_clientList.GetCount())
|
||||
{
|
||||
gtk_menu_append( GTK_MENU(menu), menu_item );
|
||||
m_clientList.Append( (wxObject*) NULL );
|
||||
index = m_clientList.GetCount() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_menu_insert( GTK_MENU(menu), menu_item, pos );
|
||||
m_clientList.Insert( pos, (wxObject*) NULL );
|
||||
index = pos;
|
||||
}
|
||||
}
|
||||
|
||||
if (GTK_WIDGET_REALIZED(m_widget))
|
||||
{
|
||||
|
@@ -269,6 +269,93 @@ void wxComboBox::Append( const wxString &item, wxClientData *clientData )
|
||||
AppendCommon( item );
|
||||
}
|
||||
|
||||
void wxComboBox::InsertCommon( const wxString &item, int pos )
|
||||
{
|
||||
wxCHECK_RET(!(GetWindowStyle() & wxCB_SORT), wxT("can't insert into sorted list"));
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
|
||||
|
||||
int count = GetCount();
|
||||
wxCHECK_RET((pos>=0) && (pos<=count), wxT("invalid index"));
|
||||
if (pos == count)
|
||||
{
|
||||
AppendCommon(item);
|
||||
return;
|
||||
}
|
||||
|
||||
DisableEvents();
|
||||
|
||||
GtkWidget *list = GTK_COMBO(m_widget)->list;
|
||||
|
||||
GtkWidget *list_item = gtk_list_item_new_with_label( wxGTK_CONV( item ) );
|
||||
|
||||
GList *gitem_list = g_list_alloc ();
|
||||
gitem_list->data = list_item;
|
||||
gtk_list_insert_items( GTK_LIST (list), gitem_list, pos );
|
||||
|
||||
if (GTK_WIDGET_REALIZED(m_widget))
|
||||
{
|
||||
gtk_widget_realize( list_item );
|
||||
gtk_widget_realize( GTK_BIN(list_item)->child );
|
||||
|
||||
if (m_widgetStyle) ApplyWidgetStyle();
|
||||
}
|
||||
|
||||
gtk_widget_show( list_item );
|
||||
|
||||
EnableEvents();
|
||||
}
|
||||
|
||||
void wxComboBox::Insert( const wxString &item, int pos )
|
||||
{
|
||||
wxCHECK_RET(!(GetWindowStyle() & wxCB_SORT), wxT("can't insert into sorted list"));
|
||||
int count = GetCount();
|
||||
wxCHECK_RET((pos>=0) && (pos<=count), wxT("invalid index"));
|
||||
if (pos == count)
|
||||
{
|
||||
Append(item);
|
||||
return;
|
||||
}
|
||||
|
||||
m_clientDataList.Insert( pos, (wxObject*) NULL );
|
||||
m_clientObjectList.Insert( pos, (wxObject*) NULL );
|
||||
|
||||
InsertCommon( item, pos );
|
||||
}
|
||||
|
||||
void wxComboBox::Insert( const wxString &item, int pos, void *clientData )
|
||||
{
|
||||
wxCHECK_RET(!(GetWindowStyle() & wxCB_SORT), wxT("can't insert into sorted list"));
|
||||
int count = GetCount();
|
||||
wxCHECK_RET((pos>=0) && (pos<=count), wxT("invalid index"));
|
||||
if (pos == count)
|
||||
{
|
||||
Append(item, clientData);
|
||||
return;
|
||||
}
|
||||
|
||||
m_clientDataList.Insert( pos, (wxObject*) clientData );
|
||||
m_clientObjectList.Insert( pos, (wxObject*)NULL );
|
||||
|
||||
InsertCommon( item, pos );
|
||||
}
|
||||
|
||||
void wxComboBox::Insert( const wxString &item, int pos, wxClientData *clientData )
|
||||
{
|
||||
wxCHECK_RET(!(GetWindowStyle() & wxCB_SORT), wxT("can't insert into sorted list"));
|
||||
int count = GetCount();
|
||||
wxCHECK_RET((pos>=0) && (pos<=count), wxT("invalid index"));
|
||||
if (pos == count)
|
||||
{
|
||||
Append(item, clientData);
|
||||
return;
|
||||
}
|
||||
|
||||
m_clientDataList.Insert( pos, (wxObject*) NULL );
|
||||
m_clientObjectList.Insert( pos, (wxObject*) clientData );
|
||||
|
||||
InsertCommon( item, pos );
|
||||
}
|
||||
|
||||
void wxComboBox::SetClientData( int n, void* clientData )
|
||||
{
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
|
||||
|
@@ -81,6 +81,22 @@ int wxChoice::DoAppend(const wxString& item)
|
||||
return index ;
|
||||
}
|
||||
|
||||
int wxChoice::DoInsert(const wxString& item, int pos)
|
||||
{
|
||||
wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
|
||||
wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
|
||||
|
||||
if (pos == GetCount())
|
||||
return DoAppend(item);
|
||||
|
||||
UMAAppendMenuItem(MAC_WXHMENU( m_macPopUpMenuHandle ) , item);
|
||||
m_strings.Insert( item, pos ) ;
|
||||
m_datas.Insert( NULL, pos ) ;
|
||||
DoSetItemClientData( pos , NULL ) ;
|
||||
SetControl32BitMaximum( (ControlHandle) m_macControl , pos) ;
|
||||
return pos ;
|
||||
}
|
||||
|
||||
void wxChoice::Delete(int n)
|
||||
{
|
||||
wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") );
|
||||
|
@@ -81,6 +81,22 @@ int wxChoice::DoAppend(const wxString& item)
|
||||
return index ;
|
||||
}
|
||||
|
||||
int wxChoice::DoInsert(const wxString& item, int pos)
|
||||
{
|
||||
wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
|
||||
wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
|
||||
|
||||
if (pos == GetCount())
|
||||
return DoAppend(item);
|
||||
|
||||
UMAAppendMenuItem(MAC_WXHMENU( m_macPopUpMenuHandle ) , item);
|
||||
m_strings.Insert( item, pos ) ;
|
||||
m_datas.Insert( NULL, pos ) ;
|
||||
DoSetItemClientData( pos , NULL ) ;
|
||||
SetControl32BitMaximum( (ControlHandle) m_macControl , pos) ;
|
||||
return pos ;
|
||||
}
|
||||
|
||||
void wxChoice::Delete(int n)
|
||||
{
|
||||
wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") );
|
||||
|
@@ -209,6 +209,14 @@ int wxChoice::DoAppend(const wxString& item)
|
||||
return GetCount() - 1;
|
||||
}
|
||||
|
||||
int wxChoice::DoInsert(const wxString& item, int pos)
|
||||
{
|
||||
wxCHECK_MSG(FALSE, -1, wxT("insert not implemented"));
|
||||
|
||||
// wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
|
||||
// if (pos == GetCount()) return DoAppend(item);
|
||||
}
|
||||
|
||||
void wxChoice::Delete(int n)
|
||||
{
|
||||
Widget w = (Widget)m_widgetArray[n];
|
||||
|
@@ -145,6 +145,22 @@ int wxComboBox::DoAppend(const wxString& item)
|
||||
return GetCount() - 1;
|
||||
}
|
||||
|
||||
int wxComboBox::DoInsert(const wxString& item, int pos)
|
||||
{
|
||||
wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
|
||||
wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
|
||||
|
||||
if (pos == GetCount())
|
||||
return DoAppend(item);
|
||||
|
||||
wxXmString str( item.c_str() );
|
||||
XmComboBoxAddItem((Widget) m_mainWidget, str(), pos+1);
|
||||
m_stringList.Insert(pos, item);
|
||||
m_noStrings ++;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
void wxComboBox::Delete(int n)
|
||||
{
|
||||
XmComboBoxDeletePos((Widget) m_mainWidget, n+1);
|
||||
|
@@ -197,6 +197,22 @@ int wxComboBox::DoAppend(const wxString& item)
|
||||
return GetCount() - 1;
|
||||
}
|
||||
|
||||
int wxComboBox::DoInsert(const wxString& item, int pos)
|
||||
{
|
||||
wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
|
||||
wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
|
||||
|
||||
if (pos == GetCount())
|
||||
return DoAppend(item);
|
||||
|
||||
wxXmString str( item.c_str() );
|
||||
XmComboBoxAddItem((Widget) m_mainWidget, str(), pos+1, False);
|
||||
m_noStrings ++;
|
||||
AdjustDropDownListSize();
|
||||
|
||||
return GetCount() - 1;
|
||||
}
|
||||
|
||||
void wxComboBox::Delete(int n)
|
||||
{
|
||||
#ifdef LESSTIF_VERSION
|
||||
|
@@ -115,6 +115,20 @@ int wxChoice::DoAppend(const wxString& item)
|
||||
return n;
|
||||
}
|
||||
|
||||
int wxChoice::DoInsert(const wxString& item, int pos)
|
||||
{
|
||||
wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
|
||||
wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
|
||||
|
||||
int n = (int)SendMessage(GetHwnd(), CB_INSERTSTRING, pos, (LONG)item.c_str());
|
||||
if ( n == CB_ERR )
|
||||
{
|
||||
wxLogLastError(wxT("SendMessage(CB_INSERTSTRING)"));
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void wxChoice::Delete(int n)
|
||||
{
|
||||
wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") );
|
||||
|
@@ -111,6 +111,32 @@ int wxChoice::DoAppend(
|
||||
return nIndex;
|
||||
} // end of wxChoice::DoAppend
|
||||
|
||||
int wxChoice::DoInsert(
|
||||
const wxString& rsItem
|
||||
int pos
|
||||
)
|
||||
{
|
||||
wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
|
||||
wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
|
||||
|
||||
if (pos == GetCount())
|
||||
return DoAppend(item);
|
||||
|
||||
int nIndex;
|
||||
SHORT nIndexType = 0;
|
||||
|
||||
if (m_windowStyle & wxLB_SORT)
|
||||
nIndexType = LIT_SORTASCENDING;
|
||||
else
|
||||
nIndexType = pos;
|
||||
nIndex = (int)::WinSendMsg( GetHwnd()
|
||||
,LM_INSERTITEM
|
||||
,(MPARAM)nIndexType
|
||||
,(MPARAM)rsItem.c_str()
|
||||
);
|
||||
return nIndex;
|
||||
} // end of wxChoice::DoInsert
|
||||
|
||||
void wxChoice::Delete(
|
||||
int n
|
||||
)
|
||||
|
@@ -825,6 +825,18 @@ int wxComboBox::DoAppend(const wxString& item)
|
||||
return GetLBox()->Append(item);
|
||||
}
|
||||
|
||||
int wxComboBox::DoInsert(const wxString& item, int pos)
|
||||
{
|
||||
wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
|
||||
wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index"));
|
||||
|
||||
if (pos == GetCount())
|
||||
return DoAppend(item);
|
||||
|
||||
GetLBox()->Insert(1, &item, pos);
|
||||
return pos;
|
||||
}
|
||||
|
||||
void wxComboBox::DoSetItemClientData(int n, void* clientData)
|
||||
{
|
||||
GetLBox()->SetClientData(n, clientData);
|
||||
|
Reference in New Issue
Block a user