[haiku-3rdparty-dev] Re: BPictureButton with own BMessenger

  • From: Robert Stiehler <r.stiehler85@xxxxxxxxxxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Thu, 3 Mar 2011 12:27:41 +0100

Hmmm but the Deskbar wouldn't know my custom BPictureButton class. So the
Deskbar could just instantiate it from the BPictureButton class my custom
class inherits from and so my own Invoke() Method would never be called
in/from the Deskbar... or i'm wrong?

regards,
Robert


2011/3/3 Stephan Aßmus <superstippi@xxxxxx>

> On 03.03.2011 11:59, Robert Stiehler wrote:
>
>> Yes, the application is Running and overwrites the MessageReceived
>> Method in the class which extends BApplication. But to explain more:
>>
>> I have a "normal" Application which extends BApplication and has a
>> BWindow. In the overwritten method from BApplication "ReadyToRun()" i
>> set an DeskbarIcon while doing this:
>>
>>     BPicture *mPicture = new BPicture();
>>     BPictureButton mBtnCall = new BPictureButton(BRect(0, 0, 16, 16),
>> "deskbar icon", mPicture, mPicture, new BMessage('picC'),
>> B_TWO_STATE_BUTTON);
>>
>>     BMessenger objMessanger("application/x-vnd.TestXYZ");
>>     mBtnCall->SetTarget(objMessanger);
>>     BDeskbar mDeskbar;
>>     status_t err = mDeskbar.AddItem(mBtnCall, &mDeskbarIconId);
>>
>> The adding to the Deskbar works, i have the BPictureButton in the
>> Deskbar, like i expected.
>>
>> The BApplication constructor gets "application/x-vnd.TestXYZ" as
>> parameter. If the BPictureButton i added to the BDeskbar is clicked a
>> BMessage should be send to my Applications MessageReceived method, but
>> it doesn't work.
>>
>> In my understanding the AddItem method if the Deskbar archive's the
>> given object and sends it to the Deskbar, is it possible that it doesn't
>> archive the BMessenger and after instantiating in the Deskbar the
>> standard BMessenger of the Deskbar is used?
>>
>
> Yes, that is exactly the problem, I think so too. I am not sure whether the
> unarchiving should indeed restore the target messenger, as that may or may
> not work anyway. For example, when you restart your system, the Deskbar
> could be started before the other application, and then the messenger would
> not be valid. I admit I don't know off-hand how BMessengers are archived and
> if the messenger could become valid during it's livetime.
>
> The solution/workaround for your problem would be to write a custom
> BPictureButton, which overrides the Invoke() method. In the method, you can
> create the BMessenger on the fly each time the method is called. That way
> you would always try to send the message to the correct application, even
> when it has been restarted in the meantime.
>
> Best regards,
> -Stephan
>
>

Other related posts: