13 Replies Latest reply: May 6, 2010 5:36 AM by dheeraj_c RSS

    How to get resize callbacks for a dockable plugin window?

    dheeraj_c Community Member

      Hi All,

                I'm going through Panelator plugin. It comes as a separate window. I want some callback when the window is getting resized or moved. What kind of event I need to register for gtting the callback. Any suggestions will help me a lot.

       

      I tried using foillowing method, but I'm not getting the callback. I thought kEventClassWindow is related to window events.

       

      static const EventTypeSpec  kDrawEventSpec[] = {kEventClassControl,  kEventControlDraw, kEventClassWindow };
         
      OSErr    err = InstallEventHandler (GetControlEventTarget (i_refH),
                                              NewEventHandlerUPP (S_EventHandler),
                                              1,
                                              kDrawEventSpec,
                                              (void *) this,
                                              NULL);

       

      Thanks,

      Dheeraj.

        • 1. Re: How to get resize callbacks for a dockable plugin window?
          dheeraj_c Community Member

          I tried this too :

           

          static const EventTypeSpec  kDrawEventSpec[] = { {kEventClassControl, kEventControlDraw},
                                                                                            {kEventClassWindow, kEventWindowResizeStarted}};

          OSErr    err = InstallEventHandler (GetControlEventTarget (i_refH), // 6
                                                  NewEventHandlerUPP (S_EventHandler),
                                                  2,
                                                  kDrawEventSpec,
                                                  (void *) this,
                                                  NULL);

           

          Thanks,

          Dheeraj.

          • 2. Re: How to get resize callbacks for a dockable plugin window?
            shachar carmi Community Member

            this is how i define the events:

             

            static const EventTypeSpec  kControlEventSpec[] = {

            {kEventClassCommand, kEventProcessCommand},

            {kEventClassControl, kEventControlDraw},

            {kEventClassControl, kEventControlOwningWindowChanged},

            {kEventClassControl, kEventControlBoundsChanged}// <------ this is what i use for resizing

            };

             

             

            err = InstallEventHandler ( GetControlEventTarget(i_refH),

            NewEventHandlerUPP(S_EventHandler),

            GetEventTypeCount(kControlEventSpec),

            kControlEventSpec,

            (void*)this,

            NULL);

             

            • 3. Re: How to get resize callbacks for a dockable plugin window?
              dheeraj_c Community Member

              Thanks for the suggestion shachar.

               

              I get the callback when the control owning window is changed but the problem is that the custom component inside the Panelator window is not visible, it just vanishes.

               

              I tries this peice of code, but it didn't work :

               

                      HIRect      origClientArea;
                      HIViewGetBounds (i_refH, &origClientArea);
                     
                      WindowRef hostWindow;
                     
                      hostWindow = (WindowRef) HIViewGetWindow(i_refH);
                     
                      Rect r;
                      GetWindowBounds (hostWindow, kWindowContentRgn, &r);
                     
                     
                      if (firstResize)
                      {
                          diffW = (r.right - r.left) - _pJuceComponent->getWidth();
                          diffH = (r.bottom - r.top) - _pJuceComponent->getHeight();
                          firstResize = false;
                      }
                     
                      r.right = r.left + origClientArea.size.width + diffW;
                      r.bottom = r.top + origClientArea.size.height + diffH;
                     
                      SetWindowBounds (hostWindow, kWindowContentRgn, &r);
                     
                      r.bottom -= r.top;
                      r.right -= r.left;
                      r.left = r.top = 0;
                      InvalWindowRect (hostWindow, &r);

               

               

              Is it because the Panelator window's owner has changed? Do I need to place my custom component inside again?

               

              Instead of adding custom component to window, Is there a way to add the custom component to the Panelator tab itself?

              Because the component gets added to AE main window itself if the Panelator window is docked.

              • 4. Re: How to get resize callbacks for a dockable plugin window?
                shachar carmi Community Member

                i don't know about reinstalling reinstallin components after docking / undocking.

                however i see in my code that after docking / undocking i uninstall the event handlers, and reinstall them on the new owning window.

                i think the content of your window vanishes because you don't get any more drawing calls, as the old event handler no longer applies.

                • 5. Re: How to get resize callbacks for a dockable plugin window?
                  dheeraj_c Community Member

                  Thanks Shachar. You have been very helpful.

                   

                  Instead of adding custom component to window, Is there a way to add the  custom component to the Panelator tab itself?

                  • 6. Re: How to get resize callbacks for a dockable plugin window?
                    shachar carmi Community Member

                    well...

                    AE creates the window in which the tab resides, and hands you an empty control to draw your content into.

                    you could get the parent for that control and add controls directly to that window, but that would mean your putting stuff outside your designated space.

                    if that's what you need, go ahead. but most likely you'd want you stuff in the control you were handed and not anywhere else graphically.

                    if you want your palette to look like an AE palette, then you shouldn't add to the window.

                    • 7. Re: How to get resize callbacks for a dockable plugin window?
                      dheeraj_c Community Member

                      Hi Shachar,

                                          I'm facing a problem here :

                       

                      I add the custom component to the Panelator window. If the window is independent then I get Panelator window handle. So I add to Panelator window.

                       

                      Now if the Panelator window is inside the AE window, then what I get is the AE window handle itself. So the custom component gets added to the AE window not Panelator window. I want the component to sit inside the Panelator tab.

                       

                      How do I add the custom component to Panelator tab irrespective of where it resides?

                       

                      Hope the problem is clear.

                       

                      Thanks,

                      Dheeraj.

                      • 8. Re: How to get resize callbacks for a dockable plugin window?
                        shachar carmi Community Member

                        this is from the original code of the panelator:

                         

                        ControlRef newControl;

                        err = CreatePushButtonControl (NULL,  &buttonRect,   CFSTR("Click Me!"),  &newControl);

                        err = HIViewAddSubview(i_refH, newControl);

                        you add the new control as a subview of your control, and not directly to the window.

                        • 9. Re: How to get resize callbacks for a dockable plugin window?
                          dheeraj_c Community Member

                          Thanks Shachar. I have a WindowRef handle, how do I convert it to ControlRef handle to call

                          err = HIViewAddSubview(i_refH, newControl); ?

                           

                          Should I use this function :

                          ControlRef GetNewControl(
                            SInt16      resourceID,
                            WindowRef   owningWindow);

                           

                          In that case what is resourceID?

                           

                          Thanks,

                          Dheeraj.

                          • 10. Re: How to get resize callbacks for a dockable plugin window?
                            shachar carmi Community Member

                            nope.

                            you should just use CreatePushButtonControl as it appears in the panelator sample.

                            jump to the definition of CreatePushButtonControl and you'll see all the rest of the control types.

                             

                            if you do it like in the sample, then these controls will belong to the one control AE hands you.

                            • 11. Re: How to get resize callbacks for a dockable plugin window?
                              dheeraj_c Community Member

                              Thanks Shachar.

                               

                              Correct me if I'm wrong :

                               

                               

                              CreatePushButtonControl function will create a button of specified type & returns the ControlRef to that button.

                               

                              But my requirement is a external custom component. How do I get the ControlRef to my component?

                              Is there any method for passing custom component to a function which returns me the ControlRef?

                              • 12. Re: How to get resize callbacks for a dockable plugin window?
                                shachar carmi Community Member

                                don't you get a ControlRef when you create that external custom component?

                                these are all standard quartz calls.

                                if you know how to place that component in a normal os window, you should use the same method to place as a subView of the panel control.

                                • 13. Re: How to get resize callbacks for a dockable plugin window?
                                  dheeraj_c Community Member

                                  Thanks a lot shachar. I got the clue. You are great.