FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Tab Key on RichText
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Tab Key on RichText
Posted: Thu Mar 16, 2006 06:22 PM

Hi.

Pressing tab while on a Richtext control is not inserting spaces, but instead it is highlighting the full text. How can I change this behavior?

Thank you,

Reinaldo.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Tab Key on RichText
Posted: Thu Mar 16, 2006 09:30 PM

Reinaldo,

Is the richedit control placed on a dialogbox ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Tab Key on RichText
Posted: Thu Mar 16, 2006 09:41 PM

Yes. Inside a "SysTabControl32" that is inside a Dialog.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Tab Key on RichText
Posted: Thu Mar 16, 2006 09:56 PM

Reinaldo,

Please try this:

oRichEdit:nDlgCode = DLGC_WANTALLKEYS

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Tab Key on RichText
Posted: Thu Mar 16, 2006 11:15 PM

Nope. Didn't do it. Same behavior.

Reinaldo.

Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Tab Key on RichText
Posted: Fri Mar 17, 2006 02:43 PM

Si se te ocurre alguna otra cosa, plis...

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Tab Key on RichText
Posted: Fri Mar 17, 2006 04:48 PM

Reinaldo,

Estamos investigándo, te contestamos cuanto antes.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: Tab Key on RichText
Posted: Fri May 15, 2009 12:47 AM
Hi.

I still need to find a way to insert a tab (to indent the paragraph) on a richtext control.

I found this vb code to do the job. The problem is that I don't know how to translate the constant vbTab.

Code (fw): Select all Collapse
Private Sub ctlRichText1_KeyDown(KeyCode As Integer, _
      ByVal Shift As Integer)
   Dim rtf As RichTextBox
   Set rtf = Me!ctlRichText1.Object
   If KeyCode = 9 Then  ' TAB key was pressed.
      ' Ignore the TAB key, so focus doesn't
      ' leave the control
      KeyCode = 0
      ' Replace selected text with the tab character
      rtf.SelText = vbTab
   End If
End Sub

Does anybody know how?

thank you,



Reinaldo.
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Tab Key on RichText
Posted: Fri May 15, 2009 06:10 AM

Dear Mr.Reinaldo,

After reading the code, I assume that the value of the constant vbTab should be Space(4) or Space(5) ( whatever the length occupies in a line when ever we press the TAB key).

The code is just trying to ignore the TAB character and is replacing TAB with VbTab (VbTab should be character type, filled with blank space)

Regards

Anser

Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: Tab Key on RichText
Posted: Fri May 15, 2009 09:08 PM
I wish it was that simple. RichText works a little different. I think that we are going to need a wrapper function for the SelText property/method? and also the value of vbTab. I whould think that there are more people working with RichText controls in this forum.

Please help!

Here is another sample I found using Delphi that calls SelText.
Code (fw): Select all Collapse
//richEdit1 of type TRichEdit
with richEdit1 do
begin
  //move caret to end
  SelStart := GetTextLen;

  //add one unformatted line
  SelText := 'This is the first line' + #13#10;

  //add some normal font text
  SelText := 'Formatted lines in RichEdit' + #13#10;

  //bigger text
  SelAttributes.Size := 13;

  //add bold + red
  SelAttributes.Style := [fsBold];
  SelAttributes.Color := clRed;
  SelText := 'About';

  //only bold
  SelAttributes.Color := clWindowText;
  SelText := ' Delphi ';

  //add italic + blue
  SelAttributes.Style := [fsItalic];
  SelAttributes.Color := clBlue;
  SelText := 'Programming';

  //new line
  SelText := #13#10;

  //add normal again
  SelAttributes.Size := 8;
  SelAttributes.Color := clGreen;
  SelText := 'think of AddFormattedLine custom procedure...';
end;


Reinaldo.
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: Tab Key on RichText
Posted: Sat May 16, 2009 02:15 PM
In an effort to get someone interested, I post my latest findings on the subject.

I'm working with a few tabs on a Dialog window from resources. Each tab contains a richtext control where the user may transcribe text.

With oRtf:bKeyChar I'm able to trap the tab key. To insert the tab character I'm doing this in bKeyChar code block:

Code (fw): Select all Collapse
...
    RELoadRTF( ortf:hWnd,  chr( 9 ) + Chr( 0 ), SF_TEXT )
    FwKeyboard( ortf, VK_RIGHT )  //otherwise all text is highlighted. don't know why


The problem is that before the tab key gets intercepted by oRtf:bKeyChar for some reason the cursor moves to the beginning of the text on the oRtf control, thus all/any tab key only gets inserted at the start of the text. Any attempt to find cursor position in bKeyChar yields zero (oRtf:GetPos()). It seems like some other control is trapping the tab key before ortf:bKeyChar does.

Any ideas?


Reinaldo.
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Tab Key on RichText
Posted: Sat May 16, 2009 05:24 PM

Reinaldo,

Maybe this will help:

http://support.microsoft.com/kb/170141

Have you tried using bKeyDown?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: Tab Key on RichText
Posted: Sat May 16, 2009 05:38 PM
Hi James;

bKeyDown does not seem to trap VK_TAB. Actually I could not trap any keystrokes at all with method keydown() of class TRichEdit. Here is how I know:
Code (fw): Select all Collapse
*-------------------------------------------------------------------------------------------------------------------------------
METHOD KeyDown( nKey, nFlags ) CLASS RchEdt

    logfile( "trace.log", { "Keydown", nKey } )
    ::PostMsg( FM_CHANGE ) //FM_HIGHLIGHT )
    
Return Nil //Super:KeyDown( nKey, nFlags )


The sample you cite is the one I used to get this far. I posted it in this same thread above. The problem seems to be a fwh problem. VB and Delphi samples assume the cursor has not moved.

The reason I know the cursor is moving just before bKeyDown is called when VK_TAB is pressed, is because I traced ortf:getpos() after each key stroke. For some reason the cursor position is reset to the origin when VK_TAB is pressed. Only after that my bKeyChar gets executed. :-)



Reinaldo.
Posts: 782
Joined: Wed Dec 19, 2007 07:50 AM
Re: Tab Key on RichText
Posted: Sat May 16, 2009 06:48 PM
Hi Reinaldo:

Try next changes in KeyChar and KeyDown methods of TRichEdit class:

Method KeyChar:
Code (fw): Select all Collapse
METHOD KeyChar( nKey, nFlags ) CLASS TRichEdit

   if ::lReadOnly .and. ! GetKeyState( VK_ESCAPE )
      return 0
   endif

   if nKey == VK_TAB // added by mmercado
        Return 0
   endif

   Super:KeyChar( nKey, nFlags )

   ::PostMsg( FM_CHANGE )

   if ::lHighlight
      ::PostMsg( FM_HIGHLIGHT )
   endif

return nil


Method KeyDown:
Code (fw): Select all Collapse
METHOD KeyDown( nKey, nFlags ) CLASS TRichEdit

   if ( nKey == VK_INSERT  .and. GetKeyState( VK_SHIFT ) .or. ;
        nKey == Asc( "V" ) .and. GetKeyState( VK_CONTROL ) )

      if ! ::lReadOnly
         ::Paste()
         ::PostMsg( FM_CHANGE )
      endif

      return 0
   endif

   if ::lReadOnly
      if nKey == VK_BACK .or. nKey == VK_DELETE .or. nKey == VK_RETURN
         return 0
      endif
   endif

   if nKey == VK_TAB // added by mmercado
      ::insertRtf( Chr( 9 ) )      
      ::PostMsg( FM_CHANGE )
      Return 0
   endif

   Super:KeyDown( nKey, nFlags )

   ::PostMsg( FM_CHANGE )

   if ::lHighlight
      if nKey == VK_DELETE .or. nKey == VK_BACK
         ::PostMsg( FM_HIGHLIGHT )
      endif
   endif

return nil


Un abrazo.

Manuel Mercado
manuelmercado at prodigy dot net dot mx
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: Tab Key on RichText
Posted: Mon May 18, 2009 09:43 PM

Manuel --Hola. es grato ver tu respuesta.

I have created a reduced self-contained sample that demonstrates how the tab key is handled in this particular situation by FW. If any of you would like to help, I can send the sample via email. BTW, I'm willing to pay for the solution.

The self-contained-reduced sample is a single .prg + .rc that can be compiled with the compile batch command in fw/samples.

Thank you all.

Reinaldo.