shellmouse.c

Go to the documentation of this file.
00001 
00002 /*  $Id: shellmouse.c 1209 2006-04-05 23:59:59Z karstenw $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "frontier.h"
00029 #include "standard.h"
00030 
00031 #include "mac.h"
00032 #include "quickdraw.h"
00033 #include "cursor.h"
00034 #include "scrollbar.h"
00035 #include "menu.h"
00036 #include "mouse.h"
00037 #include "frontierwindows.h"
00038 #include "kb.h"
00039 #include "shell.h"
00040 #include "shellbuttons.h"
00041 #include "shellhooks.h"
00042 #include "shellmenu.h"
00043 #include "shellprivate.h"
00044 
00045 
00046 
00047 #ifdef MACVERSION
00048 static void shellhandlecontent (Point pt) {
00049     
00050     register WindowPtr w = shellwindow;
00051     register hdlwindowinfo h = shellwindowinfo;
00052     hdlscrollbar ctrl;
00053     short part;
00054     tyclickflags flags = clicknormal;
00055     
00056     if (pointinrect (pt, (**h).buttonsrect)) {
00057         
00058         shellbuttonhit (pt);
00059         
00060         return;
00061         }
00062     
00063     if (findscrollbar (pt, w, &ctrl, &part)) { /*mouse hit in a scrollbar*/
00064     
00065         register hdlscrollbar scrollbar = (**h).vertscrollbar;
00066         
00067         if (ctrl == scrollbar) {
00068             
00069             shellscroll (true, scrollbar, part, pt);
00070             
00071             return;
00072             }
00073             
00074         scrollbar = (**h).horizscrollbar;
00075         
00076         if (ctrl == scrollbar) {
00077             
00078             shellscroll (false, scrollbar, part, pt);
00079             
00080             return;
00081             }
00082         }
00083         
00084     setkeyboardstatus (shellevent.message, shellevent.what, shellevent.modifiers); /*allow callback to work with global keyboard record*/
00085     
00086     if (keyboardstatus.flshiftkey)
00087         flags |= clickextend;
00088 
00089     if (keyboardstatus.flcontrolkey)
00090         flags |= clickdiscontiguous;
00091     
00092     if (keyboardstatus.floptionkey)
00093         flags |= clickoption;
00094     
00095     if (keyboardstatus.flcmdkey)
00096         flags |= clickcommand;
00097     
00098     if (mousestatus.fldoubleclick)
00099         flags |= clickwords;
00100     
00101     if (ismouseleftclick())
00102         (*shellglobals.mouseroutine) (pt, flags);
00103 
00104     else if (ismouserightclick())
00105         (*shellglobals.rmouseroutine) (pt, flags);
00106     
00107     else if (ismousecenterclick())
00108         (*shellglobals.cmouseroutine) (pt, flags);
00109     
00110     else if (ismousewheelclick())
00111         (*shellglobals.wmouseroutine) (pt, flags);
00112     } /*shellhandlecontent*/
00113     
00114 
00115 static void shellhandlegrow (Point pt, WindowPtr wgrow) {
00116     
00117     register WindowPtr w = wgrow;
00118     register long x;
00119     Rect boundsrect;
00120     Rect r;
00121     
00122     getdesktopbounds (&r);
00123     
00124     boundsrect.left = config.rmin.right - config.rmin.left; /*minimum window width*/
00125     
00126     boundsrect.right = r.right - r.left - 5; /*maximum window width*/
00127     
00128     boundsrect.top = config.rmin.bottom - config.rmin.top; /*minimum window height*/
00129     
00130     boundsrect.bottom = r.bottom - r.top - 5; /*maximum window height*/
00131     
00132     x = GrowWindow (w, pt, &boundsrect);
00133     
00134     if (x) {
00135         
00136         sizewindow (w, LoWord (x), HiWord (x));
00137         
00138         shelladjustaftergrow (w);
00139         }
00140     } /*shellhandlegrow*/
00141 
00142 
00143 static void shellhandlezoom (EventRecord ev, WindowPtr wzoom, short part) {
00144     
00145     register WindowPtr w = wzoom;
00146     
00147     assert (w == shellwindow);
00148     
00149     if (TrackBox (w, ev.where, part))
00150         (*shellglobals.zoomwindowroutine) (shellwindowinfo, part == inZoomIn);
00151     } /*shellhandlezoom*/
00152 
00153 
00154 void shellhandledrag (EventRecord ev, WindowPtr w) {
00155     
00156     /*
00157     7/25/91 dmb: if the mouse isn't still down, make sure that the 
00158     window is brought to the front, unless the command key is down.
00159     
00160     note that mouse up event is created before calling DragWindow to 
00161     avoid accidental double-clicks when trying to move windows around
00162     */
00163     
00164     Rect r;
00165     
00166     ev.when = gettickcount ();
00167     
00168     mouseup (ev.when, ev.where.h, ev.where.v, ev.what); /*DragWindow will consume mouseup; create one to enable double-click*/
00169     
00170     getdesktopbounds (&r);
00171     
00172     insetrect (&r, dragscreenmargin, dragscreenmargin);
00173     
00174     if (mousestilldown ())
00175         DragWindow (w, ev.where, &r);
00176     
00177     else {
00178         
00179         if (!keyboardstatus.flcmdkey)
00180             windowbringtofront (w);
00181         }
00182     } /*shellhandledrag*/
00183 
00184 #endif
00185 
00186 void shellhandlemouseup (void) {
00187     mouseup (shellevent.when, shellevent.where.h, shellevent.where.v, shellevent.what); /*call mouse.c routine to record info*/
00188     } /*shellhandlemouseup*/
00189 
00190 void shellhandlemouse (void) {
00191     
00192     /*
00193     1/30/91 dmb: moved shellcalleventhooks calls and test for nil macwindow 
00194     into new cases in first switch statement.  much simpler; hopefully correct.
00195     
00196     5/27/92 dmb: only call the titleclickcallback when the window is frontmost
00197     */
00198     
00199     Point mousept;
00200     short windowpart;
00201     WindowPtr macwindow;
00202     register WindowPtr w;
00203 #ifdef WIN95VERSION     
00204     tyclickflags flags = clicknormal;
00205 #endif
00206 
00207     #ifdef MACVERSION
00208         Point localpt;
00209     #endif
00210 
00211     mousedown (shellevent.when, shellevent.where.h, shellevent.where.v, shellevent.what); /*call mouse.c routine to record info*/
00212     
00213     mousept = shellevent.where;
00214 
00215     findmousewindow (mousept, &macwindow, &windowpart);
00216 
00217 #ifdef WIN95VERSION     
00218     macwindow = (WindowPtr) shellevent.hwnd;
00219 
00220     if (!isshellwindow (macwindow)) // 4.0b6, 2/23/96 dmb
00221         return;
00222     
00223     if (!shellcalleventhooks (&shellevent, macwindow))
00224         return;
00225 
00226     w = macwindow;
00227 
00228     shellpushglobals (w); /*following mouse operations assume globals are pushed*/
00229     
00230     if ((macwindow != getfrontwindow ())) {
00231         
00232         windowbringtofront (macwindow);
00233         
00234         if (!config.fldontconsumefrontclicks) {
00235             
00236             mousedoubleclickdisable (); /*click can't be part of a doubleclick*/
00237             
00238             goto exit; /*the mouse click is consumed by the windowbringtofront operation*/
00239             }
00240         }
00241 
00242     setkeyboardstatus (shellevent.message, shellevent.what, shellevent.modifiers); /*allow callback to work with global keyboard record*/
00243     
00244     if (keyboardstatus.flshiftkey)
00245         flags |= clickextend;
00246 
00247     if (keyboardstatus.flcontrolkey)
00248         flags |= clickdiscontiguous;
00249     
00250     if (keyboardstatus.floptionkey)
00251         flags |= clickoption;
00252     
00253     if (keyboardstatus.flcmdkey)
00254         flags |= clickcommand;
00255     
00256     if (mousestatus.fldoubleclick)
00257         flags |= clickwords;
00258     
00259     if (pointinrect (mousept, (**shellwindowinfo).buttonsrect)) {
00260         
00261         shellbuttonhit (mousept);
00262         
00263         goto exit;
00264         }
00265 
00266     switch (shellevent.part) {
00267         case HTCLIENT:
00268             if (ismouseleftclick())
00269                 (*shellglobals.mouseroutine) (mousept, flags);
00270 
00271             else if (ismouserightclick())
00272                 (*shellglobals.rmouseroutine) (mousept, flags);
00273             
00274             else if (ismousecenterclick())
00275                 (*shellglobals.cmouseroutine) (mousept, flags);
00276             
00277             else if (ismousewheelclick())
00278                 (*shellglobals.wmouseroutine) (mousept, flags);
00279             break;
00280 
00281         case HTCAPTION:
00282             if (macwindow == getfrontwindow ())
00283                 if ((*shellglobals.titleclickroutine) (mousept)) /*click was consumed*/
00284                     break;
00285             break;
00286 
00287         case HTBORDER:
00288         case HTBOTTOM:
00289         case HTBOTTOMLEFT:
00290         case HTBOTTOMRIGHT:
00291         case HTGROWBOX:
00292         case HTHSCROLL:
00293         case HTLEFT:
00294         case HTMENU:
00295         case HTREDUCE:
00296         case HTRIGHT:
00297         case HTSYSMENU:
00298         case HTTOP:
00299         case HTTOPLEFT:
00300         case HTTOPRIGHT:
00301         case HTVSCROLL:
00302         case HTZOOM:
00303             break;
00304 
00305         default:
00306             break;
00307         }
00308 
00309 #endif
00310 
00311 #ifdef MACVERSION   
00312     switch (windowpart) { /*operations that don't require globals pushed*/
00313         
00314         case inDesk:
00315             return;
00316         
00317         case inSysWindow:
00318             //Code change by Timothy Paustian Friday, June 16, 2000 3:07:31 PM
00319             //Changed to Opaque call for Carbon
00320             //not used in carbon
00321             #if !TARGET_API_MAC_CARBON
00322             SystemClick (&shellevent, macwindow); 
00323             #endif
00324 
00325             return;
00326         
00327         case inMenuBar:
00328             assert (macwindow == nil);
00329             
00330             frontshellwindow (&macwindow);
00331             
00332             break;
00333         
00334         default:
00335             assert (macwindow != nil);
00336             
00337             if (!isshellwindow (macwindow)) // 4.0b6, 2/23/96 dmb
00338                 return;
00339             
00340             if (!shellcalleventhooks (&shellevent, macwindow))
00341                 return;
00342             
00343             break;
00344         } /*switch*/
00345     
00346     w = macwindow; /*copy into register*/
00347     
00348     shellpushglobals (w); /*following mouse operations assume globals are pushed*/
00349     
00350     #if TARGET_API_MAC_CARBON == 1
00351     
00352         /*On OS X, some operations don't require the window to come to front. PBS 7.0b53.*/
00353 
00354         if ((macwindow != getfrontwindow ()) && (windowpart != inDrag) && (windowpart != inMenuBar)
00355             && (windowpart != inGoAway) && (windowpart != inZoomOut) && (windowpart != inZoomIn)
00356             && (windowpart != inProxyIcon)) {
00357     
00358     #else
00359     
00360         if ((macwindow != getfrontwindow ()) && (windowpart != inDrag) && (windowpart != inMenuBar)) {
00361     
00362     #endif
00363         
00364         windowbringtofront (macwindow);
00365         
00366         if (!config.fldontconsumefrontclicks) {
00367             
00368             mousedoubleclickdisable (); /*click can't be part of a doubleclick*/
00369             
00370             goto exit; /*the mouse click is consumed by the windowbringtofront operation*/
00371             }
00372         }
00373     
00374     setkeyboardstatus (shellevent.message, shellevent.what, shellevent.modifiers); /*fill keyboardstatus record with modifier key info*/
00375 
00376     localpt = mousept;
00377     
00378     globaltolocalpoint (w, &localpt);
00379     
00380     switch (windowpart) {
00381     
00382         case inGrow:
00383             /*
00384             if (!shellcalleventhooks (&shellevent, w))
00385                 break;
00386             */
00387             
00388             if (config.flgrowable) {
00389                 
00390                 shellhandlegrow (mousept, w);
00391                 
00392                 break;
00393                 }
00394             
00395             /*window not growable -- fall through to content-handling code*/
00396             
00397         case inContent: 
00398             /*
00399             if (!shellcalleventhooks (&shellevent, w))
00400                 break;
00401             */
00402             shellhandlecontent (localpt); 
00403             
00404             break;
00405         
00406         case inMenuBar: 
00407 
00408             shellupdatemenus (); /*be sure the menus are properly checked and highlighted*/
00409             
00410             setcursortype (cursorisarrow); /*arrow cursor is more appropriate here*/
00411             
00412             shellhandlemenu (trackmenu (mousept)); 
00413             
00414             break;
00415         
00416         case inDrag:
00417             /*
00418             if (!shellcalleventhooks (&shellevent, w))
00419                 break;
00420             */
00421             
00422             if (macwindow == getfrontwindow ())
00423                 if ((*shellglobals.titleclickroutine) (localpt)) /*click was consumed*/
00424                     break;
00425             
00426             shellhandledrag (shellevent, w);
00427             
00428             break;
00429             
00430         case inGoAway:
00431             /*
00432             if (!shellcalleventhooks (&shellevent, w))
00433                 break;
00434             */
00435             
00436             if (TrackGoAway (w, mousept))
00437             {
00438                 // 2006-04-03 - kw --- brace for ambiguity warning
00439                 if (keyboardstatus.floptionkey)
00440                     shellcloseall (w, true);
00441                 else
00442                     shellclose (w, true);
00443             }
00444                     
00445             break;
00446         
00447         case inZoomOut: case inZoomIn:
00448             /*
00449             if (!shellcalleventhooks (&shellevent, w))
00450                 break;
00451             */
00452             
00453             shellhandlezoom (shellevent, w, windowpart);
00454             
00455             break;
00456             
00457         #if TARGET_API_MAC_CARBON == 1
00458         
00459             case inProxyIcon: /*7.0b50: proxy icons are draggable in OS X*/
00460             
00461                 TrackWindowProxyDrag (w, mousept);
00462                 
00463                 break;
00464         #endif
00465         } /*switch*/
00466 #endif
00467     
00468     exit:
00469     
00470     shellpopglobals ();
00471     } /*shellhandlemouse*/
00472 
00473 
00474 boolean shellcheckautoscroll (Point pt, boolean flhoriz, tydirection *dir) {
00475     
00476     return (mousecheckautoscroll (pt, (**shellwindowinfo).contentrect, flhoriz, dir));
00477     } /*shellcheckautoscroll*/
00478 
00479 
00480 #if TARGET_API_MAC_CARBON == 1
00481 
00482 static pascal OSStatus mousewheelhandler (EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) {
00483     
00484     /*
00485     7.1b24 PBS: called from the system when the mouse wheel is moved.
00486     */
00487     
00488     #pragma unused(nextHandler) /*happy compiler*/
00489     #pragma unused(userData)
00490     
00491     SInt32 delta;
00492     OSErr ec = eventNotHandledErr;
00493     WindowPtr w;
00494     tydirection dir = down;
00495         
00496     if (GetEventParameter (theEvent, kEventParamMouseWheelDelta, typeLongInteger, NULL, sizeof (delta), NULL, &delta) != noErr)
00497         return (ec);
00498 
00499     w = getfrontwindow ();
00500     
00501     shellpushglobals (w);
00502     
00503     if (delta < 0)
00504         dir = up;
00505         
00506     (*shellglobals.scrollroutine) (dir, false, abs (delta) * 2);
00507     
00508     shellpopglobals ();
00509 
00510     return (noErr);
00511     } /*dockmenuhandler*/
00512 
00513 
00514 static void shellinstallmousewheelhandler (void) {
00515     
00516     EventTypeSpec myevents = {kEventClassMouse, kEventMouseWheelMoved};
00517     
00518     InstallApplicationEventHandler (NewEventHandlerUPP (mousewheelhandler), 1, &myevents, 0, NULL); 
00519     } /*dockmenuinstallhandler*/
00520 
00521 #endif
00522 
00523 void initmouse (void) {
00524     
00525     #if TARGET_API_MAC_CARBON == 1
00526     
00527         shellinstallmousewheelhandler (); /*7.1b24 PBS: install mouse wheel support on OS X.*/
00528         
00529     #endif
00530     } /*initmouse*/
00531 

Generated on Wed May 31 18:20:01 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6