webview

Check-in [f19371823b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improved dialog interface, injection code
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f19371823b877ee2b45a27739bc5015d79603e60f732fca2d3b7d3e694ebda75
User & Date: murphy 2018-09-01 04:23:22
Context
2018-09-01
13:06
Silly fortune database example check-in: 0f7cbfc3e6 user: murphy tags: trunk
04:23
Improved dialog interface, injection code check-in: f19371823b user: murphy tags: trunk
01:49
Fragment rendering for write-html check-in: 78dabae49f user: murphy tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to main.scm.

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

143
144
145
146
147


148
149

150
151
152


153

154
155
156




157
158
159


160
161

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
(define (webview-inject view id html)
  (webview-eval
   view
   (call-with-output-string
    (lambda (port)
      (display "document.getElementById(" port)
      (write-js id port)
      (display ").innerHTML = " port)
      (write-js
       (call-with-output-string (cut write-html html <>))
       port)
      (display ";" port)))))

(define (webview-dialog view title #!optional value #!rest type)
  (let ([type

         (cond
           [(memq #:open type)
            (foreign-value "WEBVIEW_DIALOG_TYPE_OPEN" int)]
           [(memq #:save type)
            (foreign-value "WEBVIEW_DIALOG_TYPE_SAVE" int)]


           [else
            (foreign-value "WEBVIEW_DIALOG_TYPE_ALERT" int)])]

        [flags
         (bitwise-ior
           (if (memq #:directory type)


             (foreign-value "WEBVIEW_DIALOG_FLAG_DIRECTORY" int)

             (foreign-value "WEBVIEW_DIALOG_FLAG_FILE" int))
           (cond
             [(memq #:error type)




              (foreign-value "WEBVIEW_DIALOG_FLAG_ERROR" int)]
             [(memq #:warning type)
              (foreign-value "WEBVIEW_DIALOG_FLAG_WARNING" int)]


             [else
              (foreign-value "WEBVIEW_DIALOG_FLAG_INFO" int)]))]

        [buf
         (make-string 4096 #\nul)])
    ((foreign-safe-lambda
      void "webview_dialog"
      nonnull-webview int int nonnull-c-string c-string
      scheme-pointer size_t)
     view type flags title value
     buf (string-length buf))
    (let scan ([pos 0])
      (if (or (fx>= pos (string-length buf))
              (eqv? (string-ref buf pos) #\nul))
        (and (fx> pos 0) (substring buf 0 (fx- pos 1)))
        (scan (fx+ pos 1))))))

(define webview-log
  (foreign-lambda
   void "webview_print_log"
   nonnull-c-string))

;; vim: set ai et ts=4 sts=2 sw=2 ft=scheme: ;;







|


|
<

|

>
|
<

|

>
>

<
>


<
>
>
|
>
|
<
<
>
>
>
>
|
|

>
>

<
>











|








128
129
130
131
132
133
134
135
136
137
138

139
140
141
142
143

144
145
146
147
148
149

150
151
152

153
154
155
156
157


158
159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
(define (webview-inject view id html)
  (webview-eval
   view
   (call-with-output-string
    (lambda (port)
      (display "document.getElementById(" port)
      (write-js id port)
      (display ").innerHTML=" port)
      (write-js
       (call-with-output-string (cut write-html html <>))
       port)))))


(define (webview-dialog view title type #!optional value)
  (let ([type
         (case type
           [(#:open #:open-directory)

            (foreign-value "WEBVIEW_DIALOG_TYPE_OPEN" int)]
           [(#:save)
            (foreign-value "WEBVIEW_DIALOG_TYPE_SAVE" int)]
           [(#:info #:warning #:error)
            (foreign-value "WEBVIEW_DIALOG_TYPE_ALERT" int)]
           [else

            (error 'webview-dialog "unknown dialog type" type)])]
        [flags
         (bitwise-ior

           (case type
             [(#:open #:save)
              (foreign-value "WEBVIEW_DIALOG_FLAG_FILE" int)]
             [(#:open-directory)
              (foreign-value "WEBVIEW_DIALOG_FLAG_DIRECTORY" int)]


             [else
              0])
           (case type
             [(#:info)
              (foreign-value "WEBVIEW_DIALOG_FLAG_INFO" int)]
             [(#:warning)
              (foreign-value "WEBVIEW_DIALOG_FLAG_WARNING" int)]
             [(#:error)
              (foreign-value "WEBVIEW_DIALOG_FLAG_ERROR" int)]
             [else

              0]))]
        [buf
         (make-string 4096 #\nul)])
    ((foreign-safe-lambda
      void "webview_dialog"
      nonnull-webview int int nonnull-c-string c-string
      scheme-pointer size_t)
     view type flags title value
     buf (string-length buf))
    (let scan ([pos 0])
      (if (or (fx>= pos (string-length buf))
              (eqv? (string-ref buf pos) #\nul))
        (and (fx> pos 0) (substring buf 0 pos))
        (scan (fx+ pos 1))))))

(define webview-log
  (foreign-lambda
   void "webview_print_log"
   nonnull-c-string))

;; vim: set ai et ts=4 sts=2 sw=2 ft=scheme: ;;

Changes to webview.wiki.

85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

105
106
107
108
109

110
111
112
113
114
115
116

<tt>HTML</tt> content is specified in the form accepted by
<tt>write-html</tt>.

<h2>Dialogs</h2>

<h3><tt><nowiki>
  (webview-dialog WEBVIEW TITLE [VALUE] [#:open | #:save | #:error | #:warning] [#:directory]) ⇒ VALUE
</nowiki></tt></h3>

Shows a modal dialog with the given <tt>TITLE</tt> in the context of the
given <tt>WEBVIEW</tt>.

If the <tt>#:open</tt> or <tt>#:save</tt> flags are given, a file
selection dialog is shown and <tt>VALUE</tt> may be the path to a file
that will be pre-selected. The <tt>#:directory</tt> flag indicates that
directories rather than regular files should be selected. The procedure
will return the path to a selected file or <tt>#f</tt> in case the
dialog is cancelled.


Otherwise, a message dialog is shown and the <tt>#:error</tt> or
<tt>#:warning</tt> flags may be used to switch from an information icon
to a different look. In this case, <tt>VALUE</tt> is the message to
display in the dialog and the procedure will not return a meaningful
result.


The running operating system thread will be blocked until the dialog is
dismissed.

<h2>Logging</h2>

<h3><tt><nowiki>







|





|
|
|
|
|
|

>
|
<
<
|
<
>







85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106


107

108
109
110
111
112
113
114
115

<tt>HTML</tt> content is specified in the form accepted by
<tt>write-html</tt>.

<h2>Dialogs</h2>

<h3><tt><nowiki>
  (webview-dialog WEBVIEW TITLE TYPE [VALUE]) ⇒ VALUE
</nowiki></tt></h3>

Shows a modal dialog with the given <tt>TITLE</tt> in the context of the
given <tt>WEBVIEW</tt>.

If <tt>TYPE</tt> is <tt>#:open</tt> or <tt>#:save</tt>, a file selection
dialog is shown and <tt>VALUE</tt> may be the path to a file that will
be pre-selected. If <tt>TYPE</tt> is <tt>#:open-directory</tt>, the
dialog allows the selection of directories rather than regular files.
The procedure will return the path to a selected file or <tt>#f</tt> in
case the dialog is cancelled.

If <tt>TYPE</tt> is <tt>#:info</tt>, <tt>#:warning</tt> or
<tt>#:error</tt>, a message dialog is shown and <tt>VALUE</tt> is the


message to display in the dialog. The procedure will not return a

meaningful result in this case.

The running operating system thread will be blocked until the dialog is
dismissed.

<h2>Logging</h2>

<h3><tt><nowiki>