Chapter 2. KOffice Technology

KParts - the building blocks of KOffice

Each KOffice application is designed to fulfill very specific needs. For example, KSpread is a program for manipulating spreadsheets, while KWord is a program for word processing. By focusing on a specific area, each program aims for perfection in exactly this area. However, depending on what you do with KOffice, you'll often want to take advantage of functionality provided by different applications, but in the same document.

Suppose that you are preparing a document in KWord and want to illustrate some point using a table. While KWord provides its own functionality for the insertion of tables, this may not be enough for your needs. For example, you may want to use certain currency data formats or to do calculations using spreadsheet formulae. Now, some KWord programmer certainly could try to implement this functionality. However, KWord would never be as good as KSpread in this field; and if it tried to implement all the functionality you might possibly need, it would end up becoming unreasonably complex and the source code would become impossible to maintain.

The alternative to this is KParts. Its philosophy is simple: let every application do what it does best.

Compound documents with KParts

With KParts, your documents can use all functionality offered by all KOffice applications. You can take advantage of this by inserting so-called parts into your document. Every one of those parts is essentially another document, that is, a document within a document.

In the example mentioned above, you would simply insert a KSpread part into your KWord document. Then, whenever you edit your table, KSpread would take control in the background. Control would return to KWord when you stop working on the table and start working on text again. The only change you would notice is that the toolbars and menus, while editing the table, reflect the functionality of KSpread instead of that of KWord. This ability to include the functionality of one application in another is called embedding.

Using KParts in your document

If you have never worked with compound documents, you may find them confusing at first. The following step-by-step instructions show you that using KParts is just as easy as working with a single application.

Procedure 2.1. Inserting a KSpread part into a KWord application

  1. Start KWord. You can do that either from the panel or by typing kword at the command line.

  2. Start a new, blank document. You may want to type some sample text.

  3. Select InsertObject FrameSpreadsheets. You'll notice that the mouse cursor has changed to a cross. This form of the cursor indicates that you are supposed to select an area.

  4. Press the left mouse button mouse button where you want the upper left corner of your table to be, hold it and drag it to the lower right corner. Release the button. Now a dialog appears that gives you the possibility to insert an existing document or to create a new one. Create a blank worksheet. That's it--you're done.

Easy, isn't it? You should now see a table frame in your KWord document. Now, doubleclick inside the table to see what happens. You'll notice that:

  • Your menubars and toolbars have changed. They now reflect those of KSpread.

  • Your table frame now contains the elements of a KSpread view, with scrollbars, a tab bar for the selection of tables, etc.

Try editing the table. You'll see that it's not different from using KSpread. In fact you are using KSpread.

Now click somewhere into your KWord document, outside of the table area. The menubars and toolbars should change back to those of KWord, the elements of the KSpread view should disappear. Your table stays and still reflects all of the changes you've applied to it.

KParts are easy to use. Try inserting other parts or even parts in parts.