static void registerDescriptionList(WMScreen * scr, WMView * view, WMArray * operationArray) { char *text, *textListItem, *textList; int count = WMGetArrayItemCount(operationArray); int i; int size = 0; /* size of XA_STRING info */ for (i = 0; i < count; i++) { size += strlen(WMGetDragOperationItemText(WMGetFromArray(operationArray, i))) + 1 /* NULL */; } /* create text list */ textList = wmalloc(size); textListItem = textList; for (i = 0; i < count; i++) { text = WMGetDragOperationItemText(WMGetFromArray(operationArray, i)); wstrlcpy(textListItem, text, size); /* to next text offset */ textListItem = &(textListItem[strlen(textListItem) + 1]); } XChangeProperty(scr->display, WMViewXID(view), scr->xdndActionDescriptionAtom, XA_STRING, XDND_ACTION_DESCRIPTION_FORMAT, PropModeReplace, (unsigned char *)textList, size); }
void WMSetTextFieldText(WMTextField * tPtr, const char *text) { CHECK_CLASS(tPtr, WC_TextField); if ((text && strcmp(tPtr->text, text) == 0) || (!text && tPtr->textLen == 0)) return; if (text == NULL) { tPtr->text[0] = 0; tPtr->textLen = 0; } else { tPtr->textLen = strlen(text); if (tPtr->textLen >= tPtr->bufferSize) { tPtr->bufferSize = tPtr->textLen + TEXT_BUFFER_INCR; tPtr->text = wrealloc(tPtr->text, tPtr->bufferSize); } wstrlcpy(tPtr->text, text, tPtr->bufferSize); } tPtr->cursorPosition = tPtr->selection.position = tPtr->textLen; tPtr->viewPosition = 0; tPtr->selection.count = 0; if (tPtr->view->flags.realized) paintTextField(tPtr); }
static char *createTruncatedString(WMFont * font, const char *text, int *textLen, int width) { size_t slen; int dLen; char *textBuf; dLen = WMWidthOfString(font, ".", 1); slen = *textLen + 4; textBuf = wmalloc(slen); if (width >= 3 * dLen) { int tmpTextLen = *textLen; if (wstrlcpy(textBuf, text, slen) >= slen) goto error; while (tmpTextLen && (WMWidthOfString(font, textBuf, tmpTextLen) + 3 * dLen > width)) tmpTextLen--; if (wstrlcpy(textBuf + tmpTextLen, "...", slen) >= slen) goto error; *textLen = tmpTextLen + 3; } else if (width >= 2 * dLen) { if (wstrlcpy(textBuf, "..", slen) >= slen) goto error; *textLen = 2; } else if (width >= dLen) { if (wstrlcpy(textBuf, ".", slen) >= slen) goto error; *textLen = 1; } else { *textBuf = '\0'; *textLen = 0; } return textBuf; error: wfree(textBuf); return NULL; }
void wWorkspaceMenuUpdate(WMenu *menu) { int i; long ws; char title[MAX_WORKSPACENAME_WIDTH + 1]; WMenuEntry *entry; int tmp; if (!menu) return; if (menu->entry_no < w_global.workspace.count + MC_WORKSPACE1) { /* new workspace(s) added */ i = w_global.workspace.count - (menu->entry_no - MC_WORKSPACE1); ws = menu->entry_no - MC_WORKSPACE1; while (i > 0) { wstrlcpy(title, w_global.workspace.array[ws]->name, MAX_WORKSPACENAME_WIDTH); entry = wMenuAddCallback(menu, title, switchWSCommand, (void *)ws); entry->flags.indicator = 1; entry->flags.editable = 1; i--; ws++; } } else if (menu->entry_no > w_global.workspace.count + MC_WORKSPACE1) { /* removed workspace(s) */ for (i = menu->entry_no - 1; i >= w_global.workspace.count + MC_WORKSPACE1; i--) wMenuRemoveItem(menu, i); } for (i = 0; i < w_global.workspace.count; i++) { /* workspace shortcut labels */ if (i / 10 == w_global.workspace.current / 10) menu->entries[i + MC_WORKSPACE1]->rtext = GetShortcutKey(wKeyBindings[WKBD_WORKSPACE1 + (i % 10)]); else menu->entries[i + MC_WORKSPACE1]->rtext = NULL; menu->entries[i + MC_WORKSPACE1]->flags.indicator_on = 0; } menu->entries[w_global.workspace.current + MC_WORKSPACE1]->flags.indicator_on = 1; wMenuRealize(menu); /* don't let user destroy current workspace */ if (w_global.workspace.current == w_global.workspace.count - 1) wMenuSetEnabled(menu, MC_DESTROY_LAST, False); else wMenuSetEnabled(menu, MC_DESTROY_LAST, True); /* back to last workspace */ if (w_global.workspace.count && w_global.workspace.last_used != w_global.workspace.current) wMenuSetEnabled(menu, MC_LAST_USED, True); else wMenuSetEnabled(menu, MC_LAST_USED, False); tmp = menu->frame->top_width + 5; /* if menu got unreachable, bring it to a visible place */ if (menu->frame_x < tmp - (int)menu->frame->core->width) wMenuMove(menu, tmp - (int)menu->frame->core->width, menu->frame_y, False); wMenuPaint(menu); }
char *wexpandpath(const char *path) { const char *origpath = path; char buffer2[PATH_MAX + 2]; char buffer[PATH_MAX + 2]; int i; memset(buffer, 0, PATH_MAX + 2); if (*path == '~') { const char *home; path++; if (*path == '/' || *path == 0) { home = wgethomedir(); if (strlen(home) > PATH_MAX || wstrlcpy(buffer, home, sizeof(buffer)) >= sizeof(buffer)) goto error; } else { int j; j = 0; while (*path != 0 && *path != '/') { if (j > PATH_MAX) goto error; buffer2[j++] = *path; buffer2[j] = 0; path++; } home = getuserhomedir(buffer2); if (!home || wstrlcat(buffer, home, sizeof(buffer)) >= sizeof(buffer)) goto error; } } i = strlen(buffer); while (*path != 0 && i <= PATH_MAX) { char *tmp; if (*path == '$') { int j; path++; /* expand $(HOME) or $HOME style environment variables */ if (*path == '(') { path++; j = 0; while (*path != 0 && *path != ')') { if (j > PATH_MAX) goto error; buffer2[j++] = *(path++); } buffer2[j] = 0; if (*path == ')') { path++; tmp = getenv(buffer2); } else { tmp = NULL; } if (!tmp) { if ((i += strlen(buffer2) + 2) > PATH_MAX) goto error; buffer[i] = 0; if (wstrlcat(buffer, "$(", sizeof(buffer)) >= sizeof(buffer) || wstrlcat(buffer, buffer2, sizeof(buffer)) >= sizeof(buffer)) goto error; if (*(path-1)==')') { if (++i > PATH_MAX || wstrlcat(buffer, ")", sizeof(buffer)) >= sizeof(buffer)) goto error; } } else { if ((i += strlen(tmp)) > PATH_MAX || wstrlcat(buffer, tmp, sizeof(buffer)) >= sizeof(buffer)) goto error; } } else { j = 0; while (*path != 0 && *path != '/') { if (j > PATH_MAX) goto error; buffer2[j++] = *(path++); } buffer2[j] = 0; tmp = getenv(buffer2); if (!tmp) { if ((i += strlen(buffer2) + 1) > PATH_MAX || wstrlcat(buffer, "$", sizeof(buffer)) >= sizeof(buffer) || wstrlcat(buffer, buffer2, sizeof(buffer)) >= sizeof(buffer)) goto error; } else { if ((i += strlen(tmp)) > PATH_MAX || wstrlcat(buffer, tmp, sizeof(buffer)) >= sizeof(buffer)) goto error; } } } else { buffer[i++] = *path; path++; } } if (*path!=0) goto error; return wstrdup(buffer); error: errno = ENAMETOOLONG; werror(_("could not expand %s"), origpath); return NULL; }