File:  [mozdev] / chimera / nsAlertController.mm
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Thu Mar 7 18:42:43 2002 UTC (18 years, 3 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Add the tri-license to all files.

    1: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
    2: /* ***** BEGIN LICENSE BLOCK *****
    3:  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
    4:  *
    5:  * The contents of this file are subject to the Netscape Public License
    6:  * Version 1.1 (the "License"); you may not use this file except in
    7:  * compliance with the License. You may obtain a copy of the License at
    8:  * http://www.mozilla.org/NPL/
    9:  *
   10:  * Software distributed under the License is distributed on an "AS IS" basis,
   11:  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
   12:  * for the specific language governing rights and limitations under the
   13:  * License.
   14:  *
   15:  * The Original Code is mozilla.org code.
   16:  *
   17:  * The Initial Developer of the Original Code is 
   18:  * Netscape Communications Corporation.
   19:  * Portions created by the Initial Developer are Copyright (C) 2002
   20:  * the Initial Developer. All Rights Reserved.
   21:  *
   22:  * Contributor(s):
   23:  *
   24:  * Alternatively, the contents of this file may be used under the terms of
   25:  * either the GNU General Public License Version 2 or later (the "GPL"), or 
   26:  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
   27:  * in which case the provisions of the GPL or the LGPL are applicable instead
   28:  * of those above. If you wish to allow use of your version of this file only
   29:  * under the terms of either the GPL or the LGPL, and not to allow others to
   30:  * use your version of this file under the terms of the NPL, indicate your
   31:  * decision by deleting the provisions above and replace them with the notice
   32:  * and other provisions required by the GPL or the LGPL. If you do not delete
   33:  * the provisions above, a recipient may use your version of this file under
   34:  * the terms of any one of the NPL, the GPL or the LGPL.
   35:  *
   36:  * ***** END LICENSE BLOCK ***** */
   37:  
   38: #import "nsAlertController.h"
   39: #import "nsCocoaBrowserService.h"
   40: 
   41: @implementation nsAlertController
   42: 
   43: - (IBAction)hitButton1:(id)sender
   44: {
   45:   [NSApp stopModalWithCode:1];
   46: }
   47: 
   48: - (IBAction)hitButton2:(id)sender
   49: {
   50:   [NSApp stopModalWithCode:2];
   51: }
   52: 
   53: - (IBAction)hitButton3:(id)sender
   54: {
   55:   [NSApp stopModalWithCode:3];
   56: }
   57: 
   58: 
   59: - (void)awakeFromNib
   60: {
   61:   nsCocoaBrowserService::SetAlertController(self);
   62: }
   63: 
   64: - (void)alert:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
   65: {
   66:   [alertPanelText setStringValue:text];
   67:   [alertPanel setTitle:title];
   68: 
   69:   [NSApp runModalForWindow:alertPanel relativeToWindow:parent];
   70:   
   71:   [alertPanel close];
   72: }
   73: 
   74: - (void)alertCheck:(NSWindow*)parent title:(NSString*)title text:(NSString*)text checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue
   75: {
   76:   [alertCheckPanelText setStringValue:text];
   77:   [alertCheckPanel setTitle:title];
   78:   int state = (*checkValue ? NSOnState : NSOffState);
   79:   [alertCheckPanelCheck setState:state];
   80:   [alertCheckPanelCheck setTitle:checkMsg];
   81: 
   82:   [NSApp runModalForWindow:alertCheckPanel relativeToWindow:parent];
   83: 
   84:   *checkValue = ([alertCheckPanelCheck state] == NSOnState);
   85:   [alertCheckPanel close];
   86: }
   87: 
   88: - (BOOL)confirm:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
   89: {
   90:   [confirmPanelText setStringValue:text];
   91:   [confirmPanel setTitle:title];
   92: 
   93:   int result = [NSApp runModalForWindow:confirmPanel relativeToWindow:parent];
   94:   
   95:   [confirmPanel close];
   96: 
   97:   return (result == 1);
   98: }
   99: 
  100: - (BOOL)confirmCheck:(NSWindow*)parent title:(NSString*)title text:(NSString*)text checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue
  101: {
  102:   [confirmCheckPanelText setStringValue:text];
  103:   [confirmCheckPanel setTitle:title];
  104:   int state = (*checkValue ? NSOnState : NSOffState);
  105:   [confirmCheckPanelCheck setState:state];
  106:   [confirmCheckPanelCheck setTitle:checkMsg];
  107: 
  108:   int result = [NSApp runModalForWindow:confirmCheckPanel relativeToWindow:parent];
  109: 
  110:   *checkValue = ([confirmCheckPanelCheck state] == NSOnState);
  111:   [confirmCheckPanel close];
  112: 
  113:   return (result == 1);
  114: }
  115: 
  116: - (int)confirmEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
  117:    button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3
  118: {
  119:   return 0;
  120: }
  121: 
  122: - (int)confirmCheckEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text 
  123:   button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3
  124:   checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue
  125: {
  126:   return 0;
  127: }
  128: 
  129: - (BOOL)prompt:(NSWindow*)parent title:(NSString*)title text:(NSString*)text promptText:(NSMutableString*)promptText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck
  130: {
  131:   [promptPanelText setStringValue:text];
  132:   [promptPanel setTitle:title];
  133:   if (doCheck) {
  134:     int state = (*checkValue ? NSOnState : NSOffState);
  135:     [promptPanelCheck setState:state];
  136:     [promptPanelCheck setEnabled:YES];
  137:   }
  138:   else {
  139:     [promptPanelCheck setEnabled:NO];
  140:   }  
  141:   [promptPanelCheck setTitle:checkMsg];
  142:   [promptPanelInput setStringValue:promptText];
  143: 
  144:   int result = [NSApp runModalForWindow:promptPanel relativeToWindow:parent];
  145: 
  146:   *checkValue = ([promptPanelCheck state] == NSOnState);
  147: 
  148:   NSString* value = [promptPanelInput stringValue];
  149:   PRUint32 length = [promptText length];
  150:   if (length) {
  151:     NSRange all;
  152:     all.location = 0;
  153:     all.length = [promptText length];
  154:     [promptText deleteCharactersInRange:all];
  155:   }
  156:   [promptText appendString:value];
  157: 
  158:   [promptPanel close];
  159: 
  160:   return (result == 1);	
  161: }
  162: 
  163: - (BOOL)promptUserNameAndPassword:(NSWindow*)parent title:(NSString*)title text:(NSString*)text userNameText:(NSMutableString*)userNameText passwordText:(NSMutableString*)passwordText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck
  164: {
  165:   [usernamePanelText setStringValue:text];
  166:   [usernamePanel setTitle:title];
  167:   if (doCheck) {
  168:     int state = (*checkValue ? NSOnState : NSOffState);
  169:     [usernamePanelCheck setState:state];
  170:     [usernamePanelCheck setEnabled:YES];
  171:   }
  172:   else {
  173:     [usernamePanelCheck setEnabled:NO];
  174:   }  
  175:   [usernamePanelCheck setTitle:checkMsg];
  176:   [usernamePanelPassword setStringValue:passwordText];
  177:   [usernamePanelUserName setStringValue:userNameText];
  178: 
  179:   int result = [NSApp runModalForWindow:usernamePanel relativeToWindow:parent];
  180: 
  181:   *checkValue = ([usernamePanelCheck state] == NSOnState);
  182: 
  183:   NSString* value = [usernamePanelUserName stringValue];
  184:   PRUint32 length = [userNameText length];
  185:   if (length) {
  186:     NSRange all;
  187:     all.location = 0;
  188:     all.length = [userNameText length];
  189:     [userNameText deleteCharactersInRange:all];
  190:   }
  191:   [userNameText appendString:value];
  192: 
  193:   value = [usernamePanelPassword stringValue];
  194:   length = [passwordText length];
  195:   if (length) {
  196:     NSRange all;
  197:     all.location = 0;
  198:     all.length = [passwordText length];
  199:     [passwordText deleteCharactersInRange:all];
  200:   }
  201:   [passwordText appendString:value];
  202: 
  203:   [usernamePanel close];
  204: 
  205:   return (result == 1);	
  206: }
  207: 
  208: - (BOOL)promptPassword:(NSWindow*)parent title:(NSString*)title text:(NSString*)text passwordText:(NSMutableString*)passwordText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck
  209: {
  210:   [passwordPanelText setStringValue:text];
  211:   [passwordPanel setTitle:title];
  212:   if (doCheck) {
  213:     int state = (*checkValue ? NSOnState : NSOffState);
  214:     [passwordPanelCheck setState:state];
  215:     [passwordPanelCheck setEnabled:YES];
  216:   }
  217:   else {
  218:     [passwordPanelCheck setEnabled:NO];
  219:   }  
  220:   [passwordPanelCheck setTitle:checkMsg];
  221:   [passwordPanelInput setStringValue:passwordText];
  222: 
  223:   int result = [NSApp runModalForWindow:passwordPanel relativeToWindow:parent];
  224: 
  225:   *checkValue = ([passwordPanelCheck state] == NSOnState);
  226: 
  227:   NSString* value = [passwordPanelInput stringValue];
  228:   PRUint32 length = [passwordText length];
  229:   if (length) {
  230:     NSRange all;
  231:     all.location = 0;
  232:     all.length = [passwordText length];
  233:     [passwordText deleteCharactersInRange:all];
  234:   }
  235:   [passwordText appendString:value];
  236: 
  237:   [passwordPanel close];
  238: 
  239:   return (result == 1);	
  240: }
  241: @end

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>