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

  • From: Robert Stiehler <r.stiehler85@xxxxxxxxxxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Fri, 4 Mar 2011 01:32:37 +0100

Hi,

tried it but now change, same problem, same error ;/

actual code:

CustomPictureButton::CustomPictureButton(BRect frame,
                        const char* name,
                        BPicture *off,
                        BPicture *on,
                        BMessage *message,
                        uint32 behavior,
                        uint32 resizeMask,
                        uint32 flgs)
: BPictureButton(frame, name, off, on, message, behavior, resizeMask, flgs)
{
}


CustomPictureButton::CustomPictureButton(BMessage *msg)
: BPictureButton(msg) {
}


CustomPictureButton::~CustomPictureButton() {
}


status_t
CustomPictureButton::Archive(BMessage *msg, bool deep) const {
    status_t err;

    err = BPictureButton::Archive(msg, deep);
    msg->AddString("class", "CustomPictureButton");
    return err;
}


CustomPictureButton*
CustomPictureButton::Instantiate(BMessage *msg) {
    if (!validate_instantiation(msg, "CustomPictureButton")) {
        return NULL;
    }
    return new CustomPictureButton(msg);
}

Maybe a problem in Instantiate() method or the constructor
"CustomPictureButton(BMessage *msg)"?


2011/3/4 Brian Hill <perelandra777@xxxxxxxxx>

>
> On Mar 3, 2011, at 5:37 PM, Robert Stiehler wrote:
>
> > Hi Brian,
> >
> > actual i try it with my own CustomPictureButton way. Now i have the
> problem that the adding of my custom picture button to the deskbar doesn't
> work. AddItem(...) returns with error.
> >
> > My CustomPictureButton class looks like this:
> > CustomPictureButton.h
> > ################################################
> > #ifndef CUSTOMPICTUREBUTTON_H
> > #define CUSTOMPICTUREBUTTON_H
> >
> > #include <Message.h>
> > #include <PictureButton.h>
> >
> > class _EXPORT CustomPictureButton : public BPictureButton {
> > public:
> >     CustomPictureButton(BRect frame,
> >                         const char* name,
> >                         BPicture *off,
> >                         BPicture *on,
> >                         BMessage *message,
> >                         uint32 behavior = B_ONE_STATE_BUTTON,
> >                         uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
> >                         uint32 flgs = B_WILL_DRAW | B_NAVIGABLE);
> >      CustomPictureButton(BMessage *msg);
> >     ~CustomPictureButton();
> >
> >     status_t Archive(BMessage *data, bool deep) const;
> >     static BArchivable *Instantiate(BMessage *data);
> > };
> >
> > #endif
> >
> > ###########################################
> >
> > CustomPictureButton.cpp
> >
> > ###########################################
> >
> > #include "CustomPictureButton.h"
> >
> > CustomPictureButton::CustomPictureButton(BRect frame,
> >                         const char* name,
> >                         BPicture *off,
> >                         BPicture *on,
> >                         BMessage *message,
> >                         uint32 behavior,
> >                         uint32 resizeMask,
> >                         uint32 flgs)
> > : BPictureButton(frame, name, off, on, message, behavior, resizeMask,
> flgs)
> > {
> > }
> >
> >
> > CustomPictureButton::CustomPictureButton(BMessage *msg)
> > : BPictureButton(msg) {
> > }
> >
> >
> > CustomPictureButton::~CustomPictureButton() {
> > }
> >
> >
> > status_t
> > CustomPictureButton::Archive(BMessage *msg, bool deep) const {
> >     status_t err;
> >
> >     err = BPictureButton::Archive(msg, deep);
> >     return err;
> > }
> >
> >
> > BArchivable*
> > CustomPictureButton::Instantiate(BMessage *msg) {
> >     if (!validate_instantiation(msg, "CustomPictureButton")) {
> >         return NULL;
> >     }
> >     return new CustomPictureButton(msg);
> > }
> >
> > ###########################################
> >
> > I try to add it to the deskbar with this:
> >
> > BPicture *mPicture = new BPicture();
> > CustomPictureButton *mBtnCall = new CustomPictureButton(BRect(0, 0, 16,
> 16), "deskbar icon", mPicture, mPicture, new BMessage('picC'),
> B_TWO_STATE_BUTTON);
> >
> > status_t err = mDeskbar.AddItem(mBtnCall/*, &mDeskbarIconId*/);
> >
> > if (err != B_OK) {
> >         BAlert *alert = new BAlert(NULL, strerror(err), "OOK");
> >         alert->Go(NULL);
> > }
> >
> > The Method AddItem ends with error code related to the error message
> "Invalid argument"...
> >
> > I don't know what the problem is, so help would be nice :)
> >
> > regards,
> > Robert
>
> Robert,
> Try replacing in your custom class:
>
> BArchivable*
> CustomPictureButton::Instantiate(BMessage *msg) {
>
> with:
>
> CustomPictureButton*
> CustomPictureButton::Instantiate(BMessage *msg) {
>
>
> Also, if I remember correctly you need to define the className used by the
> validate_instantiation(BMessage *archive, const char *className) function
> when you archive the class.  One line needs to be added to your Archive
> function as so:
>
> status_t
> CustomPictureButton::Archive(BMessage *msg, bool deep) const {
>    status_t err;
>
>    err = BPictureButton::Archive(msg, deep);
>     msg->AddString("class", "CustomPictureButton");
>    return err;
> }
>
>
> Keep trying, I think you're almost there.
>
> -Brian
>
>
>
>

Other related posts: