BOOL wbIsWBObj(void *pwbo, BOOL bShowErrors)
{
	if(!pwbo) {
		if(bShowErrors)
			wbError(__FUNCTION__, MB_ICONWARNING, "NULL WinBinder object");
		return FALSE;
	}

	// Is pwbo a valid memory address?

	if(IsBadReadPtr(pwbo, sizeof(WBOBJ))) {
		if(bShowErrors)
			wbError(__FUNCTION__, MB_ICONWARNING, "Invalid memory address");
//		printf("%d\n", pwbo);
		return FALSE;
	}

	// A Windows or menu handle is not a WinBinder object

	if(IsWindow(pwbo) || IsMenu(pwbo)) {
		if(bShowErrors)
			wbError(__FUNCTION__, MB_ICONWARNING, "Not a WinBinder object");
		return FALSE;
	}

	// Does it have a valid handle?

	{
		PWBOBJ pwboTest = wbMalloc(sizeof(WBOBJ));
		if(pwboTest) {
			CopyMemory(pwboTest, pwbo, sizeof(WBOBJ));

			if(!pwboTest->hwnd) {
				wbFree(pwboTest);
				if(bShowErrors)
					wbError(__FUNCTION__, MB_ICONWARNING, "NULL WinBinder object handle");
				return FALSE;
			}
			wbFree(pwboTest);
		}
	}

	if(IsMenu((HMENU)((PWBOBJ)pwbo)->hwnd))
		return TRUE;

	if(IsWindow((HWND)((PWBOBJ)pwbo)->hwnd))
		return TRUE;

	if(bShowErrors)
		wbError(__FUNCTION__, MB_ICONWARNING, "Invalid WinBinder object");

	return FALSE;
}
Beispiel #2
0
static void * wbImport(const char * file, int * resRows, int * resColumns, const char * type) {
    void * data, * res;
    wbImport_t imp;
    size_t sz;
    int columns = 0, rows = 0;
    wbImportKind_t kind;

    if (file == NULL) {
        fprintf(stderr, "Failed to import file.\n");
        wbExit();
    }

    kind = _parseImportExtension(file);

    wbAssert(kind != wbImportKind_unknown);

    imp = wbImport_open(file, kind);
    if (wbString_sameQ(type, "Real")) {
        data = wbImport_readAsReal(imp);
        sz = sizeof(wbReal_t);
    } else {
        data = wbImport_readAsInteger(imp);
        sz = sizeof(int);
    }

    if (kind == wbImportKind_csv || kind == wbImportKind_tsv) {
        rows = wbImportCSV_getRowCount(wbImport_getCSV(imp));
        columns = wbImportCSV_getColumnCount(wbImport_getCSV(imp));
    } else if (kind == wbImportKind_raw) {
        rows = wbImportRaw_getRowCount(wbImport_getRaw(imp));
        columns = wbImportRaw_getColumnCount(wbImport_getRaw(imp));
    }

    if (resRows != NULL) {
        *resRows = rows;
    }

    if (resColumns != NULL) {
        *resColumns = columns;
    }

    res = wbMalloc(sz * rows * columns);
    memcpy(res, data, sz * rows * columns);

    wbImport_close(imp);

    return res;
}
Beispiel #3
0
TCHAR * Utf82WideChar(const char *str, int len)
{
	TCHAR *wstr = 0;
	int wlen = 0;
	if (!str)
		return NULL;

	if (len <= 0)
		len = -1; //len = strlen(str);

	wlen = MultiByteToWideChar(CP_UTF8, 0, str, len, wstr, 0);

	wstr = wbMalloc(sizeof(TCHAR)*(wlen+1));
	wstr[wlen] = '\0';

	MultiByteToWideChar(CP_UTF8, 0, str, len, wstr, wstr + 1);
	return wstr;
}
PWBOBJ wbCreateToolbar(PWBOBJ pwboParent, PWBITEM pitem[], int nItems, int nBtnWidth, int nBtnHeight, HBITMAP hbm)
{
	int i;
	PWBOBJ pwbo;
	HWND hToolbar;

	if(!pwboParent || !pwboParent->hwnd || !IsWindow(pwboParent->hwnd))
		return NULL;

	// Create the toolbar

	hToolbar = CreateToolbar((HWND)pwboParent->hwnd, nItems, nBtnWidth, nBtnHeight, hbm);
	if(!hToolbar) {
		wbError(__FUNCTION__, MB_ICONWARNING, "Could not create toolbar");
		return NULL;
	}

	pwbo = wbMalloc(sizeof(WBOBJ));
	pwbo->hwnd = hToolbar;
	pwbo->id = 0;
	pwbo->uClass = ToolBar;
	pwbo->item = -1;
	pwbo->subitem = -1;
	pwbo->style = 0;
	pwbo->pszCallBackFn = NULL;
	pwbo->pszCallBackObj = NULL;
	pwbo->lparam = 0;
	pwbo->parent = pwboParent;

	for(i = 0; i < nItems; i++) {
		if(!pitem[i] || !pitem[i]->id)
			CreateToolbarButton(hToolbar, 0, i, NULL);				// Separator
		else
			CreateToolbarButton(hToolbar, pitem[i]->id, pitem[i]->index, pitem[i]->pszHint);
	}

	SetWindowLong(pwbo->hwnd, GWL_USERDATA, (LONG)pwbo);

	return pwbo;
}
Beispiel #5
0
char *WideChar2Utf8(LPCTSTR wcs, int *plen)
{
	char *str = 0;
	int str_len = 0;

	if (!wcs)
		return NULL;

	str_len = WideCharToMultiByte(CP_UTF8, 0, wcs, -1, str, 0, NULL, NULL);
	if (str_len == 0)
		return NULL;

	str = wbMalloc(str_len+1);
	str[str_len] = '\0';
	str[str_len-1] = '\0';

	if (plen)
		*plen = WideCharToMultiByte(CP_UTF8, 0, wcs, -1, str, str_len, NULL, NULL);
	else
		WideCharToMultiByte(CP_UTF8, 0, wcs, -1, str, str_len, NULL, NULL);
	return str;
}
Beispiel #6
0
PWBOBJ wbCreateMenu(PWBOBJ pwboParent, PWBITEM pitem[], int nItems)
{
	int i;
	MENUITEMINFO mi;
	PWBOBJ pwbo;
	HMENU hMenu, hPopup = NULL;
	LPCTSTR pszLastPopup = NULL;

	if(!pwboParent || !pwboParent->hwnd || !IsWindow(pwboParent->hwnd))
		return NULL;

	// Start building the menu

	hMenu = CreateMenu();

	for(i = 0; i < nItems; i++) {

		if(!pitem[i]) {

			AppendMenu(hPopup, MF_SEPARATOR, 0, NULL);

		} else if(!pitem[i]->id) {

			if(pitem[i]->pszCaption && *pitem[i]->pszCaption) {		// Attach a pop-up menu to a top-level menu
				if(hPopup && pszLastPopup) {
					AppendMenu(hMenu, MF_POPUP, (UINT)hPopup, pszLastPopup);
				}
				hPopup = CreateMenu();
				pszLastPopup = pitem[i]->pszCaption;
			} else {												// Separator
				AppendMenu(hPopup, MF_SEPARATOR, 0, NULL);
			}

		} else {

			if(pitem[i]->pszCaption && *pitem[i]->pszCaption) {		// Create a submenu item
				AppendMenu(hPopup, MF_STRING, pitem[i]->id, pitem[i]->pszCaption);
				if(pitem[i]->pszImage && *pitem[i]->pszImage) {
					HBITMAP hImage = wbLoadImage(pitem[i]->pszImage, 0, 0);

					if(hImage)
						SetMenuItemBitmaps(hPopup, pitem[i]->id, MF_BYCOMMAND, hImage, hImage);
				}
			}
		}
	}

	// Create last first-level menu

	if(hPopup && pszLastPopup) {
		AppendMenu(hMenu, MF_POPUP, (UINT)hPopup, pszLastPopup);
	}

	// Attach the menu to the window

	pwbo = wbMalloc(sizeof(WBOBJ));
	pwbo->hwnd = (HWND)hMenu;
	pwbo->id = 0;
	pwbo->uClass = Menu;
	pwbo->item = -1;
	pwbo->subitem = -1;
	pwbo->style = 0;
	pwbo->pszCallBackFn = NULL;
	pwbo->pszCallBackObj = NULL;
	pwbo->lparam = 0;
	pwbo->parent = pwboParent;

	// ********* DOESN'T WORK
	mi.dwItemData = (DWORD)pwbo;
	SetMenuItemInfo((HMENU)pwbo->hwnd, 0, TRUE, &mi);
	// ********* DOESN'T WORK

	SetMenu(pwboParent->hwnd, hMenu);
	return pwbo;
}