2 /// \file BaseButtons.cc
3 /// Support class for BaseFrame
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 "BaseButtons.h"
23 #include "BaseFrame.h"
24 #include "PNGButton.h"
25 #include "windowids.h"
32 //////////////////////////////////////////////////////////////////////////////
35 BaseButtons::BaseButtons(wxWindow
*parent
)
38 // first, discover the size of the average button
39 wxString file
= GetButtonFilename(MainMenu_BackupAndRestore
,
42 m_buttonWidth
= sizer
.GetWidth();
43 m_buttonHeight
= sizer
.GetHeight();
45 for( int i
= MainMenu_FirstButton
; i
<= MainMenu_LastButton
; i
++ ) {
46 int row
= (i
- MainMenu_FirstButton
) / 3;
47 int col
= (i
- MainMenu_FirstButton
) % 3;
48 int y_offset
= MAIN_HEADER_OFFSET
; // skip the header
50 PNGButton
*button
= new PNGButton(parent
, i
,
52 row
* m_buttonHeight
+ y_offset
,
55 m_buttons
.push_back(button
);
59 BaseButtons::~BaseButtons()
61 vector
<PNGButton
*>::iterator b
= m_buttons
.begin();
62 for( ; b
!= m_buttons
.end(); ++b
) {
68 PNGButton
* BaseButtons::CalculateHit(int x
, int y
)
70 int col
= x
/ m_buttonWidth
;
71 if( x
< 0 || col
< 0 || col
> 2 )
74 int y_offset
= MAIN_HEADER_OFFSET
; // graphic header size
76 int row
= (y
- y_offset
) / m_buttonHeight
;
77 if( y
< y_offset
|| row
< 0 || row
> 2 )
80 unsigned int index
= col
+ row
* 3;
81 if( index
>= m_buttons
.size() )
84 return m_buttons
[index
];
87 void BaseButtons::InitAll(wxDC
&dc
)
89 vector
<PNGButton
*>::iterator b
= m_buttons
.begin();
90 for( ; b
!= m_buttons
.end(); ++b
) {
95 void BaseButtons::DrawAll(wxDC
&dc
)
97 vector
<PNGButton
*>::iterator b
= m_buttons
.begin();
98 for( ; b
!= m_buttons
.end(); ++b
) {
103 void BaseButtons::HandleMotion(wxDC
&dc
, int x
, int y
)
105 PNGButton
*hit
= CalculateHit(x
, y
);
106 if( hit
!= m_current
) {
109 m_current
->Normal(dc
);
114 // draw the new state
116 m_current
->Focus(dc
);
120 void BaseButtons::HandleDown(wxDC
&dc
, int x
, int y
)
122 HandleMotion(dc
, x
, y
);
128 void BaseButtons::HandleUp(wxDC
&dc
, int x
, int y
)
130 HandleMotion(dc
, x
, y
);
131 if( m_current
&& m_current
->IsPushed() ) {
132 m_current
->Click(dc
);