📄 lgui.c
字号:
/* Copyright (C) 2004-2005 Li Yudong*//*** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program 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 General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program; if not, write to the Free Software** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include "./include/common.h"#include "./include/rect.h"#include "./include/mouse.h"#include "./include/keyboard.h"#include "./include/framebuffer.h"#include "./include/socketio.h"#include "./include/blockheap.h"#include "./include/invalidregion.h"#include "./include/clipregion.h"#include "./include/message.h"#include "./include/regclass.h"#include "./include/hdc.h"#include "./include/hdcbitblt.h"#include "./include/caret.h"#include "./include/winnc.h"#include "./include/winbase.h"#include "./include/window.h"#include "./include/lguiapp.h"#include "./include/ipcmsg.h"#include "./include/gdi.h"#include "./include/text.h"#include "./include/button.h"#include "./include/xml.h"#include "./include/stack.h"#include "./include/scrollbar.h"#include "./include/timer.h"#include "./include/lgui.h"#include "./include/status.h"#include "./include/idlecontrol.h"#include "./include/imewin.h"#include "./include/keyboard_pro.h"#include "./include/skbwin.h"#include "./include/pinyin.h"#include "./include/filedir.h"#include "./include/system.h"#include "./include/startmenu.h"extern PWindowsTree _lGUI_pActiveWin;extern PWindowsTree _lGUI_pFocus;extern PWindowsTree _lGUI_pWindowsTree;extern PlGUIAppStat _lGUI_pAppStat;extern PWindowsTree _lGUI_pImeWindow;extern PWindowsTree _lGUI_pSkbWindow;extern PWindowsTree _lGUI_pStartMenuWindow;extern WndCaptureMouse _lGUI_wndCaptureMouse;extern char** environ;#define ID_TABCONTROL 100#define ID_TASKBAR 101#define ID_SCROLLBAR 102#define ID_USER 1024PDeskIconInfo pDeskIconInfo;HWND hWndTab = NULL;//================================================================int WinMain(){ char pString[256]; char *pEnvStr; HANDLE hWnd; WNDCLASSEX wcex; MSG msg; if(!InitGUIServer()) return 0; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = 0; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = 0; wcex.hIcon = 0; wcex.hCursor = 0; wcex.hbrBackground = CreateSolidBrush(RGB(200,100,20)); wcex.lpszMenuName = NULL; wcex.lpszClassName = "desktop"; wcex.hIconSm = 0; RegisterClass(&wcex); pEnvStr=getenv("LGUI_HOME"); if(!pEnvStr){ printerror("Env variable LGUI_HOME is Null!"); return false; } strcpy(pString,pEnvStr); strcat(pString,"/pics/sys/mainback.bmp"); hWnd = CreateWindow("desktop", "desktop", WS_DESKTOP , 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, NULL, pString); if (!hWnd) return false; ShowWindow(hWnd, true); //UpdateWindow(hWnd); //ShowWindow((HWND)_lGUI_pSkbWindow,true); //ShowWindow((HWND)_lGUI_pImeWindow,true); while (GetMessage(&msg,hWnd)){ TranslateMessage(&msg); DispatchMessage(&msg); } TerminateGUIServer(); return 0;}LRESULT WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ static int iTabValue; FILE* fp; void* pData; static HDC hDC,hDCBack; static char pStr[128]; static RECT rc; static PAINTSTRUCT ps; char pString[256]; char *pEnvStr; PWindowsTree pWin; char* pFileName; int x,y,i,iWidth,iHeight; static HWND hWndTaskBar,hWndScrollBar; SCROLLINFO si; pWin=(PWindowsTree)hWnd; switch(message){ case LMSG_CREATE: { PDeskIconClass pClass; pFileName=(char*)lParam; if(!pFileName) return false; hDCBack = CreateCompatibleDC(NULL); if(!hDCBack) return false; fp= fopen(pFileName,"rb"); if(!fp) return false; if(!ReadBmpToBuf(fp, SCREEN_WIDTH,SCREEN_HEIGHT, (void*)(hDCBack->pData))){ free(pData); fclose(fp); return false; } fclose(fp); pWin->dwAddData = (DWORD)hDCBack; //create tab control(hWndTab is a global variable) hWndTab=CreateWindow("tabcontrol","tab", WS_CONTROL | WS_VISIBLE, 0,0,SCREEN_WIDTH,DESK_TAB_HEIGHT,hWnd,(HMENU)ID_TABCONTROL,NULL,NULL); pEnvStr=getenv("LGUI_HOME"); if(!pEnvStr){ printerror("Env variable LGUI_HOME is Null!"); return false; } GetDeskIconInfo(); //add item to the tab control pClass = pDeskIconInfo->pHead; while(pClass){ SendMessage(hWndTab,TM_ADDITEM, (WPARAM)(pClass->lpszClassName),(LPARAM)(pClass->lpszIconName)); pClass = pClass->pNext; } SendMessage(hWndTab,TM_SETCURTAB,(WPARAM)0,(LPARAM)NULL); iTabValue = 0; hWndTaskBar = CreateWindow("taskbar","taskbar",WS_CONTROL|WS_VISIBLE, 0,DESK_TASKBAR_TOP,SCREEN_WIDTH,DESK_TASKBAR_HEIGHT, hWnd,(HMENU)ID_TASKBAR,NULL,NULL); iWidth = GetSystemMetrics(SM_CXVSCROLL); iHeight = DESK_CLIENT_BOTTOM - DESK_CLIENT_TOP + 1; hWndScrollBar = CreateWindow("scrollbar","scrollbar",WS_CONTROL|WS_VSCROLL|WS_VISIBLE, DESK_CLIENT_RIGHT-GetSystemMetrics(SM_CXVSCROLL),DESK_CLIENT_TOP+1, iWidth,iHeight, hWnd,(HMENU)ID_SCROLLBAR,NULL,NULL); //setup scrollbar according first class icon si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; si.nMax = pDeskIconInfo->pHead->iScrollMax; si.nMin = pDeskIconInfo->pHead->iScrollMin; si.nPage = DESKICON_LINES_PER_PAGE; si.nPos = 0; SetScrollInfo(hWndScrollBar,SB_CTL,&si,false); SetRect(&rc, IMEWIN_LEFT, IMEWIN_TOP, IMEWIN_LEFT + IMEWIN_WIDTH - 1, IMEWIN_TOP + IMEWIN_HEIGHT - 1); CreateImeWindow(&rc); SetRect(&rc, SKBWIN_LEFT, SKBWIN_TOP, SKBWIN_LEFT + SKBWIN_WIDTH - 1, SKBWIN_TOP + SKBWIN_HEIGHT - 1); CreateSkbWindow(&rc); CreateDeskIcon(); break; } case LMSG_SHOWWINDOW: { PDeskIconClass pClass; pClass = GetCurrentClass(hWndTab); ShowClassDeskIcon(pClass); break; } case LMSG_COMMAND: switch(HIWORD(wParam)){ case BN_CLICKED: DeskIconClicked(LOWORD(wParam)); break; case TM_TABCHANGED: { int i,iValue; PDeskIconClass pClass; pClass = pDeskIconInfo->pHead; for(i=0;i<iTabValue;i++){ pClass = pClass->pNext; } HideClassDeskIcon(pClass); iValue = (int)lParam; pClass = pDeskIconInfo->pHead; for(i=0;i<iValue;i++){ pClass = pClass->pNext; } ShowClassDeskIcon(pClass); iTabValue = iValue; break; } case LMSG_VSCROLL: { ProDeskIconScroll(hWndScrollBar,hWndTab); break; } case STARTMENU_ITEM_CLICKED: ProcessStartMenuItemClicked(wParam, lParam); break; case STARTMENU_CLICKED://start button clicked ProcessStartMenuClicked(); break; default: break; } break; case LMSG_PENDOWN: CaptureMouse(hWnd,BYCLIENT); break; case LMSG_PENMOVE: //hDC=GetWindowDC(hWnd); //winSetPixel(hDC,(int)wParam,(int)lParam,RGB(0,0,0)); //ReleaseDC(hWnd,hDC); break; case LMSG_PENUP: DisCaptureMouse(); break; case LMSG_PAINT: ps.bPaintDirect=false; hDC=BeginPaint(hWnd, &ps); if(!hDC){ return true; } BitBlt(hDC,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,(HDC)(pWin->dwAddData),0,0,SRCCOPY); EndPaint(hWnd, &ps); break; case LMSG_DESTROY: DestroyImeWindow(); DestroySkbWindow(); DestroyStartMenuControl(); ReleaseDC((HWND)_lGUI_pWindowsTree,(HDC)(pWin->dwAddData)); PostQuitMessage(hWnd); break; default: return DefWndProcDesktop(hWnd, message, wParam, lParam); } return true;}LRESULT DefWndProcDesktop( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ PWindowsTree pWin; PWindowsTree pControl; PInvalidRect pInvRect; PClipRect pClipRect; HDC hDC; RECT rc; HBRUSH hBrush; COLORREF crColor; PWNDCLASSEX pWndClass; pWin=(PWindowsTree)hWnd; hDC=(HDC)wParam; switch(message){ case LMSG_NCPAINT: break; case LMSG_ACTIVEWINDOW: if(pWin->pFocus){ SetFocus(pWin->pFocus); } else{ pControl=pWin->pControlTail; if(pControl) SetFocus(pControl); } break; case LMSG_DISACTIVEWINDOW: UnSetFocus((HWND)_lGUI_pFocus); UpdateWindow((HWND)_lGUI_pFocus); break; case LMSG_ERASEBKGND: pWndClass=GetRegClass(pWin->lpszClassName); if(!pWndClass) return (LRESULT)NULL; hBrush=pWndClass->hbrBackground; crColor=((BRUSH*)hBrush)->crBrushColor; pInvRect=pWin->pInvRgn->pHead; if(hDC->iType==DC_TYPE_MEM){//Is Memory DC while(pInvRect){ pClipRect=pWin->pClipRgn->pHead; if(pInvRect->bErase){ while(pClipRect){ if(IntersectRect(&rc,&(pInvRect->rect),&(pClipRect->rect))) EraseRect2Memory(hDC,&(pWin->rect),&rc,crColor); pClipRect=pClipRect->pNext; } } pInvRect=pInvRect->pNext; } } else{ while(pInvRect){ pClipRect=pWin->pClipRgn->pHead; if(pInvRect->bErase){ while(pClipRect){ if(IntersectRect(&rc,&(pInvRect->rect),&(pClipRect->rect))) EraseRect2Screen(&rc,crColor); pClipRect=pClipRect->pNext; } } pInvRect=pInvRect->pNext; } } break; case LMSG_SRVEXIT: DestroyWindow(hWnd); break; case LMSG_IPC_DESTROYAPP: DestroyApplicationServer((int)wParam,NULL,0); break; case LMSG_RAW_MOUSEDOWN: if(!srvRawMouseDown(wParam,lParam)) return false; break; case LMSG_RAW_MOUSEUP: if(!srvRawMouseUp(wParam,lParam)) return false; break; case LMSG_RAW_MOUSEMOVE: if(!srvRawMouseMove(wParam,lParam)) return false; break; case LMSG_RAW_KEYDOWN: break; case LMSG_RAW_KEYUP: break; case LMSG_RAW_CHAR: break; } return true;}BOOL srvRawMouseDown( WPARAM wParam, LPARAM lParam){ PWNDCLASSEX pWndClass; RECT rect; int iCounter; PWindowsTree pWin; POINT point; PClipRect pCRect; int x,y; PlGUIAppStat pStat,pCurStat,pPrevStat,pThisStat,pTopStat,pActiveStat; x=(int)wParam; y=(int)lParam; pPrevStat=_lGUI_pAppStat; pStat=_lGUI_pAppStat; pTopStat=_lGUI_pAppStat; if(IsVisible((HWND)_lGUI_pStartMenuWindow)){ if(PtInRect(&(_lGUI_pStartMenuWindow->rect),x,y)){ PostMessage((HWND)_lGUI_pStartMenuWindow,LMSG_PENDOWN,wParam,lParam); return true; } DestroyStartMenuControl(); } if(IsVisible((HWND)_lGUI_pImeWindow)){ if(PtInRect(&(_lGUI_pImeWindow->rect),x,y)){ PostMessage((HWND)_lGUI_pImeWindow,LMSG_PENDOWN,wParam,lParam); return true; } } //if _lGUI_pSkbWindow is not null; if(IsVisible((HWND)_lGUI_pSkbWindow)){ if(PtInRect(&(_lGUI_pSkbWindow->rect),x,y)){ PostMessage((HWND)_lGUI_pSkbWindow,LMSG_PENDOWN,wParam,lParam); return true; } } while(pStat){ if(PtInRect(&(pStat->rc),x,y)){ point.x=x; point.y=y; if(pStat!=_lGUI_pAppStat){ pPrevStat->pNext=pStat->pNext; pStat->pNext=_lGUI_pAppStat; _lGUI_pAppStat=pStat; pCurStat=_lGUI_pAppStat->pNext; pThisStat=pPrevStat->pNext; while(pCurStat!=pThisStat){ if(pCurStat->bVisible) SubtractClipRegion (pCurStat->pClipRgn, &(_lGUI_pAppStat->rc)); SendClipRgnChangeMsg(pCurStat); pCurStat=pCurStat->pNext; } SendMsgByServer(pTopStat,LMSG_IPC_DISACTIVEAPP,NULL,0); SetInitRectClipRegion (_lGUI_pAppStat->pClipRgn, &(_lGUI_pAppStat->rc)); if(IsVisible((HWND)_lGUI_pImeWindow)) SubtractClipRegion(_lGUI_pAppStat->pClipRgn,&_lGUI_pImeWindow->rect); if(IsVisible((HWND)_lGUI_pSkbWindow)) SubtractClipRegion(_lGUI_pAppStat->pClipRgn,&_lGUI_pSkbWindow->rect); SendClipRgnChangeMsg(_lGUI_pAppStat); SendMsgByServer(_lGUI_pAppStat,LMSG_IPC_REDRAW,NULL,0); } SendMsgByServer(_lGUI_pAppStat,LMSG_PENDOWN,(void*)&point,sizeof(POINT)); DisactiveWindow(_lGUI_pWindowsTree); return true; } pPrevStat=pStat; pStat=pStat->pNext; } iCounter=1; pWin=_lGUI_pWindowsTree->pControlHead; while(pWin){ if(IsVisible((HWND)pWin) && PtInRect(&(pWin->pClipRgn->rcBound),x,y)){ pCRect=pWin->pClipRgn->pHead; while(pCRect){ if(PtInRect(&(pCRect->rect),x,y)){ pWndClass=GetRegClass(pWin->lpszClassName); if(strcmp(pWndClass->lpszClassName,"DESKICON")==0){ pActiveStat = GetActiveApplication(); if(pActiveStat){//send disactive message to the application SendMsgByServer(pActiveStat,LMSG_IPC_DISACTIVEAPP,NULL,NULL); } _lGUI_pWindowsTree->pFocus = pWin; //if a window is active, then ActiveWindow function will do nothing. //so implement the function like below if(!IsActive(_lGUI_pWindowsTree)) ActiveWindow(_lGUI_pWindowsTree); else //SetFocus(pWin); SetFocusNoPaint(pWin); } scrGetClientRect(pWin,&rect); if(PtInRect(&rect,(int)wParam,(int)lParam)){ PostMessage((HWND)pWin,LMSG_PENDOWN,wParam,lParam); } else PostMessage((HWND)pWin,LMSG_NCPENDOWN,wParam,lParam); return true; } pCRect=pCRect->pNext; } } pWin=pWin->pNext; iCounter++; } _lGUI_wndCaptureMouse.pWin = _lGUI_pWindowsTree; _lGUI_wndCaptureMouse.iByWho = BYCLIENT; pActiveStat = GetActiveApplication(); if(pActiveStat){//send disactive message to the application SendMsgByServer(pActiveStat,LMSG_IPC_DISACTIVEAPP,NULL,NULL); } ActiveWindow((HWND)_lGUI_pWindowsTree); PostMessage((HWND)_lGUI_pWindowsTree,LMSG_PENDOWN,wParam,lParam); return true;}//Get Current active application//if no active application,return null;PlGUIAppStat GetActiveApplication(){ PlGUIAppStat pActiveStat; if(_lGUI_pActiveWin)//if desktop is active,no application is active return NULL; pActiveStat = _lGUI_pAppStat; while(pActiveStat){ if(pActiveStat->bVisible == true) break; pActiveStat = pActiveStat->pNext; } return pActiveStat;}BOOL srvRawMouseMove( WPARAM wParam, LPARAM lParam){ PClipRect pCRect; POINT point; int x,y; PlGUIAppStat pStat; x=(int)wParam; y=(int)lParam; if(_lGUI_wndCaptureMouse.pWin){ if(PtInRect(&(_lGUI_wndCaptureMouse.pWin->pClipRgn->rcBound),x,y)){ pCRect=_lGUI_wndCaptureMouse.pWin->pClipRgn->pHead; while(pCRect){ if(PtInRect(&(pCRect->rect),x,y)){ if(_lGUI_wndCaptureMouse.iByWho == BYCLIENT) PostMessage((HWND)(_lGUI_wndCaptureMouse.pWin),LMSG_PENMOVE,wParam,lParam); else PostMessage((HWND)(_lGUI_wndCaptureMouse.pWin),LMSG_NCPENMOVE,wParam,lParam); return true; } pCRect=pCRect->pNext; } } } else{ pStat=_lGUI_pAppStat; if(pStat){ if(PtInRect(&(pStat->rc),x,y)){ point.x=x; point.y=y; SendMsgByServer(pStat,LMSG_PENMOVE,(void*)&point,sizeof(POINT)); return true; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -