MCPcopy Index your code
hub / github.com/lxn/walk / initButtonForAction

Method initButtonForAction

toolbar.go:325–384  ·  view source on GitHub ↗
(action *Action, state, style *byte, image *int32, text *uintptr)

Source from the content-addressed store, hash-verified

323}
324
325func (tb *ToolBar) initButtonForAction(action *Action, state, style *byte, image *int32, text *uintptr) (err error) {
326 if tb.hasStyleBits(win.CCS_VERT) {
327 *state |= win.TBSTATE_WRAP
328 } else if tb.defaultButtonWidth == 0 {
329 *style |= win.BTNS_AUTOSIZE
330 }
331
332 if action.checked {
333 *state |= win.TBSTATE_CHECKED
334 }
335
336 if action.enabled {
337 *state |= win.TBSTATE_ENABLED
338 }
339
340 if action.checkable {
341 *style |= win.BTNS_CHECK
342 }
343
344 if action.exclusive {
345 *style |= win.BTNS_GROUP
346 }
347
348 if tb.buttonStyle != ToolBarButtonImageOnly && len(action.text) > 0 {
349 *style |= win.BTNS_SHOWTEXT
350 }
351
352 if action.menu != nil {
353 if len(action.Triggered().handlers) > 0 {
354 *style |= win.BTNS_DROPDOWN
355 } else {
356 *style |= win.BTNS_WHOLEDROPDOWN
357 }
358 }
359
360 if action.IsSeparator() {
361 *style = win.BTNS_SEP
362 }
363
364 if tb.buttonStyle != ToolBarButtonTextOnly {
365 if *image, err = tb.imageIndex(action.image); err != nil {
366 return err
367 }
368 }
369
370 var actionText string
371 if s := action.shortcut; tb.buttonStyle == ToolBarButtonImageOnly && s.Key != 0 {
372 actionText = fmt.Sprintf("%s (%s)", action.Text(), s.String())
373 } else {
374 actionText = action.Text()
375 }
376
377 if len(actionText) != 0 {
378 *text = uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(actionText)))
379 } else if len(action.toolTip) != 0 {
380 *text = uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(action.toolTip)))
381 }
382

Callers 2

onActionChangedMethod · 0.95
insertActionMethod · 0.95

Calls 6

imageIndexMethod · 0.95
hasStyleBitsMethod · 0.80
TriggeredMethod · 0.80
IsSeparatorMethod · 0.80
TextMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected