*New Ver 4 : AutoResize EditorGadget And More.... [Windows]

Share your advanced PureBasic knowledge/code with the community.
User avatar
Michael Vogel
Addict
Addict
Posts: 2810
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Updated Ver 3 : AutoResize EditorGadget [Windows]

Post by Michael Vogel »

RASHAD wrote:Ver 3.0
This code as per @MV request
It is not the advanced one
I hope you like it
I do :mrgreen:

I've seen, that the resizing does not work, when the window will be invisible, so there's a kind of flicker – no problem for me, because I won't resize the gadget, but typically, I move the cursor to the first line using SendMessage_(GadgetID(1),#EM_SETSEL,0,0)

Here's just one small iteration of the given code, demonstrating how to create nice help dialogs with colors, bold text and more...

Code: Select all

Procedure SetFormat(Gadget,FSize=9,FColor=#Black,FFlags=0)

	; SetFormat(Gadget,FSize,FName.s,FColor,FFlags)
	
	#Alignment_Left=0
	#Alignment_Center=1
	#Alignment_Right=2
	
	Protected FontFormat.CHARFORMAT
	Protected FontMask

	With FontFormat

		\cbSize=SizeOf(CHARFORMAT)

		;If Len(FName.s)
		;	PokeS(@FontFormat\szFaceName,FName.s)
		;	FontMask|#CFM_FACE
		;EndIf
		If FSize
			\yHeight=FSize*20;1440/72
			FontMask|#CFM_SIZE
		EndIf

		#CFM_LINK=$20
		\dwMask=FontMask|#CFM_COLOR|#CFM_ITALIC|#CFM_BOLD|#CFM_STRIKEOUT|#CFM_UNDERLINE|#CFM_LINK

		\crTextColor=FColor
		\dwEffects=FFlags

		SendMessage_(GadgetID(Gadget),#EM_SETCHARFORMAT,#SCF_SELECTION,@FontFormat)

	EndWith

EndProcedure
Procedure AddText(Gadget,Text.s,Eol=#True)

	If Eol
		Text.s+#CR$
	EndIf

	SendMessage_(GadgetID(Gadget),#EM_REPLACESEL,#True,@Text)
	
	If Eol>1
		SetFormat(Gadget,Eol)
		Text=#CR$
		SendMessage_(GadgetID(Gadget),#EM_REPLACESEL,#True,@Text)
	EndIf
	
	SetFormat(Gadget);		Einstellungen rücksetzen

EndProcedure
Procedure AddBoldText(Gadget,Text.s,Eol=#True)

	Protected Dummy.s
	Protected Bold

	Repeat
		
		Bold=FindString(Text,#TAB$,1)
		
		If Bold
			Dummy=Left(Text,Bold)
			Text=Mid(Text,Bold+1)
			
			SetFormat(Gadget,0,0,#CFM_BOLD)
			SendMessage_(GadgetID(Gadget),#EM_REPLACESEL,#True,@Dummy)
			
			SetFormat(Gadget,0,0,0)
		EndIf
		
		Bold=FindString(Text,#CR$,1)
		If Bold
			Dummy=Left(Text,Bold)
			Text=Mid(Text,Bold+1)
			SendMessage_(GadgetID(Gadget),#EM_REPLACESEL,#True,@Dummy)
			
		Else
			Break
		EndIf
		
	ForEver
	
	AddText(Gadget,Text,Eol)
	
EndProcedure
Procedure AddParagraph(Gadget,Size=9)

	SetFormat(Gadget,Size);	Zeilenabstand definieren
	AddText(Gadget,"");		CR$
	SetFormat(Gadget);		Einstellungen rücksetzen

EndProcedure


If OpenWindow(0,0,0,500,500,"EditorGadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

	EditorGadget(1,10,10,480,412,#PB_Editor_ReadOnly|#Alignment_Left)

	#InstanceWindow="Forerunner Training Center"
	#TextHeaderColor=$30A030
	#TextHeaderSize=11

	AddParagraph(1,4)
	SetFormat(1,#TextHeaderSize,#TextHeaderColor,#CFM_BOLD)
	AddText(1,"INFORMATION",4)
	AddText(1,"The "+#InstanceWindow+" is able to read your sport history taken from Garmin"+#CR$+"applications (e.g. Forerunner Training Center) which can be easily adapted using"+#CR$+"the Converter program."+#CR$+#CR$+"To view one of your sport tracks in 3D, choose it from the main dialog and press"+#CR$+"enter. You can rotate the track by using the cursor keys or the mouse and set many"+#CR$+"display options (see shortcuts page). Chosing 'report' from the main dialog generates"+#CR$+"monthly reports which also can exported easily to other programs."+#CR$+#CR$+"The option dialog contains different panels. When changing an option parameter"+#CR$+"followed by an asterisk, the History track is reloaded to take effect. A small circle"+#CR$+"behind a parameter indicates restarting the program is required to take effekt."+#CR$+#CR$+"The "+#InstanceWindow+" has been written by Michael Vogel - hopefully you"+#CR$+"like this program. If you also like puzzles like Sudoku, you can also have a look at")
	SetFormat(1,0,0,#CFM_LINK)
	AddText(1,"http://sites.google.com/site/mrvogel",12)
	SetFormat(1,#TextHeaderSize,#TextHeaderColor,#CFM_BOLD)
	AddText(1,"SPORT PROGRAMS",4)
	AddBoldText(1,"Training Center:"+#TAB$+"software from Garmin to collect and organize sport tracks"+#CR$+#TAB$+#TAB$+"from GPS sport devices"+#CR$+#TAB$+#TAB$+"(reads '.hst' and '.tcx' files, writes '.hst' or '.tcx' files)"+#CR$+#CR$+"Converter:"+#TAB$+"compresses '.hst' and the large '.tcx' history files and"+#CR$+#TAB$+#TAB$+"converts standard '.gpx' files to '.hst' history files"+#CR$+#CR$+#InstanceWindow+":"+#CR$+#TAB$+#TAB$+"displays tracks and make monthly reports (reads '.hst', '.hsz'"+#CR$+#TAB$+#TAB$+"and '.tcz' files, writes '.hst' and '.gpx' files)",12)
	SetFormat(1,#TextHeaderSize,#TextHeaderColor,#CFM_BOLD)
	AddText(1,"HISTORY FILE TYPES",4)
	AddBoldText(1,"  .hst"+#TAB$+"old history file of the Garmin Training Center"+#CR$+"  .hsz"+#TAB$+"compressed history file"+#CR$+"  .tcx"+#TAB$+"new history file of the Garmin Training Center"+#CR$+"  .tcz"+#TAB$+"compressed history file"+#CR$+"  .gpx"+#TAB$+"standard exchange file format")

	SendMessage_(GadgetID(1),#EM_SETSEL,0,0)
	SetActiveGadget(1)
	;AutoresizeEG(1)

	Repeat
	Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: *New Ver 4 : AutoResize EditorGadget [Windows]

Post by RASHAD »

Hi Michael
Nice shoot
New ver 4 (Wait till we come to ver 10) we are ahead of PB
1- Autoresize has been updated (I was aware about that windows must be visible)
2- Added Line or Paragraph alignement (Left - Center - Right)
3- Added disable Caret in some cases

Code: Select all


#CFM_LINK  = $20

Procedure AutoresizeEG(Gadget)
  OldStyle = GetWindowLongPtr_(GadgetID(Gadget),#GWL_STYLE)
  For i = 6 To 500 Step 4
  MoveWindow_(GadgetID(Gadget),0,0,0,i,1)
  SendMessage_(GadgetID(Gadget),#WM_VSCROLL,#SB_TOP,0)
  SendMessage_(GadgetID(Gadget),#WM_VSCROLL,#SB_BOTTOM,0)  
  NewStyle = GetWindowLongPtr_(GadgetID(Gadget),#GWL_STYLE)
  If NewStyle <> OldStyle
     Break
  EndIf
  Next
  MoveWindow_(GadgetID(Gadget),10,10,480,i,1)
EndProcedure

Procedure CharFormat(Gadget,FName$,FSize,FColor,FFlags)
  format.CHARFORMAT
  format\cbSize = SizeOf(CHARFORMAT)
  format\dwMask = #CFM_FACE|#CFM_COLOR|#CFM_SIZE|#CFM_ITALIC|#CFM_BOLD|#CFM_STRIKEOUT|#CFM_UNDERLINE|#CFM_LINK
  PokeS(@format\szFaceName, FName$)
  format\yHeight = FSize*1440/72
  format\crTextColor = FColor
  format\dwEffects = FFlags
  SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)  
EndProcedure

Procedure RangeAlign(Gadget,SLIndex,ELIndex,Align)
  sel.CHARRANGE
  sel\cpMin = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX,SLIndex, 0)
  sel\cpMax = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX,ELIndex, 0)
  SendMessage_(GadgetID(Gadget), #EM_EXSETSEL, 0, @sel)  
  para.PARAFORMAT  
  para\cbSize = SizeOf(PARAFORMAT)
  para\dwMask = #PFM_ALIGNMENT|#PFM_TABSTOPS
  para\wAlignment = Align                                     ;#PFA_CENTER,#PFA_LEFT,#PFA_RIGHT
  SendMessage_(GadgetID(Gadget), #EM_SETPARAFORMAT, 0, @para)
  sel\cpMin = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, 0, 0)
  sel\cpMax = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, 0, 0)
  SendMessage_(GadgetID(Gadget), #EM_EXSETSEL, 0, @sel)  
EndProcedure

Procedure AddText(Gadget,Text$,Eolf)
If Eolf = 1
   Text$ = Text$ + #CRLF$
EndIf
SendMessage_(GadgetID(Gadget), #EM_REPLACESEL, #True, @Text$)
EndProcedure

If OpenWindow(0, 0, 0, 500, 500, "EditorGadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  EditorGadget(1, 0, 0, 0,0,#PB_Editor_ReadOnly)
  ;Remove the remark from next line in case you need to disable Caret But in this case #CFM_LINK will be disabled
  ;SetWindowLongPtr_(GadgetID(1), #GWL_STYLE, GetWindowLongPtr_(GadgetID(1), #GWL_STYLE)|#WS_DISABLED)

    CharFormat(1,"Forte",16,$0102FE,#CFM_UNDERLINE)                        ;CharFormat(#Gadget,Font Name,Font Size,Font Color,Font Flags)
    AddText(1,"This is a Test",0)                                          ;AddText(#Gadget,Text$,End of Line Flag(1 new line - 0 continue at the same line))

    CharFormat(1,"Broadway",24,$78FE87,#CFM_BOLD|#CFM_ITALIC)
    AddText(1," It is OK ",0)    
    
    CharFormat(1,"Forte",16,$FD0202,#CFM_UNDERLINE)
    AddText(1,"For MV",1)

    CharFormat(1,"Times new Roman",16,$FB1404,#CFM_ITALIC|#CFM_STRIKEOUT)
    AddText(1,"This is Italic and Strikeout",1)
    
    CharFormat(1,"Times new Roman",10,$000000,#CFM_LINK)
    AddText(1,"This is a Link",1)
    
    RangeAlign(1,0,1,#PFA_CENTER)
    RangeAlign(1,2,3,#PFA_RIGHT)    
   
    AutoresizeEG(1)
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Have fun
Egypt my love
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: *New Ver 4 : AutoResize EditorGadget [Windows]

Post by kernadec »

Hello, Rashad and Michael Vogel
good job, thank you for sharing
@ Michael Vogel
question?
How to use your code with a HyperLinkGadget
Thank
Good Day
User avatar
Michael Vogel
Addict
Addict
Posts: 2810
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: *New Ver 4 : AutoResize EditorGadget [Windows]

Post by Michael Vogel »

kernadec wrote:Hello, Rashad and Michael Vogel
good job, thank you for sharing
@ Michael Vogel
question?
How to use your code with a HyperLinkGadget
Thank
Good Day
Hi, 'm not sure, if you're just missing the constant #CFM_LINK=$20 (which seems to be predefined in PB4.50 already) or something else does not work as expected :|

PS BTW, in fact Rashad is doing all the job, I just copied and reorded some lines, but maybe there are also other point of views present :lol:
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: *New Ver 4 : AutoResize EditorGadget [Windows]

Post by RASHAD »

@Michael Hi
The man is asking how to run the proper URL by clicking the hypertext
You included your URL in your help file(Give him some example)

@kernadec Hi
Search the forum for 'hyperlink' you will get some answers

Have a good day sirs
Egypt my love
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: *New Ver 4 : AutoResize EditorGadget [Windows]

Post by kernadec »

Hi, RASHAD and Michael Vogel
thanks you,
YES, the code Netmaestro very well. http://www.purebasic.fr/english/viewtop ... rlink+Menu
It is not easy to include HyperLinkGadget and gadgeteditor
Then I wondered if Michael Vogel had found maybe the solution in its code

bye
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: *New Ver 4 : AutoResize EditorGadget [Windows]

Post by RASHAD »

@kernadec Hi
Next ia a very fast snippet I hope it is fine with you
Sorry,it is really a mess (My trial code)
That @MV he left me alone :D

Code: Select all

 
#CFM_LINK            =  $20
#CFM_IMPRINT         =  $1000
#CFM_SUPERSCRIPT     =  $10000
#CFM_SUBSCRIPT       =  $30000
#CFM_BACKCOLOR       =  $4000000

Procedure AutoresizeEG(Gadget)
  OldStyle = GetWindowLongPtr_(GadgetID(Gadget),#GWL_STYLE)
  For i = 6 To 500 Step 4
  MoveWindow_(GadgetID(Gadget),0,0,0,i,1)
  SendMessage_(GadgetID(Gadget),#WM_VSCROLL,#SB_TOP,0)
  SendMessage_(GadgetID(Gadget),#WM_VSCROLL,#SB_BOTTOM,0)  
  NewStyle = GetWindowLongPtr_(GadgetID(Gadget),#GWL_STYLE)
  If NewStyle <> OldStyle
     Break
  EndIf
  Next
  MoveWindow_(GadgetID(Gadget),10,10,480,i,1)
EndProcedure

Procedure CharFormat(Gadget,FName$,FSize,FColor,BColor,FFlags)
  format.CHARFORMAT2
  format\cbSize = SizeOf(CHARFORMAT2)
  format\dwMask = #CFM_FACE|#CFM_COLOR|#CFM_BACKCOLOR|#CFM_SIZE|#CFM_ITALIC|#CFM_BOLD|#CFM_STRIKEOUT|#CFM_UNDERLINE|#CFM_LINK|#CFM_SUBSCRIPT|#CFM_SUPERSCRIPT
  PokeS(@format\szFaceName, FName$)
  format\yHeight = FSize*1440/72
  format\crTextColor = FColor
  format\crBackColor = BColor
  format\dwEffects = FFlags
  SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)  
EndProcedure

Procedure RangeAlign(Gadget,SLIndex,ELIndex,Align)
  sel.CHARRANGE
  sel\cpMin = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX,SLIndex, 0)
  sel\cpMax = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX,ELIndex, 0)
  SendMessage_(GadgetID(Gadget), #EM_EXSETSEL, 0, @sel)  
  para.PARAFORMAT
  para\cbSize = SizeOf(PARAFORMAT)
  para\dwMask = #PFM_ALIGNMENT|#PFM_TABSTOPS|#PFM_RIGHTINDENT|#PFM_RTLPARA
  ;para\dxStartIndent =
  ;para\dxRightIndent =
  ;para\dxOffset =
  ;para\cTabCount =
  ;para\rgxTabs  = 
  para\wAlignment = Align                                     ;#PFA_CENTER,#PFA_LEFT,#PFA_RIGHT
  SendMessage_(GadgetID(Gadget), #EM_SETPARAFORMAT, 0, @para)
  sel\cpMin = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, 0, 0)
  sel\cpMax = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, 0, 0)
  SendMessage_(GadgetID(Gadget), #EM_EXSETSEL, 0, @sel)  
EndProcedure

Procedure AddText(Gadget,Text$,Eolf)
If Eolf = 1
   Text$ = Text$ + #CR$
EndIf
SendMessage_(GadgetID(Gadget), #EM_REPLACESEL, #True, @Text$)
EndProcedure

Procedure WndProc(hWnd, uMsg, wParam, lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select uMsg 
    Case #WM_NOTIFY 
      *el.ENLINK = lParam 
      If *el\nmhdr\code=#EN_LINK 
        If *el\msg=#WM_LBUTTONDOWN 
          LinkBuffer = AllocateMemory(#MAX_PATH) 
          lnk.TEXTRANGE
          lnk\chrg\cpMin = *el\chrg\cpMin 
          lnk\chrg\cpMax = *el\chrg\cpMax 
          lnk\lpstrText  = LinkBuffer
          SendMessage_(GadgetID(1), #EM_GETTEXTRANGE, 0, @lnk) 
          If PeekS(LinkBuffer,24) = "http:\\www.purebasic.com"
            ShellExecute_(0,"open","http:\\www.purebasic.com",0,0,#SW_SHOWNORMAL)
          EndIf 
          FreeMemory(LinkBuffer) 
        EndIf 
      EndIf 
  EndSelect 
  ProcedureReturn result 
EndProcedure 

If OpenWindow(0, 0, 0, 500, 500, "EditorGadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  SetWindowCallback(@WndProc())
  EditorGadget(1, 0, 0, 0,0,#PB_Editor_ReadOnly)
  SendMessage_(GadgetID(1), #EM_SETEVENTMASK, 0, #ENM_LINK|SendMessage_(GadgetID(1), #EM_GETEVENTMASK, 0, 0))
  ;Remove the remark from next line in case you need to disable Caret But in this case #CFM_LINK will be disabled
  ;SetWindowLongPtr_(GadgetID(1), #GWL_STYLE, GetWindowLongPtr_(GadgetID(1), #GWL_STYLE)|#WS_DISABLED)
  ;StringGadget(2,10,470,200,20,"TEST")

    CharFormat(1,"Forte",16,$0102FE,$000000,#CFM_BACKCOLOR)           ;CharFormat(#Gadget,Font Name,Font Size,Font Color,Font Flags)
    AddText(1,"This is a",0)                                          ;AddText(#Gadget,Text$,End of Line Flag(1 new line - 0 continue at the same line))

    CharFormat(1,"Broadway",24,$000000,$02FEFD,#CFM_BOLD)
    AddText(1," Test is OK ",0)    
    
    CharFormat(1,"Forte",16,$FD0202,$000000,#CFM_UNDERLINE|#CFM_BACKCOLOR)    ;To disable BackColor Use #CFM_BACKCOLOR
    AddText(1,"For MV",1)

    ;CharFormat(1,"Times new Roman",16,$05B9FA,$000000,#CFM_BACKCOLOR)
    ;AddText(1,"",1)
    
    CharFormat(1,"Times new Roman",16,$05B9FA,$000000,#CFM_IMPRINT)
    AddText(1," This is EMBOSS",1)
    
    CharFormat(1,"Times new Roman",10,$000000,$000000,#CFM_LINK|#CFM_BACKCOLOR)
    AddText(1,"http:\\www.purebasic.com",1)
    
    RangeAlign(1,0,1,#PFA_CENTER)
    RangeAlign(1,1,2,#PFA_CENTER)    
   
    AutoresizeEG(1)
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Egypt my love
User avatar
kernadec
Enthusiast
Enthusiast
Posts: 146
Joined: Tue Jan 05, 2010 10:35 am

Re: *New Ver 4 : AutoResize EditorGadget [Windows]

Post by kernadec »

very nice, I am very satisfied thanks RASHAD
exactly what I wished
I'll work on this code
thank you for your help and sharing your work
thanks
bye RASHAD
User avatar
Michael Vogel
Addict
Addict
Posts: 2810
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: *New Ver 4 : AutoResize EditorGadget [Windows]

Post by Michael Vogel »

RASHAD wrote:@MV he left me alone :D
I'm observing you, so nothing can happen :lol:
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: *New Ver 4 : AutoResize EditorGadget And More.... [Windo

Post by RASHAD »

Some progress
Added :
1- Full Bullet support
2- Line indention support
3- Line Spacing support
and More

Have Fun

Code: Select all


#CFM_LINK            =  $20
#CFM_IMPRINT         =  $1000
#CFM_SUPERSCRIPT     =  $10000
#CFM_SUBSCRIPT       =  $30000
#CFM_BACKCOLOR       =  $4000000
#PFM_ALL2            =  $0FFFDFF
#CFM_ALL2            =  $E403002F


Global BFormat,BStart,BStyle,LeftInd,RightInd,SpRule,LSp,SpBefore,SpAfter 
LoadFont(1, "Broadway",16)

Procedure AutoresizeEG(Gadget)
  OldStyle = GetWindowLongPtr_(GadgetID(Gadget),#GWL_STYLE)
  For i = 6 To 500 Step 4
  MoveWindow_(GadgetID(Gadget),0,0,0,i,1)
  SendMessage_(GadgetID(Gadget),#WM_VSCROLL,#SB_TOP,0)
  SendMessage_(GadgetID(Gadget),#WM_VSCROLL,#SB_BOTTOM,0)  
  NewStyle = GetWindowLongPtr_(GadgetID(Gadget),#GWL_STYLE)
  If NewStyle <> OldStyle
     Break
  EndIf
  Next
  MoveWindow_(GadgetID(Gadget),10,10,480,i,1)
EndProcedure


Procedure SpFont(text$,x,y,LColor,FColor,Efff)
  If Efff=0
    LColor = $000000
    FColor = $FFFFFF
  EndIf  
  StartDrawing(WindowOutput(0))
  DrawingFont(FontID(1))     
    DrawingMode(#PB_2DDrawing_Transparent)
    For i = 1 To Len(text$)
      FrontColor(LColor)
      tex$ = Mid(Text$,i,1)
      DrawText(x-1,y,tex$)
      If Efff = 1
        DrawText(x+1,y,tex$)
        DrawText(x,y-1,tex$)
        DrawText(x,y+1,tex$)
      EndIf
      FrontColor(FColor) 
      DrawText(x,y,tex$)
      x = x + TextWidth(Tex$) + 2
    Next 
  StopDrawing() 
EndProcedure


Procedure CharFormat(Gadget,FName$,FSize,FColor,BColor,FFlags)
  format.CHARFORMAT2
  format\cbSize = SizeOf(CHARFORMAT2)
  format\dwMask = #CFM_ALL2
  PokeS(@format\szFaceName, FName$)  
  format\yHeight = FSize*1440/72
  ;format\yOffset = 10
  ;format\yHeight = 600
  format\crTextColor = FColor
  format\crBackColor = BColor
  format\dwEffects = FFlags
  SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)  
EndProcedure

Procedure RangeFormat(Gadget,SLIndex,ELIndex,InFlag,BFlag,SpFlag,Align)
  sel.CHARRANGE
  sel\cpMin = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX,SLIndex, 0)
  sel\cpMax = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX,ELIndex, 0)
  SendMessage_(GadgetID(Gadget), #EM_EXSETSEL, 0, @sel)  
  para.PARAFORMAT2
  para\cbSize = SizeOf(PARAFORMAT2)  
  para\dwMask = #PFM_ALL2
  If InFlag = 1
    para\dxStartIndent = LeftInd 
    para\dxRightIndent = RightInd
  EndIf
  If BFlag = 1 
    para\wNumbering = BFormat
    para\wNumberingStart = BStart
    para\wNumberingStyle = BStyle
  EndIf
  If SpFlag = 1
    para\bLineSpacingRule = SpRule
    para\dyLineSpacing = LSp       
    para\dySpaceBefore = SpBefore 
    para\dySpaceAfter =  SpAfter
  EndIf 
  para\wAlignment = Align  ;#PFA_CENTER,#PFA_LEFT,#PFA_RIGHT,#PFA_JUSTIFY,#PFA_FULL_INTERWORD
  SendMessage_(GadgetID(Gadget), #EM_SETPARAFORMAT, 0, @para)
  sel\cpMin = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, 0, 0)
  sel\cpMax = SendMessage_(GadgetID(Gadget), #EM_LINEINDEX, 0, 0)
  SendMessage_(GadgetID(Gadget), #EM_EXSETSEL, 0, @sel)
EndProcedure

Procedure AddText(Gadget,Text$,Eolf)
  If Eolf = 1
     Text$ = Text$ + Chr(10)
  EndIf
   SendMessage_(GadgetID(Gadget), #EM_REPLACESEL, #True, @Text$)
EndProcedure

Procedure WndProc(hWnd, uMsg, wParam, lParam) 
  result = #PB_ProcessPureBasicEvents 
  Select uMsg 
    Case #WM_NOTIFY 
      *el.ENLINK = lParam 
      If *el\nmhdr\code=#EN_LINK 
        If *el\msg=#WM_LBUTTONDOWN 
          LinkBuffer = AllocateMemory(#MAX_PATH) 
          lnk.TEXTRANGE
          lnk\chrg\cpMin = *el\chrg\cpMin 
          lnk\chrg\cpMax = *el\chrg\cpMax 
          lnk\lpstrText  = LinkBuffer
          SendMessage_(GadgetID(1), #EM_GETTEXTRANGE, 0, @lnk) 
          If PeekS(LinkBuffer) = "http:\\www.purebasic.com"
            ShellExecute_(0,"open","http:\\www.purebasic.com",0,0,#SW_SHOWNORMAL)
          EndIf 
          FreeMemory(LinkBuffer) 
        EndIf 
      EndIf 
  EndSelect 
  ProcedureReturn result 
EndProcedure

BFormat = 3   ;Bullet Format :Turn Off = 0,Normal = 1,Number = 2,LowerCaseLetter = 3,UpperCaseLetter = 4
              ;,LowerCaseRoman = 5,UpperCaseRoman = 6
BStart = 1    ;Bullet Start
BStyle = $100 ;Bullet Style :RightParenthesis = 0,DoubleParenthesis = $100,Period = $200,Plain = $300,NoNumber = $400 

LeftInd = 10        ;Left Indent
RightInd = 50       ;Right Indent

SpRule = 1 ;4       ;Line Spacing Rule :Single spacing = 0,One-and-a-half spacing = 1
                    ;,Double spacing = 2,dyLineSpacing is active = 3,4,5 
LSp = 500           ;Line Height in Twips
SpBefore = 10       ;Height Before Character in Twips
SpAfter = 10        ;Height After Character in Twips

If OpenWindow(0, 0, 0,500,500, "EditorGadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  SetWindowCallback(@WndProc())
  EditorGadget(1,0,0,0,0,#PB_Editor_ReadOnly)
  SendMessage_(GadgetID(1), #EM_SETEVENTMASK, 0, #ENM_LINK|SendMessage_(GadgetID(1), #EM_GETEVENTMASK, 0, 0))
  ;Remove the remark from next line in case you need to disable Caret But in this case #CFM_LINK will be disabled
  ;SetWindowLongPtr_(GadgetID(1), #GWL_STYLE, GetWindowLongPtr_(GadgetID(1), #GWL_STYLE)|#WS_DISABLED)
  ;StringGadget(2,10,470,200,20,"TEST")    
    
    
    CharFormat(1,"Forte",16,$0102FE,$000000,#CFM_BACKCOLOR)   ;CharFormat(#Gadget,Font Name,Font Size,Font Color,Font Flags)
    AddText(1,"This is a",0)              ;AddText(#Gadget,Text$,End of Line Flag(1 new line - 0 continue at the same line))

    CharFormat(1,"Broadway",24,$000000,$02FEFD,#CFM_BOLD)
    AddText(1," Test is OK ",0)    
    
    CharFormat(1,"Forte",16,$FD0202,$000000,#CFM_UNDERLINE|#CFM_BACKCOLOR)    ;To disable BackColor Use #CFM_BACKCOLOR
    AddText(1,"For MV",1)

    ;CharFormat(1,"Times new Roman",16,$05B9FA,$000000,#CFM_BACKCOLOR)
    ;AddText(1,"",1)
    
    CharFormat(1,"Times new Roman",16,$05B9FA,$000000,#CFM_ITALIC)  ;If The Font is Italic and right justified set para\dxRightIndent = 50
    AddText(1," This is EMBOSS",1)
    
    CharFormat(1,"Times new Roman",10,$000000,$000000,#CFM_LINK|#CFM_BACKCOLOR)
    AddText(1,"http:\\www.purebasic.com",0)
    ;AddText(1,"",1)                           ;Empty Line   
                                                                                                                      
    RangeFormat(1,0,1,0,1,0,#PFA_CENTER)      ;RangeFormat(Gadget,Start_Line,End_Line,Indent_Flag,Bullet_Flag,Line_Spacing_Flag,Alignment)
    RangeFormat(1,1,2,1,1,0,#PFA_RIGHT)
    ;RangeFormat(1,2,3,0,0,0,#PFA_LEFT)       
    
    SpFont("Quality",10,100,$0102FE,$E0FFFF,1) ;SpFont(Text$,x,y,Front_Color,Back_Color,Font_Flag( 0 or 1)) 
   
    AutoresizeEG(1)
    
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Last edited by RASHAD on Tue Jul 27, 2010 10:48 pm, edited 1 time in total.
Egypt my love
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: *New Ver 4 : AutoResize EditorGadget And More.... [Windo

Post by Vera »

Hi RASHAD,

sorry, but my Computer does not AutoResize on your code :lol:

This is by far the widest posting I've ever come across on both forums.


Could you please send me two more Computers to fit it in row ?
or Image
maybe insert some cheap blanks into those code lines:
format\dwMask = #CFM_FACE|#CFM_COLOR|#CFM_BACKCOLOR|....
para\dwMask = #PFM_ALL2;|#PFM_ALIGNMENT|#PFM_TABSTOPS|#PFM_RIGHTINDENT.....


Thanks ~ and thanks for your engagement ~ :wink: ~ Vera

edit: reinstalled : roll : icon to correct the deranged meaning by forum supporter
Last edited by Vera on Sat Oct 30, 2010 7:24 pm, edited 1 time in total.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: *New Ver 4 : AutoResize EditorGadget And More.... [Windo

Post by RASHAD »

Sorry @Vera :D
I did not notice
I hope that the code still OK

Now I am waiting for your comments

Have a good day sir
Egypt my love
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: *New Ver 4 : AutoResize EditorGadget And More.... [Windo

Post by Vera »

Dear RASHAD,

thanks - that's much better :)
But if you want to see if a posting is too wide just narrow your browser (test this thread ;) ).
As for the code: blanks don't corrupt the single line (resp. paragraph) and the wrapping is only optical but not breaking.

cheers ~ Vera
Post Reply