1
1
Fork 0
mirror of https://github.com/FellippeHeitor/InForm.git synced 2025-01-15 03:49:56 +00:00

Extended control type management.

Allows design-time swapping between common controls like CheckBox x ToggleSwitch or ListBox x DropdownList.

Closes #66
This commit is contained in:
FellippeHeitor 2018-08-18 20:12:15 -03:00
parent 5894e20312
commit 02817799b1
2 changed files with 129 additions and 35 deletions

View file

@ -123,6 +123,9 @@ END TYPE
TYPE __UI_Types
Name AS STRING * 16
Count AS LONG
TurnsInto AS INTEGER
DefaultHeight AS INTEGER
DefaultWidth AS INTEGER
END TYPE
TYPE __UI_ThemeImagesType
@ -209,26 +212,74 @@ DIM SHARED __UI_FrameRate AS SINGLE, __UI_Font8Offset AS INTEGER, __UI_Font16Off
DIM SHARED __UI_ClipboardCheck$, __UI_MenuBarOffsetV AS INTEGER
DIM SHARED __UI_KeepScreenHidden AS _BYTE
'Control types:
'Control types: -----------------------------------------------
DIM SHARED __UI_Type(0 TO 18) AS __UI_Types
__UI_Type(1).Name = "Form"
__UI_Type(2).Name = "Frame"
__UI_Type(2).DefaultWidth = 230
__UI_Type(2).DefaultHeight = 150
__UI_Type(3).Name = "Button"
__UI_Type(3).DefaultWidth = 80
__UI_Type(3).DefaultHeight = 23
__UI_Type(4).Name = "Label"
__UI_Type(4).DefaultWidth = 150
__UI_Type(4).DefaultHeight = 23
__UI_Type(5).Name = "CheckBox"
__UI_Type(5).DefaultWidth = 150
__UI_Type(5).DefaultHeight = 23
__UI_Type(5).TurnsInto = __UI_Type_ToggleSwitch
__UI_Type(6).Name = "RadioButton"
__UI_Type(6).DefaultWidth = 150
__UI_Type(6).DefaultHeight = 23
__UI_Type(7).Name = "TextBox"
__UI_Type(7).DefaultWidth = 120
__UI_Type(7).DefaultHeight = 23
__UI_Type(8).Name = "ProgressBar"
__UI_Type(8).DefaultWidth = 300
__UI_Type(8).DefaultHeight = 23
__UI_Type(9).Name = "ListBox"
__UI_Type(9).DefaultWidth = 200
__UI_Type(9).DefaultHeight = 200
__UI_Type(9).TurnsInto = __UI_Type_DropdownList
__UI_Type(10).Name = "DropdownList"
__UI_Type(10).DefaultWidth = 200
__UI_Type(10).DefaultHeight = 23
__UI_Type(10).TurnsInto = __UI_Type_ListBox
__UI_Type(11).Name = "MenuBar"
__UI_Type(11).TurnsInto = __UI_Type_ContextMenu
__UI_Type(12).Name = "MenuItem"
__UI_Type(13).Name = "MenuPanel"
__UI_Type(14).Name = "PictureBox"
__UI_Type(14).DefaultWidth = 230
__UI_Type(14).DefaultHeight = 150
__UI_Type(15).Name = "TrackBar"
__UI_Type(15).DefaultWidth = 300
__UI_Type(15).DefaultHeight = 45
__UI_Type(16).Name = "ContextMenuPanel"
__UI_Type(16).TurnsInto = __UI_Type_MenuBar
__UI_Type(17).Name = "Font"
__UI_Type(18).Name = "ToggleSwitch"
__UI_Type(18).DefaultWidth = 40
__UI_Type(18).DefaultHeight = 17
__UI_Type(18).TurnsInto = __UI_Type_CheckBox
'--------------------------------------------------------------
CONST True = -1, False = 0
'$INCLUDE:'InFormVersion.bas'
@ -266,7 +317,7 @@ SUB __UI_InternalMenus
Control(__UI_NewID).Font = SetFont("segoeui.ttf?arial.ttf?/Library/Fonts/Arial.ttf?InForm/resources/NotoMono-Regular.ttf?cour.ttf", 12)
'Hotkeys used:
'A, B, C, D, E, G, H, I, L, M, O, P, R, S, T, V, X, Y, Z
'A, B, C, D, E, G, H, I, L, M, N, O, P, R, S, T, V, X, Y, Z
__UI_NewID = __UI_NewControl(__UI_Type_MenuItem, "__UI_PreviewMenuNewMenuBar", 0, 0, 0, 0, __UI_GetID("__UI_PreviewMenu"))
SetCaption __UI_GetID("__UI_PreviewMenuNewMenuBar"), "Add &menu bar control-"
@ -274,6 +325,9 @@ SUB __UI_InternalMenus
SetCaption __UI_GetID("__UI_PreviewMenuSetDefaultButton"), "&Set as default button-"
ToolTip(__UI_NewID) = "The default button can be triggered with Enter even if it doesn't have focus at run time."
__UI_NewID = __UI_NewControl(__UI_Type_MenuItem, "__UI_PreviewMenuConvertType", 0, 0, 0, 0, __UI_GetID("__UI_PreviewMenu"))
SetCaption __UI_GetID("__UI_PreviewMenuConvertType"), "Co&nvert to type-"
__UI_NewID = __UI_NewControl(__UI_Type_MenuItem, "__UI_PreviewMenuImageOriginalSize", 0, 0, 0, 0, __UI_GetID("__UI_PreviewMenu"))
SetCaption __UI_GetID("__UI_PreviewMenuImageOriginalSize"), "Restore &image dimensions-"
@ -1716,6 +1770,7 @@ SUB __UI_EventDispatcher
Control(__UI_GetID("__UI_PreviewMenuImageOriginalSize")).Hidden = True
Control(__UI_GetID("__UI_PreviewMenuNumericOnly")).Hidden = True
Control(__UI_GetID("__UI_PreviewMenuSetDefaultButton")).Hidden = True
Control(__UI_GetID("__UI_PreviewMenuConvertType")).Hidden = True
Control(__UI_GetID("__UI_PreviewMenuNewMenuBar")).Hidden = False
ELSEIF __UI_TotalSelectedControls = 1 THEN
Control(__UI_GetID("__UI_PreviewMenuAlignLeft")).Hidden = True
@ -1776,6 +1831,12 @@ SUB __UI_EventDispatcher
Control(__UI_GetID("__UI_PreviewMenuCut")).Disabled = False
Control(__UI_GetID("__UI_PreviewMenuCopy")).Disabled = False
Control(__UI_GetID("__UI_PreviewMenuDelete")).Disabled = False
IF __UI_Type(Control(__UI_FirstSelectedID).Type).TurnsInto THEN
Control(__UI_GetID("__UI_PreviewMenuConvertType")).Hidden = False
SetCaption __UI_GetID("__UI_PreviewMenuConvertType"), "Co&nvert to " + RTRIM$(__UI_Type(__UI_Type(Control(__UI_FirstSelectedID).Type).TurnsInto).Name) + "-"
ELSE
Control(__UI_GetID("__UI_PreviewMenuConvertType")).Hidden = True
END IF
ELSEIF __UI_TotalSelectedControls = 2 THEN
Control(__UI_GetID("__UI_PreviewMenuNewMenuBar")).Hidden = True
Control(__UI_GetID("__UI_PreviewMenuAlignLeft")).Hidden = False
@ -1796,6 +1857,7 @@ SUB __UI_EventDispatcher
Control(__UI_GetID("__UI_PreviewMenuImageOriginalSize")).Hidden = True
Control(__UI_GetID("__UI_PreviewMenuSetDefaultButton")).Hidden = True
Control(__UI_GetID("__UI_PreviewMenuNumericOnly")).Hidden = True
GOTO AddConvertMenu
ELSE
Control(__UI_GetID("__UI_PreviewMenuNewMenuBar")).Hidden = True
Control(__UI_GetID("__UI_PreviewMenuAlignLeft")).Hidden = False
@ -1816,6 +1878,29 @@ SUB __UI_EventDispatcher
Control(__UI_GetID("__UI_PreviewMenuImageOriginalSize")).Hidden = True
Control(__UI_GetID("__UI_PreviewMenuSetDefaultButton")).Hidden = True
Control(__UI_GetID("__UI_PreviewMenuNumericOnly")).Hidden = True
AddConvertMenu:
IF __UI_Type(Control(__UI_FirstSelectedID).Type).TurnsInto THEN
DIM SearchType AS INTEGER, AddConvertMenuCheck AS _BYTE
SearchType = Control(__UI_FirstSelectedID).Type
AddConvertMenuCheck = True
FOR i = 1 TO UBOUND(Control)
IF Control(i).ControlIsSelected THEN
IF Control(i).Type <> SearchType THEN
AddConvertMenuCheck = False
EXIT FOR
END IF
END IF
NEXT
IF AddConvertMenuCheck THEN
Control(__UI_GetID("__UI_PreviewMenuConvertType")).Hidden = False
SetCaption __UI_GetID("__UI_PreviewMenuConvertType"), "Co&nvert to " + RTRIM$(__UI_Type(__UI_Type(Control(__UI_FirstSelectedID).Type).TurnsInto).Name) + "-"
ELSE
Control(__UI_GetID("__UI_PreviewMenuConvertType")).Hidden = True
END IF
ELSE
Control(__UI_GetID("__UI_PreviewMenuConvertType")).Hidden = True
END IF
END IF
IF LEFT$(_CLIPBOARD$, LEN(__UI_ClipboardCheck$)) = __UI_ClipboardCheck$ THEN
@ -2530,6 +2615,8 @@ SUB __UI_EventDispatcher
END IF
CASE UCASE$("__UI_PreviewMenuNewMenuBar")
__UI_KeyPress 224
CASE UCASE$("__UI_PreviewMenuConvertType")
__UI_KeyPress 225
CASE "__UI_PREVIEWMENUCUT": GOTO ControlCut
CASE "__UI_PREVIEWMENUCOPY": GOTO ControlCopy
CASE "__UI_PREVIEWMENUPASTE": GOTO ControlPaste

View file

@ -41,6 +41,7 @@ CONST EmptyForm$ = "9iVA_9GK1P<000`ooO7000@00D006mVL]53;1`B000000000noO100006mVL
' 222 = Add new textbox with the .NumericOnly property set to true
' 223 = Switch .NumericOnly between True/__UI_NumericWithBounds
' 224 = Add new MenuBar control
' 225 = Convert control type to alternative type
'SavePreview parameters:
CONST InDisk = 1
@ -245,46 +246,33 @@ SUB __UI_BeforeUpdateDisplay
TempValue = CVI(thisData$)
IF TempValue > 0 THEN
DIM defW AS INTEGER, defH AS INTEGER
DIM tempType AS LONG
defW = __UI_Type(TempValue).DefaultWidth
defH = __UI_Type(TempValue).DefaultHeight
tempType = TempValue
SaveUndoImage
SELECT CASE TempValue
CASE __UI_Type_Button
TempValue = __UI_NewControl(__UI_Type_Button, "", 80, 23, TempWidth \ 2 - 40, TempTop - 12, ThisContainer)
SetCaption TempValue, RTRIM$(Control(TempValue).Name)
CASE __UI_Type_Label
TempValue = __UI_NewControl(TempValue, "", 150, 23, TempWidth \ 2 - 75, TempTop - 12, ThisContainer)
SetCaption TempValue, RTRIM$(Control(TempValue).Name)
AutoSizeLabel Control(TempValue)
CASE __UI_Type_CheckBox, __UI_Type_RadioButton
TempValue = __UI_NewControl(TempValue, "", 150, 23, TempWidth \ 2 - 75, TempTop - 12, ThisContainer)
SetCaption TempValue, RTRIM$(Control(TempValue).Name)
CASE __UI_Type_TextBox
TempValue = __UI_NewControl(__UI_Type_TextBox, "", 120, 23, TempWidth \ 2 - 60, TempTop - 12, ThisContainer)
SetCaption TempValue, RTRIM$(Control(TempValue).Name)
CASE __UI_Type_ListBox
TempValue = __UI_NewControl(__UI_Type_ListBox, "", 200, 200, TempWidth \ 2 - 100, TempTop - 100, ThisContainer)
Control(TempValue).HasBorder = True
CASE __UI_Type_DropdownList
TempValue = __UI_NewControl(__UI_Type_DropdownList, "", 200, 23, TempWidth \ 2 - 100, TempTop - 12, ThisContainer)
CASE __UI_Type_TrackBar
TempValue = __UI_NewControl(__UI_Type_TrackBar, "", 300, 45, TempWidth \ 2 - 150, TempTop - 23, ThisContainer)
CASE __UI_Type_ProgressBar
TempValue = __UI_NewControl(__UI_Type_ProgressBar, "", 300, 23, TempWidth \ 2 - 150, TempTop - 12, ThisContainer)
CASE __UI_Type_PictureBox
TempValue = __UI_NewControl(TempValue, "", 230, 150, TempWidth \ 2 - 115, TempTop - 75, ThisContainer)
CASE __UI_Type_Frame
TempValue = __UI_NewControl(TempValue, "", 230, 150, TempWidth \ 2 - 115, TempTop - 75, 0)
SetCaption TempValue, RTRIM$(Control(TempValue).Name)
CASE __UI_Type_MenuBar
IF tempType = __UI_Type_MenuBar THEN
TempValue = AddNewMenuBarControl
CASE __UI_Type_MenuItem
ELSEIF tempType = __UI_Type_MenuItem THEN
IF __UI_ActiveMenu > 0 AND LEFT$(Control(__UI_ParentMenu).Name, 5) <> "__UI_" THEN
TempValue = __UI_NewControl(TempValue, "", 0, 0, 0, 0, __UI_ParentMenu)
TempValue = __UI_NewControl(tempType, "", 0, 0, 0, 0, __UI_ParentMenu)
SetCaption TempValue, RTRIM$(Control(TempValue).Name)
__UI_ActivateMenu Control(__UI_ParentMenu), False
END IF
CASE __UI_Type_ToggleSwitch
TempValue = __UI_NewControl(TempValue, "", 40, 17, TempWidth \ 2 - 20, TempTop - 8, ThisContainer)
ELSE
TempValue = __UI_NewControl(TempValue, "", defW, defH, TempWidth \ 2 - defW \ 2, TempTop - defH \ 2, ThisContainer)
SetCaption TempValue, RTRIM$(Control(TempValue).Name)
END IF
SELECT CASE tempType
CASE __UI_Type_Label
AutoSizeLabel Control(TempValue)
CASE __UI_Type_ListBox
Control(TempValue).HasBorder = True
END SELECT
IF __UI_ActiveMenu > 0 AND (Control(TempValue).Type <> __UI_Type_MenuBar AND Control(TempValue).Type <> __UI_Type_MenuItem) THEN
__UI_DestroyControl Control(__UI_ActiveMenu)
END IF
@ -1164,6 +1152,8 @@ SUB __UI_KeyPress (id AS LONG)
DIM TempID AS LONG
TempID = AddNewMenuBarControl
SelectNewControl TempID
CASE 225
ConvertControlToAlternativeType
END SELECT
END SUB
@ -1442,6 +1432,23 @@ SUB DoAlign (AlignMode AS INTEGER)
END SELECT
END SUB
SUB ConvertControlToAlternativeType
DIM i AS LONG
DIM NewType AS INTEGER
NewType = __UI_Type(Control(__UI_FirstSelectedID).Type).TurnsInto
FOR i = 1 TO UBOUND(Control)
IF Control(i).ControlIsSelected THEN
Control(i).Type = NewType
Control(i).Width = __UI_Type(NewType).DefaultWidth
Control(i).Height = __UI_Type(NewType).DefaultHeight
END IF
NEXT
__UI_ForceRedraw = True
END SUB
SUB SelectAllControls
DIM i AS LONG
IF __UI_TotalSelectedControls = 1 AND Control(__UI_FirstSelectedID).Type = __UI_Type_Frame THEN