use structure instead of void pointers

git-svn-id: svn://kolibrios.org@6500 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Serhii Sakhno 2016-08-23 23:43:26 +00:00
parent c6db9a29e8
commit 80ebd71171
2 changed files with 87 additions and 11 deletions

View File

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <kos32sys.h>
#include <kolibri_gui.h>
#include <kolibri_kmenu.h>
@ -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 <string.h>
if(gui_event == KOLIBRI_EVENT_REDRAW)
{
kolibri_handle_event_redraw(main_window);

View File

@ -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 */