|
| 1 | +#include <iostream> |
| 2 | +#include <memory> |
| 3 | +#include "nativeapi.h" |
| 4 | + |
| 5 | +using namespace nativeapi; |
| 6 | + |
| 7 | +int main() { |
| 8 | + std::cout << "=== MessageDialog Example ===" << std::endl; |
| 9 | + |
| 10 | + // Get the Application instance to initialize platform |
| 11 | + Application& app = Application::GetInstance(); |
| 12 | + |
| 13 | + try { |
| 14 | + std::cout << "\n1. Creating a simple informational dialog..." << std::endl; |
| 15 | + |
| 16 | + // Create a simple informational message dialog |
| 17 | + auto info_dialog = std::make_shared<MessageDialog>( |
| 18 | + "Information", |
| 19 | + "This is an informational message dialog.\n\n" |
| 20 | + "MessageDialog can be used to display various types of messages to users."); |
| 21 | + |
| 22 | + info_dialog->SetModality(DialogModality::Application); |
| 23 | + |
| 24 | + std::cout << "Dialog title: " << info_dialog->GetTitle() << std::endl; |
| 25 | + std::cout << "Dialog message: " << info_dialog->GetMessage() << std::endl; |
| 26 | + std::cout << "Opening dialog..." << std::endl; |
| 27 | + |
| 28 | + // Open the dialog (this will block until user dismisses it) |
| 29 | + if (info_dialog->Open()) { |
| 30 | + std::cout << "Dialog was opened successfully" << std::endl; |
| 31 | + } else { |
| 32 | + std::cout << "Failed to open dialog" << std::endl; |
| 33 | + } |
| 34 | + |
| 35 | + std::cout << "\n2. Creating a warning dialog..." << std::endl; |
| 36 | + |
| 37 | + // Create a warning dialog |
| 38 | + auto warning_dialog = std::make_shared<MessageDialog>( |
| 39 | + "Warning", |
| 40 | + "This is a warning message.\n\n" |
| 41 | + "Warning dialogs are used to alert users about potential issues."); |
| 42 | + |
| 43 | + warning_dialog->SetModality(DialogModality::Application); |
| 44 | + warning_dialog->Open(); |
| 45 | + |
| 46 | + std::cout << "\n3. Creating a dialog with updated content..." << std::endl; |
| 47 | + |
| 48 | + // Create a dialog and update its content |
| 49 | + auto dynamic_dialog = std::make_shared<MessageDialog>( |
| 50 | + "Update Available", |
| 51 | + "Initial message"); |
| 52 | + |
| 53 | + // Update the title and message before opening |
| 54 | + dynamic_dialog->SetTitle("System Update"); |
| 55 | + dynamic_dialog->SetMessage( |
| 56 | + "A new version of the application is available.\n\n" |
| 57 | + "Version 2.0 includes:\n" |
| 58 | + "• Improved performance\n" |
| 59 | + "• New features\n" |
| 60 | + "• Bug fixes\n\n" |
| 61 | + "Would you like to update now?"); |
| 62 | + |
| 63 | + dynamic_dialog->SetModality(DialogModality::Application); |
| 64 | + |
| 65 | + std::cout << "Updated title: " << dynamic_dialog->GetTitle() << std::endl; |
| 66 | + std::cout << "Opening updated dialog..." << std::endl; |
| 67 | + dynamic_dialog->Open(); |
| 68 | + |
| 69 | + std::cout << "\n4. Demonstrating different modality types..." << std::endl; |
| 70 | + |
| 71 | + // Non-modal dialog (default) |
| 72 | + auto non_modal_dialog = std::make_shared<MessageDialog>( |
| 73 | + "Non-Modal Dialog", |
| 74 | + "This dialog does not block interaction.\n\n" |
| 75 | + "The application continues running and users can interact with other windows."); |
| 76 | + non_modal_dialog->SetModality(DialogModality::None); |
| 77 | + std::cout << "Modality: None (non-modal)" << std::endl; |
| 78 | + non_modal_dialog->Open(); |
| 79 | + |
| 80 | + // Application modal dialog |
| 81 | + auto app_modal_dialog = std::make_shared<MessageDialog>( |
| 82 | + "Application Modal", |
| 83 | + "This dialog blocks interaction with all windows in the current application."); |
| 84 | + app_modal_dialog->SetModality(DialogModality::Application); |
| 85 | + std::cout << "Modality: Application" << std::endl; |
| 86 | + app_modal_dialog->Open(); |
| 87 | + |
| 88 | + // Window modal dialog (behaves as Application on macOS) |
| 89 | + auto window_modal_dialog = std::make_shared<MessageDialog>( |
| 90 | + "Window Modal", |
| 91 | + "This dialog blocks interaction with a specific parent window.\n\n" |
| 92 | + "Note: On macOS, this behaves as Application."); |
| 93 | + window_modal_dialog->SetModality(DialogModality::Window); |
| 94 | + std::cout << "Modality: Window" << std::endl; |
| 95 | + window_modal_dialog->Open(); |
| 96 | + |
| 97 | + std::cout << "\n=== MessageDialog Example Complete ===" << std::endl; |
| 98 | + std::cout << "This example demonstrated:" << std::endl; |
| 99 | + std::cout << "1. Creating MessageDialog instances" << std::endl; |
| 100 | + std::cout << "2. Setting title and message" << std::endl; |
| 101 | + std::cout << "3. Updating dialog content programmatically" << std::endl; |
| 102 | + std::cout << "4. Opening dialogs with different modality types (None, Application, Window)" << std::endl; |
| 103 | + std::cout << "5. Modal vs non-modal dialog behavior" << std::endl; |
| 104 | + |
| 105 | + std::cout << "\nExiting MessageDialog Example..." << std::endl; |
| 106 | + return 0; |
| 107 | + |
| 108 | + } catch (const std::exception& e) { |
| 109 | + std::cerr << "Error: " << e.what() << std::endl; |
| 110 | + return 1; |
| 111 | + } |
| 112 | +} |
| 113 | + |
0 commit comments