Annotation of chimera/nsAlertController.mm, revision 1.4

1.3       hyatt       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:  
1.1       hyatt      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: 
1.2       hyatt     116: - (int)confirmEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
                    117:    button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3
                    118: {
1.4     ! hyatt     119:   printf("ConfirmEx invoked, and this is not yet implemented!\n");
1.2       hyatt     120:   return 0;
                    121: }
                    122: 
                    123: - (int)confirmCheckEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text 
                    124:   button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3
                    125:   checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue
                    126: {
1.4     ! hyatt     127:   printf("ConfirmCheckEx invoked, and this is not yet implemented!\n");
1.2       hyatt     128:   return 0;
                    129: }
                    130: 
1.1       hyatt     131: - (BOOL)prompt:(NSWindow*)parent title:(NSString*)title text:(NSString*)text promptText:(NSMutableString*)promptText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck
                    132: {
                    133:   [promptPanelText setStringValue:text];
                    134:   [promptPanel setTitle:title];
                    135:   if (doCheck) {
                    136:     int state = (*checkValue ? NSOnState : NSOffState);
                    137:     [promptPanelCheck setState:state];
                    138:     [promptPanelCheck setEnabled:YES];
                    139:   }
                    140:   else {
                    141:     [promptPanelCheck setEnabled:NO];
                    142:   }  
                    143:   [promptPanelCheck setTitle:checkMsg];
                    144:   [promptPanelInput setStringValue:promptText];
                    145: 
                    146:   int result = [NSApp runModalForWindow:promptPanel relativeToWindow:parent];
                    147: 
                    148:   *checkValue = ([promptPanelCheck state] == NSOnState);
                    149: 
                    150:   NSString* value = [promptPanelInput stringValue];
                    151:   PRUint32 length = [promptText length];
                    152:   if (length) {
                    153:     NSRange all;
                    154:     all.location = 0;
                    155:     all.length = [promptText length];
                    156:     [promptText deleteCharactersInRange:all];
                    157:   }
                    158:   [promptText appendString:value];
                    159: 
                    160:   [promptPanel close];
                    161: 
                    162:   return (result == 1);  
                    163: }
                    164: 
                    165: - (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
                    166: {
                    167:   [usernamePanelText setStringValue:text];
                    168:   [usernamePanel setTitle:title];
                    169:   if (doCheck) {
                    170:     int state = (*checkValue ? NSOnState : NSOffState);
                    171:     [usernamePanelCheck setState:state];
                    172:     [usernamePanelCheck setEnabled:YES];
                    173:   }
                    174:   else {
                    175:     [usernamePanelCheck setEnabled:NO];
                    176:   }  
                    177:   [usernamePanelCheck setTitle:checkMsg];
                    178:   [usernamePanelPassword setStringValue:passwordText];
                    179:   [usernamePanelUserName setStringValue:userNameText];
                    180: 
                    181:   int result = [NSApp runModalForWindow:usernamePanel relativeToWindow:parent];
                    182: 
                    183:   *checkValue = ([usernamePanelCheck state] == NSOnState);
                    184: 
                    185:   NSString* value = [usernamePanelUserName stringValue];
                    186:   PRUint32 length = [userNameText length];
                    187:   if (length) {
                    188:     NSRange all;
                    189:     all.location = 0;
                    190:     all.length = [userNameText length];
                    191:     [userNameText deleteCharactersInRange:all];
                    192:   }
                    193:   [userNameText appendString:value];
                    194: 
                    195:   value = [usernamePanelPassword stringValue];
                    196:   length = [passwordText length];
                    197:   if (length) {
                    198:     NSRange all;
                    199:     all.location = 0;
                    200:     all.length = [passwordText length];
                    201:     [passwordText deleteCharactersInRange:all];
                    202:   }
                    203:   [passwordText appendString:value];
                    204: 
                    205:   [usernamePanel close];
                    206: 
                    207:   return (result == 1);  
                    208: }
                    209: 
                    210: - (BOOL)promptPassword:(NSWindow*)parent title:(NSString*)title text:(NSString*)text passwordText:(NSMutableString*)passwordText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck
                    211: {
                    212:   [passwordPanelText setStringValue:text];
                    213:   [passwordPanel setTitle:title];
                    214:   if (doCheck) {
                    215:     int state = (*checkValue ? NSOnState : NSOffState);
                    216:     [passwordPanelCheck setState:state];
                    217:     [passwordPanelCheck setEnabled:YES];
                    218:   }
                    219:   else {
                    220:     [passwordPanelCheck setEnabled:NO];
                    221:   }  
                    222:   [passwordPanelCheck setTitle:checkMsg];
                    223:   [passwordPanelInput setStringValue:passwordText];
                    224: 
                    225:   int result = [NSApp runModalForWindow:passwordPanel relativeToWindow:parent];
                    226: 
                    227:   *checkValue = ([passwordPanelCheck state] == NSOnState);
                    228: 
                    229:   NSString* value = [passwordPanelInput stringValue];
                    230:   PRUint32 length = [passwordText length];
                    231:   if (length) {
                    232:     NSRange all;
                    233:     all.location = 0;
                    234:     all.length = [passwordText length];
                    235:     [passwordText deleteCharactersInRange:all];
                    236:   }
                    237:   [passwordText appendString:value];
                    238: 
                    239:   [passwordPanel close];
                    240: 
                    241:   return (result == 1);  
                    242: }
                    243: @end

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