Function to create a drop-down dialog with a list of layers.
Function to create a drop-down dialog with a list of layers.
by tu2011 » Sun Jun 24, 2012 10:56 pm
/******************************************************************************************************************
*FUNCTION: This function test a layer to see if it's one of the specified type, i.e. Special, Derived, Drawn, All*
* *
*******************************************************************************************************************/
bool LLayer_IsOfType(LFile pFile, LLayer pLayer, LLayerType LayerType)
{
if (LayerType == Special)
{
if ( (pLayer == LLayer_GetSpecial(pFile, GridLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, OriginLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, CellOutlineLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, ErrorLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, IconLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, DragBoxLayer)) )
return true;
else
return false;
}
if (LayerType == Derived)
{
if (LLayer_IsDerived(pLayer))
return true;
else
return false;
}
if (LayerType == Drawn)
{
if (!LLayer_IsDerived(pLayer))
{
if ((pLayer == LLayer_GetSpecial(pFile, GridLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, OriginLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, CellOutlineLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, ErrorLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, IconLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, DragBoxLayer)))
return false;
else
return true;
}
}
if (LayerType == All)
{
return true;
}
else
return false;
}//End of LLayer_IsOfType() function.
/**************************************************************************************************************
*FUNCTION: Provides a dialog box with a list of Layers of a specified type, i.e. Special, Derived, Drawn, All*
*EXAMPLE: LLayer_PickList(pSrcFile, "Select source layer to copy", All);
*********************************************************************************************************/
LLayer LLayer_PickList(LFile pFile, const char* szDialogTitle, LLayerType LayerType)
{
// Count the number of layers.
long lNumOfLayers = 0;
LLayer pLayer = NULL;
char szLayerName[MAX_LAYER_NAME];
long i = 0;
if (NotAssigned(pFile))
{
LDialog_MsgBox("Invalid pointer to File");
return NULL;
}
for(pLayer = LLayer_GetList(pFile); Assigned(pLayer); pLayer = LLayer_GetNext(pLayer))
{
if (LLayer_IsOfType(pFile, pLayer, LayerType))
lNumOfLayers++;
}
// Allocate space for all of the layer names.
char** szaLayerNames = (char **) malloc(lNumOfLayers * sizeof(char *)); // Array of pointers.
LLayer* paLayers = (LLayer *) malloc(lNumOfLayers * sizeof(LLayer *)); // Array of pointers.
// Add all the layer names to the array of layer names.
for(pLayer = LLayer_GetList(pFile); Assigned(pLayer); pLayer = LLayer_GetNext(pLayer))
{
if (LLayer_IsOfType(pFile, pLayer, LayerType))
{
// Get the name.
paLayers[i] = pLayer;
LLayer_GetName(pLayer, szLayerName, sizeof(szLayerName));
// Allocate space for the name.
szaLayerNames[i] = (char *) malloc((strlen(szLayerName) + 1) * sizeof(char));
// Add it to the list of layers.
strcpy(szaLayerNames[i++], szLayerName);
}
}
// Display the picklist.
int nLayerResult = LDialog_PickList(szDialogTitle, (const char**)(szaLayerNames), lNumOfLayers, 0);
if(nLayerResult >= 0)
return paLayers[nLayerResult];
else
return NULL;
// Deallocate the cell name array.
for(i = 0; i < lNumOfLayers; i++)
{
free(szaLayerNames[i]);
free(paLayers[i]);
}
free(szaLayerNames);
free(paLayers);
} // End of Function: PickList
*FUNCTION: This function test a layer to see if it's one of the specified type, i.e. Special, Derived, Drawn, All*
* *
*******************************************************************************************************************/
bool LLayer_IsOfType(LFile pFile, LLayer pLayer, LLayerType LayerType)
{
if (LayerType == Special)
{
if ( (pLayer == LLayer_GetSpecial(pFile, GridLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, OriginLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, CellOutlineLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, ErrorLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, IconLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, DragBoxLayer)) )
return true;
else
return false;
}
if (LayerType == Derived)
{
if (LLayer_IsDerived(pLayer))
return true;
else
return false;
}
if (LayerType == Drawn)
{
if (!LLayer_IsDerived(pLayer))
{
if ((pLayer == LLayer_GetSpecial(pFile, GridLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, OriginLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, CellOutlineLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, ErrorLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, IconLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, DragBoxLayer)))
return false;
else
return true;
}
}
if (LayerType == All)
{
return true;
}
else
return false;
}//End of LLayer_IsOfType() function.
/**************************************************************************************************************
*FUNCTION: Provides a dialog box with a list of Layers of a specified type, i.e. Special, Derived, Drawn, All*
*EXAMPLE: LLayer_PickList(pSrcFile, "Select source layer to copy", All);
*********************************************************************************************************/
LLayer LLayer_PickList(LFile pFile, const char* szDialogTitle, LLayerType LayerType)
{
// Count the number of layers.
long lNumOfLayers = 0;
LLayer pLayer = NULL;
char szLayerName[MAX_LAYER_NAME];
long i = 0;
if (NotAssigned(pFile))
{
LDialog_MsgBox("Invalid pointer to File");
return NULL;
}
for(pLayer = LLayer_GetList(pFile); Assigned(pLayer); pLayer = LLayer_GetNext(pLayer))
{
if (LLayer_IsOfType(pFile, pLayer, LayerType))
lNumOfLayers++;
}
// Allocate space for all of the layer names.
char** szaLayerNames = (char **) malloc(lNumOfLayers * sizeof(char *)); // Array of pointers.
LLayer* paLayers = (LLayer *) malloc(lNumOfLayers * sizeof(LLayer *)); // Array of pointers.
// Add all the layer names to the array of layer names.
for(pLayer = LLayer_GetList(pFile); Assigned(pLayer); pLayer = LLayer_GetNext(pLayer))
{
if (LLayer_IsOfType(pFile, pLayer, LayerType))
{
// Get the name.
paLayers[i] = pLayer;
LLayer_GetName(pLayer, szLayerName, sizeof(szLayerName));
// Allocate space for the name.
szaLayerNames[i] = (char *) malloc((strlen(szLayerName) + 1) * sizeof(char));
// Add it to the list of layers.
strcpy(szaLayerNames[i++], szLayerName);
}
}
// Display the picklist.
int nLayerResult = LDialog_PickList(szDialogTitle, (const char**)(szaLayerNames), lNumOfLayers, 0);
if(nLayerResult >= 0)
return paLayers[nLayerResult];
else
return NULL;
// Deallocate the cell name array.
for(i = 0; i < lNumOfLayers; i++)
{
free(szaLayerNames[i]);
free(paLayers[i]);
}
free(szaLayerNames);
free(paLayers);
} // End of Function: PickList
1 post
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 2 guests
- Board index
- The team • Delete all board cookies • Delete style cookies • All times are UTC - 8 hours [ DST ]