MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / ControlSetEnabled

Method ControlSetEnabled

source/script_gui.cpp:1067–1116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1065
1066
1067void GuiType::ControlSetEnabled(GuiControlType &aControl, bool aEnabled)
1068{
1069 GuiControlType *tab_control;
1070 int selection_index;
1071
1072 // GUI_CONTROL_ATTRIB_EXPLICITLY_DISABLED is maintained for use with tab controls. It allows controls
1073 // on inactive tabs to be marked for later enabling. It also allows explicitly disabled controls to
1074 // stay disabled even when their tab/page becomes active. It is updated unconditionally for simplicity
1075 // and maintainability.
1076 if (aEnabled)
1077 aControl.attrib &= ~GUI_CONTROL_ATTRIB_EXPLICITLY_DISABLED;
1078 else
1079 aControl.attrib |= GUI_CONTROL_ATTRIB_EXPLICITLY_DISABLED;
1080 if (tab_control = FindTabControl(aControl.tab_control_index)) // It belongs to a tab control that already exists.
1081 {
1082 if (GetWindowLong(tab_control->hwnd, GWL_STYLE) & WS_DISABLED) // But its tab control is disabled...
1083 return;
1084 selection_index = TabCtrl_GetCurSel(tab_control->hwnd);
1085 if (selection_index != aControl.tab_index && selection_index != -1)
1086 // There is no current tab/page or the one selected is not this control's:
1087 // Do not disable or re-enable the control in this case.
1088 // v1.0.48.04: Above now also checks for -1, which is a tab control containing zero tabs/pages.
1089 // The controls on such a tab control might be wrongly/inadvertently visible because
1090 // ControlUpdateCurrentTab() isn't capable of handling that situation. Since fixing
1091 // ControlUpdateCurrentTab() would reduce backward compatibility -- and in case anyone is
1092 // using tabless tab controls for anything -- it seems best to allow these "wrongly visible"
1093 // controls to be explicitly manipulated by GuiControl Enable/Disable and Hide/Show.
1094 // UPDATE: ControlUpdateCurrentTab() has been fixed, so the controls won't be visible
1095 // unless the script specifically made them so. The check is kept in case it is of
1096 // some use. Prior to the fix, the controls would have only been visible if the tab
1097 // control previously had a tab but it was deleted, since controls are created in a
1098 // hidden state if the tab they are on is not selected.
1099 return;
1100 }
1101
1102 // L23: Restrict focus workaround to when the control is/was actually focused. Fixes a bug introduced by L13: enabling or disabling a control caused the active Edit control to reselect its text.
1103 bool gui_control_was_focused = GetForegroundWindow() == mHwnd && GetFocus() == aControl.hwnd;
1104
1105 // Since above didn't return, act upon the enabled/disable:
1106 EnableWindow(aControl.hwnd, aEnabled);
1107
1108 // L23: Only if EnableWindow removed the keyboard focus entirely, reset the focus.
1109 if (gui_control_was_focused && !GetFocus())
1110 SetFocus(mHwnd);
1111
1112 if (aControl.type == GUI_CONTROL_TAB) // This control is a tab control.
1113 // Update the control so that its current tab's controls will all be enabled or disabled (now
1114 // that the tab control itself has just been enabled or disabled):
1115 ControlUpdateCurrentTab(aControl, false);
1116}
1117
1118
1119

Callers 1

InvokeMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected