205 |
206 |
206 // add listview to current container |
207 // add listview to current container |
207 UI_APPLY_LAYOUT1(current, args); |
208 UI_APPLY_LAYOUT1(current, args); |
208 |
209 |
209 current->container->Add(bcbar, false); |
210 current->container->Add(bcbar, false); |
210 |
|
211 return widget; |
|
212 } |
|
213 |
|
214 |
|
215 extern "C" static void destroy_ui_pathbar(void* ptr) { |
|
216 UiPathBar* pb = (UiPathBar*)ptr; |
|
217 delete pb; |
|
218 } |
|
219 |
|
220 static void ui_context_add_pathbar_destructor(UiContext* ctx, UiPathBar* pb) { |
|
221 cxMempoolRegister(ctx->mp, pb, destroy_ui_pathbar); |
|
222 } |
|
223 |
|
224 UIEXPORT UIWIDGET ui_pathbar_create(UiObject* obj, UiPathBarArgs args) { |
|
225 UiObject* current = uic_current_obj(obj); |
|
226 |
|
227 // create view and toolkit wrapper |
|
228 Border pathbar = Border(); |
|
229 |
|
230 IInspectable bgRes = Application::Current().Resources().Lookup(box_value(L"TextControlBackground")); |
|
231 IInspectable borderThicknessRes = Application::Current().Resources().Lookup(box_value(L"TextControlBorderThemeThickness")); |
|
232 IInspectable borderBrushRes = Application::Current().Resources().Lookup(box_value(L"TextControlBorderBrush")); |
|
233 // IInspectable cornerRes = Application::Current().Resources().Lookup(box_value(L"TextControlCornerRadius")); |
|
234 |
|
235 Brush bgBrush = unbox_value<Brush>(bgRes); |
|
236 Thickness border = unbox_value<Thickness>(borderThicknessRes); |
|
237 Brush borderBrush = unbox_value<Brush>(borderBrushRes); |
|
238 CornerRadius cornerRadius = { 4, 4, 4, 4 }; //unbox_value<CornerRadius>(cornerRes); |
|
239 |
|
240 pathbar.Background(bgBrush); |
|
241 pathbar.BorderBrush(borderBrush); |
|
242 pathbar.BorderThickness(border); |
|
243 pathbar.CornerRadius(cornerRadius); |
|
244 |
|
245 Grid content = Grid(); |
|
246 pathbar.Child(content); |
|
247 |
|
248 GridLength gl; |
|
249 gl.Value = 1; |
|
250 gl.GridUnitType = GridUnitType::Star; |
|
251 |
|
252 ColumnDefinition coldef = ColumnDefinition(); |
|
253 coldef.Width(gl); |
|
254 content.ColumnDefinitions().Append(coldef); |
|
255 |
|
256 TextBox pathTextBox = TextBox(); |
|
257 Thickness t = { 0, 0, 0, 0 }; |
|
258 CornerRadius c = { 0 ,0, 0, 0 }; |
|
259 pathTextBox.BorderThickness(t); |
|
260 //pathTextBox.CornerRadius(c); |
|
261 |
|
262 |
|
263 pathTextBox.HorizontalAlignment(HorizontalAlignment::Stretch); |
|
264 content.SetColumn(pathTextBox, 0); |
|
265 |
|
266 content.Children().Append(pathTextBox); |
|
267 |
|
268 // stackpanel for buttons |
|
269 StackPanel buttons = StackPanel(); |
|
270 buttons.Orientation(Orientation::Horizontal); |
|
271 buttons.Visibility(Visibility::Collapsed); |
|
272 content.SetColumn(buttons, 0); |
|
273 content.Children().Append(buttons); |
|
274 |
|
275 if (args.ontextinput) { |
|
276 // TODO |
|
277 } |
|
278 |
|
279 //pathTextBox.Visibility(Visibility::Collapsed); |
|
280 |
|
281 UiPathBar* uipathbar = new UiPathBar; |
|
282 ui_context_add_pathbar_destructor(current->ctx, uipathbar); |
|
283 uipathbar->grid = content; |
|
284 uipathbar->buttons = buttons; |
|
285 uipathbar->textbox = pathTextBox; |
|
286 uipathbar->obj = obj; |
|
287 uipathbar->enabledrag = args.enabledrag; |
|
288 uipathbar->enabledrop = args.enabledrop; |
|
289 uipathbar->getvalue = args.getvalue; |
|
290 uipathbar->model = args.model; |
|
291 uipathbar->onactivate = args.onactivate; |
|
292 uipathbar->onactivatedata = args.onactivatedata; |
|
293 uipathbar->ondragstart = args.ondragstart; |
|
294 uipathbar->ondragstartdata = args.ondragstartdata; |
|
295 uipathbar->ondragcomplete = args.ondragcomplete; |
|
296 uipathbar->ondragcompletedata = args.ondragcompletedata; |
|
297 uipathbar->ondrop = args.ondrop; |
|
298 uipathbar->ondropdata = args.ondropsdata; |
|
299 |
|
300 UIElement elm = pathbar; |
|
301 UiWidget* widget = new UiWidget(elm); |
|
302 widget->data1 = uipathbar; |
|
303 ui_context_add_widget_destructor(current->ctx, widget); |
|
304 |
|
305 // bind var |
|
306 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
|
307 if (var) { |
|
308 UiList* list = (UiList*)var->value; |
|
309 list->update = ui_pathbar_update; |
|
310 list->obj = widget; |
|
311 ui_pathbar_update(list, 0); |
|
312 } |
|
313 |
|
314 // add listview to current container |
|
315 UI_APPLY_LAYOUT1(current, args); |
|
316 |
|
317 current->container->Add(pathbar, false); |
|
318 |
211 |
319 return widget; |
212 return widget; |
320 } |
213 } |
321 |
214 |
322 static void* getstrvalue(void* elm, int ignore) { |
215 static void* getstrvalue(void* elm, int ignore) { |
381 } |
274 } |
382 |
275 |
383 bar.ItemsSource(items); |
276 bar.ItemsSource(items); |
384 } |
277 } |
385 |
278 |
386 static void ui_pathbar_clear(StackPanel &buttons) { |
|
387 for (int i = buttons.Children().Size() - 1; i >= 0; i--) { |
|
388 buttons.Children().RemoveAt(i); |
|
389 } |
|
390 } |
|
391 |
|
392 extern "C" void ui_pathbar_update(UiList * list, int i) { |
|
393 UiWidget* widget = (UiWidget*)list->obj; |
|
394 UiPathBar* pb = (UiPathBar*)widget->data1; |
|
395 Grid grid = pb->grid; |
|
396 |
|
397 UiModel* model = pb->model; |
|
398 ui_getvaluefunc getvalue = pb->getvalue; |
|
399 |
|
400 // priority: getvalue, model.getvalue, getstrvalue (fallback) |
|
401 if (getvalue == nullptr) { |
|
402 if (model && model->getvalue) { |
|
403 getvalue = model->getvalue; |
|
404 } |
|
405 else { |
|
406 getvalue = getstrvalue; |
|
407 } |
|
408 } |
|
409 |
|
410 // hide textbox, show button panel |
|
411 pb->textbox.Visibility(Visibility::Collapsed); |
|
412 pb->buttons.Visibility(Visibility::Visible); |
|
413 |
|
414 // clear old buttons |
|
415 ui_pathbar_clear(pb->buttons); |
|
416 |
|
417 // add new buttons |
|
418 void* elm = list->first(list); |
|
419 int j = 0; |
|
420 while (elm) { |
|
421 char* value = (char*)getvalue(elm, 0); |
|
422 wchar_t* wstr = str2wstr(value, nullptr); |
|
423 Button button = Button(); |
|
424 button.Content(box_value(wstr)); |
|
425 free(wstr); |
|
426 |
|
427 if (pb->onactivate) { |
|
428 button.Click([pb, j](IInspectable const& sender, RoutedEventArgs) { |
|
429 UiEvent evt; |
|
430 evt.obj = pb->obj; |
|
431 evt.window = evt.obj->window; |
|
432 evt.document = evt.obj->ctx->document; |
|
433 evt.eventdata = nullptr; |
|
434 evt.intval = j; |
|
435 pb->onactivate(&evt, pb->onactivatedata); |
|
436 }); |
|
437 } |
|
438 |
|
439 Thickness t = { 0, 0, 1, 0 }; |
|
440 CornerRadius c = { 0 ,0, 0, 0 }; |
|
441 button.BorderThickness(t); |
|
442 button.CornerRadius(c); |
|
443 |
|
444 pb->buttons.Children().Append(button); |
|
445 |
|
446 j++; |
|
447 elm = list->next(list); |
|
448 } |
|
449 } |
|
450 |
|
451 |
279 |
452 std::vector<int> ui_create_listview_selection(ListView listview) { |
280 std::vector<int> ui_create_listview_selection(ListView listview) { |
453 std::vector<int> selection; |
281 std::vector<int> selection; |
454 int p = 0; |
282 int p = 0; |
455 auto ranges = listview.SelectedRanges(); |
283 auto ranges = listview.SelectedRanges(); |