-
Notifications
You must be signed in to change notification settings - Fork 3
/
RCIncludes.asm
319 lines (290 loc) · 8.13 KB
/
RCIncludes.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
INCLUDEMEM STRUCT
szfile DB MAX_PATH DUP(?)
INCLUDEMEM ENDS
.DATA?
hBrowseButton HWND ?
lpPrevBrowseProc DWORD ?
bIncludesModified DWORD ?
.CODE
ParseFileName Proc Uses ESI EDI lpRCMem:DWORD
Local nend :BYTE
MOV ESI,lpRCMem
MOV EDI,Offset ThisWord
CALL SkipSpace
XOR ECX,ECX
.While TRUE
MOV AL,[ESI+ECX]
.If AL==VK_RETURN
XOR AL,AL
.EndIf
MOV [EDI+ECX],AL
INC ECX
.Break .If !AL
.EndW
LEA ESI,[ESI+ECX-1]
PUSH ESI
MOV ESI,Offset ThisWord
MOV EDI,ESI
MOV AL,[ESI]
.If AL=='"'
MOV nend,AL
INC ESI
.ElseIf AL=='<'
MOV nend,'>'
INC ESI
.Else
MOV nend,' '
.EndIf
.While BYTE PTR [ESI]
MOV AL,[ESI]
.If AL==nend
XOR AL,AL
.ElseIf AL=='\'
.If BYTE PTR [ESI+1]=='\'
INC ESI
.EndIf
; .ElseIf AL=='/'
; MOV AL,'\'
.EndIf
MOV [EDI],AL
INC ESI
INC EDI
.EndW
POP ESI
MOV EAX,ESI
SUB EAX,lpRCMem
RET
ParseFileName EndP
ParseInclude Proc Uses ESI EDI lpRCMem:DWORD,lpProMem:DWORD
MOV ESI,lpRCMem
.If !lpIncludesMem
Invoke HeapAlloc,hMainHeap,HEAP_ZERO_MEMORY,64*1024
MOV lpIncludesMem,EAX
.EndIf
MOV EDI,lpIncludesMem
PUSH EDI
.While [EDI].INCLUDEMEM.szfile
ADD EDI,SizeOf INCLUDEMEM
.EndW
Invoke ParseFileName,ESI
ADD ESI,EAX
Invoke lstrcpy,ADDR [EDI].INCLUDEMEM.szfile,Offset ThisWord
POP EDI
.If !hIncludesParentItem
Invoke AddToOthersTree,2,Offset szIncFiles,EDI
MOV hIncludesParentItem,EAX
.EndIf
MOV EAX,ESI
SUB EAX,lpRCMem
RET
ParseInclude EndP
BrowseButtonProc Proc Uses EBX hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
Local Buffer[256] :BYTE
Local Buffer2[256] :BYTE
Local lvi :LVITEM
.If uMsg==WM_LBUTTONUP
Invoke BrowseForFile,hWnd,Offset AllFilesFilter,0,ADDR Buffer
.If EAX
;------------------------------------
Invoke GetWindowLong,hRCEditorWindow,0
LEA ECX,CHILDWINDOWDATA.szFileName[EAX]
Invoke GetFilePath,ECX,ADDR Buffer2
MOV EBX,EAX
MOV CL,Buffer[EBX+1]
MOV Buffer[EBX+1],0
PUSH ECX
Invoke lstrcmpi,ADDR Buffer,ADDR Buffer2
POP ECX
MOV Buffer[EBX+1],CL
.If !EAX
LEA ECX,Buffer
ADD EBX,ECX
INC EBX
.Else
LEA EBX,Buffer
ADD EBX,2
.EndIf
;------------------------------------
Invoke GetParent,hWnd
PUSH EAX
Invoke SendMessage,EAX,LVM_GETNEXTITEM,-1,LVNI_ALL or LVNI_SELECTED
MOV lvi.iItem,EAX
MOV lvi.imask,LVIF_TEXT or LVIF_STATE
MOV lvi.cchTextMax,256
MOV lvi.iSubItem, 0
MOV lvi.state,LVIS_SELECTED
;LEA EAX,Buffer
MOV lvi.pszText,EBX
POP ECX
MOV EBX,ECX
Invoke SendMessage,ECX,LVM_SETITEM,0,ADDR lvi
Invoke SetFocus,EBX
MOV bIncludesModified,TRUE
.EndIf
.EndIf
Invoke CallWindowProc,lpPrevBrowseProc,hWnd,uMsg,wParam,lParam
RET
BrowseButtonProc EndP
IncludesDialogProc Proc Uses EBX EDI ESI hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
Local lvc :LV_COLUMN
Local lvi :LVITEM
Local hList :DWORD
Local Rect :RECT
Local Buffer[256] :BYTE
;PrintHex uMsg
.If uMsg == WM_INITDIALOG
MOV bIncludesModified,FALSE
Invoke GetDlgItem,hWnd,1 ;Get List handle
MOV EBX,EAX
Invoke SendMessage,EBX,LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_GRIDLINES OR LVS_EX_FULLROWSELECT
Invoke CreateWindowEx,NULL,ADDR szButton,Offset szTwoDots,WS_CHILD or WS_VISIBLE + WS_CLIPSIBLINGS,0,0,0,0,EBX,100,hInstance,NULL
MOV hBrowseButton,EAX
Invoke SetWindowLong,EAX,GWL_WNDPROC,Offset BrowseButtonProc
MOV lpPrevBrowseProc,EAX
MOV lvc.imask, LVCF_TEXT OR LVCF_WIDTH OR LVCF_FMT
MOV lvc.fmt,LVCFMT_LEFT
MOV lvc.cchTextMax,MAX_PATH
MOV lvc.pszText,Offset szIncFiles;szIncludeFiles
MOV lvc.lx,315
Invoke SendMessage, EBX, LVM_INSERTCOLUMN, 0, addr lvc
.If lpIncludesMem
MOV EDI,lpIncludesMem
MOV lvi.imask,LVIF_TEXT or LVIF_STATE
MOV lvi.cchTextMax,256
MOV lvi.iSubItem, 0
MOV lvi.state,LVIS_SELECTED
XOR ESI,ESI
.While [EDI].INCLUDEMEM.szfile
MOV lvi.iItem,ESI
LEA EAX,[EDI].INCLUDEMEM.szfile
MOV lvi.pszText,EAX
Invoke SendMessage,EBX,LVM_INSERTITEM,0,ADDR lvi
ADD EDI,SizeOf INCLUDEMEM
INC ESI
.EndW
.EndIf
.ElseIf uMsg == WM_COMMAND
MOV EAX,wParam
MOV EDX,EAX
SHR EDX,16
AND EAX,0FFFFh
.If EDX==BN_CLICKED
.If EAX==2 ;OK
.If bIncludesModified
Invoke SetRCModified,TRUE
.EndIf
.If lpIncludesMem
Invoke RtlZeroMemory,lpIncludesMem,64*1024
.EndIf
Invoke GetDlgItem,hWnd,1
MOV hList,EAX
Invoke SendMessage,hList,LVM_GETITEMCOUNT,0,0
.If EAX
MOV EBX,EAX
.If !lpIncludesMem
Invoke HeapAlloc,hMainHeap,HEAP_ZERO_MEMORY,64*1024
MOV lpIncludesMem,EAX
.EndIf
MOV EDI,lpIncludesMem
XOR ESI,ESI
.While ESI<EBX
Invoke GetItemText,hList,ESI,0,ADDR Buffer
LEA ECX,Buffer
.If BYTE PTR [ECX]!=0
Invoke lstrcpy,ADDR [EDI].INCLUDEMEM.szfile,ADDR Buffer
ADD EDI,SizeOf INCLUDEMEM
.EndIf
INC ESI
.EndW
.EndIf
.If !hIncludesParentItem && lpIncludesMem
Invoke AddToOthersTree,2,Offset szIncFiles,lpIncludesMem
MOV hIncludesParentItem,EAX
.EndIf
Invoke SendMessage,hWnd,WM_CLOSE,NULL,NULL
.ElseIf EAX== 3 ;Cancel
Invoke SendMessage,hWnd,WM_CLOSE,NULL,NULL
.ElseIf EAX==4 ;Add
MOV bIncludesModified,TRUE
Invoke GetDlgItem,hWnd,1
MOV hList,EAX
Invoke SendMessage,hList,LVM_GETITEMCOUNT,0,0
MOV lvi.imask,LVIF_TEXT or LVIF_STATE
MOV lvi.cchTextMax,256
MOV lvi.iSubItem, 0
MOV lvi.iItem,EAX
MOV lvi.pszText,Offset szNULL
MOV lvi.state,LVIS_SELECTED; or LVIS_FOCUSED
Invoke SendMessage,hList,LVM_INSERTITEM,0,ADDR lvi
Invoke SendMessage,hList,LVM_ENSUREVISIBLE,EAX,FALSE
Invoke SetFocus,hList
;So that Browse for file dialog is displayed automatically
Invoke SendMessage,hBrowseButton,WM_LBUTTONUP,0,0
.ElseIf EAX==5 ;Delete
Invoke GetDlgItem,hWnd,1
MOV hList,EAX
Invoke SendMessage,hList,LVM_GETNEXTITEM,-1,LVNI_ALL or LVNI_SELECTED
.If EAX!=-1
MOV bIncludesModified,TRUE
MOV lvi.iItem,EAX
.If lvi.iItem
DEC lvi.iItem ;Because after deleting selection, we will select the previous one
.EndIf
Invoke SendMessage,hList,LVM_DELETEITEM,EAX,0
MOV lvi.imask,LVIF_STATE
MOV lvi.iSubItem, 0
MOV lvi.state,LVIS_SELECTED
MOV lvi.stateMask,LVIS_SELECTED
Invoke SendMessage,hList,LVM_SETITEM,0,ADDR lvi
Invoke SendMessage,hList,LVM_GETITEMCOUNT,0,0
.If !EAX
Invoke MoveWindow,hBrowseButton,0,0,0,0,TRUE
.EndIf
Invoke SendMessage,hList,LVM_ENSUREVISIBLE,lvi.iItem,FALSE
Invoke UpdateWindow,hList
Invoke SetFocus,hList
.EndIf
.EndIf
.EndIf
.ElseIf uMsg == WM_NOTIFY
MOV EDI,lParam
Invoke GetDlgItem,hWnd,1
MOV hList,EAX
MOV ECX, [EDI].NMHDR.hwndFrom
.If ECX==hList
.If [EDI].NMHDR.code == LVN_ITEMCHANGED || [EDI].NMHDR.code==0FFFFFFF4h
;hBrowseButton
.If [EDI].NMHDR.code == LVN_ITEMCHANGED
MOV ECX,[EDI].NM_LISTVIEW.iItem
.Else
Invoke SendMessage,hList,LVM_GETNEXTITEM,-1,LVNI_ALL or LVNI_SELECTED
MOV ECX,EAX
.EndIf
MOV Rect.left,LVIR_LABEL
Invoke SendMessage,hList,LVM_GETITEMRECT,ECX,ADDR Rect
MOV EAX,Rect.bottom
SUB EAX,Rect.top
MOV ECX,Rect.right
SUB ECX,EAX
;Invoke MoveWindow,hBrowseButton,ECX,Rect.top,EAX,EAX,TRUE
Invoke SetWindowPos,hBrowseButton,HWND_BOTTOM,ECX,Rect.top,EAX,EAX,SWP_SHOWWINDOW
Invoke UpdateWindow,hList
.ElseIf [EDI].NMHDR.code ==LVN_KEYDOWN
;MOV EAX,lParam
.If [EDI].LV_KEYDOWN.wVKey==VK_DELETE ;simulate delete button
Invoke SendMessage,hWnd,WM_COMMAND, (BN_CLICKED SHL 16) OR 5,0
.EndIf
.ElseIf [EDI].NMHDR.code==NM_DBLCLK ;Simulate Browse button
Invoke SendMessage,hList,LVM_GETNEXTITEM,-1,LVNI_ALL or LVNI_SELECTED
.If EAX!=-1
Invoke PostMessage,hBrowseButton,WM_LBUTTONUP,0,0
.EndIf
.EndIf
.EndIf
.ElseIf uMsg == WM_CLOSE
Invoke EnableAllDockWindows,TRUE
Invoke EndDialog,hWnd,NULL
.EndIf
MOV EAX,FALSE
RET
IncludesDialogProc EndP