1. RichEdit Attributes Bold, Italic, Underline

Hello everyone,

I'm new to Euphoria have been working with it for about a month and a half.
I've gone through the documentation and examples and explored the user 
contributed code from the Euphoria website. I'm trying to learn to use the 
RichEdit Control. Here is my question:

Instead of using the font dialog to change attributes like bold, italic,
underline
I want to use a seperate button for each and toggle these attributes on/off for
either selected text or from the insertion point while editing text.

Nothing I try seems to work. Is there a way of doing this, Or am I better off 
just using the font dialog instead?

Any help would be much appriciated.

Alan

new topic     » topic index » view message » categorize

2. Re: RichEdit Attributes Bold, Italic, Underline

Alan Hollingsworth wrote:
> Instead of using the font dialog to change attributes like bold, italic,
> underline
> I want to use a seperate button for each and toggle these attributes on/off
> for
> either selected text or from the insertion point while editing text.
>
> Nothing I try seems to work. Is there a way of doing this, Or am I better off 
> just using the font dialog instead?

My understanding is that you would have to (with code in your button) do 
the following.

Get the selected text with
buffer = getStream(RichTextField, StreamRTF).
Modify it to change various attributes (see below).
Put the text back in the control with putstream(RichTextField, 
StreamRTF, buffer).

To change the attributes of the text, you would have to learn up on RTF.

As an example, the following will display the word 'Euphoria' in plain 
text then in bold text on a new line:

=====================================
{\rtf1\ansi\deff0
{\fonttbl{\f0 Times New Roman;}
}
\f0 Euphoria\par
\b \f0 Euphoria
}
=====================================
The only change is the '\b' to make it bold, but it's the placement that 
is the key.

To test it, copy the file to a text editor; save it with a filetype of 
.rtf; double-click, and it should open in Word.

-- 
Craig

new topic     » goto parent     » topic index » view message » categorize

3. Re: RichEdit Attributes Bold, Italic, Underline

Craig Welch wrote:
> 
> Alan Hollingsworth wrote:
> > Instead of using the font dialog to change attributes like bold, italic,
> > underline
> > I want to use a seperate button for each and toggle these attributes on/off
> > for
> > either selected text or from the insertion point while editing text.
> >
> > Nothing I try seems to work. Is there a way of doing this, Or am I better
> > off
> > just using the font dialog instead?
> 
> My understanding is that you would have to (with code in your button) do 
> the following.
> 
> Get the selected text with
> buffer = getStream(RichTextField, StreamRTF).
> Modify it to change various attributes (see below).
> Put the text back in the control with putstream(RichTextField, 
> StreamRTF, buffer).
> 
> To change the attributes of the text, you would have to learn up on RTF.

I just bought "RTF Pocket Guide" with the intention of learning more about RTF.

> 
> As an example, the following will display the word 'Euphoria' in plain 
> text then in bold text on a new line:
> 
> =====================================
> {\rtf1\ansi\deff0
> {\fonttbl{\f0 Times New Roman;}
> }
> \f0 Euphoria\par
> \b \f0 Euphoria
> }
> =====================================
> The only change is the '\b' to make it bold, but it's the placement that 
> is the key.
> 
> To test it, copy the file to a text editor; save it with a filetype of 
> .rtf; double-click, and it should open in Word.
> 
> -- 
> Craig
> 
Thanks for taking the time to give me your ideas on this. I see now that I am at
least on the right track.
There are probably many ways to go about manipulating text within the RichEdit
control. I have much more than just RTF to learn about I'm sure.
Looks like I will also need to learn more about riched20.dll and how to use it
from within Euphoria.
(hopefully I'll get the hang of using this forum along the way...)
This should be interesting and fun too:)

Alan

new topic     » goto parent     » topic index » view message » categorize

4. Re: RichEdit Attributes Bold, Italic, Underline

Alan Hollingsworth wrote:
> 
> Hello everyone,
> 
> I'm new to Euphoria have been working with it for about a month and a half.
> I've gone through the documentation and examples and explored the user 
> contributed code from the Euphoria website. I'm trying to learn to use the 
> RichEdit Control. Here is my question:
> 
> Instead of using the font dialog to change attributes like bold, italic,
> underline
> I want to use a seperate button for each and toggle these attributes on/off
> for
> either selected text or from the insertion point while editing text.
> 
> Nothing I try seems to work. Is there a way of doing this, Or am I better off
> 
> just using the font dialog instead?
> 
> Any help would be much appriciated.
> 
> Alan


Hello Alan,

if you use the win32lib.ew, using the font dialog could not help you anymore, 
since two pieces should still be missing from the routine: Derek said it will 
be updated next. If you download the dEbUg_magic_box from the RDS contrib.
you will find inside the setFont_fix.ew with the needed patches to complete.

Thereafter, to directly change RichEdit text attributes is not so difficult; 
what's always difficult is to start knowing how to..
____________________________________

function inRange( integer bg, integer en, integer item)

    return bg< item and item< en
    
end function
--- ========
function GetTextFont( integer self)
object font
 
    font = struct_CHARFORMAT( 0,0,0,0,0,0,0, "")
    VOID = sendMessage( self, EM_GETCHARFORMAT, 1, font)
    font = fetch_CHARFORMAT( font)
    return {font[9], font[4]/20, font[3], font[6]}
 
end function

--- ======== these are my handlers for a popup menu, 
--- ======== THAT YOU CAN USE FOR BUTTONS

constant LOGeffects = 
    {BoldFnt, ItalicF, BulletA, Underln, LeftAli, CentAli, RigtAli, StrikeT}

 
       
--- I have added in my procedure a routine that checks the existance of any 
--- attribute before setting it, so that it can be switched off if already 
--- present, i.e. like to toggle a Bold button, switching a Bold text on/off 
--- with the single control command. Briefly, my routine works like this:

procedure Popup_RichEdLOG( integer self, integer event, sequence prm)
object font
    
    LOGchanged = find( self, LOGeffects)
    if inRange( 5, 7, LOGchanged) then
     font = {0, 2, 6}                          
--   TA_LEFT = 0, TA_RIGHT = 2, TA_CENTER = 6,
     setAlignment( LOGlist, font[LOGchanged])
      
    elsif LOGchanged = 3 then      
     setBullet( LOGlist)
        
    else                                       -- 1,2,4,8

     font = GetTextFont( LOGlist)
 
     if and_bits( LOGchanged, font[3]) then    -- if already exist
      LOGchanged = -LOGchanged                 -- will be deactivated
     end if
     setFont( LOGlist, {font[1], font[4]}, font[2], LOGchanged +font[3])
 
    end if
 
end procedure
--- =========

 

Hope this can help.

Antonio A.


 } when you understand Euphoria, it's like to fly! }

new topic     » goto parent     » topic index » view message » categorize

5. Re: RichEdit Attributes Bold, Italic, Underline

Antonio Alessi wrote:
> 
> Alan Hollingsworth wrote:
> > 
> > Hello everyone,
> > 
> > I'm new to Euphoria have been working with it for about a month and a half.
> > I've gone through the documentation and examples and explored the user 
> > contributed code from the Euphoria website. I'm trying to learn to use the 
> > RichEdit Control. Here is my question:
> > 
> > Instead of using the font dialog to change attributes like bold, italic,
> > underline
> > I want to use a seperate button for each and toggle these attributes on/off
> > for
> > either selected text or from the insertion point while editing text.
> > 
> > Nothing I try seems to work. Is there a way of doing this, Or am I better
> > off
> > 
> > just using the font dialog instead?
> > 
> > Any help would be much appriciated.
> > 
> > Alan
> 
> 
> Hello Alan,
> 
> if you use the win32lib.ew, using the font dialog could not help you anymore,
> 
> since two pieces should still be missing from the routine: Derek said it will
> 
> be updated next. If you download the dEbUg_magic_box from the RDS contrib.
> you will find inside the setFont_fix.ew with the needed patches to complete.
> 
> Thereafter, to directly change RichEdit text attributes is not so difficult;
> 
> what's always difficult is to start knowing how to..
> ____________________________________
> 
> }}}
<eucode>
> function inRange( integer bg, integer en, integer item)
> 
>     return bg< item and item< en
>     
> end function
> --- ========
> function GetTextFont( integer self)
> object font
>  
>     font = struct_CHARFORMAT( 0,0,0,0,0,0,0, "")
>     VOID = sendMessage( self, EM_GETCHARFORMAT, 1, font)
>     font = fetch_CHARFORMAT( font)
>     return {font[9], font[4]/20, font[3], font[6]}
>  
> end function
> 
> --- ======== these are my handlers for a popup menu, 
> --- ======== THAT YOU CAN USE FOR BUTTONS
> 
> constant LOGeffects = 
>     {BoldFnt, ItalicF, BulletA, Underln, LeftAli, CentAli, RigtAli, StrikeT}
> </eucode>
{{{
 
>        
> --- I have added in my procedure a routine that checks the existance of any
> 
> --- attribute before setting it, so that it can be switched off if already 
> --- present, i.e. like to toggle a Bold button, switching a Bold text on/off
> 
> --- with the single control command. Briefly, my routine works like this:
> 
> }}}
<eucode>       
> procedure Popup_RichEdLOG( integer self, integer event, sequence prm)
> object font
>     
>     LOGchanged = find( self, LOGeffects)
>     if inRange( 5, 7, LOGchanged) then
>      font = {0, 2, 6}                          
> --   TA_LEFT = 0, TA_RIGHT = 2, TA_CENTER = 6,
>      setAlignment( LOGlist, font[LOGchanged])
>       
>     elsif LOGchanged = 3 then      
>      setBullet( LOGlist)
>         
>     else                                       -- 1,2,4,8
> 
>      font = GetTextFont( LOGlist)
>  
>      if and_bits( LOGchanged, font[3]) then    -- if already exist
>       LOGchanged = -LOGchanged                 -- will be deactivated
>      end if
>      setFont( LOGlist, {font[1], font[4]}, font[2], LOGchanged +font[3])
>  
>     end if
>  
> end procedure
> --- =========
> </eucode>
{{{
 
> 
> Hope this can help.
> 
> Antonio A.
> 
> 
>  } when you understand Euphoria, it's like to fly! }

Thank you Antonio! This should get me started in the right direction.

Alan

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu