Back to index

lightning-sunbird  0.9+nobinonly
PromptService.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "PromptService.h"
00039 #include "nsCOMPtr.h"
00040 #include "nsIPromptService.h"
00041 #include "nsString.h"
00042 #include "nsReadableUtils.h"
00043 #include "nsIWindowWatcher.h"
00044 #include "nsIServiceManager.h"
00045 #include "nsIWebBrowserChrome.h"
00046 #include "nsIEmbeddingSiteWindow.h"
00047 
00048 // Local Includes
00049 #include "ApplIDs.h"
00050 #include "UMacUnicode.h"
00051 #include "CBrowserChrome.h"
00052 
00053 // PowerPlant
00054 #include <LStaticText.h>
00055 #include <LCheckBox.h>
00056 #include <LEditText.h>
00057 #include <UModalDialogs.h>
00058 #include <LPushButton.h>
00059 
00060 //*****************************************************************************
00061 // CPromptService
00062 //*****************************************************************************   
00063 
00064 NS_IMPL_ISUPPORTS1(CPromptService, nsIPromptService)
00065 
00066 CPromptService::CPromptService()
00067 {
00068 }
00069 
00070 CPromptService::~CPromptService()
00071 {
00072 }
00073 
00074 
00075 NS_IMETHODIMP CPromptService::Alert(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
00076                                     const PRUnichar *text)
00077 {    
00078     StDialogHandler   theHandler(dlog_Alert, CBrowserChrome::GetLWindowForDOMWindow(parent));
00079     LWindow                  *theDialog = theHandler.GetDialog();
00080     nsCAutoString    cStr;
00081     Str255           pStr;
00082 
00083     CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
00084     theDialog->SetDescriptor(pStr);
00085 
00086     LStaticText      *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
00087     CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
00088     cStr.ReplaceChar('\n', '\r');                       
00089     msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
00090 
00091     theDialog->Show();
00092     theDialog->Select();
00093        
00094        while (true)  // This is our modal dialog event loop
00095        {                           
00096               MessageT      hitMessage = theHandler.DoDialog();
00097               
00098               if (hitMessage == msg_OK)
00099               break;
00100        }
00101 
00102     return NS_OK;
00103 }
00104 
00105 NS_IMETHODIMP CPromptService::AlertCheck(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
00106                                          const PRUnichar *text,
00107                                          const PRUnichar *checkMsg, PRBool *checkValue)
00108 {
00109     NS_ENSURE_ARG_POINTER(checkValue);
00110 
00111     StDialogHandler  theHandler(dlog_AlertCheck, CBrowserChrome::GetLWindowForDOMWindow(parent));
00112     LWindow                  *theDialog = theHandler.GetDialog();
00113     nsCAutoString    cStr;
00114     Str255           pStr;
00115 
00116     CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
00117     theDialog->SetDescriptor(pStr);
00118 
00119     LStaticText      *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
00120     CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
00121     cStr.ReplaceChar('\n', '\r');                       
00122     msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
00123     
00124     LCheckBox *checkBox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
00125     CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(checkMsg), pStr);
00126     checkBox->SetDescriptor(pStr);
00127     checkBox->SetValue(*checkValue ? 1 : 0);
00128 
00129     theDialog->Show();
00130     theDialog->Select();
00131        
00132        while (true)  // This is our modal dialog event loop
00133        {                           
00134               MessageT      hitMessage = theHandler.DoDialog();
00135               
00136               if (hitMessage == msg_OK)
00137               {
00138                   *checkValue = checkBox->GetValue();    
00139                   break;
00140               }
00141        }
00142 
00143     return NS_OK;
00144 }
00145 
00146 NS_IMETHODIMP CPromptService::Confirm(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
00147                                       const PRUnichar *text,
00148                                       PRBool *_retval)
00149 {
00150     NS_ENSURE_ARG_POINTER(_retval);
00151     
00152     StDialogHandler  theHandler(dlog_Confirm, CBrowserChrome::GetLWindowForDOMWindow(parent));
00153     LWindow                  *theDialog = theHandler.GetDialog();
00154     nsCAutoString    cStr;
00155     Str255           pStr;
00156     
00157     CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
00158     theDialog->SetDescriptor(pStr);
00159                      
00160     LStaticText      *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
00161     CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
00162     cStr.ReplaceChar('\n', '\r');                       
00163     msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
00164 
00165     theDialog->Show();
00166     theDialog->Select();
00167        
00168        while (true)  // This is our modal dialog event loop
00169        {                           
00170               MessageT      hitMessage = theHandler.DoDialog();
00171               
00172               if (hitMessage == msg_OK)
00173               {
00174                   *_retval = PR_TRUE;    
00175                   break;
00176               }
00177               else if (hitMessage == msg_Cancel)
00178               {
00179                   *_retval = PR_FALSE;
00180                   break;
00181               }
00182        }
00183 
00184     return NS_OK;
00185 }
00186 
00187 NS_IMETHODIMP CPromptService::ConfirmCheck(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
00188                                            const PRUnichar *text,
00189                                            const PRUnichar *checkMsg, PRBool *checkValue,
00190                                            PRBool *_retval)
00191 {
00192     NS_ENSURE_ARG_POINTER(checkValue);
00193     NS_ENSURE_ARG_POINTER(_retval);
00194 
00195     StDialogHandler  theHandler(dlog_ConfirmCheck, CBrowserChrome::GetLWindowForDOMWindow(parent));
00196     LWindow                  *theDialog = theHandler.GetDialog();
00197     nsCAutoString    cStr;
00198     Str255           pStr;
00199 
00200     CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
00201     theDialog->SetDescriptor(pStr);
00202 
00203     LStaticText      *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
00204     CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
00205     cStr.ReplaceChar('\n', '\r');                       
00206     msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
00207     
00208     LCheckBox *checkBox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
00209     CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(checkMsg), pStr);
00210     checkBox->SetDescriptor(pStr);
00211     checkBox->SetValue(*checkValue ? 1 : 0);
00212 
00213     theDialog->Show();
00214     theDialog->Select();
00215        
00216        while (true)  // This is our modal dialog event loop
00217        {                           
00218               MessageT      hitMessage = theHandler.DoDialog();
00219               
00220               if (hitMessage == msg_OK)
00221               {
00222                   *_retval = PR_TRUE;
00223                   *checkValue = checkBox->GetValue();    
00224                   break;
00225               }
00226               else if (hitMessage == msg_Cancel)
00227               {
00228                   *_retval = PR_FALSE;
00229                   break;
00230               }
00231        }
00232 
00233     return NS_OK;
00234 }
00235 
00236 NS_IMETHODIMP CPromptService::ConfirmEx(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
00237                                         const PRUnichar *text,
00238                                         PRUint32 buttonFlags,
00239                                         const PRUnichar *button0Title,
00240                                         const PRUnichar *button1Title,
00241                                         const PRUnichar *button2Title,
00242                                         const PRUnichar *checkMsg, PRBool *checkValue,
00243                                         PRInt32 *buttonPressed)
00244 {
00245     NS_ENSURE_ARG_POINTER(buttonPressed);
00246 
00247     StDialogHandler  theHandler(dlog_ConfirmEx, CBrowserChrome::GetLWindowForDOMWindow(parent));
00248     LWindow                  *theDialog = theHandler.GetDialog();
00249     nsCAutoString   cStr;
00250     Str255          pStr;
00251     SDimension16    oldSize;
00252     SInt16          bestWidth, bestHeight, baselineOffset;
00253 
00254     if (dialogTitle) {
00255         CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
00256         theDialog->SetDescriptor(pStr);
00257     }
00258 
00259     LCheckBox *checkBox = nil;
00260     if (checkMsg && checkValue) {
00261         checkBox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
00262         CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(checkMsg), pStr);
00263         checkBox->SetDescriptor(pStr);
00264         checkBox->SetValue(*checkValue ? 1 : 0);
00265         
00266         // Let the checkbox text first stretch the width of the dialog.
00267         // Do not let it reduce the width.
00268         // For checkboxes, CalcBestControlRect will attempt to keep the text on one line.
00269         if (checkBox->SupportsCalcBestRect()) {
00270             checkBox->GetFrameSize(oldSize);
00271             checkBox->CalcBestControlRect(bestWidth, bestHeight, baselineOffset);
00272             // The view is set up so that this will shift and stretch everything properly.
00273             if (bestWidth > oldSize.width)
00274                 theDialog->ResizeWindowBy(bestWidth - oldSize.width, bestHeight - oldSize.height);
00275         }
00276     }
00277 
00278     LStaticText      *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
00279     CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
00280     cStr.ReplaceChar('\n', '\r');
00281     msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
00282     
00283     // For static text, CalcBestControlRect will stretch vertically
00284     if (msgText->SupportsCalcBestRect()) {
00285         msgText->GetFrameSize(oldSize);
00286         msgText->CalcBestControlRect(bestWidth, bestHeight, baselineOffset);
00287         // The view is set up so that this will shift and stretch everything properly.
00288         // Do not let it reduce the width of the dialog.
00289         SInt16 hDelta = bestWidth - oldSize.width;
00290         if (hDelta < 0)
00291             hDelta = 0;
00292         theDialog->ResizeWindowBy(hDelta, bestHeight - oldSize.height);
00293     }
00294     
00295     const PRUnichar* buttonTitles[3] = { button0Title, button1Title, button2Title };
00296     PaneIDT buttonIDs[3] = { 'Btn0', 'Btn1', 'Btn2' };
00297     SInt16 buttonShift = 0;
00298     
00299     for (int i = 0; i < 3; i++)
00300     {
00301         LPushButton *button = dynamic_cast<LPushButton*>(theDialog->FindPaneByID(buttonIDs[i]));
00302         if (!button)
00303             continue;
00304             
00305         SInt16 strIndex = -1;
00306         Boolean hidden = false;
00307         
00308         switch (buttonFlags & 0x00FF)
00309         {
00310             case 0:
00311                 button->Hide();
00312                 hidden = true;
00313                 break;
00314             case BUTTON_TITLE_OK:
00315                 strIndex = str_OK;
00316                 break;
00317             case BUTTON_TITLE_CANCEL:
00318                 strIndex = str_Cancel;
00319                 break;
00320             case BUTTON_TITLE_YES:
00321                 strIndex = str_Yes;
00322                 break;
00323             case BUTTON_TITLE_NO:
00324                 strIndex = str_No;
00325                 break;
00326             case BUTTON_TITLE_SAVE:
00327                 strIndex = str_Save;
00328                 break;
00329             case BUTTON_TITLE_DONT_SAVE:
00330                 strIndex = str_DontSave;
00331                 break;
00332             case BUTTON_TITLE_REVERT:
00333                 strIndex = str_Revert;
00334                 break;
00335             case BUTTON_TITLE_IS_STRING:
00336                 {
00337                 CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(buttonTitles[i]), pStr);
00338                 button->SetDescriptor(pStr);
00339                 }
00340                 break;
00341         }
00342         if (strIndex != -1) {
00343             LStr255 buttonTitle(STRx_StdButtonTitles, strIndex);
00344             button->SetDescriptor(buttonTitle);
00345         }
00346         if (!hidden) {
00347             if (button->SupportsCalcBestRect()) {
00348                 button->GetFrameSize(oldSize);
00349                 button->CalcBestControlRect(bestWidth, bestHeight, baselineOffset);
00350                 buttonShift += bestWidth - oldSize.width;
00351                 button->MoveBy(-buttonShift, 0, false);
00352                 button->ResizeFrameTo(bestWidth, bestHeight, false);
00353             }
00354         }
00355         buttonFlags >>= 8;
00356     }
00357         
00358     theDialog->Show();
00359     theDialog->Select();
00360        
00361        while (true)  // This is our modal dialog event loop
00362        {                           
00363               MessageT      hitMessage = theHandler.DoDialog();
00364               
00365               if (hitMessage == 'Btn0')
00366               {
00367                   *buttonPressed = 0;
00368                   break;
00369               }
00370               else if (hitMessage == 'Btn1')
00371               {
00372                   *buttonPressed = 1;
00373                   break;
00374               }
00375               else if (hitMessage == 'Btn2')
00376               {
00377                   *buttonPressed = 2;
00378                   break;
00379               }
00380        }
00381 
00382     if (checkBox)
00383         *checkValue = checkBox->GetValue();
00384 
00385     return NS_OK;
00386 }
00387 
00388 NS_IMETHODIMP CPromptService::Prompt(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
00389                                      const PRUnichar *text, PRUnichar **value,
00390                                      const PRUnichar *checkMsg, PRBool *checkValue,
00391                                      PRBool *_retval)
00392 {
00393     NS_ENSURE_ARG_POINTER(_retval);
00394 
00395     nsresult resultErr = NS_OK;
00396 
00397     StDialogHandler  theHandler(dlog_Prompt, CBrowserChrome::GetLWindowForDOMWindow(parent));
00398     LWindow                  *theDialog = theHandler.GetDialog();
00399     LCheckBox        *checkbox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
00400     nsCAutoString   cStr;
00401     Str255          pStr;
00402 
00403     if (dialogTitle) {
00404         CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
00405         theDialog->SetDescriptor(pStr);
00406     }
00407 
00408     LStaticText      *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
00409     CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
00410     cStr.ReplaceChar('\n', '\r');
00411     msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
00412     
00413     LEditText *responseText = dynamic_cast<LEditText*>(theDialog->FindPaneByID('Rslt'));
00414     if (value && *value) {
00415         CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(*value), pStr);
00416         responseText->SetDescriptor(pStr);
00417     }
00418     
00419     if (checkValue) {
00420         checkbox->SetValue(*checkValue);
00421         if (checkMsg) {
00422             CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(checkMsg), pStr);
00423             checkbox->SetDescriptor(pStr);
00424         }
00425     }
00426     else
00427         checkbox->Hide();
00428 
00429     theDialog->SetLatentSub(responseText);    
00430     theDialog->Show();
00431     theDialog->Select();
00432        
00433        while (true)  // This is our modal dialog event loop
00434        {                           
00435               MessageT      hitMessage = theHandler.DoDialog();
00436               
00437               if (hitMessage == msg_OK)
00438               {
00439                   nsAutoString ucStr;
00440 
00441                   *_retval = PR_TRUE;
00442                   if (value && *value) {
00443                       nsMemory::Free(*value);
00444                       *value = nsnull;
00445                   }
00446                   responseText->GetDescriptor(pStr);
00447                   CPlatformUCSConversion::GetInstance()->PlatformToUCS(pStr, ucStr);
00448                   *value = ToNewUnicode(ucStr);    
00449                   if (*value == nsnull)
00450                       resultErr = NS_ERROR_OUT_OF_MEMORY;
00451                       
00452                   if (checkValue)
00453                       *checkValue = checkbox->GetValue();
00454                       
00455                   break;
00456               }
00457               else if (hitMessage == msg_Cancel)
00458               {
00459                   *_retval = PR_FALSE;
00460                   break;
00461               }
00462        }
00463 
00464     return resultErr;
00465 }
00466 
00467 NS_IMETHODIMP CPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
00468                                                         const PRUnichar *text,
00469                                                         PRUnichar **username, PRUnichar **password,
00470                                                         const PRUnichar *checkMsg, PRBool *checkValue,
00471                                                         PRBool *_retval)
00472 {
00473     NS_ENSURE_ARG_POINTER(_retval);
00474 
00475     nsresult resultErr = NS_OK;
00476 
00477     StDialogHandler  theHandler(dlog_PromptNameAndPass, CBrowserChrome::GetLWindowForDOMWindow(parent));
00478     LWindow                  *theDialog = theHandler.GetDialog();
00479     LCheckBox        *checkbox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
00480     nsCAutoString   cStr;
00481     Str255          pStr;
00482 
00483     if (dialogTitle) {
00484         CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
00485         theDialog->SetDescriptor(pStr);
00486     }
00487 
00488     LStaticText      *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
00489     CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
00490     cStr.ReplaceChar('\n', '\r');
00491     msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
00492     
00493     LEditText *userText = dynamic_cast<LEditText*>(theDialog->FindPaneByID('Name'));
00494     if (username && *username) {
00495         CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(*username), pStr);
00496         userText->SetDescriptor(pStr);
00497     }
00498     LEditText *pwdText = dynamic_cast<LEditText*>(theDialog->FindPaneByID('Pass'));
00499     if (password && *password) {
00500         CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(*password), pStr);
00501         pwdText->SetDescriptor(pStr);
00502     }
00503 
00504     if (checkValue) {
00505         checkbox->SetValue(*checkValue);
00506         if (checkMsg) {
00507             CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(checkMsg), pStr);
00508             checkbox->SetDescriptor(pStr);
00509         }
00510     }
00511     else
00512         checkbox->Hide();
00513  
00514     theDialog->SetLatentSub(userText);   
00515     theDialog->Show();
00516     theDialog->Select();
00517        
00518        while (true)  // This is our modal dialog event loop
00519        {                           
00520               MessageT      hitMessage = theHandler.DoDialog();
00521               
00522               if (hitMessage == msg_OK)
00523               {
00524                   nsAutoString    ucStr;
00525                   
00526                   if (username && *username) {
00527                       nsMemory::Free(*username);
00528                       *username = nsnull;
00529                   }
00530                   userText->GetDescriptor(pStr);
00531                   CPlatformUCSConversion::GetInstance()->PlatformToUCS(pStr, ucStr);
00532                   *username = ToNewUnicode(ucStr);
00533                   if (*username == nsnull)
00534                       resultErr = NS_ERROR_OUT_OF_MEMORY;
00535                   
00536                   if (password && *password) {
00537                       nsMemory::Free(*password);
00538                       *password = nsnull;
00539                   }
00540                   pwdText->GetDescriptor(pStr);
00541                   CPlatformUCSConversion::GetInstance()->PlatformToUCS(pStr, ucStr);
00542                   *password = ToNewUnicode(ucStr);
00543                   if (*password == nsnull)
00544                       resultErr = NS_ERROR_OUT_OF_MEMORY;
00545 
00546                   if (checkValue)
00547                       *checkValue = checkbox->GetValue();
00548                   
00549                   *_retval = PR_TRUE;        
00550                   break;
00551               }
00552               else if (hitMessage == msg_Cancel)
00553               {
00554                   *_retval = PR_FALSE;
00555                   break;
00556               }
00557        }
00558 
00559     return resultErr;
00560 }
00561 
00562 NS_IMETHODIMP CPromptService::PromptPassword(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
00563                                              const PRUnichar *text,
00564                                              PRUnichar **password,
00565                                              const PRUnichar *checkMsg, PRBool *checkValue,
00566                                              PRBool *_retval)
00567 {
00568     NS_ENSURE_ARG_POINTER(_retval);
00569     
00570     nsresult resultErr = NS_OK;
00571 
00572     StDialogHandler   theHandler(dlog_PromptPassword, CBrowserChrome::GetLWindowForDOMWindow(parent));
00573     LWindow                  *theDialog = theHandler.GetDialog();
00574     LCheckBox        *checkbox = dynamic_cast<LCheckBox*>(theDialog->FindPaneByID('Chck'));
00575     nsCAutoString    cStr;
00576     Str255           pStr;
00577 
00578     if (dialogTitle) {
00579         CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(dialogTitle), pStr);
00580         theDialog->SetDescriptor(pStr);
00581     }
00582 
00583     LStaticText      *msgText = dynamic_cast<LStaticText*>(theDialog->FindPaneByID('Msg '));
00584     CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(text), cStr);
00585     cStr.ReplaceChar('\n', '\r');
00586     msgText->SetText(const_cast<char *>(cStr.get()), cStr.Length());
00587     
00588     LEditText *pwdText = dynamic_cast<LEditText*>(theDialog->FindPaneByID('Pass'));
00589     if (password && *password) {
00590         CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(*password), pStr);
00591         pwdText->SetDescriptor(pStr);
00592     }
00593     
00594     if (checkValue) {
00595         checkbox->SetValue(*checkValue);
00596         if (checkMsg) {
00597             CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsDependentString(checkMsg), pStr);
00598             checkbox->SetDescriptor(pStr);
00599         }
00600     }
00601     else
00602         checkbox->Hide();
00603  
00604     theDialog->SetLatentSub(pwdText);   
00605     theDialog->Show();
00606     theDialog->Select();
00607        
00608        while (true)  // This is our modal dialog event loop
00609        {                           
00610               MessageT      hitMessage = theHandler.DoDialog();
00611               
00612               if (hitMessage == msg_OK)
00613               {
00614                   nsAutoString    ucStr;
00615                                 
00616                   if (password && *password) {
00617                       nsMemory::Free(*password);
00618                       *password = nsnull;
00619                   }
00620                   pwdText->GetDescriptor(pStr);
00621                   CPlatformUCSConversion::GetInstance()->PlatformToUCS(pStr, ucStr);
00622                   *password = ToNewUnicode(ucStr);
00623                   if (*password == nsnull)
00624                       resultErr = NS_ERROR_OUT_OF_MEMORY;
00625 
00626                   if (checkValue)
00627                       *checkValue = checkbox->GetValue();
00628 
00629                   *_retval = PR_TRUE;        
00630                   break;
00631               }
00632               else if (hitMessage == msg_Cancel)
00633               {
00634                   *_retval = PR_FALSE;
00635                   break;
00636               }
00637        }
00638 
00639     return resultErr;
00640 }
00641 
00642 NS_IMETHODIMP CPromptService::Select(nsIDOMWindow *parent, const PRUnichar *dialogTitle,
00643                                      const PRUnichar *text, PRUint32 count,
00644                                      const PRUnichar **selectList, PRInt32 *outSelection,
00645                                      PRBool *_retval)
00646 {
00647     return NS_ERROR_NOT_IMPLEMENTED;
00648 }