commit d5cf47b490dc24af0f055c8872d92f61d7f28eec
parent 2734b84a7a418cb838e8dae0c1fa0e860dd0cb89
Author: Dominik Schmidt <das1993@hotmail.com>
Date: Sun, 14 Sep 2014 16:20:19 +0200
Further work on Advanced GUI.
Diffstat:
7 files changed, 86 insertions(+), 25 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -33,7 +33,7 @@ configure_file(
"${PROJECT_SOURCE_DIR}/include/EGong/Util/Config_Compiletime.h.in"
"${PROJECT_SOURCE_DIR}/include/EGong/Util/Config_Compiletime.h"
)
-set(CMAKE_CFLAGS, ${CMAKE_CFLAGS} -std=gnu99)
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
if(CMAKE_FIND_ROOT_PATH)
link_directories(${CMAKE_FIND_ROOT_PATH}/usr/lib)
endif(CMAKE_FIND_ROOT_PATH)
@@ -84,7 +84,9 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(USE_WINGUI)
set(WIN32_EXECUTABLE ON)
EGong_link_libs("gdi32")
-# SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mwindows")
+ if(NOT CMAKE_BUILD_TYPE STREQUAL "debug")
+ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mwindows")
+ endif()
endif(USE_WINGUI)
endif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
@@ -133,7 +135,7 @@ target_link_libraries(EGong ${EGONG_EXT_LIBS})
#INSTALL
install(TARGETS EGong DESTINATION bin)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
- install(FILES ${EGONG_DATADIR}/EGong.ico DESTINATION share)
+ install(FILES ${EGONG_DATADIR}/EGong.ico DESTINATION share/EGong/)
endif()
#PACKING
absolute_libs(ABS_LIBS "${OPENSSL_LIBRARIES};${LIBAO_LIBRARIES}")
diff --git a/include/EGong/Interfaces/GTK.h b/include/EGong/Interfaces/GTK.h
@@ -23,3 +23,8 @@ enum EGONG_IF_GTK_INIT{
EGONG_IF_GTK_INIT_TRAY=(1<<1),
EGONG_IF_GTK_INIT_ALL=(~0)
};
+
+struct EGong_if_gtk_callbackparam{
+ struct EGong_GUI_item *caller;
+ struct EGong_GUI_event *event;
+};
diff --git a/include/EGong/Interfaces/GUI.h b/include/EGong/Interfaces/GUI.h
@@ -19,6 +19,7 @@ enum EGONG_GUI_TYPE{
};
enum EGONG_GUI_EVSRC{
EGONG_GUI_EVSRC_ELEMENT,
+ EGONG_GUI_EVSRC_ELEMENT_SELF,
EGONG_GUI_EVSRC_STATIC,
};
enum EGONG_GUI_MENUITEM_IMAGES{
@@ -27,6 +28,7 @@ enum EGONG_GUI_MENUITEM_IMAGES{
enum EGONG_GUI_ITEM{
EGONG_GUI_WINDOW,
EGONG_GUI_BUTTON,
+ EGONG_GUI_TOGGLE_BUTTON,
EGONG_GUI_LABEL,
EGONG_GUI_TEXT,
EGONG_GUI_MENU,
@@ -60,7 +62,7 @@ struct EGong_GUI_event{
};
extern void EGong_GUI_event_hide(void *gui_element);
extern void *EGong_GUI_create(struct EGong_GUI_item *gui);
-extern void EGong_GUI_event_callback(struct EGong_GUI_event *event);
+extern void EGong_GUI_event_callback(struct EGong_GUI_item *self, struct EGong_GUI_event *event);
extern int EGong_GUI_exit(void);
#ifdef USE_GTK
diff --git a/src/Interfaces/GTK.c b/src/Interfaces/GTK.c
@@ -9,6 +9,7 @@
#include <gtk/gtk.h>
#include <EGong/Util/Config_Compiletime.h>
#include <EGong/Util/Config.h>
+#include <stdlib.h>
#ifdef USE_LIBNOTIFY
#include <libnotify/notify.h>
#endif
@@ -58,7 +59,20 @@ int EGong_if_gtk_cycle(struct EGong_interface *interface, String *msg, char **de
int EGong_if_gtk_display_window(struct EGong_interface *interface, const String *msg){
do_log("Displaying message in window", LOG_TYPE_NORMAL, LOG_LEVEL_DEBUG);
- gtk_dialog_new_with_buttons(msg->data, GTK_WINDOW(Egong_if_gtk_root), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK);
+ GtkWidget *win=gtk_message_dialog_new(GTK_WINDOW(Egong_if_gtk_root), (Egong_if_gtk_root==NULL) ? 0 : GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "EGong Nachricht");
+ if(win==NULL){
+ do_log("Couldn't create messagebox", LOG_TYPE_NORMAL, LOG_LEVEL_ERROR);
+ }
+ GtkWidget *img=gtk_image_new_from_pixbuf(EGong_if_gtk_icon);
+ if(img==NULL){
+ do_log("ERRIR", LOG_TYPE_NORMAL, LOG_LEVEL_DEBUG);
+ }
+ else{
+ gtk_message_dialog_set_image(GTK_MESSAGE_DIALOG(win), img);
+ }
+ gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(win), msg->data);
+ g_signal_connect_swapped(GTK_WIDGET(win), "response", G_CALLBACK(gtk_widget_destroy), win);
+ gtk_widget_show_all(GTK_WIDGET(win));
}
int EGong_if_gtk_display_notify(struct EGong_interface *interface, const String *msg){
do_log("Displaying message with libnotify", LOG_TYPE_NORMAL, LOG_LEVEL_DEBUG);
@@ -105,6 +119,9 @@ void EGong_if_gtk_widget_toggle(GtkWidget *caller){
void EGong_if_gtk_show_element(struct EGong_GUI_item *itm){
gtk_widget_show(GTK_WIDGET(itm->itemptr));
}
+static void EGong_if_gtk_event_callback(GtkWidget *caller, struct EGong_if_gtk_callbackparam *param){
+ EGong_GUI_event_callback(param->caller, param->event);
+}
GtkWidget *EGong_if_gtk_create_gui(struct EGong_GUI_item *parent, struct EGong_GUI_item *this){
unsigned int i;
GtkWidget *element=NULL;
@@ -128,6 +145,10 @@ GtkWidget *EGong_if_gtk_create_gui(struct EGong_GUI_item *parent, struct EGong_G
}
eventdefault="activate";
break;
+ case EGONG_GUI_TOGGLE_BUTTON:
+ element=(this->text!=NULL) ? gtk_toggle_button_new_with_label(this->text) : gtk_toggle_button_new();
+ eventdefault="toggled";
+ break;
case EGONG_GUI_BUTTON:
element=(this->text!=NULL) ? gtk_button_new_with_label(this->text) : gtk_button_new();
eventdefault="clicked";
@@ -149,7 +170,7 @@ GtkWidget *EGong_if_gtk_create_gui(struct EGong_GUI_item *parent, struct EGong_G
if(this->type==EGONG_GUI_MENUITEM_IMAGE){
gchar *stockid;
- switch((unsigned int)this->extra){
+ switch((unsigned int)(intptr_t)this->extra){
case EGUI_MIMG_EXIT:
stockid=GTK_STOCK_QUIT;
break;
@@ -189,8 +210,10 @@ GtkWidget *EGong_if_gtk_create_gui(struct EGong_GUI_item *parent, struct EGong_G
if(this->events!=NULL){
struct EGong_GUI_event *ev;
for(i=0;this->events[i]!=NULL; i++){
- ev=this->events[i];
- g_signal_connect_swapped(element, eventdefault, G_CALLBACK(EGong_GUI_event_callback), (gpointer)ev);
+ struct EGong_if_gtk_callbackparam *param=malloc(sizeof(struct EGong_if_gtk_callbackparam));
+ param->caller=this;
+ param->event=this->events[i];
+ g_signal_connect(element, eventdefault, G_CALLBACK(EGong_if_gtk_event_callback), (gpointer)param);
}
}
if(children!=NULL){
@@ -238,7 +261,7 @@ GtkWidget *EGong_if_gtk_create_gui(struct EGong_GUI_item *parent, struct EGong_G
}
}
}
- if(parent==NULL&&Egong_if_gtk_root==NULL){
+ if(parent==NULL&&Egong_if_gtk_root==NULL&&this->type!=EGONG_GUI_SYSTRAY){
Egong_if_gtk_root=element;
}
this->itemptr=(void *)element;
@@ -253,6 +276,9 @@ void *EGong_gtk_get_item_value(struct EGong_GUI_item *itm){
case EGONG_GUI_WINDOW:
ret=(void *)itm->itemptr;
break;
+ case EGONG_GUI_TOGGLE_BUTTON:
+ ret=(void *)(intptr_t)(unsigned int)(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(itm->itemptr)) ? 1 : 0);
+ break;
default:
do_log("Event datasource specified where no data can be obtained", LOG_TYPE_NORMAL, LOG_LEVEL_ERROR);
break;
diff --git a/src/Interfaces/GUI.c b/src/Interfaces/GUI.c
@@ -16,12 +16,20 @@ struct EGong_GUI_item EGong_GUI_newmessage={.type=EGONG_GUI_WINDOW, .extra=(void
EGUI_EL{.type=EGONG_GUI_HBOX, .extra=(void *)15, .text=NULL, .tooltip=NULL, .child=EGUI_ARR{
EGUI_ELX(EGong_GUI_systray_sendmsgfield),
EGUI_EL{.type=EGONG_GUI_BUTTON, .text=GUIT("Senden"), .tooltip=GUIT("Nachricht Senden"), .child=NULL, .events=EEV_ARR{
+ EEV_EL{.command={.type={.type=EGONG_COMMAND_FUNC_POINTER, .args=1}, .pointer=&EGong_GUI_event_hide}, .sources=EES_ARR{
+ EES_EL{.type=EGONG_GUI_EVSRC_ELEMENT, .data=&EGong_GUI_newmessage},
+ EES_FIN
+ }},
EEV_EL{.command={.type={.type=EGONG_COMMAND_FUNC_STRING, .args=1}, .pointer=&EGong_cnc_sendmessage_broad}, .sources=EES_ARR{
EES_EL{.type=EGONG_GUI_EVSRC_ELEMENT, .data=&EGong_GUI_systray_sendmsgfield},
EES_FIN
}},
- EEV_EL{.command={.type={.type=EGONG_COMMAND_FUNC_POINTER, .args=1}, .pointer=&EGong_GUI_event_hide}, .sources=EES_ARR{
- EES_EL{.type=EGONG_GUI_EVSRC_ELEMENT, .data=&EGong_GUI_newmessage},
+ EEV_FIN
+ }},
+ EGUI_EL{.type=EGONG_GUI_TOGGLE_BUTTON, .extra=NULL, .text=GUIT("Test"), .tooltip=GUIT("Testen"), .child=NULL, .events=EEV_ARR{
+ EEV_EL{.command={.type={.type=EGONG_COMMAND_BIT_SET, .args=2}, .pointer=&EGong_global_configuration.gui.destinations}, .sources=EES_ARR{
+ EES_EL{.type=EGONG_GUI_EVSRC_STATIC, .data=(void *)(unsigned int)EGONG_CONFIG_GUI_DEST_WINDOW},
+ EES_EL{.type=EGONG_GUI_EVSRC_ELEMENT_SELF, .data=NULL},
EES_FIN
}},
EEV_FIN
@@ -99,7 +107,7 @@ void EGong_GUI_event_hide(void *gui_element){
}
#endif
}
-void EGong_GUI_event_callback(struct EGong_GUI_event *event){
+void EGong_GUI_event_callback(struct EGong_GUI_item *self, struct EGong_GUI_event *event){
void *args[event->command.type.args];
unsigned int i;
@@ -108,6 +116,9 @@ void EGong_GUI_event_callback(struct EGong_GUI_event *event){
if(event->sources[i]->type==EGONG_GUI_EVSRC_ELEMENT){
args[i]=EGong_if_gui_pointers.get_value(event->sources[i]->data);
}
+ else if(event->sources[i]->type==EGONG_GUI_EVSRC_ELEMENT_SELF){
+ args[i]=EGong_if_gui_pointers.get_value(self);
+ }
else if(event->sources[i]->type==EGONG_GUI_EVSRC_STATIC){
args[i]=event->sources[i]->data;
}
@@ -115,11 +126,17 @@ void EGong_GUI_event_callback(struct EGong_GUI_event *event){
do_log("Trying to execute command", LOG_TYPE_NORMAL, LOG_LEVEL_DEBUG);
EGong_command_exec(&event->command, args);
- for(i=0;i<event->command.type.args;i++){
+ do_log("Command execution done, freeing memory...", LOG_TYPE_NORMAL, LOG_LEVEL_DEBUG);
+
+ for(i=0;i<event->command.type.args&&event->sources[i]!=NULL;i++){
if(event->sources[i]->type==EGONG_GUI_EVSRC_ELEMENT){
EGong_if_gui_pointers.free_value(event->sources[i]->data, args[i]);
}
+ else if(event->sources[i]->type==EGONG_GUI_EVSRC_ELEMENT_SELF){
+ EGong_if_gui_pointers.free_value(self, args[i]);
+ }
}
+ do_log("Freeing done, good bye...", LOG_TYPE_NORMAL, LOG_LEVEL_DEBUG);
}
int EGong_if_gui_setup(struct EGong_interface *interface){
diff --git a/src/Interfaces/Windows.c b/src/Interfaces/Windows.c
@@ -69,6 +69,8 @@ RECT EGong_if_win_getsize(struct EGong_GUI_item *this, unsigned short int recurs
rect.bottom=childr.bottom;
}
}
+ rect.right+=2*(unsigned int)(uintptr_t)this->extra;
+ rect.bottom+=2*(unsigned int)(uintptr_t)this->extra;
break;
case EGONG_GUI_TEXT:
DrawText(hdc, GUIT("M"), 1, &rect, DT_CALCRECT);
@@ -79,6 +81,7 @@ RECT EGong_if_win_getsize(struct EGong_GUI_item *this, unsigned short int recurs
case EGONG_GUI_LABEL:
DrawText(hdc, this->text, 1, &rect, DT_CALCRECT);
break;
+ case EGONG_GUI_TOGGLE_BUTTON:
case EGONG_GUI_BUTTON:
DrawText(hdc, this->text, -1, &rect, DT_CALCRECT);
rect.right+=10;
@@ -119,7 +122,7 @@ HWND EGong_if_win_create(struct EGong_GUI_item *parent, struct EGong_GUI_item *t
unsigned int tmp;
struct EGong_GUI_item **children=this->child;
if(parent!=this){
- if(this->type==EGONG_GUI_TEXT||this->type==EGONG_GUI_BUTTON||this->type==EGONG_GUI_HBOX||this->type==EGONG_GUI_VBOX||this->type==EGONG_GUI_LABEL){
+ if(this->type==EGONG_GUI_TEXT||this->type==EGONG_GUI_BUTTON||this->type==EGONG_GUI_TOGGLE_BUTTON||this->type==EGONG_GUI_HBOX||this->type==EGONG_GUI_VBOX||this->type==EGONG_GUI_LABEL){
dimensions=EGong_if_win_getsize(this, 1);
if(parent->type==EGONG_GUI_HBOX||parent->type==EGONG_GUI_VBOX){
parentd=parent->userdata;
@@ -142,6 +145,8 @@ HWND EGong_if_win_create(struct EGong_GUI_item *parent, struct EGong_GUI_item *t
case EGONG_GUI_WINDOW:
hInstance=(HINSTANCE)GetWindowLong( GetForegroundWindow(), GWL_HINSTANCE );
dimensions=EGong_if_win_getsize(this, 1);
+ dimensions.right+=2*GetSystemMetrics(SM_CXSIZEFRAME);
+ dimensions.bottom+=2*GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYSIZE);
element=CreateWindow(EGong_if_win_getmsg.lpszClassName, this->text, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, dimensions.right+(unsigned int)this->extra, dimensions.bottom+(unsigned int)this->extra, 0, 0, hInstance, 0);
break;
case EGONG_GUI_TEXT:
@@ -150,6 +155,9 @@ HWND EGong_if_win_create(struct EGong_GUI_item *parent, struct EGong_GUI_item *t
case EGONG_GUI_BUTTON:
element=CreateWindow(L"Button", this->text, WS_VISIBLE | WS_CHILD, dimensions.left, dimensions.top, dimensions.right, dimensions.bottom, parent->itemptr, (HMENU) child, NULL, NULL);
break;
+ case EGONG_GUI_TOGGLE_BUTTON:
+ element=CreateWindow(L"Button", this->text, WS_VISIBLE | WS_CHILD | BS_CHECKBOX , dimensions.left, dimensions.top, dimensions.right, dimensions.bottom, parent->itemptr, (HMENU) child, NULL, NULL);
+ break;
case EGONG_GUI_MENUITEM:
case EGONG_GUI_MENUITEM_IMAGE:
case EGONG_GUI_MENUITEM_SEPARATOR:
@@ -208,8 +216,6 @@ HWND EGong_if_win_create(struct EGong_GUI_item *parent, struct EGong_GUI_item *t
}
notify=malloc(sizeof(NOTIFYICONDATA));
if(parent==NULL){
- //struct EGong_GUI_item virtual_parent={.type=EGONG_GUI_WINDOW, .text=NULL, .tooltip=NULL, .child=NULL};
- //notify->hWnd=EGong_if_win_create(NULL, &virtual_parent, 0);
if(EGong_if_win_root==NULL){
notify->hWnd=CreateWindow(EGong_if_win_getmsg.lpszClassName, NULL, 0, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInstance, 0);
EGong_if_win_root=notify->hWnd;
@@ -228,7 +234,6 @@ HWND EGong_if_win_create(struct EGong_GUI_item *parent, struct EGong_GUI_item *t
notify->uID=12+1;
notify->uFlags=NIF_ICON | NIF_MESSAGE;
notify->uCallbackMessage=WM_TRAY_ACTION;
- //HMODULE hModule = GetModuleHandle(NULL);
notify->hIcon=LoadImage(GetModuleHandle(NULL), GUIT("Master_icon"), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
if(notify->hIcon==NULL){
do_log("Couldn't load Icon", LOG_TYPE_SIGNAL, LOG_LEVEL_ERROR);
@@ -294,13 +299,13 @@ void EGong_if_win_show_item(HWND item){
}
void EGong_if_win_free_item_value(struct EGong_GUI_item *item, void *value){
- String *str;
+ do_log("Guessing type", LOG_TYPE_NORMAL, LOG_LEVEL_DEBUG);
switch(item->type){
case EGONG_GUI_TEXT:
- str=(String *)value;
- free(str->data);
- free(str);
+ free(value);
break;
+ default:
+ do_log("Nothing to do...", LOG_TYPE_NORMAL, LOG_LEVEL_DEBUG);
}
}
void *EGong_if_win_get_item_value(struct EGong_GUI_item *item){
@@ -323,8 +328,12 @@ void *EGong_if_win_get_item_value(struct EGong_GUI_item *item){
}
msg[bytes]='\0';
ret=(void *)msg;
+
free(text);
break;
+ case EGONG_GUI_TOGGLE_BUTTON:
+ ret=(void *)(intptr_t)(unsigned int)(((Button_GetState(item->itemptr)&BST_PUSHED)>0) ? 1 : 0);
+ break;
case EGONG_GUI_WINDOW:
ret=(void *)item->itemptr;
break;
@@ -369,7 +378,7 @@ void EGong_if_win_actionhandler(struct EGong_GUI_item *item){
do_log("We have action!1", LOG_TYPE_NORMAL, LOG_LEVEL_DEBUG);
unsigned int i=0;
for(i=0; item->events[i]!=NULL; i++){
- EGong_GUI_event_callback(item->events[i]);
+ EGong_GUI_event_callback(item, item->events[i]);
}
}
diff --git a/src/Util/Command.c b/src/Util/Command.c
@@ -111,11 +111,11 @@ int EGong_command_exec(struct EGong_command *command, void **data){
strncpy(strex->str.data, charptr, len);
break;
case EGONG_COMMAND_BIT_SET:
- if(((unsigned int *)data)[1]){
- *(unsigned int *)command->pointer|=((unsigned int *)data)[0];
+ if((unsigned int)((intptr_t *)data)[1]){
+ *(unsigned int *)command->pointer|=(unsigned int)((intptr_t *)data)[0];
}
else{
- *(unsigned int *)command->pointer&=~((unsigned int *)data)[0];
+ *(unsigned int *)command->pointer&=~(unsigned int)((intptr_t *)data)[0];
}
break;
case EGONG_COMMAND_UINT_INC: