shellwindowmenu.c

Go to the documentation of this file.
00001 
00002 /*  $Id: shellwindowmenu.c 1199 2006-04-05 22:17:27Z 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 "menu.h"
00032 #include "sounds.h"
00033 #include "frontierwindows.h"
00034 #include "shell.h"
00035 #include "shellmenu.h"
00036 #include "shellprivate.h"
00037 #include "cancoon.h"
00038 #if TARGET_API_MAC_CARBON == 1
00039     #include "launch.h" /*For OS X Bring All to Front command*/
00040 #endif
00041 
00042 
00043 
00044 
00045 static hdlmenu hwindowsmenu = nil;
00046 
00047 static boolean flwindowmenudirty = true;
00048 
00049 static boolean fllastwasdottedline = false;
00050 
00051 static short ixsearch;
00052 
00053 static hdlwindowinfo hsearch;
00054 
00055 
00056 
00057 
00058 static boolean pushwindowmenuvisit (WindowPtr w, ptrvoid ptr) {
00059 #pragma unused (ptr)
00060 
00061     /*
00062     3/8/91 dmb: mark the current root item with an asterix, if not checked
00063     
00064     4/5/91 dmb: italicize hidden windows
00065 
00066     5.1b23 dmb: for Win threading, check getwindowinfo result
00067 
00068     7.0b26 PBS: mark the current root only on Macintosh. This is because the mark
00069     used on Windows is a checkmark, which makes for two checkmarks in the Window
00070     menu, which is confusing.
00071     */
00072     
00073     bigstring bs;
00074     WindowPtr wfront;
00075     register short ix;
00076     hdlwindowinfo hinfo;
00077     Style itemstyle = 0;
00078 
00079     #ifdef MACVERSION
00080         hdlwindowinfo hroot;
00081     #endif
00082     
00083     if (!getwindowinfo (w, &hinfo))
00084         return (false);
00085     
00086 #ifdef xxxPIKE
00087     /* Pike only displays visible .root windows */
00088     if ((hinfo != nil) && ((**hinfo).configresnum == idcancoonconfig) && (**hinfo).flhidden)
00089         return (true);
00090 #endif
00091 
00092     shellgetwindowtitle (hinfo, bs); // 7.24.97 dmb: was windowgettitle
00093     
00094     if (isemptystring (bs))
00095         return (true);
00096     
00097     if (!pushmenuitem (hwindowsmenu, windowsmenu, bs, 0))
00098         return (false);
00099     
00100     fllastwasdottedline = false;
00101 
00102     frontshellwindow (&wfront);
00103     
00104     ix = countmenuitems (hwindowsmenu);
00105     
00106     if (w == wfront)
00107         checkmenuitem (hwindowsmenu, ix, true);
00108     
00109     #ifdef MACVERSION /*7.0b26: mark the current root only if this is the Mac version.*/
00110 
00111         else {
00112             if (frontrootwindow (&hroot) && (hinfo == hroot)) /*we're the active root*/
00113                 markmenuitem (hwindowsmenu, ix, '');
00114             }
00115     #endif
00116     
00117     if ((**hinfo).flmadechanges)
00118         itemstyle += underline;
00119     
00120     if ((**hinfo).flhidden)
00121         itemstyle += italic;
00122     
00123     if (itemstyle != 0)
00124         stylemenuitem (hwindowsmenu, ix, itemstyle);
00125     
00126     if (ix == ixsearch) /*side-effect for window menu selection*/
00127         hsearch = hinfo;
00128     
00129     return (true);
00130     } /*pushwindowmenuvisit*/
00131     
00132     
00133 static boolean shellpushmajortype (short id) {
00134     
00135     /*
00136     there can be more than one window of a "major" type, so if there's more than
00137     zero of them, we push all their names and push a dotted line after the names.
00138     */
00139     
00140     register boolean fl = true;
00141     
00142     if (counttypedwindows (id) == 0) 
00143         return (true);
00144         
00145     if (!shellvisittypedwindows (id, &pushwindowmenuvisit, nil))
00146         return (false);
00147     
00148     if (!fllastwasdottedline) {
00149 
00150         fl = pushdottedlinemenuitem (hwindowsmenu);
00151     
00152         fllastwasdottedline = true;
00153         }
00154 
00155     return (fl);
00156     } /*shellpushmajortype*/
00157     
00158     
00159 static boolean shellpushminortype (short id) {
00160     
00161     /*
00162     there can be only one window of a "minor" type, so we push it on without the
00163     ceremonious dotted line.
00164     */
00165     
00166     register boolean fl;
00167     
00168     if (counttypedwindows (id) == 0) 
00169         return (true);
00170         
00171     fl = shellvisittypedwindows (id, &pushwindowmenuvisit, nil);
00172     
00173     fllastwasdottedline = false;
00174     
00175     return (fl);
00176     } /*shellpushminortype*/
00177     
00178     
00179 boolean shellupdatewindowmenu (void) {
00180     
00181     /*
00182     call this when a window is opened or closed, we traverse the window list, building
00183     the window menu, sorted by window type.
00184     
00185     8/30/90 dmb: check for nil windowsmenu
00186     
00187     2/21/91 dmb: window menu is now a main menu; need to disable when empty
00188     
00189     9/11/91 dmb: added idlangdialogconfig minor type
00190     
00191     5.0d16 dmb: push all odb windows as minor types; kill extra dotted lines
00192     
00193     5.0d17 dmb: push idcancoonconfig in export mode _or_ if the root is visible
00194     
00195     5.0a2 dmb: new hidewindow item
00196     
00197     7.0B44 PBS: new Minimize Window menu item.
00198     */
00199     
00200     boolean flwasempty;
00201     hdlwindowinfo hinfo;
00202     
00203     hwindowsmenu = shellmenuhandle (windowsmenu);
00204     
00205     if (hwindowsmenu == nil)
00206         return (true);
00207     
00208     setmenuitemenable (hwindowsmenu, hidewindowitem, isshellwindow (getfrontwindow ()));
00209     
00210     #if TARGET_API_MAC_CARBON == 1
00211     
00212         setmenuitemenable (hwindowsmenu, minimizewindowitem, isshellwindow (getfrontwindow ()));
00213         
00214         setmenuitemenable (hwindowsmenu, bringalltofrontwindowitem, true);
00215         
00216     #endif
00217     
00218     if (!flwindowmenudirty)
00219         return (true);
00220     
00221     flwindowmenudirty = false; /*consume it*/
00222     
00223     flwasempty = countmenuitems (hwindowsmenu) == 0;
00224 
00225     fllastwasdottedline = true; /*default*/
00226     
00227     #if TARGET_API_MAC_CARBON == 1
00228     
00229         deleteallmenuitems (hwindowsmenu, hidewindowitem + 4);
00230 
00231     #else
00232     
00233         deleteallmenuitems (hwindowsmenu, hidewindowitem + 1);
00234     
00235     #endif
00236 
00237 #ifndef PIKE    
00238     if (ccinexpertmode () || (ccfindrootwindow (&hinfo) && !(**hinfo).flhidden))
00239         shellpushmajortype (idcancoonconfig);
00240 #endif
00241 
00242     shellpushminortype (idaboutconfig);
00243     
00244 #ifdef MACVERSION
00245     
00246     shellpushminortype (idplayerconfig); /*7.0b4 PBS: QuickTime Player window*/
00247     
00248 #endif
00249     
00250     shellpushminortype (idcommandconfig);
00251     
00252     shellpushminortype (idlangerrorconfig);
00253     
00254     /*
00255     shellpushminortype (idmessageconfig);
00256     
00257     shellpushminortype (idprogressconfig);
00258     */
00259     
00260     shellpushminortype (idstatsconfig);
00261     
00262     shellpushminortype (idlangdialogconfig);
00263     
00264     if (countmenuitems (hwindowsmenu) > 2 && !fllastwasdottedline) {
00265         
00266         pushdottedlinemenuitem (hwindowsmenu);
00267         
00268         fllastwasdottedline = true;
00269         }
00270     
00271     shellpushminortype (idtableconfig);
00272     
00273     shellpushminortype (idmenueditorconfig);
00274     
00275     shellpushminortype (idscriptconfig);
00276     
00277     shellpushminortype (idoutlineconfig);
00278     
00279     shellpushminortype (idwpconfig);
00280     
00281     shellpushminortype (idpictconfig);
00282     
00283     shellpushminortype (idiowaconfig);
00284 
00285 #ifdef PIKE 
00286     if (countmenuitems (hwindowsmenu) > 2 && !fllastwasdottedline) {
00287         
00288         pushdottedlinemenuitem (hwindowsmenu);
00289         
00290         fllastwasdottedline = true;
00291         }
00292 
00293     if (ccinexpertmode () || (ccfindrootwindow (&hinfo) && !(**hinfo).flhidden))
00294         shellpushmajortype (idcancoonconfig);
00295 #endif
00296 
00297     if (countmenuitems (hwindowsmenu) > 2 && fllastwasdottedline) /*eliminate extraneous dotted line*/
00298         deletelastmenuitem (hwindowsmenu);
00299     
00300     if (flwasempty != (countmenuitems (hwindowsmenu) == 0)) {
00301         
00302         setmenuitemenable (hwindowsmenu, 0, flwasempty);
00303         
00304         drawmenubar ();
00305         }
00306     
00307     return (true);
00308     } /*shellupdatewindowmenu*/
00309     
00310     
00311 void shellwindowmenudirty (void) {
00312     
00313     flwindowmenudirty = true; /*set local flag*/
00314     } /*shellwindowmenudirty*/
00315     
00316 
00317 void shellwindowmenuselect (short ixmenu) {
00318     
00319     /*
00320     implemented using a side-effect we programmed into the update process for
00321     the window menu.
00322     
00323     as the menu is being built pushwindowmenuvisit watches for the indicated
00324     item number, when found it sets the global hsearch.  that's the one we
00325     want to bring to the front.
00326     
00327     5.0a2 dmb: new hidewindow item
00328     
00329     7.0b44 PBS: Minimize Window item on Mac OS X.
00330     */
00331     
00332     boolean flcommand = false;
00333     
00334     flwindowmenudirty = true; /*force update*/
00335     
00336     if (ixmenu == hidewindowitem) {
00337         hdlwindowinfo hinfo;
00338         
00339         if (getfrontwindowinfo (&hinfo))
00340             shellhidewindow (hinfo);
00341         }
00342     else {
00343     
00344         #if TARGET_API_MAC_CARBON == 1
00345         
00346             if (ixmenu == minimizewindowitem) {
00347                 
00348                 hdlwindowinfo hinfo;
00349         
00350                 flcommand = true;
00351                             
00352                 if (getfrontwindowinfo (&hinfo))
00353                 
00354                     CollapseWindow ((**hinfo).macwindow, true);             
00355                 } /*if*/
00356             
00357             if (ixmenu == bringalltofrontwindowitem) {
00358                 
00359                 activateapplication (nil); /*nil means self*/
00360                 
00361                 flcommand = true;
00362                 } /*if*/
00363                 
00364         #endif
00365         
00366         if (!flcommand) {
00367 
00368             ixsearch = ixmenu; /*set global*/
00369             
00370             hsearch = nil; /*indicate it wasn't found*/
00371             
00372             shellupdatewindowmenu (); /*for side-effect*/
00373             
00374             if (hsearch != nil) /*it was found*/
00375                 shellbringtofront (hsearch);
00376             else
00377                 ouch ();
00378             } /*if*/
00379         }
00380     } /*shellwindowmenuselect*/
00381 
00382 
00383 
00384 

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