Skip navigation
Currently Being Moderated

Create ButtonWidget observer for panel

Jan 2, 2012 1:29 AM

Tags: #button #indesign_cs5 #panel #observer

Hi all,

Iam trying to create panel with some buttons and some text input (TextEditBoxWidget). I would like to know how to crate one observer fot both items or at least for button. All buttons that Iam using are ButtonWidget. I have created

IAPButtonActionObserver.cpp which inherits from CObserver, it has AutoAttach, AutoDetach, Upadate, constructor, destructor... than I have here implementation of all methods, and  CREATE_PMINTERFACE(IAPButtonActionObserver, kIAPButtonActionObserverImpl). In my IAPID.h file I have following(except generated code from dollys):

DECLARE_PMID(kClassIDSpace, kIAPButtonActionObserverBoss, kIAPPrefix + 3)

DECLARE_PMID(kImplementationIDSpace, kIAPButtonActionObserverImpl, kIAPPrefix + 6)

// WidgetIDs:

DECLARE_PMID(kWidgetIDSpace, kIAPPanelWidgetID, kIAPPrefix + 0)

DECLARE_PMID(kWidgetIDSpace, kImageButtonWidgetID, kIAPPrefix + 2)

DECLARE_PMID(kWidgetIDSpace, kLinkButtonWidgetID, kIAPPrefix + 3)

DECLARE_PMID(kWidgetIDSpace, kSlideShowButtonWidgetID, kIAPPrefix + 4)

DECLARE_PMID(kWidgetIDSpace, kVideoButtonWidgetID, kIAPPrefix + 5)

 

In resource IAP.fr file :

Class

          {

                    kIAPButtonActionObserverBoss,

                    kButtonWidgetBoss,

                    {

                              /**

                              Handles button press (and release), see IAPButtonActionObserver...

                              */

                              IID_IOBSERVER, kIAPButtonActionObserverImpl,

                    }

          },

and definition of buttons. I know that I should attach use AttachToWidget in observer, but in this observer doesnt inherits from dialog observer, so it hasnt any method like this. So my question is how to connect my observer to button defined on panel??


Thanks a lot



 
Replies
  • Currently Being Moderated
    Jan 2, 2012 2:22 AM   in reply to Ondrej Vyhlidal

    What you need to do for this is to first create a boss for your panel, inside this panel you add your observer. Thus when your panel will load all the classes inside that boss gets instantiated i.e. your observer implementation also gets called and inside the observer's autoattach method attach the observer to your buttons and textfield.

     

    Manan Joshi

     

    - Efficient InDesign Solutions -

    MetaDesign Solutions

    http://metadesignsolutions.com/services/indesign-development.php

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 2, 2012 5:21 AM   in reply to Ondrej Vyhlidal

    Your panel boss should derive from an existing pallete boss, that way you will have the basic functionality of the panel. Within this class description you will place the "id, implementation" pair of your observer.

     

    Manan Joshi

     

    - Efficient InDesign Solutions -

    MetaDesign Solutions

    http://metadesignsolutions.com/services/indesign-development.php

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 2, 2012 6:39 AM   in reply to Ondrej Vyhlidal

    You could use something like this

     

              Class

              {

                        kYourPanelPanelBoss,

                        kPalettePanelWidgetBoss,

                        {

                                  /** An implementation of ITextControlData, but with interface

                                  identifier of IID_IPANELMENUDATA, serves to name the popout panel menu.

                                  Implementation provided by the API.*/

                                  IID_IPANELMENUDATA,                              kCPanelMenuDataImpl,

      

                                  IID_IOBSERVER,                                        kYourPanelObserverImpl,

                        }

              },

     

    Then create a type based on this boss class, and then add your buttons and textbox to this new type.

     

    Manan Joshi

     

    - Efficient InDesign Solutions -

    MetaDesign Solutions

    http://metadesignsolutions.com/services/indesign-development.php

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 3, 2012 2:23 AM   in reply to Ondrej Vyhlidal

    That list looks good, i hope by 3 point you have done something as i have postulated in the previous post in this thread.

     

    When all is done you can check whether you are getting the call in your observer's autoattach on not when you load your panel. if you get the call then you are on the right path. The next thing that remains then is to just attach the observer to the buttons and the textfield on the panel.

     

     

    Manan Joshi

     

    - Efficient InDesign Solutions -

    MetaDesign Solutions

    http://metadesignsolutions.com/services/indesign-development.php

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 3, 2012 6:16 AM   in reply to Ondrej Vyhlidal

    On the first look the approach looks good, but one thing that i observed wrong in this code is that you must inherit your observer from CObserver not the IObserver interface. As if you use IObserver you won't have the basic functionality that every interface does have in Indesign like the Queryinterface method.

    In addition to this change your Observer constructor will also change and call the base class constructor with proper argument, refer the SDK it has lot of examples of it.

     

    Once you get the code compiled then lets me know if you manage to get your observer called or not.

     

    Manan Joshi

     

    - Efficient InDesign Solutions -

    MetaDesign Solutions

    http://metadesignsolutions.com/services/indesign-development.php

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 3, 2012 11:57 PM   in reply to Ondrej Vyhlidal

    As you have not added the observer to monitor anything there won't be any call made to the update and nothing will happen, only the observer constructor is called and that is the behaviour that you are observing.

     

    What you need to make sure first is that are you getting the call on the AutoAttach or not? Because this method must be called to attach the observer to the subjects. So what you have written must surely be in the AutoAttach method, but things will work only when this method gets called,

     

    Manan Joshi

     

    - Efficient InDesign Solutions -

    MetaDesign Solutions

    http://metadesignsolutions.com/services/indesign-development.php

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 5, 2012 1:42 AM   in reply to Ondrej Vyhlidal

    On noticing your code i figured one problem in it, replace your implemetationID form "IID_BUTTONACTIONOBSERVER" to "IID_IOBSERVER", because you get call on observers only if the implementationID is "IID_IOBSERVER" for other ID's you need to explicitly call your observer's AutoAttach method.

     

    Try this and let me know if you get any ahead. I hope this should solve your problem.

     

    Manan Joshi

     

    - Efficient InDesign Solutions -

    MetaDesign Solutions

    http://metadesignsolutions.com/services/indesign-development.php

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 5, 2012 2:53 AM   in reply to Ondrej Vyhlidal

    Looking at code does not show any error as such, it would take less time if you could share the project with all the files, so that i can debug the project when i have time.

     

    Manan Joshi

     

    - Efficient InDesign Solutions -

    MetaDesign Solutions

    http://metadesignsolutions.com/services/indesign-development.php

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 5, 2012 3:00 AM   in reply to Ondrej Vyhlidal

    that will do i suppose.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 5, 2012 3:11 AM   in reply to Ondrej Vyhlidal

    Hi Ondrej

     

     

     

    I just created new plugin in DollyXs and everything works fine. In Your code there's few bugs related to attaching observer to Panel and creating button widget based on Panel Wiget

    (type ButtonActionWidget(kViewRsrcType) : PalettePanelWidget(ClassID = kButtonActionObserverBoss))

     

    I think the easiest way will be if you do exatcly the same. It's only few steps that you need to reproduce.

    So. What i have done to create button.

     

    1. Created new plugin in DollyXs with panel

     

    2. In YourPluginID.h added

         a) DECLARE_PMID(kClassIDSpace, kEPBtnWidgetBoss, kEreaderPluginPrefix + 100 )

             in ClassID: section

         b) DECLARE_PMID(kImplementationIDSpace, kEPBtnObsImpl, kEreaderPluginPrefix + 100 )

             in ImplementationIDs: section

         c) DECLARE_PMID(kWidgetIDSpace, kEPBtnWidgetId, kEreaderPluginPrefix + 100)

              in WidgetIDs: section

     

    3. In YourPlugin.fr file.

         a)

              Class { kEPBtnWidgetBoss, kButtonWidgetBoss,

                        {          IID_IOBSERVER,                                                            kEPBtnObsImpl,                                        }}

        

         in class definitions

     

         b)

              type EPBtnWidget(kViewRsrcType)                              : ButtonWidget                                        (ClassID = kEPBtnWidgetBoss)                    {};

     

         in Type definitions

     

         c)

             

                                  EPBtnWidget

                            (    

                                            kEPBtnWidgetId, kSysButtonPMRsrcId, kBindNone,

                                            105, 10, 202, 27, kTrue, kTrue, "Your Text",                              ),

     

          in PanelView definition ("Your Text", should be localized)

     

    4. In YourPluginFactoryList.h

         REGISTER_PMINTERFACE(CEPBtnObs,                                        kEPBtnObsImpl)

     

    5. Created a class for your observer

     

    #include <CObserver.h>

    #include <ISubject.h>

    #include <IBooleanControlData.h>

    #include "EreaderPluginID.h"

     

    #include "ISubject.h"

    class CEPBtnObs : public CObserver {

    public:

              CEPBtnObs(IPMUnknown *boss);

     

              ~CEPBtnObs();

              virtual void Update(const ClassID& theChange, ISubject* theSubject, const PMIID &protocol, void* changedBy);

              virtual void AutoAttach();

              virtual void AutoDetach();

    };

     

    CREATE_PMINTERFACE(CEPBtnObs, kEPBtnObsImpl)

     

    CEPBtnObs::CEPBtnObs(IPMUnknown* boss):CObserver(boss)

    {

     

    }

     

    CEPBtnObs::~CEPBtnObs()

    {

     

    }

     

    void CEPBtnObs::AutoAttach()

    {

      InterfacePtr<ISubject> theSubject(this, UseDefaultIID());

              if(theSubject != nil)

                        theSubject->AttachObserver(this, IID_IBOOLEANCONTROLDATA);

     

    }

     

     

    void CEPBtnObs::AutoDetach()

    {

      InterfacePtr<ISubject> theSubject(this, UseDefaultIID());

              if(theSubject != nil)

                        theSubject->DetachObserver(this, IID_IBOOLEANCONTROLDATA);

     

    }

     

    void CEPBtnObs::Update(const ClassID& theChange, ISubject* theSubject, const PMIID &protocol, void* changedBy)

    {

              do

              {

                        if(theChange != kTrueStateMessage)

      break;

     

      printf("\n Update");

     

              } while(kFalse);

    }

     

     

    If follow those steps then you'll be able to create observer in less than 5 minutes.

     

    Regards

    Bartek

     


     
    |
    Mark as:
  • Currently Being Moderated
    Jan 5, 2012 3:20 AM   in reply to Bartek Kropaczewski

    Hello Cropas,

     

    That is a good summary of steps given by you, but using this approach we will only be able to create an observer for the button and not the text field i suppose.

    If we place an observer in the panel it can be used for every widget on the panel. So i suppose the previous path that was proposed is altogehter a different route than just creating an observer for button widget.

     

    Manan Joshi

     

    - Efficient InDesign Solutions -

    MetaDesign Solutions

    http://metadesignsolutions.com/services/indesign-development.php

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points