lib: removed dead code from Bookmark parser
[barry/progweb.git] / desktop / src / ClickImage.cc
blobf119fc2eb161eccac83b867ca88468c8439d3790
1 ///
2 /// \file ClickImage.cc
3 /// Clickable image class
4 ///
6 /*
7 Copyright (C) 2009-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include "ClickImage.h"
24 //////////////////////////////////////////////////////////////////////////////
25 // ClickableImage
27 ClickableImage::ClickableImage(wxWindow *parent,
28 const wxBitmap &image,
29 int ID,
30 int x, int y,
31 bool event_on_up,
32 const wxCursor &hover)
33 : m_parent(parent)
34 , m_id(ID)
35 , m_image(image)
36 , m_x(x)
37 , m_y(y)
38 , m_focus(false)
39 , m_event_on_up(event_on_up)
40 , m_hover_cursor(hover)
44 bool ClickableImage::CalculateHit(int x, int y)
46 return ( x >= m_x && x < (m_x + m_image.GetWidth()) )
48 ( y >= m_y && y < (m_y + m_image.GetHeight()) );
51 void ClickableImage::Draw(wxDC &dc)
53 dc.DrawBitmap(m_image, m_x, m_y, true);
56 void ClickableImage::HandleMotion(wxDC &dc, int x, int y)
58 bool focus = CalculateHit(x, y);
60 if( focus && !m_focus ) {
61 // newly in focus
62 m_parent->SetCursor(m_hover_cursor);
64 else if( m_focus && !focus ) {
65 // not in focus anymore
66 m_parent->SetCursor(wxNullCursor);
69 // remember state
70 m_focus = focus;
73 void ClickableImage::HandleDown(wxDC &dc, int x, int y)
75 if( !m_event_on_up ) {
76 m_focus = CalculateHit(x, y);
78 if( m_focus ) {
79 // replace the cursor
80 m_parent->SetCursor(wxNullCursor);
81 m_focus = false;
83 // send the event
84 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED,m_id);
85 m_parent->GetEventHandler()->ProcessEvent(event);
90 void ClickableImage::HandleUp(wxDC &dc, int x, int y)
92 if( m_event_on_up ) {
93 m_focus = CalculateHit(x, y);
95 if( m_focus ) {
96 // replace the cursor
97 m_parent->SetCursor(wxNullCursor);
98 m_focus = false;
100 // send the event
101 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED,m_id);
102 m_parent->GetEventHandler()->ProcessEvent(event);