static TkappObject * Tkapp_New(char *screenName, char *baseName, char *className, int interactive) { TkappObject *v; char *argv0; v = PyObject_New(TkappObject, &Tkapp_Type); if (v == NULL) return NULL; v->interp = Tcl_CreateInterp(); #if defined(macintosh) /* This seems to be needed */ ClearMenuBar(); TkMacInitMenus(v->interp); #endif /* Delete the 'exit' command, which can screw things up */ Tcl_DeleteCommand(v->interp, "exit"); if (screenName != NULL) Tcl_SetVar2(v->interp, "env", "DISPLAY", screenName, TCL_GLOBAL_ONLY); if (interactive) Tcl_SetVar(v->interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY); else Tcl_SetVar(v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); /* This is used to get the application class for Tk 4.1 and up */ argv0 = (char*)ckalloc(strlen(className) + 1); if (!argv0) { PyErr_NoMemory(); Py_DECREF(v); return NULL; } strcpy(argv0, className); if (isupper((int)(argv0[0]))) argv0[0] = tolower(argv0[0]); Tcl_SetVar(v->interp, "argv0", argv0, TCL_GLOBAL_ONLY); ckfree(argv0); if (Tcl_AppInit(v->interp) != TCL_OK) return (TkappObject *)Tkinter_Error((PyObject *)v); EnableEventHook(); return v; }
EXPORT(sqInt) primitiveClearMenuBar(void) { ClearMenuBar(); return null; }
static void winproc(void *a) { MenuItemIndex index; winRect.left = 30; winRect.top = 60; winRect.bottom = (devRect.size.height * 0.75) + winRect.top; winRect.right = (devRect.size.width * 0.75) + winRect.left; ClearMenuBar(); InitCursor(); CreateStandardWindowMenu(0, &windMenu); InsertMenu(windMenu, 0); CreateNewMenu(1004, 0, &viewMenu); SetMenuTitleWithCFString(viewMenu, CFSTR("View")); AppendMenuItemTextWithCFString(viewMenu, CFSTR("Toggle Full Screen"), 0, kFullScreenCmd, &index); SetMenuItemCommandKey(viewMenu, index, FALSE, 'F'); InsertMenu(viewMenu, GetMenuID(windMenu)); DrawMenuBar(); uint32_t windowAttrs = 0 | kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowResizableAttribute | kWindowStandardHandlerAttribute | kWindowFullZoomAttribute ; CreateNewWindow(kDocumentWindowClass, windowAttrs, &winRect, &theWindow); SetWindowTitleWithCFString(theWindow, CFSTR("Acme SAC")); if(PasteboardCreate(kPasteboardClipboard, &appleclip) != noErr) sysfatal("pasteboard create failed"); const EventTypeSpec app_events[] = { { kEventClassApplication, kEventAppQuit } }; const EventTypeSpec commands[] = { { kEventClassWindow, kEventWindowClosed }, { kEventClassWindow, kEventWindowBoundsChanged }, { kEventClassCommand, kEventCommandProcess } }; const EventTypeSpec events[] = { { kEventClassTextInput, kEventTextInputUpdateActiveInputArea }, { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, { kEventClassTextInput, kEventTextInputOffsetToPos }, { kEventClassTextInput, kEventTextInputPosToOffset }, { kEventClassTextInput, kEventTextInputShowHideBottomWindow }, { kEventClassTextInput, kEventTextInputGetSelectedText }, { kEventClassTextInput, kEventTextInputUnicodeText }, { kEventClassTextInput, kEventTextInputFilterText }, { kEventClassKeyboard, kEventRawKeyDown }, { kEventClassKeyboard, kEventRawKeyModifiersChanged }, { kEventClassKeyboard, kEventRawKeyRepeat }, { kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseUp }, { kEventClassMouse, kEventMouseMoved }, { kEventClassMouse, kEventMouseDragged }, { kEventClassMouse, kEventMouseWheelMoved }, }; InstallApplicationEventHandler ( NewEventHandlerUPP (ApplicationQuitEventHandler), GetEventTypeCount(app_events), app_events, NULL, NULL); InstallApplicationEventHandler ( NewEventHandlerUPP (MainWindowEventHandler), GetEventTypeCount(events), events, NULL, NULL); InstallWindowEventHandler ( theWindow, NewEventHandlerUPP (MainWindowCommandHandler), GetEventTypeCount(commands), commands, theWindow, NULL); ShowWindow(theWindow); ShowMenuBar(); window_resized(); Rectangle rect = { { 0, 0 }, { bounds.size.width, bounds.size.height } }; wmtrack(0, rect.max.x, rect.max.y, 0); SelectWindow(theWindow); // Run the event loop readybit = 1; Wakeup(&rend); RunApplicationEventLoop(); }