Using the Control Manager with SC

External developers... This forum's for you!

Using the Control Manager with SC

Postby sctell » Fri Sep 02, 2011 9:40 am

Is it possible to add your own controls to a SC window.

I was thinking about a Data Browser.

I have tried a simple experiment of a push button.

It does not display when I use

CreatePushButtonControl (tWindow,&tRect,CFSTR("Test Button"),&outControl);

The button is on the screen as there is a brief flash when it is visible but it seems the SC window is overlaid with something that hides my button.

What is that and is it possible for me to put my control on top of it?

All the best

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: Using the Control Manager with SC

Postby Dave_Higgins » Fri Sep 02, 2011 9:49 am

Seeing all the trouble you had getting views to work, it doesn't surprise me. My guess is that you would need to do another small view just large enough to fit the button in order to get it to float above SC's layers, but that could very well end up looking pretty funky (unless you can make the view invisible with the button visible, or use a square button (yuk)).

Good luck.
My two favorite teams are Detroit and whoever's playing Chicago.
User avatar
Dave_Higgins
 
Posts: 454
Joined: Mon Jul 07, 2008 9:50 am
Location: Dark Side Of The Moon

Re: Using the Control Manager with SC

Postby sctell » Fri Sep 02, 2011 11:33 am

Well Dave,

Nice to hear from you.

I get the windowRef for say wd id 100

Code: Select all
status = GetWindowPtr ([pBlock paramPtr],SCWindDescriptor,&tWindow);


Register this window for events using

Code: Select all
void RegisterForEvent (WindowRef window)
{
   EventTypeSpec    eventTypes[2];
   EventHandlerUPP  handlerUPP;
   
   eventTypes[0].eventClass = kEventClassMouse;
   eventTypes[0].eventKind  = kEventMouseDown;
   
   eventTypes[1].eventClass = kEventClassWindow;
   eventTypes[1].eventKind  = kEventWindowUpdate;
   
   handlerUPP = NewEventHandlerUPP(DoWindowEvents);
   
   InstallWindowEventHandler (window,handlerUPP,2, eventTypes,NULL,NULL);
}



I have a button created with then show it.

Code: Select all
CreatePushButtonControl (scWindow,&tRect,CFSTR("Test Button"),&myButton);
ShowControl(myButton);


Then I monitor the events with

Code: Select all
pascal OSStatus DoWindowEvents (EventHandlerCallRef nextHandler,EventRef theEvent,void* userData)
{
   OSStatus result;
   
   switch (GetEventClass(theEvent))
   {
      case kEventClassMouse:
      {
         doMouse(theEvent);
         break;
      }
         
      case kEventClassWindow:
      {
         doWindow(theEvent);
         break;
      }
   }
   return eventNotHandledErr;
//   result = CallNextEventHandler (nextHandler, theEvent);
//   return result;
}


void doMouse(EventRef theEvent)
{
   EventRecord tEventRec;
   EventRecord* eventStrucPtr;
   ControlRef     controlRef;
   SInt16         controlValue, controlPartCode;
   
   ConvertEventRefToEventRecord (theEvent,&tEventRec);
   eventStrucPtr = &tEventRec;
   GlobalToLocal(&eventStrucPtr->where);

   
   switch (GetEventKind( theEvent ))
   {
      case kEventMouseDown:
      {
            if(TrackControl(myButton,eventStrucPtr->where,NULL))
            {
               NSBeep();
            }
         break;
      }
   }
}

void doWindow(EventRef theEvent)
{
   switch (GetEventKind( theEvent ))
   {
      case kEventWindowUpdate:
      {
         ShowControl(myButton);
         break;
      }
   }
}


And...

Surprise, surprise as with everything other than basic externals it nearly works.

It's probably my fault not understanding carbon (SC) events to well but the button does show on the screen, it does depress and it does beep however...

The mouseDowns in SC native controls are affecting their display.

Perhaps someone could point me in the right direction or tell me to forget it?

All the best

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am

Re: Using the Control Manager with SC

Postby sctell » Fri Sep 02, 2011 10:54 pm

Hi,

I seemed to have fixed the issue by changing the above mouseDown code to:

Code: Select all
   switch (GetEventKind( theEvent ))
   {
      case kEventMouseDown:
      {
          if((controlPartCode = FindControl(eventStrucPtr->where,scWindow,&controlRef)))
          {
             if(controlRef == myButton)
             {
                if(TrackControl(myButton,eventStrucPtr->where,NULL))
                {
                   NSBeep();
                }
             }
          }
         break;
      }
   }


I'm sure this code is not efficient and could be done in a better way but it's a start.

So now we have a button created by the external within a SC window that beeps and seems to behave properly.

Obviously SC has no knowledge of this button as it belongs to the external.

So, what else can we have. Possibly any control that does not need a compositing window.

The big advantage is that we do not rely on overlay windows, these controls are part of the SC window but only accessible via. the external.

Data Browser certainly comes to mind as I have read this does not need a compositing window.

All the best

Terry
sctell
 
Posts: 1128
Joined: Sun Jul 06, 2008 10:41 am


Return to Xcode and the Internals Toolbox

Who is online

Users browsing this forum: No registered users and 1 guest

cron