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

📄 desktop.c

📁 在ecos 下mingui 的移植开发
💻 C
📖 第 1 页 / 共 5 页
字号:
// $Id: desktop.c,v 1.34 2000/11/26 07:18:59 ymwei Exp $//// desktop.c: The Desktop module.//// Copyright (C) 1999, 2000, Wei Yongming.// Copyright (C) 1999, 2000, EESG of ICT.//// Current maintainer: Wei Yongming./***  This library is free software; you can redistribute it and/or**  modify it under the terms of the GNU Library General Public**  License as published by the Free Software Foundation; either**  version 2 of the License, or (at your option) any later version.****  This library is distributed in the hope that it will be useful,**  but WITHOUT ANY WARRANTY; without even the implied warranty of**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU**  Library General Public License for more details.****  You should have received a copy of the GNU Library General Public**  License along with this library; if not, write to the Free**  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,**  MA 02111-1307, USA*/// Create date: 1999.04.19//// Modify records:////  Who             When        Where       For What                Status//-----------------------------------------------------------------------------//  Wei Yongming    1999.9.11   Tsinghua    WS_DISABLED             done//  Wei Yongming    1999.9.28   Tsinghua    Remove collector thread done//  Wei Yongming    1999.9.28   Tsinghua    Timer module to desktop done//  Wei Yongming    1999.10.28  Tsinghua    Desktop Menu            done//  Wei Yongming    2000.11.05  Wudaokou    add message.c           done//  Wei Yongming    2000.11.05  Wudaokou    add init.c              done//// TODO://#include <stdio.h>#include <stdlib.h>#include <string.h>#include <pthread.h>#include <semaphore.h>#ifndef __ECOS# include <sys/termios.h>#endif#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "cliprect.h"#include "gal.h"#include "internals.h"#include "ctrlclass.h"#include "menu.h"#include "timer.h"#ifndef lintstatic char fileid[] = "$Id: desktop.c,v 1.34 2000/11/26 07:18:59 ymwei Exp $";#endif/******************************* extern data *********************************/extern int timer_counter;/******************************* global data *********************************/pthread_t desktop, parsor, timer;int DesktopProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam);/********************* Window management support *****************************/MSGQUEUE DskMsgs;RECT g_rcScr;PMAINWIN pActiveMainWnd;HWND hCaptureWnd;static FREECLIPRECTLIST sg_FreeInvRectList;static FREECLIPRECTLIST sg_FreeClipRectList;static ZORDERINFO MainWinZOrder;static ZORDERINFO TopMostWinZOrder;static PTRACKMENUINFO sg_ptmi;static HWND sg_hIMEWnd;static HWND sg_hCaretWnd;static UINT sg_uCaretBTime;static GCRINFO sg_ScrGCRInfo;static void InitWndManagementInfo(void){    InitMainWinMetrics();    hCaptureWnd = HWND_DESKTOP;    pActiveMainWnd = NULL;    sg_ptmi = NULL;    sg_hIMEWnd = HWND_DESKTOP;    sg_hCaretWnd = HWND_DESKTOP;    g_rcScr.left = g_rcScr.top = 0;    g_rcScr.right = GetGDCapability (HDC_SCREEN, GDCAP_MAXX);    g_rcScr.bottom = GetGDCapability (HDC_SCREEN, GDCAP_MAXY);    InitClipRgn (&sg_ScrGCRInfo.crgn, &sg_FreeClipRectList);    SetClipRgn (&sg_ScrGCRInfo.crgn, &g_rcScr);    pthread_mutex_init (&sg_ScrGCRInfo.lock, NULL);    sg_ScrGCRInfo.age = 0;}BITMAP SystemBitmap [SYSBMP_ITEM_NUMBER];HICON  LargeSystemIcon [SYSICO_ITEM_NUMBER] = {0};HICON  SmallSystemIcon [SYSICO_ITEM_NUMBER] = {0};static void InitZOrderInfo (PZORDERINFO pZOrderInfo, HWND hHost);BOOL InitDesktop (void){    int i;    int nIconNr;    char szValue [12];        /*     * Init ZOrderInfo here.     */    InitZOrderInfo (&MainWinZOrder, HWND_DESKTOP);    InitZOrderInfo (&TopMostWinZOrder, HWND_DESKTOP);        /*     * Init heap of clipping rects.     */    if (!InitFreeClipRectList (&sg_FreeClipRectList, SIZE_CLIPRECTHEAP)) {        fprintf (stderr, "DESKTOP: Allocate free clip rect heap failure!\n");        return FALSE;    }    /*     * Init heap of invalid rects.     */    if (!InitFreeClipRectList (&sg_FreeInvRectList, SIZE_INVRECTHEAP)) {        fprintf (stderr, "DESKTOP: Allocate free invalid rect heap failure!\n");        return FALSE;    }    /*     * Load system bitmaps here.     */    if (!LoadSystemBitmap (SystemBitmap,     "minimize")) return FALSE;    if (!LoadSystemBitmap (SystemBitmap + 1, "maximize")) return FALSE;    if (!LoadSystemBitmap (SystemBitmap + 2, "restore")) return FALSE;    if (!LoadSystemBitmap (SystemBitmap + 3, "close")) return FALSE;    if (!LoadSystemBitmap (SystemBitmap + 4,  "arrowup")) return FALSE;    if (!LoadSystemBitmap (SystemBitmap + 5,  "arrowupd")) return FALSE;    if (!LoadSystemBitmap (SystemBitmap + 6,  "arrowdown")) return FALSE;    if (!LoadSystemBitmap (SystemBitmap + 7,  "arrowdownd")) return FALSE;    if (!LoadSystemBitmap (SystemBitmap + 8,  "arrowleft")) return FALSE;    if (!LoadSystemBitmap (SystemBitmap + 9,  "arrowleftd")) return FALSE;    if (!LoadSystemBitmap (SystemBitmap + 10, "arrowright")) return FALSE;    if (!LoadSystemBitmap (SystemBitmap + 11, "arrowrightd")) return FALSE;    /*     * Load system icons here.     */    if( GetValueFromEtcFile(ETCFILEPATH, "iconinfo", "iconnumber",                             szValue, 10) < 0 )        return FALSE;    nIconNr = atoi(szValue);    if (nIconNr <= 0)        return FALSE;    nIconNr = nIconNr < SYSICO_ITEM_NUMBER ? nIconNr : SYSICO_ITEM_NUMBER;    for (i = 0; i < nIconNr; i++) {        sprintf(szValue, "icon%d", i);                SmallSystemIcon [i] = LoadSystemIcon (szValue, 1);        LargeSystemIcon [i] = LoadSystemIcon (szValue, 0);        if (SmallSystemIcon [i] == 0                || LargeSystemIcon [i] == 0)            return FALSE;    }        // Init Window Management information.    InitWndManagementInfo();    return TRUE;}void TerminateDesktop (void){    int i;        for (i=0; i<SYSBMP_ITEM_NUMBER; i++)        UnloadBitmap (SystemBitmap + i);    for (i=0; i<SYSICO_ITEM_NUMBER; i++) {        if (SmallSystemIcon [i])            DestroyIcon (SmallSystemIcon [i]);        if (LargeSystemIcon [i])            DestroyIcon (LargeSystemIcon [i]);    }    DestroyFreeClipRectList (&sg_FreeClipRectList);    DestroyFreeClipRectList (&sg_FreeInvRectList);}PGCRINFO GetGCRgnInfo(HWND hWnd){    if (hWnd == HWND_DESKTOP)        return &sg_ScrGCRInfo;    return ((PMAINWIN)hWnd)->pGCRInfo;}inline void DesktopSetActiveWindow(PMAINWIN pWin){    if (sg_hIMEWnd != HWND_DESKTOP && pWin) {        if (pWin->dwExStyle & WS_EX_IMECOMPOSE)            SendNotifyMessage (sg_hIMEWnd, MSG_IME_OPEN, 0, 0);        else            SendNotifyMessage (sg_hIMEWnd, MSG_IME_CLOSE, 0, 0);                    SendNotifyMessage (sg_hIMEWnd, MSG_IME_SETTARGET, (WPARAM)pWin, 0);    }    pActiveMainWnd = pWin;}static HWND DesktopSetCapture(HWND hwnd){    HWND hTemp;    hTemp = hCaptureWnd;    hCaptureWnd = hwnd;    return hTemp;}static void dskScreenToClient (PMAINWIN pWin, const RECT* rcScreen, RECT* rcClient){    PCONTROL pParent;    rcClient->top = rcScreen->top - pWin->ct;    rcClient->left = rcScreen->left - pWin->cl;    rcClient->right = rcScreen->right - pWin->cl;    rcClient->bottom = rcScreen->bottom - pWin->ct;    pParent = (PCONTROL) pWin;    while ((pParent = pParent->pParent)) {        rcClient->top -= pParent->ct;        rcClient->left -= pParent->cl;        rcClient->right -= pParent->cl;        rcClient->bottom -= pParent->ct;    }}static void dskScreenToWindow (PMAINWIN pWin, const RECT* rcScreen, RECT* rcWindow){    PCONTROL pParent;    rcWindow->top = rcScreen->top - pWin->top;    rcWindow->left = rcScreen->left - pWin->left;    rcWindow->right = rcScreen->right - pWin->left;    rcWindow->bottom = rcScreen->bottom - pWin->top;    pParent = (PCONTROL) pWin;    while ((pParent = pParent->pParent)) {        rcWindow->top -= pParent->ct;        rcWindow->left -= pParent->cl;        rcWindow->right -= pParent->cl;        rcWindow->bottom -= pParent->ct;    }}static void dskClientToScreen (PMAINWIN pWin, const RECT* rcClient, RECT* rcScreen){    PCONTROL pParent;    rcScreen->top = rcClient->top + pWin->ct;    rcScreen->left = rcClient->left + pWin->cl;    rcScreen->right = rcClient->right + pWin->cl;    rcScreen->bottom = rcClient->bottom + pWin->ct;    pParent = (PCONTROL) pWin;    while ((pParent = pParent->pParent)) {        rcScreen->top += pParent->ct;        rcScreen->left += pParent->cl;        rcScreen->right += pParent->cl;        rcScreen->bottom += pParent->ct;    }}#if 0static void dskWindowToScreen (PMAINWIN pWin, const RECT* rcWindow, RECT* rcScreen){    PCONTROL pParent;    rcScreen->top = rcWindow->top + pWin->top;    rcScreen->left = rcWindow->left + pWin->left;    rcScreen->right = rcWindow->right + pWin->left;    rcScreen->bottom = rcWindow->bottom + pWin->top;    pParent = (PCONTROL) pWin;    while ((pParent = pParent->pParent)) {        rcScreen->top += pParent->ct;        rcScreen->left += pParent->cl;        rcScreen->right += pParent->cl;        rcScreen->bottom += pParent->ct;    }}#endifstatic void dskGetWindowRectInScreen (PMAINWIN pWin, RECT* prc){    PCONTROL pParent;    PCONTROL pCtrl;    pParent = pCtrl = (PCONTROL)pWin;    prc->left = pCtrl->left;    prc->top  = pCtrl->top;    prc->right = pCtrl->right;    prc->bottom = pCtrl->bottom;    while ((pParent = pParent->pParent)) {        prc->left += pParent->cl;        prc->top  += pParent->ct;        prc->right += pParent->cl;        prc->bottom += pParent->ct;    }}static void dskGetClientRectInScreen (PMAINWIN pWin, RECT* prc){    PCONTROL pCtrl;    PCONTROL pParent;    pParent = pCtrl = (PCONTROL) pWin;    prc->left = pCtrl->cl;    prc->top  = pCtrl->ct;    prc->right = pCtrl->cr;    prc->bottom = pCtrl->cb;    while ((pParent = pParent->pParent)) {        prc->left += pParent->cl;        prc->top  += pParent->ct;        prc->right += pParent->cl;        prc->bottom += pParent->ct;    }}/************************* ZOrder operation **********************************/static void InitZOrderInfo(PZORDERINFO pZOrderInfo, HWND hHost){    pZOrderInfo->nNumber = 0;    pZOrderInfo->hWnd = hHost;    pZOrderInfo->pTopMost = NULL;}// reset clip info of windowstatic void reset_window (PMAINWIN pWin, RECT* rcWin){    PGCRINFO pGCRInfo;    RECT rcTemp;    pGCRInfo = pWin->pGCRInfo;    IntersectRect (&rcTemp, rcWin, &g_rcScr);    SetClipRgn (&pGCRInfo->crgn, &rcTemp);}static void start_clip_window (PMAINWIN pWin){    pthread_mutex_lock (&pWin->pGCRInfo->lock);}static void end_clip_window (PMAINWIN pWin){    pWin->pGCRInfo->age ++;    pthread_mutex_unlock (&pWin->pGCRInfo->lock);}// clip by all windows in specified zorder// call start_clip_window and end_clip_window.static void clip_by_windows (ZORDERINFO* zorder, PMAINWIN pWin){    PZORDERNODE pNode;    PMAINWIN pTemp;    RECT rcTemp;        pNode = zorder->pTopMost;    while (pNode)    {        pTemp = (PMAINWIN)(pNode->hWnd);        if (pTemp->dwStyle & WS_VISIBLE) {            dskGetWindowRectInScreen (pTemp, &rcTemp);            SubtractClipRect (&pWin->pGCRInfo->crgn, &rcTemp);        }        pNode = pNode->pNext;    }}// clip all windows in specified zorderstatic void clip_windows (ZORDERINFO* zorder, RECT* rcWin){    PZORDERNODE pNode;    PGCRINFO pGCRInfo;        pNode = zorder->pTopMost;    while (pNode)    {        if (((PMAINWIN)(pNode->hWnd))->dwStyle & WS_VISIBLE) {            pGCRInfo = ((PMAINWIN)(pNode->hWnd))->pGCRInfo;                    pthread_mutex_lock (&pGCRInfo->lock);            SubtractClipRect (&pGCRInfo->crgn, rcWin);            pGCRInfo->age ++;            pthread_mutex_unlock (&pGCRInfo->lock);        }        pNode = pNode->pNext;    }}// clip desktopstatic void clip_desktop (RECT* rcWin){    pthread_mutex_lock (&sg_ScrGCRInfo.lock);    SubtractClipRect (&sg_ScrGCRInfo.crgn, rcWin);    sg_ScrGCRInfo.age ++;    pthread_mutex_unlock (&sg_ScrGCRInfo.lock);}// clip all windows under this window.static void clip_windows_under_this (ZORDERINFO* zorder, PMAINWIN pWin, RECT* rcWin){    PZORDERNODE pNode;    PGCRINFO pGCRInfo;        pNode = zorder->pTopMost;    while (pNode->hWnd != (HWND)pWin)        pNode = pNode->pNext;    pNode = pNode->pNext;    while (pNode)    {        if (((PMAINWIN)(pNode->hWnd))->dwStyle & WS_VISIBLE) {            pGCRInfo = ((PMAINWIN)(pNode->hWnd))->pGCRInfo;                    pthread_mutex_lock (&pGCRInfo->lock);            SubtractClipRect (&pGCRInfo->crgn, rcWin);            pGCRInfo->age ++;            pthread_mutex_unlock (&pGCRInfo->lock);        }        pNode = pNode->pNext;    }}static void clip_by_all_above_this (ZORDERINFO* zorder, PMAINWIN pWin){    PZORDERNODE pNode;    PGCRINFO pGCRInfo = pWin->pGCRInfo;    PMAINWIN pTemp;

⌨️ 快捷键说明

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