summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXCarbonEvents.c
diff options
context:
space:
mode:
authordas <das>2005-08-09 07:39:48 (GMT)
committerdas <das>2005-08-09 07:39:48 (GMT)
commitb8c4ee9a5df85da2ac51dfea85177ffa458c2a50 (patch)
treeb77a27b7d580d802ccbfcb5442bba1206c3ff248 /macosx/tkMacOSXCarbonEvents.c
parentce8d7d22d0f5eb10e00df422dffb587c95481678 (diff)
downloadtk-b8c4ee9a5df85da2ac51dfea85177ffa458c2a50.zip
tk-b8c4ee9a5df85da2ac51dfea85177ffa458c2a50.tar.gz
tk-b8c4ee9a5df85da2ac51dfea85177ffa458c2a50.tar.bz2
* macosx/tkMacOSXCarbonEvents.c (new): moved carbon events code into
* macosx/tkMacOSXHLEvents.c: new file like on HEAD, * macosx/tkMacOSXInit.c (TkpInit): initialize carbon event handlers * macosx/tkMacOSXInt.h: in TkpInit(), add new source * unix/Makefile.in: file to Makefile.in. * macosx/tkMacOSXCarbonEvents.c (AppEventHandlerProc): handle carbon events sent directly to application event target via the general TkMacOSXProcessEvent() in the same way as events posted to the event loop. Moved existing app event handlers to tkMacOSXWindowEvent.c. (TkMacOSXInitCarbonEvents): register our application event handler for kEventWindowExpanded events to deal with uncollapsing from the dock. * macosx/tkMacOSXEvent.h: made TkMacOSXProcessEvent() non-static, added * macosx/tkMacOSXEvent.c: new interp field to TkMacOSXEvent struct for use by app event handler. * macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): retrieve current window, partCode, modifiers and local cursor position from carbon mouse event if possible. Use new static GenerateButtonEvent() taking a MouseEventData struct instead of TkGenerateButtonEvent() to avoid recomputing already known values. Move process activation on MouseDown into BringWindowForward() to allow clicking on window titlebar widgets without activating process. Move code dealing with clicks in window titelbar into separate function HandleWindowTitlebarMouseDown() to avoid code duplication. Avoid repeated calls to TkMacOSXGetXWindow() by storing result in MouseEventData struct. (TkMacOSXButtonKeyState, XQueryPointer): try to get button and modifier state from currently processed carbon event (to avoid unnecessary IPC with the window server), otherwise use modern carbon API to get this info instead of Button() and GetKeys(); only retrieve info caller asks for (via non-NULL ptr passed to XQueryPointer). (ButtonModifiers2State): new static function converting carbon button and modifier state into tk state, allows detection of more than 3 mouse buttons (tk supports up to 5) and of NumLock and Fn modifier keys (NumLock is mapped to Mod3 and Fn to Mod4). * macosx/tkMacOSXWindowEvent.c (TkMacOSXProcessApplicationEvent): handle kEventWindowExpanded event to deal with window uncollapsing from the dock by generating tk Map event, handle kEventAppHidden and kEventAppShown events (moved here from tkMacOSXCarbonEvents.c). * macosx/tkMacOSXSubwindows.c (XUnmapWindow): only hide window when it is not iconified to avoid window flashing on collapse. * macosx/tkMacOSXWm.c: replaced Tk_DoWhenIdle() by Tcl_DoWhenIdle(). (TkMacOSXZoomToplevel): remove call to TrackBox(), now done in HandleWindowTitlebarMouseDown() in tkMacOSXMouseEvent.c. (TkpWmSetState): avoid window flashing on collapse by unmapping after calling CollapseWindow(); only uncollapse window if it is collapsed. * generic/tkInt.decls: changed TkMacOSXZoomToplevel() signature. * generic/tkIntPlatDecls.h: * macosx/tkMacOSXKeyEvent.c (TkMacOSXProcessKeyboardEvent): only call GetMenuItemCommandID() on KeyDown or KeyRepeat events. * macosx/tkMacOSXMenu.c (ReconfigureMacintoshMenu): remove call to obsolete AppendResMenu() API. * macosx/tkMacOSXKeyEvent.c: replaced all direct uses of expensive * macosx/tkMacOSXMenu.c: GetMouse() and TkMacOSXButtonKeyState() * macosx/tkMacOSXMenus.c: APIs by calls to XQueryPointer() * macosx/tkMacOSXMouseEvent.c: * macosx/tkMacOSXScale.c: * macosx/tkMacOSXScrlbr.c: * macosx/tkMacOSXWm.c: * macosx/tkMacOSXDialog.c: replaced use of FrontNonFloatingWindow() * macosx/tkMacOSXKeyEvent.c: by ActiveNonFloatingWindow() as * macosx/tkMacOSXMenu.c: recommended by Carbon docs. * macosx/tkMacOSXMenus.c: * macosx/tkMacOSXSubwindows.c: * macosx/tkMacOSXWm.c: * macosx/tkMacOSXDialog.c: fixed warnings * macosx/tkMacOSXTest.c: * macosx/tkMacOSXCarbonEvents.c: added CVS Id line to file header. * macosx/tkMacOSXDebug.c: * macosx/tkMacOSXDebug.h: * macosx/tkMacOSXEntry.c: * macosx/tkMacOSXEvent.h: * macosx/tkMacOSXKeyEvent.c: * macosx/tkMacOSXMouseEvent.c: * macosx/tkMacOSXWindowEvent.c: * macosx/tkMacOSXWm.h: * macosx/tkMacOSXEmbed.c: replaced all uses of panic() with Tcl_Panic() * macosx/tkMacOSXFont.c: (sync with HEAD). * macosx/tkMacOSXMenus.c: * macosx/tkMacOSXSubwindows.c: * macosx/tkMacOSXWm.c: * macosx/tkMacOSXXStubs.c: * macosx/tkMacOSXInt.h: sync with HEAD changes of 2005-03-14. * macosx/tkMacOSXSubwindows.c: * macosx/tclets.r (removed): sync with HEAD. * macosx/tkMacOSXScale.c: * macosx/tkMacOSXPort.h: * library/demos/menu.tcl: removed errant '}'.
Diffstat (limited to 'macosx/tkMacOSXCarbonEvents.c')
-rw-r--r--macosx/tkMacOSXCarbonEvents.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/macosx/tkMacOSXCarbonEvents.c b/macosx/tkMacOSXCarbonEvents.c
new file mode 100644
index 0000000..c0539d2
--- /dev/null
+++ b/macosx/tkMacOSXCarbonEvents.c
@@ -0,0 +1,146 @@
+/*
+ * tkMacOSXCarbonEvents.c --
+ *
+ * This file implements functions that register for and handle
+ * various Carbon Events. The reason a separate set of handlers
+ * is necessary is that not all interesting events get delivered
+ * directly to the event queue through ReceiveNextEvent. Some only
+ * get delivered if you register a Carbon Event Handler for the event.
+ *
+ * Copyright 2001, Apple Computer, Inc.
+ *
+ * The following terms apply to all files originating from Apple
+ * Computer, Inc. ("Apple") and associated with the software
+ * unless explicitly disclaimed in individual files.
+ *
+ *
+ * Apple hereby grants permission to use, copy, modify,
+ * distribute, and license this software and its documentation
+ * for any purpose, provided that existing copyright notices are
+ * retained in all copies and that this notice is included
+ * verbatim in any distributions. No written agreement, license,
+ * or royalty fee is required for any of the authorized
+ * uses. Modifications to this software may be copyrighted by
+ * their authors and need not follow the licensing terms
+ * described here, provided that the new terms are clearly
+ * indicated on the first page of each file where they apply.
+ *
+ *
+ * IN NO EVENT SHALL APPLE, THE AUTHORS OR DISTRIBUTORS OF THE
+ * SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
+ * INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF
+ * THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
+ * EVEN IF APPLE OR THE AUTHORS HAVE BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE. APPLE, THE AUTHORS AND
+ * DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS
+ * SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND APPLE,THE
+ * AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
+ * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * GOVERNMENT USE: If you are acquiring this software on behalf
+ * of the U.S. government, the Government shall have only
+ * "Restricted Rights" in the software and related documentation
+ * as defined in the Federal Acquisition Regulations (FARs) in
+ * Clause 52.227.19 (c) (2). If you are acquiring the software
+ * on behalf of the Department of Defense, the software shall be
+ * classified as "Commercial Computer Software" and the
+ * Government shall have only "Restricted Rights" as defined in
+ * Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the
+ * foregoing, the authors grant the U.S. Government and others
+ * acting in its behalf permission to use and distribute the
+ * software in accordance with the terms specified in this
+ * license.
+ *
+ * RCS: @(#) $Id: tkMacOSXCarbonEvents.c,v 1.3.2.2 2005/08/09 07:39:54 das Exp $
+ */
+
+#include "tkInt.h"
+#include "tkMacOSXInt.h"
+#include "tkMacOSXEvent.h"
+
+static EventHandlerRef ApplicationCarbonEventHandler;
+
+/* Definitions of functions used only in this file */
+static OSStatus AppEventHandlerProc (
+ EventHandlerCallRef callRef,
+ EventRef inEvent,
+ void *userData);
+
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * AppEventHandlerProc --
+ *
+ * This procedure is the Application CarbonEvent
+ * handler. Currently, it handles the Hide & Show
+ * events.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * Dispatches CarbonEvents.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static OSStatus
+AppEventHandlerProc (
+ EventHandlerCallRef callRef,
+ EventRef inEvent,
+ void *inUserData)
+{
+ OSStatus result = eventNotHandledErr;
+ TkMacOSXEvent macEvent;
+ MacEventStatus eventStatus;
+
+ macEvent.eventRef = inEvent;
+ macEvent.eClass = GetEventClass(macEvent.eventRef);
+ macEvent.eKind = GetEventKind(macEvent.eventRef);
+ macEvent.interp = (Tcl_Interp *) inUserData;
+ bzero(&eventStatus, sizeof(eventStatus));
+ TkMacOSXProcessEvent(&macEvent,&eventStatus);
+ if (!eventStatus.stopProcessing) {
+ result = noErr;
+ }
+ return result;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TkMacOSXInitCarbonEvents --
+ *
+ * This procedure initializes the Application CarbonEvent
+ * handler.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * A handler for Application targeted Carbon Events is registered.
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+TkMacOSXInitCarbonEvents (
+ Tcl_Interp *interp)
+{
+ const EventTypeSpec inAppEventTypes[] = {
+ {kEventClassApplication, kEventAppHidden},
+ {kEventClassApplication, kEventAppShown},
+ {kEventClassWindow, kEventWindowExpanded},
+ };
+
+ InstallEventHandler(GetApplicationEventTarget(),
+ NewEventHandlerUPP(AppEventHandlerProc),
+ GetEventTypeCount(inAppEventTypes),
+ inAppEventTypes, (void *) interp,
+ &ApplicationCarbonEventHandler);
+
+}
+