| 7710 | |
| 7711 | |
| 7712 | ResultType GuiType::Submit(ResultToken &aResultToken, bool aHideIt) |
| 7713 | // Caller has ensured that all controls have valid, non-NULL hwnds: |
| 7714 | { |
| 7715 | if (!mHwnd) |
| 7716 | return FAIL; // Shouldn't be possible. |
| 7717 | |
| 7718 | Object* ret = Object::Create(); |
| 7719 | if (!ret) |
| 7720 | _o_throw_oom; |
| 7721 | |
| 7722 | // Handle all non-radio controls: |
| 7723 | GuiIndexType u; |
| 7724 | for (u = 0; u < mControlCount; ++u) |
| 7725 | { |
| 7726 | GuiControlType& control = *mControl[u]; // For performance and readability. |
| 7727 | if (control.name == NULL) // Skip the control if it does not have a name |
| 7728 | continue; |
| 7729 | |
| 7730 | if (control.HasSubmittableValue()) |
| 7731 | { |
| 7732 | TCHAR temp_buf[MAX_NUMBER_SIZE]; |
| 7733 | ResultToken value; |
| 7734 | value.InitResult(temp_buf); |
| 7735 | |
| 7736 | if ( !ControlGetContents(value, control, Submit_Mode) |
| 7737 | || !ret->SetOwnProp(control.name, value) ) |
| 7738 | goto outofmem; |
| 7739 | } |
| 7740 | } |
| 7741 | |
| 7742 | // Handle GUI_CONTROL_RADIO separately so that any radio group that has a single name |
| 7743 | // to share among all its members can be given special treatment: |
| 7744 | int group_radios = 0; // The number of radio buttons in the current group. |
| 7745 | int group_radios_with_name = 0; // The number of the above that have a name. |
| 7746 | LPTSTR group_name = NULL; // The last-found name of the current group. |
| 7747 | int selection_number = 0; // Which radio in the current group is selected (0 if none). |
| 7748 | LPTSTR output_name; |
| 7749 | |
| 7750 | // The below uses <= so that it goes one beyond the limit. This allows the final radio group |
| 7751 | // (if any) to be noticed in the case where the very last control in the window is a radio button. |
| 7752 | // This is because in such a case, there is no "terminating control" having the WS_GROUP style: |
| 7753 | for (u = 0; u <= mControlCount; ++u) |
| 7754 | { |
| 7755 | GuiControlType& control = *mControl[u]; // For performance and readability. |
| 7756 | |
| 7757 | // WS_GROUP is used to determine where one group ends and the next begins -- rather than using |
| 7758 | // seeing if the control's type is radio -- because in the future it may be possible for a radio |
| 7759 | // group to have other controls interspersed within it and yet still be a group for the purpose |
| 7760 | // of "auto radio button (only one selected at a time)" behavior: |
| 7761 | if (u == mControlCount || GetWindowLong(control.hwnd, GWL_STYLE) & WS_GROUP) // New group. Relies on short-circuit boolean order. |
| 7762 | { |
| 7763 | // If the prior group had more than one radio in it but only one had a name, that |
| 7764 | // name is shared among all radios (as of v1.0.20). Otherwise: |
| 7765 | // 1) If it has zero radios and/or zero names: already fully handled by other logic. |
| 7766 | // 2) It has multiple names: the default values assigned in the loop are simply retained. |
| 7767 | // 3) It has exactly one radio in it and that radio has a name: same as above. |
| 7768 | if (group_radios_with_name == 1 && group_radios > 1) |
| 7769 | { |
nothing calls this directly
no test coverage detected