Re: RichEdit Attributes Bold, Italic, Underline
- Posted by Antonio Alessi <a.admin at myway.it> Apr 18, 2006
- 507 views
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! }