From The Document Foundation Wiki
Jump to: navigation, search

DISCLAIMER: This page contains some random notes about the code. It may not be true and will evolve with the progress of my understanding of the Sw code.

Debugging utils

In order to get a human-readable representation of the internals for a document do the following:

  • export SW_DEBUG=t
  • ./soffice.bin path/to/the/document
  • Hit F12 to dump the layout structure in $PWD/layout.xml or Shift-F12 to dump the document model structure in $PWD/nodes.xml
  • For layout debugging, try OSL_DEBUG_LAYOUT values 1 and more

Document Model

Getting the attributes for a SwPaM

SwUnoCursorHelper::GetCrsrAttr() is a nice example for this, here is an (untested) example from it:

SfxItemSet aCharAttrsAtPaM( pPaM->GetDoc()->GetAttrPool(),
                            RES_CHRATR_BEGIN, RES_CHRATR_END -1,
                            0 );

// TODO Get an SwTxtNode pNd and a xub_StrLen nStart and nEnd offset from the SwPaM

static_cast<SwTxtNode*>(pNd)->GetAttr(aCharAttrsAtPaM, nStart, nEnd, bOnlyTxtAttr, bGetFromChrFmt);

// Do something with aCharAttrsAtPaM

Styles structures

Graph showing the styles classes in sw

In Writer, sfx2 structures for styles aren't really used: sw is only emulating them to show styles in some common dialogs like Styles and Formatting


From paragraph to lines

Drawing objects

I got the following informations from Oliver Rainer-Wittman's talk in Orvieto.

  • One draw model + one draw page
  • Invisible Layers: to hide objects in hidden parts of the document (eg: hidden sections)
  • Virtual Drawing Object: Placeholder for repeated objects (eg, objects in header/footers)

Misc Discoveries

  • Convert an SwPosition into a screen position is possible using SwTxtFrm::GetCharRect( )
  • The difference between SwFrm::Frm() and SwFrm::Prt() seems to be only when we have borders around the frame (See this comment)



Code Pointers:

Sfx2 bits

Here are some random notes from what I learned when hacking the InfoBars:

  • Give the focus to the document: pViewFrame()->GetWindow()->GrabFocusToDocument( )
  • Adding a new UI element:
    • create a new SfxChildWindow class. This is used to register the Window in the SfxFrame children.
    • The new FooChildWindow constructor needs to create the vcl Window to show.
    • To get inspiration from other ChildWindows, grok for SwInputChild (the formula bar in Writer).
  • Updating the SfxFrame children from the SfxChildWindow:
    • Make sure you have stored the SfxBindings* as a member: it'll provide the way back to the SfxViewFrame
    • Get the hand on the SfxViewFrame: m_pBindings->GetDispatcher( )->GetFrame( )
    • Use ShowChildWindow( nId ) to update the child window. SetPosSizePixel( ) on the Window object of your Child window won't be used unless this is called.