Skip to main content
December 6, 2010
Answered

How to get the GridAddress of a given character position?

  • December 6, 2010
  • 1 reply
  • 436 views

Hi,

My starting point is that i know the startposition of a character in a ITextModel. So, i can test if the given position refers to an object in a table or in a regular textframe:

InterfacePtr<ITableModel> tableModel(Utils<ITableUtils>()->GetTableModel(txtModel, startPos + 1), UseDefaultIID());

if(!tableModel){

     //Do things in a textframe (i'm not assuming this is text on a textpath, for simplicity)

} else {

     //Do things on the containing table

}

I'm stuck on the "Do things on the containing table part". I want the containing cell of the text (the gridaddress, i assume?).

Anyone any ideas?

Thanks in advance!

Bart Devos.

This topic has been closed for replies.
Correct answer Chris_Roueche

Bart--

To find the table cell of the insertion point, you could use something like:

InterfacePtr<ITextStoryThread> storythreadp(txtModel->QueryStoryThread(startPos + 1));

InterfacePtr<ICellContent> cellcontentp(storythreadp, UseDefaultIID());

if (! cellcontentp) {

  // Not a table cell, so see if it's the primary thread (kTextStoryBoss/ITextModel).

  InterfacePtr<ITextModel> threadmodelp(storythreadp, UseDefaultIID());

  if (threadmodelp) {

    // It's the primary thread...

  }

  else {

    // It's something else with an ITextStoryThread (note, footnote, etc.).

  }

}

else {

  // The insertion point's in a table cell (kTextCellContentBoss).

  InterfacePtr<ITableModel> tableModel(cellcontentp->GetTableModel(), UseDefaultIID());

  GridID gridID(cellcontentp->GetGridID());

  GridAddress gridLoc(cellcontentp->GetGridAddress());

  // ...and so on.

}

Hope this helps get you where you want to go.

---

Chris Roueche / Freelance Developer

1 reply

Chris_RouecheCorrect answer
Participating Frequently
December 7, 2010

Bart--

To find the table cell of the insertion point, you could use something like:

InterfacePtr<ITextStoryThread> storythreadp(txtModel->QueryStoryThread(startPos + 1));

InterfacePtr<ICellContent> cellcontentp(storythreadp, UseDefaultIID());

if (! cellcontentp) {

  // Not a table cell, so see if it's the primary thread (kTextStoryBoss/ITextModel).

  InterfacePtr<ITextModel> threadmodelp(storythreadp, UseDefaultIID());

  if (threadmodelp) {

    // It's the primary thread...

  }

  else {

    // It's something else with an ITextStoryThread (note, footnote, etc.).

  }

}

else {

  // The insertion point's in a table cell (kTextCellContentBoss).

  InterfacePtr<ITableModel> tableModel(cellcontentp->GetTableModel(), UseDefaultIID());

  GridID gridID(cellcontentp->GetGridID());

  GridAddress gridLoc(cellcontentp->GetGridAddress());

  // ...and so on.

}

Hope this helps get you where you want to go.

---

Chris Roueche / Freelance Developer

December 8, 2010

Chris,

This was exactly what i needed! Thank you very much. You saved my day...

Bart Devos.