⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 text.tex

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 TEX
📖 第 1 页 / 共 3 页
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%% wxTextCtrl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\section{\class{wxTextCtrl}}\label{wxtextctrl}A text control allows text to be displayed and edited. It may besingle 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 generatethe event wxEVT\_COMMAND\_TEXT\_ENTER (otherwise pressing Enter keyis either processed internally by the control or used for navigation betweendialog controls).}\twocolitem{\windowstyle{wxTE\_PROCESS\_TAB}}{The control will receivewxEVT\_CHAR events for TAB pressed - normally, TAB is used for passing to thenext 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, thisallows to have more than 64KB of text in the control even under Win9x. Thisstyle is ignored under other platforms.}\twocolitem{\windowstyle{wxTE\_RICH2}}{Use rich text control version 2.0 or 3.0under Win32, this style is ignored under other platforms}\twocolitem{\windowstyle{wxTE\_AUTO\_URL}}{Highlight the URLs and generate thewxTextUrlEvents when mouse events occur over them. This style is only supportedfor wxTE\_RICH Win32 and multi-line wxGTK2 text controls.}\twocolitem{\windowstyle{wxTE\_NOHIDESEL}}{By default, the Windows text controldoesn't show the selection when it doesn't have focus - use this style to forceit to always show it. It doesn't do anything under other platforms.}\twocolitem{\windowstyle{wxHSCROLL}}{A horizontal scrollbar will be created andused, 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}.Note that alignment styles (\windowstyle{wxTE\_LEFT}, \windowstyle{wxTE\_CENTRE} and \windowstyle{wxTE\_RIGHT}) can be changeddynamically after control creation on wxMSW and wxGTK. \windowstyle{wxTE\_READONLY}, \windowstyle{wxTE\_PASSWORD} and wrapping stylescan be dynamically changed under wxGTK but not wxMSW. The other styles can beonly set during control creation.\wxheading{wxTextCtrl text format}The multiline text controls always store the text as a sequence of linesseparated by {\tt $\backslash$n} characters, i.e. in the Unix text format evenon non-Unix platforms. This allows the user code to ignore the differencesbetween the platforms but at a price: the indices in the control such as thosereturned by \helpref{GetInsertionPoint}{wxtextctrlgetinsertionpoint} or\helpref{GetSelection}{wxtextctrlgetselection} can {\bf not} be used asindices into the string returned by \helpref{GetValue}{wxtextctrlgetvalue} asthey'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 obtainedfrom the control with the help of the functions mentioned above, you shoulduse \helpref{GetRange}{wxtextctrlgetrange}. And the indices themselves canonly be passed to other methods, for example\helpref{SetInsertionPoint}{wxtextctrlsetinsertionpoint} or\helpref{SetSelection}{wxtextctrlsetselection}.To summarize: never use the indices returned by (multiline) wxTextCtrl asindices into the string it contains, but only as arguments to be passed backto the other wxTextCtrl methods.\wxheading{wxTextCtrl styles}Multi-line text controls support the styles, i.e. provide a possibility to setcolours and font for individual characters in it (note that under Windows {\ttwxTE\_RICH} style is required for style support). To use the styles you caneither call \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle} beforeinserting the text or call \helpref{SetStyle}{wxtextctrlsetstyle} later tochange the style of the text already in the control (the first solution ismuch more efficient).In either case, if the style doesn't specify some of the attributes (forexample you only want to set the text colour but without changing the font northe 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 areused.So the following code correctly describes what it does: the second callto \helpref{SetDefaultStyle}{wxtextctrlsetdefaultstyle} doesn't change thetext foreground colour (which stays red) while the last one doesn't change thebackground 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 acompile error, define the symbol {\bf NO\_TEXT\_WINDOW\_STREAM} in thewxTextCtrl header file.Note that independently of this setting you can always use wxTextCtrl itselfin 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 withwxTextCtrl may be useful if you need to redirect the output of a functiontaking an ostream as parameter to a text control.Another commonly requested need is to redirect {\bf std::cout} to the textcontrol. 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 insteadyou 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 moredetails.\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 processedautomatically, when the control has the focus.To process input from a text control, use these event handler macros to direct input to memberfunctions 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 be sentwhen the text controls contents changes - whether this is due to user input orcomes from the program itself (for example, if SetValue() is called); see ChangeValue() fora function which does not send this event.}\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 havewxTE\_PROCESS\_ENTER style for this event to be generated).}\twocolitem{{\bf EVT\_TEXT\_URL(id, func)}}{A mouse event occurred over an URLin the text control (wxMSW and wxGTK2 only)}\twocolitem{{\bf EVT\_TEXT\_MAXLEN(id, func)}}{User tried to enter more textinto 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 createdfor multi-line text controls.Without a horizontal scrollbar, text lines that don't fit in the control'ssize will be wrapped (but no newline character is inserted). Single linecontrols don't have a horizontal scrollbar, the text is automatically scrolledso that the \helpref{insertion point}{wxtextctrlgetinsertionpoint} is alwaysvisible.% 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 thetext control. On some platforms (Motif, GTK) this is an approximationand 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 operationcan 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 operationcan be undone.\membersection{wxTextCtrl::Clear}\label{wxtextctrlclear}\func{virtual void}{Clear}{\void}Clears the text in the control.Note that this function will generate a {\tt wxEVT\_COMMAND\_TEXT\_UPDATED}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -