' Copyright And Detail -------------------------------------------------------------------------------------
' Name: GNWizardFrameWork.WizardTemplateDesigner
' Author: Gary Noble
' Date: 09/01/2006
'
' Requires: GNWizardFrameWorkTemplateDesigner
'
' Copyright � 2005 Gary Noble
' --------------------------------------------------------------------------------------
'
' Wizard Designer
'
' --------------------------------------------------------------------------------------
' History:
'
' --------------------------------------------------------------------------------------
' Date User Detail
' --------------------------------------------------------------------------------------
'
' 09/01/2006 Gary Noble Created
'
' --------------------------------------------------------------------------------------
'
' ********* If You Use This Control Please Give Credit *********
'
' --------------------------------------------------------------------------------------
' Copyright (c) 2005/6 Gary Noble
' ---------------------------------------------------------------------
'
' Redistribution and use in source and binary forms, with or
' without modification, are permitted provided that the following
' conditions are met:
'
' 1. Redistributions of source code must retain the above copyright
' notice, this list of conditions and the following disclaimer.
'
' 2. Redistributions in binary form must reproduce the above copyright
' notice, this list of conditions and the following disclaimer in
' the documentation and/or other materials provided with the distribution.
'
' 3. The end-user documentation included with the redistribution, if any,
' must include the following acknowledgment:
'
' "This product includes software developed by Gary Noble"
'
' Alternately, this acknowledgment may appear in the software itself, if
' and wherever such third-party acknowledgments normally appear.
'
' THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
' INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
' AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
' GARY NOBLE OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
' INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
' BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
' USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
' THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
' (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
' THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'
' ---------------------------------------------------------------------
#Region "Imports"
Imports System
Imports System.Drawing
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Collections
Imports System.Diagnostics
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System.ComponentModel.Design.DesignerVerbCollection
Imports GNWizardFrameWork
#End Region
Namespace GNWizardFrameWork
''' -----------------------------------------------------------------------------
''' Project : GNWizardFrameWork
''' Class : Winforms.UIStudio.Controls.WizardTemplateDesigner
'''
''' -----------------------------------------------------------------------------
''' <summary>
''' Designer for the GN Wizard Template
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' [G_Noble] 13/03/2006 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Class WizardTemplateDesigner
Inherits ControlDesigner
#Region " Declarations "
' Our Wizard Control
Private m_WizardControl As WizardTemplate = Nothing
Private Shadows m_Verbs As DesignerVerbCollection = Nothing
Private m_bisOld As Boolean
#End Region
#Region " Constructor "
Public Sub New()
m_Verbs = New DesignerVerbCollection
End Sub
#End Region
#Region " Overrides "
Public Overloads Overrides Sub Initialize(ByVal component As IComponent)
MyBase.Initialize(component)
Try
Dim service As ISelectionService = CType(MyBase.GetService(GetType(ISelectionService)), ISelectionService)
AddHandler service.SelectionChanged, AddressOf OnServiceSelectionChange
'-- Set the control
m_WizardControl = CType(component, GNWizardFrameWork.WizardTemplate)
'-- Add The Deigntime Menu items
Verbs.Add(New DesignerVerb(String.Concat("&Add Wizard External Page"), AddressOf OnAddCommandEXT))
Verbs.Add(New DesignerVerb(String.Concat("&Add Wizard Internal Page"), AddressOf OnAddCommand))
Verbs.Add(New DesignerVerb(String.Concat("&Remove Selected Wizard Page"), AddressOf OnRemoveCommand))
Verbs.Add(New DesignerVerb(String.Concat("&Change Selected Page Type"), AddressOf OnChangePageType))
Verbs.Add(New DesignerVerb(String.Concat("&About"), AddressOf OnShowAbout))
Catch ex As Exception
End Try
End Sub
''' -----------------------------------------------------------------------------
''' <summary>
''' Here we are checking to see the mous position of the control at design time
''' </summary>
''' <param name="point"></param>
''' <returns></returns>
''' <remarks>
''' </remarks>
''' <history>
''' [G_Noble] 13/03/2006 Created
''' </history>
''' -----------------------------------------------------------------------------
Protected Overrides Function GetHitTest(ByVal point As System.Drawing.Point) As Boolean
Dim _CTL As Button
' is the mouse over a control in the Button Panel
_CTL = m_WizardControl.ButtonPanel.GetChildAtPoint(m_WizardControl.ButtonPanel.PointToClient(point))
If Not _CTL Is Nothing Then
Return True
End If
Return False
End Function
#End Region
#Region " Methods "
Private Sub OnServiceSelectionChange(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim service As ISelectionService = CType(MyBase.GetService(GetType(ISelectionService)), ISelectionService)
Dim compFlag As Boolean = False
If service Is Nothing Then
Return
End If
For Each item As GNWizardFrameWork.WizardPage In m_WizardControl.Pages
If service.GetComponentSelected(item) Then
compFlag = True
End If
Next
If (Not (compFlag = m_bisOld)) OrElse compFlag Then
m_bisOld = compFlag
m_WizardControl.Invalidate()
End If
Catch ex As Exception
Throw ex
End Try
End Sub
''' -----------------------------------------------------------------------------
''' <summary>
''' Adds An Exterior Page To The Wizard
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' </remarks>
''' <history>
''' [G_Noble] 15/03/2006 Created
''' </history>
''' -----------------------------------------------------------------------------
Friend Sub OnAddCommandEXT(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim host As IDesignerHost = CType(MyBase.GetService(GetType(IDesignerHost)), IDesignerHost)
Dim service As IComponentChangeService = CType(MyBase.GetService(GetType(IComponentChangeService)), IComponentChangeService)
Dim transaction As DesignerTransaction = host.CreateTransaction("Add Item")
service.OnComponentChanging(m_WizardControl, Nothing)
Dim item As GNWizardFrameWork.WizardPage = CType(host.CreateComponent(GetType(GNWizardFrameWork.WizardPage)), GNWizardFrameWork.WizardPage)
Dim name As String = "New Tab Item "
Dim i As Integer = 1
While ContainsWizardPage(name + i.ToString)
System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)
End While
item.PageStyle = PageStyle.eWPS_Exterior
item.Text = name + i.ToString
m_WizardControl.Pages.Add(item)
service.OnComponentChanged(m_WizardControl, Nothing, Nothing, Nothing)
transaction.Commit()
m_WizardControl.Invalidate(True)
m_WizardControl.UpdateDesignTimeComponents()
Catch ex As Exception
Throw ex
End Try
End Sub
''' -----------------------------------------------------------------------------
''' <summary>
''' Chages The selected page style
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' </remarks>
''' <history>
''' [G_Noble] 21/03/2006 Created
''' </history>
''' -----------------------------------------------------------------------------
Friend Sub OnChangePageType(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim host As IDesignerHost = CType(MyBase.GetService(GetType(IDesignerHost)), IDesignerHost)
Dim service As IComponentChangeService = CType(MyBase.GetService(GetType(IComponentChangeService)), IComponentChangeService)
Dim transaction As DesignerTransaction = host.CreateTransaction("Add Item")
Dim Item As WizardPage
Item = m_WizardControl.CurrentPage
If Not Item Is Nothing Then
service.OnComponentChanging(m_WizardControl.CurrentPage, Nothing)
If Item.PageStyle = PageStyle.eWPS_Exterior Then
Item.PageStyle = PageStyle.eWPS_Interior
Else
Item.PageStyle = PageStyle.eWPS_Exterior
End If
service.OnComponentChanged(m_WizardControl.CurrentPage, Nothing, Nothing, Nothing)
transaction.Commit()
m_WizardControl.CurrentPage.Invalidate(True)
End If
m_WizardControl.Invalidate(True)
m_WizardControl.UpdateDesignTimeComponents()
Catch ex As Exception
If m_WizardControl.Pages.Count > 0 Then
MsgBox(ex.Message, MsgBoxStyle.Information, Application.ProductName)
Else
MsgBox("There are no Pages to change!", MsgBoxStyle.Information, Application.ProductName)
End If
End Try
End Sub
''' -----------------------------------------------------------------------------
''' <summary>
''' Adds An Interior Page to The Wizard
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' </remarks>
''' <history>
''' [G_Noble] 15/03/2006 Created
''' </history>
''' -----------------------------------------------------------------------------
Friend Sub OnAddCommand(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim host As IDesignerHost = CType(MyBase.GetService(GetType(IDesignerHost)), IDesignerHost)
Dim service As IComponentChangeService = CType(MyBase.GetService(GetType(IComponentChangeService)), IComponentChangeService)
Dim transaction As DesignerTransaction = host.CreateTransaction("Add Item")
service.OnComponentChanging(m_WizardControl, Nothing)
Dim item As GNWizardFrameWork.WizardPage = CType(host.CreateComponent(GetType(GNWizardFrameWork.WizardPage)), GNWizardFrameWork.WizardPage)
Dim name As String = "New Tab Item "
Dim i As Integer = 1
While ContainsWizardPage(name + i.ToString)
System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)
End While
item.Text = name + i.ToString
m_WizardControl.Pages.Add(item)
service.OnComponentChanged(m_WizardControl, Nothing, Nothing, Nothing)
transaction.Commit()
m_WizardControl.Invalidate(True)
m_WizardControl.UpdateDesignTimeComponents()
Catch ex As Exception
Throw ex
End Try
End Sub
''' -----------------------------------------------------------------------------
''' <summary>
''' Checks To See If the Page Aready Exists
''' </summary>
''' <param name="name"></param>
''' <returns></returns>
''' <remarks>
''' </remarks>
''' <history>
''' [G_Noble] 15/03/2006 Created
''' </history>
''' -----------------------------------------------------------------------------
Function ContainsWizardPage(ByVal name As String) As Boolean
If m_WizardControl Is Nothing Then
Return False
End If
For Each tab As GNWizardFrameWork.WizardPage In m_WizardControl.Pages
If tab.Text = name Then
Return True
End If
Next
Return False
End Function
''' -----------------------------------------------------------------------------
''' <summary>
''' Removes A Page From The Wizard
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' </remarks>
''' <history>
''' [G_Noble] 15/03/2006 Created
''' </history>
''' -----------------------------------------------------------------------------
Friend Sub OnRemoveCommand(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim host As IDesignerHost = CType(MyBase.GetService(GetType(IDesignerHost)), IDesignerHost)
Dim service As IComponentChangeService = CType(MyBase.GetService(GetType(IComponentChangeService)), IComponentChangeService)
Dim selService As ISelectionService = CType(MyBase.GetService(GetType(ISelectionService)), ISelectionService)
Dim selected As GNWizardFrameWork.WizardPage = m_WizardControl.SelectedPane
If selected Is Nothing Then
MsgBox("WizardTemplate: OnRemoveCommand: Nothing")
Return
End If
Dim transaction As DesignerTransaction = host.CreateTransaction("Delete Item")
service.OnComponentChanging(m_WizardControl, Nothing)
m_WizardControl.Pages.Remove(selected)
host.DestroyComponent(selected)
service.OnComponentChanged(m_WizardControl, Nothing, Nothing, Nothing)
transaction.Commit()
If m_WizardControl.Pages.Count > 0 Then
m_WizardControl.DisplayCurrentPage()
End If
Catch ex As Exception
If m_WizardControl.Pages.Count > 0 Then
MsgBox(ex.Message, MsgBoxStyle.Information, Application.ProductName)
Else
MsgBox("There are no Pages to remove!", MsgBoxStyle.Information, Application.ProductName)
End If
End Try
End Sub
''' -----------------------------------------------------------------------------
''' <summary>
''' Shows the about box
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>
''' </remarks>
''' <history>
''' [G_Noble] 09/01/2006 Created
''' </history>
''' -----------------------------------------------------------------------------
Protected Sub OnShowAbout(ByVal sender As Object, ByVal e As EventArgs)
Dim _About As New About
_About.IsCallingAssembly = True
_About.ShowDialog()
_About.Dispose()
End Sub
#End Region
#Region " Properties "
Public Overloads Overrides ReadOnly Property AssociatedComponents() As System.Collections.ICollection
Get
Return m_WizardControl.Pages
End Get
End Property
<ComVisible(True)> _
Public Overrides ReadOnly Property Verbs() As DesignerVerbCollection
Get
Try
'-- Hides The Remove current Page If the Count = 0
If m_WizardControl.InternalItemCount = 0 Then
m_Verbs(2).Enabled = False
m_Verbs(3).Enabled = False
Else
m_Verbs(3).Enabled = True
m_Verbs(2).Enabled = True
End If
Catch ex As Exception
End Try
Return m_Verbs
End Get
End Property
#End Region
End Class
End Namespace