?? text.tex
字號:
%%%%%%%%%%%%%%%%%%%%%%%%%%%% wxTextCtrl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{\class{wxTextCtrl}}\label{wxtextctrl}
A text control allows text to be displayed and edited. It may be
single line or multi-line.
\wxheading{Derived from}
streambuf\\
\helpref{wxControl}{wxcontrol}\\
\helpref{wxWindow}{wxwindow}\\
\helpref{wxEvtHandler}{wxevthandler}\\
\helpref{wxObject}{wxobject}
\wxheading{Include files}
<wx/textctrl.h>
\wxheading{Window styles}
\twocolwidtha{5cm}
\begin{twocollist}\itemsep=0pt
\twocolitem{\windowstyle{wxTE\_PROCESS\_ENTER}}{The control will generate
the event wxEVT\_COMMAND\_TEXT\_ENTER (otherwise pressing Enter key
is either processed internally by the control or used for navigation between
dialog controls).}
\twocolitem{\windowstyle{wxTE\_PROCESS\_TAB}}{The control will receive
wxEVT\_CHAR events for TAB pressed - normally, TAB is used for passing to the
next control in a dialog instead. For the control created with this style,
you can still use Ctrl-Enter to pass to the next control from the keyboard.}
\twocolitem{\windowstyle{wxTE\_MULTILINE}}{The text control allows multiple lines.}
\twocolitem{\windowstyle{wxTE\_PASSWORD}}{The text will be echoed as asterisks.}
\twocolitem{\windowstyle{wxTE\_READONLY}}{The text will not be user-editable.}
\twocolitem{\windowstyle{wxTE\_RICH}}{Use rich text control under Win32, this
allows to have more than 64KB of text in the control even under Win9x. This
style is ignored under other platforms.}
\twocolitem{\windowstyle{wxTE\_RICH2}}{Use rich text control version 2.0 or 3.0
under Win32, this style is ignored under other platforms}
\twocolitem{\windowstyle{wxTE\_AUTO\_URL}}{Highlight the URLs and generate the
wxTextUrlEvents when mouse events occur over them. This style is only supported
for wxTE\_RICH Win32 and multi-line wxGTK2 text controls.}
\twocolitem{\windowstyle{wxTE\_NOHIDESEL}}{By default, the Windows text control
doesn't show the selection when it doesn't have focus - use this style to force
it to always show it. It doesn't do anything under other platforms.}
\twocolitem{\windowstyle{wxHSCROLL}}{A horizontal scrollbar will be created and
used, so that text won't be wrapped. No effect under wxGTK1.}
\twocolitem{\windowstyle{wxTE\_LEFT}}{The text in the control will be left-justified (default).}
\twocolitem{\windowstyle{wxTE\_CENTRE}}{The text in the control will be centered (currently wxMSW and wxGTK2 only).}
\twocolitem{\windowstyle{wxTE\_RIGHT}}{The text in the control will be right-justified (currently wxMSW and wxGTK2 only).}
\twocolitem{\windowstyle{wxTE\_DONTWRAP}}{Same as {\tt wxHSCROLL} style: don't wrap at all, show horizontal scrollbar instead.}
\twocolitem{\windowstyle{wxTE\_CHARWRAP}}{Wrap the lines too long to be shown entirely at any position (wxUniv and wxGTK2 only).}
\twocolitem{\windowstyle{wxTE\_WORDWRAP}}{Wrap the lines too long to be shown entirely at word boundaries (wxUniv and wxGTK2 only).}
\twocolitem{\windowstyle{wxTE\_BESTWRAP}}{Wrap the lines at word boundaries or at any other character if there are words longer than the window width (this is the default).}
\twocolitem{\windowstyle{wxTE\_CAPITALIZE}}{On PocketPC and Smartphone, causes the first letter to be capitalized.}
\end{twocollist}
See also \helpref{window styles overview}{windowstyles} and \helpref{wxTextCtrl::wxTextCtrl}{wxtextctrlctor}.
\wxheading{wxTextCtrl text format}
The multiline text controls always store the text as a sequence of lines
separated by {\tt $\backslash$n} characters, i.e. in the Unix text format even
on non-Unix platforms. This allows the user code to ignore the differences
between the platforms but at a price: the indices in the control such as those
returned by \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} or
\helpref{GetSelection}{wxtextctrlgetselection} can {\bf not} be used as
indices into the string returned by \helpref{GetValue}{wxtextctrlgetvalue} as
they're going to be slightly off for platforms using
{\tt $\backslash$r$\backslash$n} as separator (as Windows does), for example.
Instead, if you need to obtain a substring between the $2$ indices obtained
from the control with the help of the functions mentioned above, you should
use \helpref{GetRange}{wxtextctrlgetrange}. And the indices themselves can
only be passed to other methods, for example
\helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint} or
\helpref{SetSelection}{wxtextctrlsetselection}.
To summarize: never use the indices returned by (multiline) wxTextCtrl as
indices into the string it contains, but only as arguments to be passed back
to the other wxTextCtrl methods.
\wxheading{wxTextCtrl styles}
Multi-line text controls support the styles, i.e. provide a possibility to set
colours and font for individual characters in it (note that under Windows {\tt
wxTE\_RICH} style is required for style support). To use the styles you can
either call \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle} before
inserting the text or call \helpref{SetStyle}{wxtextctrlsetstyle} later to
change the style of the text already in the control (the first solution is
much more efficient).
In either case, if the style doesn't specify some of the attributes (for
example you only want to set the text colour but without changing the font nor
the text background), the values of the default style will be used for them.
If there is no default style, the attributes of the text control itself are
used.
So the following code correctly describes what it does: the second call
to \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle} doesn't change the
text foreground colour (which stays red) while the last one doesn't change the
background colour (which stays grey):
{\small%
\begin{verbatim}
text->SetDefaultStyle(wxTextAttr(*wxRED));
text->AppendText("Red text\n");
text->SetDefaultStyle(wxTextAttr(wxNullColour, *wxLIGHT_GREY));
text->AppendText("Red on grey text\n");
text->SetDefaultStyle(wxTextAttr(*wxBLUE);
text->AppendText("Blue on grey text\n");
\end{verbatim}
}%
\wxheading{wxTextCtrl and C++ streams}
This class multiply-inherits from {\bf streambuf} where compilers allow,
allowing code such as the following:
{\small%
\begin{verbatim}
wxTextCtrl *control = new wxTextCtrl(...);
ostream stream(control)
stream << 123.456 << " some text\n";
stream.flush();
\end{verbatim}
}%
If your compiler does not support derivation from {\bf streambuf} and gives a
compile error, define the symbol {\bf NO\_TEXT\_WINDOW\_STREAM} in the
wxTextCtrl header file.
Note that independently of this setting you can always use wxTextCtrl itself
in a stream-like manner:
{\small%
\begin{verbatim}
wxTextCtrl *control = new wxTextCtrl(...);
*control << 123.456 << " some text\n";
\end{verbatim}
}%
always works. However the possibility to create an ostream associated with
wxTextCtrl may be useful if you need to redirect the output of a function
taking an ostream as parameter to a text control.
Another commonly requested need is to redirect {\bf std::cout} to the text
control. This could be done in the following way:
{\small%
\begin{verbatim}
#include <iostream>
wxTextCtrl *control = new wxTextCtrl(...);
std::streambuf *sbOld = std::cout.rdbuf();
std::cout.rdbuf(*control);
// use cout as usual, the output appears in the text control
...
std::cout.rdbuf(sbOld);
\end{verbatim}
}%
But wxWidgets provides a convenient class to make it even simpler so instead
you may just do
{\small%
\begin{verbatim}
#include <iostream>
wxTextCtrl *control = new wxTextCtrl(...);
wxStreamToTextRedirector redirect(control);
// all output to cout goes into the text control until the exit from current
// scope
\end{verbatim}
}%
See \helpref{wxStreamToTextRedirector}{wxstreamtotextredirector} for more
details.
\wxheading{Constants}
The values below are the possible return codes of the
\helpref{HitTest}{wxtextctrlhittest} method:
{\small
\begin{verbatim}
// the point asked is ...
enum wxTextCtrlHitTestResult
{
wxTE_HT_UNKNOWN = -2, // this means HitTest() is simply not implemented
wxTE_HT_BEFORE, // either to the left or upper
wxTE_HT_ON_TEXT, // directly on
wxTE_HT_BELOW, // below [the last line]
wxTE_HT_BEYOND // after [the end of line]
};
// ... the character returned
\end{verbatim}
}
\wxheading{Event handling}
The following commands are processed by default event handlers in wxTextCtrl: wxID\_CUT, wxID\_COPY,
wxID\_PASTE, wxID\_UNDO, wxID\_REDO. The associated UI update events are also processed
automatically, when the control has the focus.
To process input from a text control, use these event handler macros to direct input to member
functions that take a \helpref{wxCommandEvent}{wxcommandevent} argument.
\twocolwidtha{7cm}%
\begin{twocollist}\itemsep=0pt
\twocolitem{{\bf EVT\_TEXT(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_UPDATED event,
generated when the text changes. Notice that this event will always be sent
when the text controls contents changes - whether this is due to user input or
comes from the program itself (for example, if SetValue() is called)}
\twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Respond to a wxEVT\_COMMAND\_TEXT\_ENTER event,
generated when enter is pressed in a text control (which must have
wxTE\_PROCESS\_ENTER style for this event to be generated).}
\twocolitem{{\bf EVT\_TEXT\_URL(id, func)}}{A mouse event occurred over an URL
in the text control (wxMSW and wxGTK2 only)}
\twocolitem{{\bf EVT\_TEXT\_MAXLEN(id, func)}}{User tried to enter more text
into the control than the limit set by
\helpref{SetMaxLength}{wxtextctrlsetmaxlength}.}
\end{twocollist}%
\latexignore{\rtfignore{\wxheading{Members}}}
\membersection{wxTextCtrl::wxTextCtrl}\label{wxtextctrlctor}
\func{}{wxTextCtrl}{\void}
Default constructor.
\func{}{wxTextCtrl}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id},\rtfsp
\param{const wxString\& }{value = ``"}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp
\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = wxTextCtrlNameStr}}
Constructor, creating and showing a text control.
\wxheading{Parameters}
\docparam{parent}{Parent window. Should not be NULL.}
\docparam{id}{Control identifier. A value of -1 denotes a default value.}
\docparam{value}{Default text value.}
\docparam{pos}{Text control position.}
\docparam{size}{Text control size.}
\docparam{style}{Window style. See \helpref{wxTextCtrl}{wxtextctrl}.}
\docparam{validator}{Window validator.}
\docparam{name}{Window name.}
\wxheading{Remarks}
The horizontal scrollbar ({\bf wxHSCROLL} style flag) will only be created
for multi-line text controls.
Without a horizontal scrollbar, text lines that don't fit in the control's
size will be wrapped (but no newline character is inserted). Single line
controls don't have a horizontal scrollbar, the text is automatically scrolled
so that the \helpref{insertion point}{wxtextctrlgetinsertionpoint} is always
visible.
% VZ: this is no longer true
%Under Windows, if the {\bf wxTE\_MULTILINE} style is used, the window is implemented
%as a Windows rich text control with unlimited capacity. Otherwise, normal edit control limits
%apply.
\wxheading{See also}
\helpref{wxTextCtrl::Create}{wxtextctrlcreate}, \helpref{wxValidator}{wxvalidator}
\membersection{wxTextCtrl::\destruct{wxTextCtrl}}\label{wxtextctrldtor}
\func{}{\destruct{wxTextCtrl}}{\void}
Destructor, destroying the text control.
\membersection{wxTextCtrl::AppendText}\label{wxtextctrlappendtext}
\func{void}{AppendText}{\param{const wxString\& }{ text}}
Appends the text to the end of the text control.
\wxheading{Parameters}
\docparam{text}{Text to write to the text control.}
\wxheading{Remarks}
After the text is appended, the insertion point will be at the end of the text control. If this behaviour is not desired,
the programmer should use \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} and \helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint}.
\wxheading{See also}
\helpref{wxTextCtrl::WriteText}{wxtextctrlwritetext}
\membersection{wxTextCtrl::CanCopy}\label{wxtextctrlcancopy}
\func{virtual bool}{CanCopy}{\void}
Returns {\tt true} if the selection can be copied to the clipboard.
\membersection{wxTextCtrl::CanCut}\label{wxtextctrlcancut}
\func{virtual bool}{CanCut}{\void}
Returns {\tt true} if the selection can be cut to the clipboard.
\membersection{wxTextCtrl::CanPaste}\label{wxtextctrlcanpaste}
\func{virtual bool}{CanPaste}{\void}
Returns {\tt true} if the contents of the clipboard can be pasted into the
text control. On some platforms (Motif, GTK) this is an approximation
and returns {\tt true} if the control is editable, {\tt false} otherwise.
\membersection{wxTextCtrl::CanRedo}\label{wxtextctrlcanredo}
\func{virtual bool}{CanRedo}{\void}
Returns {\tt true} if there is a redo facility available and the last operation
can be redone.
\membersection{wxTextCtrl::CanUndo}\label{wxtextctrlcanundo}
\func{virtual bool}{CanUndo}{\void}
Returns {\tt true} if there is an undo facility available and the last operation
can be undone.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -