appletwindowmenu.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletwindowmenu.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include "appletinternal.h"
00008 #include "appletmain.h"
00009 #include "appletmenu.h"
00010 #include "appletmenuops.h"
00011 #include "appletwindowmenu.h"
00012 
00013 
00014 MenuHandle hdlwindowmenu;
00015 
00016 static WindowPtr **windowarray = nil; /*dynamic array of window pointers*/
00017 
00018 static short ixwindowarray;
00019 
00020 static short firstwindowmenuslot = 1;
00021 
00022 
00023 
00024 typedef boolean (*tyvisitroutine) (WindowPtr);
00025 
00026 
00027 static boolean visitmacwindows (tyvisitroutine visitproc) {
00028     
00029     WindowPtr w = FrontWindow ();
00030     
00031     while (w != nil) {
00032         
00033         if (!(*visitproc) (w)) /*stop the traversal*/
00034             return (false);
00035         
00036         w = (WindowPtr) (*(WindowPeek) w).nextWindow; 
00037         } /*while*/
00038         
00039     return (true); /*completed the traversal*/
00040     } /*visitmacwindows*/
00041     
00042     
00043 static boolean countvisit (WindowPtr w) {
00044 
00045     ixwindowarray++;
00046     
00047     return (true);
00048     } /*countvisit*/
00049     
00050     
00051 static short countmacwindows (void) {
00052     
00053     ixwindowarray = 0;
00054     
00055     visitmacwindows (&countvisit);
00056     
00057     return (ixwindowarray);
00058     } /*countmacwindows*/
00059     
00060 
00061 static boolean fillwindowarrayvisit (WindowPtr w) {
00062     
00063     (*windowarray) [ixwindowarray++] = w;
00064 
00065     return (true); /*keep going*/
00066     } /*fillwindowarrayvisit*/
00067     
00068     
00069 void adjustwindowmenu (void) {
00070 /*
00071     LDR 10/29/95    if there are no windows in the menu, disable the menu title
00072 */
00073 
00074     MenuHandle hmenu = hdlwindowmenu;
00075     short ctwindows, i;
00076     
00077     for (i = countmenuitems (hmenu); i >= firstwindowmenuslot; i--)
00078         deletemenuitem (hmenu, i);
00079         
00080     disposehandle ((Handle) windowarray);
00081     
00082     windowarray = nil;
00083     
00084     ctwindows = countmacwindows ();
00085     
00086     if (!newclearhandle (ctwindows * longsizeof (WindowPtr), (Handle *) &windowarray))
00087         return;
00088     
00089     ixwindowarray = 0;
00090     
00091     visitmacwindows (&fillwindowarrayvisit);
00092     
00093     /*sort the window array*/ {
00094         
00095         bigstring bssmallest;
00096         short ixsmallest;
00097         short i, j;
00098         bigstring bs;
00099         
00100         for (i = 0; i < ctwindows; i++) {
00101             
00102             ixsmallest = i;
00103             
00104             GetWTitle ((*windowarray) [i], bssmallest);
00105             
00106             alllower (bssmallest);
00107             
00108             for (j = i + 1; j < ctwindows; j++) {
00109                 
00110                 GetWTitle ((*windowarray) [j], bs);
00111                 
00112                 alllower (bs);
00113                 
00114                 if (stringlessthan (bs, bssmallest)) {
00115                     
00116                     copystring (bs, bssmallest);
00117                     
00118                     ixsmallest = j;
00119                     }
00120                 } /*for*/
00121             
00122             if (ixsmallest != i) {
00123                 
00124                 WindowPtr x = (*windowarray) [i];
00125                 
00126                 (*windowarray) [i] = (*windowarray) [ixsmallest];
00127                 
00128                 (*windowarray) [ixsmallest] = x;
00129                 }
00130             } /*for*/
00131         }
00132         
00133     for (i = 0; i < ctwindows; i++) {
00134         
00135         WindowPtr w = (*windowarray) [i];
00136         bigstring windowtitle;
00137         short ct;
00138         hdlappwindow appwindow;
00139         
00140         GetWTitle (w, windowtitle);
00141         
00142         pushmenuitem (hmenu, windowtitle, true);
00143         
00144         ct = countmenuitems (hmenu);
00145         
00146         if (getappwindow (w, &appwindow)) {
00147         
00148             if ((**appwindow).flmadechanges)
00149                 stylemenuitem (hmenu, ct, underline);
00150             }
00151             
00152         if (w == FrontWindow ()) 
00153             checkmenuitem (hmenu, ct, true);
00154         } /*for*/
00155         
00156     if (countmenuitems (hmenu) == 0)
00157         disableallmenuitems(hmenu);
00158     else
00159         enableallmenuitems(hmenu);
00160 
00161     } /*adjustwindowmenu*/
00162     
00163     
00164 void selectwindowmenu (short iditem) {
00165 
00166     if (windowarray != nil)
00167         SelectWindow ((*windowarray) [iditem - firstwindowmenuslot]);
00168     } /*selectwindowmenu*/
00169     
00170     
00171 void initwindowmenu (void) {
00172 
00173     if (app.haswindowmenu) {
00174     
00175         installmenu (windowmenu, &hdlwindowmenu);
00176     
00177         firstwindowmenuslot = countmenuitems (hdlwindowmenu) + 1;
00178         }
00179     } /*initwindowmenu*/
00180     
00181     
00182     
00183     
00184 

Generated on Wed May 31 18:19:44 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6