GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — WinObjC/Frameworks/UIKit.Xaml/ContentDialog.xaml.cpp at develop · microsoft/WinObjC
This repository was archived by the owner on May 28, 2025. It is now read-only.
Expand file tree/ Copy pathContentDialog.xaml.cppMore file actions 130 lines (102 loc) · 5.66 KB / Copy pathContentDialog.xaml.cppFile metadata and controls130 lines (102 loc) · 5.66 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 //****************************************************************************** // // Copyright (c) Microsoft. All rights reserved. // // This code is licensed under the MIT License (MIT). // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // //****************************************************************************** // clang-format does not like C++/CX // clang-format off #include "pch.h" #include "ContentDialog.xaml.h" using namespace Microsoft::WRL; using namespace Windows::Foundation; using namespace Windows::UI::Xaml; using namespace Windows::UI::Xaml::Controls; using namespace Windows::UI::Xaml::Controls::Primitives; namespace UIKit { namespace Xaml { ContentDialog::ContentDialog() : _buttonPressedIndex(-1) { InitializeComponent(); ObservableItems = ref new Platform::Collections::Vector<Item^>(); // Bind the list view source to our vector of items ActionsListView->ItemsSource = ObservableItems; } ////////////////////////////////////////////////////// // Implement derived XAML control functionality ////////////////////////////////////////////////////// void ContentDialog::OnSelectionChanged(Platform::Object ^sender, SelectionChangedEventArgs ^e) { auto listView = safe_cast<ListView^>(sender); if (listView) { Item^ selectedItem = safe_cast<Item^>(listView->SelectedItem); _buttonPressedIndex = selectedItem->Index; } // This triggers the showAsync event handler where we can process the index for the button pressed through its getter, ContentDialogCustomResult Hide(); } } /* Xaml*/ } /* UIKit*/ //////////////////////////////////////////////////////////////////////////////////// // ObjectiveC Interop //////////////////////////////////////////////////////////////////////////////////// UIKIT_XAML_EXPORT void XamlCreateContentDialog(IInspectable** created) { ComPtr<IInspectable> inspectable = InspectableFromObject(ref new UIKit::Xaml::ContentDialog()); *created = inspectable.Detach(); } UIKIT_XAML_EXPORT int XamlContentDialogPressedIndex(const ComPtr<IInspectable>& inspectableContentDialog) { auto contentDialog = safe_cast<UIKit::Xaml::ContentDialog^>(reinterpret_cast<Platform::Object^>(inspectableContentDialog.Get())); return contentDialog->PressedIndex; } UIKIT_XAML_EXPORT unsigned int XamlContentDialogAddButtonWithTitle(const ComPtr<IInspectable>& inspectableContentDialog, const std::wstring& buttonTitle) { auto contentDialog = safe_cast<UIKit::Xaml::ContentDialog^>(reinterpret_cast<Platform::Object^>(inspectableContentDialog.Get())); // Append a new item to the listview unsigned int newIndex = contentDialog->NumberOfItems; auto newItem = ref new UIKit::Xaml::Item(Platform::StringReference(buttonTitle.c_str()), newIndex); contentDialog->ObservableItems->Append(newItem); return newIndex; } UIKIT_XAML_EXPORT IInspectable* XamlContentDialogButtonTitleAtIndex(const ComPtr<IInspectable>& inspectableContentDialog, unsigned int buttonIndex) { auto contentDialog = safe_cast<UIKit::Xaml::ContentDialog^>(reinterpret_cast<Platform::Object^>(inspectableContentDialog.Get())); // Strings are passed via PropertyValues to Objective-C Platform::Object^ propVal; for (UIKit::Xaml::Item^ item : contentDialog->ObservableItems) { if (item->Index == buttonIndex) { propVal = PropertyValue::CreateString(item->Title); break; } } return InspectableFromObject(propVal).Detach(); } UIKIT_XAML_EXPORT unsigned int XamlContentDialogNumberOfButtons(const ComPtr<IInspectable>& inspectableContentDialog) { auto contentDialog = safe_cast<UIKit::Xaml::ContentDialog^>(reinterpret_cast<Platform::Object^>(inspectableContentDialog.Get())); return contentDialog->NumberOfItems; } UIKIT_XAML_EXPORT void XamlContentDialogSetCancelButtonIndex(const ComPtr<IInspectable>& inspectableContentDialog, unsigned int cancelButtonIndex) { auto contentDialog = safe_cast<UIKit::Xaml::ContentDialog^>(reinterpret_cast<Platform::Object^>(inspectableContentDialog.Get())); // Remove the cancel button from its current position because we're going to append it to the end of the list for (UIKit::Xaml::Item^ item : contentDialog->ObservableItems) { if (item->Index == cancelButtonIndex) { // There is a single listview that holds all our buttons. The cancel button is the only button that has defined position i.e. end of the list // In the scenarios where buttons are dynamically added (e.g. not using initWithTitle:...) we need to remove and re-append the cancel button unsigned int itemToRemoveIndex; contentDialog->ObservableItems->IndexOf(item, &itemToRemoveIndex); contentDialog->ObservableItems->RemoveAt(itemToRemoveIndex); contentDialog->ObservableItems->Append(item); // TODO: Change the style to match the design guidelines break; } } } UIKIT_XAML_EXPORT void XamlContentDialogSetDestructiveButtonIndex(const ComPtr<IInspectable>& inspectableContentDialog, unsigned int destructiveButtonIndex) { auto contentDialog = safe_cast<UIKit::Xaml::ContentDialog^>(reinterpret_cast<Platform::Object^>(inspectableContentDialog.Get())); // TODO: Change the style to match the design guidelines } // clang-format on |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |