application/main.c

Sat, 30 Aug 2014 22:48:46 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 30 Aug 2014 22:48:46 +0200
changeset 58
2b124f8ebd95
parent 56
87e3a5dc66dd
child 59
eb6611be50c7
permissions
-rw-r--r--

added table view (Qt)

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2012 Olaf Wintermann. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdio.h>
#include <stdlib.h>

#include <ui/ui.h>
#include <ucx/buffer.h>
#include <ucx/utils.h>


typedef struct Person {
    char *name;
    char *mail;
} Person;

typedef struct Document {
    UiText text;
} Document;

UiText text;

void action_new(UiEvent *event, void *data) {
    printf("new\n");
}

void action_close(UiEvent *event, void *data) {
    printf("action_close\n");
    ui_close(event->obj);
}

char* person_getvalue(Person *p, int column) {
    switch(column) {
        case 0: return p->name;
        case 1: return p->mail;
    }
    return NULL;
}

void action_activate(UiEvent *event, void *data) {
    UiListSelection *selection = event->eventdata;
    printf("activate: %d\n", event->intval);
}

void action_select(UiEvent *event, void *data) {
    UiListSelection *selection = event->eventdata;
    printf("selection[%d]: ", selection->count);
    for(int i=0;i<selection->count;i++) {
        printf("%d ", selection->rows[i]);
    }
    printf("\n");
}

void action_button(UiEvent *event, void *data) {
    printf("button: %d\n", event->intval);
    //char *s = ui_gettext(event->obj, "text");
    char *s = ui_getval(text);
    printf("{%s}\n", s);
}

int main(int argc, char** argv) { 
    ui_init("app1", argc, argv);
    ui_locales_dir("/opt/app1/locales");
    ui_load_lang_def(NULL, "en_EN");
    //ui_openfilefunc(action_new, NULL);
    
    
    
    ui_menu("File");
    //ui_menuitem("Close", action_close, NULL);
    ui_menuitem_st(UI_STOCK_NEW, action_new, NULL);
    ui_menuitem_st(UI_STOCK_CLOSE, action_close, NULL);
    //ui_checkitem("Check", action_button, NULL);
    
    ui_toolitem_st("button", UI_STOCK_OPEN, action_button, NULL);
    ui_toolbar_add_default("button");
    
    printf("create window\n");
    UiObject *window = ui_window("Mod0", NULL);
    //ui_textarea(window, &text);
    
    ///*
    UiModelInfo *model = ui_model_info(window->ctx, UI_STRING, "Name", UI_STRING, "Email", -1);
    model->getvalue = (ui_model_getvalue_f)person_getvalue;
    model->activate = action_activate;
    model->selection = action_select;
    UiList *list = ui_list_new();
    Person *p1 = ui_malloc(window->ctx, sizeof(Person));
    Person *p2 = ui_malloc(window->ctx, sizeof(Person));
    Person *p3 = ui_malloc(window->ctx, sizeof(Person));
    Person *p4 = ui_malloc(window->ctx, sizeof(Person));
    p1->name = "Some Näme";
    p1->mail = "mail@host.com";
    p2->name = "押井守";
    p2->mail = "other.person@provider.com";
    p3->name = "My Self";
    p3->mail = "my@self.org";
    p4->name = "Gregory House";
    p4->mail = "greg@pp";
    ui_list_append(list, p1);
    ui_list_append(list, p2);
    ui_list_append(list, p3);
    ui_list_append(list, p4);
    
    //ui_sidebar(window);
    ui_table(window, list, model);
    //ui_end(window);
    
    /*
    UiTabbedPane *view = ui_tabbed_document_view(window);
    
    UiObject *tab1 = ui_document_tab(view);
    Document *doc1 = ui_document_new(1024);
    UiContext *ctx1 = ui_document_context(doc1);
    ui_document_regtext(doc1, "text", &doc1->text);
    ui_textarea_nv(tab1, "text");
    ui_set_document(tab1, doc1);
    
    
    UiObject *tab2 = ui_document_tab(view);
    Document *doc2 = ui_document_new(1024);
    UiContext *ctx2 = ui_document_context(doc2);
    ui_document_regtext(doc2, "text", &doc2->text);
    ui_textarea_nv(tab2, "text");
    ui_set_document(tab2, doc2);
    
    UiObject *tab3 = ui_document_tab(view);
    Document *doc3 = ui_document_new(1024);
    UiContext *ctx3 = ui_document_context(doc3);
    ui_document_regtext(doc3, "text", &doc3->text);
    ui_textarea_nv(tab3, "text");
    ui_set_document(tab3, doc3);
    */
    
    ui_show(window);
    ui_main();
    
    return (EXIT_SUCCESS);
}

mercurial