4 Website: http://www.vultaire.net/software/jben/
5 License: GNU General Public License (GPL) version 2
6 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt)
8 File: scrolledcheck.cpp
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>
24 #include "scrolledcheck.h"
26 BEGIN_EVENT_TABLE(ScrolledCheck
, wxCheckBox
)
27 EVT_SET_FOCUS(ScrolledCheck::OnSetFocus
)
30 ScrolledCheck::ScrolledCheck(wxScrolledWindow
*owner
, int id
, int localIndex
, const wxString
& label
)
31 : wxCheckBox(owner
, id
, label
) {
32 index
= localIndex
; /* This is our index of which checkbox this is within its parent wxScrolledWindow. */
35 void ScrolledCheck::OnSetFocus(wxFocusEvent
& event
) {
36 int viewX
, viewY
, sizeY
, stepY
, sizeInYSteps
, newY
;
37 wxScrolledWindow
*scrl
= (wxScrolledWindow
*)this->GetParent();
39 /* Get our current step index and the total number of y steps in our dialog */
40 scrl
->GetViewStart(&viewX
, &viewY
);
41 scrl
->GetClientSize(NULL
, &sizeY
);
42 scrl
->GetScrollPixelsPerUnit(NULL
, &stepY
);
43 sizeInYSteps
= sizeY
/ stepY
;
45 /* Calculate whether we need to scroll the window, or whether we just leave it alone. */
49 else if(index
> viewY
+ sizeInYSteps
-1)
50 newY
= index
- (sizeInYSteps
-1);
52 if(newY
!=viewY
) scrl
->Scroll(viewX
, newY
);