Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Imports FarPoint.Win
Imports FarPoint.Win.Spread
Imports FarPoint.Win.Spread.CellType
Imports FarPoint.Win.Spread.Model
Imports Spread.Common.DataStore
Imports Spread.Common.Features.Spread.Common.Features.Sample

Namespace Features
	Public Partial Class OperationModesDemo
		Inherits BaseSampleControl
		'private MultiOptionCellType _multiOptional = new MultiOptionCellType();
		Public Sub New()
			InitializeComponent()
			InitializeSample()
		End Sub
		Private Sub InitializeSample()
			Dim _multiOptional As New MultiOptionCellType()
			Name = "Selection and Operation Modes"
			spreadMain.Sheets(0).Rows.[Default].Height = 25
			spreadMain.DataSource = New DataService().AccessDataSource.GetNWINDData("Customers")
			sheetViewMain.AlternatingRows(1).BackColor = Color.WhiteSmoke
			sheetViewControl.Cells(0, 0).Locked = True
			sheetViewControl.Cells(0, 0).Text = "OperationMode:"
			_multiOptional.Items = [Enum].GetNames(GetType(OperationMode))
			_multiOptional.Orientation = FarPoint.Win.RadioOrientation.Vertical
			sheetViewControl.Cells(1, 0).CellType = _multiOptional
			sheetViewControl.Cells(1, 0).RowSpan = 5
			sheetViewControl.Cells(1, 0).Value = sheetViewMain.OperationMode
			sheetViewControl.Cells(0, 1).Locked = True
			sheetViewControl.Cells(0, 1).Text = "SelectionBlockOptions:"
			Dim _checkBoxCellType As New CheckBoxCellType()
			_checkBoxCellType.Caption = [Enum].GetName(GetType(SelectionBlockOptions), SelectionBlockOptions.None)
			sheetViewControl.Cells(1, 1).CellType = _checkBoxCellType
			sheetViewControl.Cells(1, 1).Tag = SelectionBlockOptions.None
			sheetViewControl.Cells(1, 1).Value = (spreadMain.SelectionBlockOptions = SelectionBlockOptions.None)
			_checkBoxCellType = New CheckBoxCellType()
			_checkBoxCellType.Caption = [Enum].GetName(GetType(SelectionBlockOptions), SelectionBlockOptions.Cells)
			sheetViewControl.Cells(2, 1).CellType = _checkBoxCellType
			sheetViewControl.Cells(2, 1).Tag = SelectionBlockOptions.Cells
			sheetViewControl.Cells(2, 1).Value = ((spreadMain.SelectionBlockOptions And SelectionBlockOptions.Cells) = SelectionBlockOptions.Cells)
			_checkBoxCellType = New CheckBoxCellType()
			_checkBoxCellType.Caption = [Enum].GetName(GetType(SelectionBlockOptions), SelectionBlockOptions.Rows)
			sheetViewControl.Cells(3, 1).CellType = _checkBoxCellType
			sheetViewControl.Cells(3, 1).Tag = SelectionBlockOptions.Rows
			sheetViewControl.Cells(3, 1).Value = ((spreadMain.SelectionBlockOptions And SelectionBlockOptions.Rows) = SelectionBlockOptions.Rows)
			_checkBoxCellType = New CheckBoxCellType()
			_checkBoxCellType.Caption = [Enum].GetName(GetType(SelectionBlockOptions), SelectionBlockOptions.Columns)
			sheetViewControl.Cells(4, 1).CellType = _checkBoxCellType
			sheetViewControl.Cells(4, 1).Tag = SelectionBlockOptions.Columns
			sheetViewControl.Cells(4, 1).Value = ((spreadMain.SelectionBlockOptions And SelectionBlockOptions.Columns) = SelectionBlockOptions.Columns)
			_checkBoxCellType = New CheckBoxCellType()
			_checkBoxCellType.Caption = [Enum].GetName(GetType(SelectionBlockOptions), SelectionBlockOptions.Sheet)
			sheetViewControl.Cells(5, 1).CellType = _checkBoxCellType
			sheetViewControl.Cells(5, 1).Tag = SelectionBlockOptions.Sheet
			sheetViewControl.Cells(5, 1).Value = ((spreadMain.SelectionBlockOptions And SelectionBlockOptions.Sheet) = SelectionBlockOptions.Sheet)
			sheetViewControl.SetOutlineBorder(New CellRange(1, 1, 5, 1), New LineBorder(Color.Black))
			_multiOptional = New MultiOptionCellType()
			sheetViewControl.Cells(6, 0).Locked = True
			sheetViewControl.Cells(6, 0).Text = "SelectionPolicy:"
			_multiOptional.Items = [Enum].GetNames(GetType(SelectionPolicy))
			_multiOptional.Orientation = FarPoint.Win.RadioOrientation.Vertical
			sheetViewControl.Cells(7, 0).CellType = _multiOptional
			sheetViewControl.Cells(7, 0).Value = sheetViewMain.SelectionPolicy
			_multiOptional = New MultiOptionCellType()
			sheetViewControl.Cells(6, 1).Locked = True
			sheetViewControl.Cells(6, 1).Text = "SelectionUnit:"
			_multiOptional.Items = [Enum].GetNames(GetType(SelectionUnit))
			_multiOptional.Orientation = FarPoint.Win.RadioOrientation.Vertical
			sheetViewControl.Cells(7, 1).CellType = _multiOptional
			sheetViewControl.Cells(7, 1).Value = sheetViewMain.SelectionUnit
			sheetViewControl.Columns(0).Width = 150
			sheetViewControl.Columns(1).Width = 180
			sheetViewControl.Rows(7).Height = 60
			sheetViewControl.HorizontalGridLine = New GridLine(GridLineType.None)
			sheetViewControl.VerticalGridLine = New GridLine(GridLineType.None)
		End Sub

		Private Sub SpreadControl_ButtonClicked(sender As Object, e As EditorNotifyEventArgs)
			If e.Row = 1 AndAlso e.Column = 0 Then
				' OperationMode
				Dim _selectedValue As Object = sheetViewControl.Cells(1, 0).Value
				If TypeOf _selectedValue Is Integer Then
					sheetViewMain.ClearSelection()
					sheetViewMain.OperationMode = CType(_selectedValue, OperationMode)
					If CInt(_selectedValue) > 1 Then
						' disable other options 
						sheetViewControl.Cells(6, 0, 7, 1).Locked = True
						sheetViewControl.Cells(0, 1, 5, 1).Locked = True
					Else
						' enable other options
						sheetViewControl.Cells(6, 0, 7, 1).Locked = False
						sheetViewControl.Cells(0, 1, 5, 1).Locked = False
					End If
				End If
			ElseIf 0 < e.Row AndAlso e.Row < 6 AndAlso e.Column = 1 Then
				' SelectionBlockOptions
				Dim value As Object = sheetViewControl.Cells(e.Row, 1).Value
				Dim isChecked As Boolean = TypeOf value Is Boolean AndAlso CBool(value) = True
				Dim _opt As SelectionBlockOptions = CType(sheetViewControl.Cells(e.Row, 1).Tag, SelectionBlockOptions)
				If isChecked Then
					sheetViewMain.ClearSelection()
					spreadMain.SelectionBlockOptions = If(_opt = 0, _opt, spreadMain.SelectionBlockOptions Or _opt)
					If _opt = 0 Then
						sheetViewControl.Cells(2, 1, 5, 1).Value = False
					Else
						sheetViewControl.Cells(1, 1).Value = False
					End If
				ElseIf _opt > 0 Then
					sheetViewMain.ClearSelection()
					spreadMain.SelectionBlockOptions = spreadMain.SelectionBlockOptions And Not _opt
				End If
			ElseIf e.Row = 7 AndAlso e.Column = 0 Then
				' SelectionPolicy (Normal or Read Only mode only)
				Dim _selectedValue As Object = sheetViewControl.Cells(7, 0).Value
				If TypeOf _selectedValue Is Integer Then
					sheetViewMain.ClearSelection()
					sheetViewMain.SelectionPolicy = CType(_selectedValue, SelectionPolicy)
				End If
			ElseIf e.Row = 7 AndAlso e.Column = 1 Then
				' SelectionUnit (Normal or Read Only mode only)
				Dim _selectedValue As Object = sheetViewControl.Cells(7, 1).Value
				If TypeOf _selectedValue Is Integer Then
					sheetViewMain.ClearSelection()
					sheetViewMain.SelectionUnit = CType(_selectedValue, SelectionUnit)
				End If
			End If
		End Sub
	End Class
End Namespace

'
'OperationModesDemo.Designer.vb
'

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

        ''' <summary> 
        ''' Clean up any resources being used.
        ''' </summary>
        ''' <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        Protected Overloads Sub Dispose(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()
			Me.spreadMain = New FarPoint.Win.Spread.FpSpread()
			Me.sheetViewMain = New FarPoint.Win.Spread.SheetView()
			Me.spreadControl = New FarPoint.Win.Spread.FpSpread()
			Me.sheetViewControl = New FarPoint.Win.Spread.SheetView()
			Me.pnlMain.SuspendLayout()
			Me.pnlControls.SuspendLayout()
			DirectCast(Me.spreadMain, System.ComponentModel.ISupportInitialize).BeginInit()
			DirectCast(Me.sheetViewMain, System.ComponentModel.ISupportInitialize).BeginInit()
			DirectCast(Me.spreadControl, System.ComponentModel.ISupportInitialize).BeginInit()
			DirectCast(Me.sheetViewControl, System.ComponentModel.ISupportInitialize).BeginInit()
			Me.SuspendLayout()
			' 
			' pnlMain
			' 
			Me.pnlMain.Controls.Add(Me.spreadMain)
			' 
			' pnlControls
			' 
			Me.pnlControls.Controls.Add(Me.spreadControl)
			' 
			' spreadMain
			' 
			Me.spreadMain.Dock = System.Windows.Forms.DockStyle.Fill
			Me.spreadMain.Location = New System.Drawing.Point(0, 0)
			Me.spreadMain.Name = "spreadMain"
			Me.spreadMain.Sheets.AddRange(New FarPoint.Win.Spread.SheetView() {Me.sheetViewMain})
			Me.spreadMain.Size = New System.Drawing.Size(477, 487)
			Me.spreadMain.TabIndex = 0
			' 
			' sheetViewMain
			' 
			Me.sheetViewMain.Reset()
			Me.sheetViewMain.SheetName = "Main Sheet"
			' Formulas and custom names must be loaded with R1C1 reference style
			Me.sheetViewMain.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1
			Me.sheetViewMain.ColumnCount = 15
			Me.sheetViewMain.RowCount = 100
			Me.sheetViewMain.ActiveColumnIndex = 1
			Me.sheetViewMain.ActiveRowIndex = 2
			Me.sheetViewMain.Cells.[Get](2, 1).Font = New System.Drawing.Font("Times New Roman", 8.25F)
			Me.sheetViewMain.Columns.[Get](1).Width = 175F
			Me.sheetViewMain.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1
			' 
			' spreadControl
			' 
			Me.spreadControl.DefaultSkin = FarPoint.Win.Spread.DefaultSpreadSkins.[Default]
			Me.spreadControl.Dock = System.Windows.Forms.DockStyle.Fill
			Me.spreadControl.Location = New System.Drawing.Point(0, 0)
			Me.spreadControl.Name = "spreadControl"
			Me.spreadControl.Sheets.AddRange(New FarPoint.Win.Spread.SheetView() {Me.sheetViewControl})
			Me.spreadControl.Size = New System.Drawing.Size(157, 487)
			Me.spreadControl.TabIndex = 0
			AddHandler Me.spreadControl.ButtonClicked, New FarPoint.Win.Spread.EditorNotifyEventHandler(AddressOf Me.SpreadControl_ButtonClicked)
			' 
			' sheetViewControl
			' 
			Me.sheetViewControl.Reset()
			Me.sheetViewControl.SheetName = "Sheet1"
			' Formulas and custom names must be loaded with R1C1 reference style
			Me.sheetViewControl.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1
			Me.sheetViewControl.ColumnCount = 2
			Me.sheetViewControl.RowCount = 8
			Me.sheetViewControl.DefaultStyle.Font = New System.Drawing.Font("Verdana", 8.25F)
			Me.sheetViewControl.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1
			' 
			' OperationModesDemo
			' 
			Me.AutoScaleDimensions = New System.Drawing.SizeF(6F, 13F)
			Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
			Me.Name = "OperationModesDemo"
			Me.pnlMain.ResumeLayout(False)
			Me.pnlControls.ResumeLayout(False)
			DirectCast(Me.spreadMain, System.ComponentModel.ISupportInitialize).EndInit()
			DirectCast(Me.sheetViewMain, System.ComponentModel.ISupportInitialize).EndInit()
			DirectCast(Me.spreadControl, System.ComponentModel.ISupportInitialize).EndInit()
			DirectCast(Me.sheetViewControl, System.ComponentModel.ISupportInitialize).EndInit()
			Me.ResumeLayout(False)

		End Sub

		#End Region

		Private spreadMain As FarPoint.Win.Spread.FpSpread
		Private sheetViewMain As FarPoint.Win.Spread.SheetView
		Private spreadControl As FarPoint.Win.Spread.FpSpread
		Private sheetViewControl As FarPoint.Win.Spread.SheetView
	End Class
End Namespace
