⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pw_event.c

📁 Very very small GUI. Usefull for small system, without OS or small OS. Event driven, support user m
💻 C
字号:
#include <i_pwin.h>#include "guidebug.h"/* -------------------------------------------------------------------------- *//** *  Sends the key pressed event to window @p win or to one of its parents in *  case window @p win does't consume it. *  @param win     pointer to target window *  @param keycode code of the pressed key *  @return true if the event was successfully send *  @internal */ Pw_Bool IPw_EventSendKeyPress(Pw_Window* win, Pw_uInt keycode){    Pw_Event   event;    Pw_Window* twin;    IPW_TRACE_ENTER(EV2);    IPW_CHECK_PTR(win);    twin = win;    event.data.type   = Pw_KeyPressEventType;    event.key.keycode = keycode;     while (PW_NULL != twin)   {        IPW_TRACE3M(EV1, p, twin, p, twin->event_cb, d, keycode);        event.data.win = twin;        if (PW_NULL != twin->event_cb)  {            if (twin->event_cb(&event)) {                IPW_TRACE_EXIT_V(EV2, d, TRUE);                return(TRUE);            }        }        twin = twin->parent;    }    IPW_TRACE_EXIT_V(EV2, d, FALSE);    return(FALSE);} /** *  Sends the key released event to window @p win or to one of its parents in *  case window @p win does't consume it. *  @param win     pointer to target window *  @param keycode code of the released key *  @return true if the event was successfully send *  @internal */ Pw_Bool IPw_EventSendKeyRelease(Pw_Window* win, Pw_uInt keycode){    Pw_Event   event;    Pw_Window* twin;        IPW_TRACE_ENTER(EV2);    IPW_CHECK_PTR(win);    twin = win;    event.data.type   = Pw_KeyReleaseEventType;    event.key.keycode = keycode;     while (PW_NULL != twin)  {        IPW_TRACE3M(EV1, p, twin, p, twin->event_cb, d, keycode);        event.data.win = twin;        if (PW_NULL != twin->event_cb) {            if (twin->event_cb(&event)){                IPW_TRACE_EXIT_V(EV2, d, TRUE);                return(TRUE);            }        }        twin = twin->parent;    }    IPW_TRACE_EXIT_V(EV2, d, FALSE);    return(FALSE);} /** *  Sends the xinput event to window @p win. *  @param win pointer to target window *  @param num number of xinput  *  @param val value of xinput  *  @return true if the event was successfully send *  @internal */ Pw_Bool IPw_EventSendXInput(Pw_Window* win, Pw_uInt num, Pw_Int val){    Pw_Event event;    IPW_TRACE_ENTER(EV2);    IPW_CHECK_PTR(win);    IPW_TRACE4M(EV1, p, win, p, win->event_cb, d, num, d, val);    event.data.type   = Pw_XInputEventType;    event.xinput.num  = num;    event.xinput.val  = val;    event.data.win    = win;    if (PW_NULL != win->event_cb) {        if (win->event_cb(&event)) {            IPW_TRACE_EXIT_V(EV2, d, TRUE);            return(TRUE);        }    }    IPW_TRACE_EXIT_V(EV2, d, FALSE);    return(FALSE);} /** *  Sends the focus in (gained) event to window @p win. *  @param win pointer to target window *  @return true if the event was successfully send *  @internal */ Pw_Bool IPw_EventSendFocusIn(Pw_Window* win){    Pw_Event event;    IPW_TRACE_ENTER(EV2);    IPW_CHECK_PTR(win);    IPW_TRACE2(EV1, p, win, win->event_cb);     event.data.type = Pw_FocusInEventType;    event.data.win  = win;    if (PW_NULL != win->event_cb)    {        if (win->event_cb(&event))        {            IPW_TRACE_EXIT_V(EV2, d, TRUE);            return(TRUE);        }    }    IPW_TRACE_EXIT_V(EV2, d, FALSE);    return(FALSE);}/** *  Sends the focus out (lost) event to window @p win. *  @param win pointer to target window *  @return true if the event was successfully send *  @internal */ Pw_Bool IPw_EventSendFocusOut(Pw_Window* win){    Pw_Event event;    IPW_TRACE_ENTER(EV2);    IPW_CHECK_PTR(win);    IPW_TRACE2(EV1, p, win, win->event_cb);     event.data.type = Pw_FocusOutEventType;    event.data.win  = win;    if (PW_NULL != win->event_cb) {        if (win->event_cb(&event))  {            IPW_TRACE_EXIT_V(EV2, d, TRUE);            return(TRUE);        }    }    IPW_TRACE_EXIT_V(EV2, d, FALSE);    return(FALSE);} /** *  Sends the window mapped (visible) event to window @p win. *  @param win pointer to target window *  @return true if the event was successfully send *  @internal */ Pw_Bool IPw_EventSendMapped(Pw_Window* win){    Pw_Event event;    IPW_TRACE_ENTER(EV2);    IPW_CHECK_PTR(win);    IPW_TRACE2(EV1, p, win, win->event_cb);     event.data.type = Pw_MapEventType;    event.data.win  = win;    if (PW_NULL != win->event_cb) {        if (win->event_cb(&event)) {            IPW_TRACE_EXIT_V(EV2, d, TRUE);            return(TRUE);        }    }    IPW_TRACE_EXIT_V(EV2, d, FALSE);    return(FALSE);}/** *  Sends the window unmapped (invisible) event to window @p win. *  @param win pointer to target window *  @return true if the event was successfully send *  @internal */ Pw_Bool IPw_EventSendUnmapped(Pw_Window* win){    Pw_Event event;    IPW_TRACE_ENTER(EV2);    IPW_CHECK_PTR(win);    IPW_TRACE2(EV1, p, win, win->event_cb);     event.data.type = Pw_UnmapEventType;    event.data.win  = win;    if (PW_NULL != win->event_cb) {        if (win->event_cb(&event)) {            IPW_TRACE_EXIT_V(EV2, d, TRUE);            return(TRUE);        }    }    IPW_TRACE_EXIT_V(EV2, d, FALSE);    return(FALSE);}/** *  Sends the window reshaped event to window @p win. *  @param win pointer to target window *  @return true if the event was successfully send *  @internal */ Pw_Bool IPw_EventSendReshaped(Pw_Window* win){    Pw_Event event;    IPW_TRACE_ENTER(EV2);    IPW_CHECK_PTR(win);    IPW_TRACE2(EV1, p, win, win->event_cb);     event.data.type = Pw_ReshapeEventType;    event.data.win  = win;    if (PW_NULL != win->event_cb)  {        if (win->event_cb(&event)) {            IPW_TRACE_EXIT_V(EV2, d, TRUE);            return(TRUE);        }    }    IPW_TRACE_EXIT_V(EV2, d, FALSE);    return(FALSE);}/** *  Sends the window destroy event to window @p win. *  @param win pointer to target window *  @return true if the event was successfully send *  @internal */ Pw_Bool IPw_EventSendDestroy(Pw_Window* win){    Pw_Event event;    IPW_TRACE_ENTER(EV2);    IPW_CHECK_PTR(win);    IPW_TRACE2(EV1, p, win, win->event_cb);     event.data.type = Pw_DestroyEventType;    event.data.win  = win;    if (PW_NULL != win->event_cb)  {        if (win->event_cb(&event)) {            IPW_TRACE_EXIT_V(EV2, d, TRUE);            return(TRUE);        }    }    IPW_TRACE_EXIT_V(EV2, d, FALSE);    return(FALSE);} /** *  Sends the repaint event to window @p win. *  @param win pointer to target window *  @param gc pointer to graphic context of window @p win *  @return true if the event was successfully send *  @internal */  Pw_Bool IPw_EventSendRepaint(Pw_Window* win, Pw_GC* gc){    IPW_TRACE_ENTER(EV2);    IPW_CHECK_PTR2(win, gc);    IPW_TRACE3(EV1, p, win, gc, win->repaint_cb);	
//	GUI_DEBUG_LOG("Event REPAINT");     if (PW_NULL != win->repaint_cb) {        win->repaint_cb(gc);        IPW_TRACE_EXIT_V(EV2, d, TRUE);        return(TRUE);    }    IPW_TRACE_EXIT_V(EV2, d, FALSE);    return(FALSE);} /** *  Sends the key pressed event to the window in focus. *  @param dpy     pointer to display  *  @param keycode code of the pressed key *  @return true if the event was successfully send *  @internal */ Pw_Bool IPw_EventKeyPressed(Pw_Display* dpy, Pw_uInt keycode){    Pw_Bool ret;    IPW_TRACE_ENTER(EV2);    IPW_CHECK_PTR(dpy);    IPW_TRACE2(EV1, p, dpy, dpy->focus_win);     if (PW_NULL == dpy->focus_win)  {        IPW_TRACE_EXIT_V(EV2, d, FALSE);        return(FALSE);    }    ret = IPw_EventSendKeyPress(dpy->focus_win, keycode);    IPW_TRACE_EXIT_V(EV2, d, ret);    return(ret);}/** *  Sends the key released event to the window in focus. *  @param dpy     pointer to display  *  @param keycode code of the released key *  @return true if the event was successfully send *  @internal */ Pw_Bool IPw_EventKeyReleased(Pw_Display* dpy, Pw_uInt keycode){    Pw_Bool ret;    IPW_TRACE_ENTER(EV2);    IPW_CHECK_PTR(dpy);    IPW_TRACE2(EV1, p, dpy, dpy->focus_win);     if (PW_NULL == dpy->focus_win)  {        IPW_TRACE_EXIT_V(EV2, d, FALSE);        return(FALSE);    }    ret = IPw_EventSendKeyRelease(dpy->focus_win, keycode);    IPW_TRACE_EXIT_V(EV2, d, ret);    return(ret);} /** *  Sends the xinput event to listening window (if any). *  @param dpy pointer to display  *  @param num xinput number  *  @param val xinput value  *  @return true if the event was successfully send *  @internal */ Pw_Bool IPw_EventXInputChanged(Pw_Display* dpy, Pw_uInt num, Pw_Int val){    Pw_Bool ret;    IPW_TRACE_ENTER(EV2);    IPW_CHECK_PTR(dpy);    IPW_TRACE3M(EV1, p, dpy, d, num, d, val);     IPW_FAIL(num < PW_XINPUTS_MAX_NUM, ("XInput out of range (%d)!", num));        IPW_TRACE1(EV1, p, dpy->xinput_win[num]);    if (PW_NULL == dpy->xinput_win[num])  {        IPW_TRACE_EXIT_V(EV2, d, FALSE);        return(FALSE);    }    ret = IPw_EventSendXInput(dpy->xinput_win[num], num, val);    IPW_TRACE_EXIT_V(EV2, d, ret);    return(ret);} /*---------------------------------------------------------------------------// end of pw_event.c//--------------------------------------------------------------------------- */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -