pascal OSStatus my_cmd_handler( EventHandlerCallRef handlerRef, EventRef event, void *userdata) { OSStatus osresult; HICommand command; word32 command_id; osresult = eventNotHandledErr; GetEventParameter(event, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &command); command_id = (word32)command.commandID; switch(command_id) { case 'Kbep': SysBeep(10); osresult = noErr; break; case 'abou': show_simple_alert("KEGSMAC v", (char *)g_kegs_version_str, ", Copyright 2004 Kent Dickey\n" "Latest version at http://kegs.sourceforge.net/\n", 0); osresult = noErr; break; case 'KCFG': #ifdef ACTIVEGS #else cfg_toggle_config_panel(); #endif osresult = noErr; break; case 'quit': break; case 'swin': /* not sure what this is, but Panther sends it */ break; default: printf("commandID %08x unknown\n", command_id); SysBeep(90); break; } return osresult; }
int #ifdef ACTIVEGS macmain #else main #endif (int argc, char* argv[]) { ProcessSerialNumber my_psn; IBNibRef nibRef; EventHandlerUPP handlerUPP; EventTypeSpec cmd_event[3]; GDHandle g_gdhandle; Rect win_rect; OSStatus err; char *argptr; int slash_cnt; int i; #ifndef ACTIVEGS /* Prepare argv0 */ slash_cnt = 0; argptr = argv[0]; for(i = strlen(argptr); i >= 0; i--) { if(argptr[i] == '/') { slash_cnt++; if(slash_cnt == 3) { strncpy(&(g_argv0_path[0]), argptr, i); g_argv0_path[i] = 0; } } } printf("g_argv0_path is %s\n", g_argv0_path); g_mac_argv[0] = argv[0]; g_mac_argc = 1; i = 1; while((i < argc) && (g_mac_argc < MAX_MAC_ARGS)) { if(!strncmp(argv[i], "-psn", 4)) { /* skip this argument */ } else { g_mac_argv[g_mac_argc++] = argv[i]; } i++; } #endif InitCursor(); g_event_rgnhandle = NewRgn(); g_status_font_family = FMGetFontFamilyFromName("\pCourier"); SetRect(&win_rect, 0, 0, X_A2_WINDOW_WIDTH, X_A2_WINDOW_HEIGHT // OG Remove status line from ActiveGS window #ifndef ACTIVEGS + MAX_STATUS_LINES*16 + 8 #endif ); OffsetRect(&win_rect, 64, 50); // Create a Nib reference passing the name of the nib file // CreateNibReference only searches into the application bundle. err = CreateNibReference(CFSTR("main"), &nibRef); require_noerr( err, CantGetNibRef ); // Once the nib reference is created, set the menu bar. err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar")); require_noerr( err, CantSetMenuBar ); #ifndef ACTIVEGS err = CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute, &win_rect, &g_main_window); err = SetWindowTitleWithCFString(g_main_window, CFSTR("GSport")); #else err = CreateNewWindow(kDocumentWindowClass, (kWindowCloseBoxAttribute /*| kWindowFullZoomAttribute */| kWindowCollapseBoxAttribute /*| kWindowResizableAttribute*/) /*kWindowStandardDocumentAttributes*/ | kWindowStandardHandlerAttribute, &win_rect, &g_main_window); extern CFStringRef activeGSversionSTR; err = SetWindowTitleWithCFString(g_main_window, activeGSversionSTR); #endif //printf("CreateNewWindow ret: %d, g_main_window: %p\n", (int)err, g_main_window); // We don't need the nib reference anymore. DisposeNibReference(nibRef); SysBeep(120); handlerUPP = NewEventHandlerUPP( my_cmd_handler ); cmd_event[0].eventClass = kEventClassCommand; cmd_event[0].eventKind = kEventProcessCommand; InstallWindowEventHandler(g_main_window, handlerUPP, 1, &cmd_event[0], (void *)g_main_window, NULL); handlerUPP = NewEventHandlerUPP(my_win_handler); cmd_event[0].eventClass = kEventClassWindow; cmd_event[0].eventKind = kEventWindowDrawContent; cmd_event[1].eventClass = kEventClassWindow; cmd_event[1].eventKind = kEventWindowUpdate; cmd_event[2].eventClass = kEventClassWindow; cmd_event[2].eventKind = kEventWindowClose; err = InstallWindowEventHandler(g_main_window, handlerUPP, 3, &cmd_event[0], (void *)g_main_window, NULL); require_noerr(err, CantCreateWindow); // Get screen depth g_gdhandle = GetGDevice(); g_screen_mdepth = (**((**g_gdhandle).gdPMap)).pixelSize; g_screen_depth = g_screen_mdepth; if(g_screen_depth > 16) { /* 32-bit display */ g_red_mask = 0xff; g_green_mask = 0xff; g_blue_mask = 0xff; /* if (macUsingCoreGraphics) { g_red_left_shift = 0; g_green_left_shift = 8; g_blue_left_shift = 16; } else */ { g_red_left_shift = 16; g_green_left_shift = 8; g_blue_left_shift = 0; } g_red_right_shift = 0; g_green_right_shift = 0; g_blue_right_shift = 0; } else if(g_screen_depth > 8) { /* 16-bit display */ g_red_mask = 0x1f; g_green_mask = 0x1f; g_blue_mask = 0x1f; g_red_left_shift = 10; g_green_left_shift = 5; g_blue_left_shift = 0; g_red_right_shift = 3; g_green_right_shift = 3; g_blue_right_shift = 3; } // show_alert("About to show window", (int)g_main_window); update_main_window_size(); update_window(); // The window was created hidden so show it. ShowWindow( g_main_window ); BringToFront( g_main_window ); update_window(); // Make us pop to the front a different way err = GetCurrentProcess(&my_psn); if(err == noErr) { (void)SetFrontProcess(&my_psn); } // Call the event loop temp_run_application_event_loop(); CantCreateWindow: CantSetMenuBar: CantGetNibRef: show_simple_alert("ending", "", "error code", err); return err; }