| 1 |
;;; |
| 2 |
;;; windows.stub - windows api bridge |
| 3 |
;;; |
| 4 |
;;; Copyright (c) 2010-2024 Shiro Kawai <[email protected]> |
| 5 |
;;; |
| 6 |
;;; Redistribution and use in source and binary forms, with or without |
| 7 |
;;; modification, are permitted provided that the following conditions |
| 8 |
;;; are met: |
| 9 |
;;; |
| 10 |
;;; 1. Redistributions of source code must retain the above copyright |
| 11 |
;;; notice, this list of conditions and the following disclaimer. |
| 12 |
;;; |
| 13 |
;;; 2. Redistributions in binary form must reproduce the above copyright |
| 14 |
;;; notice, this list of conditions and the following disclaimer in the |
| 15 |
;;; documentation and/or other materials provided with the distribution. |
| 16 |
;;; |
| 17 |
;;; 3. Neither the name of the authors nor the names of its contributors |
| 18 |
;;; may be used to endorse or promote products derived from this |
| 19 |
;;; software without specific prior written permission. |
| 20 |
;;; |
| 21 |
;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 22 |
;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 23 |
;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 24 |
;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 25 |
;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 26 |
;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
| 27 |
;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 28 |
;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 29 |
;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 |
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 |
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 |
;;; |
| 33 |
|
| 34 |
(in-module os.windows) |
| 35 |
|
| 36 |
(inline-stub |
| 37 |
(.include "gauche/extend.h") |
| 38 |
(.when (defined GAUCHE_WINDOWS) |
| 39 |
|
| 40 |
;; The following bindings are provided in the core: |
| 41 |
;; <win:handle> |
| 42 |
;; sys-win-process? |
| 43 |
;; sys-win-process-pid |
| 44 |
;; sys-get-osfhandle |
| 45 |
|
| 46 |
;;==================================================================== |
| 47 |
;; Fileapi |
| 48 |
;; |
| 49 |
|
| 50 |
(define-cproc sys-get-disk-free-space-ex (path::<const-cstring>) |
| 51 |
(let* ([wpath::LPTSTR (SCM_MBS2WCS path)] |
| 52 |
[avail::ULARGE_INTEGER] |
| 53 |
[total::ULARGE_INTEGER] |
| 54 |
[tfree::ULARGE_INTEGER] |
| 55 |
[r::BOOL (GetDiskFreeSpaceEx wpath (& avail) (& total) (& tfree))]) |
| 56 |
(when (== r 0) (Scm_SysError "GetDiskFreeSpaceEx failed on path %s" path)) |
| 57 |
(return (SCM_LIST3 (Scm_OffsetToInteger (ref avail QuadPart)) |
| 58 |
(Scm_OffsetToInteger (ref total QuadPart)) |
| 59 |
(Scm_OffsetToInteger (ref tfree QuadPart)))))) |
| 60 |
|
| 61 |
;;==================================================================== |
| 62 |
;; MessageBox |
| 63 |
;; |
| 64 |
|
| 65 |
;; flags for buttons |
| 66 |
(define-enum MB_ABORTRETRYIGNORE) |
| 67 |
(define-enum MB_CANCELTRYCONTINUE) |
| 68 |
(define-enum MB_HELP) |
| 69 |
(define-enum MB_OK) |
| 70 |
(define-enum MB_OKCANCEL) |
| 71 |
(define-enum MB_RETRYCANCEL) |
| 72 |
(define-enum MB_YESNO) |
| 73 |
(define-enum MB_YESNOCANCEL) |
| 74 |
|
| 75 |
;; flags for icons |
| 76 |
(define-enum MB_ICONEXCLAMATION) |
| 77 |
(define-enum MB_ICONWARNING) |
| 78 |
(define-enum MB_ICONINFORMATION) |
| 79 |
(define-enum MB_ICONASTERISK) |
| 80 |
(define-enum MB_ICONQUESTION) |
| 81 |
(define-enum MB_ICONSTOP) |
| 82 |
(define-enum MB_ICONERROR) |
| 83 |
(define-enum MB_ICONHAND) |
| 84 |
|
| 85 |
;; flags for default button |
| 86 |
(define-enum MB_DEFBUTTON1) |
| 87 |
(define-enum MB_DEFBUTTON2) |
| 88 |
(define-enum MB_DEFBUTTON3) |
| 89 |
(define-enum MB_DEFBUTTON4) |
| 90 |
|
| 91 |
;; flags for modality |
| 92 |
(define-enum MB_APPLMODAL) |
| 93 |
(define-enum MB_SYSTEMMODAL) |
| 94 |
(define-enum MB_TASKMODAL) |
| 95 |
|
| 96 |
;; flags for other options |
| 97 |
(define-enum MB_DEFAULT_DESKTOP_ONLY) |
| 98 |
(define-enum MB_RIGHT) |
| 99 |
(define-enum MB_RTLREADING) |
| 100 |
(define-enum MB_SETFOREGROUND) |
| 101 |
(define-enum MB_TOPMOST) |
| 102 |
(define-enum MB_SERVICE_NOTIFICATION) |
| 103 |
|
| 104 |
;; return values |
| 105 |
(define-enum IDABORT) |
| 106 |
(define-enum IDCANCEL) |
| 107 |
(define-enum IDCONTINUE) |
| 108 |
(define-enum IDIGNORE) |
| 109 |
(define-enum IDNO) |
| 110 |
(define-enum IDOK) |
| 111 |
(define-enum IDRETRY) |
| 112 |
(define-enum IDTRYAGAIN) |
| 113 |
(define-enum IDYES) |
| 114 |
|
| 115 |
(define-cproc sys-message-box (window |
| 116 |
text::<const-cstring>? |
| 117 |
:optional (caption::<const-cstring>? #f) |
| 118 |
(type::<uint> 0)) |
| 119 |
::<int> |
| 120 |
(let* ([h::HANDLE NULL] |
| 121 |
[wtext::(const TCHAR*) NULL] |
| 122 |
[wcaption::(const TCHAR*) NULL] |
| 123 |
[r::int 0]) |
| 124 |
(cond [(SCM_FALSEP window) (= h NULL)] |
| 125 |
[(Scm_WinHandleP window '#f) (= h (Scm_WinHandle window '#f))] |
| 126 |
[else (SCM_TYPE_ERROR window "<win:handle> or #f")]) |
| 127 |
(when text (= wtext (SCM_MBS2WCS text))) |
| 128 |
(when caption (= wcaption (SCM_MBS2WCS caption))) |
| 129 |
(= r (MessageBox h wtext wcaption type)) |
| 130 |
(when (== r 0) (Scm_SysError "MessageBox failed")) |
| 131 |
(result r))) |
| 132 |
|
| 133 |
|
| 134 |
); defined(GAUCHE_WINDOWS) |
| 135 |
|
| 136 |
); inline-stub |
| 137 |
|
| 138 |
;; Local variables: |
| 139 |
;; mode: scheme |
| 140 |
;; end: |