]> gitweb.factorcode.org Git - factor.git/commitdiff
file-picker: implement save-file-dialog on windows
authorAlexander Iljin <ajsoft@yandex.ru>
Wed, 24 May 2017 23:37:39 +0000 (02:37 +0300)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 29 May 2017 15:05:59 +0000 (08:05 -0700)
extra/file-picker/windows/windows.factor
extra/windows/comdlg32/authors.txt [new file with mode: 0644]
extra/windows/comdlg32/comdlg32.factor [new file with mode: 0644]
extra/windows/comdlg32/platforms.txt [new file with mode: 0644]

index dba941fa635be085bc0058f7f51729b43cde5d2a..ef4f8b78b438d5eb8221be417bc5bd0ad0a2304b 100644 (file)
@@ -1,8 +1,8 @@
 USING: accessors alien.c-types alien.data alien.strings
 alien.syntax classes.struct destructors file-picker
 io.encodings.string io.encodings.utf8 kernel libc literals math
-system windows windows.kernel32 windows.shell32 windows.types
-windows.user32 ;
+system windows windows.comdlg32 windows.kernel32 windows.shell32
+windows.types windows.user32 ;
 IN: file-picker.windows
 LIBRARY: shell32
 
@@ -70,4 +70,11 @@ M: windows open-file-dialog
         ] if*
     ] with-destructors ;
 
-M: windows save-file-dialog ;
+M: windows save-file-dialog
+    [
+        drop ! TODO: support supplying a suggested file name or path
+        OPENFILENAME [ malloc-struct &free ] [ heap-size ] bi >>lStructSize
+            MAX_UNICODE_PATH [ 2 calloc &free >>lpstrFile ] [ >>nMaxFile ] bi
+            OFN_OVERWRITEPROMPT >>Flags
+        dup GetSaveFileName zero? [ drop f ] [ lpstrFile>> ] if
+    ] with-destructors ;
diff --git a/extra/windows/comdlg32/authors.txt b/extra/windows/comdlg32/authors.txt
new file mode 100644 (file)
index 0000000..8e1955f
--- /dev/null
@@ -0,0 +1 @@
+Alexander Ilin
diff --git a/extra/windows/comdlg32/comdlg32.factor b/extra/windows/comdlg32/comdlg32.factor
new file mode 100644 (file)
index 0000000..4b1ba1b
--- /dev/null
@@ -0,0 +1,40 @@
+! Copyright (C) 2017 Alexander Ilin.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors alien alien.c-types alien.libraries
+alien.syntax classes.struct destructors kernel libc math
+sequences strings windows windows.types ;
+
+IN: windows.comdlg32
+
+<< "comdlg32" "comdlg32.dll" stdcall add-library >>
+
+LIBRARY: comdlg32
+
+CONSTANT: OFN_OVERWRITEPROMPT 2
+
+STRUCT: OPENFILENAME
+    { lStructSize DWORD }
+    { hwndOwner HWND }
+    { hInstance HINSTANCE }
+    { lpstrFilter LPCTSTR }
+    { lpstrCustomFilter LPTSTR }
+    { nMaxCustFilter DWORD }
+    { nFilterIndex DWORD }
+    { lpstrFile LPTSTR }
+    { nMaxFile DWORD }
+    { lpstrFileTitle LPTSTR }
+    { nMaxFileTitle DWORD }
+    { lpstrInitialDir LPCTSTR }
+    { lpstrTitle LPCTSTR }
+    { Flags DWORD }
+    { nFileOffset WORD }
+    { nFileExtension WORD }
+    { lpstrDefExt LPCTSTR }
+    { lCustData LPARAM }
+    { lpfnHook PVOID }
+    { lpTemplateName LPCTSTR } ;
+
+TYPEDEF: OPENFILENAME* LPOPENFILENAME
+
+FUNCTION: BOOL GetSaveFileNameW ( LPOPENFILENAME lpofn )
+ALIAS: GetSaveFileName GetSaveFileNameW
diff --git a/extra/windows/comdlg32/platforms.txt b/extra/windows/comdlg32/platforms.txt
new file mode 100644 (file)
index 0000000..8e1a559
--- /dev/null
@@ -0,0 +1 @@
+windows