@@ -117,22 +117,65 @@ static void dopopupanswerdialog_prewait(void *p_context)
117117 t_title = [NSString stringWithCString: ctxt -> title == nil ? " " : ctxt -> title encoding: NSMacOSRomanStringEncoding];
118118 NSString *t_prompt;
119119 t_prompt = [NSString stringWithCString: ctxt -> message == nil ? " " : ctxt -> message encoding: NSMacOSRomanStringEncoding];
120-
121- ctxt -> delegate = [[ModalDelegate alloc ] init ];
122- ctxt -> alert_view = [[UIAlertView alloc ] initWithTitle: t_title message: t_prompt delegate: ctxt -> delegate cancelButtonTitle: nil otherButtonTitles: nil ];
123-
124- if (ctxt -> button_count == 0 )
125- {
126- [ctxt -> delegate setIndex: 0 ];
127- [ctxt -> alert_view addButtonWithTitle: @" OK" ];
128- }
129- else
130- {
131- [ctxt -> delegate setIndex: ctxt -> button_count - 1 ];
132- for (uint32_t i = 0 ; i < ctxt -> button_count; i++)
133- [ctxt -> alert_view addButtonWithTitle: [ NSString stringWithCString: ctxt -> buttons[i] encoding: NSMacOSRomanStringEncoding ]];
134- }
135- [ctxt -> alert_view show ];
120+
121+ if (MCmajorosversion < 800 )
122+ {
123+ ctxt -> delegate = [[ModalDelegate alloc ] init ];
124+ ctxt -> alert_view = [[UIAlertView alloc ] initWithTitle: t_title message: t_prompt delegate: ctxt -> delegate cancelButtonTitle: nil otherButtonTitles: nil ];
125+
126+ if (ctxt -> button_count == 0 )
127+ {
128+ [ctxt -> delegate setIndex: 0 ];
129+ [ctxt -> alert_view addButtonWithTitle: @" OK" ];
130+ }
131+ else
132+ {
133+ [ctxt -> delegate setIndex: ctxt -> button_count - 1 ];
134+ for (uint32_t i = 0 ; i < ctxt -> button_count; i++)
135+ [ctxt -> alert_view addButtonWithTitle: [ NSString stringWithCString: ctxt -> buttons[i] encoding: NSMacOSRomanStringEncoding ]];
136+ }
137+ [ctxt -> alert_view show ];
138+ }
139+ else
140+ {
141+ #ifdef __IPHONE_8_0
142+ // MM-2014-10-13: [[ Bug 13656 ]] Use new UIAlertController for iOS 8. Solves rotation issues.
143+ UIAlertController *t_alert_controller;
144+ t_alert_controller = [UIAlertController alertControllerWithTitle: t_title
145+ message: t_prompt
146+ preferredStyle: UIAlertControllerStyleAlert];
147+
148+ if (ctxt -> button_count == 0 )
149+ {
150+ UIAlertAction *t_action;
151+ t_action = [UIAlertAction actionWithTitle: @" OK"
152+ style: UIAlertActionStyleDefault
153+ handler: ^(UIAlertAction *action)
154+ {
155+ ctxt -> result = 0 ;
156+ s_in_modal = false ;
157+ }];
158+ [t_alert_controller addAction: t_action];
159+ }
160+ else
161+ {
162+ for (uint32_t i = 0 ; i < ctxt -> button_count; i++)
163+ {
164+ UIAlertAction *t_action;
165+ t_action = [UIAlertAction actionWithTitle: [NSString stringWithCString: ctxt -> buttons[i] encoding: NSMacOSRomanStringEncoding]
166+ style: UIAlertActionStyleDefault
167+ handler: ^(UIAlertAction *action)
168+ {
169+ ctxt -> result = i;
170+ s_in_modal = false ;
171+ }];
172+ [t_alert_controller addAction: t_action];
173+ }
174+ }
175+
176+ [MCIPhoneGetViewController () presentViewController: t_alert_controller animated: YES completion: nil ];
177+ #endif
178+ }
136179
137180}
138181
@@ -141,11 +184,14 @@ static void dopopupanswerdialog_postwait(void *p_context)
141184 popupanswerdialog_t *ctxt;
142185 ctxt = (popupanswerdialog_t *)p_context;
143186
144- int32_t t_result;
145- ctxt -> result = [ctxt -> delegate index ];
146-
147- [ctxt -> delegate release ];
148- [ctxt -> alert_view release ];
187+ if (MCmajorosversion < 800 )
188+ {
189+ int32_t t_result;
190+ ctxt -> result = [ctxt -> delegate index ];
191+
192+ [ctxt -> delegate release ];
193+ [ctxt -> alert_view release ];
194+ }
149195}
150196
151197int32_t MCScreenDC::popupanswerdialog (const char *p_buttons[], uint32_t p_button_count, uint32_t p_type, const char *p_title, const char *p_message)
@@ -381,60 +427,122 @@ static void dopopupaskdialog_prewait(void *p_context)
381427 NSString *t_initial;
382428 t_initial = [NSString stringWithCString: (ctxt -> initial == nil ? " " : ctxt -> initial) encoding: NSMacOSRomanStringEncoding];
383429
384- ctxt -> delegate = [[ModalDelegate alloc ] init ];
385-
386- UITextField *t_text_field;
387- UIAlertView *t_alert;
388- if (MCmajorosversion < 500 )
389- {
390- ctxt-> alert = [[TextAlertView alloc ] initWithTitle: t_title
391- message: t_message
392- delegate: ctxt -> delegate
393- type: ctxt -> type
394- cancelButtonTitle: @" Cancel"
395- otherButtonTitles: @" OK" , nil ];
396-
397- t_text_field = [ctxt -> alert textField ];
398- t_alert = ctxt -> alert;
399- }
400- else
401- {
402- #ifdef __IPHONE_5_0
403- ctxt -> alert_view = [[UIAlertView alloc ] initWithTitle: t_title
404- message: t_message
405- delegate: ctxt -> delegate
406- cancelButtonTitle: nil
407- otherButtonTitles: nil ];
408- if (ctxt -> type == AT_PASSWORD)
409- [ctxt -> alert_view setAlertViewStyle: UIAlertViewStyleSecureTextInput];
430+ if (MCmajorosversion < 800 )
431+ {
432+ ctxt -> delegate = [[ModalDelegate alloc ] init ];
433+
434+ UITextField *t_text_field;
435+ UIAlertView *t_alert;
436+ if (MCmajorosversion < 500 )
437+ {
438+ ctxt-> alert = [[TextAlertView alloc ] initWithTitle: t_title
439+ message: t_message
440+ delegate: ctxt -> delegate
441+ type: ctxt -> type
442+ cancelButtonTitle: @" Cancel"
443+ otherButtonTitles: @" OK" , nil ];
444+
445+ t_text_field = [ctxt -> alert textField ];
446+ t_alert = ctxt -> alert;
447+ }
410448 else
411- [ctxt -> alert_view setAlertViewStyle: UIAlertViewStylePlainTextInput];
412- [ctxt -> alert_view addButtonWithTitle: @" Cancel" ];
413- [ctxt -> alert_view addButtonWithTitle: @" OK" ];
449+ {
450+ #ifdef __IPHONE_5_0
451+ ctxt -> alert_view = [[UIAlertView alloc ] initWithTitle: t_title
452+ message: t_message
453+ delegate: ctxt -> delegate
454+ cancelButtonTitle: nil
455+ otherButtonTitles: nil ];
456+ if (ctxt -> type == AT_PASSWORD)
457+ [ctxt -> alert_view setAlertViewStyle: UIAlertViewStyleSecureTextInput];
458+ else
459+ [ctxt -> alert_view setAlertViewStyle: UIAlertViewStylePlainTextInput];
460+ [ctxt -> alert_view addButtonWithTitle: @" Cancel" ];
461+ [ctxt -> alert_view addButtonWithTitle: @" OK" ];
462+
463+ ctxt -> text_field = [ctxt -> alert_view textFieldAtIndex: 0 ];
464+
465+ t_text_field = ctxt -> text_field;
466+ t_alert = ctxt -> alert_view;
467+ #endif
468+ }
414469
415- ctxt -> text_field = [ctxt -> alert_view textFieldAtIndex: 0 ];
416-
417- t_text_field = ctxt -> text_field;
418- t_alert = ctxt -> alert_view;
419- #endif
420- }
421-
422- // MW-2012-10-12: [[ Bug 10175 ]] Refactored textField manipulations.
423- if (t_text_field != nil )
424- {
425- [ctxt -> delegate setView: t_alert];
426-
427- [t_text_field setAutocorrectionType: UITextAutocorrectionTypeNo];
428- [t_text_field setKeyboardType: MCIPhoneGetKeyboardType ()];
429- // MW-2012-10-12: [[ Bug 10377 ]] If we want a hint, set placeholder not text.
430- if (ctxt -> hint)
431- [t_text_field setPlaceholder: t_initial];
432- else
433- [t_text_field setText: t_initial];
434- [t_text_field setDelegate: ctxt -> delegate];
435- }
436-
437- [t_alert show ];
470+ // MW-2012-10-12: [[ Bug 10175 ]] Refactored textField manipulations.
471+ if (t_text_field != nil )
472+ {
473+ [ctxt -> delegate setView: t_alert];
474+
475+ [t_text_field setAutocorrectionType: UITextAutocorrectionTypeNo];
476+ [t_text_field setKeyboardType: MCIPhoneGetKeyboardType ()];
477+ // MW-2012-10-12: [[ Bug 10377 ]] If we want a hint, set placeholder not text.
478+ if (ctxt -> hint)
479+ [t_text_field setPlaceholder: t_initial];
480+ else
481+ [t_text_field setText: t_initial];
482+ [t_text_field setDelegate: ctxt -> delegate];
483+ }
484+
485+ [t_alert show ];
486+ }
487+ else
488+ {
489+ #ifdef __IPHONE_8_0
490+ // MM-2014-10-13: [[ Bug 13656 ]] Use new UIAlertController for iOS 8. Solves rotation issues.
491+ UIAlertController *t_alert_controller;
492+ t_alert_controller = [UIAlertController alertControllerWithTitle: t_title
493+ message: t_message
494+ preferredStyle: UIAlertControllerStyleAlert];
495+
496+ [t_alert_controller addTextFieldWithConfigurationHandler: ^(UITextField *p_text_field)
497+ {
498+ [p_text_field setAlpha: 0.75 ];
499+ // [p_text_field setBorderStyle: UITextBorderStyleBezel];
500+ [p_text_field setBackgroundColor: [UIColor whiteColor ]];
501+
502+ if (ctxt -> type == AT_PASSWORD)
503+ [p_text_field setSecureTextEntry: YES ];
504+ else
505+ [p_text_field setSecureTextEntry: NO ];
506+
507+ [p_text_field setAutocorrectionType: UITextAutocorrectionTypeNo];
508+ [p_text_field setKeyboardType: MCIPhoneGetKeyboardType ()];
509+ if (ctxt -> hint)
510+ [p_text_field setPlaceholder: t_initial];
511+ else
512+ [p_text_field setText: t_initial];
513+ }];
514+
515+ UIAlertAction *t_cancel_action;
516+ t_cancel_action = [UIAlertAction actionWithTitle: @" Cancel"
517+ style: UIAlertActionStyleCancel
518+ handler: ^(UIAlertAction *action)
519+ {
520+ s_in_modal = false ;
521+ ctxt -> result = nil ;
522+ }];
523+ [t_alert_controller addAction: t_cancel_action];
524+
525+ UIAlertAction *t_ok_action;
526+ t_ok_action = [UIAlertAction actionWithTitle: @" OK"
527+ style: UIAlertActionStyleDefault
528+ handler: ^(UIAlertAction *action)
529+ {
530+ s_in_modal = false ;
531+
532+ UITextField *t_text_field;
533+ t_text_field = [[t_alert_controller textFields ] firstObject ];
534+
535+ const char *t_message_text;
536+ t_message_text = [[t_text_field text ] cStringUsingEncoding: NSMacOSRomanStringEncoding];
537+
538+ MCMemoryAllocate (MCCStringLength (t_message_text) + 1 , ctxt -> result);
539+ MCCStringClone (t_message_text, ctxt -> result);
540+ }];
541+ [t_alert_controller addAction: t_ok_action];
542+
543+ [MCIPhoneGetViewController () presentViewController: t_alert_controller animated: YES completion: nil ];
544+ #endif
545+ }
438546}
439547
440548static void dopopupaskdialog_postwait (void *p_context)
@@ -459,7 +567,7 @@ static void dopopupaskdialog_postwait(void *p_context)
459567
460568 [ctxt -> alert release ];
461569 }
462- else
570+ else if (MCmajorosversion < 800 )
463571 {
464572#ifdef __IPHONE_5_0
465573 const char * t_message_text;
0 commit comments