table_cell_t* table_get_cell(table_t* table, WORD col, WORD row) { TABLE_TRACE("table_get_cell(%p, %hd, %hd)", table, col, row); if(MC_ERR(col >= table->col_count && col != MC_TABLE_HEADER)) { MC_TRACE("table_get_cell: Column ID %hd does not exist", col); SetLastError(ERROR_INVALID_PARAMETER); return NULL; } if(MC_ERR(row >= table->row_count && row != MC_TABLE_HEADER)) { MC_TRACE("table_get_cell: Row ID %hd does not exist", row); SetLastError(ERROR_INVALID_PARAMETER); return NULL; } if(MC_ERR(col == MC_TABLE_HEADER && row == MC_TABLE_HEADER)) { MC_TRACE("table_get_cell: The \"dead\" cell requested."); SetLastError(ERROR_INVALID_PARAMETER); return NULL; } if(col == MC_TABLE_HEADER) return &table->rows[row]; else if(row == MC_TABLE_HEADER) return &table->cols[col]; else return table_cell(table, col, row); }
static BSTR html_bstr(const void* from_str, int from_type) { WCHAR* str_w; BSTR str_b; if(from_str == NULL) { /* According to MSDN, BSTR should never be NULL. */ from_str = L""; from_type = MC_STRW; } if(from_type == MC_STRW) { str_w = (WCHAR*) from_str; } else { char* str_a; MC_ASSERT(from_type == MC_STRA); str_a = (char*) from_str; str_w = (WCHAR*) mc_str(str_a, from_type, MC_STRW); if(MC_ERR(str_w == NULL)) { MC_TRACE("html_bstr: mc_str() failed."); return NULL; } } str_b = html_SysAllocString(str_w); if(MC_ERR(str_b == NULL)) MC_TRACE("html_bstr: SysAllocString() failed."); if(str_w != from_str) free(str_w); return str_b; }
table_t* table_create(WORD col_count, WORD row_count) { table_t* table; TABLE_TRACE("table_create(%hd, %hd)", col_count, row_count); table = (table_t*) malloc(sizeof(table_t)); if(MC_ERR(table == NULL)) { MC_TRACE("table_create: malloc() failed."); return NULL; } table->refs = 1; table->col_count = 0; table->row_count = 0; table->cols = NULL; table->rows = NULL; table->cells = NULL; view_list_init(&table->vlist); if(MC_ERR(table_resize(table, col_count, row_count) != 0)) { MC_TRACE("table_create: table_resize() failed."); free(table); return NULL; } return table; }
static int imgview_load_resource(imgview_t* iv, HINSTANCE instance, void* res_name, BOOL unicode) { gdix_Image* image; if(res_name != NULL) { TCHAR* tmp; if(unicode == MC_IS_UNICODE) { tmp = res_name; } else { tmp = mc_str(res_name, (unicode ? MC_STRW : MC_STRA), MC_STRT); if(MC_ERR(tmp == NULL)) { MC_TRACE("imgview_load_resource: mc_str() failed."); return -1; } } image = imgview_load_image_from_resource(instance, res_name); if(tmp != res_name) free(tmp); if(MC_ERR(image == NULL)) { MC_TRACE("imgview_load_resource: imgview_load_image_from_resource() failed"); return -1; } } else { image = NULL; } if(iv->image) gdix_DisposeImage(iv->image); iv->image = image; return 0; }
static int imgview_load_file(imgview_t* iv, void* path, BOOL unicode) { gdix_Image* image; if(path != NULL) { WCHAR* tmp; if(unicode) { tmp = path; } else { tmp = mc_str(path, MC_STRA, MC_STRW); if(MC_ERR(tmp == NULL)) { MC_TRACE("imgview_load_file: mc_str() failed."); return -1; } } image = imgview_load_image_from_file(tmp); if(tmp != path) free(tmp); if(MC_ERR(image == NULL)) { MC_TRACE("imgview_load_file: imgview_load_image_from_file() failed"); return -1; } } else { image = NULL; } if(iv->image) gdix_DisposeImage(iv->image); iv->image = image; return 0; }
static BSTR html_bstr(const void* from_str, int from_type) { WCHAR* str_w; BSTR str_b; if(from_str == NULL) return NULL; if(from_type == MC_STRW) { str_w = (WCHAR*) from_str; if(str_w[0] == L'\0') return NULL; } else { char* str_a; MC_ASSERT(from_type == MC_STRA); str_a = (char*) from_str; if(str_a[0] == '\0') return NULL; str_w = (WCHAR*) mc_str(str_a, from_type, MC_STRW); if(MC_ERR(str_w == NULL)) { MC_TRACE("html_bstr: mc_str() failed."); return NULL; } } str_b = html_SysAllocString(str_w); if(MC_ERR(str_b == NULL)) MC_TRACE("html_bstr: SysAllocString() failed."); if(from_type == MC_STRA) free(str_w); return str_b; }
void* xcom_init_create(const CLSID* clsid, DWORD context, const IID* iid) { void* obj; HRESULT hr; redo: switch(xcom_mode) { case XCOM_MODE_APP: /* The application already initialized COM so we do not manage it * at all and just reuse app's apartment. */ hr = CoCreateInstance(clsid, NULL, context, iid, &obj); if(MC_ERR(FAILED(hr))) { MC_TRACE("xcom_create_init: CoCreateInstance(1) failed. [0x%lx]", hr); return NULL; } return obj; case XCOM_MODE_MCTRL: /* We are responsible to initialize COM whenever we want to use * it. */ hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); if(MC_ERR(FAILED(hr))) { MC_TRACE("xcom_create_init: CoInitializeEx() failed. [0x%lx]", hr); return NULL; } hr = CoCreateInstance(clsid, NULL, context, iid, &obj); if(MC_ERR(FAILED(hr))) { MC_TRACE("xcom_create_init: CoCreateInstance(2) failed. [0x%lx]", hr); CoUninitialize(); return NULL; } return obj; case XCOM_MODE_UNKNOWN: EnterCriticalSection(&xcom_lock); if(xcom_mode != XCOM_MODE_UNKNOWN) { /* Resolve a race. */ LeaveCriticalSection(&xcom_lock); goto redo; } hr = CoCreateInstance(clsid, NULL, context, iid, &obj); if(SUCCEEDED(hr)) { xcom_mode = XCOM_MODE_APP; } else if(hr == CO_E_NOTINITIALIZED) { xcom_mode = XCOM_MODE_MCTRL; } else { MC_TRACE("xcom_create_init: CoCreateInstance(3) failed. [0x%lx]", hr); obj = NULL; } LeaveCriticalSection(&xcom_lock); if(hr == CO_E_NOTINITIALIZED) goto redo; return obj; default: MC_UNREACHABLE; return NULL; } }
int table_set_cell_data(table_t* table, WORD col, WORD row, MC_TABLECELL* cell_data, BOOL unicode) { table_cell_t* cell; table_refresh_detail_t refresh_detail; TABLE_TRACE("table_set_cell_data(%p, %hd, %hd, %p, %s)", table, col, row, cell_data, (unicode ? "unicode" : "ansi")); cell = table_get_cell(table, col, row); if(MC_ERR(cell == NULL)) { MC_TRACE("table_set_cell_data: table_get_cell() failed."); return -1; } if(MC_ERR(cell_data->fMask & ~MC_TCMF_ALL)) { MC_TRACE("table_set_cell_data: Unsupported pCell->fMask 0x%x", cell_data->fMask); SetLastError(ERROR_INVALID_PARAMETER); return -1; } /* Set the cell */ if(cell_data->fMask & MC_TCMF_TEXT) { TCHAR* str; if(cell_data->pszText == MC_LPSTR_TEXTCALLBACK) { str = MC_LPSTR_TEXTCALLBACK; } else if(cell_data->pszText != NULL) { str = mc_str(cell_data->pszText, (unicode ? MC_STRW : MC_STRA), MC_STRT); if(MC_ERR(str == NULL)) { MC_TRACE("table_set_cell_data: mc_str() failed."); return -1; } } else { str = NULL; } table_cell_clear(cell); cell->text = str; } if(cell_data->fMask & MC_TCMF_PARAM) cell->lp = cell_data->lParam; if(cell_data->fMask & MC_TCMF_FLAGS) cell->flags = cell_data->dwFlags; /* Refresh */ refresh_detail.event = TABLE_CELL_CHANGED; refresh_detail.param[0] = col; refresh_detail.param[1] = row; table_refresh(table, &refresh_detail); return 0; }
static menubar_t* menubar_nccreate(HWND win, CREATESTRUCT *cs) { menubar_t* mb; TCHAR parent_class[16]; MENUBAR_TRACE("menubar_nccreate(%p, %p)", win, cs); mb = (menubar_t*) malloc(sizeof(menubar_t)); if(MC_ERR(mb == NULL)) { MC_TRACE("menubar_nccreate: malloc() failed."); return NULL; } memset(mb, 0, sizeof(menubar_t)); mb->win = win; /* Lets be a little friendly to the app. developers: If the parent is * ReBar control, lets send WM_NOTIFY/WM_COMMAND to the ReBar's parent * as ReBar really is not interested in it, and embedding the menubar * in the ReBar is actually main advantage of this control in comparison * with the standard window menu. */ GetClassName(cs->hwndParent, parent_class, MC_SIZEOF_ARRAY(parent_class)); if(_tcscmp(parent_class, _T("ReBarWindow32")) == 0) mb->notify_win = GetAncestor(cs->hwndParent, GA_PARENT); else mb->notify_win = cs->hwndParent; mb->hot_item = -1; mb->pressed_item = -1; return mb; }
void* debug_realloc(const char* fname, int line, void* mem, size_t size) { void* new_mem; new_mem = debug_malloc(fname, line, size); if(MC_ERR(new_mem == NULL)) return NULL; /* Copy contents from the old memory chunk */ if(mem != NULL) { mem_info_t* mi; mi = mem_hashtable[MEM_HASHTABLE_INDEX(mem)]; while(mi->mem != mem) { if(MC_ERR(mi == NULL)) { /* Not registered? */ MC_TRACE("%s:%d: \tdebug_realloc(%p): Attempting to realloc " "non-allocated memory.", fname, line, mem); MC_ASSERT(1 == 0); } mi = mi->next; } memcpy(new_mem, mem, MC_MIN(size, mi->size)); debug_free(fname, line, mem); } return new_mem; }
static html_t* html_nccreate(HWND win, CREATESTRUCT* cs) { html_t* html = NULL; /* Allocate and setup the html_t structure */ html = (html_t*) malloc(sizeof(html_t)); if(MC_ERR(html == NULL)) { MC_TRACE("html_nccreate: malloc() failed."); return NULL; } memset(html, 0, sizeof(html_t)); html->win = win; html->notify_win = cs->hwndParent; html->style = cs->style; html->dispatch.lpVtbl = &dispatch_vtable; html->client_site.lpVtbl = &client_site_vtable; html->inplace_site_ex.lpVtbl = &inplace_site_ex_vtable; html->inplace_frame.lpVtbl = &inplace_frame_vtable; html->ui_handler.lpVtbl = &ui_handler_vtable; /* Ask parent if it expects Unicode or ANSI notifications */ html_notify_format(html); return html; }
static int grid_get_geometry(grid_t* grid, MC_GGEOMETRY* geom) { GRID_TRACE("grid_get_geometry(%p, %p)", grid, geom); if(MC_ERR((geom->fMask & ~GRID_GGF_ALL) != 0)) { MC_TRACE("grid_get_geometry: fMask has some unsupported bit(s)"); SetLastError(ERROR_INVALID_PARAMETER); return -1; } if(geom->fMask & MC_GGF_COLUMNHEADERHEIGHT) geom->wColumnHeaderHeight = grid->header_height; if(geom->fMask & MC_GGF_ROWHEADERWIDTH) geom->wRowHeaderWidth = grid->header_width; if(geom->fMask & MC_GGF_DEFCOLUMNWIDTH) geom->wDefColumnWidth = grid->def_col_width; if(geom->fMask & MC_GGF_DEFROWHEIGHT) geom->wDefRowHeight = grid->def_row_height; if(geom->fMask & MC_GGF_PADDINGHORZ) geom->wPaddingHorz = grid->padding_h; if(geom->fMask & MC_GGF_PADDINGVERT) geom->wPaddingVert = grid->padding_v; return 0; }
int menubar_init_module(void) { WNDCLASS wc = { 0 }; if(MC_ERR(mc_init_comctl32(ICC_BAR_CLASSES | ICC_COOL_CLASSES) != 0)) { MC_TRACE("menubar_init_module: mc_init_comctl32() failed."); return -1; } if(MC_ERR(!GetClassInfo(NULL, _T("ToolbarWindow32"), &wc))) { MC_TRACE_ERR("menubar_init_module: GetClassInfo() failed"); return -1; } /* Remember needed values of standard toolbar window class */ orig_toolbar_proc = wc.lpfnWndProc; extra_offset = wc.cbWndExtra; /* Create our subclass. */ wc.lpfnWndProc = menubar_proc; wc.cbWndExtra += sizeof(menubar_t*); wc.style |= CS_GLOBALCLASS; wc.hInstance = NULL; wc.lpszClassName = menubar_wc; if(MC_ERR(!RegisterClass(&wc))) { MC_TRACE_ERR("menubar_init_module: RegisterClass() failed"); return -1; } InitializeCriticalSection(&menubar_ht_lock); return 0; }
static int grid_get_cell(grid_t* grid, WORD col, WORD row, MC_TABLECELL* cell, BOOL unicode) { if(MC_ERR(grid->table == NULL)) { SetLastError(ERROR_INVALID_HANDLE); MC_TRACE("grid_get_cell: No table installed."); return -1; } if(MC_ERR(table_get_cell_data(grid->table, col, row, cell, unicode) != 0)) { MC_TRACE("grid_get_cell: table_get_cell_data() failed."); return -1; } return 0; }
static int grid_resize_table(grid_t* grid, WORD col_count, WORD row_count) { GRID_TRACE("grid_resize_table(%d, %d)", (int) col_count, (int) row_count); if(grid->table != 0) { if(MC_ERR(table_resize(grid->table, col_count, row_count) != 0)) { MC_TRACE("grid_resize_table: table_resize() failed."); return -1; } } else { if(grid->col_widths != NULL) grid_alloc_col_widths(grid, grid->col_count, col_count, TRUE); if(grid->row_heights) grid_alloc_row_heights(grid, grid->row_count, row_count, TRUE); grid->col_count = col_count; grid->row_count = row_count; if(!grid->no_redraw) { InvalidateRect(grid->win, NULL, TRUE); grid_setup_scrollbars(grid, TRUE); } } return 0; }
static void menubar_ht_enable(menubar_t* mb) { MENUBAR_TRACE("menubar_ht_enable(%p)", mb); EnterCriticalSection(&menubar_ht_lock); if(MC_ERR(menubar_ht_hook != NULL)) { MC_TRACE("menubar_ht_enable: Another menubar hot tracks???"); menubar_ht_perform_disable(); } menubar_ht_hook = SetWindowsHookEx(WH_MSGFILTER, menubar_ht_proc, mc_instance, GetCurrentThreadId()); if(MC_ERR(menubar_ht_hook == NULL)) { MC_TRACE_ERR("menubar_ht_enable: SetWindowsHookEx() failed"); goto err_hook; } menubar_ht_mb = mb; GetCursorPos(&menubar_ht_last_pos); MapWindowPoints(NULL, mb->win, &menubar_ht_last_pos, 1); err_hook: LeaveCriticalSection(&menubar_ht_lock); }
static int grid_alloc_row_heights(grid_t* grid, WORD old_row_count, WORD new_row_count, BOOL cannot_fail) { WORD* row_heights; row_heights = realloc(grid->row_heights, new_row_count * sizeof(WORD)); if(MC_ERR(row_heights == NULL)) { MC_TRACE("grid_alloc_row_heights: realloc() failed."); mc_send_notify(grid->notify_win, grid->win, NM_OUTOFMEMORY); if(cannot_fail && grid->row_heights != NULL) { /* We need to be sync'ed with the underlying table, and if we * cannot have enough slots, we just fallback to the default * heights. */ free(grid->row_heights); grid->row_heights = NULL; } return -1; } /* Set new rows to the default heights. */ if(new_row_count > old_row_count) { memset(&row_heights[old_row_count], 0xff, (new_row_count - old_row_count) * sizeof(WORD)); } grid->row_heights = row_heights; return 0; }
static int menubar_create(menubar_t* mb, CREATESTRUCT *cs) { MENUBAR_TRACE("menubar_create(%p, %p)", mb, cs); if(MC_ERR(MENUBAR_SENDMSG(mb->win, WM_CREATE, 0, cs) != 0)) { MC_TRACE_ERR("menubar_create: CallWindowProc() failed"); return -1; } MENUBAR_SENDMSG(mb->win, TB_SETPARENT, mb->win, 0); MENUBAR_SENDMSG(mb->win, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); MENUBAR_SENDMSG(mb->win, TB_SETBITMAPSIZE, 0, MAKELONG(0, -2)); MENUBAR_SENDMSG(mb->win, TB_SETPADDING, 0, MAKELONG(10, 6)); MENUBAR_SENDMSG(mb->win, TB_SETDRAWTEXTFLAGS, MENUBAR_DTFLAGS, MENUBAR_DTFLAGS); /* Add some styles we consider default */ SetWindowLongPtr(mb->win, GWL_STYLE, cs->style | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | CCS_NODIVIDER); if(cs->lpCreateParams != NULL) { if(MC_ERR(menubar_set_menu(mb, (HMENU) cs->lpCreateParams, FALSE) != 0)) { MC_TRACE("menubar_create: menubar_set_menu() failed."); return -1; } } menubar_update_ui_state(mb, FALSE); return 0; }
static imgview_t* imgview_nccreate(HWND win, CREATESTRUCT* cs) { imgview_t* iv; iv = (imgview_t*) malloc(sizeof(imgview_t)); if(MC_ERR(iv == NULL)) { MC_TRACE("imgview_nccreate: malloc() failed."); return NULL; } memset(iv, 0, sizeof(imgview_t)); iv->win = win; iv->notify_win = cs->hwndParent; iv->style = cs->style; if(cs->lpszName != NULL) { #ifdef UNICODE if(cs->lpszName != NULL && cs->lpszName[0] == 0xffff) cs->lpszName = MAKEINTRESOURCE(cs->lpszName[1]); #endif iv->image = imgview_load_image_from_resource(cs->hInstance, cs->lpszName); /* Do not propagate cs->lpszName into WM_CREATE and WM_SETTEXT */ cs->lpszName = NULL; } return iv; }
static int module_init_modules(module_t** modules, int n) { int res = 0; int i = 0; EnterCriticalSection(&mod_lock); while(i < n) { if(modules[i]->refs == 0) { res = modules[i]->fn_init(); if(MC_ERR(res != 0)) { MC_TRACE("module_init_modules: %s_init() failed.", modules[i]->name); /* Rollback previous initializations */ while(--i >= 0) { modules[i]->refs--; if(modules[i]->refs == 0) modules[i]->fn_fini(); } break; } } modules[i]->refs++; i++; } LeaveCriticalSection(&mod_lock); return res; }
BOOL MCTRL_API mcTable_GetCellA(MC_HTABLE hTable, WORD wCol, WORD wRow, MC_TABLECELLA* pCell) { if(MC_ERR(table_get_cell_data(hTable, wCol, wRow, (MC_TABLECELL*)pCell, FALSE) != 0)) { MC_TRACE("mcTable_GetCellA: table_get_cell_data() failed."); return FALSE; } return TRUE; }
int html_init_module(void) { WNDCLASS wc = { 0 }; /* Load OLEAUT32.DLL */ if(MC_ERR(NULL == (oleaut32_dll = LoadLibrary(_T("OLEAUT32.DLL"))) || NULL == (html_SysAllocString = (BSTR (WINAPI*)(const OLECHAR*)) GetProcAddress(oleaut32_dll, "SysAllocString")) || NULL == (html_SysFreeString = (INT (WINAPI*)(BSTR)) GetProcAddress(oleaut32_dll, "SysFreeString")))) { MC_TRACE("html_init_module: LoadLibrary(OLEAUT32.DLL) failed."); goto err_oleaut32; } /* Load OLE32.DLL */ if(MC_ERR(NULL == (ole32_dll = LoadLibrary(_T("OLE32.DLL"))) || NULL == (html_OleInitialize = (HRESULT (WINAPI*)(void*)) GetProcAddress(ole32_dll, "OleInitialize")) || NULL == (html_OleUninitialize = (void (WINAPI*)(void)) GetProcAddress(ole32_dll, "OleUninitialize")) || NULL == (html_CoCreateInstance = (HRESULT (WINAPI*)(REFCLSID,IUnknown*,DWORD,REFIID,void**)) GetProcAddress(ole32_dll, "CoCreateInstance")))) { MC_TRACE("html_init_module: LoadLibrary(OLE32.DLL) failed."); goto err_ole32; } /* Register window class */ mc_init_common_controls(ICC_STANDARD_CLASSES); wc.style = CS_GLOBALCLASS | CS_PARENTDC; wc.lpfnWndProc = html_proc; wc.cbWndExtra = sizeof(html_t*); wc.lpszClassName = html_wc; if(MC_ERR(!RegisterClass(&wc))) { MC_TRACE_ERR("html_init_module: RegisterClass() failed"); goto err_register; } /* Success */ return 0; /* Error path unwinding */ err_register: FreeLibrary(ole32_dll); err_ole32: FreeLibrary(oleaut32_dll); err_oleaut32: return -1; }
static void html_key_msg(html_t* html, UINT msg, WPARAM wp, LPARAM lp) { DWORD pos; MSG message; IWebBrowser2* browser_iface; IOleInPlaceActiveObject* active_iface; HRESULT hr; pos = GetMessagePos(); /* Setup the message structure */ message.hwnd = html->ie_win; message.message = msg; message.wParam = wp; message.lParam = lp; message.time = GetMessageTime(); message.pt.x = GET_X_LPARAM(pos); message.pt.y = GET_Y_LPARAM(pos); /* ->TranslateAccelerator() */ hr = html->browser_obj->lpVtbl->QueryInterface(html->browser_obj, &IID_IWebBrowser2, (void**)&browser_iface); if(MC_ERR(hr != S_OK || browser_iface == NULL)) { MC_TRACE("html_key_msg: " "QueryInterface(IID_IWebBrowser2) failed [0x%lx]", hr); goto err_browser; } hr = browser_iface->lpVtbl->QueryInterface(browser_iface, &IID_IOleInPlaceActiveObject, (void**)&active_iface); if(MC_ERR(hr != S_OK || active_iface == NULL)) { MC_TRACE("html_key_msg: " "QueryInterface(IID_IOleInPlaceActiveObject) failed [0x%lx]", hr); goto err_active; } active_iface->lpVtbl->TranslateAccelerator(active_iface, &message); /* Cleanup */ active_iface->lpVtbl->Release(active_iface); err_active: browser_iface->lpVtbl->Release(browser_iface); err_browser: ; /* noop */ }
BOOL MCTRL_API mcTable_Resize(MC_HTABLE hTable, WORD wColumnCount, WORD wRowCount) { if(MC_ERR(table_resize(hTable, wColumnCount, wRowCount) != 0)) { MC_TRACE("mcTable_Resize: table_resize() failed."); return FALSE; } return TRUE; }
static LONG grid_get_col_width(grid_t* grid, WORD col) { if(MC_ERR(col >= grid->col_count)) { MC_TRACE("grid_get_col_width: column %hu our of range.", col); SetLastError(ERROR_INVALID_PARAMETER); return -1; } return MAKELPARAM(grid_col_width(grid, col), 0); }
static LONG grid_get_row_height(grid_t* grid, WORD row) { if(MC_ERR(row >= grid->row_count)) { MC_TRACE("grid_get_row_height: row %hu our of range.", row); SetLastError(ERROR_INVALID_PARAMETER); return -1; } return MAKELPARAM(grid_row_height(grid, row), 0); }
/* We dig into the raw resources instead of using LoadStringW() with nBufferMax * set to zero. * * See http://blogs.msdn.com/b/oldnewthing/archive/2004/01/30/65013.aspx. * * This allows us to do two useful things: * -- Verify easily the string is zero-terminated (the assertion). * -- Implement a fall-back to English, as translations can be potentially * incomplete. */ const TCHAR* mc_str_load(UINT id) { #ifndef UNICODE #error mc_str_load() is not (yet?) implemented for ANSI build. #endif const UINT lang_id[2] = { MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT) }; TCHAR* rsrc_id = MAKEINTRESOURCE(id/16 + 1); int str_num = (id & 15); HRSRC rsrc; HGLOBAL handle; WCHAR* str; UINT len; int i, j; for(i = 0; i < MC_SIZEOF_ARRAY(lang_id); i++) { rsrc = FindResourceEx(mc_instance, RT_STRING, rsrc_id, lang_id[i]); if(MC_ERR(rsrc == NULL)) goto not_found; handle = LoadResource(mc_instance, rsrc); if(MC_ERR(handle == NULL)) goto not_found; str = (WCHAR*) LockResource(handle); if(MC_ERR(str == NULL)) goto not_found; for(j = 0; j < str_num; j++) str += 1 + (UINT) *str; len = (UINT) *str; if(MC_ERR(len == 0)) goto not_found; str++; /* Verify string resources are '\0'-terminated. This is not default * behavior of RC.EXE as well as windres.exe. For windres.exe we need * to have resources in the form "foo bar\0". For RC.EXE, we need to * use option '/n' to terminate the strings as RC.EXE even strips final * '\0' from the string even when explicitly specified. */ MC_ASSERT(str[len - 1] == L'\0'); return str; not_found: MC_TRACE("mc_str_load: String %u missing [language 0x%x].", id, (DWORD)(lang_id[i] == MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) ? LANGIDFROMLCID(GetThreadLocale()) : lang_id[i])); } return _T(""); }
static int grid_clear(grid_t* grid, DWORD what) { if(MC_ERR(grid->table == NULL)) { SetLastError(ERROR_NOT_SUPPORTED); MC_TRACE("grid_clear: No table installed."); return -1; } mcTable_Clear(grid->table, what); return 0; }
static int grid_create(grid_t* grid) { grid_open_theme(grid); if(MC_ERR(grid_set_table(grid, NULL) != 0)) { MC_TRACE("grid_create: grid_set_table() failed."); return -1; } return 0; }
int table_get_cell_data(table_t* table, WORD col, WORD row, MC_TABLECELL* cell_data, BOOL unicode) { table_cell_t* cell; TABLE_TRACE("table_get_cell_data(%p, %hd, %hd, %p, %s)", table, col, row, cell_data, (unicode ? "unicode" : "ansi")); cell = table_get_cell(table, col, row); if(MC_ERR(cell == NULL)) { MC_TRACE("table_set_cell_data: table_get_cell_data() failed."); return -1; } if(MC_ERR(cell_data->fMask & ~MC_TCMF_ALL)) { MC_TRACE("table_get_cell_data: Unsupported pCell->fMask 0x%x", cell_data->fMask); SetLastError(ERROR_INVALID_PARAMETER); return -1; } if(cell_data->fMask & MC_TCMF_TEXT) { if(cell->text == MC_LPSTR_TEXTCALLBACK) { MC_TRACE("table_get_cell_data: Table cell contains " "MC_LPSTR_TEXTCALLBACK and that cannot be asked for."); SetLastError(ERROR_INVALID_PARAMETER); return -1; } else { mc_str_inbuf(cell->text, MC_STRT, cell_data->pszText, (unicode ? MC_STRW : MC_STRA), cell_data->cchTextMax); } } if(cell_data->fMask & MC_TCMF_PARAM) cell_data->lParam = cell->lp; if(cell_data->fMask & MC_TCMF_FLAGS) cell_data->dwFlags = cell->flags; return 0; }