***KEY EVENTS***

Login to reply to this topic.
Wed, 2005-11-23 11:05
Joined: 2005-11-16
Forum posts: 34
Hi there, guys!  Cheezy

I'm almost finished with a task I'm doing with regards to richtext box. The only problem left is the key handling function.

Can someone tell me if it is possible to move 1 line up the textbox when the UP key is pressed and move 1 line down when the DOWN key is pressed.

Here is the code I used:

Code:
//richtext
TInt edwinFlags = EEikEdwinInclusiveSizeFixed|
                      EEikEdwinNoAutoSelection|
                      //EEikEdwinDisplayOnly|
                      EEikEdwinReadOnly|
                      EEikEdwinLineCursor|
                      EEikEdwinNoHorizScrolling|
                      EEikEdwinAvkonDisableCursor;

iRtEd = new(ELeave) CEikRichTextEditor;
iRtEd->ConstructL(this, 0, 0, edwinFlags, EGulFontControlAll, EGulAllFonts);
    iRtEd->SetAknEditorFlags(edwinFlags);

// scrollbars
iRtEd->CreatePreAllocatedScrollBarFrameL();
    iRtEd->ScrollBarFrame()->SetScrollBarVisibilityL (CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);

// Sets the container window
    iRtEd->SetContainerWindowL(*this);
    iRtEd->SetObserver(this);
    iRtEd->SetExtent(TPoint(10, 106), TSize(156, 80));
    iRtEd->SetFocus(ETrue);


   // Set font type
    TFontSpec fontspec = LatinPlain12()->FontSpecInTwips();
    TCharFormat charFormat( fontspec.iTypeface.iName,fontspec.iHeight );
    TCharFormatMask charFormatMask;

    // Activate the attributes
    charFormatMask.SetAttrib(EAttColor);
    charFormatMask.SetAttrib(EAttFontTypeface);
    charFormatMask.SetAttrib(EAttFontHeight);

    // Apply font to the whole text
    iRtEd->SelectAllL();
    iRtEd->ApplyCharFormatL(charFormat, charFormatMask);
    iRtEd->ClearSelectionL();

// Insert image
iRtEd->RichText()->DeleteL(0, iRtEd->Text()->DocumentLength());
insertPictureL(iRtEd->Text()->DocumentLength(), 0);
iRtEd->RichText()->InsertL(iRtEd->Text()->DocumentLength(), CEditableText::ELineBreak);


// Product profile
iRtEd->RichText()->InsertL(iRtEd->Text()->DocumentLength(),_L("PRODUCT #1\n"));
iRtEd->RichText()->InsertL(iRtEd->Text()->DocumentLength(), CEditableText::ELineBreak);

iRtEd->RichText()->InsertL(iRtEd->Text()->DocumentLength(),_L("$800.00\n"));
iRtEd->RichText()->InsertL(iRtEd->Text()->DocumentLength(), CEditableText::ELineBreak);

//Description.
TInt a;
for (a=0; a < 5; a++) {
iRtEd->RichText()->InsertL(iRtEd->Text()->DocumentLength(),KTestText);
}

// Clear selection then set selection to none.
iRtEd->SetSelectionL(0,0); //
iRtEd->SetCursorPosL(0, EFalse);

// Update position
iRtEd->MoveCursorL(TCursorPosition::EFPageDown, EFalse);
    iRtEd->MoveCursorL(TCursorPosition::EFLineBeg, EFalse);
   
iRtEd->UpdateScrollBarsL();

How do I evaluate the keys being pressed?

Thanks!!!

Thu, 2005-11-24 01:57
Joined: 2005-11-16
Forum posts: 34
Re: ***KEY EVENTS***
Just some supplementary info regarding my question.

What I mean to do is something like how browsers work upon keypress. Some sort of scrolling the view up 1 line when the UP key is pressed and 1 line down when the DOWN key is pressed.

I hope somebody out there already came upon similar code coz I really need help on this one.

Thanks agian, guys!
Thu, 2005-11-24 02:58
Joined: 2005-11-16
Forum posts: 34
Re: ***KEY EVENTS***
OK, I finally figured it out.

In case somebody out here is having the same problem, check the codes below:

Code:
TKeyResponse CRTF_XMLContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
{
switch(aKeyEvent.iCode) {
case EKeyUpArrow:{
iRtEd->MoveDisplayL(TCursorPosition::EFLineUp);
break;
}

case EKeyDownArrow:{
iRtEd->MoveDisplayL(TCursorPosition::EFLineDown);
break;
}

default: {
return iRtEd->OfferKeyEventL(aKeyEvent, aType);
break;
}
}

return EKeyWasNotConsumed;
}   

I hope this code helps... Happy coding to you all...
  • Login to reply to this topic.