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

📄 message.c

📁 在ecos 下mingui 的移植开发
💻 C
📖 第 1 页 / 共 2 页
字号:
// $Id: message.c,v 1.6 2000/11/23 06:26:38 ymwei Exp $//// message.c: The Messaging module.//// Copyright (C) 2000, Wei Yongming.//// Current maintainer: Wei Yongming.// Create date: 2000/11/05///***  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*///// Modify records:////  Who             When        Where       For What                Status//-----------------------------------------------------------------------------//// 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"#ifndef lintstatic char fileid[] = "$Id: message.c,v 1.6 2000/11/23 06:26:38 ymwei Exp $";#endif/******************************* extern data *********************************/extern pthread_t desktop, parsor, timer;extern int DesktopProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam);extern MSGQUEUE DskMsgs;extern HWND hCaptureWnd;/****************************** Message support ******************************/static FREEQMSGLIST FreeQMSGList;/* QMSG allocation */BOOL InitFreeQMSGList (void){    if( !(FreeQMSGList.heap = malloc (sizeof(QMSG)*SIZE_QMSG_HEAP)))         return FALSE;            FreeQMSGList.free = 0;    pthread_mutex_init (&FreeQMSGList.lock, NULL);    FreeQMSGList.head = FreeQMSGList.tail = NULL;    FreeQMSGList.nr = 0;    return TRUE;}static PQMSG QMSGAlloc (void){    PQMSG pqmsg;    pthread_mutex_lock (&FreeQMSGList.lock);    if (FreeQMSGList.head) {        pqmsg = FreeQMSGList.head;        FreeQMSGList.head = pqmsg->next;        FreeQMSGList.nr --;    }    else {        if (FreeQMSGList.free < SIZE_QMSG_HEAP) {            pqmsg = FreeQMSGList.heap + FreeQMSGList.free;            pqmsg->fromheap = TRUE;            FreeQMSGList.free ++;        }        else {            pqmsg = malloc (sizeof(QMSG));            if (pqmsg == NULL)                fprintf (stderr, "DESKTOP: allocating qmessage failure!\n");            else                pqmsg->fromheap = FALSE;        }    }    pthread_mutex_unlock (&FreeQMSGList.lock);    return pqmsg;}static void FreeQMSG (PQMSG pqmsg){    pthread_mutex_lock (&FreeQMSGList.lock);    pqmsg->next = NULL;    if (FreeQMSGList.head) {        FreeQMSGList.tail->next = pqmsg;        FreeQMSGList.tail = pqmsg;    }    else {        FreeQMSGList.head = FreeQMSGList.tail = pqmsg;     }    FreeQMSGList.nr++;    pthread_mutex_unlock (&FreeQMSGList.lock);}static void EmptyFreeQMSGList (void){    PQMSG pqmsg, pTemp;    pthread_mutex_lock (&FreeQMSGList.lock);    pqmsg = FreeQMSGList.head;    while (pqmsg) {        pTemp = pqmsg->next;                if (!pqmsg->fromheap)            free (pqmsg);        pqmsg = pTemp;    }    FreeQMSGList.head = FreeQMSGList.tail = NULL;    FreeQMSGList.nr = 0;    FreeQMSGList.free = 0;    pthread_mutex_unlock (&FreeQMSGList.lock);}void DestroyFreeQMSGList (void){    EmptyFreeQMSGList ();    free (FreeQMSGList.heap);}BOOL InitMsgQueue (PMSGQUEUE pMsgQueue, int iBufferLen){    int i;        pMsgQueue->dwState = QS_EMPTY;    pthread_mutex_init (&pMsgQueue->lock, NULL);    sem_init (&pMsgQueue->wait, 0, 0);    pMsgQueue->pFirstNotifyMsg = NULL;    pMsgQueue->pLastNotifyMsg = NULL;    pMsgQueue->readpos = 0;    pMsgQueue->writepos = 0;    pMsgQueue->pFirstSyncMsg = NULL;    pMsgQueue->pLastSyncMsg = NULL;    if (iBufferLen <= 0)        iBufferLen = DEF_MSGQUEUE_LEN;            pMsgQueue->msg = malloc (sizeof (MSG) * iBufferLen);    pMsgQueue->len = iBufferLen;    pMsgQueue->TimerMask = 0xFF;    for (i = 0; i < 8; i++) {        pMsgQueue->TimerOwner [i] = HWND_DESKTOP;        pMsgQueue->TimerID [i] = 0;    }    return pMsgQueue->msg != NULL;}void DestroyMsgQueue (PMSGQUEUE pMsgQueue){    free (pMsgQueue->msg);    pMsgQueue->msg = NULL;}PMAINWIN MainWindow (HWND hWnd){    PMAINWIN pWin;    pWin = (PMAINWIN)hWnd;    if(pWin->DataType != TYPE_HWND)        return NULL;    if (pWin->WinType == TYPE_MAINWIN)        return pWin;    return NULL; }PMAINWIN GetMainWindow (HWND hWnd){    PMAINWIN pWin;    if (hWnd == HWND_DESKTOP || hWnd == HWND_INVALID)        return NULL;    pWin = (PMAINWIN)hWnd;    if(pWin->DataType != TYPE_HWND)        return NULL;    if (pWin->WinType == TYPE_MAINWIN)        return pWin;    return ((PCONTROL)hWnd)->pMainWin;}PMSGQUEUE GetMsgQueue (HWND hWnd){    if (hWnd == HWND_DESKTOP) return &DskMsgs;    return GetMainWindow (hWnd)->pMessages;}static inline WNDPROC GetWndProc (HWND hWnd){     PMAINWIN  pMainWin = (PMAINWIN)hWnd;     if (hWnd == HWND_DESKTOP)         return DesktopProc;     return pMainWin->MainWindowProc;}static HWND msgCheckInvalidRegion (PMAINWIN pWin){    PCONTROL pCtrl = (PCONTROL)pWin;    HWND hwnd;    if (pCtrl->InvRgn.rgn.head)        return (HWND)pCtrl;    pCtrl = pCtrl->children;    while (pCtrl) {        if ((hwnd = msgCheckInvalidRegion ((PMAINWIN) pCtrl)))            return hwnd;        pCtrl = pCtrl->next;    }    return 0;}static PMAINWIN msgGetHostingRoot (PMAINWIN pHosted){    PMAINWIN pHosting;        pHosting = pHosted->pHosting;    if (pHosting)        return msgGetHostingRoot (pHosting);    return pHosted;}static HWND msgCheckHostedTree (PMAINWIN pHosting){    HWND hNeedPaint;    PMAINWIN pHosted;    if ( (hNeedPaint = msgCheckInvalidRegion (pHosting)) )        return hNeedPaint;    pHosted = pHosting->pFirstHosted;    while (pHosted) {        if ( (hNeedPaint = msgCheckHostedTree (pHosted)) )            return hNeedPaint;        pHosted = pHosted->pNextHosted;    }    return 0;}static void CheckCapturedMouseMessage (PMSG pMsg){    if (pMsg->message >= MSG_FIRSTMOUSEMSG             && pMsg->message <= MSG_LASTMOUSEMSG) {        if (hCaptureWnd  && (hCaptureWnd != HWND_INVALID)                && (GetMsgQueue (hCaptureWnd) == GetMsgQueue (pMsg->hwnd))) {            if (!(pMsg->wParam | KS_CAPTURED)) {                int x, y;                x = LOWORD (pMsg->lParam);                y = HIWORD (pMsg->lParam);                ClientToScreen (pMsg->hwnd, &x, &y);                pMsg->lParam = MAKELONG (x, y);                pMsg->wParam |= KS_CAPTURED;            }            pMsg->hwnd = hCaptureWnd;        }    }}int GUIAPI GetMessage(PMSG pMsg, HWND hWnd){    PMAINWIN pWin;    PMSGQUEUE pMsgQueue;    PQMSG phead;    int slot;    if( !(pMsgQueue = GetMsgQueue(hWnd)) ) return ERR_INV_HWND;    memset (pMsg, 0, sizeof(MSG));checkagain:    if (pMsgQueue->dwState & QS_QUIT) {        pMsg->hwnd = hWnd;        pMsg->message = MSG_QUIT;        pMsg->wParam = 0;        pMsg->lParam = 0;        pMsg->pAdd = NULL;        pMsgQueue->dwState &= ~QS_QUIT;                return 0;    }    if (pMsgQueue->dwState & QS_NOTIFYMSG) {               pthread_mutex_lock (&pMsgQueue->lock);        if (pMsgQueue->pFirstNotifyMsg) {            phead = pMsgQueue->pFirstNotifyMsg;            pMsgQueue->pFirstNotifyMsg = phead->next;                        *pMsg = phead->Msg;            pMsg->pAdd = NULL;            FreeQMSG (phead);            pthread_mutex_unlock (&pMsgQueue->lock);            return 1;        }        else            pMsgQueue->dwState &= ~QS_NOTIFYMSG;                pthread_mutex_unlock (&pMsgQueue->lock);    }    if (pMsgQueue->dwState & QS_SYNCMSG) {        pthread_mutex_lock (&pMsgQueue->lock);        if (pMsgQueue->pFirstSyncMsg) {            *pMsg = pMsgQueue->pFirstSyncMsg->Msg;            pMsg->pAdd = pMsgQueue->pFirstSyncMsg;            pMsgQueue->pFirstSyncMsg = pMsgQueue->pFirstSyncMsg->pNext;            pthread_mutex_unlock (&pMsgQueue->lock);            return 1;        }        else            pMsgQueue->dwState &= ~QS_SYNCMSG;                    pthread_mutex_unlock (&pMsgQueue->lock);    }    if (pMsgQueue->dwState & QS_POSTMSG) {            pthread_mutex_lock (&pMsgQueue->lock);        if (pMsgQueue->readpos != pMsgQueue->writepos) {            *pMsg = pMsgQueue->msg[pMsgQueue->readpos];            CheckCapturedMouseMessage (pMsg);            pMsg->pAdd = NULL;            pMsgQueue->readpos++;            if (pMsgQueue->readpos >= pMsgQueue->len) pMsgQueue->readpos = 0;            pthread_mutex_unlock (&pMsgQueue->lock);            return 1;        }        else            pMsgQueue->dwState &= ~QS_POSTMSG;        pthread_mutex_unlock (&pMsgQueue->lock);    }    if (pMsgQueue->dwState & QS_PAINT) {        PMAINWIN pHostingRoot;        HWND hNeedPaint;                if (hWnd == HWND_DESKTOP) {            pMsg->hwnd = hWnd;            pMsg->message = MSG_PAINT;            pMsg->wParam = 0;            pMsg->lParam = 0;            pMsg->pAdd = NULL;            pthread_mutex_lock (&pMsgQueue->lock);            pMsgQueue->dwState &= ~QS_PAINT;            pthread_mutex_unlock (&pMsgQueue->lock);            return 1;        }        pWin = GetMainWindow (hWnd);        pMsg->message = MSG_PAINT;        pMsg->wParam = 0;        pMsg->lParam = 0;        pMsg->pAdd = NULL;        pHostingRoot = msgGetHostingRoot (pWin);        if ( (hNeedPaint = msgCheckHostedTree (pHostingRoot)) ) {            pMsg->hwnd = hNeedPaint;            return 1;        }                pthread_mutex_lock (&pMsgQueue->lock);        pMsgQueue->dwState &= ~QS_PAINT;        pthread_mutex_unlock (&pMsgQueue->lock);    }        if (pMsgQueue->dwState & QS_TIMER) {        if (hWnd == HWND_DESKTOP) {            pMsg->hwnd = hWnd;            pMsg->message = MSG_TIMER;            pMsg->wParam = 0;            pMsg->lParam = 0;            pMsg->pAdd = NULL;            pthread_mutex_lock (&pMsgQueue->lock);            pMsgQueue->dwState &= ~0x01;            pthread_mutex_unlock (&pMsgQueue->lock);            return 1;        }                pthread_mutex_lock (&pMsgQueue->lock);        for (slot=0; slot<8; slot++) {            if (pMsgQueue->dwState & (0x01 << slot))                break;        }        if (slot == 8) {            pMsgQueue->dwState &= ~QS_TIMER;            pthread_mutex_unlock (&pMsgQueue->lock);        }        else {            pMsg->hwnd = pMsgQueue->TimerOwner[slot];            pMsg->message = MSG_TIMER;            pMsg->wParam = pMsgQueue->TimerID[slot];            pMsg->lParam = 0;            pMsg->pAdd = NULL;

⌨️ 快捷键说明

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