/////////////////////////////////////////////////////////////////////////////
// Name: textctrl.cpp
// Purpose: wxTextCtrl
-// Author: AUTHOR
+// Author: David Webster
// Modified by:
-// Created: ??/??/98
+// Created: 10/17/99
// RCS-ID: $Id$
-// Copyright: (c) AUTHOR
-// Licence: wxWindows licence
+// Copyright: (c) David Webster
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
-#pragma implementation "textctrl.h"
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifndef WX_PRECOMP
+ #include "wx/textctrl.h"
+ #include "wx/settings.h"
+ #include "wx/brush.h"
+ #include "wx/utils.h"
+ #include "wx/log.h"
#endif
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fstream.h>
+#if wxUSE_CLIPBOARD
+ #include "wx/app.h"
+ #include "wx/clipbrd.h"
+#endif
-#include "wx/textctrl.h"
-#include "wx/settings.h"
-#include "wx/filefn.h"
-#include "wx/utils.h"
+#include "wx/textfile.h"
+
+#include "wx/os2/private.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
-#if defined(__BORLANDC__) && !defined(__WIN32__)
-#include <alloc.h>
+#if wxUSE_IOSTREAMH
+# include <fstream.h>
#else
-#ifndef __GNUWIN32__
-#include <malloc.h>
-#endif
+# include <fstream>
#endif
-#if !USE_SHARED_LIBRARY
+
+// ----------------------------------------------------------------------------
+// event tables and other macros
+// ----------------------------------------------------------------------------
+
IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
- EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
+ EVT_CHAR(wxTextCtrl::OnChar)
+ EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
+
EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
END_EVENT_TABLE()
-#endif
-// Text item
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// creation
+// ----------------------------------------------------------------------------
+
wxTextCtrl::wxTextCtrl()
-#ifndef NO_TEXT_WINDOW_STREAM
- :streambuf()
-#endif
{
- m_fileName = "";
}
bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
- const wxString& value,
- const wxPoint& pos,
- const wxSize& size, long style,
- const wxValidator& validator,
- const wxString& name)
+ const wxString& value,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style,
+#if wxUSE_VALIDATORS
+ const wxValidator& validator,
+#endif
+ const wxString& name)
{
- m_fileName = "";
- SetName(name);
- SetValidator(validator);
- if (parent) parent->AddChild(this);
+ // base initialization
+ if ( !CreateBase(parent, id, pos, size, style, validator, name) )
+ return FALSE;
- m_windowStyle = style;
+ // Validator was set in CreateBase
+ //SetValidator(validator);
+ if ( parent )
+ parent->AddChild(this);
- if ( id == -1 )
- m_windowId = (int)NewControlId();
+ // set colours
+ SetupColours();
+
+ // translate wxWin style flags to MSW ones, checking for consistency while
+ // doing it
+// TODO:
+/*
+ long msStyle = ES_LEFT | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
+ if ( m_windowStyle & wxTE_MULTILINE )
+ {
+ wxASSERT_MSG( !(m_windowStyle & wxTE_PROCESS_ENTER),
+ wxT("wxTE_PROCESS_ENTER style is ignored for multiline "
+ "text controls (they always process it)") );
+
+ msStyle |= ES_MULTILINE | ES_WANTRETURN;
+ if ((m_windowStyle & wxTE_NO_VSCROLL) == 0)
+ msStyle |= WS_VSCROLL;
+ m_windowStyle |= wxTE_PROCESS_ENTER;
+ }
else
- m_windowId = id;
+ msStyle |= ES_AUTOHSCROLL;
+
+ if (m_windowStyle & wxHSCROLL)
+ msStyle |= (WS_HSCROLL | ES_AUTOHSCROLL);
+
+ if (m_windowStyle & wxTE_READONLY)
+ msStyle |= ES_READONLY;
+
+ if (m_windowStyle & wxHSCROLL)
+ msStyle |= (WS_HSCROLL | ES_AUTOHSCROLL);
+ if (m_windowStyle & wxTE_PASSWORD) // hidden input
+ msStyle |= ES_PASSWORD;
+
+ // we always want the characters and the arrows
+ m_lDlgCode = DLGC_WANTCHARS | DLGC_WANTARROWS;
+
+ // we may have several different cases:
+ // 1. normal case: both TAB and ENTER are used for dialog navigation
+ // 2. ctrl which wants TAB for itself: ENTER is used to pass to the next
+ // control in the dialog
+ // 3. ctrl which wants ENTER for itself: TAB is used for dialog navigation
+ // 4. ctrl which wants both TAB and ENTER: Ctrl-ENTER is used to pass to
+ // the next control
+ if ( m_windowStyle & wxTE_PROCESS_ENTER )
+ m_lDlgCode |= DLGC_WANTMESSAGE;
+ if ( m_windowStyle & wxTE_PROCESS_TAB )
+ m_lDlgCode |= DLGC_WANTTAB;
+
+ // do create the control - either an EDIT or RICHEDIT
+ const wxChar *windowClass = wxT("EDIT");
+
+ bool want3D;
+ WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D);
+
+ // Even with extended styles, need to combine with WS_BORDER for them to
+ // look right.
+ if ( want3D || wxStyleHasBorder(m_windowStyle) )
+ msStyle |= WS_BORDER;
+
+ // NB: don't use pos and size as CreateWindowEx arguments because they
+ // might be -1 in which case we should use the default values (and
+ // SetSize called below takes care of it)
+ m_hWnd = (WXHWND)::CreateWindowEx(exStyle,
+ windowClass,
+ NULL,
+ msStyle,
+ 0, 0, 0, 0,
+ GetHwndOf(parent),
+ (HMENU)m_windowId,
+ wxGetInstance(),
+ NULL);
+
+ wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create text ctrl") );
+*/
+ SubclassWin(GetHWND());
+
+ // set font, position, size and initial value
+ wxFont& fontParent = parent->GetFont();
+ if ( fontParent.Ok() )
+ {
+ SetFont(fontParent);
+ }
+ else
+ {
+ SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT));
+ }
+
+ SetSize(pos.x, pos.y, size.x, size.y);
return TRUE;
}
+// Make sure the window style (etc.) reflects the HWND style (roughly)
+void wxTextCtrl::AdoptAttributesFromHWND()
+{
+ wxWindow::AdoptAttributesFromHWND();
+
+ HWND hWnd = GetHwnd();
+ // TODO:
+ /*
+ long style = GetWindowLong(hWnd, GWL_STYLE);
+
+ if (style & ES_MULTILINE)
+ m_windowStyle |= wxTE_MULTILINE;
+ if (style & ES_PASSWORD)
+ m_windowStyle |= wxTE_PASSWORD;
+ if (style & ES_READONLY)
+ m_windowStyle |= wxTE_READONLY;
+ if (style & ES_WANTRETURN)
+ m_windowStyle |= wxTE_PROCESS_ENTER;
+ */
+}
+
+void wxTextCtrl::SetupColours()
+{
+ // FIXME why is bg colour not inherited from parent?
+ SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
+ SetForegroundColour(GetParent()->GetForegroundColour());
+}
+
+// ----------------------------------------------------------------------------
+// set/get the controls text
+// ----------------------------------------------------------------------------
+
wxString wxTextCtrl::GetValue() const
{
- // TODO
- return wxString("");
+ return wxGetWindowText(GetHWND());
}
void wxTextCtrl::SetValue(const wxString& value)
{
- // TODO
+// TODO:
+/*
+ wxString valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
+
+ SetWindowText(GetHwnd(), valueDos);
+
+ AdjustSpaceLimit();
+*/
+}
+
+void wxTextCtrl::WriteText(const wxString& value)
+{
+// TODO:
+/*
+ wxString valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
+
+ SendMessage(GetHwnd(), EM_REPLACESEL, 0, (LPARAM)valueDos.c_str());
+
+ AdjustSpaceLimit();
+*/
}
-void wxTextCtrl::SetSize(int x, int y, int width, int height, int sizeFlags)
+void wxTextCtrl::AppendText(const wxString& text)
+{
+// TODO:
+/*
+ SetInsertionPointEnd();
+ WriteText(text);
+*/
+}
+
+void wxTextCtrl::Clear()
{
- // TODO
+// SetWindowText(GetHwnd(), wxT(""));
}
+// ----------------------------------------------------------------------------
// Clipboard operations
+// ----------------------------------------------------------------------------
+
void wxTextCtrl::Copy()
{
- // TODO
+ if (CanCopy())
+ {
+ HWND hWnd = GetHwnd();
+// SendMessage(hWnd, WM_COPY, 0, 0L);
+ }
}
void wxTextCtrl::Cut()
{
- // TODO
+ if (CanCut())
+ {
+ HWND hWnd = GetHwnd();
+// SendMessage(hWnd, WM_CUT, 0, 0L);
+ }
}
void wxTextCtrl::Paste()
{
- // TODO
+ if (CanPaste())
+ {
+ HWND hWnd = GetHwnd();
+// SendMessage(hWnd, WM_PASTE, 0, 0L);
+ }
+}
+
+bool wxTextCtrl::CanCopy() const
+{
+ // Can copy if there's a selection
+ long from = 0L;
+ long to = 0L;
+// GetSelection(& from, & to);
+ return (from != to);
+}
+
+bool wxTextCtrl::CanCut() const
+{
+ // Can cut if there's a selection
+ long from = 0L;
+ long to = 0L;
+// GetSelection(& from, & to);
+ return (from != to);
+}
+
+bool wxTextCtrl::CanPaste() const
+{
+ if (!IsEditable())
+ return FALSE;
+
+ // Standard edit control: check for straight text on clipboard
+ bool isTextAvailable = FALSE;
+//TODO:
+/*
+ if ( ::OpenClipboard(GetHwndOf(wxTheApp->GetTopWindow())) )
+ {
+ isTextAvailable = (::IsClipboardFormatAvailable(CF_TEXT) != 0);
+ ::CloseClipboard();
+ }
+*/
+ return isTextAvailable;
}
+// ----------------------------------------------------------------------------
+// Accessors
+// ----------------------------------------------------------------------------
+
void wxTextCtrl::SetEditable(bool editable)
{
- // TODO
+ HWND hWnd = GetHwnd();
+// SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
}
void wxTextCtrl::SetInsertionPoint(long pos)
{
- // TODO
+// TODO:
+/*
+ HWND hWnd = GetHwnd();
+ {
+ SendMessage(hWnd, EM_SETSEL, pos, pos);
+ SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
+ }
+ static const char *nothing = "";
+ SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)nothing);
+*/
}
void wxTextCtrl::SetInsertionPointEnd()
{
+// TODO:
+/*
long pos = GetLastPosition();
SetInsertionPoint(pos);
+*/
}
long wxTextCtrl::GetInsertionPoint() const
{
- // TODO
+// TODO:
+/*
+ DWORD Pos = (DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
+ return Pos & 0xFFFF;
+*/
return 0;
}
long wxTextCtrl::GetLastPosition() const
{
- // TODO
- return 0;
-}
+ HWND hWnd = GetHwnd();
-void wxTextCtrl::Replace(long from, long to, const wxString& value)
-{
- // TODO
-}
+// TODO:
+/*
+ // Will always return a number > 0 (according to docs)
+ int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L);
-void wxTextCtrl::Remove(long from, long to)
-{
- // TODO
-}
+ // This gets the char index for the _beginning_ of the last line
+ int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)(noLines-1), (LPARAM)0L);
-void wxTextCtrl::SetSelection(long from, long to)
-{
- // TODO
+ // Get number of characters in the last line. We'll add this to the character
+ // index for the last line, 1st position.
+ int lineLength = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0L);
+
+ return (long)(charIndex + lineLength);
+*/
+ return 0L;
}
-bool wxTextCtrl::LoadFile(const wxString& file)
+// If the return values from and to are the same, there is no
+// selection.
+void wxTextCtrl::GetSelection(long* from, long* to) const
{
- if (!wxFileExists(file))
- return FALSE;
+ DWORD dwStart, dwEnd;
+ MPARAM wParam = (MPARAM) (DWORD*) & dwStart; // receives starting position
+ MPARAM lParam = (MPARAM) (DWORD*) & dwEnd; // receives ending position
- m_fileName = file;
+// ::SendMessage(GetHwnd(), EM_GETSEL, wParam, lParam);
- Clear();
+ *from = dwStart;
+ *to = dwEnd;
+}
- ifstream input((char*) (const char*) file, ios::nocreate | ios::in);
+bool wxTextCtrl::IsEditable() const
+{
+// TODO:
+/*
+ long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
- if (!input.bad())
- {
- struct stat stat_buf;
- if (stat(file, &stat_buf) < 0)
- return FALSE;
- // This may need to be a bigger buffer than the file size suggests,
- // if it's a UNIX file. Give it an extra 1000 just in case.
- char *tmp_buffer = (char*)malloc((size_t)(stat_buf.st_size+1+1000));
- long no_lines = 0;
- long pos = 0;
- while (!input.eof() && input.peek() != EOF)
- {
- input.getline(wxBuffer, 500);
- int len = strlen(wxBuffer);
- wxBuffer[len] = 13;
- wxBuffer[len+1] = 10;
- wxBuffer[len+2] = 0;
- strcpy(tmp_buffer+pos, wxBuffer);
- pos += strlen(wxBuffer);
- no_lines++;
- }
-
- // TODO add line
-
- free(tmp_buffer);
-
- return TRUE;
- }
+ return ((style & ES_READONLY) == 0);
+*/
return FALSE;
}
-// If file is null, try saved file name first
-// Returns TRUE if succeeds.
-bool wxTextCtrl::SaveFile(const wxString& file)
+// ----------------------------------------------------------------------------
+// Editing
+// ----------------------------------------------------------------------------
+
+void wxTextCtrl::Replace(long from, long to, const wxString& value)
{
- wxString theFile(file);
- if (theFile == "")
- theFile = m_fileName;
- if (theFile == "")
- return FALSE;
- m_fileName = theFile;
+#if wxUSE_CLIPBOARD
+ HWND hWnd = GetHwnd();
+ long fromChar = from;
+ long toChar = to;
- ofstream output((char*) (const char*) theFile);
- if (output.bad())
- return FALSE;
+ // Set selection and remove it
+// SendMessage(hWnd, EM_SETSEL, fromChar, toChar);
+// SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
- // TODO get and save text
+ // Now replace with 'value', by pasting.
+ wxSetClipboardData(wxDF_TEXT, (wxObject *) (const wxChar *)value, 0, 0);
- return FALSE;
+ // Paste into edit control
+// SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L);
+#else
+ wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
+#endif
}
-void wxTextCtrl::WriteText(const wxString& text)
+void wxTextCtrl::Remove(long from, long to)
{
- // TODO write text to control
+ HWND hWnd = GetHwnd();
+ long fromChar = from;
+ long toChar = to;
+
+ // Cut all selected text
+// SendMessage(hWnd, EM_SETSEL, fromChar, toChar);
+// SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
}
-void wxTextCtrl::AppendText(const wxString& text)
+void wxTextCtrl::SetSelection(long from, long to)
{
- // TODO append text to control
+ HWND hWnd = GetHwnd();
+ long fromChar = from;
+ long toChar = to;
+
+ // if from and to are both -1, it means (in wxWindows) that all text should
+ // be selected. Translate into Windows convention
+ if ((from == -1) && (to == -1))
+ {
+ fromChar = 0;
+ toChar = -1;
+ }
+
+// SendMessage(hWnd, EM_SETSEL, (WPARAM)fromChar, (LPARAM)toChar);
+// SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
}
-void wxTextCtrl::Clear()
+bool wxTextCtrl::LoadFile(const wxString& file)
{
- // TODO
+// TODO:
+/*
+ if ( wxTextCtrlBase::LoadFile(file) )
+ {
+ // update the size limit if needed
+ AdjustSpaceLimit();
+
+ return TRUE;
+ }
+*/
+ return FALSE;
}
bool wxTextCtrl::IsModified() const
{
- // TODO
+// return (SendMessage(GetHwnd(), EM_GETMODIFY, 0, 0) != 0);
return FALSE;
}
// Makes 'unmodified'
void wxTextCtrl::DiscardEdits()
{
- // TODO
+// SendMessage(GetHwnd(), EM_SETMODIFY, FALSE, 0L);
}
int wxTextCtrl::GetNumberOfLines() const
{
- // TODO
+// return (int)SendMessage(GetHwnd(), EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
return 0;
}
long wxTextCtrl::XYToPosition(long x, long y) const
{
- // TODO
- return 0;
+ HWND hWnd = GetHwnd();
+
+ // This gets the char index for the _beginning_ of this line
+// TODO:
+/*
+ int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)y, (LPARAM)0);
+ return (long)(x + charIndex);
+*/
+ return 0L;
}
-void wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
+bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
{
- // TODO
+ HWND hWnd = GetHwnd();
+
+ // This gets the line number containing the character
+ int lineNo = -1;
+// lineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, 0);
+
+ if ( lineNo == -1 )
+ {
+ // no such line
+ return FALSE;
+ }
+
+ // This gets the char index for the _beginning_ of this line
+ int charIndex = 0; // TODO: (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)lineNo, (LPARAM)0);
+ if ( charIndex == -1 )
+ {
+ return FALSE;
+ }
+
+ // The X position must therefore be the different between pos and charIndex
+ if ( x )
+ *x = (long)(pos - charIndex);
+ if ( y )
+ *y = (long)lineNo;
+
+ return TRUE;
}
void wxTextCtrl::ShowPosition(long pos)
{
- // TODO
+ HWND hWnd = GetHwnd();
+
+ // To scroll to a position, we pass the number of lines and characters
+ // to scroll *by*. This means that we need to:
+ // (1) Find the line position of the current line.
+ // (2) Find the line position of pos.
+ // (3) Scroll by (pos - current).
+ // For now, ignore the horizontal scrolling.
+
+ // Is this where scrolling is relative to - the line containing the caret?
+ // Or is the first visible line??? Try first visible line.
+// int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
+
+// TODO:
+/*
+ int currentLineLineNo = (int)SendMessage(hWnd, EM_GETFIRSTVISIBLELINE, (WPARAM)0, (LPARAM)0L);
+
+ int specifiedLineLineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, (LPARAM)0L);
+
+ int linesToScroll = specifiedLineLineNo - currentLineLineNo;
+
+ if (linesToScroll != 0)
+ (void)SendMessage(hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)linesToScroll);
+*/
}
int wxTextCtrl::GetLineLength(long lineNo) const
{
- // TODO
+// TODO:
+/*
+
+ long charIndex = XYToPosition(0, lineNo);
+ int len = (int)SendMessage(GetHwnd(), EM_LINELENGTH, charIndex, 0);
+ return len;
+*/
return 0;
}
wxString wxTextCtrl::GetLineText(long lineNo) const
{
- // TODO
- return wxString("");
-}
+ size_t len = (size_t)GetLineLength(lineNo) + 1;
+ char *buf = (char *)malloc(len);
+ *(WORD *)buf = len;
+ int noChars = 0; // TODO:(int)SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
+ buf[noChars] = 0;
-bool wxTextCtrl::CanCopy() const
-{
- // Can copy if there's a selection
- long from, to;
- GetSelection(& from, & to);
- return (from != to) ;
-}
+ wxString str(buf);
-bool wxTextCtrl::CanCut() const
-{
- // Can cut if there's a selection
- long from, to;
- GetSelection(& from, & to);
- return (from != to) ;
-}
+ free(buf);
-bool wxTextCtrl::CanPaste() const
-{
- return IsEditable() ;
+ return str;
}
+// ----------------------------------------------------------------------------
// Undo/redo
+// ----------------------------------------------------------------------------
+
void wxTextCtrl::Undo()
{
- // TODO
+ if (CanUndo())
+ {
+// ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
+ }
}
void wxTextCtrl::Redo()
{
- // TODO
+ if (CanRedo())
+ {
+ // Same as Undo, since Undo undoes the undo, i.e. a redo.
+// ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
+ }
}
bool wxTextCtrl::CanUndo() const
{
- // TODO
+// return (::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0);
return FALSE;
}
bool wxTextCtrl::CanRedo() const
{
- // TODO
+// return (::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0);
return FALSE;
}
-// If the return values from and to are the same, there is no
-// selection.
-void wxTextCtrl::GetSelection(long* from, long* to) const
-{
- // TODO
- *from = 0;
- *to = 0;
-}
-
-bool wxTextCtrl::IsEditable() const
-{
- // TODO
- return FALSE;
-}
+// ----------------------------------------------------------------------------
+// implemenation details
+// ----------------------------------------------------------------------------
void wxTextCtrl::Command(wxCommandEvent & event)
{
- SetValue (event.GetString());
+ SetValue(event.GetString());
ProcessCommand (event);
}
}
}
-// The streambuf code was partly taken from chapter 3 by Jerry Schwarz of
-// AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers
-
-//=========================================================================
-// Called then the buffer is full (gcc 2.6.3)
-// or when "endl" is output (Borland 4.5)
-//=========================================================================
-// Class declaration using multiple inheritance doesn't work properly for
-// Borland. See note in wb_text.h.
-#ifndef NO_TEXT_WINDOW_STREAM
-int wxTextCtrl::overflow(int c)
-{
- // Make sure there is a holding area
- if ( allocate()==EOF )
- {
- wxError("Streambuf allocation failed","Internal error");
- return EOF;
- }
-
- // Verify that there are no characters in get area
- if ( gptr() && gptr() < egptr() )
- {
- wxError("Who's trespassing my get area?","Internal error");
- return EOF;
- }
-
- // Reset get area
- setg(0,0,0);
-
- // Make sure there is a put area
- if ( ! pptr() )
- {
-/* This doesn't seem to be fatal so comment out error message */
-// wxError("Put area not opened","Internal error");
- setp( base(), base() );
- }
-
- // Determine how many characters have been inserted but no consumed
- int plen = pptr() - pbase();
-
- // Now Jerry relies on the fact that the buffer is at least 2 chars
- // long, but the holding area "may be as small as 1" ???
- // And we need an additional \0, so let's keep this inefficient but
- // safe copy.
-
- // If c!=EOF, it is a character that must also be comsumed
- int xtra = c==EOF? 0 : 1;
-
- // Write temporary C-string to wxTextWindow
- {
- char *txt = new char[plen+xtra+1];
- memcpy(txt, pbase(), plen);
- 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
- AppendText(txt);
- delete[] txt;
- }
-
- // Reset put area
- setp(pbase(), epptr());
-
-#if defined(__WATCOMC__)
- return __NOT_EOF;
-#elif defined(zapeof) // HP-UX (all cfront based?)
- return zapeof(c);
-#else
- return c!=EOF ? c : 0; // this should make everybody happy
-#endif
-}
+WXHBRUSH wxTextCtrl::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
+ WXUINT message, WXWPARAM wParam,
+ WXLPARAM lParam)
+{
+ HDC hdc = (HDC)pDC;
+// TODO:
+/*
+ SetBkMode(hdc, GetParent()->GetTransparentBackground() ? TRANSPARENT
+ : OPAQUE);
-//=========================================================================
-// called then "endl" is output (gcc) or then explicit sync is done (Borland)
-//=========================================================================
-int wxTextCtrl::sync()
-{
- // Verify that there are no characters in get area
- if ( gptr() && gptr() < egptr() )
- {
- wxError("Who's trespassing my get area?","Internal error");
- return EOF;
- }
-
- if ( pptr() && pptr() > pbase() ) return overflow(EOF);
-
- return 0;
-/* OLD CODE
- int len = pptr() - pbase();
- char *txt = new char[len+1];
- strncpy(txt, pbase(), len);
- txt[len] = '\0';
- (*this) << txt;
- setp(pbase(), epptr());
- delete[] txt;
- return 0;
+ ::SetBkColor(hdc, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
+ ::SetTextColor(hdc, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
*/
-}
+ wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
-//=========================================================================
-// Should not be called by a "ostream". Used by a "istream"
-//=========================================================================
-int wxTextCtrl::underflow()
-{
- return EOF;
+ return (WXHBRUSH) backgroundBrush->GetResourceHandle();
}
-#endif
-wxTextCtrl& wxTextCtrl::operator<<(const wxString& s)
+void wxTextCtrl::OnChar(wxKeyEvent& event)
{
- AppendText(s);
- return *this;
-}
+ switch ( event.KeyCode() )
+ {
+// TODO:
+/*
+ case WXK_RETURN:
+ if ( !(m_windowStyle & wxTE_MULTILINE) )
+ {
+ 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:
+ // always produce navigation event - even if we process TAB
+ // ourselves the fact that we got here means that the user code
+ // decided to skip processing of this TAB - probably to let it
+ // do its default job.
+ //
+ // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
+ // handled by Windows
+ {
+ wxNavigationKeyEvent eventNav;
+ eventNav.SetDirection(!event.ShiftDown());
+ eventNav.SetWindowChange(FALSE);
+ eventNav.SetEventObject(this);
+
+ if ( GetEventHandler()->ProcessEvent(eventNav) )
+ return;
+ }
+ break;
+*/
+ default:
+ event.Skip();
+ return;
+ }
-wxTextCtrl& wxTextCtrl::operator<<(float f)
-{
- wxString str;
- str.Printf("%.2f", f);
- AppendText(str);
- return *this;
+ // don't just call event.Skip() because this will cause TABs and ENTERs
+ // be passed upwards and we don't always want this - instead process it
+ // right here
+
+ // FIXME
+ event.Skip();
}
-wxTextCtrl& wxTextCtrl::operator<<(double d)
+bool wxTextCtrl::OS2Command(WXUINT param, WXWORD WXUNUSED(id))
{
- wxString str;
- str.Printf("%.2f", d);
- AppendText(str);
- return *this;
+ switch (param)
+ {
+// TODO:
+/*
+ case EN_SETFOCUS:
+ case EN_KILLFOCUS:
+ {
+ wxFocusEvent event(param == EN_KILLFOCUS ? wxEVT_KILL_FOCUS
+ : wxEVT_SET_FOCUS,
+ m_windowId);
+ event.SetEventObject( this );
+ GetEventHandler()->ProcessEvent(event);
+ }
+ break;
+
+ case EN_CHANGE:
+ {
+ wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
+ wxString val(GetValue());
+ if ( !val.IsNull() )
+ event.m_commandString = WXSTRINGCAST val;
+ event.SetEventObject( this );
+ ProcessCommand(event);
+ }
+ break;
+
+ case EN_ERRSPACE:
+ // the text size limit has been hit - increase it
+ AdjustSpaceLimit();
+ break;
+
+ // the other notification messages are not processed
+ case EN_UPDATE:
+ case EN_MAXTEXT:
+ case EN_HSCROLL:
+ case EN_VSCROLL:
+*/
+ default:
+ return FALSE;
+ }
+
+ // processed
+ return TRUE;
}
-wxTextCtrl& wxTextCtrl::operator<<(int i)
+void wxTextCtrl::AdjustSpaceLimit()
{
- wxString str;
- str.Printf("%d", i);
- AppendText(str);
- return *this;
+// TODO:
+/*
+ unsigned int len = ::GetWindowTextLength(GetHwnd()),
+ limit = ::SendMessage(GetHwnd(), EM_GETLIMITTEXT, 0, 0);
+ if ( len > limit )
+ {
+ limit = len + 0x8000; // 32Kb
+
+ if ( limit > 0xffff )
+ ::SendMessage(GetHwnd(), EM_LIMITTEXT, 0, limit);
+ else
+ ::SendMessage(GetHwnd(), EM_LIMITTEXT, limit, 0);
+ }
+*/
}
-wxTextCtrl& wxTextCtrl::operator<<(long i)
+bool wxTextCtrl::AcceptsFocus() const
{
- wxString str;
- str.Printf("%ld", i);
- AppendText(str);
- return *this;
+ // we don't want focus if we can't be edited
+ return IsEditable() && wxControl::AcceptsFocus();
}
-wxTextCtrl& wxTextCtrl::operator<<(const char c)
+wxSize wxTextCtrl::DoGetBestSize() const
{
- char buf[2];
+ int cx, cy;
+ wxGetCharSize(GetHWND(), &cx, &cy, (wxFont*)&GetFont());
- buf[0] = c;
- buf[1] = 0;
- AppendText(buf);
- return *this;
+ int wText = DEFAULT_ITEM_WIDTH;
+
+ int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
+ if ( m_windowStyle & wxTE_MULTILINE )
+ {
+ hText *= wxMin(GetNumberOfLines(), 5);
+ }
+ //else: for single line control everything is ok
+
+ return wxSize(wText, hText);
}
+// ----------------------------------------------------------------------------
+// standard handlers for standard edit menu events
+// ----------------------------------------------------------------------------
+
void wxTextCtrl::OnCut(wxCommandEvent& event)
{
Cut();
{
event.Enable( CanRedo() );
}
+