void MCStack::updatemodifiedmark(void) { if (!MCModeMakeLocalWindows()) return; if (window != NULL) SetWindowModified((WindowPtr)window -> handle . window, getextendedstate(ECS_MODIFIED_MARK)); }
bool AquaGui::run() { double interval = _interval / 1000.0; OSStatus ret = InstallEventLoopTimer (GetMainEventLoop(), 0, interval, DoAdvanceMovie, this, _advance_timer); if (ret != noErr) { return false; } RepositionWindow(myWindow, NULL, kWindowCascadeOnMainScreen); SelectWindow(myWindow); ShowWindow(myWindow); SetWindowModified(myWindow, false); RunApplicationEventLoop(); return true; }
/***************************************************** * * 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
/***************************************************** * * Do_NewWindow() * * Purpose: called to create a new window that has been constructed with Interface Builder * * Inputs: none * * Returns: OSStatus - error code (0 == no error) */ OSStatus Do_NewWindow(void) { OSStatus status; static IBNibRef gIBNibRef = NULL; WindowRef aWindowRef = NULL; CFStringRef theTitle = NULL; CFMutableStringRef theNewTitle = NULL; if (gIBNibRef == NULL) { // Create a Nib reference passing the name of the nib file (without the .nib extension) // CreateNibReference only searches into the application bundle. status = CreateNibReference(CFSTR("main"), &gIBNibRef); require_noerr(status, CantGetNibRef); } require(gIBNibRef != NULL, CantGetNibRef); // 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, CantCreateWindow); require(NULL != aWindowRef, CantCreateWindow); // Grab the title of the window and add the window count to it status = CopyWindowTitleAsCFString(aWindowRef, &theTitle); require_noerr(status, CantGetSetTitle); theNewTitle = CFStringCreateMutableCopy(NULL, 0, theTitle); require(NULL != theNewTitle, CantGetSetTitle); CFStringAppendFormat(theNewTitle, NULL, CFSTR(" %ld"), ++gWindowCount); status = SetWindowTitleWithCFString(aWindowRef, theNewTitle); require_noerr(status, CantGetSetTitle); // Create the custom view to be tested and embed it in our group box control HIViewRef groupBox; status = HIViewFindByID(HIViewGetRoot(aWindowRef), kGroupBoxID, &groupBox); require_noerr(status, CantFindGroupBox); require(groupBox != NULL, CantFindGroupBox); HIViewRef customView; status = HICreateCustomView(NULL, &customView); require_noerr(status, CantCreateCustom); require(customView != NULL, CantCreateCustom); HIRect groupBoxBounds; HIViewGetBounds(groupBox, &groupBoxBounds); groupBoxBounds.origin.x += 20; groupBoxBounds.origin.y += 34; groupBoxBounds.size.width -= 40; groupBoxBounds.size.height -= 54; HIViewSetFrame(customView, &groupBoxBounds); HIViewSetLayoutInfo(customView, &kBindToParentLayout); status = HIViewAddSubview(groupBox, customView); require_noerr(status, CantAddSubview); HIViewSetVisible(customView, true); // Let's react to User's commands. EventTypeSpec eventTypeCP = {kEventClassCommand, kEventCommandProcess}; status = InstallWindowEventHandler(aWindowRef, Handle_WindowCommandProcess, 1, &eventTypeCP, (void *)customView, NULL); require_noerr(status, CantInstallEventHandler); // Let's update our static text field whenever the value or hilite of our tested custom view changes EventTypeSpec eventTypeCVFC[] = { {kEventClassControl, kEventControlValueFieldChanged}, {kEventClassControl, kEventControlHiliteChanged} }; status = InstallControlEventHandler(customView, Handle_ControlValueFieldOrHiliteChanged, 2, eventTypeCVFC, (void *)customView, NULL); require_noerr(status, CantInstallEventHandler); // We accept only numbers in our Edit text control HIViewRef editText; HIViewFindByID(HIViewGetRoot(GetControlOwner(customView)), kSetValueEditID, &editText); #ifdef MAC_OS_X_VERSION_10_4 // in Tiger, only 1 event handler is necessary for the key filtering EventTypeSpec eventTypeTSCIR = {kEventClassTextField, kEventTextShouldChangeInRange}; status = InstallControlEventHandler(editText, Handle_TextShouldChangeInRange, 1, &eventTypeTSCIR, (void *)editText, NULL); require_noerr(status, CantInstallEventHandler); #else // pre-Tiger, we need a different event handler and a validation proc to handle pastes and drops. ControlEditTextValidationUPP textValidation = MyValidationProc; SetControlData(editText, kControlEntireControl, kControlEditTextValidationProcTag, sizeof(textValidation), &textValidation); EventTypeSpec eventTypeTIUFKE = {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent}; status = InstallControlEventHandler(editText, Handle_TextInputEvent, 1, &eventTypeTIUFKE, (void *)editText, NULL); require_noerr(status, CantInstallEventHandler); #endif // Finishing the custom view setup SetControl32BitMinimum(customView, 0); SetControl32BitMaximum(customView, 36); SetControl32BitValue(customView, 2); // We want window and thus our custom view to be able to respond to drops status = SetAutomaticControlDragTrackingEnabledForWindow(aWindowRef, true); require_noerr(status, SetAutomaticControlDragTrackingEnabledForWindow); ShowWindow(aWindowRef); SetWindowModified(aWindowRef, false); SetAutomaticControlDragTrackingEnabledForWindow: SetControlDragTrackingEnabled: CantAddSubview: CantCreateCustom: CantFindGroupBox: CantInstallEventHandler: CantGetSetTitle: CantAllocateWindowData: CantCreateWindow: CantGetNibRef: if (theTitle != NULL) CFRelease(theTitle); if (theNewTitle != NULL) CFRelease(theNewTitle); return status; } // Do_NewWindow