1 #include "PasteTask.h"
2 #include "GraphBricks.h"
3 #include "RedLineDrawlet.h"
4 #include "RedHatchDrawlet.h"
5 #include "NassiFileContent.h"
6 #include "commands.h"
7 #include "NassiView.h"
8
9 #include "rc/dnd_move_cur.xpm"
10
PasteTask(NassiView * view,NassiFileContent * nfc,NassiBrick * brick,wxString strc,wxString strs)11 PasteTask::PasteTask(NassiView *view, NassiFileContent *nfc, NassiBrick *brick, wxString strc, wxString strs):
12 Task(),
13 m_view(view),
14 m_nfc(nfc),
15 m_done(false),
16 m_brick(brick),
17 m_strc(strc),
18 m_strs(strs)
19 {}
20
~PasteTask()21 PasteTask::~PasteTask()
22 {
23 if ( m_brick )
24 delete m_brick;
25 }
26
Start()27 wxCursor PasteTask::Start()
28 {
29 wxBitmap *b_curs = new wxBitmap(dnd_move_cur_xpm);
30 wxCursor newcursor(b_curs->ConvertToImage());
31 delete b_curs;
32 return newcursor;
33 }
34
Done() const35 bool PasteTask::Done()const
36 {
37 return m_done;
38 }
39
40 // events from window:
OnMouseLeftUp(wxMouseEvent &,const wxPoint &)41 void PasteTask::OnMouseLeftUp(wxMouseEvent& /*event*/, const wxPoint& /*position*/){}
42
OnMouseLeftDown(wxMouseEvent &,const wxPoint & position)43 void PasteTask::OnMouseLeftDown(wxMouseEvent& /*event*/, const wxPoint &position)
44 {
45 if ( !m_nfc->GetFirstBrick() )
46 {
47 wxRect rect = m_view->GetEmptyRootRect();
48 if ( rect.Contains(position) )
49 {
50 NassiBrick *brick = m_brick;
51 m_brick = 0;
52 m_nfc->GetCommandProcessor()->Submit(
53 new NassiInsertFirstBrick(m_nfc, brick)
54 );
55 m_done = true;
56 }
57 return;
58 }
59
60 GraphNassiBrick *gbrick = m_view->GetBrickAtPosition(position);
61 if ( gbrick )
62 {
63 GraphNassiBrick::Position p = gbrick->GetPosition(position);
64 if (m_brick && (p.pos == GraphNassiBrick::Position::bottom ))
65 {
66 m_nfc->GetCommandProcessor()->Submit(
67 new NassiInsertBrickAfter( m_nfc, gbrick->GetBrick(), m_brick ));
68 m_brick = 0;
69 }
70 else if (m_brick && (p.pos == GraphNassiBrick::Position::top ))
71 {
72 m_nfc->GetCommandProcessor()->Submit(
73 new NassiInsertBrickBefore(m_nfc, gbrick->GetBrick(), m_brick ));
74 m_brick = 0;
75 }
76 else if ( m_brick && ( p.pos == GraphNassiBrick::Position::child ))
77 {
78 m_nfc->GetCommandProcessor()->Submit(
79 new NassiInsertChildBrickCommand(m_nfc, gbrick->GetBrick(), m_brick, p.number));
80 m_brick = 0;
81 }
82 else if ( p.pos == GraphNassiBrick::Position::childindicator )
83 {
84 m_nfc->GetCommandProcessor()->Submit(
85 new NassiAddChildIndicatorCommand(m_nfc, gbrick->GetBrick(), m_brick, p.number, m_strc, m_strs));
86 m_brick = 0;
87 }
88 m_done = true;
89 }
90 }
91
OnMouseRightDown(wxMouseEvent &,const wxPoint &)92 void PasteTask::OnMouseRightDown(wxMouseEvent& /*event*/, const wxPoint& /*position*/)
93 {
94 m_done = true;
95 }
96
OnMouseRightUp(wxMouseEvent &,const wxPoint &)97 void PasteTask::OnMouseRightUp(wxMouseEvent& /*event*/, const wxPoint& /*position*/){}
98
OnMouseMove(wxMouseEvent &,const wxPoint & position)99 HooverDrawlet *PasteTask::OnMouseMove(wxMouseEvent& /*event*/, const wxPoint &position)
100 {
101 if ( !m_nfc->GetFirstBrick() )
102 {
103 wxRect rect = m_view->GetEmptyRootRect();
104 if ( rect.Contains(position) )
105 return new RedHatchDrawlet(rect);
106 else
107 return 0;
108 }
109
110 GraphNassiBrick *gbrick = m_view->GetBrickAtPosition(position);
111 if ( gbrick )
112 return gbrick->GetDrawlet(position, false);
113 return 0;
114 }
115
OnKeyDown(wxKeyEvent & event)116 void PasteTask::OnKeyDown(wxKeyEvent &event)
117 {
118 if ( event.GetKeyCode() == WXK_ESCAPE )
119 {
120 m_done = true;
121 return;
122 }
123 //event.Skip();
124 }
125
OnChar(wxKeyEvent &)126 void PasteTask::OnChar(wxKeyEvent & /*event*/){}
127
128 // events from frame( s )
CanEdit() const129 bool PasteTask::CanEdit()const{ return false; }
130
HasSelection() const131 bool PasteTask::HasSelection()const{ return false; }
132
CanPaste() const133 bool PasteTask::CanPaste()const{ return false; }
134
DeleteSelection()135 void PasteTask::DeleteSelection(){}
136
Copy()137 void PasteTask::Copy(){}
138
Paste()139 void PasteTask::Paste(){}
140
Cut()141 void PasteTask::Cut(){}
142
143 //bool PasteTask::CanCopy()const{return false;}
144
145 //bool PasteTask::CanCut()const{return false;}
146