Tutorial About

From Apache OpenOffice Wiki
Revision as of 16:57, 16 May 2006 by ErAck (Talk | contribs)

Jump to: navigation, search
Hack the Dialog! Tutorial_Help

Well, I seem to love the About Dialog so much, so let's go poke the holy dialog itself - so we already know that the dialog is common across all the applications, so it would not be in their top-level projects, so it's probably in one of the others.

And what do we search for ? The OOo code follows a pretty nice naming convention, so you can guess that the About Dialog might just be named 'about', which in fact it is. So doing a quick 'find -name *about*' in sfx2 returns a set of results which also includes just the files we're interested in as well: about.hxx, about.cxx, about.hrc and about.src.

This is the typical layout in OOo for most dialogs. There is a cxx file that handles the dialog itself, which would most typically involve the declarations being placed in a hxx file. The dialog's resources are typically in the src file and the corresponding declarations in the hrc file. Cool! Let's hack! :-)

First poke around a little and see that it does a couple of things and has an OK button, so let's keep the hack simple - we'll just add in a second OK button to make ourselves happy :-) All it would involve is duplicating the existing OK button to add in our new button and move it so it's visible. And requires modifying only two of the files.

So first we add in the declaration in the header file:

--- sfx2/inc/about.hxx  2004-01-06 21:46:50.000000000 +0530
+++ sfx2/inc/about.hxx  2004-12-20 22:02:49.222155400 +0530
@@ -88,6 +88,7 @@ class AboutDialog : public SfxModalDialo
 {

  private:
        OKButton        aOKButton;
+       OKButton        aOKSureButton;
        Image                   aAppLogo;
 
        FixedInfo       aVersionText;

Then we initialize it the same way the other button is initialized:

--- sfx2/source/dialog/about.cxx        2004-12-07 18:51:37.000000000 +0530
+++ sfx2/source/dialog/about.cxx        2004-12-20 22:05:51.366465256 +0530
@@ -109,6 +109,7 @@ AboutDialog::AboutDialog( Window* pParen
        SfxModalDialog  ( pParent,      rId ),
 
        aOKButton       ( this,         ResId( ABOUT_BTN_OK ) ),
+       aOKSureButton   ( this,         ResId( ABOUT_BTN_OK ) ),
        aVersionText    ( this,         ResId( ABOUT_FTXT_VERSION ) ),
        aCopyrightText  ( this,         ResId( ABOUT_FTXT_COPYRIGHT ) ),
        aDeveloperAry   (                       ResId( ABOUT_STR_DEVELOPER_ARY ) ),

After which we add it into the dialog:

--- sfx2/source/dialog/about.cxx        2004-12-07 18:51:37.000000000 +0530
+++ sfx2/source/dialog/about.cxx        2004-12-20 22:05:51.366465256 +0530
@@ -247,6 +248,14 @@ AboutDialog::AboutDialog( Window* pParen
        aOKPnt.X() = ( aOutSiz.Width() - aOKSiz.Width() ) / 2;
        aOKPnt.Y() = nY + 8;
        aOKButton.SetPosPixel( aOKPnt );
+
+       // OK-Button-Position (at the bottom and centered)
+       Size aOKSureSiz = aOKSureButton.GetSizePixel();
+       Point aOKSurePnt = aOKSureButton.GetPosPixel();
+       aOKSurePnt.X() = 135 + ( aOutSiz.Width() - aOKSureSiz.Width() ) / 2;
+       aOKSurePnt.Y() = nY + 8;
+       aOKSureButton.SetPosPixel( aOKSurePnt );
+
        nY = aOKPnt.Y() + aOKSiz.Height() + a6Size.Height();
        aOutSiz.Height() = nY;
        SetOutputSizePixel( aOutSiz );

With that, we're ready to go! Rebuild sfx2 and launch soffice and you can launch the About Dialog either with the Ctrl+T or the toolbar icon, and presto! We have the new OK button :-)

Doesnt really do much though. You can fiddle around with the different options and see what happens in each case.

But this is one way the dialogs could be drawn up, the other way - as is done in a lot of the other dialogs - is where the dialog structure is in the src files and not done programmatically as it's done here.


ok-ok-about-button.diff Next: Tutorial_Charmap
Personal tools