コード例 #1
0
void MyPlugin2SelectionObserver::HandleSelectionChanged(const ISelectionMessage* selectionMessage)
{
	// get selection manager for active selection.
	ISelectionManager* iSelectionManager = Utils<ISelectionUtils>()->GetActiveSelection();
	return;
	//get pointer to textSelectionSuite using selection manager OR fCurrentSelection.
	InterfacePtr<ITextSelectionSuite> iTextSelectionSuite(iSelectionManager, UseDefaultIID());
	CAlert::InformationAlert("Selection** changed..");
	if (iTextSelectionSuite) {
		//get pointer to integrator target text using textSelectionSuite.
		//Use to  Return a list of interfaces from the "concrete selection"
		InterfacePtr<const IIntegratorTarget> iIntegratorTarget_text(iTextSelectionSuite, UseDefaultIID());
		if (iIntegratorTarget_text == nil)
			return;
		RangeData rangeData(0, RangeData::kLeanForward);
		UIDRef textRef;
		PMString tagName;
		PMString childCountString = "xml child count-";
		PMString tagUIDString = "UID of TAG -";
		UID tagUID;
		TextIndex startPosXML = 0, endPosXML = 0;
		int startIndexSelection;
		int endIndexSelection;
		// Return a list of interfaces from the "concrete selection"
		//auto_ptr automatically makes clean up of objects.
		std::auto_ptr<IIntegratorTarget::TargetSuiteCollection> selectionSuites_text(iIntegratorTarget_text->GetTarget(ITextTarget::kDefaultIID));
		for (IIntegratorTarget::TargetSuiteCollection::size_type i = 0; i < selectionSuites_text->size(); i++)
		{
			//Get target text.
			ITextTarget* target = (ITextTarget*)selectionSuites_text->at(i).get();
			if (!target)
				continue;
			// extract range from target text.
			rangeData = target->GetRange();
			
			// get start and end index of range selected.
			 startIndexSelection = rangeData.Start(nil);
			 endIndexSelection = rangeData.End();
		

			// get text model for target text.
			InterfacePtr<ITextModel>textModel(target->QueryTextModel());
			
			// get UIDRef of text model.
			textRef	= target->GetTextModel();

			// query xml reference data for text model.
			IXMLReferenceData *xmlReferenceData = Utils<IXMLUtils>()->QueryXMLReferenceData(textRef);
			if (xmlReferenceData)
			{
				// get xml reference from xml reference data.
				XMLReference xmlRef = xmlReferenceData->GetReference();
			
				// obtain xml element from xml reference
				InterfacePtr<IIDXMLElement> xmlElement(xmlRef.Instantiate());
				if (xmlElement != nil) {
					childCountString.AppendNumber(xmlElement->GetChildCount());
					XMLReference childRef = xmlElement->GetNthChild(0);
					InterfacePtr<IIDXMLElement> childXMLElement(childRef.Instantiate());
					if (childXMLElement != nil){
						tagUID = childXMLElement->GetTagUID();
						tagName = childXMLElement->GetTagString();
						Utils<IXMLUtils>()->GetElementMarkerPositions(childXMLElement, &startPosXML, &endPosXML);
					}
		    	}

			}
							
		} // for end
		int length = rangeData.Length();
		if (length >= 1) {
			PMString textFrameContentLength = "selected content length-";
			textFrameContentLength.AppendNumber(length);
			PMString srtPosString = "Start Position XML tag-";
			PMString endPosString = "End postion XML tag-";
			PMString srtPosSelString = "Start Position of Selection-";
			PMString endPosSelString = "End postion Selection-";
			srtPosString.AppendNumber(startPosXML);
			endPosString.AppendNumber(endPosXML);
			srtPosSelString.AppendNumber(startIndexSelection);
			endPosSelString.AppendNumber(endIndexSelection);
			CAlert::InformationAlert(textFrameContentLength);
			CAlert::InformationAlert(childCountString);
			CAlert::InformationAlert(tagName);
			CAlert::InformationAlert(srtPosString);
			CAlert::InformationAlert(endPosString);
			CAlert::InformationAlert(srtPosSelString);
			CAlert::InformationAlert(endPosSelString);

			if (startPosXML <= startIndexSelection && endPosXML >= endIndexSelection) {
				CAlert::InformationAlert("Selection inside tag- "+tagName);
			}
			else
			{
				CAlert::WarningAlert("Selection not inside tag- " + tagName);
			}
		}
	}
	// --------:: Table selection ::---------
	InterfacePtr<ITableSelectionSuite> iTableSelectionSuite(fCurrentSelection, UseDefaultIID());
	if (iTableSelectionSuite == nil)
		return;

	InterfacePtr<const IIntegratorTarget> iIntegratorTarget_table(iTableSelectionSuite, UseDefaultIID());
	if (iIntegratorTarget_table == nil)
		return;

	UIDRef 	tableUIDRef;
	GridArea tableGridArea;
	PMString PMRowCount = "Total no of rows-";
	PMString PMColCount = "Total no of cols-";
	std::auto_ptr<IIntegratorTarget::TargetSuiteCollection> selectionSuites_table(iIntegratorTarget_table->GetTarget(ITableTarget::kDefaultIID));
	for (IIntegratorTarget::TargetSuiteCollection::size_type i = 0; i < selectionSuites_table->size(); i++)
	{
		ITableTarget* target = (ITableTarget*)selectionSuites_table->at(i).get();
		if (!target)
			continue;
		tableUIDRef = target->GetModel();
		if (tableUIDRef != UIDRef(nil, kInvalidUID))
		{
			CAlert::WarningAlert("Table selection occured");
			tableGridArea = target->GetRange();
		}
		InterfacePtr<ITableModel>tableModel(target->QueryModel());
		if (tableModel != nil) {
			RowRange totalRows = tableModel->GetTotalRows();
			ColRange totalCols = tableModel->GetTotalCols();
			int rowCount = totalRows.count;
			int colCount = totalCols.count;
			PMRowCount.AppendNumber(rowCount);
			PMColCount.AppendNumber(colCount);
			CAlert::InformationAlert(PMRowCount);
			CAlert::InformationAlert(PMColCount);

			InterfacePtr<ITableLayout> tableLayout(tableModel, UseDefaultIID());
			if (tableLayout == nil) {
				break;
			}
			CAlert::InformationAlert("table layout present");
			ITableLayout::frame_iterator frameIter = tableLayout->begin_frame_iterator();
			CAlert::InformationAlert("Frame Iterator ppresent");
			
			CAlert::InformationAlert("Frame Iterator present");
			
			InterfacePtr<ITableFrame> tableFrame(frameIter->QueryFrame());
			CAlert::InformationAlert("table frame ppresent");
			if (tableFrame == nil){
				break;
			}
			CAlert::InformationAlert("table frame present");
			UIDRef tableContainerUIDRef = tableFrame->GetFrameRef();
			if (tableContainerUIDRef == nil){
				break;
			}
			CAlert::InformationAlert("table container UIDRef present");
			InterfacePtr<IFrameType> frameType(tableContainerUIDRef, UseDefaultIID());
			//if (frameType == nil) {
				//break;
			//}
			CAlert::InformationAlert("container frame present");
			PMString textFrameType = "Is container , text frame-";   // TYPE OF TEXT FRAME
			
		//	bool isTextFrame = frameType->IsTextFrame();
			CAlert::InformationAlert("Is text frame success");

			if (true) {
				textFrameType.Append("YES");
				CAlert::InformationAlert(textFrameType);
			}
			else {
				textFrameType.Append("NO");
				CAlert::InformationAlert(textFrameType);
			}
		}
	}
	
};
コード例 #2
0
void MyActiveSelectionObserver::tableSelection()
{
	int row=2;
	int col=2;
	do
	{
		InterfacePtr<ITableSelectionSuite> iTableSelectionSuite(fCurrentSelection, UseDefaultIID());
		if (!iTableSelectionSuite)
		{
			break;
		}
		else
		{
			InterfacePtr<const IIntegratorTarget> iIntegratorTarget_table(iTableSelectionSuite, UseDefaultIID());
			if(iIntegratorTarget_table == nil)
				return;

			RangeData rangeData(0,RangeData::kLeanForward);
			UIDRef tableRef;

			std::auto_ptr<IIntegratorTarget::TargetSuiteCollection> selectionSuites_table(iIntegratorTarget_table->GetTarget(ITableTarget::kDefaultIID));
			for(IIntegratorTarget::TargetSuiteCollection::size_type i = 0; i < selectionSuites_table->size(); i++)
			{
				ITableTarget* tableTarget = (ITableTarget*)selectionSuites_table->at(i).get();
				if(!tableTarget)
					continue;

				InterfacePtr<ITableModel> tableModel(tableTarget->QueryModel());
				if(!tableModel)
				{
					CAlert::InformationAlert("tableModel failed");
					break;
				}

				//tableRef = tableTarget->GetModel();
				bool16 hasContent=tableTarget->HasContent();
				//CAlert::InformationAlert("Table is selected.");



				if(hasContent==kTrue)
				{
					//CAlert::InformationAlert("Has Content.");
					//GridArea selectedText=iTableSelectionSuite->GetSelection();

					//InterfacePtr<ITableSuite> tableSuite(fCurrentSelection, UseDefaultIID());
					/*    Number of columns visible to user.
					int32 userNumCols=tableSuite->GetUserNumColsInTable();
					PMString UNC("No.of cols :");
					UNC.AppendNumber(userNumCols);
					CAlert::InformationAlert(UNC);
					*/
					/*        //text cell selection  (click+ esc)
					bool16 textCellSelected=tableSuite->IsAnyTextCellSelected();
					if(textCellSelected==kTrue)
					{
					CAlert::InformationAlert("Text Cell is selected.");
					}
					*/


					//this->cellTextSelection(iTableSelectionSuite);

					//GridAddress gridAdd= iTableSelectionSuite->GetAnchor();
					GridAddress gridAdd(row, col);

					GridID targetCellGridID = tableModel->GetGridID(gridAdd);
					if(!targetCellGridID)
					{
						CAlert::InformationAlert("targetCellGridID failed");
						break;
					}

					InterfacePtr<ITextStoryThreadDict> textStoryThreadDict(tableModel, UseDefaultIID());
					if (textStoryThreadDict == nil) 
					{
						CAlert::InformationAlert("textStoryThreadDict failed");
						break;
					}

					InterfacePtr<ITextStoryThread> textStoryThread(textStoryThreadDict->QueryThread(targetCellGridID));
					if (textStoryThread == nil)
					{
						CAlert::InformationAlert("textStoryThread failed");
						break;
					}

					this->getText(textStoryThread);
				}

				/*Remove this if needed*/			//this->InspectTableObject(pageItemRef);
				//	CAlert::InformationAlert("Frame is selected:");
				//}	
				/*
				/////////////////**************************************
				SDKLayoutHelper layoutHelper;
				InterfacePtr<ITextModel> textModel(layoutHelper.GetTextModelRef(graphicFrameData), UseDefaultIID());
				if (!textModel) 
				{
				break;
				}

				// Ask which TextIndex	 should be selected.
				Utils<ISnipRunParameterUtils> parameterUtils;
				int32 totalLength = textModel->TotalLength();
				TextIndex at = 0;
				if (totalLength > 1) 
				{
				at = parameterUtils->GetInt32("TextIndex", 0, 0, totalLength-1);
				if (parameterUtils->WasDialogCancelled()) 
				{
				break;
				}	
				}

				InterfacePtr<ITextFrameColumn> textFrameColumn(this->QueryTextFrameContaining(textModel, at));
				if (!textFrameColumn) 
				{
				break;
				}
				UIDRef graphicFrameRef = this->GetGraphicFrameRef(textFrameColumn, kFalse);*/
				/*if (graphicFrameRef == UIDRef::gNull) 
				{
				break;
				}
				*/
				/*		// Select that frame.
				//if (selectionManager->SelectionExists (kInvalidClass, ISelectionManager::kAnySelection)) 
				//{
				// Clear the selection
				//	selectionManager->DeselectAll(nil);
				//}
				//layoutSelectionSuite->SelectPageItems(UIDList(graphicFrameRef), Selection::kReplace, Selection::kAlwaysCenterInView);
				//				}				
				//}
				//}
				//}*/
				/*
				InterfacePtr<ITextSelectionSuite> iTextSelectionSuite(fCurrentSelection, UseDefaultIID());
				if (iTextSelectionSuite == nil) 
				{
				CAlert::InformationAlert("iTextSelectionSuite Failed");
				}
				else
				{
				InterfacePtr<const IIntegratorTarget> iIntegratorTarget_text(iTextSelectionSuite, UseDefaultIID());
				if(iIntegratorTarget_text == nil)
				break;

				InterfacePtr<const IIntegratorTarget> iIntegratorTarget_text(iTextSelectionSuite, UseDefaultIID());
				if(iIntegratorTarget_text == nil)
				break;

				RangeData rangeData(0,RangeData::kLeanForward);
				UIDRef textRef;

				std::auto_ptr<IIntegratorTarget::TargetSuiteCollection> selectionSuites_text(iIntegratorTarget_text->GetTarget(ITextTarget::kDefaultIID));
				for(IIntegratorTarget::TargetSuiteCollection::size_type i = 0; i < selectionSuites_text->size(); i++)
				{
				ITextTarget* target = (ITextTarget*)selectionSuites_text->at(i).get();
				if(!target)
				continue;

				rangeData = target->GetRange();	
				textRef = target->GetTextModel();

				if(textRef == nil)
				break;

				InterfacePtr<ITextModel> textModel(textRef,UseDefaultIID());

				TextIterator begin(textModel,rangeData.Start(nil));
				TextIterator end(textModel,rangeData.End());


				for (TextIterator iter = begin; iter != end; iter++) 
				{
				const UTF32TextChar characterCode = *iter;
				result.Append(characterCode);
				}

				CAlert::InformationAlert("Selected text is:"+result);
				}*/
			}
		}
	}while (kFalse);
}