3
// Copyright (C) 2004, 2005, 2007 Raymond Penners <raymond@dotsphinx.com>
4
// All rights reserved.
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 3 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, see <http://www.gnu.org/licenses/>.
26
#include "PaintHelper.h"
28
#define ICON_CLASS_NAME "WorkraveIcon"
30
Icon::Icon(HWND parent, HINSTANCE hinst, const char *resource, CDeskBand *deskband)
34
icon = (HICON)LoadImage(hinst, resource, IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
35
hwnd = CreateWindowEx(0, ICON_CLASS_NAME, "",
36
WS_CHILD | WS_CLIPSIBLINGS, 0, 0, 16, 16, parent, NULL, hinst, (LPVOID)this);
38
paint_helper = new PaintHelper(hwnd);
48
Icon::wnd_proc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
50
TRACE_ENTER("Icon::WndProc");
52
Icon *pThis = (Icon*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
58
LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
59
pThis = (Icon *)(lpcs->lpCreateParams);
60
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)pThis);
61
SetWindowPos(hWnd, NULL, 0, 0, 0, 0,
62
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
71
if (PaintHelper::GetCompositionEnabled())
78
SendMessage(pThis->deskband->get_command_window(), WM_USER + 1, 0, NULL);
82
if (uMessage != WM_ERASEBKGND)
84
lResult = DefWindowProc(hWnd, uMessage, wParam, lParam);
92
Icon::get_size(int &w, int &h) const
101
TRACE_ENTER("Icon::OnPaint");
103
HDC dc = paint_helper->BeginPaint();
106
paint_helper->DrawIcon(0, 0, icon, 16, 16);
107
paint_helper->EndPaint();
114
Icon::init(HINSTANCE hinst)
116
//If the window class has not been registered, then do so.
118
if (!GetClassInfo(hinst, ICON_CLASS_NAME, &wc))
120
ZeroMemory(&wc, sizeof(wc));
121
wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
122
wc.lpfnWndProc = (WNDPROC)wnd_proc;
125
wc.hInstance = hinst;
127
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
128
wc.hbrBackground = (HBRUSH)GetStockObject(HOLLOW_BRUSH);
129
wc.lpszMenuName = NULL;
130
wc.lpszClassName = ICON_CLASS_NAME;
139
TRACE_ENTER("Icon::update");
140
InvalidateRect(hwnd, NULL, FALSE);