[wxPython] wxStyledTextCtrl & autoindent

Hi,

Still playing around with the wxStyledTextCtrl, while peeking at the demo and
stc.h. There are a few things I haven't been able to figure out so far...
maybe someone can help me or point me to the right place?

1. Does the control support an auto-indent mode? (You know, when you press
Enter on a line that has an indentation of X, then the new empty line it
creates automagically gets the same indentation.)
I tried to hack up something myself, but it doesn't quite work yet. (Intercept
Enter; get the indentation of the current line; event.Skip(); insert the
desired number of spaces; move some places forward)

2. What are the methods to translate an (x,y) coordinate (column, row) to
position and vice versa?

Thanks,

Hans Nowak:

1. Does the control support an auto-indent mode? (You know, when you press
Enter on a line that has an indentation of X, then the new empty line it
creates automagically gets the same indentation.)
I tried to hack up something myself, but it doesn't quite work yet.

(Intercept

Enter; get the indentation of the current line; event.Skip(); insert the
desired number of spaces; move some places forward)

   There is no autoindent mode as that requires too much knowledge about the
language. SciTE (Scintilla and SciTE) contains autoindent
code in the SciTEBase::AutomaticIndentation method. There are some useful
Scitnilla methods GetLineIndentation, GetLineIndentPosition and
SetLineIndentation that do fairly sensible things with tabs based upon the
tab size and the tab use setting.

2. What are the methods to translate an (x,y) coordinate (column, row) to
position and vice versa?

   The surprisingly named PositionFromPoint and PointFromPosition.

   Neil

Hans Nowak:

> 1. Does the control support an auto-indent mode? (You know, when you press
> Enter on a line that has an indentation of X, then the new empty line it
> creates automagically gets the same indentation.) I tried to hack up
> something myself, but it doesn't quite work yet.
(Intercept
> Enter; get the indentation of the current line; event.Skip(); insert the
> desired number of spaces; move some places forward)

   There is no autoindent mode as that requires too much knowledge about the
language. SciTE (Scintilla and SciTE) contains autoindent code
in the SciTEBase::AutomaticIndentation method. There are some useful Scitnilla
methods GetLineIndentation, GetLineIndentPosition and SetLineIndentation that
do fairly sensible things with tabs based upon the tab size and the tab use
setting.

I guess I'll try to code it again, with those methods in mind.

> 2. What are the methods to translate an (x,y) coordinate (column, row) to
> position and vice versa?

   The surprisingly named PositionFromPoint and PointFromPosition.

Doh! I must have overlooked those.

Thanks,

···

On 10 Jan 2002, at 20:54, Neil Hodgson wrote:

I thought I overlooked these, but investigation turns out that these do not do
what I want, viz. translate (column, row) to position and vice versa. I don't
know what it returns, maybe mouse positions or pixels, but those certainly
aren't rows and columns -- I get (17, 0) when I type a character on position
0, where I would expect (0,0) or maybe (1,1).

···

On 10 Jan 2002, at 20:54, Neil Hodgson wrote:

> 2. What are the methods to translate an (x,y) coordinate (column, row) to
> position and vice versa?

   The surprisingly named PositionFromPoint and PointFromPosition.

> > 2. What are the methods to translate an (x,y) coordinate (column, row)

to

> > position and vice versa?
>
> The surprisingly named PositionFromPoint and PointFromPosition.

I thought I overlooked these, but investigation turns out that these do

not do

what I want, viz. translate (column, row) to position and vice versa. I

don't

know what it returns, maybe mouse positions or pixels, but those certainly
aren't rows and columns -- I get (17, 0) when I type a character on

position

0, where I would expect (0,0) or maybe (1,1).

You can get to/from the line with LineFromPosition and PositionFromLine, the
column can be calculated something like this:

    line = stc.LineFromPosition(pos)
    column = pos - stc.PositionFromLine(line)

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!