shellkb.c

Go to the documentation of this file.
00001 
00002 /*  $Id: shellkb.c 491 2005-12-29 02:26:01Z icreedon $    */
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 "menu.h"
00032 #include "ops.h"
00033 #include "kb.h"
00034 #include "sounds.h"
00035 #include "shell.h"
00036 #include "shellhooks.h"
00037 #include "shellmenu.h"
00038 
00039 
00040 
00041 unsigned long timelastkeystroke = 0; /*the value of tickcount for last keystroke*/
00042 
00043 static boolean flouchlocked = false;    /*4.0b7 dmb*/
00044 
00045 
00046 #ifdef MACVERSION   
00047 
00048 static boolean shellfilterfontkey (long *codeword) {
00049     
00050     /*
00051     2005-12-28 lawton, creedon : if option key is down bail out, allows command-option-u to find its item in its menubar
00052     
00053     filter cmd-shift-B,I,U,O,S to a style-menu item.
00054     */
00055     
00056     register short ixitem;
00057     register short ixmenu;
00058     
00059     if ((!keyboardstatus.flcmdkey) || (!keyboardstatus.flshiftkey) || keyboardstatus.floptionkey) 
00060         return (false);
00061     
00062     if (shellmenuhandle (fontmenu) == nil) /*font menu isn't present*/
00063         return (false);
00064     
00065     switch (uppercasechar (keyboardstatus.chkb)) {
00066         
00067         case 'P':
00068             ixmenu = stylemenu;
00069             
00070             ixitem = plainitem;
00071             
00072             break;
00073         
00074         case 'B':
00075             ixmenu = stylemenu;
00076             
00077             ixitem = bolditem;
00078             
00079             break;
00080                 
00081         case 'I':
00082             ixmenu = stylemenu;
00083             
00084             ixitem = italicitem;
00085             
00086             break;
00087                 
00088         case 'U':
00089             ixmenu = stylemenu;
00090             
00091             ixitem = underlineitem;
00092             
00093             break;
00094                 
00095         case 'O':
00096             ixmenu = stylemenu;
00097             
00098             ixitem = outlineitem;
00099             
00100             break;
00101                 
00102         case 'S':
00103             ixmenu = stylemenu;
00104             
00105             ixitem = shadowitem;
00106             
00107             break;
00108             
00109         case ',':
00110             ixmenu = sizemenu;
00111             
00112             ixitem = pointdownitem;
00113             
00114             break;
00115             
00116         case '.':
00117             ixmenu = sizemenu;
00118             
00119             ixitem = pointupitem;
00120             
00121             break;
00122             
00123         case '[':
00124             ixmenu = fontmenu;
00125             
00126             ixitem = getprevmenuitem (shellmenuhandle (fontmenu));
00127             
00128             break;
00129                 
00130         case ']':
00131             ixmenu = fontmenu;
00132             
00133             ixitem = getnextmenuitem (shellmenuhandle (fontmenu));
00134             
00135             break;
00136             
00137         default:
00138             return (false);
00139         } /*switch*/
00140     
00141     *codeword = ((long) ixmenu << 16) + ixitem;
00142     
00143     return (true);
00144     } /*shellfilterfontkey*/
00145 
00146 
00147 enum { /*key codes*/
00148     
00149     clearkey = 0x47,
00150     
00151     helpkey = 0x72,
00152     
00153     homekey = 0x73,
00154     
00155     endkey = 0x77,
00156     
00157     pgupkey = 0x74,
00158     
00159     pgdnkey = 0x79
00160     };
00161 
00162 
00163 static boolean shellfilterfunctionkey (long *codeword) {
00164     
00165     register short item;
00166     register short menu = editmenu;
00167     
00168     switch (keyboardstatus.keycode) {
00169         
00170         case 'z':
00171             item = undoitem;
00172             
00173             break;
00174         
00175         case 'x':
00176             item = cutitem;
00177             
00178             break;
00179         
00180         case 'c':
00181             item = copyitem;
00182             
00183             break;
00184         
00185         case 'v':
00186             item = pasteitem;
00187             
00188             break;
00189         
00190         case clearkey:
00191             item = clearitem;
00192             
00193             break;
00194         
00195         case helpkey:
00196             item = helpitem;
00197             
00198             menu = virtualmenu;
00199             
00200             break;
00201             
00202         case homekey:
00203             item = homeitem;
00204             
00205             menu = virtualmenu;
00206             
00207             break;
00208             
00209         case endkey:
00210             item = enditem;
00211             
00212             menu = virtualmenu;
00213             
00214             break;
00215             
00216         case pgupkey:
00217             item = pageupitem;
00218             
00219             menu = virtualmenu;
00220             
00221             break;
00222             
00223         case pgdnkey:
00224             item = pagedownitem;
00225             
00226             menu = virtualmenu;
00227             
00228             break;
00229         
00230         default:
00231             return (false);
00232         } /*switch*/
00233     
00234     *codeword = ((long) menu << 16) + item;
00235     
00236     return (true);
00237     } /*shellfilterfunctionkey*/
00238 
00239 #endif
00240 
00241 void shellhandlekeystroke (void) {
00242     
00243     /*
00244     if it's a cmd-key we first offer it to the frontmost window, if he doesn't
00245     consume it, we pass it on to the menubar.
00246     
00247     if it's shift-enter, we close the frontmost window.
00248     
00249     otherwise we pass the keystroke to the front window's handler.
00250     
00251     7/18/90 DW: add hooks.  they're allowed to consume a keystroke by returning
00252     false.
00253     
00254     11/8/90 DW: add support for style keys -- cmd-shift BIOUS.
00255     
00256     12/6/91 dmb: give menubar priority over cmdkeyfilter
00257     */
00258     
00259     unsigned int chkb;
00260     #ifdef MACVERSION   
00261         register boolean fl;
00262         long codeword;
00263     #endif
00264     
00265     timelastkeystroke = gettickcount ();
00266     
00267     setkeyboardstatus (shellevent.message, shellevent.what, shellevent.modifiers); /*fill keyboardstatus record with info about the event*/
00268     
00269     if (!keyboardstatus.flautokey)  /*4.0b7 dmb: new non-repeating ouchs*/
00270         flouchlocked = false;
00271 
00272 #ifdef MACVERSION   
00273     if (shellfilterfunctionkey (&codeword) || shellfilterfontkey (&codeword)) {
00274         
00275         fl = shellpushfrontglobals ();
00276         
00277         shellupdatemenus ();
00278         
00279         HiliteMenu (HiWord (codeword));
00280         
00281         shellhandlemenu (codeword);
00282         
00283         if (fl)
00284             shellpopglobals ();
00285             
00286         return;
00287         }
00288 #endif
00289     
00290     if (!shellcallkeyboardhooks ())
00291         return;
00292     
00293     chkb = keyboardstatus.chkb; /*move into register*/
00294 
00295 #ifdef MACVERSION   
00296     if (keyboardstatus.flcmdkey && (chkb >= chspace)) {
00297         
00298         if (chkb == '.') { /*cmd-period is consumed here*/
00299         
00300             keyboardsetescape ();
00301             
00302             return;
00303             }
00304         
00305         /*
00306         if (shellpushfrontglobals ()) { /%a window is open%/
00307             
00308             fl = (*shellglobals.cmdkeyfilterroutine) (keyboardstatus.chkb);
00309             
00310             shellpopglobals ();
00311             
00312             if (!fl) /%cmd-key was consumed%/
00313                 return;
00314             }
00315         */
00316         
00317         fl = shellpushfrontglobals ();
00318         
00319         shellupdatemenus (); /*be sure the menus are properly checked and highlighted*/
00320         
00321         if (!shellhandlemenu (MenuKey (chkb))) { /*cmd-key not consumed by menubar*/
00322             
00323             if (fl)
00324                 (*shellglobals.cmdkeyfilterroutine) (chkb);
00325             }
00326         
00327         if (fl)
00328             shellpopglobals ();
00329         
00330         return;
00331         }
00332 #endif
00333         
00334     if (shellpushfrontglobals ()) { /*a window is open to close or receive keystroke*/
00335     
00336         if (shellcalleventhooks (&shellevent, shellwindow)) /*keystroke wasn't consumed*/
00337             (*shellglobals.keystrokeroutine) ();
00338         
00339         shellpopglobals ();
00340         }
00341     } /*shellhandlekeystroke*/
00342 
00343 
00344 boolean shellfilterscrollkey (byte chkey) {
00345 
00346     switch (chkey) {
00347 
00348         case chhome:
00349             (*shellglobals.scrollroutine) (down, false, longinfinity);
00350             
00351             break;
00352         
00353         case chend:
00354             (*shellglobals.scrollroutine) (up, false, longinfinity);
00355             
00356             break;
00357         
00358         case chpageup:
00359             (*shellglobals.scrollroutine) (down, true, 1);
00360             
00361             break;
00362         
00363         case chpagedown:
00364             (*shellglobals.scrollroutine) (up, true, 1);
00365             
00366             break;
00367 
00368         default:
00369             return (false);
00370         }
00371     
00372     return (true);
00373     } /*shellfilterscrollkey*/
00374 
00375 
00376 void shellouch (void) {
00377     
00378     /*
00379     ouch in response to a keystroke -- unless it was a repeat key
00380     */
00381     
00382     if (!flouchlocked) {
00383         
00384         ouch ();
00385         
00386         flouchlocked = true;
00387         }   
00388     } /*shellouch*/
00389 
00390 

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