Debian Codegraph @

DatabaseExplorer/ErdView.cpp

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2014 Eran Ifrah
5 // file name : ErdView.cpp
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 #include "ErdView.h"
27 #include "wx/wxsf/CommonFcn.h"
28
29 #include <wx/recguard.h>
30
31 using namespace wxSFCommonFcn;
32
33 XS_IMPLEMENT_CLONABLE_CLASS(ErdView,wxSFRoundRectShape);
34
35 ErdView::ErdView():wxSFRoundRectShape()
36 {
37 Initialize();
38 }
39
40 ErdView::ErdView(View* pView):wxSFRoundRectShape()
41 {
42 SetUserData(pView);
43 Initialize();
44 }
45
46 ErdView::ErdView(const ErdView& obj):wxSFRoundRectShape(obj)
47 {
48 m_pLabel = (wxSFTextShape*) obj.m_pLabel->Clone();
49 if (m_pLabel){
50 m_pLabel->SetStyle(sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION);
51 SF_ADD_COMPONENT( m_pLabel, wxT("title") );
52 }
53 }
54
55 ErdView::~ErdView()
56 {
57 }
58
59 void ErdView::DrawHover(wxDC& dc)
60 {
61 wxSFRoundRectShape::DrawHover(dc);
62 DrawDetails(dc);
63 }
64 void ErdView::DrawNormal(wxDC& dc)
65 {
66 wxSFRoundRectShape::DrawNormal(dc);
67 DrawDetails(dc);
68 }
69
70 void ErdView::DrawHighlighted(wxDC& dc)
71 {
72 wxSFRoundRectShape::DrawHighlighted(dc);
73 DrawDetails(dc);
74 }
75
76 void ErdView::DrawDetails(wxDC& dc)
77 {
78 dc.SetPen( *wxWHITE_PEN );
79 dc.SetBrush( *wxWHITE_BRUSH );
80
81 dc.DrawRectangle( Conv2Point(GetAbsolutePosition() + wxRealPoint(1, m_nRadius)),
82 Conv2Size(m_nRectSize - wxRealPoint(2, 2*m_nRadius - 4)) );
83 }
84
85 void ErdView::Initialize()
86 {
87 AcceptConnection(wxT("All"));
88 AcceptTrgNeighbour(wxT("All"));
89 AcceptSrcNeighbour(wxT("All"));
90
91 AddStyle( sfsLOCK_CHILDREN );
92 AddStyle( sfsSHOW_SHADOW );
93
94 SetBorder( wxPen( wxColour(220, 219, 140), 1, wxPENSTYLE_SOLID ) );
95 SetFill( wxBrush( wxColour(255, 250, 200) ) );
96
97 SetRadius(15);
98
99 m_pLabel = new wxSFTextShape();
100 if (m_pLabel) {
101 m_pLabel->SetVAlign( wxSFShapeBase::valignTOP );
102 m_pLabel->SetHAlign( wxSFShapeBase::halignCENTER );
103 m_pLabel->SetVBorder( 1 );
104 m_pLabel->SetHBorder( 5 );
105 m_pLabel->GetFont().SetPointSize( 8 );
106 m_pLabel->GetFont().SetWeight(wxFONTWEIGHT_BOLD);
107
108 m_pLabel->SetText(wxT("DBETable name"));
109 m_pLabel->SetStyle( sfsHOVERING | sfsALWAYS_INSIDE | sfsPROCESS_DEL | sfsEMIT_EVENTS |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION);
110
111 SF_ADD_COMPONENT( m_pLabel, wxT("title") );
112 }
113
114 m_pGrid = new wxSFFlexGridShape();
115 if (m_pGrid){
116 // set grid
117 m_pGrid->SetRelativePosition( 0, 17 );
118 m_pGrid->SetStyle( sfsALWAYS_INSIDE | sfsPROCESS_DEL |sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION );
119 m_pGrid->SetDimensions( 1, 1 );
120
121 m_pGrid->SetFill( *wxTRANSPARENT_BRUSH );
122 m_pGrid->SetBorder( *wxTRANSPARENT_PEN );
123
124 m_pGrid->SetHAlign( wxSFShapeBase::halignLEFT );
125 m_pGrid->SetCellSpace( 1 );
126 m_pGrid->SetVBorder( 13 );
127 m_pGrid->SetHBorder( 10 );
128 m_pGrid->AcceptChild( wxT("wxSFTextShape") );
129 m_pGrid->Activate( false );
130
131 SF_ADD_COMPONENT( m_pGrid, wxT("SelectGrid") );
132 }
133 }
134
135 void ErdView::UpdateView()
136 {
137 m_pGrid->RemoveChildren();
138 m_pGrid->ClearGrid();
139 m_pGrid->SetDimensions( 1, 1 );
140
141 SetRectSize(GetRectSize().x, 0);
142
143 View* pView = wxDynamicCast(GetUserData(), View);
144 if (pView){
145 m_pLabel->SetText(pView->GetName());
146
147 wxSFTextShape* m_pCol = new wxSFTextShape();
148 if (m_pCol){
149 m_pCol->SetStyle( sfsALWAYS_INSIDE | sfsPROPAGATE_DRAGGING | sfsPROPAGATE_SELECTION );
150 //m_pCol->SetId(1);
151 if (m_pGrid->AppendToGrid(m_pCol)){
152 m_pCol->GetFont().SetPointSize(8);
153 if (pView->GetSelect().length()>100){
154 m_pCol->SetText(wxString::Format(wxT("%s ...\n\t... %s"), pView->GetSelect().Mid(0,50).c_str(), pView->GetSelect().Right(50).c_str()));
155 }else m_pCol->SetText( pView->GetSelect() );
156 m_pCol->SetHAlign(wxSFShapeBase::halignCENTER);
157 m_pCol->SetVAlign(wxSFShapeBase::valignMIDDLE);
158 m_pCol->SetVBorder(0);
159 m_pCol->SetHBorder(0);
160 m_pCol->Activate(false);
161
162 }else{
163 delete m_pCol;
164 m_pCol = NULL;
165 }
166 }
167 }
168
169 m_pGrid->Update();
170 Update();
171 }