~ubuntu-branches/ubuntu/raring/workrave/raring

« back to all changes in this revision

Viewing changes to frontend/applets/win32/src/Icon.cpp

  • Committer: Package Import Robot
  • Author(s): Francois Marier, Francois Marier, Jordi Mallach
  • Date: 2012-05-28 11:29:40 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20120528112940-bbbsjkk30fom9s8x
Tags: 1.9.909+abc941eb70-1
[ Francois Marier ]
* New upstream snapshot
  - Drop leak-fix patch (applied upstream)
  - Document how the tarball is built in README.source
* Build GNOME applets and use gsettings
* Massive update of Build-Depends as per configure.ac

* Update README.source with snapshot instructions
* Switch to machine-readable copyright file
* Update alioth git repo links
* Bump debhelper version to 9
* Bump Standards-Version to 3.9.3

[ Jordi Mallach ]
* Avoid references to GNU/Linux in manpage.
* Drop build dependency on libgnet-dev, it's obsolete and unneeded.
* Add myself to Uploaders.
* Rewrite d/rules into dh style.
  - Move all install tweaks to .install files.
  - Install manpages using dh_installman.
* As a side effect, the package installs arch-dependant data in the
  arch triplet directory; add the required Pre-Depends for m-a-support.
* Bring back GNOME Panel applet (for GNOME 3 fallback mode) and ship the
  new GNOME Shell extension (closes: #642514, #666100).
* Add private_dirs.patch: move libworkrave-private and GObject
  Introspection files to a private dir, so they are really out of the
  way, but disable it for now as it breaks the Shell extension.
* Move typelib out of the triplet dir as gobject-introspection is not
  M-A ready yet.
* Enable dh_autoreconf for the above patches.
* Add lintian overrides.
* Add necessary Breaks/Replaces as the xpm icon has moved to workrave-data.
* Prefix all debhelper files with package name.
* Suggest gnome-shell and gnome-panel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Icon.cpp --- Icon
 
2
//
 
3
// Copyright (C) 2004, 2005, 2007 Raymond Penners <raymond@dotsphinx.com>
 
4
// All rights reserved.
 
5
//
 
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.
 
10
//
 
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.
 
15
//
 
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/>.
 
18
//
 
19
// $Id$
 
20
 
 
21
#include <stdio.h>
 
22
 
 
23
#include "Icon.h"
 
24
#include "DeskBand.h"
 
25
#include "Debug.h"
 
26
#include "PaintHelper.h"
 
27
 
 
28
#define ICON_CLASS_NAME "WorkraveIcon"
 
29
 
 
30
Icon::Icon(HWND parent, HINSTANCE hinst, const char *resource, CDeskBand *deskband)
 
31
  : deskband(deskband)
 
32
{
 
33
  init(hinst);
 
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);
 
37
 
 
38
  paint_helper = new PaintHelper(hwnd);
 
39
}
 
40
 
 
41
Icon::~Icon()
 
42
{
 
43
  DestroyWindow(hwnd);
 
44
  delete paint_helper;
 
45
}
 
46
 
 
47
LRESULT CALLBACK
 
48
Icon::wnd_proc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
 
49
{
 
50
  TRACE_ENTER("Icon::WndProc");
 
51
  LRESULT lResult = 0;
 
52
  Icon  *pThis = (Icon*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
 
53
 
 
54
  switch (uMessage)
 
55
    {
 
56
    case WM_NCCREATE:
 
57
      {
 
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);
 
63
      }
 
64
      break;
 
65
 
 
66
    case WM_PAINT:
 
67
      pThis->on_paint();
 
68
      break;
 
69
 
 
70
    case WM_ERASEBKGND:
 
71
      if (PaintHelper::GetCompositionEnabled())
 
72
        {
 
73
          lResult = 1;
 
74
        }
 
75
      break;
 
76
 
 
77
    case WM_LBUTTONUP:
 
78
      SendMessage(pThis->deskband->get_command_window(), WM_USER + 1, 0, NULL);
 
79
      break;
 
80
    }
 
81
 
 
82
  if (uMessage != WM_ERASEBKGND)
 
83
    {
 
84
      lResult = DefWindowProc(hWnd, uMessage, wParam, lParam);
 
85
    }
 
86
 
 
87
  TRACE_EXIT();
 
88
  return lResult;
 
89
}
 
90
 
 
91
void
 
92
Icon::get_size(int &w, int &h) const
 
93
{
 
94
  w = 16;
 
95
  h = 16;
 
96
}
 
97
 
 
98
LRESULT
 
99
Icon::on_paint()
 
100
{
 
101
  TRACE_ENTER("Icon::OnPaint");
 
102
 
 
103
  HDC dc = paint_helper->BeginPaint();
 
104
  if (dc != NULL)
 
105
    {
 
106
      paint_helper->DrawIcon(0, 0, icon, 16, 16);
 
107
      paint_helper->EndPaint();
 
108
    }
 
109
  TRACE_EXIT();
 
110
  return 0;
 
111
}
 
112
 
 
113
void
 
114
Icon::init(HINSTANCE hinst)
 
115
{
 
116
  //If the window class has not been registered, then do so.
 
117
  WNDCLASS wc;
 
118
  if (!GetClassInfo(hinst, ICON_CLASS_NAME, &wc))
 
119
    {
 
120
      ZeroMemory(&wc, sizeof(wc));
 
121
      wc.style          = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
 
122
      wc.lpfnWndProc    = (WNDPROC)wnd_proc;
 
123
      wc.cbClsExtra     = 0;
 
124
      wc.cbWndExtra     = 0;
 
125
      wc.hInstance      = hinst;
 
126
      wc.hIcon          = NULL;
 
127
      wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
 
128
      wc.hbrBackground  = (HBRUSH)GetStockObject(HOLLOW_BRUSH);
 
129
      wc.lpszMenuName   = NULL;
 
130
      wc.lpszClassName  = ICON_CLASS_NAME;
 
131
 
 
132
      RegisterClass(&wc);
 
133
    }
 
134
}
 
135
 
 
136
void
 
137
Icon::update()
 
138
{
 
139
  TRACE_ENTER("Icon::update");
 
140
  InvalidateRect(hwnd, NULL, FALSE);
 
141
  TRACE_EXIT();
 
142
}