Tutorial About

From Apache OpenOffice Wiki
Revision as of 13:47, 22 April 2014 by Jevan (Talk | contribs)

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

If we set SourceMain in cygwin to point to the main folder of aoo-trunk, by replacing .... with the relevant directories.

SourceMain="/cygdrive/c/..../aoo-trunk/main"

The files that we will be modifying for this tutorial are:

$SourceMain/cui/source/dialogs/about.cxx $SourceMain/cui/source/inc/about.hxx

Other relevant files (not modified):

$SourceMain/cui/source/dialogs/about.hrc $SourceMain/cui/source/dialogs/about.src

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:

Index: about.hxx
===================================================================
diff --git a/openoffice/trunk/main/cui/source/inc/about.hxx b/openoffice/trunk/main/cui/source/inc/about.hxx
--- a/openoffice/trunk/main/cui/source/inc/about.hxx	(revision 1583953)
+++ b/openoffice/trunk/main/cui/source/inc/about.hxx	(working copy)
@@ -38,6 +38,7 @@
 {
 private:
     OKButton            maOKButton;
+    OKButton        	maOKSureButton;
     PushButton          maReadmeButton;
     FixedInfo           maVersionText;
     MultiLineEdit       maBuildInfoEdit;

Then we initialize it the same way the other button is initialized, and add it into the dialog.

Index: about.cxx
===================================================================
diff --git a/openoffice/trunk/main/cui/source/dialogs/about.cxx b/openoffice/trunk/main/cui/source/dialogs/about.cxx
--- a/openoffice/trunk/main/cui/source/dialogs/about.cxx	(revision 1583953)
+++ b/openoffice/trunk/main/cui/source/dialogs/about.cxx	(working copy)
@@ -283,6 +283,7 @@
 AboutDialog::AboutDialog( Window* pParent, const ResId  & rId ) :
     SfxModalDialog( pParent, rId ),
     maOKButton( this, ResId( RID_CUI_ABOUT_BTN_OK, *rId.GetResMgr() ) ),
+    maOKSureButton( this, ResId( RID_CUI_ABOUT_BTN_OK, *rId.GetResMgr() ) ),
     maReadmeButton( this, ResId( RID_CUI_ABOUT_BTN_README, *rId.GetResMgr() ) ),
     maVersionText( this, ResId( RID_CUI_ABOUT_FTXT_VERSION, *rId.GetResMgr() ) ),
     maBuildInfoEdit( this, ResId( RID_CUI_ABOUT_FTXT_BUILDDATA, *rId.GetResMgr() ) ),
@@ -474,6 +475,13 @@
     Point aOKPnt( ( aDlgSize.Width() - aOKSiz.Width() ) - a6Size.Width(), nY );
     maOKButton.SetPosPixel( aOKPnt );
 
+    // OK-Button-Position (at the bottom and centered)
+    Size aOKSureSiz = maOKSureButton.GetSizePixel();
+    Point aOKSurePnt = maOKSureButton.GetPosPixel();
+    aOKSurePnt.X() = -135 + ( aDlgSize.Width() - aOKSureSiz.Width() ) - a6Size.Width();
+    aOKSurePnt.Y() = nY;
+	maOKSureButton.SetPosPixel( aOKSurePnt );
+    
     maReadmeButton.SetPosPixel( Point(a6Size.Width(), nY) );
 
     aDlgSize.Height() = aOKPnt.Y() + aOKSiz.Height() + a6Size.Width();

With that, we're ready to go! Rebuild cui 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 :-) The original OK button is in the bottom right, and the new OK button is to the left of it.

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.


Next: Tutorial_Charmap
Personal tools