static OSStatus InstallWindowEventHandlers( WindowRef windowRef ) { static const EventTypeSpec inputEventSpec[] = { { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } }; static const EventTypeSpec windowEventSpec[] = { { kEventClassWindow, kEventWindowClosed }, { kEventClassWindow, kEventWindowBoundsChanged } }; static const EventTypeSpec viewEventSpec[] = { { kEventClassControl, kEventControlDraw } }; OSStatus err; DrawContextStruct *newContext; // allocate a new draw context newContext = calloc( 1, sizeof( DrawContextStruct ) ); require_action( newContext != NULL, InstallWindowEventHandlers_err, err = paramErr ); HIViewFindByID(HIViewGetRoot(windowRef), myHIViewID, &newContext->viewRef); newContext->windowRef = windowRef; // install a key event handler err = InstallWindowEventHandler( windowRef, NewEventHandlerUPP( HandleKeyEvent ), GetEventTypeCount( inputEventSpec ), inputEventSpec, (void *) newContext, NULL ); require_noerr( err, InstallWindowEventHandlersEvent_err ); // install a general window event handler err = InstallWindowEventHandler( windowRef, NewEventHandlerUPP( HandleWindowEvent ), GetEventTypeCount( windowEventSpec ), windowEventSpec, (void *) newContext, NULL ); require_noerr( err, InstallWindowEventHandlersEvent_err ); // install handler for the HI view err = HIViewInstallEventHandler( newContext->viewRef, NewEventHandlerUPP( HandleViewEvent ), GetEventTypeCount( viewEventSpec ), viewEventSpec, (void *) newContext, NULL); require_noerr( err, InstallWindowEventHandlersEvent_err ); // also, set the context as the window refcon SetWRefCon( windowRef, (SRefCon) newContext ); return noErr; InstallWindowEventHandlersEvent_err: // make sure that if we're bailing to get rid of the allocated buffer free( newContext ); InstallWindowEventHandlers_err: return err; }
FilterWidget::FilterWidget(QWidget *parent) : QWidget(parent) { View = 0; #ifdef Q_OS_MAC searchFieldText = CFStringCreateWithCString(0, (const char *) tr("Search").toAscii(), 0); HISearchFieldCreate(NULL, kHISearchFieldAttributesSearchIcon | kHISearchFieldAttributesCancel, NULL, searchFieldText, &searchField); create(reinterpret_cast<WId>(searchField)); EventTypeSpec mySFieldEvents[] = { { kEventClassSearchField, kEventSearchFieldCancelClicked }, { kEventClassTextField, kEventTextDidChange }, { kEventClassTextField, kEventTextAccepted } }; HIViewInstallEventHandler(searchField, FilterFieldEventHandler, GetEventTypeCount(mySFieldEvents), mySFieldEvents, (void *) this, NULL); #elif !defined(Q_WS_MAEMO_5) QHBoxLayout *layout = new QHBoxLayout(this); layout->setMargin(3); NameFilterEdit = new LineEditWithClearButton(this); setFocusProxy(NameFilterEdit); layout->addWidget(new QLabel(tr("Search") + ':', this)); layout->addWidget(NameFilterEdit); connect(NameFilterEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterTextChanged(const QString &))); #endif }
/***************************************************** * * Do_NewWindowFromAPI(outWindow) * * Purpose: called to create a new window using only API calls fron MacWindows.h, Controls.h, and HIView.h * * Notes: called by Do_NewWindow() * * Inputs: outWindow - if not NULL, the address where to return the WindowRef * - if not NULL, the callee will have to ShowWindow * * Returns: OSStatus - error code (0 == no error) */ static OSStatus Do_NewWindowFromAPI(WindowRef * outWindow) { WindowRef aWindowRef = NULL; CFStringRef theTitle = NULL; OSStatus status; // Create a window Rect bounds = {0, 0, 360, 480}; status = CreateNewWindow(kDocumentWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute | kWindowCompositingAttribute | kWindowMetalAttribute, &bounds, &aWindowRef); require_noerr(status, CreateNewWindow); require(aWindowRef != NULL, CreateNewWindow); status = RepositionWindow(aWindowRef, NULL, kWindowCascadeOnMainScreen); require_noerr(status, RepositionWindow); HIViewRef contentView; status = HIViewFindByID(HIViewGetRoot(aWindowRef), kHIViewWindowContentID, &contentView); require_noerr(status, HIViewFindByID); ControlRef aControlRef; Rect statBounds = {113, 20, 177, 460}; ControlFontStyleRec style = {kControlUseJustMask, 0, 0, 0, 0, teJustCenter}; status = CreateStaticTextControl(NULL, &statBounds, CFSTR("Click in the LittleArrows control above."), &style, &aControlRef); require_noerr(status, CreateStaticTextControl); HIViewID staticTextID = { 'STTC', 100 }; HIViewSetID(aControlRef, staticTextID); status = HIViewAddSubview(contentView, aControlRef); require_noerr(status, HIViewAddSubview); Rect littleArrowBounds = {51, 234, 73, 247}; status = CreateLittleArrowsControl(NULL, &littleArrowBounds, 0, 0, 10, 1, &aControlRef); require_noerr(status, CreateLittleArrowsControl); status = HIViewAddSubview(contentView, aControlRef); require_noerr(status, HIViewAddSubview); SetControlAction(aControlRef, LittleArrowsControlAction); EventTypeSpec eventTypeCVFC = {kEventClassControl, kEventControlValueFieldChanged}; status = HIViewInstallEventHandler(aControlRef, Handle_PostLittleArrowsClick, 1, &eventTypeCVFC, (void *)aControlRef, NULL); require_noerr(status, CantInstallEventHandler); Rect buttonBounds = {320, 390, 340, 460}; status = CreatePushButtonControl(NULL, &buttonBounds, CFSTR("OK"), &aControlRef); require_noerr(status, CreatePushButtonControl); status = SetControlCommandID(aControlRef, kHICommandOK); require_noerr(status, SetControlCommandID); status = HIViewAddSubview(contentView, aControlRef); require_noerr(status, HIViewAddSubview); status = SetWindowDefaultButton(aWindowRef, aControlRef); require_noerr(status, SetWindowDefaultButton); WindowDataPtr wdr = (WindowDataPtr)calloc(1, sizeof(WindowDataRec)); require(wdr != NULL, CantAllocateWindowData); SetWRefCon(aWindowRef, (long)wdr); theTitle = CFStringCreateWithFormat(NULL, NULL, CFSTR("LittleArrowsShowcase Window From API #%ld"), ++gWindowCount); require(theTitle != NULL, CFStringCreateWithFormat); status = SetWindowTitleWithCFString(aWindowRef, theTitle); require_noerr(status, SetWindowTitleWithCFString); EventTypeSpec eventTypeCP = {kEventClassCommand, kEventCommandProcess}; status = InstallWindowEventHandler(aWindowRef, Handle_WindowCommandProcess, 1, &eventTypeCP, (void *)aWindowRef, NULL); require_noerr(status, CantInstallEventHandler); EventTypeSpec eventTypeWC = {kEventClassWindow, kEventWindowClosed}; status = InstallWindowEventHandler(aWindowRef, Handle_WindowIsClosing, 1, &eventTypeWC, (void *)aWindowRef, NULL); require_noerr(status, CantInstallEventHandler); // The window was created hidden so show it if the outWindow parameter is NULL, // if it's not, it will be the responsibility of the caller to show it. if (outWindow == NULL) ShowWindow(aWindowRef); SetWindowModified(aWindowRef, false); CantInstallEventHandler: SetWindowTitleWithCFString: CFStringCreateWithFormat: if (theTitle != NULL) CFRelease(theTitle); CantAllocateWindowData: SetWindowDefaultButton: SetControlCommandID: CreatePushButtonControl: CreateLittleArrowsControl: HIViewAddSubview: CreateStaticTextControl: HIViewFindByID: RepositionWindow: CreateNewWindow: if (outWindow != NULL) *outWindow = aWindowRef; return status; } // Do_NewWindowFromAPI
/***************************************************** * * Do_NewWindowFromIB(outWindow) * * Purpose: called to create a new window that has been constructed with Interface Builder * * Notes: called by Do_NewWindow() * * Inputs: outWindow - if not NULL, the address where to return the WindowRef * - if not NULL, the callee will have to ShowWindow * * Returns: OSStatus - error code (0 == no error) */ static OSStatus Do_NewWindowFromIB(WindowRef * outWindow) { OSStatus status; WindowRef aWindowRef = NULL; CFStringRef theTitle = NULL; CFMutableStringRef theNewTitle = NULL; // Create a window. "MainWindow" is the name of the window object. This name is set in // InterfaceBuilder when the nib is created. status = CreateWindowFromNib(gIBNibRef, CFSTR("MainWindow"), &aWindowRef); require_noerr(status, CreateWindowFromNib); require(aWindowRef != NULL, CreateWindowFromNib); WindowDataPtr wdr = (WindowDataPtr)calloc(1, sizeof(WindowDataRec)); require(wdr != NULL, CantAllocateWindowData); SetWRefCon(aWindowRef, (long)wdr); status = CopyWindowTitleAsCFString(aWindowRef, &theTitle); require_noerr(status, CopyWindowTitleAsCFString); theNewTitle = CFStringCreateMutableCopy(NULL, 0, theTitle); require(theNewTitle != NULL, CFStringCreateMutableCopy); CFStringAppendFormat(theNewTitle, NULL, CFSTR(" %ld"), ++gWindowCount); status = SetWindowTitleWithCFString(aWindowRef, theNewTitle); require_noerr(status, SetWindowTitleWithCFString); EventTypeSpec eventTypeCP = {kEventClassCommand, kEventCommandProcess}; status = InstallWindowEventHandler(aWindowRef, Handle_WindowCommandProcess, 1, &eventTypeCP, (void *)aWindowRef, NULL); require_noerr(status, CantInstallEventHandler); EventTypeSpec eventTypeWC = {kEventClassWindow, kEventWindowClosed}; status = InstallWindowEventHandler(aWindowRef, Handle_WindowIsClosing, 1, &eventTypeWC, (void *)aWindowRef, NULL); require_noerr(status, CantInstallEventHandler); HIViewID littleArrowsId = { 'LARC', 100 }; HIViewRef littleArrows; status = HIViewFindByID(HIViewGetRoot(aWindowRef), littleArrowsId, &littleArrows); require_noerr(status, HIViewFindByID); require(littleArrows != NULL, HIViewFindByID); SetControlAction(littleArrows, LittleArrowsControlAction); EventTypeSpec eventTypeCVFC = {kEventClassControl, kEventControlValueFieldChanged}; status = HIViewInstallEventHandler(littleArrows, Handle_PostLittleArrowsClick, 1, &eventTypeCVFC, (void *)littleArrows, NULL); require_noerr(status, CantInstallEventHandler); // The window was created hidden so show it if the outWindow parameter is NULL, // if it's not, it will be the responsibility of the caller to show it. if (outWindow == NULL) ShowWindow(aWindowRef); SetWindowModified(aWindowRef, false); HIViewFindByID: CantInstallEventHandler: SetWindowTitleWithCFString: CFStringCreateMutableCopy: CopyWindowTitleAsCFString: if (theTitle != NULL) CFRelease(theTitle); if (theNewTitle != NULL) CFRelease(theNewTitle); CantAllocateWindowData: CreateWindowFromNib: if (outWindow != NULL) *outWindow = aWindowRef; return status; } // Do_NewWindowFromIB