1
1
Fork 0
mirror of https://github.com/FellippeHeitor/InForm.git synced 2025-01-14 19:49:33 +00:00

Begins the foundation for adding ContextMenu controls more easily.

This commit is contained in:
FellippeHeitor 2018-08-30 12:12:08 -03:00
parent a242dd2c13
commit 2f4b98e266
4 changed files with 124 additions and 53 deletions

View file

@ -218,72 +218,72 @@ DIM SHARED __UI_KeepScreenHidden AS _BYTE, __UI_MaxBorderSize AS INTEGER
'Control types: -----------------------------------------------
DIM SHARED __UI_Type(0 TO 18) AS __UI_Types
__UI_Type(1).Name = "Form"
__UI_Type(__UI_Type_Form).Name = "Form"
__UI_Type(2).Name = "Frame"
__UI_Type(2).DefaultWidth = 230
__UI_Type(2).DefaultHeight = 150
__UI_Type(__UI_Type_Frame).Name = "Frame"
__UI_Type(__UI_Type_Frame).DefaultWidth = 230
__UI_Type(__UI_Type_Frame).DefaultHeight = 150
__UI_Type(3).Name = "Button"
__UI_Type(3).DefaultWidth = 80
__UI_Type(3).DefaultHeight = 23
__UI_Type(__UI_Type_Button).Name = "Button"
__UI_Type(__UI_Type_Button).DefaultWidth = 80
__UI_Type(__UI_Type_Button).DefaultHeight = 23
__UI_Type(4).Name = "Label"
__UI_Type(4).DefaultWidth = 150
__UI_Type(4).DefaultHeight = 23
__UI_Type(__UI_Type_Label).Name = "Label"
__UI_Type(__UI_Type_Label).DefaultWidth = 150
__UI_Type(__UI_Type_Label).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(__UI_Type_CheckBox).Name = "CheckBox"
__UI_Type(__UI_Type_CheckBox).DefaultWidth = 150
__UI_Type(__UI_Type_CheckBox).DefaultHeight = 23
__UI_Type(__UI_Type_CheckBox).TurnsInto = __UI_Type_ToggleSwitch
__UI_Type(6).Name = "RadioButton"
__UI_Type(6).DefaultWidth = 150
__UI_Type(6).DefaultHeight = 23
__UI_Type(__UI_Type_RadioButton).Name = "RadioButton"
__UI_Type(__UI_Type_RadioButton).DefaultWidth = 150
__UI_Type(__UI_Type_RadioButton).DefaultHeight = 23
__UI_Type(7).Name = "TextBox"
__UI_Type(7).DefaultWidth = 120
__UI_Type(7).DefaultHeight = 23
__UI_Type(__UI_Type_TextBox).Name = "TextBox"
__UI_Type(__UI_Type_TextBox).DefaultWidth = 120
__UI_Type(__UI_Type_TextBox).DefaultHeight = 23
__UI_Type(8).Name = "ProgressBar"
__UI_Type(8).DefaultWidth = 300
__UI_Type(8).DefaultHeight = 23
__UI_Type(__UI_Type_ProgressBar).Name = "ProgressBar"
__UI_Type(__UI_Type_ProgressBar).DefaultWidth = 300
__UI_Type(__UI_Type_ProgressBar).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(__UI_Type_ListBox).Name = "ListBox"
__UI_Type(__UI_Type_ListBox).DefaultWidth = 200
__UI_Type(__UI_Type_ListBox).DefaultHeight = 200
__UI_Type(__UI_Type_ListBox).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(__UI_Type_DropdownList).Name = "DropdownList"
__UI_Type(__UI_Type_DropdownList).DefaultWidth = 200
__UI_Type(__UI_Type_DropdownList).DefaultHeight = 23
__UI_Type(__UI_Type_DropdownList).TurnsInto = __UI_Type_ListBox
__UI_Type(11).Name = "MenuBar"
__UI_Type(11).TurnsInto = __UI_Type_ContextMenu
__UI_Type(__UI_Type_MenuBar).Name = "MenuBar"
__UI_Type(__UI_Type_MenuBar).TurnsInto = __UI_Type_ContextMenu
__UI_Type(12).Name = "MenuItem"
__UI_Type(__UI_Type_MenuItem).Name = "MenuItem"
__UI_Type(13).Name = "MenuPanel"
__UI_Type(__UI_Type_MenuPanel).Name = "MenuPanel"
__UI_Type(14).Name = "PictureBox"
__UI_Type(14).DefaultWidth = 230
__UI_Type(14).DefaultHeight = 150
__UI_Type(__UI_Type_PictureBox).Name = "PictureBox"
__UI_Type(__UI_Type_PictureBox).DefaultWidth = 230
__UI_Type(__UI_Type_PictureBox).DefaultHeight = 150
__UI_Type(15).Name = "TrackBar"
__UI_Type(15).DefaultWidth = 300
__UI_Type(15).DefaultHeight = 45
__UI_Type(15).RestrictResize = __UI_CantResizeV
__UI_Type(__UI_Type_TrackBar).Name = "TrackBar"
__UI_Type(__UI_Type_TrackBar).DefaultWidth = 300
__UI_Type(__UI_Type_TrackBar).DefaultHeight = 45
__UI_Type(__UI_Type_TrackBar).RestrictResize = __UI_CantResizeV
__UI_Type(16).Name = "ContextMenuPanel"
__UI_Type(16).TurnsInto = __UI_Type_MenuBar
__UI_Type(__UI_Type_ContextMenu).Name = "ContextMenuPanel"
__UI_Type(__UI_Type_ContextMenu).TurnsInto = __UI_Type_MenuBar
__UI_Type(17).Name = "Font"
__UI_Type(__UI_Type_Font).Name = "Font"
__UI_Type(18).Name = "ToggleSwitch"
__UI_Type(18).DefaultWidth = 40
__UI_Type(18).DefaultHeight = 17
__UI_Type(18).TurnsInto = __UI_Type_CheckBox
__UI_Type(__UI_Type_ToggleSwitch).Name = "ToggleSwitch"
__UI_Type(__UI_Type_ToggleSwitch).DefaultWidth = 40
__UI_Type(__UI_Type_ToggleSwitch).DefaultHeight = 17
__UI_Type(__UI_Type_ToggleSwitch).TurnsInto = __UI_Type_CheckBox
'--------------------------------------------------------------
CONST True = -1, False = 0
@ -980,9 +980,9 @@ SUB __UI_UpdateDisplay
END IF
'Control drawing
DIM icount AS LONG
FOR icount = 1 TO UBOUND(ControlDrawOrder)
i = ControlDrawOrder(icount)
DIM iCount AS LONG, ctxMenuCount AS LONG
FOR iCount = 1 TO UBOUND(ControlDrawOrder)
i = ControlDrawOrder(iCount)
IF Control(i).ID > 0 AND NOT Control(i).Hidden THEN
'Direct the drawing to the appropriate canvas (main or container)
IF Control(i).ParentID > 0 AND Control(i).Type <> __UI_Type_MenuItem THEN
@ -1066,6 +1066,14 @@ SUB __UI_UpdateDisplay
IF __UI_StateHasChanged THEN __UI_ValueChanged i
CASE __UI_Type_MenuBar
__UI_DrawMenuBar Control(i), ControlState
CASE __UI_Type_ContextMenu
IF __UI_DesignMode = True AND LEFT$(Control(i).Name, 5) <> "__UI_" THEN
ctxMenuCount = ctxMenuCount + 1
Control(i).Top = Control(__UI_FormID).Height - Control(i).Height - __UI_SnapDistanceFromForm
Control(i).Left = __UI_SnapDistanceFromForm + ((ctxMenuCount - 1) * Control(i).Width)
Control(i).Left = Control(i).Left + ((ctxMenuCount - 1) * __UI_SnapDistance)
__UI_DrawContextMenuHandle Control(i), ControlState
END IF
CASE __UI_Type_PictureBox
__UI_DrawPictureBox Control(i), ControlState
CASE __UI_Type_ToggleSwitch

View file

@ -34,7 +34,8 @@ DIM SHARED ViewMenuPreviewDetach AS LONG
DIM SHARED ViewMenuShowPositionAndSize AS LONG
DIM SHARED ViewMenuPreview AS LONG, ViewMenuLoadedFonts AS LONG
DIM SHARED InsertMenuMenuBar AS LONG, InsertMenuMenuItem AS LONG
DIM SHARED InsertMenuMenuBar AS LONG, InsertMenuContextMenu AS LONG
DIM SHARED InsertMenuMenuItem AS LONG
DIM SHARED OptionsMenuSnapLines AS LONG
DIM SHARED AlignMenuAlignLeft AS LONG
@ -316,6 +317,9 @@ SUB __UI_Click (id AS LONG)
CASE InsertMenuMenuItem
b$ = "NEWCONTROL>" + MKI$(__UI_Type_MenuItem) + "<END>"
Send Client, b$
CASE InsertMenuContextMenu
b$ = "NEWCONTROL>" + MKI$(__UI_Type_ContextMenu) + "<END>"
Send Client, b$
CASE ViewMenuPreviewDetach
PreviewAttached = NOT PreviewAttached
Control(id).Value = PreviewAttached

View file

@ -146,6 +146,9 @@ SUB __UI_LoadForm
__UI_NewID = __UI_NewControl(__UI_Type_MenuItem, "InsertMenuMenuBar", 96, 18, 0, 4, __UI_GetID("InsertMenu"))
SetCaption __UI_NewID, "Menu &Bar"
__UI_NewID = __UI_NewControl(__UI_Type_MenuItem, "InsertMenuContextMenu", 96, 18, 0, 4, __UI_GetID("InsertMenu"))
SetCaption __UI_NewID, "&Context Menu-"
__UI_NewID = __UI_NewControl(__UI_Type_MenuItem, "InsertMenuMenuItem", 101, 18, 0, 22, __UI_GetID("InsertMenu"))
SetCaption __UI_NewID, "Menu &Item"
Control(__UI_NewID).Disabled = True
@ -721,6 +724,7 @@ SUB __UI_AssignIDs
ViewMenuPreview = __UI_GetID("ViewMenuPreview")
ViewMenuLoadedFonts = __UI_GetID("ViewMenuLoadedFonts")
InsertMenuMenuBar = __UI_GetID("InsertMenuMenuBar")
InsertMenuContextMenu = __UI_GetID("InsertMenuContextMenu")
InsertMenuMenuItem = __UI_GetID("InsertMenuMenuItem")
OptionsMenuSnapLines = __UI_GetID("OptionsMenuSnapLines")
AlignMenuAlignLeft = __UI_GetID("AlignMenuAlignLeft")

View file

@ -1651,6 +1651,61 @@ SUB __UI_DrawMenuPanel (This AS __UI_ControlTYPE, ControlState AS _BYTE)
IF This.Canvas THEN _PUTIMAGE (This.Left, This.Top), This.Canvas
END SUB
'---------------------------------------------------------------------------------
SUB __UI_DrawContextMenuHandle (This AS __UI_ControlTYPE, ControlState AS _BYTE)
DIM PrevDest AS LONG
DIM i AS LONG
IF This.Redraw OR This.ControlState <> ControlState OR __UI_ForceRedraw THEN
'Last time this control was drawn it had a different state/caption, so it'll be redrawn
This.Redraw = False
This.ControlState = ControlState
IF This.Canvas <> 0 THEN
_FREEIMAGE This.Canvas
END IF
This.Width = 48
This.Height = 48
This.Canvas = _NEWIMAGE(This.Width, This.Height, 32)
PrevDest = _DEST
_DEST This.Canvas
_FONT This.Font
'------
SELECT CASE This.ControlState
'1 = Normal; 2 = Hover/focus; 3 = Mouse down; 4 = Disabled;
CASE 1
COLOR This.SelectedBackColor, This.SelectedForeColor
CASE 2
COLOR This.SelectedForeColor, This.SelectedBackColor
END SELECT
CLS
DIM m$, c$, x AS INTEGER, y AS INTEGER
m$ = RTRIM$(This.Name)
x = 2: y = 2
FOR i = 1 TO LEN(m$)
c$ = MID$(m$, i, 1)
__UI_PrintString x, y, c$
x = x + __UI_PrintWidth(c$)
IF x >= _WIDTH - __UI_PrintWidth(c$) THEN x = 2: y = y + uspacing
IF y > _HEIGHT THEN EXIT FOR
NEXT
i = 0
LINE (i, i)-STEP(This.Width - 1 - i * 2, This.Height - 1 - i * 2), This.BorderColor, B
'------
__UI_MakeHardwareImageFromCanvas This
_DEST PrevDest
END IF
IF This.Canvas THEN _PUTIMAGE (This.Left, This.Top), This.Canvas
END SUB
'---------------------------------------------------------------------------------
SUB __UI_DrawPictureBox (This AS __UI_ControlTYPE, ControlState AS _BYTE)
DIM PrevDest AS LONG, TheX AS INTEGER, TheY AS INTEGER