Display file content in Edwin
| Sun, 2006-05-14 14:56 | |
|
Hello every body
These days I was programming an app to display the file content in Edwin, I met a problem that the content displayed in ONE line.(The Edwin ignores the carriage return) I have searched the a lot of posts, but can't find a complete explanation to solve this problem. I think there are many newbie like me may meet this problem, so I hope somebody who knows the solving method to tell us and give an example. Thanks zillions for your reply! |
|






Forum posts: 1156
René Brunner
Forum posts: 28
  I create this app based on the example PlainTextEditor This is my code which adds to the PlainTextEditor:
first,I use WriteFile() to generate the file I want to display in the Edwin
{
//for test
_LIT(KMyFile,"C:\\test.txt");
RFs ifs;
RFile iFile;
User::LeaveIfError(ifs.Connect());
TInt err = iFile.Open(ifs,KMyFile,EFileShareAny|EFileWrite);
if (err==KErrNotFound) // file does not exist - create it
         {
     iFile.Create(ifs,KMyFile,EFileShareAny|EFileWrite|EFileRead);
         }
TBufC8<256> buf = _L8("C:\\C1.txt\r\nC:\\C2.txt\r\nC:\\3.txt\r\nC:\\C4.txt\r\nC:\\C5.txt\r\nC:\\C6.txt\r\nC:\\C7.txt\r\nC:\\C8.txt\r\nC:\\C9.txt\r\nC:\\C10.txt");
iFile.Write(buf);
iEikonEnv->InfoMsg(_L("Writing Success!"));
// Close the connection
iFile.Close();
ifs.Close();
}
Then, I modify the code in the ConstructL()
{
CreateWindowL();
iEditor = new (ELeave) CEikEdwin;
iEditor->SetContainerWindowL(*this);
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC(reader, R_PLAINTEXTEDITOR_URLEDITOR);
iEditor->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // reader
iEditor->SetFocus(ETrue);
SetRect(aRect);
const CPlainText::TTextOrganisation aTextOrganisation = CPlainText::EOrganiseByLine;//EOrganiseByParagraph
TFileName filename(KFilePath);
iEditor->InsertFromTextFileL(filename,aTextOrganisation);
ActivateL();
}
  I think many newbies as me can be stuck by the problem. Thanks for the help of experts.
Forum posts: 1156
a) use EOrganiseByParagraph instead of EOrganiseByLine because from the SDK documentation I got the impression that you need this one here because you generate your line ends as CR/LF
b) write a UNICODE text file instead of an ASCII file and see what happens
and then, finally, if it still does not work,
c) create a scroll bar frame for the edwin, with CreateScrollBarFrameL(); maybe it only starts to use lines when it has the "freedom" to scroll if necessary...
René Brunner
Forum posts: 105
try this code snippet ..
const TFileName file(KHelpFilePath);
iEdwin->InsertFromTextFileL(file,CPlainText::EOrganiseByParagraph );
where iEdwin is object of CEikRichTextEditor class...
Cheers !!
CodePupil
Thanks and Regards
CodePupil
__________________________
You are I and I am he .. !!
Forum posts: 1156
Is the task at hand to show the user a list of file names? If yes, maybe use a listbox, the right user interface element in Symbian for this job?
If the task at hand is to allow the user to manage a list of files, maybe use a combination of a listbox to show the current list, a simple one-line EdWin for entering new names, and two functions "Add Name" and "Delete Name"?
This way we may still not know how to display text with line breaks in an EdWin, but this would not matter because other controls are used.
René Brunner
Forum posts: 28
  I have tried to modify my app according your direction, but the problem is still here.
First, I changed EOrganiseByLine to EOrganiseByParagraph. The contents displayed overlapped, i.e. there are only C:\C1.txt in the screen, and if I click the right arrow, the next content C:\C2.txt appeared when I move the cursor in the end of "C:\C1.txt", and so on.
Second, my app is not related to listbox. It likes a E-book Reader to read the .txt files. So I can't use other UI component to evade this problem.
Forum posts: 28
My problem has been solved according what did desdemona tell.
I am so silly that can not find a mistake in the rss file.
#define KUrlNumberLines 1 <----------------------Here
#define KMaxUrlLength 256
// ---------------------------------------------------------
//
// URL editor for the application
//
// ---------------------------------------------------------
//
RESOURCE EDWIN r_plaintexteditor_urleditor
{
width = KUrlWidth;
lines = KUrlNumberLines;
maxlength = KMaxUrlLength;
flags = EEikEdwinWidthInPixels | EEikEdwinReadOnly;
avkon_flags = EAknEditorFlagNoT9 | EAknEditorFlagEnableScrollBars;
default_case = EAknEditorLowerCase;
allowed_case_modes = EAknEditorUpperCase | EAknEditorLowerCase;
numeric_keymap = EAknEditorPlainNumberModeKeymap;
allowed_input_modes = EAknEditorTextInputMode | EAknEditorNumericInputMode;
default_input_mode = EAknEditorTextInputMode;
special_character_table = R_AVKON_URL_SPECIAL_CHARACTER_TABLE_DIALOG;
}
I am ashamed to trouble you who spent so much time to help me. Hope the post can help many newbies like me.
This is my correct code snippet
{
CreateWindowL();
iEditor = new (ELeave) CEikEdwin;
iEditor->SetContainerWindowL(*this);
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC(reader, R_PLAINTEXTEDITOR_URLEDITOR);
iEditor->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // reader
iEditor->SetFocus(ETrue);
iEditor->CreateScrollBarFrameL();
SetRect(aRect);
const CPlainText::TTextOrganisation aTextOrganisation = CPlainText::EOrganiseByParagraph;//EOrganiseByLine
TFileName filename(KFilePath);
iEditor->InsertFromTextFileL(filename,aTextOrganisation);
ActivateL();
iEditor->SetCursorPosL(0, EFalse);
}
Good luck everyone!