﻿Imports FarPoint.Win.Spread
Imports FarPoint.Win.Spread.CellType
Imports FarPoint.Win.Spread.Dialogs
Imports Spread.Common.Features.Spread.Common.Features.Sample
Imports System
Imports System.IO
Imports System.Windows.Forms

Namespace Spread.Worksheet.Features
    Public Partial Class RichTextEdit
        Inherits BaseSampleControl
        Public Sub New()
            InitializeComponent()
            _fpSpread.LegacyBehaviors = LegacyBehaviors.None
            _fpSpread.Features.RichTextEdit = RichTextEditMode.On
            _fpSpread.Features.RichText = True
            Using stream = New MemoryStream(My.Resources.RichTextDemo)
                _fpSpread.OpenExcel(stream)
            End Using

            _fpSpread.Features.ExcelCompatibleKeyboardShortcuts = True
            AddHandler _fpSpread.EditModeOn, AddressOf OnSpreadEditModeOn
            AddHandler _fpSpread.EditModeOff, AddressOf _fpSpread_EditModeOff
        End Sub

        Private Sub _fpSpread_EditModeOff(ByVal sender As Object, ByVal e As EventArgs)
            RemoveHandler _fpSpread.EditingControl.KeyDown, AddressOf OnEditingControlKeyDown
        End Sub

        Private Sub OnSpreadEditModeOn(ByVal sender As Object, ByVal e As EventArgs)
            If _fpSpread.EditingControl IsNot Nothing Then AddHandler _fpSpread.EditingControl.KeyDown, AddressOf OnEditingControlKeyDown
        End Sub

        Private Sub OnEditingControlKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
            Dim richTextEditor As IRichTextEditor = Nothing
            If e.Control AndAlso e.Shift AndAlso e.KeyCode = Keys.F Then
                If CSharpImpl.__Assign(richTextEditor, TryCast(_fpSpread.EditingControl, IRichTextEditor)) IsNot Nothing Then
                    BuiltInDialogs.FormatCells(richTextEditor)
                End If
            End If
        End Sub

        Private Class CSharpImpl
            <Obsolete("Please refactor calling code to use normal Visual Basic assignment")>
            Shared Function __Assign(Of T)(ByRef target As T, value As T) As T
                target = value
                Return value
            End Function
        End Class

    End Class
End Namespace


//
// RichTextEdit.Designer.vb
//

Namespace Spread.Worksheet.Features
    Partial Class RichTextEdit
        ''' <summary> 
        ''' Required designer variable.
        ''' </summary>
        Private components As ComponentModel.IContainer = Nothing

        ''' <summary> 
        ''' Clean up any resources being used.
        ''' </summary>
        ''' <paramname="disposing">true if managed resources should be disposed; otherwise, false.</param>
        Protected Sub Dispose(ByVal disposing As Boolean)
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
            MyBase.Dispose(disposing)
        End Sub

#Region "Component Designer generated code"

        ''' <summary> 
        ''' Required method for Designer support - do not modify 
        ''' the contents of this method with the code editor.
        ''' </summary>
        Private Sub InitializeComponent()
            _fpSpread = New FarPoint.Win.Spread.FpSpread()
            _fpSpread_Sheet1 = New FarPoint.Win.Spread.SheetView()
            pnlMain.SuspendLayout()
            CType(_fpSpread, ComponentModel.ISupportInitialize).BeginInit()
            CType(_fpSpread_Sheet1, ComponentModel.ISupportInitialize).BeginInit()
            SuspendLayout()
            ' 
            ' pnlMain
            ' 
            pnlMain.Controls.Add(_fpSpread)
            ' 
            ' _fpSpread
            ' 
            _fpSpread.AccessibleDescription = ""
            _fpSpread.Dock = Windows.Forms.DockStyle.Fill
            _fpSpread.Location = New Drawing.Point(0, 0)
            _fpSpread.Name = "_fpSpread"
            _fpSpread.Sheets.AddRange(New FarPoint.Win.Spread.SheetView() {_fpSpread_Sheet1})
            _fpSpread.Size = New Drawing.Size(477, 487)
            _fpSpread.TabIndex = 1
            ' 
            ' _fpSpread_Sheet1
            ' 
            _fpSpread_Sheet1.Reset()
            _fpSpread_Sheet1.SheetName = "Sheet1"
            ' Formulas and custom names must be loaded with R1C1 reference style
            _fpSpread_Sheet1.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1
            _fpSpread_Sheet1.ColumnFooter.DefaultStyle.BackColor = Drawing.Color.Empty
            _fpSpread_Sheet1.ColumnFooter.DefaultStyle.ForeColor = Drawing.Color.Empty
            _fpSpread_Sheet1.ColumnFooter.DefaultStyle.Locked = False
            _fpSpread_Sheet1.ColumnFooterSheetCornerStyle.BackColor = Drawing.Color.Empty
            _fpSpread_Sheet1.ColumnFooterSheetCornerStyle.ForeColor = Drawing.Color.Empty
            _fpSpread_Sheet1.ColumnFooterSheetCornerStyle.Locked = False
            _fpSpread_Sheet1.ColumnHeader.DefaultStyle.BackColor = Drawing.Color.Empty
            _fpSpread_Sheet1.ColumnHeader.DefaultStyle.ForeColor = Drawing.Color.Empty
            _fpSpread_Sheet1.ColumnHeader.DefaultStyle.Locked = False
            _fpSpread_Sheet1.DefaultStyle.BackColor = Drawing.Color.Empty
            _fpSpread_Sheet1.DefaultStyle.ForeColor = Drawing.Color.Empty
            _fpSpread_Sheet1.DefaultStyle.Locked = False
            _fpSpread_Sheet1.FilterBar.DefaultStyle.BackColor = Drawing.Color.Empty
            _fpSpread_Sheet1.FilterBar.DefaultStyle.ForeColor = Drawing.Color.Empty
            _fpSpread_Sheet1.FilterBar.DefaultStyle.Locked = False
            _fpSpread_Sheet1.FilterBarHeaderStyle.BackColor = Drawing.Color.Empty
            _fpSpread_Sheet1.FilterBarHeaderStyle.ForeColor = Drawing.Color.Empty
            _fpSpread_Sheet1.FilterBarHeaderStyle.Locked = False
            _fpSpread_Sheet1.RowHeader.DefaultStyle.BackColor = Drawing.Color.Empty
            _fpSpread_Sheet1.RowHeader.DefaultStyle.ForeColor = Drawing.Color.Empty
            _fpSpread_Sheet1.RowHeader.DefaultStyle.Locked = False
            _fpSpread_Sheet1.SheetCornerStyle.BackColor = Drawing.Color.Empty
            _fpSpread_Sheet1.SheetCornerStyle.ForeColor = Drawing.Color.Empty
            _fpSpread_Sheet1.SheetCornerStyle.Locked = False
            _fpSpread_Sheet1.SheetCornerStyle.VerticalAlignment = FarPoint.Win.Spread.CellVerticalAlignment.Center
            _fpSpread_Sheet1.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1
            ' 
            ' RichTextEdit
            ' 
            AutoScaleDimensions = New Drawing.SizeF(6F, 13F)
            AutoScaleMode = Windows.Forms.AutoScaleMode.Font
            Name = "Rich Text Edit"
            pnlMain.ResumeLayout(False)
            CType(_fpSpread, ComponentModel.ISupportInitialize).EndInit()
            CType(_fpSpread_Sheet1, ComponentModel.ISupportInitialize).EndInit()
            ResumeLayout(False)

        End Sub

#End Region

        Private _fpSpread As FarPoint.Win.Spread.FpSpread
        Private _fpSpread_Sheet1 As FarPoint.Win.Spread.SheetView
    End Class
End Namespace

