home *** CD-ROM | disk | FTP | other *** search
- Type TextEditBox From TextBox
- Dim FontPanel As New FontDialog
- Dim TextFont As New Font
- Dim SaveAsPanel As New SaveAsDialog
- Dim SearchPanel As New FindDialog
- Dim FilePanel As New OpenDialog
- Dim ChangedFlag As Integer
- Dim txtfile As New TextFile
-
- ' METHODS for object: TextEditBox
- Sub Change()
- ChangedFlag = True
- End Sub
-
- Sub Clear()
- ' Reset the Filename property of the OpenDialog object
- FilePanel.FileName = ""
- Text = ""
- End Sub
-
- Sub Delete()
- SelText = ""
- End Sub
-
- Sub OpenFile()
- ' Set the Title caption of the OpenDialog dialog box
- FilePanel.Title = "Select File"
-
- ' Set the list of file types that can be loaded
- FilePanel.Filter = "Text files (*.txt)|*.txt|Script files (*.bat)|*.bat|Config files (*.ini)|*.ini|All files (*.*)|*.*|"
-
- ' Post the File Open dialog box - should default to current directory
- If FilePanel.Execute = IDCANCEL Then Exit Sub
-
- ' If a filename was picked, then load the text file into the textedit box
- If FilePanel.FileName <> "" Then
- txtfile.FileName = FilePanel.FileName
- Text = txtfile.ContentsAsString
- End If
-
- SetFocus
-
- End Sub
-
- Sub PrintText()
- Dim print_cmd As String
- Dim result As Long
- Declare Function DeleteFile Lib "Kernel32" Alias "DeleteFileA" (ByVal fileName as string) as long
-
- ' This function will basically use the DOS "print" command to print the
- ' current contents of the text edit box - better check to make sure text exits
- If Text = "" Then
- InfoBox.title = "Warning!"
- InfoBox.Message("", "You have not entered any text to be printed. Type some text, and then try again.")
- Exit Sub
- End If
-
- ' Use the FileInfo object to actually save the file to disk
- txtfile.FileName = "C:\temp\prt_file.tmp"
-
- ' Save the text to disk using the SetContentsTo Method
- txtfile.SetContentsTo(Text)
-
- ' File exists now let's print it and remove it in one command
- print_cmd = "print " & txtfile.FileName
- RunProgram(print_cmd, False, False)
- DeleteFile txtfile.FileName
-
- End Sub
-
- Sub Save()
- ' If there is no opened file, then do a SaveAs and update
- ' the Open/Save txtfile object's FileName property
- If txtfile.FileName = "" Then
- ' Call the SaveAs function
- SaveAs
-
- ' Update the FileName property of the txtfile object
- txtfile.FileName = txtfile.FileName
- Else
- ' Save the text to disk using the SetContentsTo Method
- txtfile.SetContentsTo(Text)
- ChangedFlag = False
- End If
- End Sub
-
- Sub SaveAs()
- ' Check to make sure there is something to save
- If Text = "" Then
- InfoBox.title = "Warning!"
- InfoBox.Message("", "You have not entered any text to be saved. Type some text, and then try again.")
- Exit Sub
- End If
-
- ' Configure the SaveAsDialog object - SaveAsDialog will make sure FileName is entered
- SaveAsPanel.FileName = "*.txt"
- SaveAsPanel.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
-
- ' If Cancel Was clicked, do nothing
- If SaveAsPanel.Execute = IDCANCEL Then Exit Sub
- ' Use the FileInfo object to actually save the file to disk
- txtfile.FileName = SaveAsPanel.FileName
-
- ' Save the text to disk using the SetContentsTo Method
- txtfile.SetContentsTo(Text)
- ChangedFlag = False
-
- End Sub
-
- Sub SearchForward()
- ' Hide some items on the FindDialog panel
- SearchPanel.HideMatchCase = "True"
- SearchPanel.HideUpDown = "True"
- SearchPanel.HideWholeWord = "True"
-
- ' #There is a bug with displaying a string in FindDialog.Title
- ' SearchPanel.Title = "Find"
-
- ' If something is selected, make it become your search string
- ' otherwise use the last search string
- If SelLength > 0 Then
- SearchPanel.FindString = SelText
- End If
- SearchPanel.Show
-
- End Sub
-
- Sub SearchNext()
- SearchPanel_Find
- End Sub
-
- Sub SearchPanel_Find()
- Dim loc As Integer
-
- ' This guy is called from the FindDialog Panel
- loc = Instr(SelStart + 1 + SelLength, Text, SearchPanel.FindString)
- If loc Then
- SelStart = loc - 1
- SelLength = Len(SearchPanel.FindString)
- SetFocus
- Else
- InfoBox.Message("", "Cannot find '" & SearchPanel.FindString & "'")
- End If
- End Sub
-
- Sub SelectAll()
- SelStart = 0
- SelLength = Len(Text)
- End Sub
-
- Sub SetFont()
- ' Configure the font panel
- FontPanel.Bold = TextFont.Bold
- FontPanel.FaceName = TextFont.FaceName
- FontPanel.Italic = TextFont.Italic
- FontPanel.Strikethru = TextFont.Strikethru
- FontPanel.Underline = TextFont.Underline
- FontPanel.Color = ForeColor
- FontPanel.Size = TextFont.Size
-
- FontPanel.Execute
-
- ' Set the chosen font attributes
- TextFont.Bold = FontPanel.Bold
- TextFont.FaceName = FontPanel.FaceName
- TextFont.Italic = FontPanel.Italic
- TextFont.Strikethru = FontPanel.Strikethru
- TextFont.Underline = FontPanel.Underline
- ForeColor = FontPanel.Color
- TextFont.Size = FontPanel.Size
- End Sub
-
- Sub SetScrollBars(scroll_type As string)
- ' Set the scrollbars accordingly and the wordwrap property
- Select Case scroll_type
- Case "None", "0"
- ScrollBars = 0
- WordWrap = True
- Case "Horizontal", "1"
- ScrollBars = 1
- WordWrap = False
- Case "Vertical", "2"
- ScrollBars = 2
- WordWrap = True
- Case "Both", "3"
- ScrollBars = 3
- WordWrap = False
- End Select
-
- ' Set focus in the textbox
- SetFocus
-
- End Sub
-
- End Type
-
- Type TextEditMasterForm From SampleMasterForm
- Type TextEditMenuBar From MenuBar
- Dim TextEditFileMenu As New PopupMenu
- Dim TextEditEditMenu As New PopupMenu
- Dim TextEditSearchMenu As New PopupMenu
- Dim TextEditOptionsMenu As New PopupMenu
- Dim OptionsScrollBarMenu As New PopupMenu
- End Type
- Dim txtEditBox As New TextEditBox
-
- ' METHODS for object: TextEditMasterForm
- Sub Activate()
- ' This routine gets called automatically when the form is loaded
- txtEditBox.SetFocus
- End Sub
-
- Sub ClearScrollBarCheckMarks()
- ' Clear any existing checkboxes
- TextEditMenuBar.OptionsScrollBarMenu.CheckItem("ScrollBarNone", 0)
- TextEditMenuBar.OptionsScrollBarMenu.CheckItem("ScrollBarHorizontal", 0)
- TextEditMenuBar.OptionsScrollBarMenu.CheckItem("ScrollBarVertical", 0)
- TextEditMenuBar.OptionsScrollBarMenu.CheckItem("ScrollBarBoth", 0)
- End Sub
-
- Sub EditCopy_Click()
- ' Copy and save the selected text to the CutBuffer
- txtEditBox.Copy
- End Sub
-
- Sub EditCut_Click()
- ' Cut and save the selected text to the clip board
- txtEditBox.Cut
- End Sub
-
- Sub EditDelete_Click()
- ' Remove the currently selected text
- txtEditBox.Delete
- End Sub
-
- Sub EditPaste_Click()
- ' Insert the contents of the clipboard at the current type-in or selection
- txtEditBox.Paste
- End Sub
-
- Sub EditSelectAll_Click()
- ' Select everything in the textbox
- txtEditBox.SelectAll
- End Sub
-
- Function EditSelectAll_Enable ()
- EditSelectAll_Enable = txtEditBox.Text <> ""
- End Function
-
- Sub EditUndo_Click()
- ' Undo the last command
- txtEditBox.Undo
- End Sub
-
- Sub ExitApplication_Click()
- ' Set the contents of the titlebar of the YesNoBox object
- YesNoBox.title = "Quit?"
-
- ' Set the message of the YesNoPrompt object
- YesNoBox.Msg("Ok to quit application?")
-
- ' If the Yes entry was clicked, hide the textedit form
- If YesNoBox.result = 6 Then
- ' Forward to parent
- Dim F Strictly As SampleMasterForm
- F = Me
- F.ExitApplication_Click
- End If
- End Sub
-
- Sub NewEditBox_Click()
- If txtEditBox.ChangedFlag = True Then
- ' Set the contents of the titlebar of the YesNoBox object
- YesNoBox.title = "Save Changes?"
-
- ' Set the message of the YesNoPrompt object
- YesNoBox.Msg("Save your changes before starting a new file?")
-
- ' If the Yes entry was clicked, hide the textedit form
- If YesNoBox.result = 6 Then
- txtEditBox.Save
- End If
- End If
- ' Clear the contents of the text edit box
- txtEditBox.Clear
- ' Clear the contents of the txtfile object
- txtEditBox.txtfile.FileName = ""
-
- txtEditBox.ChangedFlag = False
- txtEditBox.SetFocus
- End Sub
-
- Sub OpenFile_Click()
- ' Call the openfile method of the editbox
- txtEditBox.OpenFile
- txtEditBox.Change
- End Sub
-
- Sub OptionsFont_Click()
- ' Call the textedit box setfont method
- txtEditBox.SetFont
- End Sub
-
- Sub PrintFile_Click()
- ' Call the print text routine of the textedit box
- txtEditBox.PrintText
- End Sub
-
- Function PrintFile_Enable ()
- PrintFile_Enable = txtEditBox.Text <> ""
- End Function
-
- Sub ResetApplication_Click()
- ' Initialize the Scrollbar entries
- TextEditMenuBar.OptionsScrollBarMenu.CheckItem("ScrollBarNone", 1)
- txtEditBox.SetScrollBars(0)
-
- ' Make the textedit box resize to the window size
- TextEditMasterForm.Resize
-
- ' Clear out the textedit box
- txtEditBox.Clear
- txtEditBox.SetFocus
- End Sub
-
- Sub Resize()
- ' Set the size of the text edit box to the size of the form
- txtEditBox.Move 0, 0, ScaleWidth, ScaleHeight
- txtEditBox.Refresh
- End Sub
-
- Sub SaveAsFile_Click()
- ' Call the textedit boxes SaveAs method
- txtEditBox.SaveAs
- End Sub
-
- Sub SaveFile_Click()
- ' Call the textedit box Save method
- txtEditBox.Save
- End Sub
-
- Sub ScrollBarBoth_Click()
- ' If the scrollbar is alreay checked, ignore the command
- If TextEditMenuBar.OptionsScrollBarMenu.ItemIsChecked("ScrollBarBoth") Then
- Exit Sub
- Else
- ' Clear all checkmark entries in the menu
- ClearScrollBarCheckMarks
-
- ' Add a checkmark to the Both entry
- TextEditMenuBar.OptionsScrollBarMenu.CheckItem("ScrollBarBoth", 1)
-
- ' Set the scrollbar property to both
- txtEditBox.SetScrollBars(3)
-
- ' Force the textedit box to resize to the form
- TextEditMasterForm.Resize
-
- End If
- End Sub
-
- Sub ScrollBarHorizontal_Click()
- ' If the scrollbar is alreay checked, ignore the command
- If TextEditMenuBar.OptionsScrollBarMenu.ItemIsChecked("ScrollBarHorizontal") Then
- Exit Sub
- Else
- ' Clear all checkmark entries in the menu
- ClearScrollBarCheckMarks
-
- ' Add a checkmark to the Horizontal entry
- TextEditMenuBar.OptionsScrollBarMenu.CheckItem("ScrollBarHorizontal", 1)
-
- ' Set the scrollbar property to both
- txtEditBox.SetScrollBars(1)
-
- ' Force the textedit box to resize to the form
- TextEditMasterForm.Resize
-
- End If
-
- End Sub
-
- Sub ScrollBarNone_Click()
- ' If the scrollbar is alreay checked, ignore the command
- If TextEditMenuBar.OptionsScrollBarMenu.ItemIsChecked("ScrollBarNone") Then
- Exit Sub
- Else
- ' Clear all checkmark entries in the menu
- ClearScrollBarCheckMarks
-
- ' Add a checkmark to the None entry
- TextEditMenuBar.OptionsScrollBarMenu.CheckItem("ScrollBarNone", 1)
-
- ' Set the scrollbar property to both
- txtEditBox.SetScrollBars(0)
-
- ' Force the textedit box to resize to the form
- TextEditMasterForm.Resize
-
- End If
-
- End Sub
-
- Sub ScrollBarVertical_Click()
- ' If the scrollbar is alreay checked, ignore the command
- If TextEditMenuBar.OptionsScrollBarMenu.ItemIsChecked("ScrollBarVertical") Then
- Exit Sub
- Else
- ' Clear all checkmark entries in the menu
- ClearScrollBarCheckMarks
-
- ' Add a checkmark to the Vertical entry
- TextEditMenuBar.OptionsScrollBarMenu.CheckItem("ScrollBarVertical", 1)
-
- ' Set the scrollbar property to both
- txtEditBox.SetScrollBars(2)
-
- ' Force the textedit box to resize to the form
- TextEditMasterForm.Resize
-
- End If
-
- End Sub
-
- Sub SearchForward_Click()
- ' Call the textedit boxes search function
- txtEditBox.SearchForward
- End Sub
-
- Sub SearchNext_Click()
- ' Call the txtEditBox search next method
- txtEditBox.SearchNext
- End Sub
-
- End Type
-
- Begin Code
- ' Reconstruction commands for object: TextEditBox
- '
- With TextEditBox
- .ForeColor := 128
- .Font := TextEditBox.TextFont
- .Move(0, 0, 0, 0)
- .WordWrap := True
- .MultiLine := True
- .ChangedFlag := 0
- With .FontPanel
- .FaceName := "Times New Roman"
- .Size := 18
- .Bold := True
- .Italic := True
- .Color := 128
- End With 'TextEditBox.FontPanel
- With .TextFont
- .FaceName := "13"
- .Size := 18.000000
- .Bold := True
- .Italic := True
- .Strikethru := False
- End With 'TextEditBox.TextFont
- With .SaveAsPanel
- End With 'TextEditBox.SaveAsPanel
- With .SearchPanel
- End With 'TextEditBox.SearchPanel
- With .FilePanel
- End With 'TextEditBox.FilePanel
- With .txtfile
- End With 'TextEditBox.txtfile
- End With 'TextEditBox
- ' Reconstruction commands for object: TextEditMasterForm
- '
- With TextEditMasterForm
- .Caption := "BOOTCAMP Text Editor Application"
- .Move(3720, 1740, 6930, 5535)
- .MenuBar := TextEditMasterForm.TextEditMenuBar
- .SampleDir := "W:\arsenal\apps\textedit\"
- .SampleName := "textedit"
- With .TextEditMenuBar
-
- .InsertPopup(TextEditMasterForm.TextEditMenuBar.TextEditFileMenu, "&File", -1)
- .InsertPopup(TextEditMasterForm.TextEditMenuBar.TextEditEditMenu, "&Edit", -1)
- .InsertPopup(TextEditMasterForm.TextEditMenuBar.TextEditSearchMenu, "&Search", -1)
- .InsertPopup(TextEditMasterForm.TextEditMenuBar.TextEditOptionsMenu, "&Options", -1)
- With .TextEditFileMenu
-
- .InsertItem("NewEditBox", "&New", -1)
- .InsertItem("OpenFile", "&Open...", -1)
- .InsertItem("SaveFile", "&Save", -1)
- .InsertItem("SaveAsFile", "Save &As...", -1)
- .InsertItem("PrintFile", "&Print", -1)
- .InsertSeparator(-1)
- .InsertItem("ExitApplication", "E&xit", -1)
- End With 'TextEditMasterForm.TextEditMenuBar.TextEditFileMenu
- With .TextEditEditMenu
-
- .InsertItem("EditUndo", "&Undo", -1)
- .InsertSeparator(-1)
- .InsertItem("EditCut", "Cu&t", -1)
- .InsertItem("EditCopy", "&Copy", -1)
- .InsertItem("EditPaste", "&Paste", -1)
- .InsertItem("EditDelete", "&Delete", -1)
- .InsertSeparator(-1)
- .InsertItem("EditSelectAll", "Select &All", -1)
- End With 'TextEditMasterForm.TextEditMenuBar.TextEditEditMenu
- With .TextEditSearchMenu
-
- .InsertItem("SearchForward", "&Find...", -1)
- .InsertItem("SearchNext", "Find &Next", -1)
- End With 'TextEditMasterForm.TextEditMenuBar.TextEditSearchMenu
- With .TextEditOptionsMenu
-
- .InsertItem("OptionsFont", "&Fonts...", -1)
- .InsertPopup(TextEditMasterForm.TextEditMenuBar.OptionsScrollBarMenu, "ScrollBar", -1)
- End With 'TextEditMasterForm.TextEditMenuBar.TextEditOptionsMenu
- With .OptionsScrollBarMenu
-
- .InsertItem("ScrollBarNone", "None", -1)
- .InsertItem("ScrollBarHorizontal", "Horizontal", -1)
- .InsertItem("ScrollBarVertical", "Vertical", -1)
- .InsertItem("ScrollBarBoth", "Both", -1)
- End With 'TextEditMasterForm.TextEditMenuBar.OptionsScrollBarMenu
- End With 'TextEditMasterForm.TextEditMenuBar
- With .txtEditBox
- .ForeColor := 0
- .Font := TextEditMasterForm.txtEditBox.TextFont
- .ZOrder := 1
- .Move(0, 0, 6810, 4845)
- .BorderStyle := "None"
- .ChangedFlag := -1
- With .FontPanel
- .Size := 14
- .Color := 0
- End With 'TextEditMasterForm.txtEditBox.FontPanel
- With .TextFont
- .FaceName := "Courier"
- .Size := 12.000000
- .Bold := True
- .Italic := False
- .Strikethru := False
- End With 'TextEditMasterForm.txtEditBox.TextFont
- With .SaveAsPanel
- .FileName := "W:\arsenal\apps\textedit\spam.txt"
- .Filter := "Text Files (*.txt)"
- .FilterIndex := 1
- End With 'TextEditMasterForm.txtEditBox.SaveAsPanel
- With .SearchPanel
- .FindString := "spam"
- .HideUpDown := True
- .HideMatchCase := True
- .HideWholeWord := True
- End With 'TextEditMasterForm.txtEditBox.SearchPanel
- With .FilePanel
- .Title := "Select File"
- .Filter := "Text files (*.txt)|*.txt|Script files (*.bat)|*.bat|Config files (*.ini)|*.ini|All files (*.*)|*.*|"
- .FilterIndex := 4
- End With 'TextEditMasterForm.txtEditBox.FilePanel
- With .txtfile
- End With 'TextEditMasterForm.txtEditBox.txtfile
- End With 'TextEditMasterForm.txtEditBox
- With .helpfile
- .FileName := "W:\arsenal\apps\textedit\textedit.hlp"
- End With 'TextEditMasterForm.helpfile
- End With 'TextEditMasterForm
- End Code
-