2024-06-23 01:07:33 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-06-29 23:05:16 +00:00
|
|
|
"runtime"
|
|
|
|
|
2024-06-23 01:07:33 +00:00
|
|
|
"github.com/ying32/govcl/vcl"
|
|
|
|
"github.com/ying32/govcl/vcl/types"
|
2024-06-29 23:05:16 +00:00
|
|
|
"github.com/ying32/govcl/vcl/types/colors"
|
2024-06-23 01:07:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
MY_SPACING = 6
|
|
|
|
MY_HEIGHT = 90
|
|
|
|
MY_WIDTH = 180
|
2024-07-05 07:35:24 +00:00
|
|
|
|
|
|
|
MAX_AUTO_COL_WIDTH = 240
|
2024-06-23 01:07:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// vcl_row makes a TPanel row inside the target component.
|
|
|
|
func vcl_row(owner vcl.IWinControl, top int32) *vcl.TPanel {
|
|
|
|
|
|
|
|
r := vcl.NewPanel(owner)
|
|
|
|
r.SetParent(owner)
|
|
|
|
r.SetBorderStyle(types.BsNone)
|
|
|
|
r.SetBevelInner(types.BvNone)
|
|
|
|
r.SetBevelOuter(types.BvNone)
|
|
|
|
r.SetAlign(types.AlTop)
|
|
|
|
r.SetTop(top)
|
|
|
|
r.SetAutoSize(true)
|
|
|
|
|
|
|
|
return r
|
|
|
|
}
|
2024-06-27 23:11:34 +00:00
|
|
|
|
|
|
|
// vcl_menuitem makes a child TMenuItem inside the parent menu.
|
|
|
|
func vcl_menuitem(parent *vcl.TMenuItem, caption string, imageIndex int32, onClick vcl.TNotifyEvent) *vcl.TMenuItem {
|
|
|
|
m := vcl.NewMenuItem(parent)
|
|
|
|
m.SetCaption(caption)
|
2024-06-29 00:13:18 +00:00
|
|
|
if imageIndex != -1 {
|
|
|
|
m.SetImageIndex(imageIndex)
|
|
|
|
}
|
|
|
|
if onClick != nil {
|
|
|
|
m.SetOnClick(onClick)
|
|
|
|
}
|
2024-06-27 23:11:34 +00:00
|
|
|
parent.Add(m)
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
2024-06-29 00:13:18 +00:00
|
|
|
|
|
|
|
// vcl_menuseparator adds a separator to the parent TMenuItem.
|
|
|
|
func vcl_menuseparator(parent *vcl.TMenuItem) *vcl.TMenuItem {
|
|
|
|
s := vcl.NewMenuItem(parent)
|
|
|
|
s.SetCaption("-") // Creates separator
|
|
|
|
parent.Add(s)
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|
2024-06-29 23:05:16 +00:00
|
|
|
|
|
|
|
func vcl_default_tab_background() types.TColor {
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
// Assuming that uxtheme is loaded
|
|
|
|
// @ref https://stackoverflow.com/a/20332712
|
2024-07-18 05:51:27 +00:00
|
|
|
// return colors.ClBtnHighlight
|
|
|
|
|
|
|
|
// None of the colors.** constants seem to be quite right on a test
|
|
|
|
// Windows 11 machine - should be #f9f9f9
|
|
|
|
return 0x00f9f9f9
|
2024-06-29 23:05:16 +00:00
|
|
|
} else {
|
|
|
|
return colors.ClBtnFace // 0x00f0f0f0
|
|
|
|
}
|
|
|
|
}
|
2024-07-05 07:21:08 +00:00
|
|
|
|
|
|
|
func vcl_stringgrid_clear(d *vcl.TStringGrid) {
|
|
|
|
d.SetFixedCols(0) // No left-hand cols
|
|
|
|
d.SetRowCount(1) // The 0th row is the column headers
|
|
|
|
d.SetEnabled(false)
|
|
|
|
d.Columns().Clear()
|
2024-07-05 23:04:19 +00:00
|
|
|
d.Invalidate()
|
2024-07-05 07:21:08 +00:00
|
|
|
}
|
2024-07-05 07:35:24 +00:00
|
|
|
|
|
|
|
func vcl_stringgrid_columnwidths(d *vcl.TStringGrid) {
|
|
|
|
// Skip slow processing for very large result sets
|
|
|
|
if d.RowCount() > 1000 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
d.AutoAdjustColumns()
|
|
|
|
|
|
|
|
// AutoAdjustColumns will leave some columns massively too large by themselves
|
|
|
|
// Reign them back in
|
|
|
|
ct := d.Columns().Count()
|
|
|
|
for i := int32(0); i < ct; i++ {
|
|
|
|
if d.ColWidths(i) > MAX_AUTO_COL_WIDTH {
|
|
|
|
d.SetColWidths(i, MAX_AUTO_COL_WIDTH)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-14 03:34:17 +00:00
|
|
|
|
|
|
|
func vcl_confirm_dialog(sender vcl.IComponent, title string, message string) bool {
|
|
|
|
|
|
|
|
dlg := vcl.NewTaskDialog(sender)
|
|
|
|
dlg.SetCaption(APPNAME)
|
|
|
|
dlg.SetTitle(title)
|
|
|
|
dlg.SetText(message)
|
|
|
|
dlg.SetCommonButtons(types.NewSet())
|
|
|
|
|
|
|
|
yesBtn := dlg.Buttons().Add()
|
|
|
|
yesBtn.SetCaption("Confirm")
|
|
|
|
yesBtn.SetModalResult(types.MrYes)
|
|
|
|
|
|
|
|
noBtn := dlg.Buttons().Add()
|
|
|
|
noBtn.SetCaption("Cancel")
|
|
|
|
noBtn.SetModalResult(types.MrCancel)
|
|
|
|
|
|
|
|
ret := dlg.Execute()
|
|
|
|
if !ret {
|
|
|
|
return false // dialog closed
|
|
|
|
}
|
|
|
|
if dlg.ModalResult() != types.MrYes {
|
|
|
|
return false // other button clicked
|
|
|
|
}
|
|
|
|
|
|
|
|
return true // confirmed
|
|
|
|
}
|