1 // $Id: switcherwindow.cpp,v 1.3 2003/08/03 16:56:29 nedko Exp $
4 // Copyright (C) 2000,2001,2002 Nedko Arnaudov <nedko@users.sourceforge.net>
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "SwitcherWindow.h"
22 #include "DesktopSwitcher.h"
24 #include "RunDialog.h"
28 #define BACKGROUD_COLOR RGB(96,96,96)
29 #define TEXT_COLOR RGB(220,220,220)
32 CSwitcherWindow::CSwitcherWindow(CDesktopSwitcher
*pDesktopSwitcher
, CDesktop
*pDesktop
)
34 m_pDesktopSwitcher
= pDesktopSwitcher
;
35 m_pDesktop
= pDesktop
;
39 CSwitcherWindow::~CSwitcherWindow()
43 BOOL
CSwitcherWindow::Create()
45 RECT rect
= {0,0,g_Image
.GetWidth(),g_Image
.GetHeight()};
46 if (!CWindowImpl
<CSwitcherWindow
>::Create(NULL
, // Desktop is our parent
47 rect
, // Window rectangle
48 "rDesktop Switcher", // Window name
50 WS_EX_TOPMOST
|WS_EX_TOOLWINDOW
|WS_EX_LAYERED
, // Extended style
53 DWORD dwError
= GetLastError();
57 m_pDesktopSwitcher
->RegisterHotKeys(m_hWnd
);
64 LRESULT
CSwitcherWindow::OnClose(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
66 m_pDesktopSwitcher
->Exit();
70 LRESULT
CSwitcherWindow::OnHotKey(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
72 WORD wVKey
= HIWORD(lParam
);
73 WORD wModifiers
= LOWORD(lParam
);
74 m_pDesktopSwitcher
->HotKeyPressed(wVKey
,wModifiers
);
79 void CSwitcherWindow::ToggleVisible()
81 ShowWindow(IsWindowVisible()?SW_HIDE
:SW_SHOW
);
84 LRESULT
CSwitcherWindow::OnRButtonDown(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
87 HMENU hMenu
= CreatePopupMenu();
89 mi
.cbSize
= sizeof(MENUITEMINFO
);
90 mi
.fMask
= MIIM_TYPE
|MIIM_ID
;
91 mi
.fType
= MFT_STRING
;
93 mi
.dwTypeData
= "Run...";
95 InsertMenuItem(hMenu
,n
++,TRUE
,&mi
);
97 mi
.dwTypeData
= "Exit";
99 InsertMenuItem(hMenu
,n
++,TRUE
,&mi
);
102 pt
.x
= LOWORD(lParam
);
103 pt
.y
= HIWORD(lParam
);
105 TrackPopupMenu(hMenu
,TPM_LEFTALIGN
,pt
.x
,pt
.y
,0,m_hWnd
,NULL
);
109 void CSwitcherWindow::DrawWindow()
111 const char *pszDesktopName
= m_pDesktop
->GetDesktopName();
112 HDC hScreenDC
= NULL
;
113 HDC hMemoryDC
= NULL
;
114 HBITMAP hBitmap
= NULL
;
119 // setup the blend function
120 BLENDFUNCTION blendPixelFunction
= { AC_SRC_OVER
, 0, 0xFF,AC_SRC_ALPHA
};
122 POINT ptSrc
= {0,0}; // start point of the copy from hMemoryDC to hScreenDC
123 POINT ptWindowScreenPosition
= {r
.left
,r
.top
};
124 SIZE szWindow
= {g_Image
.GetWidth(), g_Image
.GetHeight()};
126 if (pszDesktopName
== NULL
)
129 hScreenDC
= ::GetDC(m_hWnd
);
130 if (hScreenDC
== NULL
)
133 hMemoryDC
= ::CreateCompatibleDC(hScreenDC
);
134 if (hMemoryDC
== NULL
)
137 hBitmap
= g_Image
.CreateBitmap(hMemoryDC
);
141 if (SelectObject(hMemoryDC
,hBitmap
) == NULL
)
144 // perform the alpha blend
145 UpdateLayeredWindow(m_hWnd
,
147 &ptWindowScreenPosition
,
157 VERIFY(DeleteDC(hMemoryDC
));
160 VERIFY(ReleaseDC(hScreenDC
));
163 VERIFY(DeleteObject(hBitmap
));
166 LRESULT
CSwitcherWindow::OnNCHitText(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
171 LRESULT
CSwitcherWindow::OnRun(WORD wNotifyCode
, WORD wID
, HWND hWndCtl
, BOOL
& bHandled
)
175 const char *szExec
= dlg
.DoModal(m_hWnd
);
177 m_pDesktop
->Run(szExec
);
181 LRESULT
CSwitcherWindow::OnExit(WORD wNotifyCode
, WORD wID
, HWND hWndCtl
, BOOL
& bHandled
)
183 m_pDesktopSwitcher
->Exit();
187 void CSwitcherWindow::Destroy()
189 VERIFY(DestroyWindow());
192 void CSwitcherWindow::OnRun()
194 PostMessage(WM_COMMAND
,MAKEWPARAM(ID_RUN
,1),NULL
);
197 LRESULT
CSwitcherWindow::OnExitSizeMove(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
200 VERIFY(GetWindowRect(&rect));
201 if (rect.left > -DOCK && rect.left < DOCK)
203 rect.right -= rect.left;
207 if (rect.top+11 > -DOCK && rect.top+11 < DOCK)
209 rect.bottom -= rect.top+11;
213 VERIFY(SetWindowPos(NULL,rect.left,rect.top,10,10,SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER|SWP_SHOWWINDOW));*/