// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
-// Licence: wxWindows licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TEXTCTRL_H_
{
DECLARE_DYNAMIC_CLASS(wxTextCtrl)
-
+
public:
// creation
// --------
{
Create(parent, id, value, pos, size, style, validator, name);
}
-
+
bool Create(wxWindow *parent, wxWindowID id,
const wxString& value = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = wxTE_PROCESS_TAB,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxTextCtrlNameStr);
-
+
// accessors
// ---------
virtual wxString GetValue() const ;
void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO)
{ wxWindow::SetSize(rect, sizeFlags); }
void SetSize(const wxSize& size) { wxWindow::SetSize(size); }
-
+
// Clipboard operations
virtual void Copy();
virtual void Cut();
virtual void Paste();
-
+
virtual void SetInsertionPoint(long pos);
virtual void SetInsertionPointEnd();
virtual long GetInsertionPoint() const ;
virtual void Remove(long from, long to);
virtual void SetSelection(long from, long to);
virtual void SetEditable(bool editable);
-
+
// streambuf implementation
#ifndef NO_TEXT_WINDOW_STREAM
int overflow(int i);
int sync();
int underflow();
#endif
-
+
wxTextCtrl& operator<<(const wxString& s);
wxTextCtrl& operator<<(int i);
wxTextCtrl& operator<<(long i);
wxTextCtrl& operator<<(float f);
wxTextCtrl& operator<<(double d);
wxTextCtrl& operator<<(const char c);
-
+
virtual bool LoadFile(const wxString& file);
virtual bool SaveFile(const wxString& file);
virtual void WriteText(const wxString& text);
+ virtual void AppendText(const wxString& text);
virtual void DiscardEdits();
virtual bool IsModified() const;
-
+
#if WXWIN_COMPATIBILITY
inline bool Modified() const { return IsModified(); }
#endif
-
+
virtual long XYToPosition(long x, long y) const ;
virtual void PositionToXY(long pos, long *x, long *y) const ;
virtual void ShowPosition(long pos);
virtual void Clear();
-
+
// callbacks
// ---------
void OnDropFiles(wxDropFilesEvent& event);
void OnChar(wxKeyEvent& event); // Process 'enter' if required
void OnEraseBackground(wxEraseEvent& event);
-
+
// Implementation
// --------------
virtual void Command(wxCommandEvent& event);
virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam,
WXLPARAM lParam);
-
+
virtual void AdoptAttributesFromHWND();
virtual void SetupColours();
virtual long MSWGetDlgCode();
-
+
protected:
#if wxUSE_RICHEDIT
bool m_isRich; // Are we using rich text edit to implement this?
#endif
wxString m_fileName;
-
+
DECLARE_EVENT_TABLE()
};
const wxPoint &pos, const wxSize &size, int style = 0)
: wxTextCtrl(parent, id, value, pos, size, style) { }
- void OnChar(wxKeyEvent& event);
+ void OnKeyDown(wxKeyEvent& event);
private:
DECLARE_EVENT_TABLE()
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnIdle( wxIdleEvent& event );
+ void OnSize( wxSizeEvent& event );
DECLARE_EVENT_TABLE()
};
//----------------------------------------------------------------------
BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl)
- EVT_CHAR(MyTextCtrl::OnChar)
+ EVT_KEY_DOWN(MyTextCtrl::OnKeyDown)
END_EVENT_TABLE()
-void MyTextCtrl::OnChar(wxKeyEvent& event)
+void MyTextCtrl::OnKeyDown(wxKeyEvent& event)
{
switch ( event.KeyCode() )
{
EVT_BUTTON (ID_MOVE_END_ENTRY, MyPanel::OnMoveToEndOfEntry)
END_EVENT_TABLE()
-MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) :
- wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) )
+MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
+ : m_notebook(NULL), m_text(NULL),
+ wxPanel( frame, -1, wxPoint(x, y), wxSize(w, h) )
{
// SetBackgroundColour("cadet blue");
panel = new wxPanel(m_notebook);
m_textentry = new MyTextCtrl( panel, -1, "Write text here.", wxPoint(10,10), wxSize(320,28),
wxTE_PROCESS_ENTER);
- (*m_textentry) << " More text.";
+ (*m_textentry) << " More text."; // this text is appended
+ m_textentry->SetInsertionPoint(0);
+ m_textentry->WriteText("Less text."); // this text is prepended
+
m_multitext = new MyTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(320,70),
wxTE_MULTILINE );
(*m_multitext) << " More text.\nPress function keys to test different \nwxTextCtrl functions.";
void MyPanel::OnListBox( wxCommandEvent &event )
{
- m_text->WriteText( "ListBox selection string is: " );
- m_text->WriteText( event.GetString() );
- m_text->WriteText( "\n" );
+ m_text->AppendText( "ListBox selection string is: " );
+ m_text->AppendText( event.GetString() );
+ m_text->AppendText( "\n" );
}
void MyPanel::OnListBoxDoubleClick( wxCommandEvent &event )
{
- m_text->WriteText( "ListBox double click string is: " );
- m_text->WriteText( event.GetString() );
- m_text->WriteText( "\n" );
+ m_text->AppendText( "ListBox double click string is: " );
+ m_text->AppendText( event.GetString() );
+ m_text->AppendText( "\n" );
}
void MyPanel::OnListBoxButtons( wxCommandEvent &event )
{
case ID_LISTBOX_ENABLE:
{
- m_text->WriteText("Checkbox clicked.\n");
+ m_text->AppendText("Checkbox clicked.\n");
wxCheckBox *cb = (wxCheckBox*)event.GetEventObject();
if (event.GetInt())
cb->SetToolTip( "Click to enable listbox" );
void MyPanel::OnChoice( wxCommandEvent &event )
{
- m_text->WriteText( "Choice selection string is: " );
- m_text->WriteText( event.GetString() );
- m_text->WriteText( "\n" );
+ m_text->AppendText( "Choice selection string is: " );
+ m_text->AppendText( event.GetString() );
+ m_text->AppendText( "\n" );
}
void MyPanel::OnChoiceButtons( wxCommandEvent &event )
void MyPanel::OnCombo( wxCommandEvent &event )
{
- m_text->WriteText( "ComboBox selection string is: " );
- m_text->WriteText( event.GetString() );
- m_text->WriteText( "\n" );
+ m_text->AppendText( "ComboBox selection string is: " );
+ m_text->AppendText( event.GetString() );
+ m_text->AppendText( "\n" );
}
void MyPanel::OnComboButtons( wxCommandEvent &event )
void MyPanel::OnRadio( wxCommandEvent &event )
{
- m_text->WriteText( "RadioBox selection string is: " );
- m_text->WriteText( event.GetString() );
- m_text->WriteText( "\n" );
+ m_text->AppendText( "RadioBox selection string is: " );
+ m_text->AppendText( event.GetString() );
+ m_text->AppendText( "\n" );
}
void MyPanel::OnRadioButtons( wxCommandEvent &event )
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(MINIMAL_QUIT, MyFrame::OnQuit)
EVT_MENU(MINIMAL_ABOUT, MyFrame::OnAbout)
+ EVT_SIZE(MyFrame::OnSize)
EVT_IDLE(MyFrame::OnIdle)
END_EVENT_TABLE()
MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
: wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
{
- CreateStatusBar();
+ CreateStatusBar(2);
(void)new MyPanel( this, 10, 10, 300, 100 );
}
dialog.ShowModal();
}
+void MyFrame::OnSize( wxSizeEvent& event )
+{
+ wxString msg;
+ msg.Printf("%dx%d", event.GetSize().x, event.GetSize().y);
+ SetStatusText(msg, 1);
+
+ event.Skip();
+}
+
void MyFrame::OnIdle( wxIdleEvent& WXUNUSED(event) )
{
// track the window which has the focus in the status bar
long msStyle = ES_LEFT | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
if (m_windowStyle & wxTE_MULTILINE)
{
+ wxASSERT_MSG( !(m_windowStyle & wxTE_PROCESS_ENTER),
+ "wxTE_PROCESS_ENTER style is ignored for multiline controls" );
+
msStyle |= ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL ; // WS_BORDER
m_windowStyle |= wxTE_PROCESS_ENTER;
}
delete[] newtext;
}
+void wxTextCtrl::AppendText(const wxString& text)
+{
+ SetInsertionPointEnd();
+ WriteText(text);
+}
+
void wxTextCtrl::Clear()
{
-// SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)"");
SetWindowText((HWND) GetHWND(), "");
}
txt[plen] = (char)c; // append c
txt[plen+xtra] = '\0'; // append '\0' or overwrite c
// If the put area already contained \0, output will be truncated there
- WriteText(txt);
+ AppendText(txt);
delete[] txt;
}
wxTextCtrl& wxTextCtrl::operator<<(const wxString& s)
{
- WriteText(s);
- return *this;
+ AppendText(s);
+ return *this;
}
wxTextCtrl& wxTextCtrl::operator<<(float f)
{
wxString str;
str.Printf("%.2f", f);
- WriteText(str);
+ AppendText(str);
return *this;
}
{
wxString str;
str.Printf("%.2f", d);
- WriteText(str);
+ AppendText(str);
return *this;
}
{
wxString str;
str.Printf("%d", i);
- WriteText(str);
+ AppendText(str);
return *this;
}
{
wxString str;
str.Printf("%ld", i);
- WriteText(str);
+ AppendText(str);
return *this;
}
buf[0] = c;
buf[1] = 0;
- WriteText(buf);
+ AppendText(buf);
return *this;
}
case WXK_RETURN:
wxASSERT_MSG( m_windowStyle & wxTE_PROCESS_ENTER,
"this text ctrl should never receive return" );
+ if ( m_windowStyle & wxTE_MULTILINE == 0 )
{
wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
event.SetEventObject( this );
if ( GetEventHandler()->ProcessEvent(event) )
return;
}
+ //else: multiline controls need Enter for themselves
+
+ break;
case WXK_TAB:
- // only produce navigation event if we don't process TAB ourself
- if ( !(m_windowStyle & wxTE_PROCESS_TAB) )
+ // only produce navigation event if we don't process TAB ourself or
+ // if it's a Shift-Tab keypress (we assume nobody will ever need
+ // this key combo for himself)
+ //
+ // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
+ // handled by Windows
+ if ( event.ShiftDown() || !(m_windowStyle & wxTE_PROCESS_TAB) )
{
- wxNavigationKeyEvent event;
- event.SetDirection(!(::GetKeyState(VK_SHIFT) & 0x100));
- event.SetWindowChange(FALSE);
- event.SetEventObject(this);
+ wxNavigationKeyEvent eventNav;
+ eventNav.SetDirection(!event.ShiftDown());
+ eventNav.SetWindowChange(FALSE);
+ eventNav.SetEventObject(this);
- if ( GetEventHandler()->ProcessEvent(event) )
+ if ( GetEventHandler()->ProcessEvent(eventNav) )
return;
}
}
break;
}
-#if 0
case WM_KEYDOWN:
{
MSWOnKeyDown((WORD) wParam, lParam);
return Default();
break;
}
-#endif
case WM_KEYUP:
{
bool bCtrlDown = (::GetKeyState(VK_CONTROL) & 0x100) != 0;
// WM_GETDLGCODE: if the control wants it for itself, don't process it
- // (except for Ctrl-Tab combination which is always processed)
+ // (except for Ctrl-Tab/Enter combinations which are always processed)
LONG lDlgCode = 0;
if ( bProcess && !bCtrlDown ) {
lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0);
if ( !GetDefaultItem() ) {
// but if there is not it makes sense to make it work
// like a TAB
+ if ( bCtrlDown || (lDlgCode & DLGC_WANTMESSAGE == 0) )
+ {
+ // nothing to do - all variables are already set
- // nothing to do - all variables are already set
-
- break;
+ break;
+ }
+ else
+ {
+ // control wants to process Enter itself, don't
+ // call IsDialogMessage() which would interpret
+ // it
+ return FALSE;
+ }
}
//else: fall through and don't process the message