||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||
|| COPYRIGHT 2009 LogiqueWerks. All Rights Reserved
||
|| Aule Browser for Search simple-browser_002.curl
||

{curl 7.0 applet}
{curl-file-attributes character-encoding = "windows-latin-1"}
{applet
||    manifest = "manifest.mcurl",
    {compiler-directives careful? = true},
    resync-file = "resync-curl.txt"
}

{import * from CURL.GUI.STANDARD}
{import * from CURL.GUI.EMBEDDED-BROWSER}
{import WindowVisibility from CURL.GRAPHICS.WINDOW}
{import * from COM.LW.AULE.MACROS,
||    vendor = "Logiquewerks",
    location = "http://www.aule-browser.com/internal/macros.scurl"
}

{document-style PlainDocument}
{def public bg:Background = {Background.from-string "#F7F7FF"}}
{set-document-properties
  background = bg
}

{let inspect?:bool}
{if-debuggable
   set inspect? = true
}
{if not inspect? then
 {disable-inspection-gesture}
}

{let public actions?:bool = true } ||||||||||||||||||||||||||||||||||||||||| enabled

|| {set actions? = false } ||||||||||||||||||||||||||||||||||||||||||||||||||| disable here

{let public silent?:bool = false}

|| {set silent? = true } ||||||||||||||||||||||||||||||||||||||||||||||||||| disable here

{let eb:#EmbeddedBrowserGraphic = null}
{let public running?:bool}

{if not {get-the-applet}.detached? then
  {on-applet-suspend do
    {if running? and eb != null   then
      {eb.destroy-browser}
    }
    {{get-the-applet}.browse-backward}
    {exit 0}
  }
}

{let public show-targets-in-bar:bool = true}
|||||||||||||||||||||||||||||||||||||||||||||||||||||| TITLE ||||||||||||||
{let public title:String = "Aule Browser: Search"}
|||||||||||||||||||||||||||||||||||||||||||||||||||||| TARGET |||||||||||||
{def target-url = "http://www.bing.com"}  
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|| persist to CSPD on initial from splash screen

||||||||||||||||||||||||||||||||||||||||||||||||||||| topic ||||||||||||||
||
   {let public topic:String = "Aule+Browser"} ||||||||||||||||||||||||||||||| persist to CSPD
||

{define-enum ErrorType
    err = "Error",           || name , index, value 
    security-exc = "SecurityException",
    exc = "Exception"
}

{let public error-msg:ErrorType = ErrorType.exc} || {ErrorType index = 2}

{define-text-proc {error-message}:any
    {switch error-msg.index
     case ErrorType.err.index do
        {return {paragraph EmbeddedBrowserGraphic is not supported on this platform.}}
     case ErrorType.security-exc.index do
        {return {paragraph This applet requires privileged host or directory}}
     case ErrorType.exc.index do
        {return {paragraph An exception has occurred: please advise support}}
     else
        {return {paragraph An unhandled exception has occurred: please advise support}}
    }
}

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Actions

{define-enum ActionName
    projects = "projects-proc",
    notes =  "notes-proc",
    bookmarks = "bookmarks-proc",
    twine = "twine-proc",
    tagcloud = "tagcloud-proc",
    seo = "seo-proc",
    tweet = "tweet-proc",
    aule = "aule-proc"
}

{let actions:{Array-of {proc-type {ActionName}:void}} = 
    { {Array-of {proc-type {ActionName}:void}}
        {proc {an:ActionName}:void
            {browse-proc {url "http://www.qtask.com"}}
        },
        {proc {an:ActionName}:void
            {browse-proc {url "http://www.cl1p.net"}}
        },
        {proc {an:ActionName}:void
            {browse-proc {url "http://delicious.com/save?jump=yes&"}}  || runtime issue here for tagging
        },
        {proc {an:ActionName}:void
            {browse-proc {url "http://www.twine.com"}}
        },
        {proc {an:ActionName}:void
            {browse-proc {url "http://www.tagcloud.com"}} || {url "http://iweb.com"}}
        },
        {proc {an:ActionName}:void
             {browse-proc {url "http://en.wikipedia.org/wiki/Search_engine_optimization"}}
        },
        {proc {an:ActionName}:void
            {browse-proc {url "http://www.twitter.com"}}
        },
        {proc {an:ActionName}:void
            {browse-proc {url "http://www.aule-browser.com/aule-home.html"}} 
        } 
    }
}

{let action-labels:{Array-of String} = 
   { {Array-of String}
       "Projects",
       "Notes",
       "Bookmarks",
       "Twine",
       "TagCloud",
       "wp SEO",
       "tweet", 
       "Aule Browsers"
   }
}

{let public action-proc:{proc-type {ActionName}:void} =
    {proc {action-name:ActionName}:void
        {actions[action-name.index] action-name}
    }
}

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||
||
{define-class public ActionCommandButton {inherits CommandButton} 
  
  field public action-name:ActionName

  {constructor public {active
                          action-name:ActionName,
                          ...}
    {construct-super.CommandButton.default {splice ...}}
    set self.action-name = action-name
  }
  
} || eof class |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

{define-proc public {a-button action-name:ActionName, ...}:ActionCommandButton
    {return  {ActionCommandButton.active
                 action-name,
                 label = {Label action-labels[action-name.index]},
||                 width = (action-labels[action-name.index].size * 7pt),
                 enabled? = actions?,
                 {splice ...},
                {on Action at acb:ActionCommandButton do
                    {action-proc action-name}
                }
             }
    }
}


||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||
||
{define-class public UrlCommandButton {inherits CommandButton} 
  
  field public url-index:int

  {constructor public {indexed
                          index:int,
                          ...}
    {construct-super.CommandButton.default {splice ...}}
    set self.url-index = index
  }
} || eof class ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| TARGETS ||||||||||||||||||||||||||||||||||||||||||||

  || cuil  lycos  webcrawler  findstuff info looksmart

{define-enum Target
    bing = "http://www.bing.com",
    google = "http://www.google.com/search?q=%22Aule+Browser%22&rls=com.microsoft:en-us:IE-SearchBox&ie=UTF-8&oe=UTF-8&sourceid=ie7&rlz=1I7SUNA_en",
    yahoo = "http://search.yahoo.com/search?p=%22Aule+Browser%22&ei=utf-8&fr=b1ie7",
    about = "http://www.about.com",
    alta = "http://www.altavista.com/web/results?itag=ody&q=%22Aule+Browser%22&kgs=1&kls=0",
    ask = "http://www.ask.com/web?q=%22Aule+Browser%22&search=&qsrc=0&o=0&l=dir",
    dp = "http://www.dogpile.com",
    lycos = "http://search.lycos.com/?query=%22Aule+Browser%22&x=28&y=17&diktfc=CBF2D50A14F55BD0D483C782A04FE789F8291BA87BF5",
    wp = "http://en.wikipedia.org/wiki/CiteSeer",
    bbc = "http://www.bbc.co.uk",
    sv = "http://www.springer.com/computer/computer+imaging/journal/371",
    cu = "http://www.citeulike.org/",
    rh = "http://www.redherring.com",
    cs = "http://citeseerx.ist.psu.edu/",
    acm = "http://portal.acm.org/",
    help = "http://www.logiquewerks.com/help/sb-help.curl"
}

{let target-urls:{Array-of Url} = 
      { {Array-of Url}
          {url Target.bing.value},
          {url Target.google.value},
          {url Target.yahoo.value},
          {url Target.about.value},
          {url Target.alta.value},
          {url Target.ask.value},
          {url Target.dp.value},
          {url Target.lycos.value},
          {url Target.wp.value},
          {url Target.bbc.value},
          {url Target.sv.value},
          {url Target.cu.value},
          {url Target.rh.value},
          {url Target.cs.value},
          {url Target.acm.value},
          {url Target.help.value}
      }
}

{let target-labels:{Array-of String} = 
   { {Array-of String}
       "Bing",
       "Google",
       "Yahoo!",
       "About",
       "AltaVista",
       "Ask",
       "DogPile",
       "Lycos",
       "Wikipedia",
       "BBC",
       "Springer",
       "citeulike",
       "Red Herring",
       "CiteSeer",
       "ACM",
       "Help"
   }
}

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||procs

{let public browse-proc:#{proc-type {Url}:void} 
}

{let public refresh-address-bar-proc:#{proc-type {EmbeddedBrowserGraphic}:void}
}

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| eof procs

{define-proc public {b-button tgt:Target}:UrlCommandButton
    {return  {UrlCommandButton.indexed
                 tgt.index,
                 label = {Label target-labels[tgt.index]},
||                 width = (target-labels[tgt.index].size * 7pt),
                {on Action at ucb:UrlCommandButton do
                    {browse-proc target-urls[ucb.url-index]}
                }
             }
    }
}

{define-proc public {status str:String}:void
   set status-bar.value = str
}

{let status-bar?:bool = true}
{let public status-text:String = ""}

{let public status-bar:TextField =
    {TextField
        width = {make-elastic},
        height = 0.5cm,
        background = {Background.from-string "white"},
        value = title
    }
}

{let public status-box :HBox = {HBox
                                   valign = "top",
                                   border-width = 0px,
                                   margin = 0px,
                                   height =  14pt,
                                   background = {Background.from-string "wheat"},
                                   status-bar
                               }
}

{let public has-browser?:bool}

{define-proc public {brwsr-handle-event brwsr:EmbeddedBrowserGraphic, e:EmbeddedBrowserEvent}:void
    {type-switch e
     case stce:StatusTextChangeEvent do
        {if show-targets-in-bar then
            set status-text = brwsr.browser-status-text
            {if 0 == {status-text.find-string "http",  ignore-case? = true, starting-index = 0} then
                {status status-text}
            }
        }
     case e2:DocumentFinishEvent do
         {refresh-address-bar-proc brwsr}
     case e3:BrowseStartEvent do
     case e4:TitleTextChangeEvent do
     case e5:BrowseFinishEvent do
     case e6:DownloadStartEvent do
     case e7:DownloadFinishEvent do
     case e8:BrowseErrorEvent do
     else
        {error "unexpected type of event"}
    }
}

{try
    set eb =  {EmbeddedBrowserGraphic
                  external-browse-option = ExternalBrowseOption.allow,
                  silent? = silent?,
                  suppress-scrollbars? = false,
                  background = bg,
                  border-width = 0px,
                  margin = 0px
              }
    set has-browser? = true
 catch e:Error do
    {popup-message "Unable to load the browser",
        title = "Browser error"}        
    {if-debuggable
        {output "BRWSR: " & e.message}
    }
 catch se:SecurityException do
    {if-debuggable
        {popup-message ("Unable to load the browser . Please confirm in the Curl RTE Control Panel that the directory is listed on the Security tab"),
            title = "Browser security exception"}
        {output "SecurityException: " & se.message}
    }
 catch ex:Exception do
    {popup-message "Unable to load the browser                                      .",
        title = "Browser exception: Unable to load the browser"}
    {if-debuggable
        {output "EXCEPTION: " & ex.message}
    }
}

{if eb != null and {process-privileged?} then
    {eb.add-event-handler
        {on e:EmbeddedBrowserEvent at brwsr:EmbeddedBrowserGraphic do
            {brwsr-handle-event brwsr, e}
        }
    }
}
|| the following is essential when testing as a Curl file
{if not {get-the-applet}.detached? then
    {on-applet-suspend do
        {if running? and (eb != null) then
            {eb.destroy-browser}
        }
        {exit 0}
    }
}

{let public forward-count:int = -1}
{let public backward-count:int = -1}

{let public curr-url:#Url = null }
{if eb != null then
    {set eb.width = {make-elastic}}
    {set eb.height = {make-elastic}}
}

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| urlTextField
{let public startup?:bool = true}

{let public urlTextField:TextField =
    {TextField
        width = 6cm,
        background = bg,
        value = target-url,  || set to CSPD on initial from splash screen
        || ADD A HOME BUTTON
        {on action:ValueChanged at tf:TextField do
            {action.consume}
        },
        {on action:Action at tf:TextField do
            {action.consume}
        },
        {on action:ValueFinished at tf:TextField do
            {action.consume}
        },
        {on action:Commit at tf:TextField do
            {if startup? then
                set startup? = false
                {try
                    {eb.browse-url
                        {parse-url (tf.value asa String)}
                    }
                 catch se:SecurityException do
                    {if-debuggable  {output se.message} }
                 catch ex:Exception do
                    {popup-message (ex.message & "Please re-enter a valid URL"), title = "The browser rejected the URL"}
                    set tf.value = target-url 
                }
            }
            {action.consume}
        },
        {on action:KeyPress at tf:TextField do
            {if action.value == '\uef83' then
                {try
                    {eb.browse-url
                        {parse-url (tf.value asa String)}
                    }
                 catch se:SecurityException do
                    {output se.message}
                 catch ex:Exception do
                    {popup-message (ex.message & " please re-enter the URL"), title = "A browser exception has occurred"}
                    set tf.value = target-url 
                    ||                 catch err:Error do
                }
            }
        }
    }
}
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| eof urlTextField

{let public has-page?:bool}

{define-proc public {refresh-url}:void
    {if eb != null then
        {refresh-address-bar-proc eb asa EmbeddedBrowserGraphic}
    }
}

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| assign procs ||||||||||||

{set browse-proc =
    {proc  {target:Url}:void
        {if eb != null then
            {with-busy-cursor
                {if has-page? then
                    {eb.browser-stop}
                    {refresh-url}
                 else
                    set has-page? = true
                }
                set urlTextField.value = target.name
                {eb.browse-url target}
            }
        }
    }
}

{set refresh-address-bar-proc =
    {proc  {brwsr:EmbeddedBrowserGraphic}:void
        {try 
            set curr-url = brwsr.browser-location-url
         catch e:Exception do
            {if-debuggable {output e.message & " in refresh-url"}}
            set curr-url = null
        }
        {if-non-null curr-url then
            set urlTextField.value = curr-url.name
        }
    }
}

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

{let public toolbar?:bool = true}
{let public toolbar:HBox =
    {HBox
            valign = "center",
            width = {make-elastic},
            background = {Background.from-string "silver"},
            border-color = "black",
            border-width = 1px,
            margin = 2px,
            enabled? = (eb != null),
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Toolbar action declarations follow
        {a-button ActionName.projects, tooltip = {rollover "Qtask.com"}},
        {a-button ActionName.notes, tooltip = {rollover "CL1P.net"}},
        {a-button ActionName.bookmarks, tooltip = {rollover "delicious.com"}},
        {a-button ActionName.twine, tooltip = {rollover "twine.com"}},
        {a-button ActionName.tagcloud, tooltip = {rollover "tagcloud.com"}},            
        {Fill width = 10pt},
        {HBox
          valign = "center", 
          border-width = 1px,
          {Fill width = 4pt},
          {text Topic: },
          {Fill width = 4pt}, 
          {TextField width = 140pt}, |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Note2Tag
          {Fill width = 8pt},
          {CommandButton
                label = {Label "Note2Tag", vstretch? = true },
                width = 1.75cm,
                height = 17pt,
                tooltip = {Tooltip.from-string "note2tag.com"},
                {on Action do
                  {popup-message "Action to be implemented in release version", title = "Save Tag Action"}
                }
          },
          {Fill width = 4pt}
        },
        {Fill},
            {b-button Target.rh},
            {b-button Target.cs},
            {b-button Target.acm},

        {a-button ActionName.seo, tooltip = {rollover "en.wikipedia.org"}},
|| seo
        {Fill},
        {a-button ActionName.tweet, tooltip = {rollover "twitter.com"}},
        {Fill width = 4pt},
        {b-button Target.help},
        {Fill width = 4pt},
        {a-button ActionName.aule, tooltip = {rollover "aule-browser.com/aule-home.html"}},
        {Fill width = 8pt} 
    }
} ||||||||| eof toolbar |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

{let v:VBox =
    {VBox
        width = {make-elastic minimum-size = 420px} ,
        background = "white",
        ||    {heading Curl's Embedded Browser Widget},
        ||    {Fill height = 8pt},
        ||                  {text Enter a URL in the toolbar below such as  http://www.logiquewerks.com/phpinfo.php  and then use CTRl-F to find  HTTP_USER_AGENT},
        ||       hstretch? = true,
        {HBox
            ||        vstretch? = true,
            width = {make-elastic},
            background = {Background.from-string "silver"},
            border-color = "black",
            border-width = 1px,
            margin = 2px,
            enabled? = (eb != null),
            {CommandButton
                label = {Label "<-"},
                width = 0.75cm,
                tooltip = {rollover "BACK"},
                {on Action do
                    {if eb != null then
                        {try
                            {eb.browse-backward}
                         catch se:SecurityException do
                            {output se.message}
                        }
                        {refresh-url}
                    }
                }
            },
            {CommandButton
                label = {Label "->"},
                width = 0.75cm,
                tooltip = {rollover "FORWARD"},
                {on Action do
                    {if eb != null then
                        {try
                            {eb.browse-forward}
                         catch se:SecurityException do
                            {output se.message}
                        }
                        {refresh-url}
                    }
                }
            },
            {CommandButton
                label = {Label "Reload"},
||                width = 1.5cm,
                {on Action do
                    {if eb != null then
                        {eb.browser-refresh force-reload? = true}
                        {refresh-url}
                    }
                }
            },
            {CommandButton
                label = {Label "Stop"},
||                width = 1.25cm,
                {on Action do
                    {if eb != null then
                        {eb.browser-stop}
                        {refresh-url}
                    }
                }
            },
            urlTextField,
            {CommandButton
                label="+",
                width = 0.5cm,
                tooltip = {rollover "Zoom IN"},
                {on Action do
                    {if eb != null then
                        {eb.browser-zoom-in}
                    }
                }
            },
            {CommandButton
                label="-",
                width = 0.5cm,
                tooltip = {rollover "Zoom OUT"},
                {on Action do
                    {if eb != null then
                        {eb.browser-zoom-out}
                    }
                }
            },
            {Fill},
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
            {b-button Target.bing},
            {b-button Target.google},
            {b-button Target.yahoo},
||            {b-button Target.about},
            {b-button Target.alta},
            {b-button Target.ask},
            {b-button Target.dp},
            {b-button Target.lycos},
            {b-button Target.wp},
            {b-button Target.sv},
            {b-button Target.cu},
            {b-button Target.bbc},
            {Fill},
            {CommandButton
                label = {Label "TB"},
||                width = 0.8cm,
                tooltip = {rollover "Toggle Toolbar"},
                {on Action do
                    {if toolbar? then
                        set toolbar? =false
                        set toolbar.height = 0px
                     else
                        set toolbar.height = 22pt
                        set toolbar? = true
                    }
                }
            },
            {CommandButton
                label = {Label "SB"},
||                width = 0.8cm,
                tooltip = {rollover "Toggle Statusbar"},
                {on Action do
                    {if status-bar? then
                        set status-bar? =false
                        set status-bar.height = 0px
                        set status-box.height = 0px
                     else
                        set status-bar.height = 14pt
                        set status-box.height = 14pt                        
                        set status-bar? = true
                    }
                }
            },
            {Fill width = 8pt}
        },
        toolbar,
        {HBox
            border-width = 0px,
            margin = 0px,
            width = {make-elastic minimum-size =  400px},
            background = bg,
            vstretch? = true,
            {if eb != null then
                eb
             else
                {error-message}
            }
        },
        ||                  {Fill},
        {if-non-null eb then
            status-box
         else
            {text}
        },
        {Fill height = 2px}
    }
}

{View
    visibility = WindowVisibility.normal,
    background = {Background.from-string "#F8F8FF"},
    border-width = 2pt,
    width = 850,  || opening size set here
    height =  520, ||  preferred-height}, || opening size set here SEE docs
    title = title,
    v,
    {on ViewActivateEvent do
        {if startup?  then
            {after 0.25s do
                {urlTextField.handle-event {Commit}}
                set startup? = false
                set running? = true
            }
        }
    },
    {on WindowClose do
        set running? = false
        {if eb != null then
            {eb.destroy-browser}
        }
        {exit 0}
    }
}
||||||||||||||||||||||||||| eof ln 554 |||||||||||||||||||||||||||||||||||
|docs#
  EmbeddedBrowserState (enum)

  public EmbeddedBrowserState

  State of the browser used by EmbeddedBrowserGraphic.browser-state.

 &#8226; none&#8212;No page has been loaded.

 &#8226; browse-start&#8212;A browse has been started, and a BrowseStartEvent has been enqueued.

 &#8226; browse-finish&#8212;A browse has been finished, and a BrowseFinishEvent has been enqueued.

 &#8226; browse-error&#8212;A browse has had an error, and a BrowseErrorEvent has been enqueued.

 &#8226; document-finish&#8212;A page has been fully rendered, and a DocumentFinishEvent has been enqueued.

  Introduced in: version 6.0

 Package: CURL.GUI.EMBEDDED-BROWSER

  none

  browse-start

  browse-finish

  browse-error

  document-finish
#docs|


