
Option Explicit
dim     AppName         = "Report Preview",     ' application name
        fileName        = ""                    ' current file name
dim DividerLine = "\n\n<<-------------------->>\n\n"

' Main window
dim frameprev = new wxMDIChildFrame( myframe, -1, AppName & " - Reporte",wxPoint(0,0),wxSize(500,300))

'dim tool = new wxToolBar(frameprev, -1)
dim tool1 = frameprev.CreateToolBar(wxTB_HORIZONTAL) 

dim bitmapnew = new wxEmptyBitmap( 0, 0 )
bitmapnew.LoadFile("repBin/new.sbi",wxBITMAP_TYPE_PNG)
dim buttonnew = new wxBitmapButton(tool1, -1, bitmapnew, wxPoint(5,5), wxSize(-1,-1),wxNO_3D)
Connect (buttonnew,-1,wxEVT_COMMAND_BUTTON_CLICKED,"onFileNew")
buttonnew.SetToolTip( "New File")
tool.addControl(buttonnew)

dim bitmapsave = new wxEmptyBitmap( 0, 0 )
bitmapsave.LoadFile("repBin/save.sbi",wxBITMAP_TYPE_PNG)
dim buttonsave = new wxBitmapButton(tool1, -1, bitmapsave, wxPoint(45,5), wxSize(-1,-1),wxNO_3D)
Connect (buttonsave,-1,wxEVT_COMMAND_BUTTON_CLICKED,"onFileSave")
buttonSave.SetToolTip( "Save File")
tool.addControl(buttonsave)

dim bitmappaste = new wxEmptyBitmap( 0, 0 )
bitmappaste.LoadFile("repBin/copy.sbi",wxBITMAP_TYPE_PNG)
dim buttonpaste = new wxBitmapButton(tool1, -1, bitmappaste, wxPoint(95,5), wxSize(-1,-1),wxNO_3D)
Connect (buttonpaste,-1,wxEVT_COMMAND_BUTTON_CLICKED,"onEditCopy")
buttonpaste.SetToolTip( "Paste From Clipboard")
tool.addControl(buttonpaste)

dim bitmapdivider = new wxEmptyBitmap( 0, 0 )
bitmapdivider.LoadFile("repBin/divider.sbi",wxBITMAP_TYPE_gif)
dim buttondivider = new wxBitmapButton(tool1, -1, bitmapdivider, wxPoint(135,5), wxSize(-1,-1),wxNO_3D)
Connect (buttondivider,-1,wxEVT_COMMAND_BUTTON_CLICKED,"onEditInsert")
buttondivider.SetToolTip( "Insert Divider Line")
tool.addControl(buttondivider)

dim bitmapexit = new wxEmptyBitmap( 0, 0 )
bitmapexit.LoadFile("repBin/exit.sbi",wxBITMAP_TYPE_PNG)
dim buttonexit = new wxBitmapButton(tool1, -1, bitmapexit, wxPoint(175,5), wxSize(-1,-1),wxNO_3D)
Connect (buttonexit,-1,wxEVT_COMMAND_BUTTON_CLICKED,"onFileExit1")
buttonexit.SetToolTip( "Exit Program")
tool.addControl(buttonexit)

dim bitmaphelp = new wxEmptyBitmap( 0, 0 )
bitmaphelp.LoadFile("repBin/help.sbi",wxBITMAP_TYPE_PNG)
dim buttonhelp = new wxBitmapButton(tool1, -1, bitmaphelp, wxPoint(215,5), wxSize(-1,-1),wxNO_3D)
//Connect (buttonhelp,-1,wxEVT_COMMAND_BUTTON_CLICKED,"onHelpAbout")
buttonhelp.SetToolTip( "Help")
tool.addControl(buttonhelp)

' Text edit control
dim control = new wxTextCtrl( frameprev, -1, "",wxPoint(0,28),wxSize(492,443), wxTE_MULTILINE | wxTE_LINEWRAP | wxTE_RICH)


' Dialog used for Open/Save/Save As
dim fileDialog = new wxFileDialog( frameprev )



' Common routine
Sub saveAs()
    fileDialog.SetMessage("Save File As")
    fileDialog.SetFilename( fileName )
    fileDialog.SetStyle( wxSAVE )
    If fileDialog.ShowModal() = wxID_OK Then
        fileName = fileDialog.GetFilename()
        control.SaveFile( fileName )
        frameprev.SetTitle( AppName & " - " & fileName )
    End If
End Sub



Sub onFileNew( event )
    If control.IsModified() Then
        Dim dialog = new wxMessageDialog( frameprev, "Save changes first?",
            "Save Changes?", wxYES_NO + wxCENTRE + wxICON_QUESTION )
        Dim result = dialog.ShowModal()


        If result = wxID_YES Then
            If fileName = "" Then
                saveAs()
            Else
                control.SaveFile( fileName )
            End If
        End If
    End If
    control.Clear()
    fileName = ""
    frameprev.SetTitle( AppName & " - Reporte" )
End Sub
Connect( frameprev, wxID_NEW, wxEVT_COMMAND_MENU_SELECTED, "onFileNew" )



Sub onFileSaveAs( event )
    saveAs()
End Sub
Connect( frameprev, wxID_SAVEAS, wxEVT_COMMAND_MENU_SELECTED, "onFileSaveAs" )

Sub onFileSave( event )
    If fileName = "" Then
        onFileSaveAs( event )
    Else
        control.SaveFile( fileName )
    End If
End Sub
Connect( frameprev, wxID_SAVE, wxEVT_COMMAND_MENU_SELECTED, "onFileSave" )


Sub onFileExit1( event )
control.setvalue("")
frameprev.show(FALSE)    
End Sub

Connect( frameprev, wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, "onFileExit1" )
Connect( frameprev, wxEVT_CLOSE_WINDOW, "onFileExit1" )

Sub onEditCopy( event )
    control.Copy()
End Sub
Connect( frameprev, wxID_PASTE, wxEVT_COMMAND_MENU_SELECTED, "onEditCopy" )

Sub onEditInsert( event )
    Control.AppendText(DividerLine)
    Control.ShowPosition(Control.GetInsertionPoint())
End Sub
Connect(frameprev,-1,WxEVT_COMMAND_MENU_SELECTED,"onEditInsert")

Dim ico4 = new wxIconEmpty()
ico4.LoadFile("repBin/ico4.sbi",wxBITMAP_TYPE_PNG)
frameprev.SetIcon(ico4)
control.SetEditable(FALSE)
frameprev.Show(FALSE) 



