Radoslav-Splice 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,145 @@
1
+ if __FILE__ == $0
2
+ require 'ffi'
3
+
4
+ require 'Constants'
5
+ require 'Types'
6
+ end
7
+
8
+ #{ macro
9
+ def LOBYTE(w); w & 0xff end
10
+ def HIBYTE(w); (w >> 8) & 0xff end
11
+ def LOWORD(l); l & 0xffff end
12
+ def HIWORD(l); (l >> 16) & 0xffff end
13
+ def MAKEWORD(a, b); (a & 0xff) | ((b & 0xff) << 8) end
14
+ def MAKELONG(a, b); (a & 0xffff) | ((b & 0xffff) << 16) end
15
+ def SUCCEEDED(hr); hr >= 0 end
16
+ def FAILED(hr); hr < 0 end
17
+ #}
18
+
19
+ module Kernel32
20
+ extend FFI::Library
21
+
22
+ ffi_lib 'kernel32'
23
+
24
+ attach_function :GetModuleHandle, :GetModuleHandleA, [:LPCTSTR], :HMODULE
25
+
26
+ #{ actctx
27
+ attach_function :CreateActCtx, :CreateActCtxA, [:pointer], :HANDLE
28
+ attach_function :ReleaseActCtx, [:HANDLE], :void
29
+ attach_function :ActivateActCtx, [:HANDLE, :pointer], :BOOL
30
+ attach_function :DeactivateActCtx, [:DWORD, :ULONG_PTR], :BOOL
31
+ #}
32
+ end
33
+
34
+ module Ole32
35
+ extend FFI::Library
36
+
37
+ ffi_lib 'ole32'
38
+
39
+ attach_function :CoInitializeEx, [:LPVOID, :DWORD], :HRESULT
40
+ attach_function :CoUninitialize, [], :void
41
+
42
+ attach_function :OleInitialize, [:LPVOID], :HRESULT
43
+ attach_function :OleUninitialize, [], :void
44
+
45
+ attach_function :CoTaskMemFree, [:LPVOID], :void
46
+ end
47
+
48
+ module User32
49
+ extend FFI::Library
50
+
51
+ ffi_lib 'user32'
52
+
53
+ #{ icon/cursor
54
+ attach_function :LoadIcon, :LoadIconA, [:HINSTANCE, :pointer], :HICON
55
+ attach_function :LoadCursor, :LoadCursorA, [:HINSTANCE, :pointer], :HCURSOR
56
+ #}
57
+
58
+ #{ window
59
+ attach_function :RegisterClassEx, :RegisterClassExA, [:pointer], :ATOM
60
+ attach_function :CreateWindowEx, :CreateWindowExA, [:DWORD, :LPCTSTR, :LPCTSTR, :DWORD, :int, :int, :int, :int, :HWND, :HMENU, :HINSTANCE, :LPVOID], :HWND
61
+ attach_function :DestroyWindow, [:HWND], :BOOL
62
+ attach_function :GetWindowLongPtr, :GetWindowLongA, [:HWND, :int], :LONG_PTR
63
+ attach_function :GetWindow, [:HWND, :UINT], :HWND
64
+ attach_function :ShowWindow, [:HWND, :int], :BOOL
65
+ attach_function :UpdateWindow, [:HWND], :BOOL
66
+ attach_function :EnableWindow, [:HWND, :BOOL], :BOOL
67
+ attach_function :SetWindowText, :SetWindowTextA, [:HWND, :LPCTSTR], :BOOL
68
+ attach_function :GetDlgItem, [:HWND, :int], :HWND
69
+ #}
70
+
71
+ #{ dialog
72
+ attach_function :MessageBox, :MessageBoxA, [:HWND, :LPCTSTR, :LPCTSTR, :UINT], :int
73
+ attach_function :DialogBoxIndirectParam, :DialogBoxIndirectParamA, [:HINSTANCE, :pointer, :HWND, :DLGPROC, :LPARAM], :INT_PTR
74
+ attach_function :EndDialog, [:HWND, :INT_PTR], :BOOL
75
+ attach_function :CreateDialogIndirectParam, :CreateDialogIndirectParamA, [:HINSTANCE, :pointer, :HWND, :DLGPROC, :LPARAM], :HWND
76
+ #}
77
+
78
+ #{ menu
79
+ attach_function :GetMenu, [:HWND], :HMENU
80
+ attach_function :SetMenu, [:HWND, :HMENU], :BOOL
81
+ attach_function :CreateMenu, [], :HMENU
82
+ attach_function :CreatePopupMenu, [], :HMENU
83
+ attach_function :AppendMenu, :AppendMenuA, [:HMENU, :UINT, :UINT_PTR, :LPCTSTR], :BOOL
84
+ attach_function :EnableMenuItem, [:HMENU, :UINT, :UINT], :BOOL
85
+ #}
86
+
87
+ #{ accelerator
88
+ attach_function :CreateAcceleratorTable, :CreateAcceleratorTableA, [:pointer, :int], :HACCEL
89
+ attach_function :DestroyAcceleratorTable, [:HACCEL], :BOOL
90
+ #}
91
+
92
+ #{ message
93
+ attach_function :GetMessage, :GetMessageA, [:pointer, :HWND, :UINT, :UINT], :BOOL
94
+ attach_function :IsDialogMessage, [:HWND, :pointer], :BOOL
95
+ attach_function :TranslateAccelerator, [:HWND, :HACCEL, :pointer], :int
96
+ attach_function :TranslateMessage, [:pointer], :BOOL
97
+ attach_function :DispatchMessage, :DispatchMessageA, [:pointer], :LRESULT
98
+ attach_function :SendMessage, :SendMessageA, [:HWND, :UINT, :WPARAM, :LPARAM], :LRESULT
99
+ attach_function :PostMessage, :PostMessageA, [:HWND, :UINT, :WPARAM, :LPARAM], :LRESULT
100
+ attach_function :PostQuitMessage, [:int], :void
101
+ attach_function :DefWindowProc, :DefWindowProcA, [:HWND, :UINT, :WPARAM, :LPARAM], :LRESULT
102
+ #}
103
+ end
104
+
105
+ module Comctl32
106
+ extend FFI::Library
107
+
108
+ ffi_lib 'comctl32'
109
+
110
+ attach_function :InitCommonControlsEx, [:pointer], :BOOL
111
+ end
112
+
113
+ module Comdlg32
114
+ extend FFI::Library
115
+
116
+ ffi_lib 'comdlg32'
117
+
118
+ attach_function :GetOpenFileName, :GetOpenFileNameA, [:pointer], :BOOL
119
+ attach_function :GetSaveFileName, :GetSaveFileNameA, [:pointer], :BOOL
120
+ end
121
+
122
+ module Shell32
123
+ extend FFI::Library
124
+
125
+ ffi_lib 'shell32'
126
+
127
+ attach_function :SHBrowseForFolder, [:pointer], :pointer
128
+ attach_function :SHGetPathFromIDList, [:pointer, :pointer], :BOOL
129
+ end
130
+
131
+ module Gdi32
132
+ extend FFI::Library
133
+
134
+ ffi_lib 'gdi32'
135
+
136
+ attach_function :GetStockObject, [:int], :HGDIOBJ
137
+ end
138
+
139
+ include Kernel32
140
+ include Ole32
141
+ include User32
142
+ include Comctl32
143
+ include Comdlg32
144
+ include Shell32
145
+ include Gdi32
@@ -0,0 +1,223 @@
1
+ if __FILE__ == $0
2
+ require 'ffi'
3
+ end
4
+
5
+ #{ char
6
+ FFI.add_typedef(:char, :CHAR)
7
+ FFI.add_typedef(:uchar, :UCHAR)
8
+ FFI.add_typedef(:UCHAR, :BYTE)
9
+ #}
10
+
11
+ #{ short
12
+ FFI.add_typedef(:short, :SHORT)
13
+ FFI.add_typedef(:ushort, :WCHAR)
14
+ FFI.add_typedef(:ushort, :USHORT)
15
+ FFI.add_typedef(:USHORT, :WORD)
16
+ FFI.add_typedef(:WORD, :ATOM)
17
+ FFI.add_typedef(:WORD, :LANGID)
18
+ #}
19
+
20
+ #{ int
21
+ FFI.add_typedef(:int, :BOOL)
22
+ FFI.add_typedef(:int, :INT)
23
+ FFI.add_typedef(:INT, :INT_PTR)
24
+ FFI.add_typedef(:uint, :UINT)
25
+ FFI.add_typedef(:UINT, :UINT_PTR)
26
+ FFI.add_typedef(:UINT_PTR, :WPARAM)
27
+ #}
28
+
29
+ #{ long
30
+ FFI.add_typedef(:long, :LONG)
31
+ FFI.add_typedef(:LONG, :LONG_PTR)
32
+ FFI.add_typedef(:LONG_PTR, :LPARAM)
33
+ FFI.add_typedef(:LONG_PTR, :LRESULT)
34
+ FFI.add_typedef(:LONG, :HRESULT)
35
+ FFI.add_typedef(:ulong, :ULONG)
36
+ FFI.add_typedef(:ULONG, :ULONG_PTR)
37
+ FFI.add_typedef(:ULONG, :DWORD)
38
+ FFI.add_typedef(:DWORD, :DWORD_PTR)
39
+ FFI.add_typedef(:DWORD, :COLORREF)
40
+ #}
41
+
42
+ #{ string
43
+ FFI.add_typedef(:string, :LPSTR)
44
+ FFI.add_typedef(:string, :LPCSTR)
45
+ FFI.add_typedef(:string, :LPTSTR)
46
+ FFI.add_typedef(:string, :LPCTSTR)
47
+ #}
48
+
49
+ #{ void
50
+ FFI.add_typedef(:void, :VOID)
51
+ #}
52
+
53
+ #{ pointer/handle
54
+ FFI.add_typedef(:pointer, :LPVOID)
55
+ FFI.add_typedef(:pointer, :HANDLE)
56
+
57
+ FFI.add_typedef(:HANDLE, :HINSTANCE)
58
+ FFI.add_typedef(:HINSTANCE, :HMODULE)
59
+ FFI.add_typedef(:HANDLE, :HWND)
60
+ FFI.add_typedef(:HANDLE, :HMENU)
61
+ FFI.add_typedef(:HANDLE, :HACCEL)
62
+
63
+ FFI.add_typedef(:HANDLE, :HICON)
64
+ FFI.add_typedef(:HICON, :HCURSOR)
65
+
66
+ FFI.add_typedef(:HANDLE, :HDC)
67
+ FFI.add_typedef(:HANDLE, :HGDIOBJ)
68
+ FFI.add_typedef(:HANDLE, :HFONT)
69
+ FFI.add_typedef(:HANDLE, :HBITMAP)
70
+ FFI.add_typedef(:HANDLE, :HBRUSH)
71
+ FFI.add_typedef(:HANDLE, :HPEN)
72
+ #}
73
+
74
+ #{ callback
75
+ FFI.add_typedef(FFI::Struct.callback([:HWND, :UINT, :WPARAM, :LPARAM], :LRESULT), :WNDPROC)
76
+ FFI.add_typedef(FFI::Struct.callback([:HWND, :UINT, :WPARAM, :LPARAM], :INT_PTR), :DLGPROC)
77
+ FFI.add_typedef(FFI::Struct.callback([:HWND, :UINT, :WPARAM, :LPARAM], :UINT_PTR), :LPOFNHOOKPROC)
78
+ FFI.add_typedef(FFI::Struct.callback([:HWND, :UINT, :LPARAM, :LPARAM], :int), :BFFCALLBACK)
79
+ #}
80
+
81
+ #{ struct
82
+ class ACTCTX < FFI::Struct
83
+ layout \
84
+ :cbSize, :ULONG,
85
+ :dwFlags, :DWORD,
86
+ :lpSource, :LPCTSTR,
87
+ :wProcessorArchitecture, :USHORT,
88
+ :wLangId, :LANGID,
89
+ :lpAssemblyDirectory, :LPCTSTR,
90
+ :lpResourceName, :LPCTSTR,
91
+ :lpApplicationName, :LPCTSTR,
92
+ :hModule, :HMODULE
93
+ end
94
+
95
+ class WNDCLASSEX < FFI::Struct
96
+ layout \
97
+ :cbSize, :UINT,
98
+ :style, :UINT,
99
+ :lpfnWndProc, :WNDPROC,
100
+ :cbClsExtra, :int,
101
+ :cbWndExtra, :int,
102
+ :hInstance, :HINSTANCE,
103
+ :hIcon, :HICON,
104
+ :hCursor, :HCURSOR,
105
+ :hbrBackground, :HBRUSH,
106
+ :lpszMenuName, :LPCTSTR,
107
+ :lpszClassName, :LPCTSTR,
108
+ :hIconSm, :HICON
109
+ end
110
+
111
+ class CREATESTRUCT < FFI::Struct
112
+ layout \
113
+ :lpCreateParams, :LPVOID,
114
+ :hInstance, :HINSTANCE,
115
+ :hMenu, :HMENU,
116
+ :hwndParent, :HWND,
117
+ :cy, :int,
118
+ :cx, :int,
119
+ :y, :int,
120
+ :x, :int,
121
+ :style, :LONG,
122
+ :lpszName, :LPCTSTR,
123
+ :lpszClass, :LPCTSTR,
124
+ :dwExStyle, :DWORD
125
+ end
126
+
127
+ class DLGTEMPLATEEX < FFI::Struct
128
+ layout \
129
+ :dlgVer, :WORD,
130
+ :signature, :WORD,
131
+ :helpID, :DWORD,
132
+ :exStyle, :DWORD,
133
+ :style, :DWORD,
134
+ :cDlgItems, :WORD,
135
+ :x, :short,
136
+ :y, :short,
137
+ :cx, :short,
138
+ :cy, :short,
139
+ :menu, :WCHAR,
140
+ :windowClass, :WCHAR,
141
+ :title, :WCHAR,
142
+ :pointsize, :short,
143
+ :weight, :short,
144
+ :bItalic, :short,
145
+ :font, :WCHAR
146
+ end
147
+
148
+ class ACCEL < FFI::Struct
149
+ layout \
150
+ :fVirt, :BYTE,
151
+ :key, :WORD,
152
+ :cmd, :WORD
153
+ end
154
+
155
+ class POINT < FFI::Struct
156
+ layout \
157
+ :x, :LONG,
158
+ :y, :LONG
159
+ end
160
+
161
+ class RECT < FFI::Struct
162
+ layout \
163
+ :left, :LONG,
164
+ :top, :LONG,
165
+ :right, :LONG,
166
+ :bottom, :LONG
167
+ end
168
+
169
+ class MSG < FFI::Struct
170
+ layout \
171
+ :hwnd, :HWND,
172
+ :message, :UINT,
173
+ :wParam, :WPARAM,
174
+ :lParam, :LPARAM,
175
+ :time, :DWORD,
176
+ :pt, POINT
177
+ end
178
+
179
+ class INITCOMMONCONTROLSEX < FFI::Struct
180
+ layout \
181
+ :dwSize, :DWORD,
182
+ :dwICC, :DWORD
183
+ end
184
+
185
+ class OPENFILENAME < FFI::Struct
186
+ layout \
187
+ :lStructSize, :DWORD,
188
+ :hwndOwner, :HWND,
189
+ :hInstance, :HINSTANCE,
190
+ :lpstrFilter, :LPCTSTR,
191
+ :lpstrCustomFilter, :LPTSTR,
192
+ :nMaxCustFilter, :DWORD,
193
+ :nFilterIndex, :DWORD,
194
+ :lpstrFile, :LPTSTR,
195
+ :nMaxFile, :DWORD,
196
+ :lpstrFileTitle, :LPTSTR,
197
+ :nMaxFileTitle, :DWORD,
198
+ :lpstrInitialDir, :LPCTSTR,
199
+ :lpstrTitle, :LPCTSTR,
200
+ :Flags, :DWORD,
201
+ :nFileOffset, :WORD,
202
+ :nFileExtension, :WORD,
203
+ :lpstrDefExt, :LPCTSTR,
204
+ :lCustData, :LPARAM,
205
+ :lpfnHook, :LPOFNHOOKPROC,
206
+ :lpTemplateName, :LPCTSTR,
207
+ :pvReserved, :LPVOID,
208
+ :dwReserved, :DWORD,
209
+ :FlagsEx, :DWORD
210
+ end
211
+
212
+ class BROWSEINFO < FFI::Struct
213
+ layout \
214
+ :hwndOwner, :HWND,
215
+ :pidlRoot, :pointer,
216
+ :pszDisplayName, :LPTSTR,
217
+ :lpszTitle, :LPCTSTR,
218
+ :ulFlags, :UINT,
219
+ :lpfn, :BFFCALLBACK,
220
+ :lParam, :LPARAM,
221
+ :iImage, :int
222
+ end
223
+ #}
@@ -0,0 +1,75 @@
1
+ if __FILE__ == $0
2
+ require 'ffi'
3
+
4
+ require 'WinAPI/Constants'
5
+ require 'WinAPI/Types'
6
+ require 'WinAPI/Functions'
7
+
8
+ require 'Application'
9
+ end
10
+
11
+ module Splice
12
+ class Window
13
+ @@className = 'SpliceWindow'
14
+ @@classAtom = nil
15
+ @@handlers = {}
16
+
17
+ def self.onDestroy(hwnd)
18
+ PostQuitMessage(0); 0
19
+ end
20
+
21
+ def self.windowProc(hwnd, uMsg, wParam, lParam)
22
+ return @@handlers[uMsg].call(hwnd, wParam, lParam) if @@handlers.include?(uMsg)
23
+
24
+ case uMsg
25
+ when WM_DESTROY
26
+ return onDestroy(hwnd)
27
+ end
28
+
29
+ DefWindowProc(hwnd, uMsg, wParam, lParam)
30
+ end
31
+
32
+ def self.on(msg, &block)
33
+ msg = const_get("WM_#{msg.to_s.upcase}") if msg.instance_of?(Symbol)
34
+
35
+ @@handlers[msg] = block
36
+
37
+ self
38
+ end
39
+
40
+ def self.registerClass
41
+ cls = WNDCLASSEX.new
42
+
43
+ cls.to_ptr.put_uint(cls.offset_of(:cbSize), cls.size)
44
+ cls.to_ptr.put_uint(cls.offset_of(:style), 0)
45
+ cls.to_ptr.put_callback(cls.offset_of(:lpfnWndProc), method(:windowProc), FFI.find_type(:WNDPROC))
46
+ cls.to_ptr.put_int(cls.offset_of(:cbClsExtra), 0)
47
+ cls.to_ptr.put_int(cls.offset_of(:cbWndExtra), 0)
48
+ cls.to_ptr.put_pointer(cls.offset_of(:hInstance), GetModuleHandle(nil))
49
+ cls.to_ptr.put_pointer(cls.offset_of(:hIcon), LoadIcon(nil, FFI::Pointer.new(IDI_APPLICATION)))
50
+ cls.to_ptr.put_pointer(cls.offset_of(:hCursor), LoadCursor(nil, FFI::Pointer.new(IDC_ARROW)))
51
+ cls.to_ptr.put_pointer(cls.offset_of(:hbrBackground), FFI::Pointer.new(COLOR_WINDOW + 1))
52
+ cls.to_ptr.put_pointer(cls.offset_of(:lpszMenuName), nil)
53
+ cls.to_ptr.put_pointer(cls.offset_of(:lpszClassName), FFI::MemoryPointer.from_string(@@className))
54
+ cls.to_ptr.put_pointer(cls.offset_of(:hIconSm), nil)
55
+
56
+ raise 'RegisterClassEx failed!' if (atom = RegisterClassEx(cls.to_ptr)) == 0
57
+
58
+ @@classAtom = atom
59
+ end
60
+
61
+ def initialize
62
+ self.class.registerClass unless @@classAtom
63
+
64
+ @hwnd = CreateWindowEx(
65
+ 0, @@className, 'Splice', WS_OVERLAPPEDWINDOW | WS_VISIBLE,
66
+ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
67
+ nil, nil, GetModuleHandle(nil), nil
68
+ )
69
+
70
+ raise 'CreateWindowEx failed!' unless @hwnd
71
+ end
72
+
73
+ attr_reader :hwnd
74
+ end
75
+ end
@@ -0,0 +1,10 @@
1
+ require 'ffi'
2
+
3
+ require 'Lib/WinAPI/Constants'
4
+ require 'Lib/WinAPI/Types'
5
+ require 'Lib/WinAPI/Functions'
6
+
7
+ require 'Lib/Window'
8
+ require 'Lib/CommonControls'
9
+ require 'Lib/CommonDialogs'
10
+ require 'Lib/Application'