Tab Key on RichText

Tab Key on RichText

Postby reinaldocrespo » Thu Mar 16, 2006 6: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.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Postby Antonio Linares » Thu Mar 16, 2006 9:30 pm

Reinaldo,

Is the richedit control placed on a dialogbox ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby reinaldocrespo » Thu Mar 16, 2006 9:41 pm

Yes. Inside a "SysTabControl32" that is inside a Dialog.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Postby Antonio Linares » Thu Mar 16, 2006 9:56 pm

Reinaldo,

Please try this:

oRichEdit:nDlgCode = DLGC_WANTALLKEYS
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby reinaldocrespo » Thu Mar 16, 2006 11:15 pm

Nope. Didn't do it. Same behavior.

Reinaldo.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Postby reinaldocrespo » Fri Mar 17, 2006 2:43 pm

Si se te ocurre alguna otra cosa, plis...
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Postby Antonio Linares » Fri Mar 17, 2006 4:48 pm

Reinaldo,

Estamos investigándo, te contestamos cuanto antes.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Tab Key on RichText

Postby reinaldocrespo » 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: Select all  Expand view
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.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Tab Key on RichText

Postby anserkk » Fri May 15, 2009 6: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
User avatar
anserkk
 
Posts: 1329
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Tab Key on RichText

Postby reinaldocrespo » Fri May 15, 2009 9: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: Select all  Expand view
//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.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Tab Key on RichText

Postby reinaldocrespo » Sat May 16, 2009 2: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: Select all  Expand view

...
    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.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Tab Key on RichText

Postby James Bott » Sat May 16, 2009 5:24 pm

Reinaldo,

Maybe this will help:

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

Have you tried using bKeyDown?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Tab Key on RichText

Postby reinaldocrespo » Sat May 16, 2009 5: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: Select all  Expand view
*-------------------------------------------------------------------------------------------------------------------------------
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.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Tab Key on RichText

Postby mmercado » Sat May 16, 2009 6:48 pm

Hi Reinaldo:

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

Method KeyChar:
Code: Select all  Expand view
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: Select all  Expand view
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
User avatar
mmercado
 
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Re: Tab Key on RichText

Postby reinaldocrespo » Mon May 18, 2009 9: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.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 96 guests