Author |
Topic: Text Edit (Read 402 times) |
|
KenDown
New Member
member is offline


Posts: 49
|
 |
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?
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
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.
|
|
|
|
KenDown
New Member
member is offline


Posts: 49
|
 |
Re: Text Edit
« Reply #17 on: Mar 9th, 2018, 04:16am » |
|
Well, I've got it working - and thanks for all your help. I could not have done it without your patience and guidance.
Mind you, it is a horrible bodge: there are five nested IF...THEN...ENDIFs to test if the correct window is open, the mouse button is 4, the mouse x and the mouse y are in the right place and if nothing else (ie. a menu item) has been clicked on first. I'm sure that RiscOs wasn't nearly so complicated!
Incidentally, you were there at the time: is it true that the WIMP part of RiscOs was written by a games developer?
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: Text Edit
« Reply #18 on: Mar 10th, 2018, 10:47pm » |
|
on Mar 9th, 2018, 04:16am, KenDown wrote:| Incidentally, you were there at the time: is it true that the WIMP part of RiscOs was written by a games developer? |
|
I don't know who that question was directed to. Not to me, I hope, since I know nothing about RISC OS (and I certainly wasn't "there at the time").
Richard.
|
|
Logged
|
|
|
|
KenDown
New Member
member is offline


Posts: 49
|
 |
Re: Text Edit
« Reply #19 on: Mar 11th, 2018, 05:06am » |
|
My apologies. I thought you had been involved in the Archimedes.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: Text Edit
« Reply #20 on: Mar 11th, 2018, 10:31am » |
|
on Mar 11th, 2018, 05:06am, KenDown wrote:| I thought you had been involved in the Archimedes. |
|
No. My involvement with the project ended at the very beginning of Acorn's development of what became the Archimedes. I had some exchanges with Sophie over the enhancements she proposed to BBC BASIC (for example I was responsible for insisting that WHILE...ENDWHILE loops be nestable, which they weren't in her proposal), but I was 'off the case' before RISC OS itself came into being and I've never owned or used an Archimedes, RISC PC or any other Acorn ARM-based device.
You can detect some of this history in 'BBC BASIC for Windows' which has good compatibility with the old 6502 BBC BASIC, implements the new language constructs (like WHILE..ENDWHILE and CASE..ENDCASE) accurately, but has poor compatibility with the Archimedes and RISC OS. For example the MODE and SOUND statements, and the TINT function, work quite differently from those in Sophie's ARM BASIC.
Richard.
|
|
Logged
|
|
|
|
KenDown
New Member
member is offline


Posts: 49
|
 |
Re: Text Edit
« Reply #21 on: Mar 11th, 2018, 4:58pm » |
|
Ah. I've had the original Archimedes and a RiscOS. Especially in RiscOS the WIMP and the facilities it offered a programmer were - in my opinion - far superior to Bill Gates' offering.
Oh well.
Now, getting back on-topic: I've got this thing working just fine: click on a verse and it gets inserted; select some text and just the selected text gets inserted. Yippee!
(I'm using the repeated subtractions method to find the correct array element pointed to by the EM_ call, as discussed earlier.)
Then I opened up the Hungarian Bible and it has all gone to pot. The problem, I suspect, is the LEN statement. Is that fully UTF-8 compatible? Is there some quirk in the text editor which returns the wrong value with UTF-8 text?
Any suggestions would be gratefully received.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: Text Edit
« Reply #22 on: Mar 11th, 2018, 5:41pm » |
|
on Mar 11th, 2018, 4:58pm, KenDown wrote:| is the LEN statement. Is that fully UTF-8 compatible? |
|
It depends what you mean by "compatible". LEN will of course work with UTF-8 strings the same as any other, but (by design) it returns the number of bytes in the string, not the number of characters. Given that LEN is commonly used to return the length of binary data (e.g. a bitmap stored in a string) that's how it should be, but it may not be what you want.
To get the number of characters in a UTF-8 string you could call the MultiByteToWideChar API, or you may find it easier to code it yourself in BASIC (if it's fast enough for your needs).
Richard.
|
|
Logged
|
|
|
|
KenDown
New Member
member is offline


Posts: 49
|
 |
Re: Text Edit
« Reply #23 on: Mar 11th, 2018, 7:10pm » |
|
The question, of course, is which does Windows return from the EM_GETLINE function - bytes or characters? I'm guessing it is characters, as clicking on verse 16 caused verse 10 to be selected!
As you say, I might have to go down the WideChar route (I already have the routine incorporated in the program, so that won't be too difficult).
Thanks.
|
|
Logged
|
|
|
|
KenDown
New Member
member is offline


Posts: 49
|
 |
Re: Text Edit
« Reply #24 on: Mar 12th, 2018, 04:09am » |
|
Hmmmm. Famous last words!
FNulen was not too difficult, but the rest of the routine falls flat. http://bb4w.wikispaces.com/Counting+the+characters+in+a+Unicode+string mentions that WIDTH, TAB(x) and COUNT don't work with UTF-8, but you need to add that MID$() and LEFT$() (and, I presume, RIGHT$()) don't work either.
The trouble is that I don't see an easy alternative to MID$. I presume that extracting half a UTF character is not terribly useful!
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: Text Edit
« Reply #25 on: Mar 12th, 2018, 12:12pm » |
|
on Mar 12th, 2018, 04:09am, KenDown wrote:| you need to add that MID$() and LEFT$() (and, I presume, RIGHT$()) don't work either |
|
Ahem, I don't need to do anything: it's a Wiki, the essence of which is that it's a user-editable resource. If you feel it would benefit from that addition, you add it! 
Quote:| The trouble is that I don't see an easy alternative to MID$. I presume that extracting half a UTF character is not terribly useful! |
|
I'm sure you're right that UTF-8 equivalents of the string slicing functions would occasionally be useful. If you end up writing such routines, please also add them to the Wiki page (or create another if you feel that is more appropriate).
Perhaps an entire UTF-8 library might be of value, if you fancy writing such a thing (although in that case I would urge you to make it OS-agnostic so it can be used with both BB4W and BBCSDL, and on all platforms).
Richard.
|
|
Logged
|
|
|
|
KenDown
New Member
member is offline


Posts: 49
|
 |
Re: Text Edit
« Reply #26 on: Mar 12th, 2018, 3:58pm » |
|
It was more a generic "you" rather than you personally. I don't have the skill to write a UTF version of LEFT$, MID$ or RIGHT$, but in case it is of interest to anyone, here's the code I've come up with.
REM One verse per item in the array bibleln$() SYS"SendMessage",bibledisp%,EM_GETSEL,^stpos%,^endpos% REM Count the number of lines to the start character i%=0 REPEAT pos%+=FNulen(bibleln$(i%)) i%+=1 UNTILpos%+FNulen(bibleln$(i%))>stpos% REM Count the number of characters in those lines len%=0 FORj%=0TOi%-1:len%+=FNulen(bibleln$(j%))+1:NEXT REM stpos% is set to the character before the cursor REM hence the +1 p%=stpos%-len%+1 e%=endpos%-stpos% REM Now sort out what is between the start and end b$="" REPEAT REM If the selection is shorter than the verse IFe%<FNulen(bibleln$(i%))THEN REM Increase the byte count until it matches the REM start character count sp%=0 REPEAT sp%+=1 UNTILFNulen(LEFT$(bibleln$(i%),sp%))>=p% REM Increase the byte count until it matches the REM end character count ep%=0 REPEAT ep%+=1 UNTILFNulen(MID$(bibleln$(i%),sp%,ep%))>=e% b$+=MID$(bibleln$(i%),sp%,ep%) e%-=FNulen(MID$(bibleln$(i%),sp%,ep%)) ELSE REM IF the selection is longer than a single verse REM Increase the byte count until it matches the REM start character count sp%=0 REPEAT sp%+=1 UNTILFNulen(LEFT$(bibleln$(i%),sp%))=p% REM b$=the rest of the verse from the start point b$+=MID$(bibleln$(i%),sp%)+" " REM The verse number is held in four bytes e%-=(FNulen(MID$(bibleln$(i%),sp%)+" ")+4) REM Increment the array pointer to the next verse i%+=1 p%=4:REM To exclude the verse number ENDIF UNTILe%<=0 REM b$ now contains the required text slide$(cursel%,slide%,6)=b$
I imagine you'll now come up with some genius method that will incorporate all the above in three lines of code. :-)
|
|
Logged
|
|
|
|
|