static GSErrCode	CreateAText (const TextParams *textPars)
{
	API_Element		element;
	API_ElementMemo	memo;
	Int32			len;
	API_Coord		c;
	GSErrCode		err;



	if (!ClickAPoint ("Click the top/left corner of the text box", &c))
		return APIERR_CANCEL;

	BNZeroMemory (&element, sizeof (element));
	BNZeroMemory (&memo, sizeof (memo));

	element.header.typeID = API_TextID;
	err = ACAPI_Element_GetDefaults (&element, NULL);
	if (err != NoError) {
		ErrorBeep ("ACAPI_Element_GetDefaults (text)", err);
		return err;
	}

	element.text.pen    = textPars->pen;
	element.text.size   = textPars->size;
	element.text.anchor = APIAnc_LT;
	element.text.just   = APIJust_Left;

	element.text.loc = c;
	element.text.nonBreaking = true;
	element.text.nLine = 1;

	len = Strlen32 (textPars->content);

	memo.textContent = BMAllocateHandle (len + 1, ALLOCATE_CLEAR, 0);
	err = BMError ();
	if (err != NoError)
		return err;

	strcpy (*memo.textContent, textPars->content);

	err = ACAPI_CallUndoableCommand ("Create text",
		[&] () -> GSErrCode {
			return ACAPI_Element_Create (&element, &memo);
		});
	if (err != NoError)
		ErrorBeep ("ACAPI_Element_Create (text)", err);

	ACAPI_DisposeElemMemoHdls (&memo);

	return err;
}		// CreateAText
示例#2
0
void highlightElementByID(){
	GSErrCode err;
	API_NeigID neigID;
	API_Element element;
	elementidlist eleMsg;
	API_StoryCmdType	storyCmd;
	char buffer[256];

	readDelimitedFrom(getClientSocket(), &eleMsg);

	Int32 nItem = eleMsg.guid_size();
	bool add = true;

	//Clear all selected elements
	err = ACAPI_Element_Select(NULL, 0, add);

	API_Neig** neigHdl = reinterpret_cast<API_Neig**> (BMAllocateHandle(nItem * sizeof(API_Neig), ALLOCATE_CLEAR, 0));

	API_Neig neig;
	for (int i = 0; i < nItem; i++){
		BNZeroMemory(&element, sizeof(API_Element));
		element.header.guid = APIGuidFromString(eleMsg.guid(i).c_str());
		err = ACAPI_Element_Get(&element);
		if (err != NoError) {
			sprintf(buffer, ErrID_To_Name(err));
			ACAPI_WriteReport(buffer, true);
			return;
		}
		err = ACAPI_Goodies(APIAny_ElemTypeToNeigID, (void*)element.header.typeID, &neigID);

		(*neigHdl)[i].neigID = neigID;
		(*neigHdl)[i].guid = element.header.guid;
		(*neigHdl)[i].flags = API_NeigFlg_Normal;
		(*neigHdl)[i].elemPartType = APINeigElemPart_None;
	}

	//Add the current element to the selection
	err = ACAPI_Element_Select(neigHdl, nItem, add);
	if (err != NoError) {
		sprintf(buffer, ErrID_To_Name(err));
		ACAPI_WriteReport(buffer, true);
		return;
	}

	BMhKill((GSHandle*)&neigHdl);

	/*
	* In order for the GUI update, we need to create an element, and then
	* delete it.
	* By doing this we can have the selected element highlighted
	*/

	API_Element		wallElement;
	API_ElementMemo memo;
	BNZeroMemory(&memo, sizeof(API_ElementMemo));

	BNZeroMemory(&wallElement, sizeof(API_Element));

	wallElement.header.typeID = API_WallID;
	wallElement.header.layer = 1;

	err = ACAPI_Element_GetDefaults(&wallElement, &memo);
	if (err != NoError) {
		ErrorBeep("ACAPI_Element_GetMemo", err);
		return;
	}

	err = ACAPI_Element_Create(&wallElement, &memo);

	if (err != NoError){
		ErrorBeep("ACAPI_Element_Create", err);
		sprintf(buffer, ErrID_To_Name(err));
		ACAPI_WriteReport(buffer, true);
	}

	ACAPI_DisposeElemMemoHdls(&memo);

	API_Elem_Head* test;
	test = &wallElement.header;
	ACAPI_Element_Delete(&test, 1);

}