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

📄 pw_window.c

📁 Very very small GUI. Usefull for small system, without OS or small OS. Event driven, support user m
💻 C
📖 第 1 页 / 共 4 页
字号:
                Pw_Coord   x,                 Pw_Coord   y,                 Pw_Coord   w,                 Pw_Coord   h,                Pw_Window* win){    IPW_TRACE_ENTER(WN3);    IPW_CHECK_PTR2(parent, win);    IPW_TRACE3(WN2, p, win, parent, win->parent);    IPW_CHECK_COND(win->parent == PW_NULL);
	memset(win, 0, sizeof(win));
    /* Create new window */    _WindowNew(parent->dpy, win);    /* Add window to parent */    _WindowAddToParent(win, parent);    /* Set the window rectangle */    win->area.x  = x + parent->area.x;    win->area.y  = y + parent->area.y;    win->area.w  = w;    win->area.h  = h;    IPW_TRACE_RECT(WN1, &win->area);    IPW_CHECK_WINDOW(win);    /*      * This window is not yet mapped, so the      * calculation of clip region is left to     * the map window function     */     IPW_TRACE_EXIT_V(WN3, p, win);    return(win);}/** *  Destroys a window @p win. *  @param win pointer to window to be destroyed */ void Pw_WindowDestroy(Pw_Window* win){    Pw_Window* cld_win;    Pw_Window* tmp_win;     IPW_TRACE_ENTER(WN3);    IPW_CHECK_PTR(win);    IPW_CHECK_WINDOW(win);    IPW_TRACE1(WN2, p, win);    /* Send destroy event */    IPw_EventSendDestroy(win);    /*      * Unmap window to be destroyed -     * this will take care of clipping     * regions and repaints of other windows      */    Pw_WindowUnmap(win);    /* Destroy all of this window children */    cld_win = win->children;    while (PW_NULL != cld_win)  {        IPW_TRACE1(WN1, p, cld_win);        tmp_win = cld_win;        cld_win = cld_win->next;        Pw_WindowDestroy(tmp_win);    }    /* Clear event hooks */    IPw_WindowClearEventHooks(win);    /* If this is the root window then we are done */    if (win == &win->dpy->root_win)    {        IPW_TRACE_EXIT(WN3);        return;    }    IPW_CHECK_PTR(win->parent);    tmp_win = win->parent;        /* Remove it from its parent */    _WindowRemoveFromParent(win);    IPW_CHECK_WINDOW(tmp_win);    IPW_TRACE_EXIT(WN3);} /** *  Sets window @p win in focus. *  @param win pointer to window *  @return true if focus was granted */ Pw_Bool Pw_WindowSetFocus(Pw_Window* win){    IPW_TRACE_ENTER(WN3);    IPW_CHECK_PTR(win);    IPW_CHECK_WINDOW(win);    IPW_TRACE2(WN2, d, win->focus_accept, win->mapped);    /*      * Start focus transfer only if target window (win)      * accepts focus and it is mapped     */     if (win->focus_accept && win->mapped)    {        IPW_TRACE1(WN1, p, win->dpy->focus_win);        /*          * If another window had focus send focus out         * event to it         */         if (PW_NULL != win->dpy->focus_win)        {            Pw_Window* fwin = win->dpy->focus_win;            win->dpy->focus_win = PW_NULL;            IPw_EventSendFocusOut(fwin);        }        /* Set the window in focus for this window display */        win->dpy->focus_win = win;        /* Send focus in event to this window */        IPw_EventSendFocusIn(win);        IPW_TRACE1(WN1, p, win->dpy->focus_win);        IPW_TRACE_EXIT_V(WN3, d, TRUE);        return(TRUE);    }    IPW_TRACE_EXIT_V(WN3, d, FALSE);    return(FALSE);}/** *  Sets window @p win out of focus. *  @param win pointer to window *  @return TRUE if focus has left @p win   */ Pw_Bool Pw_WindowLeaveFocus(Pw_Window* win){    IPW_TRACE_ENTER(WN3);    IPW_CHECK_PTR(win);    IPW_CHECK_WINDOW(win);    IPW_TRACE2(WN2, p, win->dpy->focus_win, win);    if (win->dpy->focus_win == win)    {        win->dpy->focus_win = PW_NULL;        IPw_EventSendFocusOut(win);        IPW_TRACE_EXIT_V(WN3, d, TRUE);        return(TRUE);    }    else    {        IPW_TRACE_EXIT_V(WN3, d, FALSE);        return(FALSE);    }}/** *  Maps window @p win. *  When window is mapped it is visible on display and can get focus. *  @param win pointer to window *  @see Pw_WindowUnmap *  @todo write Pw_MapWindowChildren function */ void Pw_WindowMap(Pw_Window* win){    IPW_TRACE_ENTER(WN3);    IPW_CHECK_PTR(win);    IPW_CHECK_WINDOW(win);    IPW_TRACE2M(WN2, p, win, d, win->mapped);    /* If window is mapped we have nothing to do */    if (win->mapped)    {        IPW_TRACE_EXIT(WN3);        return;    }    IPW_TRACE1(WN1, p, win->parent);    /* If window parent isn't mapped return */    if (PW_NULL != win->parent && !win->parent->mapped)    {        IPW_TRACE_EXIT(WN3);        return;    }    /* Set the mapped flag to true */    win->mapped = TRUE;/*    _SetWindowChildrenMapped(win, TRUE); */        /* Update clip region */
    _WindowUpdateClipRegion(win);    /* Update clip region for windows below this window */    _WindowUpdateClipRegionsBelow(win);    /* Repaint this window */    _WindowRepaint(win, PW_NULL, TRUE);    /* Refresh the display */    _DisplayRefresh(win->dpy, &win->clip_reg.bounds, PW_NULL);    /* Send mapped event */    IPw_EventSendMapped(win);    IPW_CHECK_WINDOW(win);    IPW_TRACE_EXIT(WN3);}/** *  Unmaps window @p win. *  When window is not mapped it is invisible and can't get focus. *  @param win pointer to window *  @see Pw_WindowMap */ void Pw_WindowUnmap(Pw_Window* win){    Pw_RegionList clip_reg;    Pw_Region*    reg;    IPW_TRACE_ENTER(WN3);    IPW_CHECK_PTR(win);    IPW_CHECK_WINDOW(win);    IPW_TRACE2M(WN2, p, win, d, win->mapped);    /* If window is not mapped we have nothing to do */    if (!win->mapped)    {        IPW_TRACE_EXIT(WN3);        return;    }    IPW_TRACE1(WN1, p, win->dpy->focus_win);    /*      * If window in focus set window out of focus before unmapping it     */    if (Pw_WindowIsInFocus(win))        Pw_WindowLeaveFocus(win);    /*     * Copy this window clip region - used for updateing windows     * wich are obscured by this window     */    _WINDOW_COPY_CLIP_REGION(&clip_reg, &win->clip_reg);    /* Set the mapped flag to false */    win->mapped = FALSE;    /* Set this window childern mapped flag to false */    _WindowSetChildrensMappedFlag(win, FALSE);    /* Set clip region of this window and its children to empty */    _WINDOW_SET_CLIP_REGION_TO_EMPTY(win);            _WindowSetChildrenClipRegionToEmpty(win);     /* Update clip region for windows below this window */    _WindowUpdateClipRegionsBelow(win);    /*      * Repaint this window parent using this window clip region      * (if we use clip region bounds or the whole window region,      * we have to repaint all of its parent children)     */    if (PW_NULL != win->parent)    {        reg = clip_reg.regs;        while (PW_NULL != reg)        {            IPW_TRACE_RECT(WN1, &reg->area);             _WindowRepaint(win->parent, &reg->area, FALSE);            reg = reg->next;        }    }    IPW_TRACE_RECT(WN1, &clip_reg.bounds);     /*      * Repaint windows below this window with this window      * clip region bounds (it is faster this way)     */     _WindowRepaintBelow(win, &clip_reg.bounds);    /* Refresh the display */    _DisplayRefresh(win->dpy, &clip_reg.bounds, PW_NULL);    /* Send the unmapped event */    IPw_EventSendUnmapped(win);    /* Free window old clip region */    _WINDOW_FREE_CLIP_REGION(&clip_reg);    IPW_CHECK_WINDOW(win);    IPW_TRACE_EXIT(WN3);}/** *  Repaints window @p win. *  @param win pointer to window *  @see Pw_WindowRepaintPart */ void Pw_WindowRepaint(Pw_Window* win){    IPW_TRACE_ENTER(WN3);    IPW_CHECK_PTR(win);    IPW_CHECK_WINDOW(win);    IPW_TRACE2(WN2, p, win, win->clip_reg.regs);    IPW_TRACE2(WN1, d, win->clip_reg.regs_num, win->mapped);    if (_WINDOW_IS_CLIP_REGION_NON_EMPTY(win) && win->mapped)    {
        _WindowRepaint(win, PW_NULL, TRUE);         _DisplayRefresh(win->dpy, &win->clip_reg.bounds, PW_NULL);    }    IPW_TRACE_EXIT(WN3);} /** *  Repaints part of window @p win. *  @param win  pointer to window *  @param clip pointer to clip rectangle *  @see Pw_WindowRepaint */ void Pw_WindowRepaintPart(Pw_Window* win, Pw_Rectangle* clip){    IPW_TRACE_ENTER(WN3);    IPW_CHECK_PTR(win);    IPW_CHECK_WINDOW(win);    IPW_TRACE3(WN2, p, win, clip, win->clip_reg.regs);    IPW_TRACE2(WN1, d, win->clip_reg.regs_num, win->mapped);        if (_WINDOW_IS_CLIP_REGION_NON_EMPTY(win) && win->mapped)    {        _WindowRepaint(win, clip, TRUE);         _DisplayRefresh(win->dpy, clip, PW_NULL);    }    IPW_TRACE_EXIT(WN3);}/** *  Sets the listener of xinput events to window @win. *  @param win pointer to window *  @param num xinput num  */  void Pw_WindowSetXInputListener(Pw_Window* win, Pw_uInt num){    IPW_TRACE_ENTER(WN3);    IPW_CHECK_PTR(win);    IPW_CHECK_WINDOW(win);    IPW_TRACE2M(WN2, p, win, d, num);     IPW_FAIL(num < PW_XINPUTS_MAX_NUM, ("XInput out of range (%d)!", num));	    IPW_TRACE1(WN1, p, win->dpy->xinput_win[num]);	win->dpy->xinput_win[num] = win;    IPW_TRACE_EXIT(WN3);} /** *  Unsets the window @p win as listener of xinput events. *  @param win pointer to window *  @param num xinput num  */  void Pw_WindowUnsetXInputListener(Pw_Window* win, Pw_uInt num){    IPW_TRACE_ENTER(WN3);    IPW_CHECK_PTR(win);    IPW_CHECK_WINDOW(win);    IPW_TRACE2M(WN2, p, win, d, num);     IPW_FAIL(num < PW_XINPUTS_MAX_NUM, ("XInput out of range (%d)!", num));    IPW_TRACE1(WN1, p, win->dpy->xinput_win[num]);    IPW_CHECK_COND(win->dpy->xinput_win[num] == win);	win->dpy->xinput_win[num] = PW_NULL;    IPW_TRACE_EXIT(WN3);}/** *  Sets the shape of window @p win. *  @param win pointer to window *  @param x   window top left corner new x coord *  @param y   window top left corner new y coord *  @param w   window new width *  @param h   window new height  *  @see Pw_WindowSetPosition *  @see Pw_WindowSetSize */ void Pw_WindowSetShape(Pw_Window* win,                   Pw_Coord   x,                  Pw_Coord   y,                  Pw_Coord   w,                  Pw_Coord   h){    Pw_Coord      xoff, yoff; /* Move x offset and y offset */    Pw_Window*    cld_win;    /* Child window */    Pw_RegionList clip_old;   /* Old clip region */    Pw_Region*    reg;    IPW_TRACE_ENTER(WN3);    IPW_CHECK_PTR(win);    IPW_CHECK_WINDOW(win);    IPW_TRACE1(WN2, p, win);    IPW_TRACE4(WN1, d, x, y, w, h);    IPW_TRACE_RECT(WN1, &win->area);    /* Calculate move offset */    xoff = x - win->area.x;    yoff = y - win->area.y;    IPW_TRACE2(WN1, d, xoff, yoff);    /* Reshape window */    win->area.x = x;    win->area.y = y;    win->area.w = w;    win->area.h = h;    /* Move children */    cld_win = win->children;    while (PW_NULL != cld_win)    {        IPW_TRACE1(WN1, p, cld_win);        cld_win->area.x += xoff;        cld_win->area.y += yoff;

⌨️ 快捷键说明

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