BBC BASIC
« Text Edit »

Welcome Guest. Please Login or Register.
Mar 31st, 2018, 10:46pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Cross-platform BBC BASIC (Windows, Linux x86, Mac OS-X, Android, iOS, Raspberry Pi)
BBC BASIC Resources
BBC BASIC Help Documentation
BBC BASIC for Windows Home Page
BBC BASIC Programmers' Reference
BBC BASIC Beginners' Tutorial
BBC BASIC for SDL 2.0 Home Page
BBC BASIC Discussion Group

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 veryhotthread  Author  Topic: Text Edit  (Read 395 times)
KenDown
New Member
Image


member is offline

Avatar




PM


Posts: 49
xx Re: Text Edit
« Reply #2 on: Feb 28th, 2018, 10:26am »

Thanks. I am already using RichEdit so that I can have UTF-8 characters like Bulgarian.

I have read the Wiki, though I thought it was only for dialog boxes (now you'll tell me that a text window is really just a dialog box!) so I'll have another look at it. Thanks.

However it is the clicking on something that I would really like: I bring up a Bible chapter and would like to click (or double-click) on a verse and have it inserted elsewhere in the program.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Text Edit
« Reply #3 on: Feb 28th, 2018, 11:27am »

on Feb 28th, 2018, 10:26am, KenDown wrote:
However it is the clicking on something that I would really like

You can always use a 'low tech' approach. Poll the mouse using the MOUSE statement and when you see the left button pressed get the current caret position from the Rich Edit control (because clicking will have moved the caret there!).

Trivial, but because it relies on polling there is a risk that a mouse click may be missed if it is done too quickly (and by the same token a double-click will be detected even less reliably). But because it's so simple probably worth a try.

Richard.
User IP Logged

KenDown
New Member
Image


member is offline

Avatar




PM


Posts: 49
xx Re: Text Edit
« Reply #4 on: Feb 28th, 2018, 9:00pm »

Thanks. I'll try it - but I'd need to read what is at the caret. Can that be done without reading the whole text edit box?
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Text Edit
« Reply #5 on: Feb 28th, 2018, 9:36pm »

on Feb 28th, 2018, 9:00pm, KenDown wrote:
Thanks. I'll try it - but I'd need to read what is at the caret. Can that be done without reading the whole text edit box?

I had assumed that the contents of the edit control were there because you had put them there. You referred to "bringing up a Bible chapter" which I assumed was 'set in stone' (if that isn't a mixed metaphor) and therefore knowing where the caret is would allow you easily to work out which paragraph etc. it is in.

If that's not the case, for example because the user is allowed to edit the text, then as you say you'd have to read the text in the vicinity of the caret. That shouldn't be difficult though, for example you could presumably use EM_LINEFROMCHAR and EM_GETLINE to read the line containing the caret.

But I'm not an edit control expert. You'll make much faster progress by scanning the list of EM_* messages yourself. I don't know how adept you are at finding things at MSDN but it's a skill which is absolutely invaluable. Asking here is at best a very poor substitute.

Richard.
User IP Logged

KenDown
New Member
Image


member is offline

Avatar




PM


Posts: 49
xx Re: Text Edit
« Reply #6 on: Mar 1st, 2018, 06:20am »

The difficulty, as I see it, is this: the contents of the text edit window are held in an array line$() with one verse per array entry. So far so simple.

In the window, however, each verse takes up a different number of lines, from a single line for "Jesus wept" to multiple lines for some of St Paul's more prolix statements. Knowing that the cursor is on line 72 of the edit window does not tell me which verse is involved.

That is why I say that I would need to read the contents of the window - preferably the couple of lines above and below the cursor so that I could find the verse number.

Thanks for the tip about EM_ messages, though I don't anticipate much success. No doubt there are folk who can read the stuff on the MSDN site like others read the Sun newspaper, but I am not one of them. I get only the vaguest of ideas of what each parameter means from what is, essentially, gobbledy-gook. If anyone wants to write a best-seller, a translator for MSDN conventions would probably be it!

I will, however, try to make sense of the two calls you mention.

Many thanks for your patience.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Text Edit
« Reply #7 on: Mar 1st, 2018, 09:52am »

on Mar 1st, 2018, 06:20am, KenDown wrote:
Knowing that the cursor is on line 72 of the edit window does not tell me which verse is involved.

I suggested that you poll the mouse to see when the left button is pressed, and then read back the caret position. What you get back is a character index into the displayed text, i.e. it may say that the caret is at offset 1234 with respect to the start of the text; you can surely then easily find where in your original string array character 1234 is?

Getting the row and column coordinates of the caret requires extra work (for example using the EM_LINEFROMCHAR message) and I only suggested that you do that in the context of reading back the line containing the caret. As you say it's not useful when wanting to refer back to the array, so why do it?

Quote:
I get only the vaguest of ideas of what each parameter means from what is, essentially, gobbledy-gook.

The function prototypes at MSDN are described in C syntax, and anybody who can program in BASIC can easily understand simple C syntax because they are so similar. Really the only major difference, from the point of view of understanding MSDN, is that in C parameters have an explicit type (e.g. int myVar) whereas in BBC BASIC they are implicitly typed by means of a suffix character (e.g. myVar%).

Quote:
If anyone wants to write a best-seller, a translator for MSDN conventions would probably be it!

It exists, and has done for years! It's called API Viewer and can be freely downloaded. However (and it's a major issue) the plugin you need for BB4W was written by Jon Ripley and - at his own insistence - was available only from his website. Sadly Jon closed that website some time ago, and he seems to be uncontactable.

That means that anybody who downloaded and installed API Viewer (plus Jon's plugin) when they were available has a fully-automated Windows API to BBC BASIC translator, which is invaluable especially to people like you who find it a struggle. Those that didn't now can't (legally) get hold of it.

Richard.
« Last Edit: Mar 1st, 2018, 09:58am by Richard Russell » User IP Logged

KenDown
New Member
Image


member is offline

Avatar




PM


Posts: 49
xx Re: Text Edit
« Reply #8 on: Mar 1st, 2018, 2:48pm »

Hmmm. I imagine that I can find out which element of the array contains character 1234 by repeatedly subtracting line lengths until ...

However looking through the Wiki I discovered that you have a routine for putting clickable links into a dialog box or the main output window. Can that be adapted to work with a rich text edit window? That would solve all the problems at once!
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Text Edit
« Reply #9 on: Mar 1st, 2018, 3:59pm »

on Mar 1st, 2018, 2:48pm, KenDown wrote:
Hmmm. I imagine that I can find out which element of the array contains character 1234 by repeatedly subtracting line lengths until ...

If that's an unacceptable overhead you're using the wrong programming language! Maybe something like Lisp would meet your exacting requirements, but with BBC BASIC that's the sort of thing you have to do all the time.

Quote:
Can that be adapted to work with a rich text edit window? That would solve all the problems at once!

A Google search found this. I would caution, however, that the click notifications are apparently sent as a WM_NOTIFY message so the warning in the documentation for SUBCLASS.BBC that "Some Windows messages, for example WM_NOTIFY, cannot be subclassed using this technique" may apply.

Richard.
User IP Logged

DDRM
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 36
xx Re: Text Edit
« Reply #10 on: Mar 1st, 2018, 8:07pm »

This link:

http://jonripley.com/bb4w/win32api/viewer/

Appears to be active?

Best wishes,

D
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Text Edit
« Reply #11 on: Mar 2nd, 2018, 09:03am »

on Mar 1st, 2018, 8:07pm, DDRM wrote:
This link: Appears to be active?

Amazing. Grab it while you can!

Richard.
User IP Logged

KenDown
New Member
Image


member is offline

Avatar




PM


Posts: 49
xx Re: Text Edit
« Reply #12 on: Mar 2nd, 2018, 4:32pm »

Hooray!

After much head-banging I finally realised why links appeared in your window but not in mine - it was the "Link Window" instead of "RichEdit20"!

So now I have verse numbers appearing as links; so far so great. There are two problems: although by using a flag of &A00044 I have a scroll bar appearing on the right, no amount of clicking or dragging will scroll the window contents.

The second problem is that UTF-8 characters - such as Bulgarian - are not rendered.

I would be grateful for pointers to the solution, assuming that there is a solution!

bibledisp%=FN_createwindow(!bibledlg%,"Link Window","",4,4,230,558,99,&A00044,0)
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Text Edit
« Reply #13 on: Mar 2nd, 2018, 4:51pm »

on Mar 2nd, 2018, 4:32pm, KenDown wrote:
I would be grateful for pointers to the solution, assuming that there is a solution!

It's years since I've used a Link Control (I'm not even sure I've ever used one in a real program) and I've forgotten everything I ever knew about them. If it's not scrolling I fear the most likely explanation is that scrolling is not supported. sad

I'm pretty confident that Unicode text should work however. You would of course need to use WINLIB5U or WINLIB5W (depending on whether it's UTF-8 or UTF-16/UCS-2) rather than the plain WINLIB5(A) library, but otherwise I would be surprised if there is a problem.

I wonder, however, why you've seemingly abandoned the Rich Edit control because that does support scrolling (and colouring, which is something else you wanted I believe) and if you can successfully respond to the WM_NOTIFY messages from a Link Control there's no obvious reason why the same technique would not work for a Rich Edit control too.

I was thinking that you would need to use the SUBCLASS library, which is explicitly documented as not working with WM_NOTIFY messages, but the Link Window seems to work without it. I'd actually forgotten (no surprise there!) that I'd modified BB4W so that ON SYS handles WM_NOTIFY messages if you execute a *SYS 1.

Richard.
« Last Edit: Mar 2nd, 2018, 10:18pm by Richard Russell » User IP Logged

KenDown
New Member
Image


member is offline

Avatar




PM


Posts: 49
xx Re: Text Edit
« Reply #14 on: Mar 8th, 2018, 10:28am »

Weyhey! I've got part of it working - the hymn list, which is one hymn per line. Just in case anyone's interested:

ON SYS click%=FNsys(@msg%,@wparam%,@lparam%):RETURN

and then in the main program loop:

REPEAT
CASETRUE OF
WHEN!outlinedlg%>0:REM When the dialog box is open
IF@wparam%=&1000000THEN
!text%=256:SYS"SendMessage",hymnlist%,&C4,0,text%:
SYS"SendMessage",hymnlist%,&C9,-1TOline%
SYS"SetDlgItemText",!outlinedlg%,caret%,hymn$(line%)
ELSE
PROCoutlineclick(click%)
ENDIF
ENDCASE
UNTILFALSE

There is, of course, much else in the REPEAT...UNTIL loop.

I set caret% by clicking on a button beside the edit box into which the hymn will be written. (For some reason clicking on the edit box itself didn't work reliably.) PROCoutlineclick handles all other clicks in that particular dialog box.

Note that the value line% was coming out wrong until I realised that a couple of hymn titles were so long they were wrapping onto the next line. The solution was to change the final digits of the flag in the edit box creation call to &C4 instead of &44.

So thanks, Richard, for pointing me in the right direction. Now I can start battering my brains on the Bible verses!
User IP Logged

KenDown
New Member
Image


member is offline

Avatar




PM


Posts: 49
xx Re: Text Edit
« Reply #15 on: Mar 8th, 2018, 8:06pm »

We make progress!

However I am stymied by a problem that I have noticed before. In RiscOs, if you had a menu that came up over a window and you clicked on a menu item, that was fine. With windows, however, it is as though you had clicked on the underlying window. It usually returns the correct value for the menu item, but it also acts as though you had clicked on the window at that point.

Is there any way round that, please?
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Text Edit
« Reply #16 on: Mar 8th, 2018, 8:58pm »

on Mar 8th, 2018, 8:06pm, KenDown wrote:
Is there any way round that, please?

Actually, in Windows, mouse clicks aren't seen by an underlying window, except in special cases when the window itself is transparent. However, if you use the MOUSE statement (or INKEY) you aren't testing for a click, you are testing the state of the mouse buttons directly.

So if you want to avoid seeing mouse clicks on a menu, use the ON MOUSE statement rather than the MOUSE statement. This is preferable anyway, because ON MOUSE will respond to a click however short it is, whereas to guarantee it will be seen by MOUSE you have to hold the button down for a minimum time period.

This really goes back to the earlier discussions in this thread, when you wanted to detect a click on a Rich Edit control. Then you were actually taking advantage of the fact that MOUSE sees the state of the buttons directly, so you could see the click even though it was on the Rich Edit window rather than your program's window.

So, to summarise, MOUSE sees the state of the buttons, irrespective of what window the mouse is over. ON MOUSE responds to a click on BBC BASIC's window, but won't see a click on a different window. ON SYS can see clicks on other windows, if they support that functionality (which fortunately we discovered a Rich Edit control does).

Richard.
« Last Edit: Mar 10th, 2018, 10:44pm by Richard Russell » User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls