-
Notifications
You must be signed in to change notification settings - Fork 263
Creating Control Clients
The control client specifies the control's behavior, if any, when the control gains or loses focus, or is closed. You can implement this interface in the same class in which you call RegisterControl()
or in a separate class.
ControlHostService
implements IControlRegistry
, which tracks active controls, noting when controls are activated or deactivated. This interface provides:
-
ActiveControl
property. -
Controls
property, listing open controls'ControlInfo
objects with control information. - Events before and after an active control change.
- Events for a control being added or removed.
A control client implements the IControlHostClient
interface, which consists of these methods for WinForms:
void Activate(Control control);
void Deactivate(Control control);
bool Close(Control control);
These are the methods for WPF, which are almost the same, except that the parameter is object
rather than Control
, and Close()
has an extra parameter:
void Activate(object control);
void Deactivate(object control);
bool Close(object control, bool mainWindowClosing);
The Activate()
method notifies the client that its control is activated, that is, gains focus. Activation occurs when the control gets focus, or the control's parent "host" control gets focus.
Use this method to update other objects or perform operations that should occur when the control gains input focus. A common use of this method is to notify command clients that the context has changed by the control being activated.
Use the ICommandService.SetActiveClient()
method to switch the command client when the control gains focus, as in this example from the OutputService
component:
public void Activate(Control control)
{
if (m_commandService!= null)
m_commandService.SetActiveClient(this);
}
For information about command clients, see Creating Command Clients.
This example from the ATF Simple DOM Editor Sample shows a document control setting the active document and context when it is activated:
void IControlHostClient.Activate(Control control)
{
EventSequenceDocument document = control.Tag as EventSequenceDocument;
if (document != null)
{
m_documentRegistry.ActiveDocument = document;
EventSequenceContext context = document.As<EventSequenceContext>();
m_contextRegistry.ActiveContext = context;
}
}
For a discussion of contexts, see the topics in ATF Contexts.
Deactivate()
's purpose is to notify the client that its control is deactivated, that is, loses focus. Deactivation occurs when another control gets focus or the control's "host" control loses focus.
In this example from the OutputService
component, the active command client is set to null
when the output control is deactivated:
public void Deactivate(Control control)
{
if (m_commandService != null)
m_commandService.SetActiveClient(null);
}
This method requests permission to close the client's control. It returns true if the control can close, or false to not close. For WPF, the mainWindowClosing
parameter is true if the application's main window is closing.
If true is returned, ControlHostService
calls UnregisterControl()
. The application has to call RegisterControl()
again if it wants to re-register this control.
This method is not called when the user toggles control visibility by using Windows® menu commands.
This sample, from the editor code of ATF Simple DOM Editor Sample, allows the control to close if its document can be closed:
bool IControlHostClient.Close(Control control)
{
bool closed = true;
EventSequenceDocument document = control.Tag as EventSequenceDocument;
if (document != null)
{
closed = m_documentService.Close(document);
if (closed)
m_contextRegistry.RemoveContext(document);
}
return closed;
}
NOTE: If a particular control is closed when an application terminates, its control client's Close()
method should usually call IDocumentService.Close()
, as the previous example does. This gives the opportunity to check whether the document is dirty and offer the user the option of saving it; otherwise changes are lost. For instance, the often used StandardFileCommands
component implements IDocumentService
and, if the document's IDocument.Dirty
property is true, its IDocumentService.Close()
method asks a user whether or not the document's changes should be saved or discarded.
- Using Controls in ATF: Overview of using controls in ATF.
-
ControlInfo and ControlDef Classes: Description of the
ControlInfo
(WinForms) andControlDef
(WPF) classes that describe a control's appearance and location in the UI. - ATF Control Groups: About control groups, which provide an initial position for a top-level control.
-
Registering Controls: How to register controls with the
ControlHostService
component. - Creating Control Clients: Creating a control client that specifies the control's behavior, if any, when the control gains or loses focus, or is closed.
- Using WinForms Controls in WPF: How to use WinForms-based component controls and dialogs in a WPF based application.
-
Adaptable Controls: Discussion of the
AdaptableControl
class, which provides a control with adapters. - ATF Custom Controls: Overview of the custom controls ATF provides.
- ATF Custom Dialogs: Overview of the standard dialogs in ATF.
- Home
- Getting Started
- Features & Benefits
- Requirements & Dependencies
- Gallery
- Technology & Samples
- Adoption
- News
- Release Notes
- ATF Community
- Searching Documentation
- Using Documentation
- Videos
- Tutorials
- How To
- Programmer's Guide
- Reference
- Code Samples
- Documentation Files
© 2014-2015, Sony Computer Entertainment America LLC