/* Copyright (c) 2024 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved. */ /*--------------------------------------------------------------------*\ Pro/TOOLKIT includes \*--------------------------------------------------------------------*/ #include "ProToolkit.h" #include "ProMenu.h" #include "ProUtil.h" /*--------------------------------------------------------------------*\ Pro/DEVELOP includes \*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*\ C System includes \*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*\ Application includes \*--------------------------------------------------------------------*/ #include "TestError.h" #include "UtilMessage.h" #include "TestGraphics.h" #include <ProTKRunTime.h> /*--------------------------------------------------------------------*\ Macros \*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*\ Data types \*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*\ Application global/external data \*--------------------------------------------------------------------*/ /*---------------------------------------------------------------------*\ Functions declaration \*---------------------------------------------------------------------*/ int ProTestText( void*, int ); int ProTestTextFontIdCurrentSet( void*, int ); int ProTestTextHeightCurrentSet( void*, int ); int ProTestTextWidthFactorCurrentSet( void*, int ); int ProTestTextRotationAngleCurrentSet( void*, int ); int ProTestTextSlantAngleCurrentSet( void*, int ); int ProTestTextAttributesCurrentGet( void*, int ); int ProTestTextAttributesCurrentUnset( void*, int ); int ProTestTextFontIdGet( void*, int ); /*===========================================================================*\ Function : user_set_text Purpose : To set text attributes \*===========================================================================*/ /*---------------------------------------------------------------------*\ Function: ProTestText() Purpose: On-buttun function. Create and run Text Set menu to test ProText functions. Returns: 0 - success; -1 - error. \*---------------------------------------------------------------------*/ int ProTestText( void* p_dummy, int int_dummy ) { ProError status; int menu_id; /* The identifier of the created menu */ int action; /*-----------------------------*\ Create new menu Text Set \*-----------------------------*/ /* Load base menu from file */ status = ProMenuFileRegister((char*) "Text Set",(char*) "tktext.mnu", &menu_id ); TEST_CALL_REPORT( "ProMenuFileRegister()", "ProTestText()", status, status != PRO_TK_NO_ERROR ); /* Define menu buttons */ ProMenubuttonActionSet((char*) "Text Set",(char*) "Font", (ProMenubuttonAction)ProTestTextFontIdCurrentSet, 0, 0 ); ProMenubuttonActionSet((char*) "Text Set",(char*) "Height", (ProMenubuttonAction)ProTestTextHeightCurrentSet, NULL, 0 ); ProMenubuttonActionSet((char*) "Text Set",(char*) "Width", (ProMenubuttonAction)ProTestTextWidthFactorCurrentSet, NULL, 0 ); ProMenubuttonActionSet((char*) "Text Set",(char*) "Rotate", (ProMenubuttonAction)ProTestTextRotationAngleCurrentSet, NULL, 0 ); ProMenubuttonActionSet((char*) "Text Set",(char*) "Slant", (ProMenubuttonAction)ProTestTextSlantAngleCurrentSet, NULL, 0 ); ProMenubuttonActionSet((char*) "Text Set",(char*) "Get Attr", (ProMenubuttonAction)ProTestTextAttributesCurrentGet, NULL, 0 ); ProMenubuttonActionSet((char*) "Text Set",(char*) "Unset Attr", (ProMenubuttonAction)ProTestTextAttributesCurrentUnset, NULL, 0 ); ProMenubuttonActionSet((char*) "Text Set",(char*) "Dflt Font Get", (ProMenubuttonAction)ProTestTextFontIdGet, NULL, 0 ); ProMenubuttonActionSet((char*) "Text Set",(char*) "Done", (ProMenubuttonAction)ProMenuDelete, NULL, 0 ); ProMenubuttonActionSet((char*) "Text Set",(char*) "Text Set", (ProMenubuttonAction)ProMenuDelete, NULL, 0 ); /*-----------------------*\ Run menu Text Set \*-----------------------*/ status = ProMenuCreate( PROMENUTYPE_MAIN,(char*) "Text Set", &menu_id ); TEST_CALL_REPORT( "ProMenuCreate()", "ProTestText()", status, status != PRO_TK_NO_ERROR ); if( status == PRO_TK_NO_ERROR ) { status = ProMenuProcess((char*) "Text Set", &action ); TEST_CALL_REPORT( "ProMenuProcess()", "ProTestText()", status, status != PRO_TK_NO_ERROR ); } return 0; } /*---------------------------------------------------------------------*\ Function: ProTestTextFontIdCurrentSet() Purpose: On-buttun function. Set current font id to the value entered by user. Returns: 0 - success; -1 - error. \*---------------------------------------------------------------------*/ int ProTestTextFontIdCurrentSet( void* p_dummy, int int_dummy ) { ProError status; int font_id; ProUtilMsgPrint( "gen", "TEST %0s", "Enter a value: " ); if( !ProUtilIntGet( NULL, NULL, &font_id ) ) return -1; status = ProTextFontIdCurrentSet( font_id ); TEST_CALL_REPORT( "ProTextFontIdCurrentSet()", "ProTestTextFontIdCurrentSet()", status, status != PRO_TK_NO_ERROR ); return 0; } /*---------------------------------------------------------------------*\ Function: ProTestTextHeightCurrentSet() Purpose: On-buttun function. Set current text height to the value entered by user. Returns: 0 - success; -1 - error. \*---------------------------------------------------------------------*/ int ProTestTextHeightCurrentSet( void* p_dummy, int int_dummy ) { ProError status; double height; ProUtilMsgPrint( "gen", "TEST %0s", "Enter a value: " ); if( !ProUtilDoubleGet( NULL, NULL, &height ) ) return -1; status = ProTextHeightCurrentSet( height ); TEST_CALL_REPORT( "ProTextHeightCurrentSet()", "ProTestTextHeightCurrentSet()", status, status != PRO_TK_NO_ERROR ); return 0; } /*---------------------------------------------------------------------*\ Function: ProTestTextWidthFactorCurrentSet() Purpose: On-buttun function. Set current text width factor to the value entered by user. Returns: 0 - success; -1 - error. \*---------------------------------------------------------------------*/ int ProTestTextWidthFactorCurrentSet( void* p_dummy, int int_dummy ) { ProError status; double width_factor; ProUtilMsgPrint( "gen", "TEST %0s", "Enter a value: " ); if( !ProUtilDoubleGet( NULL, NULL, &width_factor ) ) return -1; status = ProTextWidthFactorCurrentSet( width_factor ); TEST_CALL_REPORT( "ProTextWidthFactorCurrentSet()", "ProTestTextWidthFactorCurrentSet()", status, status != PRO_TK_NO_ERROR ); return 0; } /*---------------------------------------------------------------------*\ Function: ProTestTextRotationAngleCurrentSet() Purpose: On-buttun function. Set current text rotation angle to the value entered by user. Returns: 0 - success; -1 - error. \*---------------------------------------------------------------------*/ int ProTestTextRotationAngleCurrentSet( void* p_dummy, int int_dummy ) { ProError status; double rotation_angle; ProUtilMsgPrint( "gen", "TEST %0s", "Enter a value: " ); if( !ProUtilDoubleGet( NULL, NULL, &rotation_angle ) ) return -1; status = ProTextRotationAngleCurrentSet( rotation_angle ); TEST_CALL_REPORT( "ProTextRotationAngleCurrentSet()", "ProTestTextRotationAngleCurrentSet()", status, status != PRO_TK_NO_ERROR ); return 0; } /*---------------------------------------------------------------------*\ Function: ProTestTextSlantAngleCurrentSet() Purpose: On-buttun function. Set current text slant angle to the value entered by user. Returns: 0 - success; -1 - error. \*---------------------------------------------------------------------*/ int ProTestTextSlantAngleCurrentSet( void* p_dummy, int int_dummy ) { ProError status; double slant_angle; ProUtilMsgPrint( "gen", "TEST %0s", "Enter a value: " ); if( !ProUtilDoubleGet( NULL, NULL, &slant_angle ) ) return -1; status = ProTextSlantAngleCurrentSet( slant_angle ); TEST_CALL_REPORT( "ProTextSlantAngleCurrentSet()", "ProTestTextSlantAngleCurrentSet()", status, status != PRO_TK_NO_ERROR ); return 0; } /*---------------------------------------------------------------------*\ Function: ProTestTextAttributesCurrentGet() Purpose: On-buttun function. Get and print out the current text attributes. Returns: 0 - success; -1 - error. \*---------------------------------------------------------------------*/ int ProTestTextAttributesCurrentGet( void* p_dummy, int int_dummy ) { ProError status; ProTextAttribute attributes; status = ProTextAttributesCurrentGet( &attributes ); TEST_CALL_REPORT( "ProTextAttributesCurrentGet()", "ProTestTextAttributesCurrentGet()", status, status != PRO_TK_NO_ERROR ); if( status == PRO_TK_NO_ERROR ) { ProTKPrintf( "\nCurrent text settings:" ); ProTKPrintf( "\n\tfont_id = %d", attributes.font_id ); ProTKPrintf( "\theight = %lf\twidth = %lf\trotate = %lf\tslant = %lf\n", attributes.height, attributes.width_factor, attributes.rot_angle, attributes.slant_angle ); } return 0; } /*---------------------------------------------------------------------*\ Function: ProTestTextAttributesCurrentUnset() Purpose: On-buttun function. Set the current text attributes to default. Returns: 0 - success; -1 - error. \*---------------------------------------------------------------------*/ int ProTestTextAttributesCurrentUnset( void* p_dummy, int int_dummy ) { ProError status; status = ProTextAttributesCurrentUnset(); TEST_CALL_REPORT( "ProTextAttributesCurrentUnset()", "ProTestTextAttributesCurrentUnset()", status, status != PRO_TK_NO_ERROR ); if( status == PRO_TK_NO_ERROR ) { ProTKPrintf( "\nText attributes is default." ); /* Print out current text settings */ ProTestTextAttributesCurrentGet( NULL, 0 ); } return 0; } /*===========================================================================*\ Function : user_get_font_id Purpose : To get a font name & id \*===========================================================================*/ /*---------------------------------------------------------------------*\ Function: ProTestTextFontIdGet() Purpose: On-button function. Test text font functions. Get deflt font id, use it to get font name, then use the name to get font id. Returns: 0 \*---------------------------------------------------------------------*/ int ProTestTextFontIdGet( void* p_dummy, int int_dummy ) { ProError status; ProLine w_font_name; char font_name[80]; int font_id; /* Get the default text font identifier */ ProTextFontDefaultIdGet( &font_id ); TEST_CALL_REPORT( "ProTextFontDefaultIdGet()", "ProTestTextFontIdGet()", (ProError)0, 0 ); /* Get the font name for the specified font identifier */ status = ProTextFontNameGet( font_id, w_font_name ); TEST_CALL_REPORT( "ProTextFontNameGet()", "ProTestTextFontIdGet()", status, status != PRO_TK_NO_ERROR ); ProWstringToString( font_name, w_font_name ); /* Get the identifier for the specified text font name */ status = ProTextFontNameToId( w_font_name, &font_id ); TEST_CALL_REPORT( "ProTextFontNameToId()", "ProTestTextFontIdGet()", status, status != PRO_TK_NO_ERROR ); if( status == PRO_TK_NO_ERROR ) ProTKPrintf( "Font Name = %s, Font Id = %d\n", font_name, font_id ); return 0; }