;;;; ;;;; w w w - b r o w s e r . s t k l o s -- A simple WEB browser ;;;; ;;;; Copyright © 1993-1999 Erick Gallesio - I3S-CNRS/ESSI ;;;; ;;;; Permission to use, copy, modify, distribute,and license this ;;;; software and its documentation for any purpose is hereby granted, ;;;; provided that existing copyright notices are retained in all ;;;; copies and that this notice is included verbatim in any ;;;; distributions. No written agreement, license, or royalty fee is ;;;; required for any of the authorized uses. ;;;; This software is provided ``AS IS'' without express or implied ;;;; warranty. ;;;; ;;;; Author: Erick Gallesio [eg@unice.fr] ;;;; Creation date: 21-Oct-1996 14:02 ;;;; Last file update: 3-Sep-1999 19:56 (eg) ;;;; (require "Tk-classes") (require "www") (import WWW) (define WWW:browser (let ((browser #f) ;; Id of browser (#f if no browser exists) (lentry #f)) ;; The labeled entry of the interface (lambda args ;; URL history management ;; (define new-url (let ((history '()) (current -1)) (lambda (txt url) (case url ((previous) (when (> (length history) 1) (set! current (modulo (- current 1) (length history))) (www:view-url (Id txt) (list-ref history current)))) ((next) (when (> (length history) 1) (set! current (modulo (+ current 1) (length history))) (www:view-url (Id txt) (list-ref history current)))) ((reload) (www:view-url (Id txt) (list-ref history current))) (ELSE (if (null? history) (begin (set! history (list url)) (set! current 0)) (unless (string=? (list-ref history current) url) (set! history (append history (list url))) (set! current (- (length history) 1))))))))) ;;; Make interface ;;; (define (make-buttons parent txt) (let ((s (make-toolbar parent `(("tb_back.gif" "Back" ,(lambda () (new-url (Id txt) 'previous))) 2 ("tb_forward.gif" "Forward" ,(lambda () (new-url (Id txt) 'next))) 2 ("tb_reload.gif" "Reload" ,(lambda () (new-url (Id txt) 'reload))) 2 ("tb_stop.gif" "Stop Loading" ,(lambda () (set! www:stop-loading #t))) 10 ("tb_exit.gif" "Exit" ,(lambda () (destroy parent))) 0 ("tb_info.gif" "Help" ,(lambda () (STk:show-help-file "STk-hlp.html")))) :relief "ridge" :border-width 2 :release-command (default-release-toolbar txt)))) s)) (define (make-location parent txt) (let* ((s (make-toolbar parent '(0) :relief "ridge" :border-width 2 :release-command (default-release-toolbar txt))) (f (toolbar-item s 0)) (le (make :parent f :title "Location:" :font '(Courier -12)))) (pack le :fill 'x :expand #t) (bind (Id le) "" (lambda () (www:view-url (Id txt) (value le)))) ;; Keep a reference on the labeled entry for later bindings (set! lentry le) s)) (define (make-interface parent) (let* ((txt (make :parent parent :font '(Courier -12) :width 100 :height 45)) (loc (make-location parent txt)) (f (make-buttons parent txt)) (f1 (make :parent parent)) (lab (make