forked from zha0/pdfstreamdumper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmFuncGraph.frm
414 lines (346 loc) · 10.8 KB
/
frmFuncGraph.frm
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
VERSION 5.00
Begin VB.Form frmFuncGraph
Caption = "Function Graph"
ClientHeight = 5580
ClientLeft = 60
ClientTop = 345
ClientWidth = 7020
LinkTopic = "Form3"
ScaleHeight = 5580
ScaleWidth = 7020
StartUpPosition = 2 'CenterScreen
Begin VB.CheckBox Check1
Caption = "Top Most"
Height = 285
Left = 5490
TabIndex = 7
Top = 90
Width = 1140
End
Begin VB.CommandButton cmdSource
Caption = "View Source"
Height = 375
Left = 1395
TabIndex = 6
Top = 45
Width = 1545
End
Begin VB.HScrollBar HScroll1
Height = 255
Left = 90
Max = 100
TabIndex = 4
Top = 5130
Width = 6540
End
Begin VB.VScrollBar VScroll1
Height = 4710
Left = 6660
Max = 100
TabIndex = 3
Top = 450
Width = 255
End
Begin VB.CommandButton Command2
Caption = "Save Image"
Height = 375
Left = 3600
TabIndex = 1
Top = 45
Width = 1455
End
Begin VB.PictureBox pictParent
BackColor = &H00FFFFFF&
Height = 4605
Left = 90
ScaleHeight = 4545
ScaleWidth = 6435
TabIndex = 0
Top = 495
Width = 6495
Begin VB.TextBox Text1
BeginProperty Font
Name = "Courier"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 2040
Left = 315
MultiLine = -1 'True
TabIndex = 2
Text = "frmFuncGraph.frx":0000
Top = 315
Width = 4110
End
Begin VB.PictureBox Picture1
AutoSize = -1 'True
Height = 1725
Left = 1305
ScaleHeight = 1665
ScaleWidth = 1620
TabIndex = 5
Top = 2520
Width = 1680
End
End
End
Attribute VB_Name = "frmFuncGraph"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim img As BinaryImage
Dim pGraph As CGraph
Dim loaded As Boolean
Dim dlg As New clsCmnDlg2
Dim defName As String
Private Declare Sub SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Sub SetWindowTopMost(f As Form, Optional topMost As Integer = 0)
SetWindowPos f.hwnd, _
IIf(topMost = 0, HWND_NOTOPMOST, HWND_TOPMOST), _
f.left / 15, f.Top / 15, f.Width / 15, f.height / 15, Empty
End Sub
'note using instr funcName as only indication of function being called withint another is not
'enough to be safe (func1, func11 etc) this should help...
Function Basic_Safetify(ByVal data As String) As String
data = Replace(data, vbLf, vbLf & " ")
data = Replace(data, "(", "( ") 'func11(func1(
data = Replace(data, "{", "{ ")
data = Replace(data, "[", "[ ")
data = Replace(data, "!", "! ")
data = Replace(data, "this.", " ")
data = Replace(data, vbTab, " ")
Basic_Safetify = data
End Function
Private Sub Check1_Click()
SetWindowTopMost Me, Check1.value
SaveMySetting "graphTopMost", Check1.value
End Sub
Private Sub cmdSource_Click()
If InStr(cmdSource.Caption, "View") > 0 Then
Text1.Visible = True
cmdSource.Caption = "Hide Source"
Else
Text1.Visible = False
cmdSource.Caption = "View Source"
End If
End Sub
Private Sub Command2_Click()
If img Is Nothing Then Exit Sub
Dim pth As String
pth = dlg.SaveDialog(AllFiles, , , , Me.hwnd, defName)
If Len(pth) = 0 Then Exit Sub
If img.Save(pth) Then
MsgBox "Saved to " & pth, vbInformation
Else
MsgBox "Save failed", vbExclamation
End If
'or SavePicture Picture1, App.Path & "\sample.bmp"
End Sub
Function GraphFrom(startfunc As String, Optional pNode As CNode)
'On Error Resume Next
Dim li As ListItem
Dim data As String
Dim foundEnd As Boolean
Dim func() As String
Dim n As CNode
Dim existingNode As CNode
Dim startLine As Long
Dim topLevel As Boolean
'If startfunc = "fix_it" Then Stop
If pNode Is Nothing Then 'top level call..
Me.Caption = Me.Caption & " from " & startfunc
End If
If Not loaded Then Form_Load
If pGraph Is Nothing Then Set pGraph = New CGraph
If pNode Is Nothing Then
defName = "from_" & startfunc & ".gif"
Set pNode = pGraph.AddNode(startfunc)
topLevel = True
End If
For Each li In Form2.lvFunc.ListItems
If li.Text = startfunc Then
startLine = CLng(li.tag)
Exit For
End If
Next
data = Form2.ExtractFunction(startLine, foundEnd)
'now we trim off the function xx(){ part..
a = InStr(data, "{")
If a > 0 Then data = Mid(data, a)
data = Basic_Safetify(data)
For Each li In Form2.lvFunc.ListItems
'If InStr(data, " " & li.Text & "(") > 0 Then
If InStr(data, li.Text & "(") > 0 Then
Set existingNode = pGraph.NodeExists(li.Text)
If Not existingNode Is Nothing Then
pNode.ConnectTo existingNode
Else
Set n = pGraph.AddNode(li.Text)
pNode.ConnectTo n
GraphFrom li.Text, n
End If
End If
Next
If Not topLevel Then Exit Function
pGraph.GenerateGraph
Set img = pGraph.dot.ToGIF(pGraph.lastGraph)
If img Is Nothing Then
Text1.Visible = True
Text1.Text = "Graph generation failed?" & vbCrLf & vbCrLf & pGraph.lastGraph
Else
Text1.Text = pGraph.lastGraph
Set Picture1.Picture = img.Picture
If Picture1.Width < pictParent.Width Then HScroll1.value = 50
End If
End Function
Function GraphTo(startfunc As String, Optional pNode As CNode)
'On Error Resume Next
Dim li As ListItem
Dim data As String
Dim foundEnd As Boolean
Dim func() As String
Dim n As CNode
Dim existingNode As CNode
Dim startLine As Long
Dim topLevel As Boolean
If Not loaded Then Form_Load
If pGraph Is Nothing Then Set pGraph = New CGraph
If pNode Is Nothing Then 'top level call..
Me.Caption = Me.Caption & " to " & startfunc
End If
If pNode Is Nothing Then
defName = "to_" & startfunc & ".gif"
Set pNode = pGraph.AddNode(startfunc)
topLevel = True
End If
For Each li In Form2.lvFunc.ListItems
If li.Text <> startfunc Then
startLine = CLng(li.tag)
data = Form2.ExtractFunction(startLine, foundEnd)
'now we trim off the function xx(){ part..
a = InStr(data, "{")
If a > 0 Then data = Mid(data, a)
data = Basic_Safetify(data)
'If InStr(data, " " & startfunc & "(") > 0 Then
If InStr(data, startfunc & "(") > 0 Then
Set existingNode = pGraph.NodeExists(li.Text)
If Not existingNode Is Nothing Then
existingNode.ConnectTo pNode
Else
Set n = pGraph.AddNode(li.Text)
n.ConnectTo pNode
GraphTo li.Text, n
End If
End If
End If
Next
If Not topLevel Then Exit Function
pGraph.GenerateGraph
Set img = pGraph.dot.ToGIF(pGraph.lastGraph)
If img Is Nothing Then
Text1.Visible = True
Text1.Text = "Graph generation failed?" & vbCrLf & vbCrLf & pGraph.lastGraph
Else
Text1.Text = pGraph.lastGraph
Set Picture1.Picture = img.Picture
If Picture1.Width < pictParent.Width Then HScroll1.value = 50
End If
End Function
Private Sub Form_Load()
Picture1.Appearance = 0
Text1.Visible = False
With pictParent
Text1.Move 0, 0, .Width, .height
Picture1.Move 0, 0, .Width, .height
End With
Me.Visible = True
loaded = True
Check1.value = GetMySetting("graphTopMost", 1)
End Sub
Private Sub Form_Resize()
On Error Resume Next
With pictParent
VScroll1.left = Me.Width - VScroll1.Width - 100
.Width = Me.Width - .left - VScroll1.Width - 100
.height = Me.height - .Top - 200 - HScroll1.height - 250
VScroll1.height = .height
HScroll1.Top = .height + .Top + 50
HScroll1.Width = Me.Width - 200
Text1.Move 0, 0, .Width, .height
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set pGraph = Nothing
Set img = Nothing
loaded = False
End Sub
'''''''''''''''''''''''''''''''''''
'Author: Zelimir Ikovic [photo_map@yahoo.com]
'http://www.activexy.com
'''''''''''''''''''''''''''''''''''
Private Sub VScroll1_Change()
Call tp
End Sub
Private Sub VScroll1_Scroll()
Call tp
End Sub
Private Sub HScroll1_Change()
Call lft
End Sub
Private Sub HScroll1_Scroll()
Call lft
End Sub
Private Sub tp()
Dim xx As Double
Dim a As Double
Dim x As Double
x = VScroll1.value
a = Picture1.height - pictParent.height
xx = (a * x) / 100
Picture1.Top = -xx
End Sub
Private Sub lft()
Dim xx As Double
Dim a As Double
Dim x As Double
x = HScroll1.value
a = Picture1.Width - pictParent.Width
xx = (a * x) / 100
Picture1.left = -xx
End Sub
'example
'Dim g As New CGraph
' Dim n0 As CNode, n1 As CNode, n2 As CNode, n3 As CNode, n4 As CNode, n5 As CNode
'
' Set n0 = g.AddNode("this is my" & vbCrLf & "multiline\nnode")
' n0.shape = "box"
' n0.style = "filled"
' n0.color = "lightyellow"
' n0.fontcolor = "#c0c0c0"
'
' Set n1 = g.AddNode
' Set n2 = g.AddNode
' Set n3 = g.AddNode
' Set n4 = g.AddNode
' Set n5 = g.AddNode
'
' n0.ConnectTo n2
' n1.ConnectTo n2
' n2.ConnectTo n3
' n1.ConnectTo n4
' n0.ConnectTo n5
'
' Call g.GenerateGraph
' Text1.Text = g.lastGraph
'
' Set img = g.dot.ToGIF(g.lastGraph)
' If img Is Nothing Then Exit Sub
'
' Set Picture1.Picture = img.Picture