-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewEdit.cpp
47 lines (42 loc) · 1017 Bytes
/
ViewEdit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "ViewEdit.h"
BEGIN_EVENT_TABLE(ViewEdit, wxWindow)
EVT_PAINT(ViewEdit::OnPaint)
EVT_LEFT_DOWN(ViewEdit::OnLeftButtonDown)
EVT_LEFT_UP(ViewEdit::OnLeftButtonUp)
END_EVENT_TABLE()
ViewEdit::ViewEdit(MainFrame *parent,wxSize s):wxWindow(parent,wxID_ANY,wxDefaultPosition,s,wxBORDER_SIMPLE),DocumentObserver(parent->GetDocument()),_parent(parent)
{
}
ViewEdit::~ViewEdit(void)
{
}
void ViewEdit::OnPaint(wxPaintEvent &event)
{
wxPaintDC dc(this);
_parent->GetDocument()->Draw(&dc);
}
void ViewEdit::OnLeftButtonDown(wxMouseEvent &event)
{
int x,y;
x = event.m_x;
y = event.m_y;
Document *document = _parent->GetDocument();
IteratorPtr<Key*> iter = document->GetKeys();
for(iter->First();!iter->IsDone(); iter->Next())
{
if(iter->Current()->HitTest(wxPoint(x,y)))
{
document->HitKey(iter->Current());
document->UpdateObservers();
}
}
}
void ViewEdit::OnLeftButtonUp(wxMouseEvent &event)
{
_parent->GetDocument()->ReleaseKey();
Refresh();
}
void ViewEdit::Observe()
{
Refresh();
}