static pascal OSStatus SimpleWindowEventHandlerProc( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData ) { #pragma unused ( inCallRef ) HICommand command; Point pt; SInt16 value; Rect r; WindowGroupRef windowGroup; WindowGroupAttributes windowGroupAttributes; UInt32 eventKind = GetEventKind( inEvent ); UInt32 eventClass = GetEventClass( inEvent ); WindowRef window = (WindowRef) inUserData; OSStatus err = eventNotHandledErr; WindowStorage *windowStorage = (WindowStorage*) GetWRefCon( window ); switch ( eventClass ) { case kEventClassWindow: if ( eventKind == kEventWindowClose ) // Dispose extra window storage here { if ( windowStorage->overlayWindow != NULL ) SendWindowCloseEvent( windowStorage->overlayWindow ); DisposePtr( (Ptr) windowStorage ); } else if ( eventKind == kEventWindowClickContentRgn ) { if ( GetControlValueByID( window, 'Butn', 0 ) == 1 ) // If the "Line Tool" button is depressed { LineTool( window ); SetControlValueByID( window, 'Butn', 0, 0 ); // Pop the button back up err = noErr; } } else if ( (eventKind == kEventWindowBoundsChanging) || (eventKind == kEventWindowBoundsChanged) ) { if ( windowStorage->overlayWindow != NULL ) // Resize the overlay window as well { (void) GetEventParameter( inEvent, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof(Rect), NULL, &r ); SizeWindow( windowStorage->overlayWindow, r.right-r.left, r.bottom-r.top, false ); } } break; case kEventClassCommand: if ( eventKind == kEventCommandProcess ) { GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &command ); if ( command.commandID == kHICommandOK ) // Change the window layering and attributes { value = GetControlValueByID( window, 'Rdio', 0 ); // Which group was chosen windowGroupAttributes = 0; // Now set the attributes for the parent group if ( GetControlValueByID( window, 'Chek', 0 ) == 1 ) windowGroupAttributes |= kWindowGroupAttrMoveTogether; ChangeWindowGroupAttributes( g.windowGroups[value-1], windowGroupAttributes, ~windowGroupAttributes ); windowGroupAttributes = kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrHideOnCollapse; err = CreateWindowGroup( windowGroupAttributes, &windowGroup ); // We can only call SetWindowGroupParent() on an empty group, so create a new one if ( err == noErr ) err = SetWindowGroupParent( windowGroup, g.windowGroups[value-1] ); // Set the new parent if ( (err == noErr) && (windowStorage->overlayWindow != NULL) ) err = SetWindowGroup( windowStorage->overlayWindow, windowGroup ); // FIRST add the overlay window so that it is on top of the "normal" window if ( err == noErr ) { ReleaseWindowGroup( GetWindowGroup(window) ); // Release the old group err = SetWindowGroup( window, windowGroup ); // Add the window to the new group } } else if ( command.commandID == 'GAtr' ) // Get the window attributes { windowGroup = GetWindowGroupParent( GetWindowGroup(window) ); GetWindowGroupAttributes( windowGroup, &windowGroupAttributes ); SetControlValueByID( window, 'Chek', 0, ((windowGroupAttributes & kWindowGroupAttrMoveTogether) != 0) ); if ( windowGroup == g.windowGroups[0] ) SetControlValueByID( window, 'Rdio', 0, 1 ); else if ( windowGroup == g.windowGroups[1] ) SetControlValueByID( window, 'Rdio', 0, 2 ); else SetControlValueByID( window, 'Rdio', 0, 3 ); } else if ( command.commandID == 'Poof' ) { SetPortWindowPort( window ); GetMouse( &pt ); LocalToGlobal( &pt ); pt.v -= 50; // Draw the Poof 50 pixels above the mouse PoofItGood( pt ); } else if ( command.commandID == 'Over' ) { if ( windowStorage->overlayWindow == NULL ) { CreateOverlayWindow( window ); } else { SendWindowCloseEvent( windowStorage->overlayWindow ); } } } break; } return( err ); }
void IconDes::FreehandTool(Point p, dword flags) { LineTool(p, flags); Current().base_image = CurrentImage(); startpoint = p; }