Exemplo n.º 1
0
 private void ApplyCoreSettings(NativeTaskDialogSettings settings)
 {
     ApplyGeneralNativeConfiguration(settings.NativeConfiguration);
     ApplyTextConfiguration(settings.NativeConfiguration);
     ApplyOptionConfiguration(settings.NativeConfiguration);
     ApplyControlConfiguration(settings);
 }
Exemplo n.º 2
0
        // Builds the actual configuration
        // that the NativeTaskDialog (and underlying Win32 API)
        // expects, by parsing the various control
        // lists, marshalling to the unmanaged heap, etc.

        private void ApplyControlConfiguration(NativeTaskDialogSettings settings)
        {
            // Deal with progress bars/marquees.
            if (progressBar != null)
            {
                if (progressBar.State == TaskDialogProgressBarState.Marquee)
                {
                    settings.NativeConfiguration.taskDialogFlags |= TaskDialogNativeMethods.TaskDialogOptions.ShowMarqueeProgressBar;
                }
                else
                {
                    settings.NativeConfiguration.taskDialogFlags |= TaskDialogNativeMethods.TaskDialogOptions.ShowProgressBar;
                }
            }

            // Build the native struct arrays that NativeTaskDialog
            // needs - though NTD will handle
            // the heavy lifting marshalling to make sure
            // all the cleanup is centralized there.
            if (buttons.Count > 0 || commandLinks.Count > 0)
            {
                // These are the actual arrays/lists of
                // the structs that we'll copy to the
                // unmanaged heap.
                List <TaskDialogButtonBase> sourceList = (buttons.Count > 0 ? buttons : commandLinks);
                settings.Buttons = BuildButtonStructArray(sourceList);

                // Apply option flag that forces all
                // custom buttons to render as command links.
                if (commandLinks.Count > 0)
                {
                    settings.NativeConfiguration.taskDialogFlags |= TaskDialogNativeMethods.TaskDialogOptions.UseCommandLinks;
                }

                // Set default button and add elevation icons
                // to appropriate buttons.
                settings.NativeConfiguration.defaultButtonIndex = FindDefaultButtonId(sourceList);

                ApplyElevatedIcons(settings, sourceList);
            }

            if (radioButtons.Count > 0)
            {
                settings.RadioButtons = BuildButtonStructArray(radioButtons);

                // Set default radio button - radio buttons don't support.
                int defaultRadioButton = FindDefaultButtonId(radioButtons);
                settings.NativeConfiguration.defaultRadioButtonIndex = defaultRadioButton;

                if (defaultRadioButton == TaskDialogNativeMethods.NoDefaultButtonSpecified)
                {
                    settings.NativeConfiguration.taskDialogFlags |= TaskDialogNativeMethods.TaskDialogOptions.NoDefaultRadioButton;
                }
            }
        }
Exemplo n.º 3
0
        // Configuration is applied at dialog creation time.
        internal NativeTaskDialog(NativeTaskDialogSettings settings, TaskDialog outerDialog)
        {
            nativeDialogConfig = settings.NativeConfiguration;
            this.settings      = settings;

            // Wireup dialog proc message loop for this instance.
            nativeDialogConfig.callback = new TaskDialogNativeMethods.TaskDialogCallback(DialogProc);

            ShowState = DialogShowState.PreShow;

            // Keep a reference to the outer shell, so we can notify.
            this.outerDialog = outerDialog;
        }
Exemplo n.º 4
0
 private static void ApplyElevatedIcons(NativeTaskDialogSettings settings, List <TaskDialogButtonBase> controls)
 {
     foreach (TaskDialogButton control in controls)
     {
         if (control.UseElevationIcon)
         {
             if (settings.ElevatedButtons == null)
             {
                 settings.ElevatedButtons = new List <int>();
             }
             settings.ElevatedButtons.Add(control.Id);
         }
     }
 }
Exemplo n.º 5
0
        private void ApplySupplementalSettings(NativeTaskDialogSettings settings)
        {
            if (progressBar != null)
            {
                if (progressBar.State != TaskDialogProgressBarState.Marquee)
                {
                    settings.ProgressBarMinimum = progressBar.Minimum;
                    settings.ProgressBarMaximum = progressBar.Maximum;
                    settings.ProgressBarValue   = progressBar.Value;
                    settings.ProgressBarState   = progressBar.State;
                }
            }

            if (HelpInvoked != null)
            {
                settings.InvokeHelp = true;
            }
        }
Exemplo n.º 6
0
        private TaskDialogResult ShowCore()
        {
            TaskDialogResult result;

            try
            {
                // Populate control lists, based on current
                // contents - note we are somewhat late-bound
                // on our control lists, to support XAML scenarios.
                SortDialogControls();

                // First, let's make sure it even makes
                // sense to try a show.
                ValidateCurrentDialogSettings();

                // Create settings object for new dialog,
                // based on current state.
                NativeTaskDialogSettings settings = new NativeTaskDialogSettings();
                ApplyCoreSettings(settings);
                ApplySupplementalSettings(settings);

                // Show the dialog.
                // NOTE: this is a BLOCKING call; the dialog proc callbacks
                // will be executed by the same thread as the
                // Show() call before the thread of execution
                // contines to the end of this method.
                nativeDialog = new NativeTaskDialog(settings, this);
                nativeDialog.NativeShow();

                // Build and return dialog result to public API - leaving it
                // null after an exception is thrown is fine in this case
                result = ConstructDialogResult(nativeDialog);
                footerCheckBoxChecked = nativeDialog.CheckBoxChecked;
            }
            finally
            {
                CleanUp();
                nativeDialog = null;
            }

            return(result);
        }