GetGadgetItemText() with WebGadget

Just starting out? Need help? Post your questions and find answers here.
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

GetGadgetItemText() with WebGadget

Post 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
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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))
quidquid Latine dictum sit altum videtur
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post 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
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

I don't really have an explanation. It is simply how the WebGadget ActiveX works i guess.
quidquid Latine dictum sit altum videtur
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

Well OK. However, thank you for showing me how have to handle the new functions nevertheless. :)

regards,
Christian
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

rendering question

Post 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?
Post Reply