home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / UStdDialogs.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  24.6 KB  |  852 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include <LPane.h>
  20. #include <LString.h>
  21. #include <LCaption.h>
  22. #include <LIconPane.h>
  23. #include <UTextTraits.h>
  24. #include <LStdControl.h>
  25.  
  26. #include "UStdDialogs.h"
  27. #include "UProcessUtils.h"
  28. #include "CNotificationAttachment.h"
  29.  
  30. #include "UTextBox.h"    // for line height calc function
  31. #include "resgui.h"        // for res id's
  32.  
  33. short    gSaveAsType = 0;    // SaveAsHook stores file type in this variable
  34. short    gUploadAsType = 1;    // UploadAsHook stores file type in this variable
  35.  
  36. const    PaneIDT    okAlertBtnID = 900;
  37. const    PaneIDT    cancelAlertBtnID = 901;
  38.  
  39.  
  40.  
  41.  
  42. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  43. //    Ñ    StStdDialogHandler
  44. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  45.  
  46. StStdDialogHandler::StStdDialogHandler(
  47.     ResIDT             inDialogID,
  48.     LCommander*     inSuper)
  49.     :    StDialogHandler(inDialogID, inSuper)
  50. {
  51.     mDialogResID = inDialogID;
  52. }
  53.  
  54. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  55. //    Ñ    WaitUserResponse
  56. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  57.  
  58. MessageT StStdDialogHandler::WaitUserResponse(void)
  59. {
  60. //    SysBeep(1);
  61.     MessageT theMessage = msg_Nothing;
  62.     while(theMessage == msg_Nothing)
  63.         theMessage = DoDialog();
  64.         
  65.     return theMessage;
  66. }
  67.  
  68. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  69. //    Ñ    
  70. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  71.  
  72. void StStdDialogHandler::SetInitialDialogPosition(LWindow* inParentWindow)
  73. {
  74.     Int16 thePlacement = CalcDialogPlacement();
  75.     if (thePlacement == noAutoCenter)
  76.         return;
  77.  
  78.     Rect theTargetRect;
  79.     CalcDialogTargetBounds(thePlacement, inParentWindow, theTargetRect);
  80.  
  81.     // Now that we have the screen we can center the window ...
  82.     LWindow* theDialogWindow = GetDialog();
  83.     SDimension16 theWindowDims;
  84.     theDialogWindow->GetFrameSize(theWindowDims);
  85.     Int16 targetHeight = theTargetRect.bottom - theTargetRect.top;
  86.     Int16 targetWidth = theTargetRect.right - theTargetRect.left;
  87.     
  88.     Point thePosition;
  89.     
  90.     switch (thePlacement)
  91.         {
  92.         case alertPositionMainScreen:
  93.         case alertPositionParentWindow:
  94.         case alertPositionParentWindowScreen:
  95.             // Place the window at the alert position (20% down) ...
  96.             thePosition.v = theTargetRect.top + (targetHeight - theWindowDims.height) / 5;
  97.             thePosition.h = theTargetRect.left + (targetWidth - theWindowDims.width) / 2;
  98.             break;
  99.             
  100.         case centerMainScreen:
  101.         case centerParentWindow:
  102.         case centerParentWindowScreen:
  103.             // Center it vertically
  104.             thePosition.v = theTargetRect.top + (targetHeight - theWindowDims.height) / 2;
  105.             thePosition.h = theTargetRect.left + (targetWidth - theWindowDims.width) / 2;
  106.             break;
  107.             
  108.         case staggerParentWindowScreen:
  109.         case staggerParentWindow:
  110.         case staggerMainScreen:
  111.         default:
  112.             Assert_(false);
  113.             break;
  114.         }
  115.             
  116.     theDialogWindow->DoSetPosition(thePosition);
  117. }
  118.  
  119. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  120. //    Ñ    
  121. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  122.  
  123. void StStdDialogHandler::CalcDialogTargetBounds(
  124.     Int16                 inPlacement,
  125.     LWindow*            inParentWindow,
  126.     Rect&                outBounds)
  127. {
  128.     Boolean bFindWindowScreen = (inPlacement == centerParentWindowScreen)             ||
  129.                                 (inPlacement == alertPositionParentWindowScreen)    ||
  130.                                 (inPlacement == staggerParentWindowScreen);
  131.  
  132.     GDHandle gdh = GetDeviceList();
  133.     if (inParentWindow == NULL)
  134.         {
  135.         GDHandle theGDH = ::GetMainDevice();
  136.         outBounds = (*theGDH)->gdRect;
  137.         outBounds.top += GetMBarHeight();
  138.         }
  139.     else
  140.         {
  141.         Rect theWindowBounds;
  142.         inParentWindow->CalcPortFrameRect(theWindowBounds);
  143.         inParentWindow->PortToGlobalPoint(topLeft(theWindowBounds));
  144.         inParentWindow->PortToGlobalPoint(botRight(theWindowBounds));
  145.         
  146.         if (bFindWindowScreen)
  147.             {
  148.             // Find out on which screen the window exists ...
  149.             Int32 theMaxArea = 0;
  150.             while (gdh != NULL)
  151.                 {
  152.                 if (::TestDeviceAttribute(gdh, screenDevice) && TestDeviceAttribute(gdh, screenActive))
  153.                     {
  154.                     Rect theSect;
  155.                     if (::SectRect(&theWindowBounds, &(*gdh)->gdRect, &theSect))
  156.                         {
  157.                         Int32 theArea = (Int32)(theSect.right - theSect.left) * (theSect.bottom - theSect.top);
  158.                         if (theArea > theMaxArea)
  159.                             {
  160.                             theMaxArea = theArea;
  161.                             outBounds = (*gdh)->gdRect;
  162.                             if (TestDeviceAttribute(gdh, mainScreen))
  163.                                 outBounds.top += GetMBarHeight();
  164.                             }
  165.                         }
  166.                     }
  167.                 gdh = ::GetNextDevice(gdh);
  168.                 }
  169.                 
  170.             // If we failed then just center the window on the main screen ...
  171.             if (theMaxArea == 0)
  172.                 CalcDialogTargetBounds(alertPositionMainScreen, NULL, outBounds);
  173.             }
  174.         else
  175.             {
  176.             // just use the windows global bounds
  177.             outBounds = theWindowBounds;
  178.             }
  179.         }
  180.  
  181. }
  182.  
  183. // Handy macros
  184. LPane* StStdDialogHandler::GetPane(PaneIDT id)
  185. {
  186.     LPane *pane = mDialog->FindPaneByID(id); 
  187.     SignalIf_(!pane); 
  188.     return pane;
  189. }
  190.  
  191. void StStdDialogHandler::HidePane(PaneIDT id)
  192. {
  193.     GetPane(id)->Hide();
  194. }
  195.  
  196. void StStdDialogHandler::EnablePane(PaneIDT id)
  197. {
  198.     GetPane(id)->Enable();
  199. }
  200.  
  201. void StStdDialogHandler::DisablePane(PaneIDT id)
  202. {
  203.     GetPane(id)->Disable();
  204. }
  205.  
  206. void StStdDialogHandler::ShowPane(PaneIDT id)
  207. {
  208.     GetPane(id)->Show();
  209. }
  210.  
  211. void StStdDialogHandler::SetBoolean(PaneIDT id, Boolean value)
  212. {
  213.     GetControl(id)->SetValue(value);
  214. }
  215.  
  216. Boolean StStdDialogHandler::GetBoolean(PaneIDT id)
  217. {
  218.     return GetControl(id)->GetValue();
  219. }
  220.  
  221. void StStdDialogHandler::SetValue(PaneIDT id, Int32 value)
  222. {
  223.     GetControl(id)->SetValue(value);
  224. }
  225.  
  226. Int32 StStdDialogHandler::GetValue(PaneIDT id)
  227. {
  228.     return GetControl(id)->GetValue();
  229. }
  230.  
  231. void StStdDialogHandler::SetText(PaneIDT id, ConstStr255Param value)
  232. {
  233.     GetPane(id)->SetDescriptor(value);
  234. }
  235.  
  236. void StStdDialogHandler::SetNumberText(PaneIDT id, SInt32 value)
  237. {
  238.     Str255 s;
  239.     ::NumToString(value, s);
  240.     GetPane(id)->SetDescriptor(s);
  241. }
  242.  
  243. void StStdDialogHandler::GetText(PaneIDT id, Str255 value)
  244. {
  245.     GetPane(id)->GetDescriptor(value);
  246. }
  247.  
  248. SInt32 StStdDialogHandler::GetNumberText(PaneIDT id)
  249. {
  250.     Str255 s;
  251.     SInt32 value;
  252.     GetPane(id)->GetDescriptor(s);
  253.     ::StringToNum(s, &value);
  254.     return value;
  255. }
  256.  
  257. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  258. //    Ñ    
  259. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  260.                         
  261. Int16 StStdDialogHandler::CalcDialogPlacement(void)
  262. {
  263.     Int16 thePlacement = noAutoCenter;
  264.     StResource theWind('WIND', mDialogResID);
  265.     
  266.     Int32 theResSize = ::GetHandleSize(theWind);
  267.     thePlacement = *(Int16*)(((Ptr)(*theWind.mResourceH)) + (theResSize - sizeof(thePlacement)));
  268.     return thePlacement;
  269. }
  270.  
  271. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  272. //    Ñ    SetCaption
  273. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  274.  
  275. void StStdDialogHandler::SetCaption(ConstStringPtr inCaption)
  276. {
  277.     LCaption* theCaption = (LCaption*)(GetDialog()->FindPaneByID(PaneID_AlertCaption));
  278.     Assert_(theCaption != NULL);
  279.     theCaption->SetDescriptor(inCaption);
  280. }
  281.  
  282. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  283. //    
  284. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  285.  
  286. StAlertHandler::StAlertHandler(
  287.     ConstStringPtr             inAlertText,
  288.     EAlertType                inAlertType,
  289.     LCommander*                inSuper)
  290.     :    StStdDialogHandler(WIND_StandardAlert, inSuper)
  291. {
  292.     SetCaption(inAlertText);
  293.  
  294.     TString<Str255> theAlertTitle(16000, inAlertType);
  295.     GetDialog()->SetDescriptor(theAlertTitle);
  296.     
  297.     SetAlertIcon(inAlertType);
  298. }
  299.  
  300. StAlertHandler::StAlertHandler(
  301.     ResIDT                    inStrListID,
  302.     Int16                     inIndex,
  303.     EAlertType                inAlertType,
  304.     LCommander*                inSuper)
  305.     :    StStdDialogHandler(WIND_StandardAlert, inSuper)
  306. {
  307.     TString<Str255> theCaptionString(inStrListID, inIndex);
  308.     SetCaption(theCaptionString);
  309.     
  310.     TString<Str255> theAlertTitle(16000, inAlertType);
  311.     GetDialog()->SetDescriptor(theAlertTitle);
  312.     
  313.     SetAlertIcon(inAlertType);
  314. }
  315.             
  316.  
  317.  
  318. void StAlertHandler::SetAlertIcon(EAlertType inAlertType)
  319. {
  320.     ResIDT theAlertIconID = inAlertType + 10000 - 1;
  321.     if (inAlertType == eAlertTypeError)
  322.         theAlertIconID--;
  323.         
  324.     LWindow* theDialog = GetDialog();
  325.     LIconPane* theIconPane = (LIconPane*)theDialog->FindPaneByID(PaneID_AlertIcon);
  326.     Assert_(theIconPane != NULL);
  327.     theIconPane->SetIconID(theAlertIconID);
  328. }
  329.  
  330. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  331. //    Ñ StAutoSizingDialog
  332. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  333.  
  334. StAutoSizingDialog::StAutoSizingDialog(
  335.     ResIDT                    inDialogID,
  336.     const CString&            inAlertText,
  337.     const CString&            inDefaultEditText,
  338.     LCommander*                inSuper)
  339.     :    StStdDialogHandler(inDialogID, inSuper)
  340. {
  341.     SetCaption(inAlertText);
  342.     
  343.     LEditField *theEditField = (LEditField *)(GetDialog()->FindPaneByID(PaneID_AlertEditField));
  344.     Assert_(theEditField != NULL);
  345.     theEditField->SetDescriptor(inDefaultEditText);
  346. }
  347.  
  348. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  349. //    Ñ SetInitialDialogSize
  350. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  351.  
  352. void StAutoSizingDialog::SetInitialDialogSize(void)
  353. {
  354.     LWindow* theDialog = GetDialog();
  355.     LCaption *theCaption = (LCaption *)theDialog->FindPaneByID(PaneID_AlertCaption);
  356.     Assert_(theCaption != NULL);
  357.     
  358.     CStr255 theCaptionString;
  359.     theCaption->GetDescriptor(theCaptionString);
  360.         
  361.         // fill boundsRect with dimensions of caption pane
  362.     Rect theCaptionFrame;
  363.     theCaption->CalcPortFrameRect(theCaptionFrame);
  364.     
  365.         // set text traits, just in case...
  366.     UTextTraits::SetPortTextTraits(theCaption->GetTextTraitsID());
  367.  
  368.         // now call line height calc function (this routine destroys the original string)
  369.     Int16 theHeight = UTextBox::TextBoxDialogHeight((Ptr)&theCaptionString[1], theCaptionString.Length(), 
  370.                                         &theCaptionFrame, teForceLeft, 0);
  371.                     
  372.     // this was in macdlg.cp, is it really necessary?
  373. //    if( height < 16 )
  374. //        height = 16;
  375.         
  376.     Int16 theHeightDifference = theHeight - (theCaptionFrame.bottom - theCaptionFrame.top);
  377.     theCaption->ResizeFrameBy(0, theHeightDifference, false);
  378.  
  379.     // set position of edit field
  380.     LEditField *theEditField = (LEditField *)theDialog->FindPaneByID(PaneID_AlertEditField);
  381.     Assert_(theEditField != NULL);
  382.     SPoint32 theEditLocation;
  383.     theEditField->GetFrameLocation(theEditLocation);
  384.     theEditField->PlaceInSuperFrameAt(theEditLocation.h, theEditLocation.v + theHeightDifference, false);
  385.  
  386.     // Now we resize the dialog by the amount that the caption text
  387.     // changed.  Note that the Ok and Cacel buttons will automatically
  388.     // adjust because we have their bottom and right bindings set.
  389.     Rect theDialogBounds;
  390.     theDialog->CalcPortFrameRect(theDialogBounds);
  391.     theDialogBounds.bottom += theHeightDifference;
  392.     
  393.     theDialog->PortToGlobalPoint(topLeft(theDialogBounds));
  394.     theDialog->PortToGlobalPoint(botRight(theDialogBounds));
  395.     theDialog->DoSetBounds(theDialogBounds);
  396. }
  397.  
  398. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  399. //    Ñ    Alert
  400. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  401.  
  402. void UStdDialogs::Alert(
  403.     ConstStringPtr         inAlertText,
  404.     EAlertType            inType,
  405.     LWindow*            inOverWindow,
  406.     LCommander*            inSuper,
  407.     LStr255*            inWindowTitle
  408.     )
  409. {
  410.     if (inSuper == NULL)
  411.         inSuper = LCommander::GetTopCommander();
  412.         
  413.     StAlertHandler theHandler(inAlertText, inType, inSuper);
  414.     theHandler.SetInitialDialogPosition(inOverWindow);
  415.     LWindow* theDialog = theHandler.GetDialog();
  416.     
  417.     if (inWindowTitle)
  418.         theDialog->SetDescriptor(*inWindowTitle);
  419.         
  420.     if (UStdDialogs::TryToInteract())
  421.         {
  422.             theDialog->Show();
  423.             MessageT theMessage = theHandler.WaitUserResponse();
  424.         }
  425. }
  426.  
  427. Boolean
  428. UStdDialogs::AskWithCustomButtons(
  429.     ConstStringPtr         inQuestion,
  430.     ConstStringPtr        inDefaultTextBtn,
  431.     ConstStringPtr        inCancelTextBtn,
  432.     LWindow*            inOverWindow,
  433.     LCommander*            inSuper,
  434.     LStr255*            inWindowTitle
  435.     )
  436. {
  437.     if (inSuper == NULL)
  438.         inSuper = LCommander::GetTopCommander();
  439.  
  440.     StStdDialogHandler theHandler(WIND_OkCancelAlert, inSuper);
  441.     theHandler.SetCaption(inQuestion);
  442.     theHandler.SetInitialDialogPosition(inOverWindow);
  443.     LWindow* theDialog = theHandler.GetDialog();
  444.  
  445.     if (inWindowTitle)
  446.         theDialog->SetDescriptor(*inWindowTitle);
  447.  
  448.     if ( inDefaultTextBtn )
  449.     {
  450.         LStdButton* okBtnPtr = dynamic_cast<LStdButton*>( theDialog->FindPaneByID( okAlertBtnID ) );
  451.         if( okBtnPtr )
  452.             okBtnPtr->SetDescriptor( inDefaultTextBtn );
  453.     }
  454.         
  455.     if ( inCancelTextBtn )
  456.     {
  457.         LStdButton* cancelBtnPtr = dynamic_cast<LStdButton*>( theDialog->FindPaneByID( cancelAlertBtnID ) );
  458.         if( cancelBtnPtr )
  459.             cancelBtnPtr->SetDescriptor( inCancelTextBtn );
  460.     }
  461.  
  462.     MessageT theMessage = msg_Cancel;
  463.     if (UStdDialogs::TryToInteract())
  464.         {
  465.         theDialog->Show();
  466.         theMessage = theHandler.WaitUserResponse();
  467.         }
  468.     
  469.     return (theMessage == msg_OK);
  470. }
  471.  
  472. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  473. //    Ñ    AskOkCancel
  474. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  475.  
  476. Boolean UStdDialogs::AskOkCancel(
  477.     ConstStringPtr        inQuestion,
  478.     LWindow*            inOverWindow,
  479.     LCommander*            inSuper,
  480.     LStr255*            inWindowTitle)
  481. {
  482.     return AskWithCustomButtons(
  483.         inQuestion,
  484.         nil, // default "Quit"
  485.         nil, // default "Cancel"
  486.         inOverWindow,
  487.         inSuper,
  488.         inWindowTitle
  489.         );
  490. }
  491.  
  492. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  493. //    Ñ    AskStandardTextPrompt
  494. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  495.  
  496. Boolean UStdDialogs::AskStandardTextPrompt(
  497.     const CStr255&            inTitleText,
  498.     const CStr255&            inPromptText,
  499.     CString&                ioString,
  500.     LWindow*                inOverWindow,
  501.     LCommander*                inSuper,
  502.     Int32                    maxIOStringSize)
  503. {
  504.     if (inSuper == NULL)
  505.         inSuper = LCommander::GetTopCommander();
  506.  
  507.     StAutoSizingDialog theHandler(WIND_Resizeable, inPromptText, ioString, inSuper);
  508.     theHandler.SetInitialDialogSize();
  509.     theHandler.SetInitialDialogPosition(inOverWindow);
  510.     LWindow* theDialog = theHandler.GetDialog();
  511.  
  512.     MessageT theMessage = msg_Cancel;
  513.     if (UStdDialogs::TryToInteract())
  514.         {
  515.         LEditField* theResponseEdit = (LEditField*)theDialog->FindPaneByID(PaneID_AlertEditField);
  516.         Assert_(theResponseEdit != NULL);
  517.         theResponseEdit->SetDescriptor(ioString);
  518.         theResponseEdit->SelectAll();
  519.         theResponseEdit->SetMaxChars(maxIOStringSize);
  520.         theHandler.SetLatentSub(theResponseEdit);
  521.  
  522.         theDialog->SetDescriptor(inTitleText);
  523.         theDialog->Show();
  524.         theMessage = theHandler.WaitUserResponse();
  525.  
  526.         if (theMessage == msg_OK)
  527.             theResponseEdit->GetDescriptor(ioString);
  528.         }
  529.     
  530.     return (theMessage == msg_OK);
  531. }
  532.  
  533. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  534. //    Ñ    AskForPassword
  535. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  536.  
  537. Boolean UStdDialogs::AskForPassword(
  538.     const CString&            inPromptText,
  539.     CString&                ioString,
  540.     LWindow*                inOverWindow,
  541.     LCommander*                inSuper)
  542. {
  543.     if (inSuper == NULL)
  544.         inSuper = LCommander::GetTopCommander();
  545.  
  546.     StAutoSizingDialog theHandler(WIND_Resizeable, inPromptText, ioString, inSuper);
  547.     theHandler.SetInitialDialogSize();
  548.     theHandler.SetInitialDialogPosition(inOverWindow);
  549.     LWindow* theDialog = theHandler.GetDialog();
  550.  
  551.     MessageT theMessage = msg_Cancel;
  552.     if (UStdDialogs::TryToInteract())
  553.         {
  554.         LEditField* theResponseEdit = (LEditField*)theDialog->FindPaneByID(PaneID_AlertEditField);
  555.         Assert_(theResponseEdit != NULL);
  556.         theResponseEdit->SetTextTraitsID(cPasswordTextTraitsID);
  557.         theResponseEdit->SetDescriptor(ioString);
  558.         theResponseEdit->SelectAll();
  559.         theDialog->SetLatentSub(theResponseEdit);
  560.         
  561.         theDialog->Show();
  562.         theMessage = theHandler.WaitUserResponse();
  563.  
  564.         if (theMessage == msg_OK)
  565.             theResponseEdit->GetDescriptor(ioString);
  566.         }
  567.     
  568.     return (theMessage == msg_OK);
  569. }
  570.  
  571. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  572. //    Ñ    AskForNameAndPassword
  573. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  574.  
  575. Boolean UStdDialogs::AskForNameAndPassword(
  576.     const CString&        inPromptText,
  577.     CString&            ioNameString,
  578.     CString&            ioPassString,
  579.     LWindow*                    inOverWindow,
  580.     LCommander*                    inSuper)
  581. {
  582.     if (inSuper == NULL)
  583.         inSuper = LCommander::GetTopCommander();
  584.  
  585.     StStdDialogHandler theHandler(WIND_NameAndPassword, inSuper);
  586.     theHandler.SetInitialDialogPosition(inOverWindow);
  587.     LWindow* theDialog = theHandler.GetDialog();
  588.  
  589.     MessageT theMessage = msg_Cancel;
  590.     if (UStdDialogs::TryToInteract())
  591.         {
  592.         LCaption* theMessageCaption = (LCaption*)theDialog->FindPaneByID(PaneID_MessageCaption);
  593.         Assert_(theMessageCaption != NULL);
  594.         theMessageCaption->SetDescriptor(inPromptText);
  595.         
  596.         LEditField* theNameField = (LEditField*)theDialog->FindPaneByID(PaneID_PasswordEditName);
  597.         Assert_(theNameField != NULL);
  598.         theNameField->SetDescriptor(ioNameString);
  599.         
  600.         LEditField* thePassField = (LEditField*)theDialog->FindPaneByID(PaneID_PasswordEditPass);
  601.         Assert_(thePassField != NULL);
  602.         thePassField->SetDescriptor(ioPassString);
  603.         
  604.         if (ioNameString.Length() == 0)
  605.             {
  606.             theDialog->SetLatentSub(theNameField);
  607.             theNameField->SelectAll();
  608.             }
  609.         else
  610.             {
  611.             theDialog->SetLatentSub(thePassField);
  612.             thePassField->SelectAll();
  613.             }
  614.  
  615.         theHandler.SetLatentSub(theNameField);
  616.         
  617.         theDialog->Show();
  618.         theMessage = theHandler.WaitUserResponse();
  619.  
  620.         if (theMessage == msg_OK)
  621.             {
  622.             theNameField->GetDescriptor(ioNameString);
  623.             thePassField->GetDescriptor(ioPassString);
  624.             }
  625.         }
  626.  
  627.     return (theMessage == msg_OK);
  628. }
  629.  
  630. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  631. //    Ñ    TryToInteract
  632. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  633.  
  634. Boolean UStdDialogs::TryToInteract(Int32 inForSeconds)
  635. {
  636.     ProcessSerialNumber theCurrentProcess;
  637.     ::GetCurrentProcess(&theCurrentProcess);
  638.         
  639.     Boolean isInFront = UProcessUtils::IsFrontProcess(theCurrentProcess);
  640.     if (!isInFront)
  641.         {
  642.         LEventDispatcher* theDispatcher = LEventDispatcher::GetCurrentEventDispatcher();
  643.  
  644.         // NOTE:  this attachment is being attached to the current event
  645.         // dispatcher.  Therefore notification will be killed when the app
  646.         // resumes or the dispatcher goes out of scope.  In the case of the
  647.         // UStdDialog alerts, the notification will go away when this routine
  648.         // times out.
  649.  
  650.         CNotificationAttachment* theNote = new CNotificationAttachment;
  651.         theDispatcher->AddAttachment(theNote);
  652.  
  653.         Uint32 theStartTime, theCurrentTime;
  654.         ::GetDateTime(&theStartTime);
  655.         theCurrentTime = theStartTime;
  656.         while (((theCurrentTime - theStartTime) < inForSeconds) && !isInFront)
  657.             {
  658.             EventRecord theEvent;
  659.             ::WaitNextEvent(everyEvent, &theEvent, 10, NULL);
  660.             theDispatcher->DispatchEvent(theEvent);
  661.             ::GetDateTime(&theCurrentTime);
  662.             
  663.             isInFront = UProcessUtils::IsFrontProcess(theCurrentProcess);
  664.             }
  665.         }
  666.         
  667.     return isInFront;
  668. }
  669.  
  670. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  671. //    Ñ DoSaveAsTextOrSource
  672. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  673.  
  674. // NOTE: I don't call ErrorManager::PrepareToInteract which makes sure
  675. // Netscape is frontmost app and uses Notification Mangler if we aren't.
  676.  
  677. OSErr UStdDialogs::AskSaveAsTextOrSource(StandardFileReply& reply,
  678.                                             const CString& initialFilename,
  679.                                             short& format)
  680. {
  681.     Point dlgTopLeft;
  682.     dlgTopLeft.h = dlgTopLeft.v = -1;
  683.     
  684.     if (gSaveAsType != 1 && gSaveAsType != 2)
  685.         gSaveAsType = 1;
  686.     
  687.     DlgHookYDUPP savehook = NewDlgHookYDProc(SaveAsHook);
  688.  
  689.     LStr255 saveAsPromptStr(MACDLG_SAVE_AS, 0);    
  690.     
  691.     UDesktop::Deactivate();
  692.     ::CustomPutFile(saveAsPromptStr,
  693.                     initialFilename,
  694.                     &reply,
  695.                     DLOG_SAVEAS,
  696.                     dlgTopLeft,
  697.                     savehook,
  698.                     NULL,
  699.                     NULL,
  700.                     NULL,
  701.                     NULL);
  702.     UDesktop::Activate();
  703.  
  704. #if GENERATINGCFM
  705.     ::DisposeRoutineDescriptor(savehook);
  706. #endif // GENERATINGCFM
  707.     
  708.     format = gSaveAsType;
  709.     return noErr;    // uhh, why bother returning a value?
  710. }
  711.  
  712.  
  713. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  714. //    Ñ SaveAsHook
  715. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  716.  
  717. pascal short UStdDialogs::SaveAsHook( short item, DialogPtr dialog, void* /*dataPtr*/ )
  718. {
  719.     short                 myType;                //    menu item selected
  720.     Handle                myHandle;            //    needed for GetDialogItem
  721.     Rect                myRect;                //    needed for GetDialogItem
  722.  
  723. #define kFileTypePopup    13
  724.  
  725.     if ( GetWRefCon( (WindowPtr)dialog ) != sfMainDialogRefCon )
  726.         return item;                    // this function is only for main dialog box
  727.  
  728.     if ( item == sfHookFirstCall)
  729.     {
  730.         GetDialogItem( dialog, kFileTypePopup, &myType, &myHandle, &myRect );
  731.         
  732.         if ( myHandle )
  733.             SetControlValue( (ControlHandle)myHandle,  gSaveAsType);
  734.     }
  735.     else
  736.     if ( item == kFileTypePopup )
  737.     {
  738.         GetDialogItem( dialog, kFileTypePopup, &myType, &myHandle, &myRect );
  739.         
  740.         if ( myHandle )
  741.             gSaveAsType = GetControlValue( (ControlHandle)myHandle );
  742.     }
  743.     
  744.     return item;
  745. }
  746.  
  747. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  748. //    Ñ AskSaveAsSource
  749. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  750.  
  751. // NOTE: I don't call ErrorManager::PrepareToInteract which makes sure
  752. // Netscape is frontmost app and uses Notification Mangler if we aren't.
  753.  
  754. OSErr UStdDialogs::AskSaveAsSource(StandardFileReply& reply,
  755.                                             const CString& initialFilename,
  756.                                             short& format)
  757. {
  758.     Point dlgTopLeft;
  759.     dlgTopLeft.h = dlgTopLeft.v = -1;
  760.     
  761.     gSaveAsType = 2;        // Set save as type to source
  762.     
  763.     LStr255 saveAsPromptStr(MACDLG_SAVE_AS, 0);    
  764.     
  765.     UDesktop::Deactivate();
  766.     ::StandardPutFile(saveAsPromptStr,
  767.                 initialFilename,
  768.                 &reply);
  769.     UDesktop::Activate();
  770.  
  771.     format = gSaveAsType;
  772.     return noErr;    // uhh, why bother returning a value?
  773. }
  774.  
  775.  
  776. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  777. //    Ñ AskUploadAsDataOrMacBin
  778. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  779.  
  780. // NOTE: I don't call ErrorManager::PrepareToInteract which makes sure
  781. // Netscape is frontmost app and uses Notification Mangler if we aren't.
  782.  
  783. OSErr UStdDialogs::AskUploadAsDataOrMacBin(StandardFileReply& reply,
  784.                                             short& format)
  785. {
  786.     SFTypeList    typeList;
  787.     Point        dlgTopLeft;
  788.     dlgTopLeft.h = dlgTopLeft.v = -1;
  789.     
  790.     DlgHookYDUPP uploadhook = NewDlgHookYDProc(UploadAsHook);
  791.  
  792.     UDesktop::Deactivate();
  793.     ::CustomGetFile(
  794.                     NULL,
  795.                     -1,
  796.                     typeList,
  797.                     &reply,
  798.                     DLOG_UPLOADAS,
  799.                     dlgTopLeft,
  800.                     uploadhook,
  801.                     NULL,
  802.                     NULL,
  803.                     NULL,
  804.                     NULL);
  805.     UDesktop::Activate();
  806.  
  807. #if GENERATINGCFM
  808.     ::DisposeRoutineDescriptor(uploadhook);
  809. #endif // GENERATINGCFM
  810.     
  811.     format = gUploadAsType;
  812.     return noErr;    // uhh, why bother returning a value?
  813. }
  814.  
  815. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  816. //    Ñ UploadAsHook
  817. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  818.  
  819. pascal short UStdDialogs::UploadAsHook( short item, DialogPtr dialog, void* /*dataPtr*/ )
  820. {
  821.     short                 myType;                //    menu item selected
  822.     Handle                myHandle;            //    needed for GetDialogItem
  823.     Rect                myRect;                //    needed for GetDialogItem
  824.  
  825. #define kUploadTypePopup    10    // WARNING!!!  Due to an embedded help item if you use Resorcerer's
  826.                                 //                option to show dialog item #s this item appears as #9
  827.                                 //                and baaaad things happen if you don't account for the
  828.                                 //                off by 1 numbering.
  829.  
  830.     if ( GetWRefCon( (WindowPtr)dialog ) != sfMainDialogRefCon )
  831.         return item;                    // this function is only for main dialog box
  832.  
  833.     if ( item == sfHookFirstCall)
  834.     {
  835.         GetDialogItem( dialog, kUploadTypePopup, &myType, &myHandle, &myRect );
  836.         
  837.         if ( myHandle )
  838.             SetControlValue( (ControlHandle)myHandle,  gUploadAsType);
  839.     }
  840.     else
  841.     if ( item == kUploadTypePopup )
  842.     {
  843.         GetDialogItem( dialog, kUploadTypePopup, &myType, &myHandle, &myRect );
  844.         
  845.         if ( myHandle )
  846.             gUploadAsType = GetControlValue( (ControlHandle)myHandle );
  847.     }
  848.     
  849.     return item;
  850. }
  851.  
  852.