button + image

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

button + image

eric b-3
Hello,


I'd like to implement a feature into the Tools -> Options dialog  
( svx/source/cui/treeopt.* connected to optgdlg.* )

The idea is to protect the prefs with a password. Shortly : prefs  
protected mean the are in read oonly mode. Not protected : can be  
modified as usual.

It works already well, but there is a missing feature, and I'm a bit  
wondering on how to add that  ...


Basically the missing feature is a button + an image included in it +  
an action associated to change the image :

- feature enabled, we'll display one green open padlock (a .png )
- feature disabled, we'll display a red closed one  ( a .png too )


What is the right way to achieve that ?  More precisely, what type if  
image use ?  ( ImageButton ? Image ? other ? ) .. and shall I  
implement the drawing, and the rendering myself ? (that's what I saw  
in backingwindow.cxx)


Please not that I don't need the code, but the right type of the  
boxes to use ( shall I inherit a Toolbox like in backingwindow.cxx ?  
Or do something else ?) +  some todo list.


At the end, the idea is to document the code and propose a ClassRoom  
about how I did to implement the feature (and other features I'd like  
to explain the way to add them), and then discuss with students the  
solution, improve and so on.


Thanks in advance
Eric Bachard

--
qɔᴉɹə




Reply | Threaded
Open this post in threaded view
|

Re: button + image

Philipp Lohmann
On 3/4/10 2:34 PM, eric b wrote:

> Hello,
>
>
> I'd like to implement a feature into the Tools -> Options dialog (
> svx/source/cui/treeopt.* connected to optgdlg.* )
>
> The idea is to protect the prefs with a password. Shortly : prefs
> protected mean the are in read oonly mode. Not protected : can be
> modified as usual.
>
> It works already well, but there is a missing feature, and I'm a bit
> wondering on how to add that ...
>
>
> Basically the missing feature is a button + an image included in it + an
> action associated to change the image :
>
> - feature enabled, we'll display one green open padlock (a .png )
> - feature disabled, we'll display a red closed one ( a .png too )
>
>
> What is the right way to achieve that ? More precisely, what type if
> image use ? ( ImageButton ? Image ? other ? ) .. and shall I implement
> the drawing, and the rendering myself ? (that's what I saw in
> backingwindow.cxx)

Actually that's not what you saw, the ImageButtons in backingwindow.cxx
are regular image buttons. The BitmapEx drawn there is the background
for the window, not the buttons.

I'd say, yes, use an ImageButton. Add the necessary png files to
default_images in the appropriate directory (probably svx/res or
nowadays cui/res). The load the images from a resource file; actually
for this you can take backingwindow.cxx as an Example.

On that ImageButton you can use SetModeImage to set the image to be
displayed (which you should change when transitioning between
locked/unlocked state).

Just my 2 cents, pl

--
Sanity is just a bad excuse for a lack of imagination.
      -- Author unknown

Registered Office: Sun Microsystems GmbH, Sonnenallee 1, D-85551
Kirchheim-Heimstetten
Commercial register of the Local Court of Munich: HRB 161028
Managing Directors: Thomas Schröder, Wolfgang Engels
Chairman of the Supervisory Board: Martin Häring

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: button + image

eric b-3
Hi Philipp,


Thanks for your light speed answer :)

I didn't answer immediately, because I wanted to experiment first.


Le 4 mars 10 à 14:42, Philipp Lohmann a écrit :

> On 3/4/10 2:34 PM, eric b wrote:
>> Hello,
>>
>> I'd like to implement a feature into the Tools -> Options dialog (
>> svx/source/cui/treeopt.* connected to optgdlg.* )
>>

[...cut...]


>> What is the right way to achieve that ? More precisely, what type if
>> image use ? ( ImageButton ? Image ? other ? ) .. and shall I  
>> implement
>> the drawing, and the rendering myself ? (that's what I saw in
>> backingwindow.cxx)
>
> Actually that's not what you saw, the ImageButtons in  
> backingwindow.cxx are regular image buttons.


Ok.

> The BitmapEx drawn there is the background for the window, not the  
> buttons.


Yes, I know (I did a complete relayout in the start center, to learn  
its foundations)


>
> I'd say, yes, use an ImageButton.


I did :)


> Add the necessary png files to default_images in the appropriate  
> directory (probably svx/res or nowadays cui/res).


Was done since a while : if I'm not too wrong, the name of the .png  
is in the .src, and when the .src are parsed, e.g. in svx, an svx
$LOCALE.ilst (for image list ?) is created in the unx..pro, and  
delivered.

At the end, the .zip is created in the packimage and the .png exists.

Currently I added two .png: one is padlock_open.png  and the second  
is obviously padlock_closed.png (or a name close to that), and both  
are found.



> The load the images from a resource file; actually for this you can  
> take backingwindow.cxx as an Example.


What I did :

1) in .src

declare a color mask :

#define MASKCOLOR  MaskColor = \
        Color { Red = 0xFFFF ; Green = 0x0000 ; Blue = 0xFFFF ; };

2) in the modaldialog, I added two ImageButton entries : one for  
every .png

e.g. :

        ImageButton IMAGE_PADLOCK_OPEN
        {
            Pos = MAP_APPFONT ( (COL_3 + COL_4 )/2 + 5, ROW_3 - 20 ) ;
            Size = MAP_APPFONT ( 16 , 16 ) ;
            TabStop = TRUE ;
            QuickHelpText [ en-US ] = "Click to lock" ;
            QuickHelpText [ fr ] = "Cliquer pour verrouiller" ;
            ButtonImage = Image
            {
                ImageBitmap = Bitmap
                {
                    File = "Padlock1_open.png";
                };
                MASKCOLOR
            };
        };


In treeopt.cxx, I added in the INI_LIST ( used in the  
OfaTreeOptionsDialog ctor), the
following initilization:     aPadlockImageButton     ( this, SVX_RES
( IMAGE_PADLOCK_OPEN ) ),\

+ I added the method  loadImage() implemented as : void  
OfaTreeOptionsDialog::loadImage( const ResId& i_rId, ImageButton&  
i_rButton )



>
> On that ImageButton you can use SetModeImage to set the image to be  
> displayed (which you should change when transitioning between  
> locked/unlocked state).
>

Indeed, I used the same code, and it works, but not completely.  The  
problem I got, is only one image is shown, means only the one  
initialized in the Ctor.

As you noticed, I initialized the imagebutton with the open paclock.  
It works well, but the closed padlock can never be displayed. Instead  
I got a transparent button, but no image.

What did I forget ?


For example, when I unlock/lock the padlock, I use the following  
action -see the code below- (after a click on the ImageButton), where  
IsPadlockLocked() is a method from the aOfMiscTabPage using itself an  
SfxPasswordDialog.  :

IMPL_LINK( OfaTreeOptionsDialog, PadlockHdl_Impl, ImageButton *,  
EMPTYARG )
{
     if ( pCurrentPageEntry && aTreeLB.GetParent( pCurrentPageEntry ) )
     {
         OptionsPageInfo* pPageInfo = (OptionsPageInfo *)
pCurrentPageEntry->GetUserData();
         if ( pPageInfo->m_pPage )
         {
             if ( ( OFA_TP_MISC == pPageInfo->m_nPageId ) )
             {
                 OfaMiscTabPage *  pOfaMiscTabPage = (OfaMiscTabPage  
*)pPageInfo->m_pPage;

                 if ( pOfaMiscTabPage )
                 {
                     bool bIsLocked = pOfaMiscTabPage->IsPadlockLocked
();
#ifdef DEBUG
                     fprintf( stdout, "pOfaMiscTabPage =  
(OfaMiscTabPage *)pPageInfo->m_pPage , bIsLocked == %d \n", bIsLocked);
#endif
                     if ( bIsLocked )
                         loadImage( SVX_RES( IMAGE_PADLOCK_CLOSED ),  
aPadlockImageButton );
                     else
                         loadImage( SVX_RES( IMAGE_PADLOCK_OPEN ),  
aPadlockImageButton );
                 }
             }
         }
     }
     return 0;
}


My questions :


- shall I create and instantiate 2 ImageButton and  Hide() / Show()  
them instead of just loadImage() them ?
- is there a method I missed to change the image with the new one  
locking, unlocking the padlock ?

Thanks in advance :)


> Just my 2 cents, pl


As usual, this helped me a lot :)




Kind regards,
Eric


--
qɔᴉɹə




Reply | Threaded
Open this post in threaded view
|

Re: button + image

Philipp Lohmann
On 3/5/10 1:22 PM, eric b wrote:

>> Add the necessary png files to default_images in the appropriate
>> directory (probably svx/res or nowadays cui/res).
>
>
> Was done since a while : if I'm not too wrong, the name of the .png is
> in the .src, and when the .src are parsed, e.g. in svx, an
> svx$LOCALE.ilst (for image list ?) is created in the unx..pro, and
> delivered.
>
> At the end, the .zip is created in the packimage and the .png exists.

Yes, that's how it currently works.

> Currently I added two .png: one is padlock_open.png and the second is
> obviously padlock_closed.png (or a name close to that), and both are found.

good :-)

>
> What I did :
>
> 1) in .src
>
> declare a color mask :
>
> #define MASKCOLOR MaskColor = \
> Color { Red = 0xFFFF ; Green = 0x0000 ; Blue = 0xFFFF ; };

You can probably skip the mask color (unless your PNG files actually
contain magenta where the mask should be). Nowadays png files with alpha
mask work just fine.

> 2) in the modaldialog, I added two ImageButton entries : one for every .png
>
> e.g. :
>
> ImageButton IMAGE_PADLOCK_OPEN
> {
> Pos = MAP_APPFONT ( (COL_3 + COL_4 )/2 + 5, ROW_3 - 20 ) ;
> Size = MAP_APPFONT ( 16 , 16 ) ;
> TabStop = TRUE ;
> QuickHelpText [ en-US ] = "Click to lock" ;
> QuickHelpText [ fr ] = "Cliquer pour verrouiller" ;
> ButtonImage = Image
> {
> ImageBitmap = Bitmap
> {
> File = "Padlock1_open.png";
> };
> MASKCOLOR
> };
> };
>
>
> In treeopt.cxx, I added in the INI_LIST ( used in the
> OfaTreeOptionsDialog ctor), the
> following initilization: aPadlockImageButton ( this, SVX_RES(
> IMAGE_PADLOCK_OPEN ) ),\
>
> + I added the method loadImage() implemented as : void
> OfaTreeOptionsDialog::loadImage( const ResId& i_rId, ImageButton&
> i_rButton )
>
>
>
>>
>> On that ImageButton you can use SetModeImage to set the image to be
>> displayed (which you should change when transitioning between
>> locked/unlocked state).
>>
>
> Indeed, I used the same code, and it works, but not completely. The
> problem I got, is only one image is shown, means only the one
> initialized in the Ctor.

The way you describe it you created two buttons where you wanted to have
one button and two images. I'd use one ImageButton and set the
apropriate image on it when changing state.

So as resource have

Image IMAGE_PADLOCK_OPEN
{
  ImageBitmap = Bitmap
  {
   File = "Padlock1_open.png";
  };
};

Image IMAGE_PADLOCK_CLOSED
{
  ImageBitmap = Bitmap
  {
   File = "Padlock1_closed.png";
  };
};

ImageButton BTN_PADLOCK
{
  Pos = MAP_APPFONT ( (COL_3 + COL_4 )/2 + 5, ROW_3 - 20 ) ;
  Size = MAP_APPFONT ( 16 , 16 ) ;
  TabStop = TRUE ;
  QuickHelpText [ en-US ] = "Click to lock" ;
  QuickHelpText [ fr ] = "Cliquer pour verrouiller" ;
};

and then use SetModeImage to set the image on the one button, when t
changes state.


> - shall I create and instantiate 2 ImageButton and Hide() / Show() them
> instead of just loadImage() them ?

Possible, but not necessary.

> - is there a method I missed to change the image with the new one
> locking, unlocking the padlock ?

Possibly call Invalidate() after changing the image on the button; I'd
expect that not to be necessary, but am not sure.

Kind regards, pl

--
"If the designers of X-window built cars, there would be no fewer than five
  steering wheels hidden about the cockpit, none of which followed the same
  principles -- but you'd be able to shift gears with your car stereo.
  Useful feature, that."
                 -- From the programming notebooks of a heretic, 1990.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: button + image

eric b-3
Hi Philipp,

Philipp Lohmann a écrit :
> You can probably skip the mask color (unless your PNG files actually
> contain magenta where the mask should be). Nowadays png files with alpha
> mask work just fine.

Noticed.

>> Indeed, I used the same code, and it works, but not completely. The
>> problem I got, is only one image is shown, means only the one initialized in the Ctor.
>
> The way you describe it you created two buttons where you wanted to have one button and two images. I'd use one ImageButton and set the
> apropriate image on it when changing state.
>
> So as resource have
>
> Image IMAGE_PADLOCK_OPEN
> {
>  ImageBitmap = Bitmap
>  {
>   File = "Padlock1_open.png";
>  };
> };
>
> Image IMAGE_PADLOCK_CLOSED
> {
>  ImageBitmap = Bitmap
>  {
>   File = "Padlock1_closed.png";
>  };
> };
>
> ImageButton BTN_PADLOCK
> {
>  Pos = MAP_APPFONT ( (COL_3 + COL_4 )/2 + 5, ROW_3 - 20 ) ;
>  Size = MAP_APPFONT ( 16 , 16 ) ;
>  TabStop = TRUE ;
>  QuickHelpText [ en-US ] = "Click to lock" ;
>  QuickHelpText [ fr ] = "Cliquer pour verrouiller" ;
> };
>
> and then use SetModeImage to set the image on the one button, when t
> changes state.

Many thanks for the tip. Unfortunaly, it does not work. The reason why I
used two buttons is that I need two different QuickHelpText (one per
status), but I can change with fixed text and Show() Hide() or something
similar. I thought Hide() Show() works well. Just the images do not show.

Nevertheless, I think I have fully understood how to create the layout,
and my main problem seems to be the use of the two images, maybe the
initialization or something silly I forgot.

To tell you more, the better I had, was the button appearing at the
beginning, and once I clicked, it disappeared, or was hidden (I don't
know exactly). Was with my first (wrong) attempt.

To save your time, I'll continue to search, but maybe you could just
remind me the normal list of things to be done ?

for example, is it mandatory to check/set the state of the buttons ?

I did :
aPadlockImageButton.SetClickHdl( LINK( this, OfaTreeOptionsDialog,
PadlockHdl_Impl ) );

in InitTreeAndHandler(), plus simply Show/Hide() when neede, but maybe
that's not enough ?


>> - shall I create and instantiate 2 ImageButton and Hide() / Show() them
>> instead of just loadImage() them ?
>
>
> Possible, but not necessary.

That's the current work in progress, but it does not work either : no
image is shown at all, but the buttons work perfectly using Show(),
Hide(), and the QuickHelp texts work perfectly too. Just the missing
images ..


>> - is there a method I missed to change the image with the new one
>> locking, unlocking the padlock ?
>
>
> Possibly call Invalidate() after changing the image on the button; I'd
> expect that not to be necessary, but am not sure.

Tested without success either.

Certainly something simple I missed :/


Kind regards,
Eric

--
Education Project:
http://wiki.services.openoffice.org/wiki/Education_Project
Projet OOo4Kids : http://wiki.ooo4kids.org/index.php/Main_Page
L'association EducOOo : http://www.educoo.org
Blog : http://eric.bachard.free.fr/news

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[SOLVED]Re: [gsl-dev] button + image

eric b-3
Hi,

In fact, the solution (if correct) I found was :

- use two ImageButton's, and declare one image per ImageButton in  
the .src
- draw only once every image
- Hide(), Show when needed

Works well there

But  *not* loadImage() more than once, i.e. not use SetModeImage more  
than one time, because this was the root of the problems.

All the other tries I did don't work.


Thanks again to Philipp, for his great help.


Regards,
Eric Bachard

>
> Tested without success either.
>
> Certainly something simple I missed :/
>
>
> Kind regards,
> Eric
>
> --
> Education Project:
> http://wiki.services.openoffice.org/wiki/Education_Project
> Projet OOo4Kids : http://wiki.ooo4kids.org/index.php/Main_Page
> L'association EducOOo : http://www.educoo.org
> Blog : http://eric.bachard.free.fr/news
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

--
qɔᴉɹə