GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — WinObjC/Frameworks/UIKit.Xaml/Button.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

/

Button.xaml.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
265 lines (222 loc) · 10.6 KB
/

Button.xaml.cpp

Copy path

File metadata and controls

265 lines (222 loc) · 10.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
//******************************************************************************
//
// 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 "Button.xaml.h"
using namespace Microsoft::WRL;
using namespace Platform;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Media::Imaging;
using namespace Windows::UI::Xaml::Controls;
namespace UIKit {
namespace Xaml {
// Method to get default text Foreground brush
Brush^ GetDefaultWhiteForegroundBrush() {
static auto ret = ref new SolidColorBrush(Windows::UI::Colors::White);
return ret;
}
Button::Button() {
InitializeComponent();
// Default to a transparent background brush so we can accept pointer input
static auto transparentBrush = ref new SolidColorBrush(Windows::UI::Colors::Transparent);
Background = transparentBrush;
}
// Accessor for our Layer content
Image^ Button::LayerContent::get() {
if (!_content && _contentCanvas) {
_content = ref new Image();
_content->Name = "LayerContent";
// Layer content is behind any sublayers
_contentCanvas->Children->InsertAt(0, _content);
}
return _content;
}
// Accessor for our Layer content
bool Button::HasLayerContent::get() {
return _content != nullptr;
}
// Accessor for our SublayerCanvas
Canvas^ Button::SublayerCanvas::get() {
return _contentCanvas;
}
// Accessor for the LayerProperty that manages the BorderBrush of this button
Private::CoreAnimation::LayerProperty^ Button::GetBorderBrushProperty() {
return ref new Private::CoreAnimation::LayerProperty(_border, _border->BorderBrushProperty);
}
// Accessor for the LayerProperty that manages the BorderThickness of this button
Private::CoreAnimation::LayerProperty^ Button::GetBorderThicknessProperty() {
return ref new Private::CoreAnimation::LayerProperty(_border, _border->BorderThicknessProperty);
}
void Button::OnPointerPressed(PointerRoutedEventArgs^ e) {
// Call the pointer hook if it exists
if (_pointerPressedHook) {
CapturePointer(e->Pointer);
_pointerPressedHook->Invoke(
InspectableFromObject(this).Get(),
ObjectToType<ABI::Windows::UI::Xaml::Input::IPointerRoutedEventArgs>(e).Get());
}
// If the pointer hook didn't handle the event, call into our base class
if (!e->Handled) {
__super::OnPointerPressed(e);
}
}
void Button::OnPointerMoved(PointerRoutedEventArgs^ e) {
// Call the pointer hook if it exists
if (_pointerMovedHook) {
_pointerMovedHook->Invoke(
InspectableFromObject(this).Get(),
ObjectToType<ABI::Windows::UI::Xaml::Input::IPointerRoutedEventArgs>(e).Get());
}
// If the pointer hook didn't handle the event, call into our base class
if (!e->Handled) {
__super::OnPointerMoved(e);
}
}
void Button::OnPointerReleased(PointerRoutedEventArgs^ e) {
// Call the pointer hook if it exists
if (_pointerReleasedHook) {
_pointerReleasedHook->Invoke(
InspectableFromObject(this).Get(),
ObjectToType<ABI::Windows::UI::Xaml::Input::IPointerRoutedEventArgs>(e).Get());
}
// If the pointer hook didn't handle the event, call into our base class
if (!e->Handled) {
__super::OnPointerReleased(e);
}
}
void Button::OnPointerCanceled(PointerRoutedEventArgs^ e) {
// Call the pointer hook if it exists
if (_pointerCanceledHook) {
_pointerCanceledHook->Invoke(
InspectableFromObject(this).Get(),
ObjectToType<ABI::Windows::UI::Xaml::Input::IPointerRoutedEventArgs>(e).Get());
}
// Call into our base class regardless of whether or not the UIKit subclass, etc. 'handled' the event
__super::OnPointerCanceled(e);
}
void Button::OnPointerCaptureLost(PointerRoutedEventArgs^ e) {
// Call the pointer hook if it exists
if (_pointerCaptureLostHook) {
_pointerCaptureLostHook->Invoke(
InspectableFromObject(this).Get(),
ObjectToType<ABI::Windows::UI::Xaml::Input::IPointerRoutedEventArgs>(e).Get());
}
// Call into our base class regardless of whether or not the UIKit subclass, etc. 'handled' the event
__super::OnPointerCaptureLost(e);
}
// Hook pointer events
void Button::HookPointerEvents(
const Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Input::IPointerEventHandler>& pointerPressedHook,
const Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Input::IPointerEventHandler>& pointerMovedHook,
const Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Input::IPointerEventHandler>& pointerReleasedHook,
const Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Input::IPointerEventHandler>& pointerCanceledHook,
const Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Input::IPointerEventHandler>& pointerCaptureLostHook) {
_pointerPressedHook = std::move(pointerPressedHook);
_pointerMovedHook = std::move(pointerMovedHook);
_pointerReleasedHook = std::move(pointerReleasedHook);
_pointerCanceledHook = std::move(pointerCanceledHook);
_pointerCaptureLostHook = std::move(pointerCaptureLostHook);
}
void Button::RemovePointerEvents() {
_pointerPressedHook = nullptr;
_pointerMovedHook = nullptr;
_pointerReleasedHook = nullptr;
_pointerCanceledHook = nullptr;
_pointerCaptureLostHook = nullptr;
}
void Button::LabelTextChanged(Windows::UI::Xaml::DependencyObject^ object, Windows::UI::Xaml::DependencyProperty^ property) {
// Update our AutomationProperties::Name so accessibility tools can read it
SetValue(Windows::UI::Xaml::Automation::AutomationProperties::NameProperty, _label->TextBlock->Text);
}
void Button::OnApplyTemplate() {
// Call GetTemplateChild to grab references to UIElements in our custom control template
_image = safe_cast<Image^>(GetTemplateChild("buttonImage"));
_border = safe_cast<Border^>(GetTemplateChild("buttonBorder"));
_contentCanvas = safe_cast<Canvas^>(GetTemplateChild(L"contentCanvas"));
// TODO: We must currently add this dynamically to work around #1919.
_label = ref new Label();
_contentCanvas->Children->Append(_label);
// TODO: We should do this with binding in our markup once #1919 is fixed
_label->TextBlock->RegisterPropertyChangedCallback(TextBlock::TextProperty, ref new DependencyPropertyChangedCallback(this, &Button::LabelTextChanged));
}
} /* Xaml*/
} /* UIKit*/
////////////////////////////////////////////////////////////////////////////////////
// ObjectiveC Interop
////////////////////////////////////////////////////////////////////////////////////
UIKIT_XAML_EXPORT void XamlCreateButton(IInspectable** created) {
ComPtr<IInspectable> inspectable = InspectableFromObject(ref new UIKit::Xaml::Button());
*created = inspectable.Detach();
}
// Retrieves the UIKit::Label's backing TextBlock as an IInspectable
UIKIT_XAML_EXPORT IInspectable* XamlGetButtonLabel(const Microsoft::WRL::ComPtr<IInspectable>& inspectableButton) {
auto button = safe_cast<UIKit::Xaml::Button^>(reinterpret_cast<Platform::Object^>(inspectableButton.Get()));
// Force-load the template so we can access the label.
if (!button->_label) {
// Force-load the template so we can access the label.
button->ApplyTemplate();
button->UpdateLayout();
}
return InspectableFromObject(button->_label).Detach();
}
// Retrieves the UIKit::Label's backing TextBlock as an IInspectable
UIKIT_XAML_EXPORT IInspectable* XamlGetButtonImage(const Microsoft::WRL::ComPtr<IInspectable>& inspectableButton) {
auto button = safe_cast<UIKit::Xaml::Button^>(reinterpret_cast<Platform::Object^>(inspectableButton.Get()));
if (!button->_image) {
// Force-load the template so we can access the label.
button->ApplyTemplate();
button->UpdateLayout();
}
return InspectableFromObject(button->_image).Detach();
}
UIKIT_XAML_EXPORT void XamlRemovePointerEvents(const ComPtr<IInspectable>& inspectableButton) {
auto button = safe_cast<UIKit::Xaml::Button^>(reinterpret_cast<Platform::Object^>(inspectableButton.Get()));
button->RemovePointerEvents();
}
UIKIT_XAML_EXPORT void XamlButtonApplyVisuals(
const ComPtr<IInspectable>& inspectableButton,
const ComPtr<IInspectable>& inspectableButtonImage,
const ComPtr<IInspectable>& inspectableBorderBackgroundBrush) {
auto button = safe_cast<UIKit::Xaml::Button^>(reinterpret_cast<Platform::Object^>(inspectableButton.Get()));
// Set the Button's Image
auto image = safe_cast<Brush^>(reinterpret_cast<Platform::Object^>(inspectableButtonImage.Get()));
if (image) {
ImageBrush^ imageBrush = safe_cast<ImageBrush^>(image);
button->_image->Source = safe_cast<BitmapSource^>(imageBrush->ImageSource);
}
// Set the border background brush (if any)
button->_border->Background = safe_cast<Brush^>(reinterpret_cast<Platform::Object^>(inspectableBorderBackgroundBrush.Get()));
}
UIKIT_XAML_EXPORT void XamlHookButtonPointerEvents(
const ComPtr<IInspectable>& inspectableButton,
const ComPtr<IInspectable>& pointerPressedHook,
const ComPtr<IInspectable>& pointerMovedHook,
const ComPtr<IInspectable>& pointerReleasedHook,
const ComPtr<IInspectable>& pointerCanceledHook,
const ComPtr<IInspectable>& pointerCaptureLostHook) {
// Now subscribe to the events on the actual button object
auto button = safe_cast<UIKit::Xaml::Button^>(reinterpret_cast<Platform::Object^>(inspectableButton.Get()));
button->HookPointerEvents(
InspectableToType<ABI::Windows::UI::Xaml::Input::IPointerEventHandler>(pointerPressedHook),
InspectableToType<ABI::Windows::UI::Xaml::Input::IPointerEventHandler>(pointerMovedHook),
InspectableToType<ABI::Windows::UI::Xaml::Input::IPointerEventHandler>(pointerReleasedHook),
InspectableToType<ABI::Windows::UI::Xaml::Input::IPointerEventHandler>(pointerCanceledHook),
InspectableToType<ABI::Windows::UI::Xaml::Input::IPointerEventHandler>(pointerCaptureLostHook));
}
// 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.