From 80ebd71171142a00265cce63505c4fc4ef9f4385 Mon Sep 17 00:00:00 2001 From: Serhii Sakhno Date: Tue, 23 Aug 2016 23:43:26 +0000 Subject: [PATCH] use structure instead of void pointers git-svn-id: svn://kolibrios.org@6500 a494cfbc-eb01-0410-851d-a64ba20cac60 --- contrib/C_Layer/EXAMPLE/kmenu/kmenu_example.c | 11 +-- contrib/C_Layer/INCLUDE/kolibri_kmenu.h | 87 +++++++++++++++++-- 2 files changed, 87 insertions(+), 11 deletions(-) diff --git a/contrib/C_Layer/EXAMPLE/kmenu/kmenu_example.c b/contrib/C_Layer/EXAMPLE/kmenu/kmenu_example.c index 0ab3f169f6..314ae884f3 100644 --- a/contrib/C_Layer/EXAMPLE/kmenu/kmenu_example.c +++ b/contrib/C_Layer/EXAMPLE/kmenu/kmenu_example.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -21,22 +22,22 @@ int main() kmenu_init(NULL); - void *sub_menu1 = ksubmenu_new(); + ksubmenu_t *sub_menu1 = ksubmenu_new(); ksubmenu_add(sub_menu1, kmenuitem_new(0, "Open", 101)); ksubmenu_add(sub_menu1, kmenuitem_new(0, "Save", 102)); ksubmenu_add(sub_menu1, kmenuitem_new(2, "", 0)); ksubmenu_add(sub_menu1, kmenuitem_new(0, "Exit", 103)); - void *sub_menu2 = ksubmenu_new(); + ksubmenu_t *sub_menu2 = ksubmenu_new(); ksubmenu_add(sub_menu2, kmenuitem_new(0, "Find", 201)); ksubmenu_add(sub_menu2, kmenuitem_new(0, "Replace", 202)); - void *sub_menu22 = ksubmenu_new(); + ksubmenu_t *sub_menu22 = ksubmenu_new(); ksubmenu_add(sub_menu22, kmenuitem_new(0, "cp1251", 211)); ksubmenu_add(sub_menu22, kmenuitem_new(0, "UTF-8", 212)); ksubmenu_add(sub_menu2, kmenuitem__submenu_new(1, "Encoding", sub_menu22)); - void *main_menu = ksubmenu_new(); + ksubmenu_t *main_menu = ksubmenu_new(); ksubmenu_add(main_menu, kmenuitem__submenu_new(1, "File", sub_menu1)); ksubmenu_add(main_menu, kmenuitem__submenu_new(1, "Edit", sub_menu2)); @@ -44,7 +45,7 @@ int main() do /* Start of main activity loop */ { - if(gui_event == KOLIBRI_EVENT_REDRAW)#include + if(gui_event == KOLIBRI_EVENT_REDRAW) { kolibri_handle_event_redraw(main_window); diff --git a/contrib/C_Layer/INCLUDE/kolibri_kmenu.h b/contrib/C_Layer/INCLUDE/kolibri_kmenu.h index 9283147cd5..a5c51d6518 100644 --- a/contrib/C_Layer/INCLUDE/kolibri_kmenu.h +++ b/contrib/C_Layer/INCLUDE/kolibri_kmenu.h @@ -13,14 +13,89 @@ #define KMENU_LBORDER_SIZE 2 #define KMENU_DBORDER_SIZE 1 +typedef struct { + int type; + uint32_t color; + union { + uint32_t bgcolor; + void *buffer; + }; +} t_font; + +typedef struct { + uint16_t left, top, right, bottom; +} t_rect; + +typedef struct kmenuitem_t{ + int type; + char *text; + union { + void *submenu; + //kmenuitem_callback_t callback; + size_t btnid; + }; + + void (*paint)(struct kmenuitem_t *item, t_rect *rc) __attribute__((__stdcall__)); + + int is_focused; + int is_enabled; + int is_visible; + size_t style; + + int font_width, font_height; + t_font font; + + size_t left, top; + size_t width, height, pref_width, pref_height; + size_t margin_left, margin_right, margin_top, margin_bottom; + size_t padding_left, padding_right, padding_top, padding_bottom; +} kmenuitem_t; + +typedef struct ksubmenu_t{ + kmenuitem_t **items; + int count; + + void (*paint)(struct ksubmenu_t *menu) __attribute__((__stdcall__)); + + int is_opened; + int focus_idx; + + size_t width, height; + size_t left, top; + int tid; + int parent_wnd, parent_tid, submenu_tid, self_wnd; + int level; + size_t return_btnid; + + int set_new_padding, set_new_margin; + t_rect items_padding; + t_rect items_margin; + + struct ksubmenu_t *parent; +} ksubmenu_t; + +typedef struct { + kmenuitem_t **submenu; + int count; + + size_t width, height; + size_t left, top; + + int line_height; + + int focus_idx; + int submenu_tid; +} kmenu_t; + + extern int kolibri_kmenu_init(void); -extern void (*kmainmenu_draw)(void *) __attribute__((__stdcall__)); -extern void (*kmainmenu_dispatch_cursorevent)(void *) __attribute__((__stdcall__)); +extern void (*kmainmenu_draw)(ksubmenu_t *) __attribute__((__stdcall__)); +extern void (*kmainmenu_dispatch_cursorevent)(ksubmenu_t *) __attribute__((__stdcall__)); extern void (*kmenu_init)(void *) __attribute__((__stdcall__)); -extern void* (*ksubmenu_new)() __attribute__((__stdcall__)); -extern void (*ksubmenu_add)(void *, void *) __attribute__((__stdcall__)); -extern void* (*kmenuitem_new)(uint32_t, const char *, uint32_t) __attribute__((__stdcall__)); -extern void* (*kmenuitem__submenu_new)(uint32_t, const char *, void *) __attribute__((__stdcall__)); +extern ksubmenu_t* (*ksubmenu_new)() __attribute__((__stdcall__)); +extern void (*ksubmenu_add)(ksubmenu_t *, kmenuitem_t *) __attribute__((__stdcall__)); +extern kmenuitem_t* (*kmenuitem_new)(uint32_t, const char *, uint32_t) __attribute__((__stdcall__)); +extern kmenuitem_t* (*kmenuitem__submenu_new)(uint32_t, const char *, ksubmenu_t *) __attribute__((__stdcall__)); #endif /* KOLIBRI_KMENU_H */