Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, it is possible, but you need to implement a <code>wxTextCtrl</code> derived control that relies on underlaying platform capabilities for any particular wxWidgets port (wxMSW, wxGTK, etc).</p> <p>So, because you have asked about Linux implementation. Let me explain how to implement it for wxGTK 2.9. Below is the <code>wxTextCtrlExt</code> control definition:</p> <pre><code>#include &lt;wx/textctrl.h&gt; #include &lt;wx/gdicmn.h&gt; //----------------------------------------------------------------------------- // wxTextCtrlExt //----------------------------------------------------------------------------- class wxTextCtrlExt : public wxTextCtrl { public: wxTextCtrlExt() : wxTextCtrl() { } wxTextCtrlExt(wxWindow* parent, wxWindowID id, const wxString&amp; value = wxEmptyString, const wxPoint&amp; pos = wxDefaultPosition, const wxSize&amp; size = wxDefaultSize, long style = wxTE_MULTILINE, const wxValidator&amp; validator = wxDefaultValidator, const wxString&amp; name = wxTextCtrlNameStr) : wxTextCtrl(parent, id, value, pos, size, style, validator, name ) { } wxPoint GetPositionCoords(long pos); }; </code></pre> <p>And the wxGTK implementation:</p> <pre><code>#include "wxTextCtrlExt.h" #include &lt;wx/defs.h&gt; #include &lt;gtk/gtk.h&gt; wxPoint wxTextCtrlExt::GetPositionCoords(long pos) { if ( IsMultiLine() ) { GtkTextView* txtView = GTK_TEXT_VIEW(m_focusWidget); GtkTextBuffer* txtBuffer = gtk_text_view_get_buffer(txtView); GtkTextIter iter; gtk_text_buffer_get_iter_at_offset(txtBuffer, &amp;iter, pos); GdkRectangle location; // output location in buffer coordinates gtk_text_view_get_iter_location(txtView, &amp;iter, &amp;location); return wxPoint(location.x, location.y); } return wxPoint(0,0); } </code></pre> <p>You may also want to convert your buffer coordinates to a widget's ones:</p> <pre><code> // If we need to convert our coordinates to GdkPoint out; gtk_text_view_buffer_to_window_coords(txtView, GTK_TEXT_WINDOW_WIDGET, location.x, location.y, &amp;out.x, &amp;out.y ); return wxPoint(out.x, out.y); </code></pre> <p>As you can see, this particular implementation does not account for a single line text entry, that's why you need to use a <code>wxTE_MULTILINE</code> style when you are creating the <code>wxTextCtrlExt</code> control.</p> <p>Well, below is how to use it. Let's <code>m_Text2</code> be the pointer to a child object of <code>wxTextCtrlExt</code> class:</p> <pre><code>long iCharPos = m_Text2-&gt;GetInsertionPoint(); long iCharPosMax = m_Text2-&gt;GetLastPosition(); wxPoint pos = m_Text2-&gt;GetPositionCoords(iCharPos); </code></pre> <p>Now we got our character position coordinates in <code>pos</code>. That's it!</p> <p>Some links that maybe of any interest to you:</p> <ul> <li><a href="http://developer.gnome.org/gtk/stable/GtkTextView.html" rel="nofollow">GtkTextView — Widget that displays a GtkTextBuffer</a></li> <li><a href="http://developer.gnome.org/gtk/stable/GtkTextBuffer.html" rel="nofollow">GtkTextBuffer — Stores attributed text for display in a GtkTextView</a></li> </ul> <h3>Now it is all about your second question.</h3> <blockquote> <p>And on these DE, who draws the controls like text edit? Is it managed by X and styled by particular DE?</p> </blockquote> <p>This depends on the wxWidgets port you are using. The wxMSW and wxGTK ports use Win32 and GTK+2 native controls, respectively. The wxUniversal based ports (such as wxX11, wxMGL) draw all the controls by wxWidgets itself. <a href="http://en.wikipedia.org/wiki/X_Window_System" rel="nofollow">X Window System</a> does not mandate the user interface by itself. It provides the basic framework for building GUI environments: drawing and moving windows on the screen and interacting with a mouse and keyboard.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload