forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Edit Box Selected Characters Identification (%rs, %re)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Wed Mar 04, 2015 4:42 pm    Post subject: Edit Box Selected Characters Identification (%rs, %re) Reply with quote

I have a simple question, which I'm sure has a simple answer, for which I can't find the answer in the documentation. If I have an edit box with a given string, how can I determine which characters in the string are highlighted (using the mouse) at a given time ?
e.g. let's say the string is 'This is a TEST program' , and the user highlights say 's a TEST p' how do I get the information that it's characters 7 through 16 which have been selected ?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Wed Mar 04, 2015 8:21 pm    Post subject: Reply with quote

I do not recall an existing ClearWin+ function that does this but it could be provided. Basically you need a call to SendMessage(hwnd, EM_GETSEL, ...) where hwnd is the handle of the control (from %lc) and the WPARAM and LPARAM arguments in the Microsoft documentation are used to get the positions of the first and last characters of the selection.

This may be enough to get you started. If not then post a reply here.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Wed Mar 04, 2015 9:23 pm    Post subject: Reply with quote

Here is some sample code...

Code:
module mod1
 character(24) str
 integer hwnd,left,right
contains
 integer function cb()
  use mswin
  integer i
  i = SendMessage(hwnd,EM_GETSEL,loc(left),loc(right))
  cb = 1
 end function
end module

winapp
program sel
use mod1
integer i,winio@
str = "This is a test string"
i = winio@("%rs&", str)
i = winio@("%lc&", hwnd)
i = winio@("%nl%cnLeft:%2rd&", left);
i = winio@("  Right:%2rd&", right);
i = winio@("%nl%cn%^bb[Get Selection]", cb)
end program
Back to top
View user's profile Send private message AIM Address
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Thu Mar 05, 2015 5:31 pm    Post subject: Reply with quote

Thanks Paul for the sample code.

Just one small tweak required.

Since the string character position indices 'left' and 'right' given:
i) start at 0 for the first character !
ii) the second value is the position of the character AFTER the last character of the selected string

... then a small mod is required in the cb function to add 1 to the value given by 'leftin the SendMessage call.

e.g.after the SendMessage, put left2=left+1 , then use left2 in the rd call.
(To be rigorous, 'right' ahould also be modified to be 'right+1-1' too, even though it gives the same result Smile )

Apart from that it works fine.

However, 2 small follow up questions:

a) do you know if it's possible, and if so how, to keep the same selected string highlighted AFTER the position is obtained ?
The code you posted as it is reverts to unhighlighted text after the button has been pressed and I'd like it to remain highlighted until the user selects another sub-string.

b) the call to Sendmessage with the EM_GETSEL option is a Windows API command right ? I can't find any documentation about it in the FTN95 manuals, is there any ?
Are all windows API commands/options callable in FTN95 or is there only a limited subset of them which will work - if the latter where can a list of those commands, and their descriptions, be found ?

Thanks, John
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Thu Mar 05, 2015 5:54 pm    Post subject: Reply with quote

a) The sample is just for illustration. Presumably you won't have a "Get selection" button. Can you indicate (preferably with sample code) how you plan to use the selection? I guess that you will need a way to monitor the selection as it changes.

b) SendMessage is a Microsoft API function. Search on Google with "MSDN SendMessage" etc.
Back to top
View user's profile Send private message AIM Address
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Fri Mar 06, 2015 2:35 pm    Post subject: Reply with quote

My application for this is to have a user-defineable 'Title' for a diagram in a %gr graphics area. I'm working on an example code (as simple as possible) and will post when I have it running.
The idea is to allow the user to select for example for some parts of the title string to be BOLD by selecting the text, then clicking on a button (like your 'GET STRING' button, and then for the program to draw the string in an attached %gr drawing surface.

My last question was for user-friendliness in that if say a certain sub-string was highlighted and then BOLD button clicked, then the user wanted to also under-line the same characters then he/she wouldn't have to keep re-highlighting the text. If it could be kept highlighted it would be much more user-friendly.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Fri Mar 06, 2015 2:53 pm    Post subject: Reply with quote

The trick is to reset the focus...


Code:
module mod1
 character(24) str
 integer hwnd,left,right
contains
 integer function cb()
  use mswin
  integer i
  i = SendMessage(hwnd,EM_GETSEL,loc(left),loc(right))
  i = SetFocus(hwnd)
  cb = 1
 end function
end module

winapp
program sel
use mod1
integer i,winio@
str = "This is a test string"
i = winio@("%rs[keep_focus]&", str)
i = winio@("%lc&", hwnd)
i = winio@("%nl%cnLeft:%2rd&", left);
i = winio@("  Right:%2rd&", right);
i = winio@("%nl%cn%^bb[Get Selection]", cb)
end program
Back to top
View user's profile Send private message AIM Address
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Sat Mar 07, 2015 6:27 pm    Post subject: Reply with quote

Q: 'Where can I get a list of those commands'
A: MSDN
Clearwin+ documentation is a mixed bag. There are:
(a) Clearwin functions that are brilliantly described, but you need to look in the FTN95.CHM or some of the equivalent documentation.
(b) Clearwin functions that are badly described, where as well as FTN95.CHM, you might find something in CLRWIN.ENH (in the documentation folder) - occasionally the forum helps, and sometimes they are simply undocumented.
(c) Not available in Clearwin, but available by calling the Windows function.

Option (c) is what most of Clearwin does anyway, but parts of Clearwin don't simply act as a 'wrapper' for the Windows functions, those parts contain a lot of additional functionality, and the documentation rarely gives you a hint which they are.

My approach to something that I find difficult to program is to see how various other respect apps do it. If the authors of CorelDRAW, for instance, find it difficult to do something, then I know (1) it isn't easy, (2) it probably isn't standard in Clearwin, or even (3) perhaps it doesn't conform to the Windows user experience guidelines.

Eddie
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Mon Mar 09, 2015 10:30 am    Post subject: Reply with quote

Thanks eddie for that run down - as I suspected, not a lot within CLEARWIN documentation to make much immediate sense of Windows API commands, nor really an explanatio nfor the layman of what is or is not 'compatible'.
I found the full caboodle of a manual, it is BIG, and the possibilities are probably endless ... if one has enough time.
In the meantime, thanks to Paul's code I can do what I want, but I have a problem writing the string to a %gr graphics window which is not 'inside' the cb function.
I've cut out the code from ny bigger version below.
Can someone please tell me how I get the string to be written to the 'black' window rather than having to use the seperate window which I created as a test ?
(you'll by looking at some commented out lines that I tried a few things, without success. I'm not really understanding the way windows and control handles and focus all work and are called and interactI think ).

Code:
module mod1
 character(50) str
 integer hwnd,left,right
integer left2,right2
integer w_win, h_win
integer hwnd_str,hwnd_plot,hwnd_sep_plot

contains
!______________________________________________________________________________
 integer function cb()
  use mswin
  integer i,ii

  i = SendMessage(hwnd_str,EM_GETSEL,loc(left),loc(right))
  i = SetFocus(hwnd_str)

left2=left+1
right2=right+1-1

hwnd_plot=11
hwnd_sep_plot=12

!**********************************************************************
! SET UP SEPERATE GR WINDOW TEMPORARILY
!
!      INTEGER i

!--- Graphics window
      i=winio@('%ww%ca[WINDOWS FONTS]&')
      i=winio@('%mn[&Exit]&','EXIT')
      i=winio@('%gr[white,rgb_colours]&',w_win,h_win)
      i=winio@('%lw',hwnd_sep_plot)

!      i=winio@('`gr[white,rgb_colours]',w_win,h_win,hwnd_sep_plot)
!i = winio@("%lc", hwnd_sep_plot)
!--- Select Windows font
      CALL select_font@('Arial')
!      CALL CHOOSE_FONT@(RGB@(255,0,0))

      CALL scale_font@(3.0D0)

!***********************************************************************

   i=SELECT_GRAPHICS_OBJECT@(hwnd_plot)
   CALL DRAW_CHARACTERS@(str(left2:right2),50,100,RGB@(255,0,0))

!   i=SELECT_GRAPHICS_OBJECT@(hwnd_sep_plot)
!   CALL DRAW_CHARACTERS@(str(left2:right2),50,100,RGB@(255,0,0))

  cb = 1
 end function
end module
!________________________________________________________________________________________
winapp
program sel
use mod1
integer i,winio@

str = "BOLDly going where no program has gone before"

w_win=600      ! Width of window for character string
h_win=100      ! height of window for character string

i=winio@('%ww%ca[WINDOWS FONTS]&')
i=winio@('%mn[&Exit]&','EXIT')

i = winio@("%nl%cn%^bb[Write Title]&", cb)

i = winio@("%2nl%rs[keep_focus]&", str)
 
i = winio@("%lc&", hwnd_str)

i = winio@("%nl%cnLeft:%2rd&", left2);
i = winio@("  Right:%2rd&", right2);

!i = winio@("%nl%gr[black]&",w_win,h_win)
!i = winio@("%lc", hwnd_plot)

i = winio@("%nl%`gr[black]",w_win,h_win,hwnd_plot)

end program
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Mon Mar 09, 2015 1:44 pm    Post subject: Reply with quote

That's what the handle is for, and CALL SELECT_GRAPHICS_OBJECT@ is all about. The graphics commands might be 'in' the callback as you put it, they relate to whichever graphics object you last selected.

The handle for a graphics object is one that you choose yourself, not one that Windows chooses, so somewhere you have to set up different handles for your different objects. It is not the same as the handle you get back from a %hw or %lc which the Windows handle for the control or window. (You don't need to set the graphics area handle if there's only one graphics area, because whatever lurks in that variable is a valid integer and so will work).

If you set up a printpage, you use the same approach by switching your graphics to its handle, but then you need to revert to the screen afterwards.

Eddie
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Mon Mar 09, 2015 1:55 pm    Post subject: Reply with quote

I realised that Eddie and that's why I put it (SELECT GRAPHICS OBJECT@) in the above code,twice in fact, but the write to 'hwnd_plot' (=11) in the cb function doesn't write anything to the %gr under the string controls in its window. The one to 'hwnd_sep_plot' (=12) appears to do so, but it may just be picking it up as the default as its definition is just above it i.e. it is 'active'
I'm lost as to why nothing I try can get to write to that %gr set up under the string controls.
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Tue Mar 10, 2015 3:49 pm    Post subject: Reply with quote

Just realised that when I said
"The one to 'hwnd_sep_plot' (=12) a ....."
I forgot to say that I've run the code above :-
a) as written
b) with the first SET_GRAPHICS/DRAW_CHARACTERS commented out and the second one activated
c) with BOTH activated
with the same result - no plotting into the 'black' hwnd_plot window.

So, why does it only plot into the same window which is in the cb f where the window is defined ?
(PS - I've also tried removing the 'keeping the focus' part of the code which Paul you suggested earlier but that has no impact.

Has anyone tried to run the code on their machine ? If so , Do you also get no graphics in the intended 'hwnd_plot' window ?
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Tue Mar 10, 2015 7:02 pm    Post subject: Reply with quote

John,

I don't understand all this module stuff, but the handle has to be accessible and not changed, and a geriatric like myself would put it in COMMON and know it was't going to get lost.
In debugging you perhaps have to write it out, and/or write out the return code from SET_GRAPHICS_OBJECT@

Taking a quick look at your code, the %gr handle CANNOT be obtained from%lw which returns the windows-returned handle for the window the graphics object appears in, not the user-supplied handle for the graphics area. Both %gr areas need their own handle if you wish to swap between them. I'll try to write an example.

Eddie
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Tue Mar 10, 2015 8:04 pm    Post subject: Reply with quote

Code:
      WINAPP
      PROGRAM SILVER
      INCLUDE <WINDOWS.INS>
      COMMON Ihand1, Ihand2, ICOL1, ICOL2, iWIN, JCOL
      EXTERNAL CB1, CB2
      ICOL1 = 0; ICOL2 = 0
      IHAND1 = 100
      IHAND2 = 200
      I = WINIO@('%ca[swapper]&')
      I = WINIO@('%`gr[rgb_colours]&', 400, 200, Ihand1)
      I = WINIO@('%ta%^12bt[Screen 1]&', CB1)
      I = WINIO@('%ff%2nl&')
      I = WINIO@('%`gr[rgb_colours]&', 400, 200, Ihand2)
      I = WINIO@('%ta%^12bt[Screen 2]&', CB2)
      I = WINIO@('%lw', iWIN)
      END

      INTEGER FUNCTION CB1()
      INCLUDE <WINDOWS.INS>
      COMMON Ihand1, Ihand2, ICOL1, ICOL2,  iWIN, JCOL
      J = SELECT_GRAPHICS_OBJECT@ (Ihand1)
      IF (ICOL1 .EQ. 0) THEN
          JCOL = RGB@(0,0,0)
          ICOL1 = 1
          ELSE
          JCOL = RGB@(255,255,255)
          ICOL1 = 0
          ENDIF
      CALL DRAW_FILLED_RECTANGLE@(0,0,400,200,JCOL)
      CALL perform_graphics_update@(Ihand1)
!      write(*,*) ICOL1, JCOL
      CB1 = 2
      RETURN
      END

      INTEGER FUNCTION CB2()
      INCLUDE <WINDOWS.INS>
      COMMON Ihand1, Ihand2, ICOL1, ICOL2,  iWIN, JCOL
      J = SELECT_GRAPHICS_OBJECT@ (Ihand2)
      IF (ICOL2 .EQ. 0) THEN
          JCOL = RGB@(0,0,0)
          ICOL2 = 1
          ELSE
          JCOL = RGB@(255,255,255)
          ICOL2 = 0
          ENDIF
      CALL DRAW_FILLED_RECTANGLE@(0,0,400,200,JCOL)
      CALL perform_graphics_update@(Ihand2)
!      write(*,*) ICOL2, JCOL
      CB2 = 2
      RETURN
      END


PERFORM_GRAPHICS_UPDATE@ shouldn't need the handle, but it works with it (!)
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Thu Mar 12, 2015 8:38 pm    Post subject: Reply with quote

First to Eddie, thanks for the input to this problem, I appreciate it.
I like you am an F77 stalwart, but I was tempted to delve into the world of F90 code with its highly 'attractive' prospects of its MODules allowing one-time declarations and usage 'across functions/routines', even though my common sense told ìme not to :O). anyway, coupled with the code Paul posted which does what my original question asked being in that format ahead - I went like a kiddie in the sweet shop. Anyway, I take on board your comment about that possibly being the source of the problem.
I also have some doubts about what is and isn't allowed where cross-calling of graphics windows is concerned. The code I posted was slapped together from a larger code which originally had the intention of writing simply to the window under the string. When that wouldn't work I added the second window definition, which I defined inside the call-back routine (this is why it says 'set up tseperate GR window temporarily' at top of that code) just to try and get it working. and effectively tries to write graphics to both the window which contains the string controls and also toa window defined in the call-back function itself. Not completely stupid because I might want to do this in reality, say have one window defined with a graphic defined in it and have another one 'pop-up' to enter/edit the string which would be a title. Anyway, the details of the final setup are tbd, the first being to solve the problem of why the string isn't printed in BOTH windows. Inspired by your set-up in your code (which effectively writes to seperate windows individually each from its own call-back function - not exactly what I'm trying to do), and taking onboard your other comments , I have modified my code as explained and posted below.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group