Re-drawing a document after changes

From: Dr William Bland (wjb@abstractnonsense.com)
Date: Mon Nov 11 2002 - 04:33:58 EST

  • Next message: Rui Miguel Silva Seabra: "Re: commit: Make xft print properly (I think)."

    Hi all,
            Ok, I've got the hang of stepping through a document, and now I've
    successfully made changes to its piecetable. The missing link is
    re-displaying the document.

    The following code works, but I can only see the changes if I save and
    re-load the document. Otherwise the display doesn't get updated.
    Any hints gratefully received.

    Best wishes,
                    Bill.

    PS: Note that I added PT_BufIndex::changeBufIndex(), but it just does
    what you would expect.

    void replace_first_text_frag( char* str, int length )
    {
      XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame();
      FV_View* myview = static_cast<FV_View*>(pFrame->getCurrentView());
      PD_Document* mydoc = myiew->getDocument();
      pt_PieceTable* mypt = mydoc->getPieceTable();
      pf_Fragments* myfrags = &(mypt->getFragments());

      for( pf_Frag* pf = myfrags->getFirst(); (pf); pf=pf->getNext() )
        {
          if( pf->getType() == pf_Frag::PFT_Text )
              {
                pf_Frag_Text* pfText = static_cast<pf_Frag_Text*>(pf);
                printf( "Replacing first text frag with %s (length is %d)\n",
                        str, length );
                PT_BufIndex* newIndex = AbiInternString( asciiToUcs( str, length ),
                                                         length );
                if( newIndex )
                  {
                    pfText->changeLength( length );
                    pfText->changeBufIndex( *newIndex );
                  }
                // Try to redraw the document...
                (myview->getLayout())->updateLayout(); // please work
                myview->updateLayout(); // pretty please
                myview->_generalUpdate(); // I'm begging now
                updateScreen(); // don't make me cry
                return;
              }
        }
    }

    inline static PT_BufIndex* AbiInternString( const UT_UCSChar* stringBuffer,
                                                UT_uint32 length )
    {
      PT_BufIndex* toret = new PT_BufIndex();
      pt_VarSet* myVarSet = &(((getCurrentDocument())->getPieceTable())->getVarSet());
      if( myVarSet->appendBuf( stringBuffer, length, toret ) )
        return toret;
      else
        {
          delete toret;
          return NULL;
        }
    }



    This archive was generated by hypermail 2.1.4 : Mon Nov 11 2002 - 04:30:19 EST