Difference between revisions of "Tutorial About"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 9: Line 9:
 
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.
 
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 <s>sfx2</s> CUI returns a set of results which also includes just the files we're interested in as well: about.hxx and about.cxx.
+
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.
  
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 <tt>svx/source/intro/{intro_tmpl.hrc,ooo.src}</tt>
+
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 <tt>svx/source/intro/{intro_tmpl.hrc,ooo.src}</tt>
  
 
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! :-)
 
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! :-)
Line 20: Line 34:
  
 
<pre>
 
<pre>
--- cui/source/inc/about.hxx 2004-01-06 21:46:50.000000000 +0530
+
Index: about.hxx
+++ cui/source/inc/about.hxx 2004-12-20 22:02:49.222155400 +0530
+
===================================================================
@@ -88,6 +88,7 @@ class AboutDialog : public cuiModalDialo
+
--- about.hxx (revision 1583953)
 +
+++ about.hxx (working copy)
 +
@@ -38,6 +38,7 @@
 
  {
 
  {
 
+
private:
  private:
+
    OKButton           maOKButton;
        OKButton       aOKButton;
+
+   OKButton       maOKSureButton;
+       OKButton       aOKSureButton;
+
    PushButton          maReadmeButton;
        Image                  aAppLogo;
+
    FixedInfo          maVersionText;
+
    MultiLineEdit       maBuildInfoEdit;
        FixedInfo       aVersionText;
+
 
</pre>
 
</pre>
  
Then we initialize it the same way the other button is initialized:
+
Then we initialize it the same way the other button is initialized, and add it into the dialog.
  
 
<pre>
 
<pre>
--- cui/source/dialogs/about.cxx       2004-12-07 18:51:37.000000000 +0530
+
Index: about.cxx
+++ cui/source/dialogs/about.cxx       2004-12-20 22:05:51.366465256 +0530
+
===================================================================
@@ -109,6 +109,7 @@ AboutDialog::AboutDialog( Window* pParen
+
--- about.cxx (revision 1583953)
        SfxModalDialog ( pParent,      rId ),
+
+++ 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)
aOKButton      ( this, ResId( ABOUT_BTN_OK, *rId.GetResMgr() ) ),
+
+   Size aOKSureSiz = maOKSureButton.GetSizePixel();
+ aOKSureButton  ( this,        ResId( ABOUT_BTN_OK, *rId.GetResMgr() ) ),
+
+   Point aOKSurePnt = maOKSureButton.GetPosPixel();
        aVersionText ( this, ResId( ABOUT_FTXT_VERSION, *rId.GetResMgr() ) ),
+
+   aOKSurePnt.X() = -135 + ( aDlgSize.Width() - aOKSureSiz.Width() ) - a6Size.Width();
        aCopyrightText  ( this,        ResId( ABOUT_FTXT_COPYRIGHT, *rId.GetResMgr() ) ),
+
+   aOKSurePnt.Y() = nY;
 
+
+ maOKSureButton.SetPosPixel( aOKSurePnt );
</pre>
+
+  
 
+
    maReadmeButton.SetPosPixel( Point(a6Size.Width(), nY) );
After which we add it into the dialog:
+
 
+
    aDlgSize.Height() = aOKPnt.Y() + aOKSiz.Height() + a6Size.Width();
<pre>
+
</pre>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.
--- 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 );
+
</pre>
+
 
+
With that, we're ready to go! Rebuild <s>sfx2</s>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 :-)
+
  
 
Doesnt really do much though. You can fiddle around with the different options and see what happens in each case.
 
Doesnt really do much though. You can fiddle around with the different options and see what happens in each case.
Line 81: Line 87:
 
<table width=100%>
 
<table width=100%>
 
  <tr>
 
  <tr>
  <td align="left">[http://go-oo.org/tutorials/ok-ok-about-button.diff.txt ok-ok-about-button.diff]</td>
 
 
   <td align="right">Next: [[Tutorial_Charmap]]</td>
 
   <td align="right">Next: [[Tutorial_Charmap]]</td>
 
  </tr>  
 
  </tr>  

Revision as of 13:28, 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 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
===================================================================
--- about.hxx	(revision 1583953)
+++ 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
===================================================================
--- about.cxx	(revision 1583953)
+++ 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