Page 1 of 1

GetGadgetItemText() with WebGadget

Posted: Mon Aug 06, 2007 1:20 pm
by Christian
Hi!

Tried to use the the new functions of the WebGadget and wanted to stream code into it. Latter works, but if I want to get the sourceode that I streamed into the WebGadget, a wrong value is returned.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - MiniBrowser
;
;    (c) 2003 - Fantaisie Software
;
; ------------------------------------------------------------
;
; This program requiers the Microsoft freely distribuable 
; ATL.dll shared library.
;

Procedure WebGadget_WriteString(GadgetID, String.s)
SetGadgetItemText(GadgetID, #PB_Web_HtmlCode, GetGadgetItemText(GadgetID, #PB_Web_HtmlCode) + String)
Debug GetGadgetItemText(GadgetID, #PB_Web_HtmlCode) + String
EndProcedure

Procedure ResizeWebWindow()
  ResizeGadget(10, #PB_Ignore, #PB_Ignore, WindowWidth(0), WindowHeight(0)-52)
  ResizeGadget(4, #PB_Ignore, #PB_Ignore, WindowWidth(0)-185, #PB_Ignore)
  ResizeGadget(5, WindowWidth(0)-25, #PB_Ignore, #PB_Ignore, #PB_Ignore)
  ResizeGadget(6, #PB_Ignore, #PB_Ignore, WindowWidth(0), #PB_Ignore)
EndProcedure


If OpenWindow(0, 100, 200, 500, 300, "PureBasic MiniBrowser v1.0", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)

  CreateStatusBar(0, WindowID(0))
    StatusBarText(0, 0, "Welcome to the world's smallest Browser ! :)", 0)

  CreateGadgetList(WindowID(0))
    ButtonGadget(1,   0, 0, 50, 25, "Back")
    ButtonGadget(2,  50, 0, 50, 25, "Next")
    ButtonGadget(3, 100, 0, 50, 25, "Stop")
  
    StringGadget(4, 155, 5, 0, 20, "http://www.purebasic.com")
    
    ButtonGadget(5, 0, 0, 25, 25, "Go")
    
    Frame3DGadget(6, 0, 30, 0, 2, "", 2) ; Nice little separator
  
    If WebGadget(10, 0, 31, 0, 0, "") = 0 : MessageRequester("Error", "ATL.dll not found", 0) : End : EndIf

; ----------------------------------------------------
;  GetGadgetItemText(...) returns the wrong value
;  "<Document ...>" instead of "<html><body>Hello world!</body></html>"
; ----------------------------------------------------

    ; - Stream Source into WebGadget
    SetGadgetItemText(10, #PB_Web_HtmlCode, "<html><body>Hello world!</body></html>")

    ; - Get HTML Code
    MessageRequester("Code", GetGadgetItemText(10, #PB_Web_HtmlCode))

; ------------------------------------------


  AddKeyboardShortcut(0, #PB_Shortcut_Return, 0)
  
  ResizeWebWindow()
  
  Repeat
    Event = WaitWindowEvent()
    
    Select Event
      Case #PB_Event_Gadget
      
        Select EventGadget()
          Case 1
            SetGadgetState(10, #PB_Web_Back)
          
          Case 2
            SetGadgetState(10, #PB_Web_Forward)
          
          Case 3
            SetGadgetState(10, #PB_Web_Stop)
          
          Case 5
            SetGadgetText(10, GetGadgetText(4))
            
        EndSelect      
      
      Case #PB_Event_Menu ; We only have one shortcut
        SetGadgetText(10, GetGadgetText(4))

      Case #PB_Event_SizeWindow
        ResizeWebWindow()
      
    EndSelect
      
  Until Event = #PB_Event_CloseWindow
   
EndIf
Regards,
Christian

Posted: Mon Aug 06, 2007 1:32 pm
by freak
You have to wait for the HTML to be rendered before you can read it back.
To allow the Gadget to render the code, you have to call (Wait)WindowEvent()
to process events.

You can use the new events of the Gadget to know when the rendering is complete.

Something like this will work as well:

Code: Select all

    ; - Stream Source into WebGadget
    SetGadgetItemText(10, #PB_Web_HtmlCode, "<html><body>Hello world!</body></html>")

    While GetGadgetAttribute(10, #PB_Web_Busy)
      While WaitWindowEvent(1): Wend
    Wend

    ; - Get HTML Code
    MessageRequester("Code", GetGadgetItemText(10, #PB_Web_HtmlCode))

Posted: Mon Aug 06, 2007 4:35 pm
by Christian
Hi freak!

Thank you for the fast answer! Will try it. But could you shortly explain why the HTML first has to be rendered?

regards,
Christian

Posted: Mon Aug 06, 2007 4:48 pm
by freak
I don't really have an explanation. It is simply how the WebGadget ActiveX works i guess.

Posted: Mon Aug 06, 2007 9:35 pm
by Christian
Well OK. However, thank you for showing me how have to handle the new functions nevertheless. :)

regards,
Christian

rendering question

Posted: Mon Oct 08, 2007 1:02 am
by Fangbeast
On the subject of streaming into the webgadget, I've grabbed the contents of an editorgadget and plonked the whole lot at once into a webgadget and not all renders properly.

1. When streaming, should I only throw one line at a time?
2. Html emails show perfectly in my emailer and they claim to use a custom rendering engine, not ie, but the emails show correctly in ie. Would this be because I am misusing the streaming option by plonking an entire page into the gadget at a time?