Difference between revisions of "Tutorial About"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 2: Line 2:
 
  <tr>
 
  <tr>
 
   <td align="left">Hack the Dialog!</td>
 
   <td align="left">Hack the Dialog!</td>
  <td align="right">[[Tutorial_Help]]</td>
 
 
  </tr>  
 
  </tr>  
 
</table>
 
</table>

Revision as of 13:19, 22 April 2014

Hack the Dialog!

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 CUI returns a set of results which also includes just the files we're interested in as well: about.hxx and about.cxx.

Typically there would also be the files about.hrc and about.src, alas exactly in this case things changed and this article is a bit outdated and nowadays doesn't match reality anymore and isn't the best example for a set of dialog files and their naming. The resource files now (2007-07-23) are located in svx/source/intro/{intro_tmpl.hrc,ooo.src}

Anyway, with accompanying about.[hs]rc this would be 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:

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

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

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

--- cui/source/dialogs/about.cxx        2004-12-07 18:51:37.000000000 +0530
+++ cui/source/dialogs/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, *rId.GetResMgr() ) ),
+	aOKSureButton   ( this,         ResId( ABOUT_BTN_OK, *rId.GetResMgr() ) ),
        aVersionText 	( this, 	ResId( ABOUT_FTXT_VERSION, *rId.GetResMgr() ) ),
        aCopyrightText  ( this,         ResId( ABOUT_FTXT_COPYRIGHT, *rId.GetResMgr() ) ),

After which we add it into the dialog:

--- cui/source/dialogs/about.cxx        2004-12-07 18:51:37.000000000 +0530
+++ cui/source/dialogs/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 sfx2cui 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