Public Member Functions
ViewContext Class Reference

## Detailed Description

The ViewContext object serves 2 functions for Custom Displays:

- Provides the parent window handle in which Custom Displays should create it's child windows
- Provides information about a notification sent by Softimage

See also:
  CTimeChangeNotification, CValueChangeNotification, CSelectionChangeNotification

Example:

            void    MyCustomDisplay_Init (XSI::CRef in_pViewCtx)
            {
                // cast the CRef into a ViewContext object
                XSI::ViewContext l_vViewContext = in_pViewCtx;

                // make sure it is valid
                assert ( l_vViewContext.IsValid() );

                // Get the string-based metadata associated with this view context,
                // which was specified via SetAttributeValue()
                //
                XSI::CString l_szMetadata = l_vViewContext.GetMetadata();

                // Get the parent window handle. We will use this to
                // create our own child window.
                HWND l_hParent = (HWND)l_vViewContext.GetParentWindowHandle();

                // Create our window as a child of the XSI parent window
                HWND l_hMyWindow = CreateDialog(  MyDllInstance,
                                                MAKEINTRESOURCE(IDD_MYCUSTOMWINDOW),
                                                l_hParent,
                                                (DLGPROC)MyWindowProc);
            }

            void    MyCustomDisplay_Notify ( XSI::CRef in_pViewContext )
            {
                // cast the CRef into a ViewContext object
                XSI::ViewContext l_vViewContext = in_pViewCtx;

                // make sure it is valid
                assert ( l_vViewContext.IsValid() );

                XSI::siEventID in_eNotifcation;
                void*   in_pData;

                l_vViewContext.GetNotificationData ( in_eNotifcation, &in_pData );

                switch ( in_eNotifcation )
                {
                    case siOnSelectionChange:
                    {
                        XSI::CSelectionChangeNotification* l_pSelection = (XSI::CSelectionChangeNotification*)in_pData;

                        XSI::CString    l_szMessage;
                        l_szMessage = L"XSI_SELECTION_CHANGED_CV";
                        l_szMessage += L" [ ";

                        //
                        // Build a string of all objects that are in the selection list
                        //

                        for (INT c=0;c<l_pSelection->GetSelectionList().GetCount();c++)
                        {
                            XSI::CRef&  l_pCRef = l_pSelection->GetSelectionList().GetItem(c);

                            XSI::SIObject mySIObject ( l_pCRef );

                            XSI::CString    Name = mySIObject.GetFullName();

                            if ( c != 0 )
                                l_szMessage += L",";

                            l_szMessage += Name;;

                        }

                        l_szMessage += L" ]";

                        //
                        // And print it
                        //

                        char *l_szMessChar = new char [ l_szMessage.Length() + 1 ];
                        W2AHelper ( l_szMessChar, l_szMessage.GetWideString() );
                        OutputDebugString ( l_szMessChar );
                        delete [] l_szMessChar;

                        break;
                    }

                    case siOnTimeChange:
                    {
                        XSI::CTimeChangeNotification* l_pTimeChange = (XSI::CTimeChangeNotification*)in_pData;

                        XSI::CString    l_szMessage;
                        l_szMessage = L"XSI_TIME_CHANGE_CV";

                        char *l_szMessChar = new char [ l_szMessage.Length() + 1 ];
                        DSW2AHelper ( l_szMessChar, l_szMessage.GetWideString() );
                        OutputDebugString ( l_szMessChar );
                        delete [] l_szMessChar;

                        break;
                    }

                    case siOnValueChange:
                    {
                        XSI::CString    l_szMessage;
                        l_szMessage = L"XSI_SET_VALUE_CV ";

                        XSI::CValueChangeNotification* l_pData = (XSI::CValueChangeNotification*) in_pData;

                        XSI::CString l_csCIDName = l_pData->GetOwner().GetClassIDName();

                        l_szMessage += l_csCIDName;
                        l_szMessage += L" [ ";
                        l_szMessage += l_pData->GetComponentName();
                        l_szMessage += L" ]";

                        char *l_szMessChar = new char [ l_szMessage.Length() + 1 ];
                        DSW2AHelper ( l_szMessChar, l_szMessage.GetWideString() );
                        OutputDebugString ( l_szMessChar );
                        delete [] l_szMessChar;

                        break;

                    }

                }
            }

`#include <xsi_viewcontext.h>`

Inheritance diagram for ViewContext:
[legend]

List of all members.

## Public Member Functions
| ViewContext ()
| ~ViewContext ()
| ViewContext (const CRef &in_ref)
| ViewContext (const ViewContext &in_obj)
bool | IsA (siClassID in_ClassID) const
siClassID | GetClassID () const
ViewContext & | operator= (const ViewContext &in_obj)
ViewContext & | operator= (const CRef &in_ref)
CString | GetMetadata () const
CValue | GetUserData ()
CStatus | PutUserData (const CValue &in_val)
void * | GetParentWindowHandle ()
View | GetView ()
CStatus | GetNotificationData (siEventID &out_eEventID, void **out_pData)
CStatus | SetFlags (LONG in_lFlags)
CStatus | SetXWindowTopLevel (void *in_pHandle)
void * | GetTopLevelWidget ()

## Constructor & Destructor Documentation

ViewContext | ( |  | ) |

Default constructor.

~ViewContext | ( |  | ) |

Default destructor.

ViewContext | ( | const CRef & | in_ref | ) |

Constructor.

Parameters:

  in_ref | constant reference object.

ViewContext | ( | const ViewContext & | in_obj | ) |

Copy constructor.

Parameters:

  in_obj | constant class object.

## Member Function Documentation

bool IsA | ( | siClassID | in_ClassID | ) | const `[virtual]`

Returns true if a given class type is compatible with this API class.

Parameters:

  in_ClassID | class type.

Returns:
  true if the class is compatible, false otherwise.

Reimplemented from CBase.

siClassID GetClassID | ( |  | ) | const `[virtual]`

Returns the type of the API class.

Returns:
  The class type.

Implements CBase.

ViewContext& operator= | ( | const ViewContext & | in_obj | ) |

Creates an object from another object.

Parameters:

  in_obj | constant class object.

Returns:
  The new Context object.

ViewContext& operator= | ( | const CRef & | in_ref | ) |

Creates an object from a reference object. The newly created object is set to empty if the input reference object is not compatible.

Parameters:

  in_ref | constant class object.

Returns:
  The new Context object.

CString GetMetadata | ( |  | ) | const

Returns the current view Metadata associated with the Context. Metadata is string data that can be used during the early initialization of a Custom Display Host. It also provides another way to store more data should UserData already be filled with a value. The "metadata" view attribute can be set via SetAttributeValue() on the view before the "targetcontent" view attribute is set, allowing the Custom Display Host to recognize the "metadata" view attribute early on.

Since:
  11.0 (2013)

Returns:
  a string containing user-specified Metadata.

CValue GetUserData | ( |  | ) |

Returns the user data stored in the Context.

Returns:
  The raw user data.

CStatus PutUserData | ( | const CValue & | in_val | ) |

Allows you to store a CValue inside the context object. This is called User Data because Softimage does not care about the content or meaning of the data. This information is not persisted. A common use for this feature is to store a pointer to a newly allocated C++ object during an `Init` callback, and then to use Context::GetUserData to retrieve the pointer when other callbacks are made. (In this scenario the object should be destroyed in the cb_Plugin_Term Term callback).

Parameters:

  in_val | user data to be set for the operator instance.

Returns:
  CStatus::OK success
  CStatus::Fail failure.

void* GetParentWindowHandle | ( |  | ) |

Returns the platform-specific parent window handle. For Windows, this must be cast to a HWND.

Note:
  This function is not necessary on Linux, where ViewContext::SetXWindowTopLevel should be used instead.

Returns:
  Window handle.

View GetView | ( |  | ) |

Returns the View object associated with this context.

Since:
  11.0 (2013)

Returns:
  View object.

CStatus GetNotificationData | ( | siEventID & | out_eEventID,
|  | void ** | out_pData
| ) |  |

Returns the data associated with a notification event

Return values:

  out_eEventID | the event that was fired
  out_pData | the associated data

CStatus SetFlags | ( | LONG | in_lFlags | ) |

Sets the Custom Display flags

Parameters:

  in_lFlags | The flags

See also:
  siCustomDisplayFlags

CStatus SetXWindowTopLevel | ( | void * | in_pHandle | ) |

Specifies the top level X window for the Custom Display.

Note:
  This is only relevant on Linux. This is needed so that Softimage can parent the Custom Display properly inside the View that hosts the Custom Display.

Parameters:

  in_pHandle | The pointer to the X Window handle

Returns:
  CStatus::OK Success
  CStatus::Fail Not a valid Window or problem with X client.

void* GetTopLevelWidget | ( |  | ) |

Returns the top level widget from Softimage. This is necessary in order to create your custom display as a child of this widget.

Returns:
  void* the Widget handle

The documentation for this class was generated from the following file:

- xsi_viewcontext.h