File:  [mozdev] / chimera / nsAlertController.mm
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Mon Feb 25 03:22:59 2002 UTC (18 years, 3 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Changes to get alerts going and form submission working again.

    1: #import "nsAlertController.h"
    2: #import "nsCocoaBrowserService.h"
    3: 
    4: @implementation nsAlertController
    5: 
    6: - (IBAction)hitButton1:(id)sender
    7: {
    8:   [NSApp stopModalWithCode:1];
    9: }
   10: 
   11: - (IBAction)hitButton2:(id)sender
   12: {
   13:   [NSApp stopModalWithCode:2];
   14: }
   15: 
   16: - (IBAction)hitButton3:(id)sender
   17: {
   18:   [NSApp stopModalWithCode:3];
   19: }
   20: 
   21: 
   22: - (void)awakeFromNib
   23: {
   24:   nsCocoaBrowserService::SetAlertController(self);
   25: }
   26: 
   27: - (void)alert:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
   28: {
   29:   [alertPanelText setStringValue:text];
   30:   [alertPanel setTitle:title];
   31: 
   32:   [NSApp runModalForWindow:alertPanel relativeToWindow:parent];
   33:   
   34:   [alertPanel close];
   35: }
   36: 
   37: - (void)alertCheck:(NSWindow*)parent title:(NSString*)title text:(NSString*)text checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue
   38: {
   39:   [alertCheckPanelText setStringValue:text];
   40:   [alertCheckPanel setTitle:title];
   41:   int state = (*checkValue ? NSOnState : NSOffState);
   42:   [alertCheckPanelCheck setState:state];
   43:   [alertCheckPanelCheck setTitle:checkMsg];
   44: 
   45:   [NSApp runModalForWindow:alertCheckPanel relativeToWindow:parent];
   46: 
   47:   *checkValue = ([alertCheckPanelCheck state] == NSOnState);
   48:   [alertCheckPanel close];
   49: }
   50: 
   51: - (BOOL)confirm:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
   52: {
   53:   [confirmPanelText setStringValue:text];
   54:   [confirmPanel setTitle:title];
   55: 
   56:   int result = [NSApp runModalForWindow:confirmPanel relativeToWindow:parent];
   57:   
   58:   [confirmPanel close];
   59: 
   60:   return (result == 1);
   61: }
   62: 
   63: - (BOOL)confirmCheck:(NSWindow*)parent title:(NSString*)title text:(NSString*)text checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue
   64: {
   65:   [confirmCheckPanelText setStringValue:text];
   66:   [confirmCheckPanel setTitle:title];
   67:   int state = (*checkValue ? NSOnState : NSOffState);
   68:   [confirmCheckPanelCheck setState:state];
   69:   [confirmCheckPanelCheck setTitle:checkMsg];
   70: 
   71:   int result = [NSApp runModalForWindow:confirmCheckPanel relativeToWindow:parent];
   72: 
   73:   *checkValue = ([confirmCheckPanelCheck state] == NSOnState);
   74:   [confirmCheckPanel close];
   75: 
   76:   return (result == 1);
   77: }
   78: 
   79: - (int)confirmEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
   80:    button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3
   81: {
   82:   return 0;
   83: }
   84: 
   85: - (int)confirmCheckEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text 
   86:   button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3
   87:   checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue
   88: {
   89:   return 0;
   90: }
   91: 
   92: - (BOOL)prompt:(NSWindow*)parent title:(NSString*)title text:(NSString*)text promptText:(NSMutableString*)promptText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck
   93: {
   94:   [promptPanelText setStringValue:text];
   95:   [promptPanel setTitle:title];
   96:   if (doCheck) {
   97:     int state = (*checkValue ? NSOnState : NSOffState);
   98:     [promptPanelCheck setState:state];
   99:     [promptPanelCheck setEnabled:YES];
  100:   }
  101:   else {
  102:     [promptPanelCheck setEnabled:NO];
  103:   }  
  104:   [promptPanelCheck setTitle:checkMsg];
  105:   [promptPanelInput setStringValue:promptText];
  106: 
  107:   int result = [NSApp runModalForWindow:promptPanel relativeToWindow:parent];
  108: 
  109:   *checkValue = ([promptPanelCheck state] == NSOnState);
  110: 
  111:   NSString* value = [promptPanelInput stringValue];
  112:   PRUint32 length = [promptText length];
  113:   if (length) {
  114:     NSRange all;
  115:     all.location = 0;
  116:     all.length = [promptText length];
  117:     [promptText deleteCharactersInRange:all];
  118:   }
  119:   [promptText appendString:value];
  120: 
  121:   [promptPanel close];
  122: 
  123:   return (result == 1);	
  124: }
  125: 
  126: - (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
  127: {
  128:   [usernamePanelText setStringValue:text];
  129:   [usernamePanel setTitle:title];
  130:   if (doCheck) {
  131:     int state = (*checkValue ? NSOnState : NSOffState);
  132:     [usernamePanelCheck setState:state];
  133:     [usernamePanelCheck setEnabled:YES];
  134:   }
  135:   else {
  136:     [usernamePanelCheck setEnabled:NO];
  137:   }  
  138:   [usernamePanelCheck setTitle:checkMsg];
  139:   [usernamePanelPassword setStringValue:passwordText];
  140:   [usernamePanelUserName setStringValue:userNameText];
  141: 
  142:   int result = [NSApp runModalForWindow:usernamePanel relativeToWindow:parent];
  143: 
  144:   *checkValue = ([usernamePanelCheck state] == NSOnState);
  145: 
  146:   NSString* value = [usernamePanelUserName stringValue];
  147:   PRUint32 length = [userNameText length];
  148:   if (length) {
  149:     NSRange all;
  150:     all.location = 0;
  151:     all.length = [userNameText length];
  152:     [userNameText deleteCharactersInRange:all];
  153:   }
  154:   [userNameText appendString:value];
  155: 
  156:   value = [usernamePanelPassword stringValue];
  157:   length = [passwordText length];
  158:   if (length) {
  159:     NSRange all;
  160:     all.location = 0;
  161:     all.length = [passwordText length];
  162:     [passwordText deleteCharactersInRange:all];
  163:   }
  164:   [passwordText appendString:value];
  165: 
  166:   [usernamePanel close];
  167: 
  168:   return (result == 1);	
  169: }
  170: 
  171: - (BOOL)promptPassword:(NSWindow*)parent title:(NSString*)title text:(NSString*)text passwordText:(NSMutableString*)passwordText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck
  172: {
  173:   [passwordPanelText setStringValue:text];
  174:   [passwordPanel setTitle:title];
  175:   if (doCheck) {
  176:     int state = (*checkValue ? NSOnState : NSOffState);
  177:     [passwordPanelCheck setState:state];
  178:     [passwordPanelCheck setEnabled:YES];
  179:   }
  180:   else {
  181:     [passwordPanelCheck setEnabled:NO];
  182:   }  
  183:   [passwordPanelCheck setTitle:checkMsg];
  184:   [passwordPanelInput setStringValue:passwordText];
  185: 
  186:   int result = [NSApp runModalForWindow:passwordPanel relativeToWindow:parent];
  187: 
  188:   *checkValue = ([passwordPanelCheck state] == NSOnState);
  189: 
  190:   NSString* value = [passwordPanelInput stringValue];
  191:   PRUint32 length = [passwordText length];
  192:   if (length) {
  193:     NSRange all;
  194:     all.location = 0;
  195:     all.length = [passwordText length];
  196:     [passwordText deleteCharactersInRange:all];
  197:   }
  198:   [passwordText appendString:value];
  199: 
  200:   [passwordPanel close];
  201: 
  202:   return (result == 1);	
  203: }
  204: @end

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