home *** CD-ROM | disk | FTP | other *** search
/ CD Direkt 1995 #6 / CDD_6_95.ISO / cdd / winanw / emedit / mdinote.bas < prev    next >
BASIC Source File  |  1994-08-25  |  22KB  |  698 lines

  1. Option Explicit
  2.  
  3. Global Const modal = 1
  4. Global Const CASCADE = 0
  5. Global Const TILE_HORIZONTAL = 1
  6. Global Const TILE_VERTICAL = 2
  7. Global Const ARRANGE_ICONS = 3
  8.  
  9.  
  10. Global Const REPLACE_CANCEL = 0
  11. Global Const REPLACE_YES = 1
  12. Global Const REPLACE_NO = 2
  13. Global Const REPLACE_ONE = 3
  14. Global Const REPLACE_ALL = 4
  15.  
  16.  
  17. ' globals used to manage MDI child windows...
  18. Type FormState
  19.     Deleted As Integer
  20.     Color As Long
  21. End Type
  22. Global FState()  As FormState
  23. Global document() As New frmNotePad
  24. Global ArrayNum As Integer
  25.  
  26. Global gfInsertMode As Integer ' insert mode : True=insert, False=Overwrite
  27. Global gfBlockType As Integer ' block type : 0=Stream, 1=Line, 2=Column
  28. Global gfRecursiveSearch As Integer
  29.  
  30.  
  31. ' API functions used to read and write to EMEDIT.INI.
  32. ' Used for handling the recent files list.
  33. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  34. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String) As Integer
  35.  
  36. Global Const SM_CXBORDER = 5
  37. Declare Function GetSystemMetrics Lib "User" (ByVal nIndex As Integer) As Integer
  38.  
  39.  
  40.  
  41. ' Key Codes
  42. Global Const KEY_LBUTTON = &H1
  43. Global Const KEY_RBUTTON = &H2
  44. Global Const KEY_CANCEL = &H3
  45. Global Const KEY_MBUTTON = &H4    ' NOT contiguous with L & RBUTTON
  46. Global Const KEY_BACK = &H8
  47. Global Const KEY_TAB = &H9
  48. Global Const KEY_CLEAR = &HC
  49. Global Const KEY_RETURN = &HD
  50. Global Const KEY_SHIFT = &H10
  51. Global Const KEY_CONTROL = &H11
  52. Global Const KEY_MENU = &H12
  53. Global Const KEY_PAUSE = &H13
  54. Global Const KEY_CAPITAL = &H14
  55. Global Const KEY_ESCAPE = &H1B
  56. Global Const KEY_SPACE = &H20
  57. Global Const KEY_PRIOR = &H21
  58. Global Const KEY_NEXT = &H22
  59. Global Const KEY_END = &H23
  60. Global Const KEY_HOME = &H24
  61. Global Const KEY_LEFT = &H25
  62. Global Const KEY_UP = &H26
  63. Global Const KEY_RIGHT = &H27
  64. Global Const KEY_DOWN = &H28
  65. Global Const KEY_SELECT = &H29
  66. Global Const KEY_PRINT = &H2A
  67. Global Const KEY_EXECUTE = &H2B
  68. Global Const KEY_SNAPSHOT = &H2C
  69. Global Const KEY_INSERT = &H2D
  70. Global Const KEY_DELETE = &H2E
  71. Global Const KEY_HELP = &H2F
  72.  
  73. ' KEY_A thru KEY_Z are the same as their ASCII equivalents: 'A' thru 'Z'
  74. ' KEY_0 thru KEY_9 are the same as their ASCII equivalents: '0' thru '9'
  75.  
  76. Global Const KEY_NUMPAD0 = &H60
  77. Global Const KEY_NUMPAD1 = &H61
  78. Global Const KEY_NUMPAD2 = &H62
  79. Global Const KEY_NUMPAD3 = &H63
  80. Global Const KEY_NUMPAD4 = &H64
  81. Global Const KEY_NUMPAD5 = &H65
  82. Global Const KEY_NUMPAD6 = &H66
  83. Global Const KEY_NUMPAD7 = &H67
  84. Global Const KEY_NUMPAD8 = &H68
  85. Global Const KEY_NUMPAD9 = &H69
  86. Global Const KEY_MULTIPLY = &H6A
  87. Global Const KEY_ADD = &H6B
  88. Global Const KEY_SEPARATOR = &H6C
  89. Global Const KEY_SUBTRACT = &H6D
  90. Global Const KEY_DECIMAL = &H6E
  91. Global Const KEY_DIVIDE = &H6F
  92. Global Const KEY_F1 = &H70
  93. Global Const KEY_F2 = &H71
  94. Global Const KEY_F3 = &H72
  95. Global Const KEY_F4 = &H73
  96. Global Const KEY_F5 = &H74
  97. Global Const KEY_F6 = &H75
  98. Global Const KEY_F7 = &H76
  99. Global Const KEY_F8 = &H77
  100. Global Const KEY_F9 = &H78
  101. Global Const KEY_F10 = &H79
  102. Global Const KEY_F11 = &H7A
  103. Global Const KEY_F12 = &H7B
  104. Global Const KEY_F13 = &H7C
  105. Global Const KEY_F14 = &H7D
  106. Global Const KEY_F15 = &H7E
  107. Global Const KEY_F16 = &H7F
  108.  
  109. Global Const KEY_NUMLOCK = &H90
  110.  
  111. 'File Open/Save Dialog Flags
  112. Global Const OFN_READONLY = &H1&
  113. Global Const OFN_OVERWRITEPROMPT = &H2&
  114. Global Const OFN_HIDEREADONLY = &H4&
  115. Global Const OFN_NOCHANGEDIR = &H8&
  116. Global Const OFN_SHOWHELP = &H10&
  117. Global Const OFN_NOVALIDATE = &H100&
  118. Global Const OFN_ALLOWMULTISELECT = &H200&
  119. Global Const OFN_EXTENTIONDIFFERENT = &H400&
  120. Global Const OFN_PATHMUSTEXIST = &H800&
  121. Global Const OFN_FILEMUSTEXIST = &H1000&
  122. Global Const OFN_CREATEPROMPT = &H2000&
  123. Global Const OFN_SHAREAWARE = &H4000&
  124. Global Const OFN_NOREADONLYRETURN = &H8000&
  125.  
  126. Function AnyPadsLeft () As Integer
  127.     Dim I As Integer
  128.  
  129.     ' Cycle throught the document array.
  130.     ' Return True if there is at least one
  131.     ' open document remaining.
  132.     For I = 1 To UBound(document)
  133.     If Not FState(I).Deleted Then
  134.         AnyPadsLeft = True
  135.         Exit Function
  136.     End If
  137.     Next
  138.  
  139. End Function
  140.  
  141. Sub CenterForm (frmParent As Form, frmChild As Form)
  142. ' This procedure centers a child form over a parent form.
  143. ' Calling this routine loads the dialog. Use the Show method
  144. ' to display the dialog after calling this routine ( ie MyFrm.Show 1)
  145.  
  146. Dim l, t
  147.   ' get left offset
  148.   l = frmParent.Left + ((frmParent.Width - frmChild.Width) / 2)
  149.   If (l + frmChild.Width > screen.Width) Then
  150.     l = screen.Width = frmChild.Width
  151.   End If
  152.  
  153.   ' get top offset
  154.   t = frmParent.Top + ((frmParent.Height - frmChild.Height) / 2)
  155.   If (t + frmChild.Height > screen.Height) Then
  156.     t = screen.Height - frmChild.Height
  157.   End If
  158.  
  159.   ' center the child formfv
  160.   frmChild.Move l, t
  161.  
  162. End Sub
  163.  
  164. Sub DisplayError ()
  165.     MsgBox Error$, 48, App.Title ' 48=MB_OK+MB_ICONEXCLAMATION
  166. End Sub
  167.  
  168. Sub EditClearAllProc ()
  169.  
  170.     frmMDI.ActiveForm.Text1.Redraw = False
  171.  
  172.     ' Mark a block that starts with the first character in the first line and
  173.     ' ends with the last character in the last line...
  174.     frmMDI.ActiveForm.Text1.SelMark = 1 'make a stream block
  175.     frmMDI.ActiveForm.Text1.SelStartX = 1
  176.     frmMDI.ActiveForm.Text1.SelStartY = 1
  177.     frmMDI.ActiveForm.Text1.SelEndY = frmMDI.ActiveForm.Text1.Count
  178.     frmMDI.ActiveForm.Text1.TextIndex = frmMDI.ActiveForm.Text1.Count
  179.     frmMDI.ActiveForm.Text1.SelEndX = Len(frmMDI.ActiveForm.Text1.TextIndex) + 1
  180.  
  181.     frmMDI.ActiveForm.Text1.Action = 4  'clear
  182.  
  183.     frmMDI.ActiveForm.Text1.Redraw = True
  184.     
  185. End Sub
  186.  
  187. Sub EditCopyProc ()
  188.     ' copy selection to clipboard
  189.     frmMDI.ActiveForm.Text1.Action = 1
  190.  
  191.     ' Alternatively, we could cut selected text to
  192.     ' Clipboard by sending a Control-Insert key to the
  193.     ' active window...
  194.     'SendKeys "^{INSERT}", True 'wait for text to be cut
  195. End Sub
  196.  
  197. Sub EditCutProc ()
  198.     ' cut selection to clipboard
  199.     frmMDI.ActiveForm.Text1.Action = 3
  200. End Sub
  201.  
  202. Sub EditDeleteProc ()
  203.     ' cut selection to clipboard
  204.     frmMDI.ActiveForm.Text1.Action = 4 'clear
  205. End Sub
  206.  
  207. Sub EditPasteProc ()
  208.     ' Place text from Clipboard into active control.
  209.     frmMDI.ActiveForm.Text1.Action = 2 ' paste selection
  210. End Sub
  211.  
  212. Sub EditUndoProc ()
  213.     ' undo the last edit
  214.     frmMDI.ActiveForm.Text1.Action = 6 'undo
  215. End Sub
  216.  
  217. Sub EditWrapAutomaticallyProc ()
  218.     Dim bAuto As Integer
  219.     bAuto = Not frmMDI.ActiveForm.Text1.WrapAutomatically
  220.     frmMDI.ActiveForm.Text1.WrapAutomatically = bAuto
  221. End Sub
  222.  
  223. Sub EditWrapFormatProc ()
  224.     ' wrap any selected text to fit the current window
  225.     frmMDI.ActiveForm.Text1.WrapX = -1 'wrap to current window size
  226.     frmMDI.ActiveForm.Text1.Action = 5 'wrap selection
  227. End Sub
  228.  
  229. Sub FileNew ()
  230.     Dim fIndex As Integer
  231.  
  232.     fIndex = FindFreeIndex()
  233.     document(fIndex).Tag = fIndex
  234.     document(fIndex).Caption = "Untitled:" & fIndex
  235.     document(fIndex).Show
  236.  
  237.     UpdateToolBar
  238. End Sub
  239.  
  240. Function FindFreeIndex () As Integer
  241.     Static NotFirstTime As Integer
  242.     If NotFirstTime Then
  243.     Dim I As Integer
  244.     Dim ArrayCount As Integer
  245.     
  246.     ArrayCount = UBound(document)
  247.     
  248.     ' Cycle throught the document array. If one of the
  249.     ' documents has been deleted, then return that
  250.     ' index.
  251.     For I = 1 To ArrayCount
  252.         If FState(I).Deleted Then
  253.         FindFreeIndex = I
  254.         FState(I).Deleted = False
  255.         document(I).Tag = I
  256.         Exit Function
  257.         End If
  258.     Next
  259.     
  260.     ' If none of the elements in the document array have
  261.     ' been deleted, then increment the document and the
  262.     ' state arrays by one and return the index to the
  263.     ' new element.
  264.     
  265.     ReDim Preserve document(ArrayCount + 1)
  266.     ReDim Preserve FState(ArrayCount + 1)
  267.     Dim FreeIndex As Integer
  268.     FreeIndex = UBound(document)
  269.     document(FreeIndex).Tag = FreeIndex
  270.     FindFreeIndex = FreeIndex
  271.     Else
  272.     'Initialize document form arr