home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 13 / CD_ASCQ_13_0494.iso / maj / 1697 / samples / mdinote.bas < prev    next >
BASIC Source File  |  1993-11-21  |  27KB  |  775 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. ' globals used to manage MDI child windows...
  10. Type FormState
  11.     Deleted As Integer
  12.     Color As Long
  13. End Type
  14. Global FState()  As FormState
  15. Global document() As New frmNotePad
  16. Global ArrayNum As Integer
  17.  
  18. ' globals used to searh for text...
  19. Global gTargetText As String
  20. Global gMatchCase As Integer
  21. Global gWholeWordOnly As Integer
  22. Global gUpDirection As Integer
  23. Global gBeginScope As Integer
  24. Global gCurPosX As Long, gCurPosY As Long
  25. Global gFirstTime As Integer
  26. Global gNewText As String
  27. Global gfReplace As Integer
  28.  
  29. Global gfInsertMode As Integer ' insert mode : True=insert, False=Overwrite
  30. Global gfBlockType As Integer ' block type : 0=Stream, 1=Line, 2=Column
  31. Global gfRecursiveSearch As Integer
  32.  
  33.  
  34. ' API functions used to read and write to EMEDIT.INI.
  35. ' Used for handling the recent files list.
  36. 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
  37. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String) As Integer
  38.  
  39.  
  40. ' Key Codes
  41. Global Const KEY_LBUTTON = &H1
  42. Global Const KEY_RBUTTON = &H2
  43. Global Const KEY_CANCEL = &H3
  44. Global Const KEY_MBUTTON = &H4    ' NOT contiguous with L & RBUTTON
  45. Global Const KEY_BACK = &H8
  46. Global Const KEY_TAB = &H9
  47. Global Const KEY_CLEAR = &HC
  48. Global Const KEY_RETURN = &HD
  49. Global Const KEY_SHIFT = &H10
  50. Global Const KEY_CONTROL = &H11
  51. Global Const KEY_MENU = &H12
  52. Global Const KEY_PAUSE = &H13
  53. Global Const KEY_CAPITAL = &H14
  54. Global Const KEY_ESCAPE = &H1B
  55. Global Const KEY_SPACE = &H20
  56. Global Const KEY_PRIOR = &H21
  57. Global Const KEY_NEXT = &H22
  58. Global Const KEY_END = &H23
  59. Global Const KEY_HOME = &H24
  60. Global Const KEY_LEFT = &H25
  61. Global Const KEY_UP = &H26
  62. Global Const KEY_RIGHT = &H27
  63. Global Const KEY_DOWN = &H28
  64. Global Const KEY_SELECT = &H29
  65. Global Const KEY_PRINT = &H2A
  66. Global Const KEY_EXECUTE = &H2B
  67. Global Const KEY_SNAPSHOT = &H2C
  68. Global Const KEY_INSERT = &H2D
  69. Global Const KEY_DELETE = &H2E
  70. Global Const KEY_HELP = &H2F
  71.  
  72. ' KEY_A thru KEY_Z are the same as their ASCII equivalents: 'A' thru 'Z'
  73. ' KEY_0 thru KEY_9 are the same as their ASCII equivalents: '0' thru '9'
  74.  
  75. Global Const KEY_NUMPAD0 = &H60
  76. Global Const KEY_NUMPAD1 = &H61
  77. Global Const KEY_NUMPAD2 = &H62
  78. Global Const KEY_NUMPAD3 = &H63
  79. Global Const KEY_NUMPAD4 = &H64
  80. Global Const KEY_NUMPAD5 = &H65
  81. Global Const KEY_NUMPAD6 = &H66
  82. Global Const KEY_NUMPAD7 = &H67
  83. Global Const KEY_NUMPAD8 = &H68
  84. Global Const KEY_NUMPAD9 = &H69
  85. Global Const KEY_MULTIPLY = &H6A
  86. Global Const KEY_ADD = &H6B
  87. Global Const KEY_SEPARATOR = &H6C
  88. Global Const KEY_SUBTRACT = &H6D
  89. Global Const KEY_DECIMAL = &H6E
  90. Global Const KEY_DIVIDE = &H6F
  91. Global Const KEY_F1 = &H70
  92. Global Const KEY_F2 = &H71
  93. Global Const KEY_F3 = &H72
  94. Global Const KEY_F4 = &H73
  95. Global Const KEY_F5 = &H74
  96. Global Const KEY_F6 = &H75
  97. Global Const KEY_F7 = &H76
  98. Global Const KEY_F8 = &H77
  99. Global Const KEY_F9 = &H78
  100. Global Const KEY_F10 = &H79
  101. Global Const KEY_F11 = &H7A
  102. Global Const KEY_F12 = &H7B
  103. Global Const KEY_F13 = &H7C
  104. Global Const KEY_F14 = &H7D
  105. Global Const KEY_F15 = &H7E
  106. Global Const KEY_F16 = &H7F
  107.  
  108. Global Const KEY_NUMLOCK = &H90
  109.  
  110. 'File Open/Save Dialog Flags
  111. Global Const OFN_READONLY = &H1&
  112. Global Const OFN_OVERWRITEPROMPT = &H2&
  113. Global Const OFN_HIDEREADONLY = &H4&
  114. Global Const OFN_NOCHANGEDIR = &H8&
  115. Global Const OFN_SHOWHELP = &H10&
  116. Global Const OFN_NOVALIDATE = &H100&
  117. Global Const OFN_ALLOWMULTISELECT = &H200&
  118. Global Const OFN_EXTENTIONDIFFERENT = &H400&
  119. Global Const OFN_PATHMUSTEXIST = &H800&
  120. Global Const OFN_FILEMUSTEXIST = &H1000&
  121. Global Const OFN_CREATEPROMPT = &H2000&
  122. Global Const OFN_SHAREAWARE = &H4000&
  123. Global Const OFN_NOREADONLYRETURN = &H8000&
  124.  
  125. Function AnyPadsLeft () As Integer
  126.     Dim I As Integer
  127.  
  128.     ' Cycle throught the document array.
  129.     ' Return True if there is at least one
  130.     ' open document remaining.
  131.     For I = 1 To UBound(document)
  132.         If Not FState(I).Deleted Then
  133.             AnyPadsLeft = True
  134.             Exit Function
  135.         End If
  136.     Next
  137.  
  138. End Function
  139.  
  140. Sub CenterForm (frmParent As Form, frmChild As Form)
  141. ' This procedure centers a child form over a parent form.
  142. ' Calling this routine loads the dialog. Use the Show method
  143. ' to display the dialog after calling this routine ( ie MyFrm.Show 1)
  144.  
  145. Dim L, t
  146.   ' get left offset
  147.   L = frmParent.Left + ((frmParent.Width - frmChild.Width) / 2)
  148.   If (L + frmChild.Width > screen.Width) Then
  149.     L = screen.Width = frmChild.Width
  150.   End If
  151.  
  152.   ' get top offset
  153.   t = frmParent.Top + ((frmParent.Height - frmChild.Height) / 2)
  154.   If (t + frmChild.Height > screen.Height) Then
  155.     t = screen.Height - frmChild.Height
  156.   End If
  157.  
  158.   ' center the child formfv
  159.   frmChild.Move L, t
  160.  
  161. End Sub
  162.  
  163. Sub DisplayError ()
  164.     MsgBox Error$, 48, App.Title ' 48=MB_OK+MB_ICONEXCLAMATION
  165. End Sub
  166.  
  167. Sub EditCopyProc ()
  168.     ' copy selection to clipboard
  169.     frmMDI.ActiveForm.Text1.Action = 1
  170.  
  171.     ' Alternatively, we could cut selected text to
  172.     ' Clipboard by sending a Control-Insert key to the
  173.     ' active window...
  174.     'SendKeys "^{INSERT}", True 'wait for text to be cut
  175. End Sub
  176.  
  177. Sub EditCutProc ()
  178.     ' cut selection to clipboard
  179.     frmMDI.ActiveForm.Text1.Action = 3
  180. End Sub
  181.  
  182. Sub EditPasteProc ()
  183.     ' Place text from Clipboard into active control.
  184.     frmMDI.ActiveForm.Text1.Action = 2 ' paste selection
  185. End Sub
  186.  
  187. Sub FileNew ()
  188.     Dim fIndex As Integer
  189.  
  190.     fIndex = FindFreeIndex()
  191.     document(fIndex).Tag = fIndex
  192.     document(fIndex).Caption = "Untitled:" & fIndex
  193.     document(fIndex).Show
  194.  
  195.     UpdateToolBar
  196. End Sub
  197.  
  198. Function FindFreeIndex () As Integer
  199.     Static NotFirstTime As Integer
  200.     If NotFirstTime Then
  201.         Dim I As Integer
  202.         Dim ArrayCount As Integer
  203.     
  204.         ArrayCount = UBound(document)
  205.     
  206.         ' Cycle throught the document array. If one of the
  207.         ' documents has been deleted, then return that
  208.         ' index.
  209.         For I = 1 To ArrayCount
  210.             If FState(I).Deleted Then
  211.                 FindFreeIndex = I
  212.                 FState(I).Deleted = False
  213.                 document(I).Tag = I
  214.                 Exit Function
  215.             End If
  216.         Next
  217.     
  218.         ' If none of the elements in the document array have
  219.         ' been deleted, then increment the document and the
  220.         ' state arrays by one and return the index to the
  221.         ' new element.
  222.     
  223.         ReDim Preserve document(ArrayCount + 1)
  224.         ReDim Preserve FState(ArrayCount + 1)
  225.         Dim FreeIndex As Integer
  226.         FreeIndex = UBound(document)
  227.         document(FreeIndex).Tag = FreeIndex
  228.         FindFreeIndex = FreeIndex
  229.     Else
  230.         'Initialize document form arrays, and show first document.
  231.         ReDim document(1)
  232.         ReDim FState(1)
  233.         document(1).Tag = 1
  234.         FindFreeIndex = 1
  235.         NotFirstTime = True
  236.     End If
  237. End Function
  238.  
  239. Function FindIt (TargetText As String, MatchCase As Integer, WholeWordOnly As Integer, UpDirection As Integer, BeginScope As Integer, NewText As String, fReplace As Integer, IsRepeat As Integer) As Integer
  240.     Dim FindStartY As Long, FindStartX As Long ' point where search starts
  241.     Dim FindEndY As Long, FindEndX As Long ' point where search ends
  242.     Dim FoundY As Long, FoundX As Long ' found text
  243.     Dim FindText As String
  244.     Dim fInStrCase As Integer
  245.     FindIt = False
  246.  
  247.     'make sure the current form's display is up to date...
  248.     frmMDI.ActiveForm.Refresh
  249.  
  250.     FindText = TargetText
  251.     If MatchCase Then fInStrCase = 0 Else fInStrCase = 1
  252.     'If Not MatchCase Then FindText = UCase(FindText)
  253.  
  254.     ' Save the arguments to this subroutine for use when
  255.     ' the find/relace is repeated
  256.     gTargetText = TargetText
  257.     gMatchCase = MatchCase
  258.     gWholeWordOnly = WholeWordOnly
  259.     gUpDirection = UpDirection
  260.     gBeginScope = BeginScope
  261.     gNewText = NewText
  262.     gfReplace = fReplace
  263.     ' If we wern't given a string to look for then don't do anything...
  264.     If FindText = "" Then Exit Function
  265.  
  266.     ' Calculate starting point...
  267.     If BeginScope = False Then ' start at cursor
  268.         FindStartY = frmMDI.ActiveForm.Text1.CaretY
  269.         FindStartX = frmMDI.ActiveForm.Text1.CaretX
  270.     Else
  271.         If UpDirection Then  ' start at end of file
  272.             FindStartY = frmMDI.ActiveForm.Text1.Count
  273.             frmMDI.ActiveForm.Text1.TextIndex = FindStartY
  274.             FindStartX = Len(frmMDI.ActiveForm.Text1.Text)
  275.         Else ' start at beginning of file
  276.             FindStartY = 1
  277.             FindStartX = 1
  278.         End If
  279.     End If
  280.  
  281.     ' Calculate ending point...
  282.     If UpDirection Then
  283.         FindEndY = 1
  284.         FindEndX = 1
  285.     Else ' end at bottom of file
  286.         FindEndY = frmMDI.ActiveForm.Text1.Count
  287.         frmMDI.ActiveForm.Text1.TextIndex = FindEndY
  288.         FindEndX = Len(frmMDI.ActiveForm.Text1.Text)
  289.     End If
  290.  
  291.     ' If the search is being repeated then don't start where we
  292.     ' the search left off otherwise you'll just find the same
  293.     ' text you found last time...
  294.     If IsRepeat And UpDirection = True Then
  295.         If gCurPosX = FindStartX And gCurPosY = FindStartY Then
  296.             FindStartX = FindStartX - Len(FindText) - 1
  297.             If FindStartX = 0 Then
  298.                 If 1 < FindStartY Then
  299.                     FindStartY = FindStartY - 1
  300.                     frmMDI.ActiveForm.Text1.TextIndex = FindStartY
  301.                     FindStartX = Len(frmMDI.ActiveForm.Text1.Text)
  302.                 Else
  303.                     FindStartX = 1
  304.                 End If
  305.             End If
  306.         End If
  307.     End If
  308.  
  309.     ' In some special situations (like searching down selected text beginning at the
  310.     ' cursor position when the cursor is at the end of the selection) don't do nothin...
  311.     If UpDirection Then
  312.         If FindStartY < FindEndY Then Exit Function
  313.     Else
  314.         If FindEndY < FindStartY Then Exit Function
  315.     End If
  316.  
  317.     ' change mousepointer to an hourglass
  318.     screen.MousePointer = 11
  319.  
  320.     'do search in down direction...
  321.     If UpDirection = False Then
  322.         Dim I As Integer
  323.         For I = FindStartY To FindEndY
  324.             Dim SourceText As String
  325.             frmMDI.ActiveForm.Text1.TextIndex = I
  326.             SourceText = frmMDI.ActiveForm.Text1.Text
  327.             If Len(SourceText) Then
  328.                 'If MatchCase = False Then SourceText = UCase(SourceText)
  329.                 FoundX = InStr(FindStartX, SourceText, FindText, fInStrCase)
  330.                 If 0 < FoundX Then
  331.                     If WholeWordOnly Then
  332.                         If IsWholeWord(SourceText, FoundX, Len(FindText)) Then
  333.                             FoundY = I
  334.                             Exit For
  335.                         End If
  336.                     Else
  337.                         FoundY = I
  338.                         Exit For
  339.                     End If
  340.                 End If
  341.             End If
  342.             FindStartX = 1
  343.         Next
  344.     End If
  345.  
  346.     'do search in up direction...
  347.     If UpDirection = True Then
  348.         'Dim I As Integer
  349.         For I = FindStartY To FindEndY Step -1
  350.             'Dim SourceText As String
  351.             frmMDI.ActiveForm.Text1.TextIndex = I
  352.             SourceText = frmMDI.ActiveForm.Text1.Text
  353.             If I <> FindStartY Then FindStartX = Len(SourceText)
  354.             If Len(SourceText) Then
  355.                 'If MatchCase = False Then SourceText = UCase(SourceText)
  356.  
  357.                 Dim X As Long
  358.                 X = 1
  359.                 'FoundX = InStr(FindStartX, SourceText, FindText)
  360.                 Do While 0 < X And X <= FindStartX
  361.                     X = InStr(X, SourceText, FindText, fInStrCase)
  362.                     If X = 0 Then
  363.                         Exit Do
  364.                     ElseIf X <= FindStartX Then
  365.                         FoundX = X
  366.                     End If
  367.                     X = X + 1
  368.                 Loop
  369.                 
  370.                 'For pos = start - 1 To 0 Step -1
  371.                 '    If pos = 0 Then Exit For
  372.                 '    If Mid(sourcestring, pos, Len(FindString)) = FindString Then Exit For
  373.                 'Next
  374.                 If 0 < FoundX Then
  375.                     If WholeWordOnly Then
  376.                         If IsWholeWord(SourceText, FoundX, Len(FindText)) Then
  377.                             FoundY = I
  378.                             Exit For
  379.                         End If
  380.                     Else
  381.                         FoundY = I
  382.                         Exit For
  383.                     End If
  384.                 End If
  385.             End If
  386.         Next
  387.     End If
  388.  
  389.     ' reset mouse pointer
  390.     screen.MousePointer = 0
  391.  
  392.     ' If string is found
  393.     If FoundY Then
  394.         FindIt = True
  395.  
  396.         ' Save the position of the found text, if the search
  397.         ' is repeated then the search starts at the next position
  398.         gCurPosX = FoundX + Len(FindText)
  399.         gCurPosY = FoundY
  400.  
  401.         ' highlight the found text...
  402.         frmMDI.ActiveForm.Text1.Redraw = False
  403.         frmMDI.ActiveForm.Text1.CaretY = FoundY
  404.         frmMDI.ActiveForm.Text1.CaretX = FoundX + Len(FindText)
  405.         frmMDI.ActiveForm.Text1.SelMark = 0' un-mark any block
  406.         frmMDI.ActiveForm.Text1.SelMark = 1' make a stream block
  407.         frmMDI.ActiveForm.Text1.SelStartY = FoundY
  408.         frmMDI.ActiveForm.Text1.SelStartX = FoundX
  409.         frmMDI.ActiveForm.Text1.SelEndY = FoundY
  410.         frmMDI.ActiveForm.Text1.SelEndX = FoundX + Len(FindText)
  411.         frmMDI.ActiveForm.Text1.Redraw = True
  412.  
  413.         ' If we are searching from the beginning of selected scope
  414.         ' and we found something then start from the cursor if the
  415.         ' search is repeated (otherwise the search will just start
  416.         ' over from the beginning of the selected scope)...
  417.         If BeginScope Then gBeginScope = False
  418.  
  419.         ' If the text is supposed to be replaced then call the replace
  420.         ' confirmation form
  421.         If fReplace = True Then
  422.             If gfRecursiveSearch = 2 Then ' replace all
  423.                 frmMDI.ActiveForm.Text1.SelText = gNewText
  424.                 'frmMDI.ActiveForm.Text1.Redraw = False
  425.                 'SendKeys gNewText, True ' replace found text
  426.                 'frmMDI.ActiveForm.Text1.Redraw = True
  427.             Else
  428.                 gfRecursiveSearch = 0' no operation
  429.                 frmReplaceConfirm.Show 1 'modal
  430.             End If
  431.             If 0 < gfRecursiveSearch Then FindIt = gfRecursiveSearch
  432.         End If
  433.     Else
  434.         If fReplace = False Or gfRecursiveSearch <> 2 Then
  435.             Dim Msg As String, response As Integer
  436.             Msg = "Cannot find " & Chr(34) & TargetText & Chr(34)
  437.             response = MsgBox(Msg, 0, App.Title)
  438.         End If
  439.         gfRecursiveSearch = 0' no operation
  440.     End If
  441.  
  442.     UpdateStatusLine
  443.  
  444. End Function
  445.  
  446. Sub FindNextProc ()
  447.  
  448.     If 0 < Len(gTargetText) Then
  449.         Do
  450.             Dim FoundIt As Integer
  451.             ' repeat the last find
  452.             FoundIt = FindIt(gTargetText, gMatchCase, gWholeWordOnly, gUpDirection, gBeginScope, gNewText, gfReplace, True)
  453.             If FoundIt <= 0 Then Exit Do
  454.         Loop
  455.     Else
  456.         FindProc
  457.     End If
  458. End Sub
  459.  
  460. Sub FindProc ()
  461.  
  462.     ' 1st, before displaying the dialog that collects search parameters,
  463.     ' initialize the text that will be displayed in the Find form's
  464.     ' combo box...
  465.     If frmMDI.ActiveForm!Text1.SelMark <> 0 And frmMDI.ActiveForm!Text1.SelStartY = frmMDI.ActiveForm!Text1.SelEndY Then
  466.         Dim start As Long, length As Long
  467.         start = frmMDI.ActiveForm!Text1.SelStartX
  468.         length = frmMDI.ActiveForm!Text1.SelEndX - start
  469.         frmMDI.ActiveForm!Text1.TextIndex = frmMDI.ActiveForm!Text1.SelStartY
  470.         frmFind!comboText.Text = RTrim(Mid(frmMDI.ActiveForm!Text1.Text, start, length))
  471.     Else
  472.         frmFind!comboText.Text = gTargetText
  473.     End If
  474.     gFirstTime = True
  475.  
  476.     ' Collect search parameters.  After the user presses the OK button
  477.     ' the Find dialog calls FindIt..
  478.     frmFind.Show
  479. End Sub
  480.  
  481. Sub FlipInsertMode ()
  482.     If gfInsertMode = True Then
  483.         gfInsertMode = False
  484.     Else
  485.         gfInsertMode = True
  486.     End If
  487.     frmMDI.ActiveForm.Text1.InsertMode = gfInsertMode
  488.  
  489.     UpdateStatusLine
  490. End Sub
  491.  
  492. Sub GetRecentFiles ()
  493.   Dim RetVal, key, I, J
  494.   Dim IniString As String
  495.  
  496.   ' This variable must be large enough to hold the return string
  497.   ' from the GetPrivateProfileString API.
  498.   IniString = String(255, 0)
  499.  
  500.   ' Get recent file strings from EMEDIT.INI
  501.   For I = 1 To 4
  502.     key = "RecentFile" & I
  503.     RetVal = GetPrivateProfileString("Recent Files", key, "Not Used", IniString, Len(IniString), "EMEDIT.INI")
  504.     If RetVal And Left(IniString, 8) <> "Not Used" Then
  505.       ' Update the MDI form's menu.
  506.       frmMDI.mnuRecentFile(0).Visible = True
  507.       frmMDI.mnuRecentFile(I).Caption = IniString
  508.       frmMDI.mnuRecentFile(I).Visible = True
  509.   
  510.       ' Iterate through all the notepads and update each menu.
  511.       For J = 1 To UBound(document)
  512.         If Not FState(J).Deleted Then
  513.           document(J).mnuRecentFile(0).Visible = True
  514.           document(J).mnuRecentFile(I).Caption = IniString
  515.           document(J).mnuRecentFile(I).Visible = True
  516.         End If
  517.       Next J
  518.     End If
  519.   Next I
  520.  
  521. End Sub
  522.  
  523. Sub InitMDINOTE ()
  524.  
  525.     'Initialize document form arrays, and show first document.
  526. '    ReDim document(1)
  527. '    ReDim FState(1)
  528. '    document(1).Tag = 1
  529. '    document(1).Show
  530.  
  531.     gfInsertMode = True ' default is to insert text
  532.     gfBlockType = 1 'block type = Stream
  533. End Sub
  534.  
  535. Function IsBlankString (DaString As String) As Integer
  536.     Dim DaStringLen As Long, I As Long
  537.     DaStringLen = Len(DaString)
  538.     IsBlankString = True
  539.     For I = 1 To DaStringLen
  540.         If Mid(DaString, I, 1) <> " " And Mid(DaString, I, 1) <> Chr(9) Then
  541.             IsBlankString = False
  542.             Exit For
  543.         End If
  544.     Next
  545. End Function
  546.  
  547. Function IsWholeWord (SourceText As String, FoundX As Long, FoundLength As Long) As Integer
  548.     Dim BeginWholeWord As Integer
  549.     IsWholeWord = False
  550.     If FoundX <= 1 Then
  551.         BeginWholeWord = True
  552.     ElseIf IsBlankString(Mid(SourceText, FoundX - 1, 1)) Then
  553.         BeginWholeWord = True
  554.     End If
  555.     
  556.     If BeginWholeWord Then
  557.         If Len(SourceText) <= FoundX + FoundLength Then
  558.             IsWholeWord = True
  559.         ElseIf IsBlankString(Mid(SourceText, FoundX + FoundLength, 1)) Then
  560.             IsWholeWord = True
  561.         End If
  562.     End If
  563. End Function
  564.  
  565. Sub OptionsToolbarProc (CurrentForm As Form)
  566.     CurrentForm.mnuOToolbar.Checked = Not CurrentForm.mnuOToolbar.Checked
  567.     If TypeOf CurrentForm Is MDIForm Then
  568.     Else
  569.         frmMDI.mnuOToolbar.Checked = CurrentForm.mnuOToolbar.Checked
  570.     End If
  571.     If CurrentForm.mnuOToolbar.Checked Then
  572.         frmMDI.picToolbar.Visible = True
  573.     Else
  574.         frmMDI.picToolbar.Visible = False
  575.     End If
  576. End Sub
  577.  
  578. Sub ReleaseDocument (fIndex As Integer)
  579.     FState(fIndex).Deleted = True
  580. End Sub
  581.  
  582. Sub ReplaceProc ()
  583.     ' 1st, before displaying the dialog that collects search parameters,
  584.     ' initialize the text that will be displayed in the Find form's
  585.     ' combo box...
  586.     If frmMDI.ActiveForm!Text1.SelMark <> 0 And frmMDI.ActiveForm!Text1.SelStartY = frmMDI.ActiveForm!Text1.SelEndY Then
  587.         Dim start As Long, length As Long
  588.         start = frmMDI.ActiveForm!Text1.SelStartX
  589.         length = frmMDI.ActiveForm!Text1.SelEndX - start
  590.         frmMDI.ActiveForm!Text1.TextIndex = frmMDI.ActiveForm!Text1.SelStartY
  591.         frmReplace!comboText.Text = RTrim(Mid(frmMDI.ActiveForm!Text1.Text, start, length))
  592.     Else
  593.         frmReplace!comboText.Text = gTargetText
  594.     End If
  595.     gFirstTime = True
  596.  
  597.     ' Collect search parameters.  After the user presses the OK button
  598.     ' the Find dialog calls FindIt..
  599.     frmReplace.Show
  600. End Sub
  601.  
  602. Sub SetBlockType (fBlockType As Integer)
  603.     If fBlockType = gfBlockType Then
  604.       Exit Sub
  605.     End If
  606.     On Error GoTo SetBlockTypeError
  607.     frmMDI.ActiveForm.Text1.SelDefaultType = fBlockType
  608.     gfBlockType = fBlockType
  609.     GoTo EndSetBlockType
  610. SetBlockTypeError:
  611.     DisplayError
  612.     Resume EndSetBlockType:
  613. EndSetBlockType:
  614.     
  615. End Sub
  616.  
  617. Sub SetFontProc ()
  618.     'set cancel to true
  619.     frmMDI.CMFontDialog.CancelError = True
  620.     On Error GoTo SetFontErrHandler
  621.  
  622.     ' set the CF_BOTH and CF_EFFECTS flags
  623.     frmMDI.CMFontDialog.Flags = &H3& Or &H100&
  624.     frmMDI.CMFontDialog.FontName = frmMDI.ActiveForm.Text1.FontName
  625.     frmMDI.CMFontDialog.FontSize = frmMDI.ActiveForm.Text1.FontSize
  626.     frmMDI.CMFontDialog.FontBold = frmMDI.ActiveForm.Text1.FontBold
  627.     frmMDI.CMFontDialog.FontItalic = frmMDI.ActiveForm.Text1.FontItalic
  628.     frmMDI.CMFontDialog.FontUnderLine = frmMDI.ActiveForm.Text1.FontUnderline
  629.     frmMDI.CMFontDialog.FontStrikeThru = frmMDI.ActiveForm.Text1.FontStrikethru
  630.     frmMDI.CMFontDialog.Color = frmMDI.ActiveForm.Text1.ForeColor
  631.  
  632.     'display the dialog box
  633.     frmMDI.CMFontDialog.Action = 4
  634.  
  635.     'set the properties according to the user's selections...
  636.     frmMDI.ActiveForm.Text1.Visible = False
  637.     frmMDI.ActiveForm.Text1.FontName = frmMDI.CMFontDialog.FontName
  638.     frmMDI.ActiveForm.Text1.FontSize = frmMDI.CMFontDialog.FontSize
  639.     frmMDI.ActiveForm.Text1.FontBold = frmMDI.CMFontDialog.FontBold
  640.     frmMDI.ActiveForm.Text1.FontItalic = frmMDI.CMFontDialog.FontItalic
  641.     frmMDI.ActiveForm.Text1.FontUnderline = frmMDI.CMFontDialog.FontUnderLine
  642.     frmMDI.ActiveForm.Text1.FontStrikethru = frmMDI.CMFontDialog.FontStrikeThru
  643.     frmMDI.ActiveForm.Text1.ForeColor = frmMDI.CMFontDialog.Color
  644.     frmMDI.ActiveForm.Text1.Visible = True
  645.  
  646. SetFontErrHandler: ' user pressed cancel button
  647.     Exit Sub
  648. End Sub
  649.  
  650. Sub UpdateComboList (comboCtrl As ComboBox, strTxt As String)
  651. ' If the given string does not exist in the control then
  652. '   Add the string to the beginning of the control's list
  653. ' otherwise
  654. '   Move the string to the beginning of the string's list
  655.     If strTxt <> "" Then
  656.     
  657.         Dim fTxtExists As Integer
  658.         fTxtExists = False
  659.     
  660.         'check to see if the given string is alreay in the list...
  661.         If 0 < comboCtrl.ListCount Then
  662.             Dim I As Integer
  663.             For I = 0 To comboCtrl.ListCount - 1
  664.                 If comboCtrl.List(I) = strTxt Then
  665.                     If I = 0 Then
  666.                         fTxtExists = True
  667.                     Else
  668.                         ' The string exists in the list, so move it to the top
  669.                         ' of the list if necessary
  670.                         comboCtrl.RemoveItem I
  671.                     End If
  672.                     Exit For
  673.                 End If
  674.             Next
  675.         End If
  676.     
  677.         'if not already in list then add string to top of list...
  678.         If fTxtExists = False Then
  679.             comboCtrl.AddItem strTxt, 0
  680.         End If
  681.     End If
  682. End Sub
  683.  
  684. Sub UpdateStatusLine ()
  685.     
  686.     'Hide toolbar edit buttons if no notepad windows
  687.     If Not AnyPadsLeft() Then
  688.         frmMDI!labelInsert = ""
  689.         frmMDI!labelPosition = ""
  690.     Else
  691.         If gfInsertMode = False Then
  692.             frmMDI.labelInsert = "Overwrite"
  693.         Else
  694.             frmMDI.labelInsert = "Insert"
  695.         End If
  696.  
  697.         Dim xpos As String, ypos As String, ysize As String
  698.         xpos = CStr(frmMDI.ActiveForm.Text1.CaretX)
  699.         ypos = CStr(frmMDI.ActiveForm.Text1.CaretY)
  700.         ysize = CStr(frmMDI.ActiveForm.Text1.Count)
  701.         frmMDI.labelPosition = "Line=" & ypos & " of " & ysize & " Column=" & xpos
  702.     End If
  703.  
  704. End Sub
  705.  
  706. Sub UpdateToolBar ()
  707.     
  708.     'Hide toolbar edit buttons if no notepad windows
  709.     If Not AnyPadsLeft() Then
  710.         frmMDI!imgCutButton.Visible = False
  711.         frmMDI!imgCopyButton.Visible = False
  712.         frmMDI!imgPasteButton.Visible = False
  713.         frmMDI!imgStreamButton.Visible = False
  714.         frmMDI!imgColumnButton.Visible = False
  715.         frmMDI!imgLineButton.Visible = False
  716.         frmMDI!imgUndoButton.Visible = False
  717.         frmMDI!imgLookButton.Visible = False
  718.         frmMDI!imgNextButton.Visible = False
  719.     End If
  720.  
  721.     Select Case gfBlockType
  722.     Case 0 'none
  723.         frmMDI.imgStreamButton.Picture = frmMDI.imgStreamButtonUp.Picture
  724.         frmMDI.imgLineButton.Picture = frmMDI.imgLineButtonUp.Picture
  725.         frmMDI.imgColumnButton.Picture = frmMDI.imgColumnButtonUp.Picture
  726.     Case 1 'stream block
  727.         frmMDI.imgStreamButton.Picture = frmMDI.imgStreamButtonPushed.Picture
  728.         frmMDI.imgLineButton.Picture = frmMDI.imgLineButtonUp.Picture
  729.         frmMDI.imgColumnButton.Picture = frmMDI.imgColumnButtonUp.Picture
  730.     Case 2 'line block
  731.         frmMDI.imgStreamButton.Picture = frmMDI.imgStreamButtonUp.Picture
  732.         frmMDI.imgLineButton.Picture = frmMDI.imgLineButtonPushed.Picture
  733.         frmMDI.imgColumnButton.Picture = frmMDI.imgColumnButtonUp.Picture
  734.     Case 3 'column block
  735.         frmMDI.imgStreamButton.Picture = frmMDI.imgStreamButtonUp.Picture
  736.         frmMDI.imgLineButton.Picture = frmMDI.imgLineButtonUp.Picture
  737.         frmMDI.imgColumnButton.Picture = frmMDI.imgColumnButtonPushed.Picture
  738.     End Select
  739.  
  740.     If AnyPadsLeft() Then
  741.         ' Make sure toolbar edit buttons are visible
  742.         frmMDI!imgCutButton.Visible = True
  743.         frmMDI!imgCopyButton.Visible = True
  744.         frmMDI!imgPasteButton.Visible = True
  745.         frmMDI!imgStreamButton.Visible = True
  746.         frmMDI!imgColumnButton.Visible = True
  747.         frmMDI!imgLineButton.Visible = True
  748.         'frmMDI!imgUndoButton.Visible = True
  749.         frmMDI!imgLookButton.Visible = True
  750.         frmMDI!imgNextButton.Visible = True
  751.     End If
  752.  
  753. End Sub
  754.  
  755. Sub WriteRecentFiles (OpenFileName)
  756.   Dim I, J, key, RetVal
  757.   Dim IniString As String
  758.   IniString = String(255, 0)
  759.  
  760.   ' Copy RecentFile1 to RecentFile2, etc.
  761.   For I = 3 To 1 Step -1
  762.     key = "RecentFile" & I
  763.     RetVal = GetPrivateProfileString("Recent Files", key, "Not Used", IniString, Len(IniString), "EMEDIT.INI")
  764.     If RetVal And Left(IniString, 8) <> "Not Used" Then
  765.       key = "RecentFile" & (I + 1)
  766.       RetVal = WritePrivateProfileString("Recent Files", key, IniString, "EMEDIT.INI")
  767.     End If
  768.   Next I
  769.   
  770.   ' Write openfile to first Recent File.
  771.     RetVal = WritePrivateProfileString("Recent Files", "RecentFile1", OpenFileName, "EMEDIT.INI")
  772.  
  773. End Sub
  774.  
  775.