| 9884 | |
| 9885 | |
| 9886 | void GuiType::ControlUpdateCurrentTab(GuiControlType &aTabControl, bool aFocusFirstControl) |
| 9887 | // Handles the selection of a new tab in a tab control. |
| 9888 | { |
| 9889 | int curr_tab_index = TabCtrl_GetCurSel(aTabControl.hwnd); |
| 9890 | // If there's no tab selected, any controls contained by the tab control should be hidden. |
| 9891 | // This can happen if all tabs are removed, such as by GuiControl,,TabCtl,| |
| 9892 | //if (curr_tab_index == -1) // No tab is selected. |
| 9893 | // return; |
| 9894 | |
| 9895 | // Fix for v1.0.23: |
| 9896 | // If the tab control lacks the visible property, hide all its controls on all its tabs. |
| 9897 | // Don't use IsWindowVisible() because that would say that tab is hidden just because the parent |
| 9898 | // window is hidden, which is not desirable because then when the parent is shown, the shower |
| 9899 | // would always have to remember to call us. This "hide all" behavior is done here rather than |
| 9900 | // attempting to "rely on everyone else to do their jobs of keeping the controls in the right state" |
| 9901 | // because it improves maintainability: |
| 9902 | DWORD tab_style = GetWindowLong(aTabControl.hwnd, GWL_STYLE); |
| 9903 | bool hide_all = !(tab_style & WS_VISIBLE); // Regardless of whether mHwnd is visible or not. |
| 9904 | bool disable_all = (tab_style & WS_DISABLED); // Don't use IsWindowEnabled() because it might return false if parent is disabled? |
| 9905 | // Say that the focus was already set correctly if the entire tab control is hidden or caller said |
| 9906 | // not to focus it: |
| 9907 | bool focus_was_set; |
| 9908 | bool parent_is_visible = IsWindowVisible(mHwnd); |
| 9909 | bool parent_is_visible_and_not_minimized = parent_is_visible && !IsIconic(mHwnd); |
| 9910 | if (hide_all || disable_all) |
| 9911 | focus_was_set = true; // Tell the below not to set focus, since all tab controls are hidden or disabled. |
| 9912 | else if (aFocusFirstControl) // Note that SetFocus() has an effect even if the parent window is hidden. i.e. next time the window is shown, the control will be focused. |
| 9913 | focus_was_set = false; // Tell it to focus the first control on the new page. |
| 9914 | else |
| 9915 | { |
| 9916 | HWND focused_hwnd; |
| 9917 | GuiControlType *focused_control; |
| 9918 | // If the currently focused control is somewhere in this tab control (but not the tab control |
| 9919 | // itself, because arrow-key navigation relies on tabs stay focused while the user is pressing |
| 9920 | // left and right-arrow), override the fact that aFocusFirstControl is false so that when the |
| 9921 | // page changes, its first control will be focused: |
| 9922 | focus_was_set = !( parent_is_visible && (focused_hwnd = GetFocus()) |
| 9923 | && (focused_control = FindControl(focused_hwnd)) |
| 9924 | && focused_control->tab_control_index == aTabControl.tab_index ); |
| 9925 | } |
| 9926 | |
| 9927 | bool will_be_visible, will_be_enabled, has_visible_style, has_enabled_style, member_of_current_tab, control_state_altered; |
| 9928 | DWORD style; |
| 9929 | RECT rect, tab_rect; |
| 9930 | POINT *rect_pt = (POINT *)▭ // i.e. have rect_pt be an array of the two points already within rect. |
| 9931 | |
| 9932 | GetWindowRect(aTabControl.hwnd, &tab_rect); |
| 9933 | |
| 9934 | // Update: Don't do the below because it causes a tab to look focused even when it isn't in cases |
| 9935 | // where a control was focused while drawing was suspended. This is because the below omits the |
| 9936 | // tab rows themselves from the InvalidateRect() further below: |
| 9937 | // Tabs on left (TCS_BUTTONS only) require workaround, at least on XP. Otherwise tab_rect.left will be |
| 9938 | // much too large. Because of this, include entire tab rect if it can't be "deflated" reliably: |
| 9939 | //if (!(tab_style & TCS_VERTICAL) || (tab_style & TCS_RIGHT) || !(tab_style & TCS_BUTTONS)) |
| 9940 | // TabCtrl_AdjustRect(aTabControl.hwnd, FALSE, &tab_rect); // Reduce it to just the area without the tabs, since the tabs have already been redrawn. |
| 9941 | |
| 9942 | HWND tab_dialog = (HWND)GetProp(aTabControl.hwnd, _T("ahk_dlg")); |
| 9943 | if (tab_dialog) |