Project

General

Profile

Statistics
| Revision:

vdfsplat / AppSrc / cSplatCodeMax.pkg @ 63

History | View | Annotate | Download (17.5 KB)

1
//TH-Header
2
//*****************************************************************************************
3
// Copyright (c)  2013 Antwise Solutions
4
// All rights reserved.
5
//
6
// $FileName    : cSplatCodemax.pkg
7
// $ProjectName : Vdf Debugger
8
// $Authors     : Wil van Antwerpen
9
// $Created     : 12.14.2013  23:50
10
// $Type        : GPLv2
11
//
12
// Contents:
13
//
14
//*****************************************************************************************
15
//TH-RevisionStart
16
//TH-RevisionEnd
17

    
18

    
19
Use cComCodeMax.pkg
20
Use cImageList32.pkg
21
Use RGB.pkg
22
Use cOSVersionInfo.pkg
23
//Use cComCDACTreeListCtl.pkg
24

    
25
Define CS_LNG_VDF for "Visual DataFlex"
26
Define CS_DAW_KEY for "Data Access Worldwide"
27
Define CS_DAW_VDF for "Visual DataFlex"
28
Define CS_DAW_DF  for "DataFlex"
29
Define CS_TAB     for (Character(9))
30

    
31

    
32
Define ICO_Brkp_obj     for $CI01 // breakpoint object icon
33
Define ICO_Inst_ptr     for $CI02 // instruction pointer icon
34
Define ICO_Inst_ptr_top for $CI04 // instruction pointer top icon
35

    
36
Class cCodeMaxImageList is a cImageList32
37
  
38
  Procedure Construct_Object
39
    Forward Send Construct_Object
40
     
41
    Set piMaxImages To 5
42
    Set piImageHeight To 16
43
    Set piImageWidth  To 16
44
  End_Procedure // Construct_Object
45
  
46
  Procedure OnCreate
47
    Integer iVoid
48
  
49
    Get AddImage "brkp_obj.ico"     To iVoid // bit 1 // seems the first image is ignored as a margin image
50
    Get AddImage "inst_ptr.ico"     To iVoid // bit 2
51
    Get AddImage "brkp_obj.ico"     To iVoid // bit 3
52
    Get AddImage "inst_ptr_top.ico" To iVoid // bit 4
53
  End_Procedure
54
End_Class
55

    
56

    
57
Class cSplatCodeMax is a cComCodeMax
58
  Procedure Construct_Object
59
    Forward Send Construct_Object
60
    Property String  psFileName     ""
61
    Property Integer piCurrentLine  0
62
    
63
    Object oCodeMaxImages is a cCodeMaxImageList
64
    End_Object
65
  End_Procedure
66
    
67
  Function HostOSis64Bits Returns Boolean
68
    Handle  hoVersionInfo
69
    Boolean bIs64Bits
70
                                                                             
71
    Move false to bIs64Bits
72
    Get Create U_cOSVersionInfo To hoVersionInfo
73
    If (hoVersionInfo) Begin
74
      Get pbX64  Of hoVersionInfo To bIs64Bits
75
    End
76
                                                                             
77
    Function_Return bIs64Bits
78
  End_Function // HostOSis64Bits
79
  
80
  // Returns compiled runtime version as DataFlex version * 10
81
  Function CompiledRuntimeVersion Returns Integer
82
    String  sVersion
83
    Integer iVersion
84
    Move (Replace(".",gsRuntimeVersion,"")) To sVersion
85
    Move (Cast(sVersion,integer)) To iVersion
86
    Function_Return iVersion
87
  End_Function
88
  
89
  //
90
  // Runtime folder that is used for compiling the current version of Splat.
91
  // This helps us in getting the required parameters
92
  //
93
  Function CurrentRuntimeFolder Returns String
94
    Boolean bOpened
95
    Boolean bExists
96
    Handle  hoRegistry
97
    String  sKey
98
    String  sPath
99
    Integer iVersion
100
    
101
    Move "" To sPath
102
    Get Create U_cRegistry to hoRegistry
103

    
104
    If (hoRegistry) Begin
105
      Set phRootKey of hoRegistry to HKEY_LOCAL_MACHINE
106
      Set pfAccessRights of hoRegistry to Key_Read
107
  
108
      // check if this is a 64 bit machine
109
      // if so, the Wow6432Node key will exist <- unreliable test as it turns out
110
      //Get KeyExists of hoRegistry "SOFTWARE\Wow6432Node" to bExists
111
      Get HostOSis64Bits To bExists
112
      If bExists Begin
113
          Move (Append("SOFTWARE\Wow6432Node\", CS_DAW_KEY)) to sKey
114
      End
115
      Else Begin
116
          Move (Append("SOFTWARE\", CS_DAW_KEY)) to sKey
117
      End
118
      
119
      Get KeyExists of hoRegistry sKey to bExists
120
      If bExists Begin
121
          Get CompiledRuntimeVersion To iVersion
122
          If (iVersion<180) Begin
123
            Move (sKey+"\"+CS_DAW_VDF+"\"+gsRuntimeVersion+"\Defaults\") To sKey
124
          End
125
          Else Begin
126
            Move (sKey+"\"+ CS_DAW_DF+"\"+gsRuntimeVersion+"\Defaults\") To sKey
127
          End
128
          Get OpenKey of hoRegistry sKey to bOpened
129
          If bOpened Begin
130
            Get ReadString of hoRegistry "VDFRootDir" To sPath
131

    
132
            Send CloseKey of hoRegistry
133
          End
134
      End
135
      
136
      Send Destroy of hoRegistry
137
    End
138
    
139
       
140
    Function_Return sPath
141
  End_Function // CurrentRuntimeFolder
142

    
143
  Procedure LoadVDFLanguageDefinition
144
    Boolean bCreated
145
    Boolean bExists
146
    String  sRootDir
147
    String  sLibDir
148
    String  sLanguageFile
149
    Integer iVersion
150
    Handle  hoLanguage
151
    Variant vLanguage
152
    
153
    Get Create U_cComlanguage To hoLanguage
154
    If (hoLanguage) Begin
155
      Send CreateComObject of hoLanguage
156
      Get IsComObjectCreated Of hoLanguage To bCreated
157
      If (bCreated) Begin
158
        Get CurrentRuntimeFolder to sRootDir
159
        If (sRootDir<>"") Begin
160
          Get vFolderFormat sRootDir To sRootDir
161
          Move (sRootDir+"Lib\") To sLibDir
162
          
163
          Get CompiledRuntimeVersion to iVersion
164
          If (iVersion<180) Begin
165
            Move (sLibDir+"VisualDataFlex.lng") To sLanguageFile
166
          End
167
          Else Begin
168
            Move (sLibDir+"DataFlex.lng") To sLanguageFile
169
          End
170
          Get vFilePathExists sLanguageFile to bExists
171
          If (bExists) Begin
172
            Send ComLoadXmlDefinition of hoLanguage sLanguageFile
173
            Set ComName of hoLanguage To CS_LNG_VDF
174
            Send ComRegister of hoLanguage
175
            
176
            Get pvComObject of hoLanguage To vLanguage
177
            Set ComLanguage To vLanguage
178
            
179
            Send Destroy of hoLanguage
180
          End
181
          Else Begin
182
            Send Info_Box ("Can't load language for runtime"*gsRuntimeVersion*"Couldn't find language file\n"*sLanguageFile)
183
          End
184
        End
185
        Else Begin
186
          Send Info_Box ("Can't load language as unable to determine runtime folder for VDF"*gsRuntimeVersion)
187
        End
188
      End
189
    End
190
  End_Procedure // LoadVDFLanguageDefinition
191
  
192
  //
193
  // Returns line numbers starting from line 0 (not line 1)
194
  // Columns numbers are also zero based
195
  //
196
  Function CurrentPosition Variant vPos Integer Byref iLine Integer Byref iColumn Returns Boolean
197
    Boolean bOK
198
    Handle  hoPos
199
    
200
    Move false To bOK
201
    Get Create (RefClass(cComPosition)) To hoPos
202
    If (hoPos) Begin
203
      Set pvComObject of hoPos to vPos
204
      Get ComLineNo of hoPos To iLine
205
      Get ComColNo  of hoPos To iColumn
206
      Send Destroy of hoPos
207
      Move True To bOk
208
    End
209
    Function_Return bOK
210
  End_Function
211
  
212
  Function CurrentLine Returns Integer
213
    Boolean bOK
214
    Integer iOffset
215
    Integer llLine
216
    Integer llColumn
217
    Integer iLine
218
    Variant vPos
219
    
220
    Move 0 To iLine
221
    Get ComSelStart to iOffset
222
    //Get ComSelEnd to llColumn
223
    Get ComOffsetToPos iOffset to vPos
224
    //Get ComGetSel False to vSel
225
    Get CurrentPosition vPos (&llLine) (&llColumn) To bOK
226
    If (bOK) Begin
227
      Move (llLine+1) To iLine  // +1 because line number returned is zero based.
228
    End
229
    If (llLine=0 and piCurrentLine(Self)<>0) Begin
230
      // .. not great ..
231
      // if file was opened via stack and this window does not yet have the focus by clicking
232
      // into the file, it will return line 0, as a result setting a breakpoint isn't reliable
233
      // so... we use this ugly workaround.
234
      Get piCurrentLine To iLine
235
    End
236
    Function_Return iLine
237
  End_Function
238
  
239
  Function WordAtPositionDoesNotWork Integer iLine Integer iColumn Returns String
240
    String  sWord
241
    String  sLeadingChar
242
    String  sTrailingChar
243
    Handle  hoPos
244
    Variant vPos
245
    
246
    Get Create (RefClass(cComPosition)) to hoPos
247
    If (hoPos) Begin
248
      Send CreateComObject to hoPos
249
      Set ComLineNo   of hoPos to iLine
250
      Set ComColNo    of hoPos to iColumn
251
      Get pvComObject of hoPos to vPos
252
      Move " (=+-*"  to sLeadingChar
253
      Move " ()=+-*" to sTrailingChar
254
      // Won't work ComGetWordEx does not stop on any of the above characters
255
      Get ComGetWordEx vPos sLeadingChar sTrailingChar to sWord
256
      Send Destroy of hoPos
257
    End
258
    Function_Return sWord
259
  End_Function
260
  
261
  Function WordAtLinePosition String sLine Integer iColumn Returns String
262
    String  sWord
263
    String  sLeadingChar
264
    String  sTrailingChar
265
    String  sChar
266
    Integer iChar
267
    Integer iStart
268
    Integer iEnd
269
    Integer iLength
270
    Boolean bStop
271
    
272
    Move (CS_TAB+" (=+-*")   To sLeadingChar
273
    Move (CS_TAB+" ()=+-*")  to sTrailingChar
274

    
275
    Move False to bStop
276
    Move iColumn to iChar
277
    if (iColumn>0) begin
278
      While not bStop
279
        Move (Mid(sLine,1,iChar)) To sChar
280
        If (iChar<=0 or sLeadingChar contains sChar) begin
281
          Move True To bStop
282
          Move (iChar+1) To iStart
283
        End
284
        Decrement iChar
285
      Loop
286
    End
287
    Move (length(sLine)) To iLength
288
    For iChar from iColumn To iLength
289
      Move (Mid(sLine,1,iChar)) To sChar
290
      If (sTrailingChar contains sChar) begin
291
        Move (iChar-1) to iEnd
292
        Move iLength To iChar
293
      End
294
    Loop
295
    If (iEnd=0) Move iLength To iEnd
296
    Move (Mid(sLine,iEnd-iStart+1,iStart)) To sWord
297
    Function_Return sWord
298
  End_Function
299
  
300
  // Returns the word under the specified location.
301
  // iLine and iColumn are zero based
302
  //
303
  Function WordAtPosition Integer iLine Integer iColumn Returns String
304
    String  sWord
305
    String  sComment
306
    String  sLeadingChar
307
    String  sTrailingChar
308
    String  sChar
309
    String  sLine
310
    Integer iCommentPos
311
    Integer iChar
312
    Boolean bBeforeLine
313
    
314
    Get ComGetLine iLine To sLine
315
    Move "//" to sComment
316
    Move (Pos(sComment,sLine)) To iCommentPos
317
    If (iCommentPos>0 and iCommentPos<iColumn and iColumn>0) Begin
318
      Function_Return "" // caret is in a comment block
319
    End
320
    Move " (=+-*"   to sLeadingChar
321
    Move " ()=+-*"  to sTrailingChar
322
    Move True to bBeforeLine // test if caret is before any words on the line
323
    For iChar from 1 to iColumn
324
      Move (Mid(sLine,1,iChar)) to sChar
325
      If not ( (sLeadingChar+sTrailingChar) contains sChar ) Begin
326
        Move False to bBeforeLine
327
        Move iColumn to iChar
328
      End
329
    Loop
330
    If (bBeforeLine) Begin
331
      Function_Return "" // before any words
332
    End
333
    Get WordAtLinePosition sLine iColumn To sWord
334
    Function_Return sWord
335
  End_Function
336
  
337
  //
338
  // A bunch of parsing problems happen because we don't know how many
339
  // white space characters exist. This replaces multiple WS characters to just
340
  // one space character.
341
  //
342
  Function SingleWhiteSpaceLine String sLine Returns String
343
    Integer iLength
344
    Integer iChar
345
    Boolean bPrevWSChar
346
    String  sChar
347
    String  sSWSLine
348
    String  sWSChars
349
    
350
    Move "" To sSWSLine
351
    Move (CS_TAB+" ") To sWSChars
352
    Move (length(sLine)) To iLength
353
    Move False To bPrevWSChar
354
    For iChar From 1 To iLength
355
      Move (Mid(sLine,1,iChar)) to sChar
356
      If (sWSChars contains sChar) begin
357
        If (bPrevWSChar=false) Begin
358
          Move True To bPrevWSChar
359
          Move (sSWSLine+" ") To sSWSLine
360
        End
361
      End
362
      Else Begin
363
        Move False To bPrevWSChar
364
        Move (sSWSLine+sChar) To sSWSLine
365
      End
366
    Loop
367
    Function_Return sSWSLine
368
  End_Function
369
  
370
  //
371
  // Tries to locate the object (or variable) in a notation like
372
  // Get Property Of oObject To
373
  // which should return oObject
374
  //
375
  Function IsPropertyOf String sProperty Integer iline Integer iColumn Returns String
376
    Integer iPos
377
    Integer iLength
378
    Integer iObj
379
    String  sObject
380
    String  sLine
381
    String  sXLine
382
    String  slLine
383
    
384
    Move "" To sObject
385
    Get ComGetLine iLine To sLine
386
    If (sLine<>"") Begin
387
      Get SingleWhiteSpaceLine sLine To sXLine
388
      Move (lowercase(sXLine)) To slLine
389
      Move (Pos(lowercase(sProperty)+" of ",slLine)) To iPos
390
      If (iPos) Begin
391
        Move (Length(sProperty+" of ")) To iLength
392
        Move (iPos+iLength+1) To iObj
393
        Get WordAtLinePosition sXline iObj To sObject
394
      End
395
        
396
    End
397
    Function_Return sObject
398
  End_Function
399
  
400
  //
401
  // Properties that are queried which are not local to the focused object will need to
402
  // be referenced in order to get the correct data back.
403
  // This code will try to parse out the object.
404
  //
405
  Function ObjectForProperty String sProperty Integer iLine Integer iColumn Returns String
406
    String sObject
407
    String sOfObject
408
    String sLine
409
    
410
    Move "Self" To sObject  // the default target object is self
411
    Get IsPropertyOf sProperty iLine iColumn To sOfObject
412
    If (sOfObject<>"") Begin
413
      Move sOfObject To sObject
414
    End
415
    Function_Return sObject
416
  End_Function
417

    
418
  Procedure OnComQuickInfo Integer llLine Integer llColumn String ByRef llTipText
419
    Handle  hoDebugger
420
    String  sWord
421
    String  sResult
422
    String  sObjectID
423
    String  sObjectName
424
    String  sType
425
    String  sTargetObject
426
    Boolean bIsProperty
427
    Boolean bIsProcedure
428
    Boolean bIsObject
429
    Boolean bOK
430
    
431
    // Does not always return what we need
432
    //Get ComCurrentWord To sWord  // gets word under cursor
433
    Move False To bOk
434
    Get WordAtPosition llLine llColumn To sWord
435
    If (sWord<>"") Begin
436
      Get phoDebugger To hoDebugger
437
      If (hoDebugger) Begin
438
        Move ""    To sResult
439
        Move ""    To sType
440
        Move False To bIsObject
441
        Get IsVariableProperty of hoDebugger sWord To bIsProperty
442
        If (bIsProperty) Begin
443
          Get ObjectForProperty sWord llLine llColumn to sTargetObject
444
          Move (sWord+"("+sTargetObject+")") To sWord
445
          Move "Property " To sType
446
        End
447
        Else Begin
448
          Get IsVariableProcedure Of hoDebugger sWord To bIsProcedure
449
          If (bIsProcedure) Begin
450
            Move "Procedure " To sType
451
          End
452
          Else Begin
453
            If (lowercase(sWord)="self") Begin
454
              Move "Object " To sType
455
              Move True     To bIsObject
456
            End
457
          End
458
        End
459
        Move ("Evaluating "+sType+"'"+sWord+"' results in"+character(10)) To llTipText
460
        If (bIsProcedure) Begin
461
          Move "Not evaluating methods." To sResult
462
        End
463
        Else Begin
464
          Get ComEval of hoDebugger sWord (&sResult) to bOK
465
        End
466
        If (bOK) Begin
467
          If (bIsObject) Begin
468
            Move sResult To sObjectID
469
            Move ""      To sObjectName
470
            Get ComEval of hoDebugger ("name("+sObjectID+")") (&sObjectName) to bOK
471
            If (bOK) Begin
472
              Move (sResult+" ("+sObjectName+") ") To sResult
473
            End
474
          End
475
          Move (sResult+character(10)+character(10)+"Eval OK") To sResult
476
        End
477
        Else Begin
478
          Move (sResult+character(10)+character(10)+"Eval Failed") To sResult
479
        End
480
        Move (sResult+", line="+trim(llLine+1)*", column="+Trim(llColumn+1)) To sResult
481
      End
482
      Else Begin
483
        Move "Unable to attach to debugger core" To sResult
484
      End
485
    End
486
    Move (llTipText+sResult) To llTipText
487
  End_Procedure
488

    
489

    
490
  Procedure OnCreate
491
    Handle  hWnd
492
    Handle  hWndImg
493
    Handle  hoImgList
494
    Variant vImageList
495
//    Boolean bCreated
496
    
497
    Forward Send OnCreate
498
    
499
    // ToDo: Set the ActiveX properties here...
500
    // ComImageListRef
501
    // ComHImageList // line margin images
502
    //Set ComHImageList  To (oEditImages(Self))//vImageList
503
    
504
    Send LoadVDFLanguageDefinition
505
    //
506
    Set ComDisplayLeftMargin To True
507
    Send ComSetColor OLEcmClrLeftMargin clLtGray
508
    Set ComBorderStyle To OLEcmBorderClient
509
    
510
    //Get Window_Handle of oCodeMaxImages To hWnd
511
    Get phImageList Of oCodeMaxImages To hWndImg
512
    //Move (oCodeMaxImages(Self)) To hoImgList
513
    Set ComHImageList  To hWndImg  //vImageList
514
    //Set ComImageListRef To hWndImg
515
  End_Procedure
516
  
517
  Procedure UpdateStatusHelp
518
    Integer Fg
519
    Move 1 To Fg
520
    Send Request_Status_Help Fg
521
  End_Procedure
522
  
523
  // update status bar when cursor is moving
524
  Procedure onCaretPosChanged
525
    Send UpdateStatusHelp
526
  End_Procedure
527
  
528
  // The caret position changed
529
  Procedure OnComSelChange
530
    Send onCaretPosChanged
531
    Forward Send OnComSelChange
532
  End_Procedure
533
  
534
  
535
  
536
  Procedure doOpenSourceFile String sFileName
537
    String sLanguage
538
    Variant vLanguage
539
    
540
    Send ComOpenFile  sFileName
541

    
542
    Set psFilename    To sFileName
543

    
544
    Set ComReadOnly To True // NO changes allowed
545
    Set ComColorSyntax To True
546
    
547
    // Update view hosting our control
548
    //Send doSetCaptionLabel sFileName
549
  End_Procedure // doOpenSourceFile
550
  
551
  Procedure doOpenSourceFileAtLine String sFileName Integer iLine
552
    Integer eBkLineColor
553
    Boolean bVisible
554
    Boolean bScrollup
555
    
556
    Move false to bScrollup
557
    Send doOpenSourceFile sFileName
558
    Set piCurrentLine To iLine
559
    If (iLine>10) Begin
560
      Move (iLine-4) To iLine // scroll up a bit so we can see context
561
      Move true to bScrollup
562
    End
563
    Send ComSetTopIndex 0 iLine
564
    If (bScrollup) Move (iLine+3) to iLine
565
    
566
    Send ComSetMarginImages iLine ICO_Inst_ptr //ICO_Brkp_obj// 2
567
    //Set psFilename     of oCodeMax To sFileName
568
    // Make it visible to the user where we are
569
    //Move True to bVisible
570
    //Send ComSelectLine of oCodeMax iLine bVisible
571
    Move (RGB(223,253,193)) To eBkLineColor
572
    Send ComSetLineColor iLine eBkLineColor //clYellow
573
    
574
    Send UpdateStatusHelp
575
    
576
//    Send ComSetLineColor iLine clRed
577
  End_Procedure // doOpenSourceFileAtLine
578
  
579
End_Class