/*********************************************************************** * UPDOWN_GetBuddyInt * Tries to read the pos from the buddy window and if it succeeds, * it stores it in the control's CurVal * returns: * TRUE - if it read the integer from the buddy successfully * FALSE - if an error occurred */ static BOOL UPDOWN_GetBuddyInt (UPDOWN_INFO *infoPtr) { WCHAR txt[20], sep, *src, *dst; int newVal; if (!((infoPtr->dwStyle & UDS_SETBUDDYINT) && IsWindow(infoPtr->Buddy))) return FALSE; /*if the buddy is a list window, we must set curr index */ if (UPDOWN_IsBuddyListbox(infoPtr)) { newVal = SendMessageW(infoPtr->Buddy, LB_GETCARETINDEX, 0, 0); if(newVal < 0) return FALSE; } else { /* we have a regular window, so will get the text */ /* note that a zero-length string is a legitimate value for 'txt', * and ought to result in a successful conversion to '0'. */ if (GetWindowTextW(infoPtr->Buddy, txt, COUNT_OF(txt)) < 0) return FALSE; sep = UPDOWN_GetThousandSep(); /* now get rid of the separators */ for(src = dst = txt; *src; src++) if(*src != sep) *dst++ = *src; *dst = 0; /* try to convert the number and validate it */ newVal = strtolW(txt, &src, infoPtr->Base); if(*src || !UPDOWN_InBounds (infoPtr, newVal)) return FALSE; } TRACE("new value(%d) from buddy (old=%d)\n", newVal, infoPtr->CurVal); infoPtr->CurVal = newVal; return TRUE; }
/*********************************************************************** * UPDOWN_SetBuddyInt * Tries to set the pos to the buddy window based on current pos * returns: * TRUE - if it set the caption of the buddy successfully * FALSE - if an error occurred */ static BOOL UPDOWN_SetBuddyInt (const UPDOWN_INFO *infoPtr) { static const WCHAR fmt_hex[] = { '0', 'x', '%', '0', '4', 'X', 0 }; static const WCHAR fmt_dec_oct[] = { '%', 'd', '\0' }; const WCHAR *fmt; WCHAR txt[20], txt_old[20] = { 0 }; int len; if (!((infoPtr->Flags & FLAG_BUDDYINT) && IsWindow(infoPtr->Buddy))) return FALSE; TRACE("set new value(%d) to buddy.\n", infoPtr->CurVal); /*if the buddy is a list window, we must set curr index */ if (UPDOWN_IsBuddyListbox(infoPtr)) { return SendMessageW(infoPtr->Buddy, LB_SETCURSEL, infoPtr->CurVal, 0) != LB_ERR; } /* Regular window, so set caption to the number */ fmt = (infoPtr->Base == 16) ? fmt_hex : fmt_dec_oct; len = wsprintfW(txt, fmt, infoPtr->CurVal); /* Do thousands separation if necessary */ if ((infoPtr->Base == 10) && !(infoPtr->dwStyle & UDS_NOTHOUSANDS) && (len > 3)) { WCHAR tmp[COUNT_OF(txt)], *src = tmp, *dst = txt; WCHAR sep = UPDOWN_GetThousandSep(); int start = len % 3; memcpy(tmp, txt, sizeof(txt)); if (start == 0) start = 3; dst += start; src += start; for (len=0; *src; len++) { if (len % 3 == 0) *dst++ = sep; *dst++ = *src++; } *dst = 0; } /* if nothing changed exit earlier */ GetWindowTextW(infoPtr->Buddy, txt_old, sizeof(txt_old)/sizeof(WCHAR)); if (lstrcmpiW(txt_old, txt) == 0) return FALSE; return SetWindowTextW(infoPtr->Buddy, txt); }
/*********************************************************************** * UPDOWN_SetBuddyInt * Tries to set the pos to the buddy window based on current pos * returns: * TRUE - if it set the caption of the buddy successfully * FALSE - if an error occurred */ static BOOL UPDOWN_SetBuddyInt (const UPDOWN_INFO *infoPtr) { WCHAR fmt[3] = { '%', 'd', '\0' }; WCHAR txt[20]; int len; if (!((infoPtr->dwStyle & UDS_SETBUDDYINT) && IsWindow(infoPtr->Buddy))) return FALSE; TRACE("set new value(%d) to buddy.\n", infoPtr->CurVal); /*if the buddy is a list window, we must set curr index */ if (UPDOWN_IsBuddyListbox(infoPtr)) { return SendMessageW(infoPtr->Buddy, LB_SETCURSEL, infoPtr->CurVal, 0) != LB_ERR; } /* Regular window, so set caption to the number */ if (infoPtr->Base == 16) fmt[1] = 'X'; len = wsprintfW(txt, fmt, infoPtr->CurVal); /* Do thousands separation if necessary */ if (!(infoPtr->dwStyle & UDS_NOTHOUSANDS) && (len > 3)) { WCHAR tmp[COUNT_OF(txt)], *src = tmp, *dst = txt; WCHAR sep = UPDOWN_GetThousandSep(); int start = len % 3; memcpy(tmp, txt, sizeof(txt)); if (start == 0) start = 3; dst += start; src += start; for (len=0; *src; len++) { if (len % 3 == 0) *dst++ = sep; *dst++ = *src++; } *dst = 0; } return SetWindowTextW(infoPtr->Buddy, txt); }