appletabout.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletabout.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 "appletops.h"
00009 #include "appletquickdraw.h"
00010 #include "appletmain.h"
00011 #include "appletzoom.h"
00012 #include "appletabout.h"
00013 
00014 
00015 #ifdef MPWC
00016 
00017 #include <toolutils.h>
00018 #include <osevents.h>
00019 
00020 #endif
00021 
00022 
00023 
00024 #define aboutlistnumber 128
00025 
00026 WindowPtr aboutwindow = nil;
00027 
00028 
00029 
00030 
00031 
00032 #define doline(x)\
00033                                                                             \
00034     MoveTo (r.left + (r.right - r.left - StringWidth (x)) / 2, linev);      \
00035                                                                             \
00036     DrawString (x);                                                         \
00037                                                                             \
00038     linev += lineinc;
00039 
00040 
00041 static void drawabout (WindowPtr w) {
00042     
00043     register short i;
00044     register short linev = 24;
00045     register short lineinc = 14;
00046     bigstring lines [6];
00047     Rect r;
00048     
00049     for (i = 0; i <= 5; i++)    
00050         GetIndString (lines [i], aboutlistnumber, i + 1);
00051     
00052     r = (*w).portRect;
00053     
00054     InsetRect (&r, 4, 4);
00055     
00056     TextFont (systemFont);
00057     
00058     TextSize (12);
00059     
00060     doline (lines [0]);
00061     
00062     TextFont (geneva);
00063     
00064     TextSize (9);
00065     
00066     doline (lines [1]);
00067     
00068     linev += lineinc; /*skip a line*/
00069     
00070     doline (lines [2]);
00071     
00072     doline (lines [3]);
00073     
00074     MoveTo (r.left + 4, r.bottom - 6);
00075     
00076     DrawString (lines [4]);
00077     
00078     MoveTo (r.right - StringWidth (lines [5]) - 4, r.bottom - 6);
00079     
00080     DrawString (lines [5]);
00081     } /*drawabout*/
00082     
00083 
00084 void openabout (Boolean flzoom) { /*can also be called to implement the splash window*/
00085 
00086     Rect r;
00087     
00088     SetRect (&r, 0, 0, 340, 120);
00089     
00090     pushmacport (aboutwindow = NewWindow (nil, &r, (ConstStr255Param)"\p", false, altDBoxProc, (WindowPtr) -1, false, 0));
00091         
00092     centerwindow ((DialogPtr) aboutwindow, quickdrawglobal (screenBits).bounds);
00093     
00094     if (flzoom)
00095         zoomport (aboutwindow, true);
00096     else
00097         ShowWindow (aboutwindow);
00098     
00099     drawabout (aboutwindow);
00100     } /*openabout*/
00101     
00102     
00103 void closeabout (Boolean flzoom) {
00104 
00105     if (aboutwindow != nil) {
00106     
00107         HideWindow (aboutwindow);
00108         
00109         if (flzoom)
00110             zoomport (aboutwindow, false);
00111         else
00112             HideWindow (aboutwindow);
00113         
00114         DisposeWindow (aboutwindow);
00115         
00116         aboutwindow = nil;
00117         
00118         popmacport ();
00119         }
00120     } /*closeabout*/
00121     
00122     
00123 static boolean aboutwindowopen (void) {
00124     
00125     return (aboutwindow != nil);
00126     } /*aboutwindowopen*/
00127 
00128 
00129 static boolean abouthandleevent (EventRecord ev, boolean *boxgoesaway) {
00130 
00131     /*
00132     return true if the event is consumed, false if not.
00133     
00134     set boxgoesaway to true if the event should cause the about box to disappear.
00135     */
00136     
00137     *boxgoesaway = false;
00138     
00139     switch (ev.what) {
00140     
00141         case keyDown: case autoKey: {
00142         
00143             register char ch = ev.message & charCodeMask;
00144             
00145             if ((ch == chreturn) || (ch == chenter)) {
00146                 
00147                 *boxgoesaway = true;
00148                 
00149                 return (true); /*event consumed*/
00150                 }
00151                 
00152             break;
00153             }
00154             
00155         case mouseDown: {   
00156             WindowPtr w;
00157             
00158             FindWindow (ev.where, &w);
00159             
00160             if (w != aboutwindow) /*event definitely not consumed*/
00161                 return (false);
00162                 
00163             if (w == FrontWindow ())
00164                 *boxgoesaway = true;
00165             else
00166                 SelectWindow (w);
00167             
00168             return (true); /*event consumed*/
00169             }
00170             
00171         case updateEvt: {
00172             register WindowPtr eventwindow = (WindowPtr) (ev.message);
00173     
00174             if (eventwindow != aboutwindow)
00175                 return (false); /*event not consumed*/
00176             
00177             /*handle update, we might be using a screen saver*/
00178             
00179             pushmacport (eventwindow);
00180             
00181             BeginUpdate (eventwindow);
00182             
00183             drawabout (eventwindow);
00184             
00185             EndUpdate (eventwindow);
00186             
00187             popmacport ();
00188                                 
00189             return (true); /*event consumed, don't get rid of the about box*/
00190             }
00191             
00192         case activateEvt:                               
00193             return (true); /*event consumed, don't get rid of the about box*/
00194         } /*switch*/
00195     
00196     return (false); /*event not consumed*/
00197     } /*abouthandleevent*/
00198 
00199 
00200 extern boolean flexitmainloop;
00201 
00202 
00203 void aboutcommand (void) {
00204     
00205     EventRecord ev;
00206     boolean flexitabout = false;
00207     
00208     openabout (true);
00209     
00210     while ((!flexitabout) && (!flexitmainloop)) {
00211         
00212         WaitNextEvent (everyEvent, &ev, 1, nil);
00213         
00214         if (!abouthandleevent (ev, &flexitabout)) /*event not consumed by about box*/
00215             appleteventdispatcher (&ev);
00216         } /*while*/
00217     
00218     closeabout (true);
00219     } /*aboutcommand*/
00220 
00221 
00222 
00223 

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