SDK:Working with VWThumbnailPopupCtrl

From Vectorworks Developer
Jump to navigation Jump to search

.SDK|SDK ..SDK:Types|SDK Types ..SDK:Using the SDK|Using the SDK ..VCOM:VCOM (Vectorworks Component Object Model)|VCOM Basics ..VCOM:Class Reference|VCOM Class Reference

Overview

This control is used to represent list of hatch, gradient or image resources.

Full example of it being used for all those types can be found in the SDK samples at:

\AppSource\Source\Plug-Ins\Sample\VWUI Dialogs Sample

Adding resource and default content

The filling the control is simmilar for all types. Here the examples are only for hatches.

1. Preparing variables that will store the list of hatch resources:

long   fHatchResListID;
long   fHatchResListItemsCnt;

2. Creating the resource list. Everytime there is a change in the resources of this document the list should be updated. Note the list contains the default resources and also the resources of this type in THIS document.

TXString     folderName;
fHatchResListItemsCnt = 0;
fHatchResListID = gSDK->BuildResourceList( kHatchDefNode,
                                           kDefaultHatchesFolder,
                                           folderName,
                                           fHatchResListItemsCnt );

3. Free the list before destroying:

::GS_DisposeResourceList( gCBP, fHatchResListID );
fHatchResListItemsCnt   = 0;

4. Filling the popup with the resource list:

VWThumbnailPopupCtrl*  pThumbnail  
            = this->GetThumbnailPopupCtrlByID( kThumbNailCtrl );
pThumbnail->RemoveAllImages();

for(long i=0; i<fHatchResListItemsCnt; i++) {
    pThumbnail->AddImageFromResource( fHatchResListID, i );
}

4a. Ensuring selection in the popup:

VWThumbnailPopupCtrl*  pThumbnail 
                     = this->GetThumbnailPopupCtrlByID( kThumbNailCtrl );
pThumbnail->SelectItem( fThumbPatternIndex );
size_t selIndex = pThumbnail->GetObjectItemIndex( fThumbPatternIndex );
if ( selIndex == size_t(-1) && pThumbnail->GetItemsCount() > 0 ) {
    pThumbnail->SelectItem( size_t(0) );
}

5. Getting the selection, and importing the resource into the document if it is not existing:

VWThumbnailPopupCtrl* pThumbnail = this->GetThumbnailPopupCtrlByID( kThumbNailCtrl );
InternalIndex popupIntIndex = pThumbnail->GetSelectedItem();;
size_t popupIndex = pThumbnail->GetSelectedItemIndex();
InternalName name;
gSDK->InternalIndexToNameN( popupIntIndex, name );
 
if ( popupIndex != size_t(-1) && name[0] == 0 ) {
    MCObjectHandle  hResource = gSDK->ImportResourceToCurrentFile( fHatchResListID, popupIndex + 1 );

    ::GS_GetObjectName( gCBP, hResource, name );
    if ( ! gSDK->NameToInternalIndexN( name, popupIntIndex ) ) {
        popupIntIndex	= 0;
    }
}
 
fThumbPatternIndex	= - popupIntIndex;


See Also

SDK:Creating handler class for VectorScript layout dialog | SDK:Creating handler class for manual layout dialog | SDK:Working with Dynamic Data Exchange (DDX) |