コード例 #1
0
ファイル: str.c プロジェクト: jhofstee/siwi2way
/**
 * Appends an integer to the string with specified format.
 *
 * @param str the string
 * @param val the integer to add
 * @param len the length of the char of the integer, e.g. 3 for 100. (max 10, 2147483647)
 * @param fmt the formatter for sprintf
 *
 * @note one digit is added to the length to always allow negative numbers
 * @note if the number doesn't fit ### will be added instead.
 */
size_t str_addIntFmt(Str *str, int val, int len, char const *fmt)
{
	char invalid[] = "###########";
	float max = 1;
	int n;

	if (len > 10)
		return 0;

	n = len;
	while (n--)
		max *= 10;

	if (abs(val) >= max)
	{
		invalid[len] = 0;
		return str_add(str, invalid);
	}

	str_fit(str, len + 1);	// 1 for sign

	if (str->error)
		return 0;

	return sprintf(str_cur(str), fmt, val);
}
コード例 #2
0
ファイル: str.c プロジェクト: jhofstee/siwi2way
/** Appends a char.
 *
 * @param str the string
 * @param value the char to append
 */
void str_addc(Str *str, char value)
{
	char *p;

	str_fit(str, 1);
	if (str->error)
		return;

	p = str_cur(str);
	p[0] = value;
	p[1] = 0;
	str_added(str, 1);
}
コード例 #3
0
ファイル: str.c プロジェクト: jhofstee/siwi2way
/**
 * This function behaves like sprintf, except that it appends to a Str.
 *
 * @param str		The Str to which the formatted string will be appended.
 * @param format	The printf style format string for the output.
 * @param ...		Any additional args required by format.
 *
 * @retval	TRUE	The output was appended.
 * @retval	FALSE	It was not possible to append the output.
 */
void str_vaddf(Str *str, char const *format, va_list varArgs)
{
	size_t length;

	/* get the length of the string */
	length = str_printfLength(format, varArgs);

	/* make sure there is memory enough */
	str_fit(str, length);
	if (str->error)
		return;

	/* now it can safely be added */
	vsprintf(str_cur(str), format, varArgs);
	str_added(str, length);
}
コード例 #4
0
ファイル: str.c プロジェクト: jhofstee/siwi2way
/** Appends a string.
 *
 * @param str the string
 * @param value the string to append
 */
size_t str_add(Str *str, char const *value)
{
	size_t len;
	char * p;

	if (value == NULL)
		return 0;

	len = strlen(value);
	str_fit(str, len);

	if (str->error)
		return 0;

	p = str_cur(str);
	memcpy(p, value, len);
	p[len] = 0;
	str_added(str, len);
	return len;
}
コード例 #5
0
ファイル: traynotify.cpp プロジェクト: RareHare/reactos
void TrayNotifyDlg::Refresh()
{
	///@todo refresh incrementally

	HiddenWindow hide(_tree_ctrl);

	TreeView_DeleteAllItems(_tree_ctrl);

	TV_INSERTSTRUCT tvi;

	tvi.hParent = 0;
	tvi.hInsertAfter = TVI_LAST;

	TV_ITEM& tv = tvi.item;
	tv.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;

	ResString str_cur(IDS_ITEMS_CUR);
	tv.pszText = str_cur.str();
	tv.iSelectedImage = tv.iImage = 0;	// IDI_DOT
	_hitemCurrent = TreeView_InsertItem(_tree_ctrl, &tvi);

	ResString str_conf(IDS_ITEMS_CONFIGURED);
	tv.pszText = str_conf.str();
	tv.iSelectedImage = tv.iImage = 2;	// IDI_DOT_RED
	_hitemConfig = TreeView_InsertItem(_tree_ctrl, &tvi);

	tvi.hParent = _hitemCurrent;

	ResString str_visible(IDS_ITEMS_VISIBLE);
	tv.pszText = str_visible.str();
	tv.iSelectedImage = tv.iImage = 0;	// IDI_DOT
	_hitemCurrent_visible = TreeView_InsertItem(_tree_ctrl, &tvi);

	ResString str_hidden(IDS_ITEMS_HIDDEN);
	tv.pszText = str_hidden.str();
	tv.iSelectedImage = tv.iImage = 1;	// IDI_DOT_TRANS
	_hitemCurrent_hidden = TreeView_InsertItem(_tree_ctrl, &tvi);

	if (_pNotifyArea) {
		_info.clear();

		tv.mask |= TVIF_PARAM;

		WindowCanvas canvas(_hwnd);

		 // insert current (visible and hidden) items
		for(NotifyIconMap::const_iterator it=_pNotifyArea->_icon_map.begin(); it!=_pNotifyArea->_icon_map.end(); ++it) {
			const NotifyInfo& entry = it->second;

			InsertItem(entry._dwState&NIS_HIDDEN? _hitemCurrent_hidden: _hitemCurrent_visible, TVI_LAST, entry, canvas);
		}

		 // insert configured items in tree view
		const NotifyIconCfgList& cfg = _pNotifyArea->_cfg;
		for(NotifyIconCfgList::const_iterator it=cfg.begin(); it!=cfg.end(); ++it) {
			const NotifyIconConfig& cfg_entry = *it;

			HICON hicon = 0;

			if (!cfg_entry._modulePath.empty()) {
				if ((int)ExtractIconEx(cfg_entry._modulePath, 0, NULL, &hicon, 1) <= 0)
					hicon = 0;

				if (!hicon) {
					SHFILEINFO sfi;

					if (SHGetFileInfo(cfg_entry._modulePath, 0, &sfi, sizeof(sfi), SHGFI_ICON|SHGFI_SMALLICON))
						hicon = sfi.hIcon;
				}
			}

			InsertItem(_hitemConfig, TVI_SORT, cfg_entry, canvas, hicon, cfg_entry._mode);

			if (hicon)
				DestroyIcon(hicon);
		}

		CheckDlgButton(_hwnd, ID_SHOW_HIDDEN_ICONS, _pNotifyArea->_show_hidden? BST_CHECKED: BST_UNCHECKED);
	}

	TreeView_Expand(_tree_ctrl, _hitemCurrent_visible, TVE_EXPAND);
	TreeView_Expand(_tree_ctrl, _hitemCurrent_hidden, TVE_EXPAND);
	TreeView_Expand(_tree_ctrl, _hitemCurrent, TVE_EXPAND);
	TreeView_Expand(_tree_ctrl, _hitemConfig, TVE_EXPAND);

	TreeView_EnsureVisible(_tree_ctrl, _hitemCurrent_visible);
}