ui/motif/text.c

changeset 927
b8c0f718b141
parent 925
df27741d02b5
child 966
e411ed7c5f10
equal deleted inserted replaced
926:32b16cbca280 927:b8c0f718b141
32 32
33 #include "text.h" 33 #include "text.h"
34 #include "container.h" 34 #include "container.h"
35 #include "pathbar.h" 35 #include "pathbar.h"
36 36
37 #include "../common/utils.h"
38
37 #include <cx/string.h> 39 #include <cx/string.h>
38 40
39 41
40 /* ------------------------------ Text Area ------------------------------ */ 42 /* ------------------------------ Text Area ------------------------------ */
41 43
516 // TODO: check if there is somonething missing 518 // TODO: check if there is somonething missing
517 XtFree((void*)pathbar->pathSegments); 519 XtFree((void*)pathbar->pathSegments);
518 XtFree((void*)pathbar); 520 XtFree((void*)pathbar);
519 } 521 }
520 522
521 // TODO: move to common
522 static UiPathElm* default_pathelm_func(const char* full_path, size_t len, size_t* ret_nelm, void* data) {
523 cxstring *pathelms;
524 size_t nelm = cx_strsplit_a(cxDefaultAllocator, cx_strn(full_path, len), CX_STR("/"), 4096, &pathelms);
525
526 if (nelm == 0) {
527 *ret_nelm = 0;
528 return NULL;
529 }
530
531 UiPathElm* elms = (UiPathElm*)calloc(nelm, sizeof(UiPathElm));
532 size_t n = nelm;
533 int j = 0;
534 for (int i = 0; i < nelm; i++) {
535 cxstring c = pathelms[i];
536 if (c.length == 0) {
537 if (i == 0) {
538 c.length = 1;
539 }
540 else {
541 n--;
542 continue;
543 }
544 }
545
546 cxmutstr m = cx_strdup(c);
547 elms[j].name = m.ptr;
548 elms[j].name_len = m.length;
549
550 size_t elm_path_len = c.ptr + c.length - full_path;
551 cxmutstr elm_path = cx_strdup(cx_strn(full_path, elm_path_len));
552 elms[j].path = elm_path.ptr;
553 elms[j].path_len = elm_path.length;
554
555 j++;
556 }
557 *ret_nelm = n;
558
559 return elms;
560 }
561
562 static void pathbar_activate(void *data, char *path, int index) { 523 static void pathbar_activate(void *data, char *path, int index) {
563 UiEventData *event = data; 524 UiEventData *event = data;
564 UiEvent evt; 525 UiEvent evt;
565 evt.obj = event->obj; 526 evt.obj = event->obj;
566 evt.window = evt.obj->window; 527 evt.window = evt.obj->window;
582 // TODO: name 543 // TODO: name
583 544
584 545
585 PathBar *pathbar = CreatePathBar(parent, xargs, n); 546 PathBar *pathbar = CreatePathBar(parent, xargs, n);
586 if(!args->getpathelm) { 547 if(!args->getpathelm) {
587 pathbar->getpathelm= default_pathelm_func; 548 pathbar->getpathelm= ui_default_pathelm_func;
588 } else { 549 } else {
589 pathbar->getpathelm = args->getpathelm; 550 pathbar->getpathelm = args->getpathelm;
590 pathbar->getpathelmdata = args->getpathelmdata; 551 pathbar->getpathelmdata = args->getpathelmdata;
591 } 552 }
592 553

mercurial