static void editor_load_file(editor c, const char *name, int enc) { textbox t = getdata(c); EditorData p = getdata(t); FILE *f; char *buffer = NULL, tmp[MAX_PATH+50], tname[MAX_PATH+1]; const char *sname; long num = 1, bufsize; if(enc == CE_UTF8) { wchar_t wname[MAX_PATH+1]; Rf_utf8towcs(wname, name, MAX_PATH+1); f = R_wfopen(wname, L"r"); reEnc2(name, tname, MAX_PATH+1, CE_UTF8, CE_NATIVE, 3); sname = tname; } else { f = R_fopen(name, "r"); sname = name; } if (f == NULL) { snprintf(tmp, MAX_PATH+50, G_("unable to open file %s for reading"), sname); R_ShowMessage(tmp); return; } p->file = 1; strncpy(p->filename, name, MAX_PATH+1); bufsize = 0; while (num > 0) { buffer = realloc(buffer, bufsize + 3000 + 1); num = fread(buffer + bufsize, 1, 3000 - 1, f); if (num >= 0) { bufsize += num; buffer[bufsize] = '\0'; } else { snprintf(tmp, MAX_PATH+50, G_("Could not read from file '%s'"), sname); askok(tmp); } } setlimittext(t, 2 * strlen(buffer)); settext(t, buffer); gsetmodified(t, 0); free(buffer); fclose(f); }
/* * Activate a control's action function. We do several things here. * Checking to see what kind of control it is, we handle some * events and discard others. We automatically toggle the state of * checkboxes and radio buttons, and handle listbox changes and * allow text box update events to call the control's action. */ PROTECTED void handle_control(HWND hwnd, UINT message) { object obj; int index; obj = find_by_handle(hwnd); if ((! obj) || (! (obj->state & Enabled))) return; /* Only let certain events cause activation. */ switch (obj->kind) { case CheckboxObject: if (obj->state & Checked) uncheck(obj); else check(obj); break; case RadioObject: if (!(obj->state & Checked)) { uncheck_neighbours(obj); check(obj); } break; case ListboxObject: /* Ignore all but selection-change events. */ if (message != LBN_SELCHANGE) return; index = sendmessage(hwnd, LB_GETCURSEL, 0, 0L); obj->value = index; break; case MultilistObject: /* Ignore all but selection-change events. */ if (message != LBN_SELCHANGE) return; index = sendmessage(hwnd, LB_GETCARETINDEX, 0, 0L); /* We do want to see de-selection events too if (! sendmessage(hwnd, LB_GETSEL, index, 0L)) return;*/ obj->value = index; break; case DroplistObject: case DropfieldObject: /* Ignore all but selection-change events. */ if (message != CBN_SELCHANGE) return; index = sendmessage(hwnd, CB_GETCURSEL, 0, 0L); obj->value = index; break; case FieldObject: case TextboxObject: if (message == EN_MAXTEXT) { /* increase the character limit in the editor by 50% if the limit is reached, but this should not happen */ setlimittext(obj, 1.5 * getlimittext(obj)); } /* Ignore everything else but killfocus. */ else if (message != EN_KILLFOCUS) return; break; default: break; } /* activate the control's callback */ activatecontrol(obj); }