Added in-place editiging in wxListCtrl
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@574 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include "wx/imaglist.h"
|
#include "wx/imaglist.h"
|
||||||
#include "wx/control.h"
|
#include "wx/control.h"
|
||||||
#include "wx/timer.h"
|
#include "wx/timer.h"
|
||||||
|
#include "wx/textctrl.h"
|
||||||
#include "wx/dcclient.h"
|
#include "wx/dcclient.h"
|
||||||
#include "wx/scrolwin.h"
|
#include "wx/scrolwin.h"
|
||||||
#include "wx/settings.h"
|
#include "wx/settings.h"
|
||||||
@@ -386,8 +387,6 @@ class wxListRenameTimer: public wxTimer
|
|||||||
void Notify();
|
void Notify();
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxListTextCtrl (internal)
|
// wxListTextCtrl (internal)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -402,48 +401,19 @@ class wxListTextCtrl: public wxTextCtrl
|
|||||||
wxListMainWindow *m_owner;
|
wxListMainWindow *m_owner;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxListTextCtrl(void) : wxTextCtrl() {};
|
wxListTextCtrl(void) {};
|
||||||
wxListTextCtrl( wxWindow *parent, const char *value = "",
|
wxListTextCtrl( wxWindow *parent, const wxWindowID id,
|
||||||
bool *accept, wxString *res, wxListMainWindow *owner,
|
bool *accept, wxString *res, wxListMainWindow *owner,
|
||||||
int x = -1, int y = -1, int w = -1, int h = -1, int style = 0, char *name = "rawtext" ) :
|
const wxString &value = "",
|
||||||
wxTextCtrl( parent, value, x, y, w, h, style, name )
|
const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
|
||||||
{
|
int style = 0, const wxValidator& validator = wxDefaultValidator,
|
||||||
m_res = res;
|
const wxString &name = "wxListTextCtrlText" );
|
||||||
m_accept = accept;
|
void OnChar( wxKeyEvent &event );
|
||||||
m_owner = owner;
|
void OnKillFocus( wxFocusEvent &event );
|
||||||
};
|
|
||||||
void OnChar( wxKeyEvent &event )
|
DECLARE_EVENT_TABLE()
|
||||||
{
|
|
||||||
if (event.keyCode == WXK_RETURN)
|
|
||||||
{
|
|
||||||
(*m_accept) = TRUE;
|
|
||||||
(*m_res) = GetValue();
|
|
||||||
m_owner->OnRenameAccept();
|
|
||||||
// Show( FALSE );
|
|
||||||
delete this;
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
if (event.keyCode == WXK_ESCAPE)
|
|
||||||
{
|
|
||||||
(*m_accept) = FALSE;
|
|
||||||
(*m_res) = "";
|
|
||||||
// Show( FALSE );
|
|
||||||
delete this;
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
void OnKillFocus(void)
|
|
||||||
{
|
|
||||||
(*m_accept) = FALSE;
|
|
||||||
(*m_res) = "";
|
|
||||||
// Show( FALSE );
|
|
||||||
delete this;
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxListMainWindow (internal)
|
// wxListMainWindow (internal)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -494,6 +464,7 @@ class wxListMainWindow: public wxScrolledWindow
|
|||||||
void DeselectLine( wxListLineData *line );
|
void DeselectLine( wxListLineData *line );
|
||||||
void DeleteLine( wxListLineData *line );
|
void DeleteLine( wxListLineData *line );
|
||||||
void RenameLine( wxListLineData *line, const wxString &newName );
|
void RenameLine( wxListLineData *line, const wxString &newName );
|
||||||
|
void StartLabelEdit( wxListLineData *line );
|
||||||
void OnRenameTimer(void);
|
void OnRenameTimer(void);
|
||||||
void OnRenameAccept(void);
|
void OnRenameAccept(void);
|
||||||
void OnMouse( wxMouseEvent &event );
|
void OnMouse( wxMouseEvent &event );
|
||||||
|
@@ -770,6 +770,59 @@ void wxListRenameTimer::Notify()
|
|||||||
m_owner->OnRenameTimer();
|
m_owner->OnRenameTimer();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxListTextCtrl (internal)
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl,wxTextCtrl);
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl)
|
||||||
|
EVT_CHAR (wxListTextCtrl::OnChar)
|
||||||
|
EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
wxListTextCtrl::wxListTextCtrl( wxWindow *parent, const wxWindowID id,
|
||||||
|
bool *accept, wxString *res, wxListMainWindow *owner,
|
||||||
|
const wxString &value, const wxPoint &pos, const wxSize &size,
|
||||||
|
int style, const wxValidator& validator, const wxString &name ) :
|
||||||
|
wxTextCtrl( parent, id, value, pos, size, style, validator, name )
|
||||||
|
{
|
||||||
|
m_res = res;
|
||||||
|
m_accept = accept;
|
||||||
|
m_owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxListTextCtrl::OnChar( wxKeyEvent &event )
|
||||||
|
{
|
||||||
|
if (event.m_keyCode == WXK_RETURN)
|
||||||
|
{
|
||||||
|
(*m_accept) = TRUE;
|
||||||
|
(*m_res) = GetValue();
|
||||||
|
m_owner->OnRenameAccept();
|
||||||
|
// Show( FALSE );
|
||||||
|
Destroy();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.m_keyCode == WXK_ESCAPE)
|
||||||
|
{
|
||||||
|
(*m_accept) = FALSE;
|
||||||
|
(*m_res) = "";
|
||||||
|
// Show( FALSE );
|
||||||
|
Destroy();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
|
||||||
|
{
|
||||||
|
(*m_accept) = FALSE;
|
||||||
|
(*m_res) = "";
|
||||||
|
// Show( FALSE );
|
||||||
|
Destroy();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxListMainWindow
|
// wxListMainWindow
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -804,7 +857,8 @@ wxListMainWindow::wxListMainWindow( void )
|
|||||||
m_hasFocus = FALSE;
|
m_hasFocus = FALSE;
|
||||||
m_usedKeys = TRUE;
|
m_usedKeys = TRUE;
|
||||||
m_lastOnSame = FALSE;
|
m_lastOnSame = FALSE;
|
||||||
// m_renameTimer = new wxRenameTimer( this );
|
// m_renameTimer = new wxListRenameTimer( this );
|
||||||
|
m_renameTimer = NULL;
|
||||||
m_isCreated = FALSE;
|
m_isCreated = FALSE;
|
||||||
m_dragCount = 0;
|
m_dragCount = 0;
|
||||||
};
|
};
|
||||||
@@ -853,11 +907,6 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
|
|||||||
// m_text->Show( FALSE );
|
// m_text->Show( FALSE );
|
||||||
|
|
||||||
SetBackgroundColour( *wxWHITE );
|
SetBackgroundColour( *wxWHITE );
|
||||||
|
|
||||||
/*
|
|
||||||
char *accepted_drop_types[] = { "text/plain" };
|
|
||||||
gtk_widget_dnd_drag_set( m_wxwindow, TRUE, accepted_drop_types, 1 );
|
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
|
|
||||||
wxListMainWindow::~wxListMainWindow( void )
|
wxListMainWindow::~wxListMainWindow( void )
|
||||||
@@ -977,9 +1026,17 @@ void wxListMainWindow::DeleteLine( wxListLineData *line )
|
|||||||
SendNotify( line, wxEVT_COMMAND_LIST_DELETE_ITEM );
|
SendNotify( line, wxEVT_COMMAND_LIST_DELETE_ITEM );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void wxListMainWindow::StartLabelEdit( wxListLineData *line )
|
||||||
|
{
|
||||||
|
SendNotify( line, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT );
|
||||||
|
};
|
||||||
|
|
||||||
void wxListMainWindow::RenameLine( wxListLineData *line, const wxString &newName )
|
void wxListMainWindow::RenameLine( wxListLineData *line, const wxString &newName )
|
||||||
{
|
{
|
||||||
wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT );
|
if (!m_parent) return;
|
||||||
|
|
||||||
|
wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, m_parent->GetId() );
|
||||||
|
le.SetEventObject( m_parent );
|
||||||
le.m_code = 0;
|
le.m_code = 0;
|
||||||
le.m_itemIndex = GetIndexOfLine( line );
|
le.m_itemIndex = GetIndexOfLine( line );
|
||||||
le.m_col = 0;
|
le.m_col = 0;
|
||||||
@@ -990,7 +1047,7 @@ void wxListMainWindow::RenameLine( wxListLineData *line, const wxString &newName
|
|||||||
|
|
||||||
void wxListMainWindow::OnRenameTimer()
|
void wxListMainWindow::OnRenameTimer()
|
||||||
{
|
{
|
||||||
return;
|
StartLabelEdit( m_current );
|
||||||
wxString s;
|
wxString s;
|
||||||
m_current->GetText( 0, s );
|
m_current->GetText( 0, s );
|
||||||
int x = 0;
|
int x = 0;
|
||||||
@@ -998,16 +1055,15 @@ void wxListMainWindow::OnRenameTimer()
|
|||||||
int w = 0;
|
int w = 0;
|
||||||
int h = 0;
|
int h = 0;
|
||||||
m_current->GetLabelExtent( x, y, w, h );
|
m_current->GetLabelExtent( x, y, w, h );
|
||||||
int dx = 0;
|
|
||||||
int dy = 0;
|
wxClientDC dc(this);
|
||||||
GetPosition( &dx, &dy );
|
PrepareDC( dc );
|
||||||
x += dx;
|
x = dc.LogicalToDeviceX( x );
|
||||||
y += dy;
|
y = dc.LogicalToDeviceY( y );
|
||||||
/*
|
|
||||||
wxRawListTextCtrl *text = new wxRawListTextCtrl(
|
wxListTextCtrl *text = new wxListTextCtrl(
|
||||||
GetParent(), s, &m_renameAccept, &m_renameRes, this, x+2, y+2, w+8, h+8 );
|
this, -1, &m_renameAccept, &m_renameRes, this, s, wxPoint(x-4,y-4), wxSize(w+11,h+8) );
|
||||||
text->SetFocus();
|
text->SetFocus();
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
m_text->SetSize( x+3, y+3, w+6, h+6 );
|
m_text->SetSize( x+3, y+3, w+6, h+6 );
|
||||||
m_text->SetValue( s );
|
m_text->SetValue( s );
|
||||||
@@ -1088,7 +1144,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
|
|||||||
(hitResult == wxLIST_HITTEST_ONITEMLABEL) /* &&
|
(hitResult == wxLIST_HITTEST_ONITEMLABEL) /* &&
|
||||||
(m_mode & wxLC_ICON) */ )
|
(m_mode & wxLC_ICON) */ )
|
||||||
{
|
{
|
||||||
m_renameTimer->Start( 330, TRUE );
|
m_renameTimer->Start( 100, TRUE );
|
||||||
};
|
};
|
||||||
m_lastOnSame = FALSE;
|
m_lastOnSame = FALSE;
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user