home *** CD-ROM | disk | FTP | other *** search
/ On Hand / On_Hand_From_Softbank_1994_Release_2_Disc_2_1994.iso / 00202 / s / disk1 / mdinote.ba_ / mdinote.bin
Text File  |  1993-04-28  |  7KB  |  230 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. Type FormState
  10.     Deleted As Integer
  11.     Dirty As Integer
  12.     Color As Long
  13. End Type
  14. Global FState()  As FormState
  15. Global Document() As New frmNotePad
  16. Global gFindString, gFindCase As Integer, gFindDirection As Integer
  17. Global gCurPos As Integer, gFirstTime As Integer
  18. Global ArrayNum As Integer
  19.  
  20. ' API functions used to read and write to MDINOTE.INI.
  21. ' Used for handling the recent files list.
  22. 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
  23. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String) As Integer
  24.  
  25. Function AnyPadsLeft () As Integer
  26.     Dim i As Integer
  27.  
  28.     ' Cycle throught the document array.
  29.     ' Return True if there is at least one
  30.     ' open document remaining.
  31.     For i = 1 To UBound(Document)
  32.         If Not FState(i).Deleted Then
  33.             AnyPadsLeft = True
  34.             Exit Function
  35.         End If
  36.     Next
  37.  
  38. End Function
  39.  
  40. Sub CenterForm (frmParent As Form, frmChild As Form)
  41. ' This procedure centers a child form over a parent form.
  42. ' Calling this routine loads the dialog. Use the Show method
  43. ' to display the dialog after calling this routine ( ie MyFrm.Show 1)
  44.  
  45. Dim l, t
  46.   ' get left offset
  47.   l = frmParent.Left + ((frmParent.Width - frmChild.Width) / 2)
  48.   If (l + frmChild.Width > screen.Width) Then
  49.     l = screen.Width = frmChild.Width
  50.   End If
  51.  
  52.   ' get top offset
  53.   t = frmParent.Top + ((frmParent.Height - frmChild.Height) / 2)
  54.   If (t + frmChild.Height > screen.Height) Then
  55.     t = screen.Height - frmChild.Height
  56.   End If
  57.  
  58.   ' center the child formfv
  59.   frmChild.Move l, t
  60.  
  61. End Sub
  62.  
  63. Sub EditCopyProc ()
  64.     ' Copy selected text to Clipboard.
  65.     ClipBoard.SetText frmMDI.ActiveForm.ActiveControl.SelText
  66. End Sub
  67.  
  68. Sub EditCutProc ()
  69.     ' Copy selected text to Clipboard.
  70.     ClipBoard.SetText frmMDI.ActiveForm.ActiveControl.SelText
  71.     ' Delete selected text.
  72.     frmMDI.ActiveForm.ActiveControl.SelText = ""
  73. End Sub
  74.  
  75. Sub EditPasteProc ()
  76.     ' Place text from Clipboard into active control.
  77.     frmMDI.ActiveForm.ActiveControl.SelText = ClipBoard.GetText()
  78. End Sub
  79.  
  80. Sub FileNew ()
  81.     Dim fIndex As Integer
  82.  
  83.     fIndex = FindFreeIndex()
  84.     Document(fIndex).Tag = fIndex
  85.     Document(fIndex).Caption = "Untitled:" & fIndex
  86.     Document(fIndex).Show
  87.  
  88.     ' Make sure toolbar edit buttons are visible
  89.     frmMDI!imgCutButton.Visible = True
  90.     frmMDI!imgCopyButton.Visible = True
  91.     frmMDI!imgPasteButton.Visible = True
  92.     
  93. End Sub
  94.  
  95. Function FindFreeIndex () As Integer
  96.     Dim i As Integer
  97.     Dim ArrayCount As Integer
  98.  
  99.     ArrayCount = UBound(Document)
  100.  
  101.     ' Cycle throught the document array. If one of the
  102.     ' documents has been deleted, then return that
  103.     ' index.
  104.     For i = 1 To ArrayCount
  105.         If FState(i).Deleted Then
  106.             FindFreeIndex = i
  107.             FState(i).Deleted = False
  108.             Exit Function
  109.         End If
  110.     Next
  111.  
  112.     ' If none of the elements in the document array have
  113.     ' been deleted, then increment the document and the
  114.     ' state arrays by one and return the index to the
  115.     ' new element.
  116.  
  117.     ReDim Preserve Document(ArrayCount + 1)
  118.     ReDim Preserve FState(ArrayCount + 1)
  119.     FindFreeIndex = UBound(Document)
  120. End Function
  121.  
  122. Sub FindIt ()
  123.     Dim start, pos, findstring, sourcestring, msg, response, Offset
  124.     
  125.     If (gCurPos = frmMDI.ActiveForm.ActiveControl.SelStart) Then
  126.         Offset = 1
  127.     Else
  128.         Offset = 0
  129.     End If
  130.  
  131.     If gFirstTime Then Offset = 0
  132.  
  133.     start = frmMDI.ActiveForm.ActiveControl.SelStart + Offset
  134.         
  135.     If gFindCase Then
  136.         findstring = gFindString
  137.         sourcestring = frmMDI.ActiveForm.ActiveControl.Text
  138.     Else
  139.         findstring = UCase(gFindString)
  140.         sourcestring = UCase(frmMDI.ActiveForm.ActiveControl.Text)
  141.     End If
  142.             
  143.     If gFindDirection = 1 Then
  144.         pos = InStr(start + 1, sourcestring, findstring)
  145.     Else
  146.         For pos = start - 1 To 0 Step -1
  147.             If pos = 0 Then Exit For
  148.             If Mid(sourcestring, pos, Len(findstring)) = findstring Then Exit For
  149.         Next
  150.     End If
  151.  
  152.     ' If string is found
  153.     If pos Then
  154.         frmMDI.ActiveForm.ActiveControl.SelStart = pos - 1
  155.         frmMDI.ActiveForm.ActiveControl.SelLength = Len(findstring)
  156.     Else
  157.         msg = "Cannot find " & Chr(34) & gFindString & Chr(34)
  158.         response = MsgBox(msg, 0, App.Title)
  159.     End If
  160.     
  161.     gCurPos = frmMDI.ActiveForm.ActiveControl.SelStart
  162.     gFirstTime = False
  163.  
  164. End Sub
  165.  
  166. Sub GetRecentFiles ()
  167.   Dim retval, key, i, j
  168.   Dim IniString As String
  169.  
  170.   ' This variable must be large enough to hold the return string
  171.   ' from the GetPrivateProfileString API.
  172.   IniString = String(255, 0)
  173.  
  174.   ' Get recent file strings from MDINOTE.INI
  175.   For i = 1 To 4
  176.     key = "RecentFile" & i
  177.     retval = GetPrivateProfileString("Recent Files", key, "Not Used", IniString, Len(IniString), "MDINOTE.INI")
  178.     If retval And Left(IniString, 8) <> "Not Used" Then
  179.       ' Update the MDI form's menu.
  180.       frmMDI.mnuRecentFile(0).Visible = True
  181.       frmMDI.mnuRecentFile(i).Caption = IniString
  182.       frmMDI.mnuRecentFile(i).Visible = True
  183.   
  184.       ' Iterate through all the notepads and update each menu.
  185.       For j = 1 To UBound(Document)
  186.         If Not FState(j).Deleted Then
  187.           Document(j).mnuRecentFile(0).Visible = True
  188.           Document(j).mnuRecentFile(i).Caption = IniString
  189.           Document(j).mnuRecentFile(i).Visible = True
  190.         End If
  191.       Next j
  192.     End If
  193.   Next i
  194.  
  195. End Sub
  196.  
  197. Sub OptionsToolbarProc (CurrentForm As Form)
  198.     CurrentForm.mnuOToolbar.Checked = Not CurrentForm.mnuOToolbar.Checked
  199.     If TypeOf CurrentForm Is MDIForm Then
  200.     Else
  201.         frmMDI.mnuOToolbar.Checked = CurrentForm.mnuOToolbar.Checked
  202.     End If
  203.     If CurrentForm.mnuOToolbar.Checked Then
  204.         frmMDI.picToolbar.Visible = True
  205.     Else
  206.         frmMDI.picToolbar.Visible = False
  207.     End If
  208. End Sub
  209.  
  210. Sub WriteRecentFiles (OpenFileName)
  211.   Dim i, j, key, retval
  212.   Dim IniString As String
  213.   IniString = String(255, 0)
  214.  
  215.   ' Copy RecentFile1 to RecentFile2, etc.
  216.   For i = 3 To 1 Step -1
  217.     key = "RecentFile" & i
  218.     retval = GetPrivateProfileString("Recent Files", key, "Not Used", IniString, Len(IniString), "MDINOTE.INI")
  219.     If retval And Left(IniString, 8) <> "Not Used" Then
  220.       key = "RecentFile" & (i + 1)
  221.       retval = WritePrivateProfileString("Recent Files", key, IniString, "MDINOTE.INI")
  222.     End If
  223.   Next i
  224.   
  225.   ' Write openfile to first Recent File.
  226.     retval = WritePrivateProfileString("Recent Files", "RecentFile1", OpenFileName, "MDINOTE.INI")
  227.  
  228. End Sub
  229.  
  230.