WebGadget several sense of writting

Share your advanced PureBasic knowledge/code with the community.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

WebGadget several sense of writting

Post by Kwai chang caine »

Hello a all

I works for several day ago, on a WebGadget who write in different senses.
Obviously KCC can't write a code alone, i have much helped by the great SPARKIE :wink:

I believe i have finish, what i want.
Then, i shared this code, if by a miracle, someone who exist on this world, be less good that me.
Yes i know, it's impossible, but we never know :lol:

There are three senses :

#Web_Normal (No need to explain, exept at KCC :oops: )
#Web_Reverse (The text writting of down to up)
#Web_LastLine (The text is writting and you always see the last line)

Code: Select all

; http://www.purebasic.fr/english/viewtopic.php?p=276073#276073
; Original code by the great SPARKIE despite that a KCC only on his back 
; Try to put in a Procedure and decayed by KCC :-(

#Form = 25 
#GadgetWeb = 2 

#Web_Normal = 1
#Web_Reverse = 2
#Web_LastLine = 3

Procedure WinCallback(hwnd, uMsg, wParam, lParam)

 Select uMsg 
  Case #WM_CLOSE 
   End 
  Case #WM_KEYDOWN 
   If wParam = #VK_ESCAPE 
    End
   EndIf 
  Case #WM_SIZING 
   ResizeGadget(#GadgetWeb, #PB_Ignore, #PB_Ignore, WindowWidth(#Form) - 10, WindowHeight(#Form) - 10) 
 EndSelect 

 ProcedureReturn #PB_ProcessPureBasicEvents 
 
EndProcedure 

Procedure WriteWebGadget(PbIdWebGadget, Texte.s, FontSize.f = 6, Affichage = #Web_Normal); #Web_Reverse / #Web_Normal / #Web_LastLine 
   
 Texte = ReplaceString(Texte, Chr(13), "<br>")
 LineHeight.f = FontSize / 0.85 
 ;- Convert font pt size to pixels 
 HwndFenetre = GetParent_(GadgetID(PbIdWebGadget))
 PbIdFenetre = GetProp_(HwndFenetre,"PB_WindowID") - 1
 hdc = StartDrawing(WindowOutput(PbIdFenetre))
 LogPixY = GetDeviceCaps_(hdc, #LOGPIXELSY) 
 StopDrawing() 
 
 Fontheight.f = FontSize / (72 / logPixY) ;-72pt = 1 inch 
 LinePixels = LineHeight / (72 / logPixY) ;-72pt = 1 inch 
 DivHeight.f= GadgetHeight(PbIdWebGadget) - (LineHeight * 2) 
 NBreLignesMax = (DivHeight / LinePixels)
 NbreLignesText = CountString(Texte, "<br>")
 
 EnteteHtml$ = "<html><head><title></title>" 
 FinHtml$ + "</div></body></html>"
 
 If Affichage = #Web_Normal

  EnteteHtml$ + "<body><div class='page' style='font-Size: " + Str(fontSize) + " pt; line-height: " + Str(lineHeight) + " pt'>" + #CRLF$ 
 
 Else
  
  EnteteHtml$ + "<body scroll='no'><div class='page' style='overflow-y: hidden; align: bottom; height: " + Str(divHeight) + "px; font-Size: " + Str(fontSize) + " pt; line-height: " + Str(lineHeight) + " pt'>" + #CRLF$  
  
  If NbreLignesText >= NBreLignesMax Or Affichage = #Web_Reverse
     
   Temp$ = ""
   
   For i = NBreLignesMax - 1 To 1 Step - 1
   
    String.s = Texte
            
    For r = 1 To NbreLignesText - i
    
     Pos = FindString(String, "<br>", 1) 
     
     If Pos 
      Field.s = Left(String, Pos - 1) 
     Else 
      Field.s = String 
     EndIf 
     
     String = Mid(String, Pos + Len("<br>"), Len(string)) 
    
    Next 
      
    Temp$ + Field + "<br>"
    
   Next
   
   Texte = Temp$
       
  EndIf 

 EndIf  

 SetGadgetItemText(PbIdWebGadget, #PB_Web_HtmlCode, EnteteHtml$ + Texte + FinHtml$)      
 While WindowEvent():Wend 
 
EndProcedure

OpenWindow(#Form, 0, 0, 800, 500, "", #PB_Window_SystemMenu|#PB_Window_SizeGadget) 
WebGadget(#GadgetWeb, 0, 0, WindowWidth(#Form) - 10, WindowHeight(#Form) - 10, "") 
SetWindowCallback(@WinCallback()) 

For i = 1 To 50
 
 a$ + "La line " + Str(i) + " of KCC is writting" + #CRLF$ 
 WriteWebGadget(#GadgetWeb, a$, 10, #Web_LastLine) 
 ;WriteWebGadget(#GadgetWeb, a$, 10, #Web_Reverse) 
 ;WriteWebGadget(#GadgetWeb, a$, 10, #Web_Normal)
 Delay(100)
 
Next

WriteWebGadget(#GadgetWeb, a$, 10, #Web_Normal) ; For Write the Page full and appears the Scrollbar

Repeat  
 Event = WaitWindowEvent() 
Until Event = #PB_Event_CloseWindow 

End
Good day
ImageThe happiness is a road...
Not a destination