Exemplo n.º 1
0
ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor,
                                  ME_DisplayItem *table_row)
{
  WCHAR endl = '\r', tab = '\t';
  ME_DisplayItem *run;
  PARAFORMAT2 *pFmt;
  int i;

  assert(table_row);
  assert(table_row->type == diParagraph);
  if (!editor->bEmulateVersion10) { /* v4.1 */
    ME_DisplayItem *insertedCell, *para, *cell, *prevTableEnd;
    cell = ME_FindItemFwd(ME_GetTableRowStart(table_row), diCell);
    prevTableEnd = ME_GetTableRowEnd(table_row);
    para = prevTableEnd->member.para.next_para;
    run = ME_FindItemFwd(para, diRun);
    editor->pCursors[0].pPara = para;
    editor->pCursors[0].pRun = run;
    editor->pCursors[0].nOffset = 0;
    editor->pCursors[1] = editor->pCursors[0];
    para = ME_InsertTableRowStartFromCursor(editor);
    insertedCell = ME_FindItemFwd(para, diCell);
    /* Copy cell properties */
    insertedCell->member.cell.nRightBoundary = cell->member.cell.nRightBoundary;
    insertedCell->member.cell.border = cell->member.cell.border;
    while (cell->member.cell.next_cell) {
      cell = cell->member.cell.next_cell;
      para = ME_InsertTableCellFromCursor(editor);
      insertedCell = ME_FindItemBack(para, diCell);
      /* Copy cell properties */
      insertedCell->member.cell.nRightBoundary = cell->member.cell.nRightBoundary;
      insertedCell->member.cell.border = cell->member.cell.border;
    };
    para = ME_InsertTableRowEndFromCursor(editor);
    *para->member.para.pFmt = *prevTableEnd->member.para.pFmt;
    /* return the table row start for the inserted paragraph */
    return ME_FindItemFwd(cell, diParagraph)->member.para.next_para;
  } else { /* v1.0 - 3.0 */
    run = ME_FindItemBack(table_row->member.para.next_para, diRun);
    pFmt = table_row->member.para.pFmt;
    assert(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE);
    editor->pCursors[0].pPara = table_row;
    editor->pCursors[0].pRun = run;
    editor->pCursors[0].nOffset = 0;
    editor->pCursors[1] = editor->pCursors[0];
    ME_InsertTextFromCursor(editor, 0, &endl, 1, run->member.run.style);
    run = editor->pCursors[0].pRun;
    for (i = 0; i < pFmt->cTabCount; i++) {
      ME_InsertTextFromCursor(editor, 0, &tab, 1, run->member.run.style);
    }
    return table_row->member.para.next_para;
  }
}
Exemplo n.º 2
0
ME_DisplayItem* ME_GetOuterParagraph(ME_DisplayItem *para)
{
  if (para->member.para.nFlags & MEPF_ROWEND)
    para = para->member.para.prev_para;
  while (para->member.para.pCell)
  {
    para = ME_GetTableRowStart(para);
    if (!para->member.para.pCell)
      break;
    para = ME_FindItemBack(para->member.para.pCell, diParagraph);
  }
  return para;
}
Exemplo n.º 3
0
static void
ME_MoveCursorLines(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs)
{
  ME_DisplayItem *pRun = pCursor->pRun;
  ME_DisplayItem *pItem, *pOldPara, *pNewPara;
  int x = ME_GetXForArrow(editor, pCursor);

  if (editor->bCaretAtEnd && !pCursor->nOffset)
    pRun = ME_FindItemBack(pRun, diRun);
  if (!pRun)
    return;
  pOldPara = ME_GetParagraph(pRun);
  if (nRelOfs == -1)
  {
    /* start of this row */
    pItem = ME_FindItemBack(pRun, diStartRow);
    assert(pItem);
    /* start of the previous row */
    pItem = ME_FindItemBack(pItem, diStartRow);
    if (!pItem)
      return; /* row not found - ignore */
    pNewPara = ME_GetParagraph(pItem);
    if (pOldPara->member.para.nFlags & MEPF_ROWEND ||
        (pOldPara->member.para.pCell &&
         pOldPara->member.para.pCell != pNewPara->member.para.pCell))
    {
      /* Brought out of a cell */
      pNewPara = ME_GetTableRowStart(pOldPara)->member.para.prev_para;
      if (pNewPara->type == diTextStart)
        return; /* At the top, so don't go anywhere. */
      pItem = ME_FindItemFwd(pNewPara, diStartRow);
    }
    if (pNewPara->member.para.nFlags & MEPF_ROWEND)
    {
      /* Brought into a table row */
      ME_Cell *cell = &ME_FindItemBack(pNewPara, diCell)->member.cell;
      while (x < cell->pt.x && cell->prev_cell)
        cell = &cell->prev_cell->member.cell;
      if (cell->next_cell) /* else - we are still at the end of the row */
        pItem = ME_FindItemBack(cell->next_cell, diStartRow);
    }
  }
  else
  {
    /* start of the next row */
    pItem = ME_FindItemFwd(pRun, diStartRow);
    if (!pItem)
      return; /* row not found - ignore */
    /* FIXME If diParagraph is before diStartRow, wrap the next paragraph?
    */
    pNewPara = ME_GetParagraph(pItem);
    if (pOldPara->member.para.nFlags & MEPF_ROWSTART ||
        (pOldPara->member.para.pCell &&
         pOldPara->member.para.pCell != pNewPara->member.para.pCell))
    {
      /* Brought out of a cell */
      pNewPara = ME_GetTableRowEnd(pOldPara)->member.para.next_para;
      if (pNewPara->type == diTextEnd)
        return; /* At the bottom, so don't go anywhere. */
      pItem = ME_FindItemFwd(pNewPara, diStartRow);
    }
    if (pNewPara->member.para.nFlags & MEPF_ROWSTART)
    {
      /* Brought into a table row */
      ME_DisplayItem *cell = ME_FindItemFwd(pNewPara, diCell);
      while (cell->member.cell.next_cell &&
             x >= cell->member.cell.next_cell->member.cell.pt.x)
        cell = cell->member.cell.next_cell;
      pItem = ME_FindItemFwd(cell, diStartRow);
    }
  }
  if (!pItem)
  {
    /* row not found - ignore */
    return;
  }
  pCursor->pRun = ME_FindRunInRow(editor, pItem, x, &pCursor->nOffset, &editor->bCaretAtEnd);
  assert(pCursor->pRun);
  assert(pCursor->pRun->type == diRun);
}
Exemplo n.º 4
0
/* Selects the next table cell or appends a new table row if at end of table */
static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
                                      ME_DisplayItem *run)
{
    ME_DisplayItem *para = ME_GetParagraph(run);
    int i;

    assert(run && run->type == diRun);
    assert(ME_IsInTable(run));
    if (!editor->bEmulateVersion10) { /* v4.1 */
        ME_DisplayItem *cell;
        /* Get the initial cell */
        if (para->member.para.nFlags & MEPF_ROWSTART) {
            cell = para->member.para.next_para->member.para.pCell;
        } else if (para->member.para.nFlags & MEPF_ROWEND) {
            cell = para->member.para.prev_para->member.para.pCell;
        } else {
            cell = para->member.para.pCell;
        }
        assert(cell);
        /* Get the next cell. */
        if (cell->member.cell.next_cell &&
                cell->member.cell.next_cell->member.cell.next_cell)
        {
            cell = cell->member.cell.next_cell;
        } else {
            para = ME_GetTableRowEnd(ME_FindItemFwd(cell, diParagraph));
            para = para->member.para.next_para;
            assert(para);
            if (para->member.para.nFlags & MEPF_ROWSTART) {
                cell = para->member.para.next_para->member.para.pCell;
            } else {
                /* Insert row */
                para = para->member.para.prev_para;
                para = ME_AppendTableRow(editor, ME_GetTableRowStart(para));
                /* Put cursor at the start of the new table row */
                para = para->member.para.next_para;
                editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
                editor->pCursors[0].nOffset = 0;
                editor->pCursors[1] = editor->pCursors[0];
                ME_WrapMarkedParagraphs(editor);
                return;
            }
        }
        /* Select cell */
        editor->pCursors[1].pRun = ME_FindItemFwd(cell, diRun);
        editor->pCursors[1].nOffset = 0;
        assert(editor->pCursors[0].pRun);
        cell = cell->member.cell.next_cell;
        editor->pCursors[0].pRun = ME_FindItemBack(cell, diRun);
        editor->pCursors[0].nOffset = 0;
        assert(editor->pCursors[1].pRun);
    } else { /* v1.0 - 3.0 */
        if (run->member.run.nFlags & MERF_ENDPARA &&
                ME_IsInTable(ME_FindItemFwd(run, diParagraphOrEnd)))
        {
            run = ME_FindItemFwd(run, diRun);
            assert(run);
        }
        for (i = 0; i < 2; i++)
        {
            while (!(run->member.run.nFlags & MERF_TAB))
            {
                run = ME_FindItemFwd(run, diRunOrParagraphOrEnd);
                if (run->type != diRun)
                {
                    para = run;
                    if (ME_IsInTable(para))
                    {
                        run = ME_FindItemFwd(para, diRun);
                        assert(run);
                        editor->pCursors[0].pRun = run;
                        editor->pCursors[0].nOffset = 0;
                        i = 1;
                    } else {
                        /* Insert table row */
                        para = ME_AppendTableRow(editor, para->member.para.prev_para);
                        /* Put cursor at the start of the new table row */
                        editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
                        editor->pCursors[0].nOffset = 0;
                        editor->pCursors[1] = editor->pCursors[0];
                        ME_WrapMarkedParagraphs(editor);
                        return;
                    }
                }
            }
            if (i == 0)
                run = ME_FindItemFwd(run, diRun);
            editor->pCursors[i].pRun = run;
            editor->pCursors[i].nOffset = 0;
        }
    }
}