April 20, 2024, 03:33:02 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Richedit and indenting

Started by Bruce Peaslee, December 16, 2015, 11:10:28 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee

I have a RichEdit control that I am using to format output. Each record in my project gets its own section. I would like the first line of each section to have zero indentation, and every subsequent line to be indented. I can get tabbing to work, but some of the lines are long enough to cause that scheme to fail.

I have seen posts on EM_SETPARAFORMAT, but cannot get anything to work.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

LarryMc

Let me see if I'm getting this right.
You're writing some sort of output to a richedit.
You write it in probably some sort of loop calling this output function.

You read the contents of the richedit and save it so you can append  the new section to it
You add a line to separate the sections and then start to add the new section.
You want it to to write the first line left justified.  If the 1st line wraps do you want the wrap to indent or stay left justified?
The 2nd line and all subsequent lines for this call to the function are indented.

Is that about right?

Is there any code you can send me to keep me fro having to start out from scratch?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Bruce Peaslee

The logic is probably over complicated. Agenda items are read into a linked list from a database. The motion and any suggested notes are put into text boxes. When the agenda item is resolved, the motion, notes, and result are loaded into a hidden rich edit for formatting. This is sent back to the dialog to another rich edit so the user can see the result. If OK, it is sent to the linked list. Here is some code:


'â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"
Sub dlgItem_PopulateMinutesText(string MSP, string result)
'-----------------------------------------------------------------------------------------------------------------
' Compiles the text for the minutes rich edit control. The text is sent first to a hidden control for formatting,
' then back to this dialog.
'-----------------------------------------------------------------------------------------------------------------

pointer pItem = dlgItem_GetItemListPointer()
SetType pItem, AgendaItem

ControlCmd(wMain, txtRtfTemp, @RTLOAD, #pItem.Minutes, @RTF)
int length = ControlCmd (wMain, txtRtfTemp, @RTGETTEXTLENGTH)
ControlCmd(wMain, txtRtfTemp, @RTSETSELECTION, length, length)

PrepareMinutes()

ControlCmd(wMain, txtRtfTemp, @RTSETSELFONT, "", 11, 1, 0)
If(GetControlText(dlgItem, txtItemNotes) <> "")
ControlCmd(wMain, txtRtfTemp, @RTREPLACESEL, "Notes:\n" + GetControlText(dlgItem, txtItemNotes)  + "\n\n")
EndIf
ControlCmd(wMain, txtRtfTemp, @RTSETSELFONT, "", 11, 1, @SFITALIC)
ControlCmd(wMain, txtRtfTemp, @RTSETSELCOLOR, MAROON)
ControlCmd(wMain, txtRtfTemp, @RTREPLACESEL, GetControlText(dlgItem, txtItemMotion) + "\n\n")
ControlCmd(wMain, txtRtfTemp, @RTSETSELFONT, "", 11, 1, 0)
ControlCmd(wMain, txtRtfTemp, @RTSETSELCOLOR, BLACK)
ControlCmd(wMain, txtRtfTemp, @RTREPLACESEL, MSP + "\n")

ControlCmd(wMain,   txtRtfTemp,     @RTSAVE, g_ItemMinutes, @RTF)
ControlCmd(dlgItem, txtItemMinutes, @RTSETSELECTION, 0, -1)
ControlCmd(dlgItem, txtItemMinutes, @RTLOAD, g_ItemMinutes, @RTF)

EnableControl(dlgItem, txtItemMotion, false)
EnableControl(dlgItem, txtItemNotes,  false)

dlgItem.status = result
dlgItem_StopTimer()

Return
EndSub

'â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"â€"
Sub dlgAgenda_ShowMinutes()
'-----------------------------------------------------------------------------------------------------------------

ControlCmd(wMain, txtRtfTemp, @RTSETSELECTION, 0, -1)
ControlCmd(wMain, txtRtfTemp, @RTDELETESEL)

For pItem = each g_pItemList as AGENDAITEM
If(#pItem.Minutes <> "")
ControlCmd(wMain, txtRtfTemp, @RTREPLACESEL, #pItem.Minutes)
EndIf
Next

DoModal dlgMinutes 'this loads the minutes and provides the print option

Return
EndSub


The attached picture shows the result. I would like to indent everything except the first line (underscored) of each record.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

LarryMc

I'll give it a look Bruce.  I've got some other "irons in the fire" so it  may be a few days.
Maybe someone else can offer up a solution sooner.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Bruce Peaslee

That's fine. I do not expect anyone to undertake a lot of research, just hoping someone already has some examples.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Andy

December 17, 2015, 01:15:02 AM #5 Last Edit: December 17, 2015, 01:16:57 AM by andy1966
Bruce,

I knocked up this program that may help you.

It takes an rtf file and indents every line that does not start with a "[".

Maybe when the hidden rich editor is loaded, you could use this for formatting.

The program stores the formatted details in "rtf2.rtf", maybe then the rich editor the user sees could load this file or whatever you call it ready for passing to the linked list.

Anyway, attached is the little code for reading and formatting an rtf file, together with two rtf files.
One made with the rich text editor example program, and one made in Word (2003).

Run the program and browse to either file to open.
Press any key when done, and then open rtf2.rtf to see the result.

See what you think.

Best wishes,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

December 17, 2015, 05:56:30 AM #6 Last Edit: December 17, 2015, 05:58:48 AM by andy1966
And the attached code goes even further.

Run the program,
Browse to either rtf.rtf OR rtfWord.rtf and load.

You will then see the indented version on screen.

So with this, you could amend it to load the minute's from your database to
control 1, a hidden rich text edit
then it will be saved to a temporary file (which gets deleted)
Finally, with the indented version displayed in control 10, you could add an "OK" button to send it to your linked list.

Best wishes,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Bruce Peaslee

Your approach is different in that you are not using ControlCmd or SendMessage. That is what has been driving me crazy.

Perhaps in the long run creating the rtf strings is the way to go.

Thanks/
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Andy

No problems, it is just an idea for you to think about.

Andy
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

I think I've figured it out using your code and the EM_SETPARAFORMAT message.
It's late here.
I'll try to put some example code together to prove I'm right and show you what you need to do tomorrow.
I think your fixes are going to be pretty easy. We'll see tomorrow.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Bruce
Compile the attached program as an windows app.
It has two buttons labeled T and P.
T generates a report that duplicates your 2 agenda items in the screenshot you posted above(+ an entry I added) only things are indented and wrapped the way I think you wanted.

I put some notes in the source code that I hope will help you out.  If you have any questions holler.

Hope this resolves your issues.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Bruce Peaslee

It works. Thanks a bunch.  :D

I tried this idea before, for a long time, without success.

There are a few wrinkles to work out. When I am done, I will post the exe so folks can see the improvements.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles