Tab Key on RichText

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

Tab Key on RichText

Post by reinaldocrespo »

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
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Reinaldo,

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

Antonio Linares
www.fivetechsoft.com
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Post by reinaldocrespo »

Yes. Inside a "SysTabControl32" that is inside a Dialog.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Reinaldo,

Please try this:

oRichEdit:nDlgCode = DLGC_WANTALLKEYS
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Post by reinaldocrespo »

Nope. Didn't do it. Same behavior.

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

Post by reinaldocrespo »

Si se te ocurre alguna otra cosa, plis...
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Reinaldo,

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

Antonio Linares
www.fivetechsoft.com
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Tab Key on RichText

Post by reinaldocrespo »

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

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
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Tab Key on RichText

Post by anserkk »

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

Re: Tab Key on RichText

Post by reinaldocrespo »

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

//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: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Tab Key on RichText

Post by reinaldocrespo »

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

...
    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
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Tab Key on RichText

Post by James Bott »

Reinaldo,

Maybe this will help:

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

Have you tried using bKeyDown?

James
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Tab Key on RichText

Post by reinaldocrespo »

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

*-------------------------------------------------------------------------------------------------------------------------------
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
mmercado
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Re: Tab Key on RichText

Post by mmercado »

Hi Reinaldo:

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

Method KeyChar:

Code: Select all

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

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

Re: Tab Key on RichText

Post by reinaldocrespo »

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.
Post Reply