@@ -512,221 +512,6 @@ - (void)updateInertia
512512 return [UIDevice currentDevice ].userInterfaceIdiom == UIUserInterfaceIdiomPad;
513513}
514514
515- void OSUtils::showMobileChoiceMenu (juce::ComponentPeer* peer, juce::StringArray options, std::function<void (int )> callback)
516- {
517- auto * view = (UIView*) peer->getNativeHandle ();
518- if (view == nil )
519- return ;
520-
521- // Find the parent view controller
522- UIViewController* viewController = nil ;
523- UIResponder* responder = view;
524- while (responder != nil )
525- {
526- if ([responder isKindOfClass: [UIViewController class ]])
527- {
528- viewController = (UIViewController*) responder;
529- break ;
530- }
531- responder = [responder nextResponder ];
532- }
533-
534- if (viewController == nil )
535- return ;
536-
537- UIAlertController* alertController =
538- [UIAlertController alertControllerWithTitle: nil
539- message: nil
540- preferredStyle: UIAlertControllerStyleActionSheet];
541-
542- // Add option actions
543- for (int i = 0 ; i < options.size (); ++i)
544- {
545- NSString * option = [[NSString alloc ] initWithUTF8String: options[i].toRawUTF8 ()];
546- UIAlertAction* action = [UIAlertAction actionWithTitle: option
547- style: UIAlertActionStyleDefault
548- handler: ^(UIAlertAction*)
549- {
550- callback (i);
551- }];
552-
553- [alertController addAction: action];
554- }
555-
556- // Cancel button
557- UIAlertAction* cancel = [UIAlertAction actionWithTitle: @" Cancel"
558- style: UIAlertActionStyleCancel
559- handler: ^(UIAlertAction*)
560- {
561- callback (-1 );
562- }];
563-
564- [alertController addAction: cancel];
565-
566- if (isIPad ())
567- {
568- alertController.preferredContentSize = view.frame .size ;
569-
570- if (auto * popoverController = alertController.popoverPresentationController )
571- {
572- popoverController.sourceView = view;
573- popoverController.sourceRect = CGRectMake (35 .0f , 1 .0f , 50 .0f , 50 .0f );
574- popoverController.canOverlapSourceViewRect = YES ;
575- }
576- }
577-
578-
579- // Present the alert controller using the found view controller
580- [viewController presentViewController: alertController animated: YES completion: nil ];
581- }
582-
583- void OSUtils::showMobileMainMenu (juce::ComponentPeer* peer, std::function<void (int )> callback)
584- {
585- auto * view = (UIView<CALayerDelegate>*)peer->getNativeHandle ();
586-
587- // Find the parent view controller
588- UIViewController *viewController = nil ;
589- UIResponder *responder = view;
590- while (responder) {
591- if ([responder isKindOfClass: [UIViewController class ]]) {
592- viewController = (UIViewController *)responder;
593- break ;
594- }
595- responder = [responder nextResponder ];
596- }
597-
598- if (viewController) {
599- // Create an alert controller
600- UIAlertController *alertController = [UIAlertController alertControllerWithTitle: @" Main Menu"
601- message: nil
602- preferredStyle: UIAlertControllerStyleActionSheet];
603-
604- UIAlertAction *themeAction = [UIAlertAction actionWithTitle: @" Select Theme..."
605- style: UIAlertActionStyleDefault
606- handler: ^(UIAlertAction * _Nonnull action) {
607- // Create a second UIAlertController for the submenu
608- UIAlertController *submenu = [UIAlertController alertControllerWithTitle: @" Themes"
609- message: nil
610- preferredStyle: UIAlertControllerStyleActionSheet];
611-
612- // Add actions for the submenu
613- UIAlertAction *subAction1 = [UIAlertAction actionWithTitle: @" First Theme (Light)"
614- style: UIAlertActionStyleDefault
615- handler: ^(UIAlertAction * _Nonnull action) {
616- callback (8 );
617- }];
618-
619- UIAlertAction *subAction2 = [UIAlertAction actionWithTitle: @" Second Theme (dark)"
620- style: UIAlertActionStyleDefault
621- handler: ^(UIAlertAction * _Nonnull action) {
622- callback (9 );
623- }];
624-
625- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle: @" Cancel"
626- style: UIAlertActionStyleCancel
627- handler: ^(UIAlertAction * _Nonnull action) {
628- callback (-1 );
629- }];
630-
631- if (isIPad ())
632- {
633-
634- submenu.preferredContentSize = view.frame .size ;
635-
636- if (auto * popoverController = submenu.popoverPresentationController )
637- {
638- popoverController.sourceView = view;
639- popoverController.sourceRect = CGRectMake (35 .0f , 1 .0f , 50 .0f , 50 .0f );
640- popoverController.canOverlapSourceViewRect = YES ;
641- }
642- }
643-
644- [submenu addAction: subAction1];
645- [submenu addAction: subAction2];
646- [submenu addAction: cancelAction];
647-
648-
649- // Present the submenu
650- [viewController presentViewController: submenu animated: YES completion: nil ];
651- }];
652-
653-
654- UIAlertAction *newPatchAction = [UIAlertAction actionWithTitle: @" New Patch"
655- style: UIAlertActionStyleDefault
656- handler: ^(UIAlertAction * _Nonnull action) {
657- callback (1 );
658- }];
659- UIAlertAction *openPatchAction = [UIAlertAction actionWithTitle: @" Open Patch"
660- style: UIAlertActionStyleDefault
661- handler: ^(UIAlertAction * _Nonnull action) {
662- callback (2 );
663- }];
664-
665- UIAlertAction *openPatchFolderAction = [UIAlertAction actionWithTitle: @" Open Folder"
666- style: UIAlertActionStyleDefault
667- handler: ^(UIAlertAction * _Nonnull action) {
668- callback (3 );
669- }];
670-
671- UIAlertAction *savePatchAction = [UIAlertAction actionWithTitle: @" Save Patch"
672- style: UIAlertActionStyleDefault
673- handler: ^(UIAlertAction * _Nonnull action) {
674- callback (4 );
675- }];
676-
677- UIAlertAction *savePatchAsAction = [UIAlertAction actionWithTitle: @" Save Patch As"
678- style: UIAlertActionStyleDefault
679- handler: ^(UIAlertAction * _Nonnull action) {
680- callback (5 );
681- }];
682- UIAlertAction *settingsAction = [UIAlertAction actionWithTitle: @" Settings"
683- style: UIAlertActionStyleDefault
684- handler: ^(UIAlertAction * _Nonnull action) {
685- callback (6 );
686- }];
687- UIAlertAction *aboutAction = [UIAlertAction actionWithTitle: @" About"
688- style: UIAlertActionStyleDefault
689- handler: ^(UIAlertAction * _Nonnull action) {
690- callback (7 );
691- }];
692-
693- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle: @" Cancel"
694- style: UIAlertActionStyleCancel
695- handler: ^(UIAlertAction * _Nonnull action) {
696- callback (-1 );
697- }];
698-
699- [alertController addAction: newPatchAction];
700- [alertController addAction: openPatchAction];
701- [alertController addAction: openPatchFolderAction];
702- [alertController addAction: savePatchAction];
703- [alertController addAction: savePatchAsAction];
704- [alertController addAction: themeAction];
705- [alertController addAction: settingsAction];
706- [alertController addAction: aboutAction];
707- [alertController addAction: cancelAction];
708-
709- if (isIPad ())
710- {
711- alertController.preferredContentSize = view.frame .size ;
712-
713- if (auto * popoverController = alertController.popoverPresentationController )
714- {
715- popoverController.sourceView = view;
716- popoverController.sourceRect = CGRectMake (35 .0f , 1 .0f , 50 .0f , 50 .0f );
717- popoverController.canOverlapSourceViewRect = YES ;
718- }
719- }
720-
721-
722- // Present the alert controller using the found view controller
723- [viewController presentViewController: alertController animated: YES completion: nil ];
724- }
725- else {
726- NSLog (@" Failed to find a UIViewController to present the UIAlertController." );
727- }
728- }
729-
730515void OSUtils::showiOSNativeMenu (juce::ComponentPeer* peer, juce::String const & title, SmallArray<TouchPopupMenuItem> const & items, SmallArray<SmallArray<TouchPopupMenuItem>> const & sub, juce::Point<int > screenPosition)
731516{
732517 static std::function<void (UIViewController*, UIView*, juce::ComponentPeer*, NSString *, SmallArray<TouchPopupMenuItem>, SmallArray<SmallArray<TouchPopupMenuItem>>, juce::Point<int >)> presentMenu;
0 commit comments