[V460]webgadget and "file://" incompatible?

Mac OSX specific forum
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

[V460]webgadget and "file://" incompatible?

Post by michel51 »

Hello all,

for a project I need a webgadget that shows a site, which is built by myself.
See the example:

Code: Select all

Define html$
html$ + "<html>"
html$ + "</head>"
html$ + "<body>"
html$ + "<pre>" ; ####!!!!####
html$ + "<code>" ; ######
html$ + "<i><p>Test</p></i>"
html$ + "<p>    2. <b>Zeile</b> angefuegt<p>"
html$ + "<p>Versuche <a href='http://www.purebasic.com/' target='_blank'>PureBasic</a> zu erreichen.<p>"
html$ + "<code>" ; ######
html$ + "</pre>" ; ####!!!!####
html$ + "</body>"
html$ + "</html>"

; this part because the flag >#PB_Web_HtmlCode< is not available on Mac OS
CreateFile( 0, GetCurrentDirectory() + "test.html" )
WriteString( 0, html$, #PB_UTF8)
CloseFile( 0 )

If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  URL$ = "file://" + GetCurrentDirectory() + "test.html"
;   URL$ = "http://www.purebasic.com"

Debug URL$

  CompilerIf #PB_Compiler_Unicode
    AsciiURL$ = Space(Len(URL$))
    PokeS(@AsciiURL$, URL$, -1, #PB_Ascii)
    URL$ = AsciiURL$
  CompilerEndIf
  
  WebGadget(0, 10, 10, 580, 280, URL$)
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
The site "test.html" is indicated correctly within the webgadget, but if I click on the link, nothing happens. The link will be selected, but the desired site is not opened.
Two possibilities should enter: either the standard browser will start and show the linked site, or the link I clicked on will be shown within the webgadget. I prefer the first option.

But if I change the url (comment out the corresponding line), all will work well.

Any idea? Can someone help?
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: [V460]webgadget and "file://" incompatible?

Post by Shield »

It's working fine here, although IE will be opened and not the standard browser (Opera).
You can try using a navigation callback and start the default browser (RunProgram) manually. :)
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: [V460]webgadget and "file://" incompatible?

Post by Polo »

Shield wrote:It's working fine here, although IE will be opened and not the standard browser (Opera).
You can try using a navigation callback and start the default browser (RunProgram) manually. :)
Mac forum :)
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: [V460]webgadget and "file://" incompatible?

Post by Shield »

oh :lol:
That's the curse of using 'View active topics'. :)
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: [V460]webgadget and "file://" incompatible?

Post by wilbert »

It looks like you can't open a site in the external browser this way.
You can open it in the gadget itself. With some extra code it is also possible to set html code directly by the way

Edit:
I see there's no need for my extra code.
#PB_Web_HtmlCode seems to work fine on OS X also.
But I'll leave the code here in case someone has the need to communicate more directly with the WebView

Code: Select all

; *** imports to interact with the WebGadget ***

ImportC ""
  objc_getClass(name.p-ascii)
  sel_registerName(str.p-ascii)
  objc_msgSend(theReceiver, theSelector, arg1 = #Null, arg2 = #Null)
  HIWebViewGetWebView(inView)
  NSStringInit(theReceiver, theSelector, characters.p-unicode, length) As "_objc_msgSend"
EndImport


; *** required Classes and Selectors *** 

Global Cls_NSString = objc_getClass("NSString")

Global Sel_alloc = sel_registerName("alloc")
Global Sel_initWithCharacters = sel_registerName("initWithCharacters:length:")
Global Sel_loadHTMLString = sel_registerName("loadHTMLString:baseURL:")
Global Sel_mainFrame = sel_registerName("mainFrame")
Global Sel_release = sel_registerName("release")


; *** procedure to convert a PB string to a NSString ***

Procedure NSString(s.s)
  ProcedureReturn NSStringInit(objc_msgSend(Cls_NSString, Sel_alloc), Sel_initWithCharacters, s, Len(s))
EndProcedure


; *** main code ***

Define html$
html$ + "<html>"
html$ + "</head>"
html$ + "<body>"
html$ + "<pre>" ; ####!!!!####
html$ + "<code>" ; ######
html$ + "<i><p>Test</p></i>"
html$ + "<p>    2. <b>Zeile</b> angefuegt<p>"
html$ + "<p>Versuche <a href='http://www.purebasic.com/'>PureBasic</a> zu erreichen.<p>"
html$ + "<code>" ; ######
html$ + "</pre>" ; ####!!!!####
html$ + "</body>"
html$ + "</html>"

If OpenWindow(0, 0, 0, 600, 340, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  ButtonGadget(0, 10, 10, 100, 20, "Set HTML")
  
  PBWebView = WebGadget(#PB_Any, 10, 50, 580, 280, "")
  WebView = HIWebViewGetWebView(GadgetID(PBWebView)); *** get the WebView from the WebGadget ***
  MainFrame = objc_msgSend(WebView, Sel_mainFrame); *** get the MainFrame fron the WebView ***
  
  Repeat
    EventID = WaitWindowEvent()
    If EventID = #PB_Event_Gadget
      Select EventGadget()
          
        Case 0; *** Set HTML *** 
          
          HTML_ = NSString(html$)
          objc_msgSend(MainFrame, Sel_loadHTMLString, HTML_, #Null)
          objc_msgSend(HTML_, Sel_release)
          
      EndSelect
    EndIf      
  Until EventID = #PB_Event_CloseWindow
  
EndIf
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Re: [V460]webgadget and "file://" incompatible?

Post by michel51 »

wilbert wrote:It looks like you can't open a site in the external browser this way.
That's the point :!:
Your code works fine, but it solves my problem not really.
I want to show a self created html file within the webgadget. See my first post the file "test.html". This works with my example.
But the links within the file cannot be opened, neither within the webgadget nor with the standard browser. That's what I need.
I'm not so familiar with Mac API, but I think, there is an easy solution that can built in a crossplatform application, with or without API.

And btw, >runprogram< seems to be buggy on Mac. See this post: http://www.purebasic.fr/english/viewtop ... 24&t=48087
#PB_Web_HtmlCode seems to work fine on OS X also.
NO, #PB_Web_HtmlCode is only on Windows working like a lot of other constants and flags. See the help in webgadget.
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
Post Reply