' *****************************************************************************
'
'  NOTE: This file is client side VBScript. 
'
'  The sample code shows how to create a simple context sensitive button
'
' *****************************************************************************
'

' Suppress errors in case ActiveXEditing.vbs is not available.
On Error Resume Next


Call EnableCompatibleToolbarHooks

'
' -----------------------------------------------------------------------------
'
'	This is the hook function being called when the Toolbar is initialized for the 
'  first time. 
'   The custom code here can add or remove toolbar buttons.
'
'	@pToolbarInterface [in] - Toolbar interface object that can be used to create
'                             button or comboboxes.
'
' sample implementation that creates a new toolbar and adds one button with the id 
' "TestButton" to it:
'
'	Dim pMyTest
'	Set pMyTest = document.ToolbarInterface.Toolbars.CreateToolbar("MyTest" )
'
'	Call pMyTest.AddButton( "TestButton", "", "undo.gif", "TestButton" )
'
'
' -----------------------------------------------------------------------------

Sub OnToolbarInitialize( ByVal pToolbarInterface )
	Dim CustomToolbar
	Set CustomToolbar = document.ToolbarInterface.Toolbars.CreateToolbar("CustomToolbar")
	Call CustomToolbar.AddButton("TableCellProperties", "", "TableCellProperties.gif", "Table/Cell Properties")
	Call CustomToolbar.AddButton("RowInsert", "", "InsertRow.gif", "Insert Row")
	Call CustomToolbar.AddButton("RowDelete", "", "DeleteRow.gif", "Delete Row")
	Call CustomToolbar.AddButton("ColumnInsert", "", "InsertColumn.gif", "Insert Column")
	Call CustomToolbar.AddButton("ColumnDelete", "", "DeleteColumn.gif", "Delete Column")
End Sub

' -----------------------------------------------------------------------------
'
'	This hook is called for each placeholder, and is used to initialize the state
'	for that specific placeholder. The toolbar state will already be initialized to
'	its default state.
'
'	@strPlaceholderName [in] - The name of the placeholder we are initializing for
'
'	@pState [in] - The toolbar state of this toolbar. The toolbar state keeps track
'					of the clicked/disabled state for the toolbar for this placeholder.
'
' sample implementation that enables our button only if the InsertTable button is enabled 
' as well:
'
'	If (pState.Item("InsertTable").Allowed = True) Then
'		pState.Item("TestButton").Allowed = True
'	End If
' -----------------------------------------------------------------------------

Sub OnToolbarStateInitialize( ByVal strPlaceholderName, ByVal pState )
	If (pState.Item("Bold").Allowed = True) Then
		pState.Item("TableCellProperties").Allowed = True
		pState.Item("RowInsert").Allowed = True
		pState.Item("ColumnInsert").Allowed = True
		pState.Item("RowDelete").Allowed = True
		pState.Item("ColumnDelete").Allowed = True
	Else
		pState.Item("TableCellProperties").Allowed = False
		pState.Item("RowInsert").Allowed = False
		pState.Item("ColumnInsert").Allowed = False
		pState.Item("RowDelete").Allowed = False
		pState.Item("ColumnDelete").Allowed = False		
	End If
End Sub

' -----------------------------------------------------------------------------
'
'	This is the hook function being called when the toolbar state should be
'	updated because there is a change of state or context in the ActiveX
'	placeholder.
'
'	@pActiveHtmlEditor [in] - The currently active DHTML control
'
'	@bEditingSource [in] - TRUE if we are currently in HTML Source Mode
'
' sample implementation that only enables the test button in non-HTML edit mode
'
'	If bEditingSource Then
'		pActiveHtmlEditor.ToolbarState.Item("TestButton").Enabled = False
'	Else
'		pActiveHtmlEditor.ToolbarState.Item("TestButton").Enabled = True
'	End If
' -----------------------------------------------------------------------------

Sub OnToolbarUpdate( ByVal pActiveHtmlEditor, ByVal bEditingSource )
	If bEditingSource Then
		pActiveHtmlEditor.ToolbarState.Item("TableCellProperties").Enabled = False
		pActiveHtmlEditor.ToolbarState.Item("RowInsert").Enabled = False
		pActiveHtmlEditor.ToolbarState.Item("ColumnInsert").Enabled = False
		pActiveHtmlEditor.ToolbarState.Item("RowDelete").Enabled = False
		pActiveHtmlEditor.ToolbarState.Item("ColumnDelete").Enabled = False
	Else
		pActiveHtmlEditor.ToolbarState.Item("TableCellProperties").Enabled = True
		pActiveHtmlEditor.ToolbarState.Item("RowInsert").Enabled = True
		pActiveHtmlEditor.ToolbarState.Item("ColumnInsert").Enabled = True
		pActiveHtmlEditor.ToolbarState.Item("RowDelete").Enabled = True
		pActiveHtmlEditor.ToolbarState.Item("ColumnDelete").Enabled = True
	End If
End Sub

' -----------------------------------------------------------------------------
'
'	This is the hook function being called when a button is clicked in the 
'	ActiveX toolbar.
'
'	@pActiveHtmlEditor [in] - The currently active DHTML edit control
'
'	@bstrId [in] - The ID of the button or combo box that was clicked on
'
'	@pItem [in] - The item that was clicked on
'
'	@bEditingSource [in] - TRUE if we are currently in HTML Source Mode
'
' sample implementation that shows a message box and makes the current text bold:
'
'	Select Case bstrId
'
'		Case "TestButton"
'			Call MsgBox( "hello!" )
'			pActiveHtmlEditor.dom.execCommand "Bold"
'
'	End Select
' -----------------------------------------------------------------------------

Sub OnToolbarEvent( Byval pActiveHtmlEditor, ByVal bstrId, ByVal pItem, ByVal bEditingSource )

	Select Case bstrId
		Case "TableCellProperties"
			Call TableOrCellProperties(pActiveHtmlEditor.DOM)
		Case "RowInsert"
			Call RowInsert(pActiveHtmlEditor.DOM)
		Case "ColumnInsert"
			Call ColumnInsert(pActiveHtmlEditor.DOM)
		Case "RowDelete"
			Call RowDelete(pActiveHtmlEditor.DOM)
		Case "ColumnDelete"
			Call ColumnDelete(pActiveHtmlEditor.DOM)
	End Select
End Sub
