1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbui.hxx"
26 #ifndef DBAUI_RTABLECONNECTION_HXX
27 #include "RTableConnection.hxx"
28 #endif
29 #ifndef _TOOLS_DEBUG_HXX
30 #include <tools/debug.hxx>
31 #endif
32 #ifndef DBAUI_RELATION_TABLEVIEW_HXX
33 #include "RelationTableView.hxx"
34 #endif
35 #ifndef _SV_SVAPP_HXX
36 #include <vcl/svapp.hxx>
37 #endif
38 #ifndef DBAUI_CONNECTIONLINE_HXX
39 #include "ConnectionLine.hxx"
40 #endif
41
42 using namespace dbaui;
43 //========================================================================
44 // class ORelationTableConnection
45 //========================================================================
DBG_NAME(ORelationTableConnection)46 DBG_NAME(ORelationTableConnection)
47 //------------------------------------------------------------------------
48 ORelationTableConnection::ORelationTableConnection( ORelationTableView* pContainer,
49 const TTableConnectionData::value_type& pTabConnData )
50 :OTableConnection( pContainer, pTabConnData )
51 {
52 DBG_CTOR(ORelationTableConnection,NULL);
53 }
54
55 //------------------------------------------------------------------------
ORelationTableConnection(const ORelationTableConnection & rConn)56 ORelationTableConnection::ORelationTableConnection( const ORelationTableConnection& rConn )
57 : OTableConnection( rConn )
58 {
59 DBG_CTOR(ORelationTableConnection,NULL);
60 // keine eigenen Members, also reicht die Basisklassenfunktionalitaet
61 }
62
63 //------------------------------------------------------------------------
~ORelationTableConnection()64 ORelationTableConnection::~ORelationTableConnection()
65 {
66 DBG_DTOR(ORelationTableConnection,NULL);
67 }
68
69 //------------------------------------------------------------------------
operator =(const ORelationTableConnection & rConn)70 ORelationTableConnection& ORelationTableConnection::operator=( const ORelationTableConnection& rConn )
71 {
72 DBG_CHKTHIS(ORelationTableConnection,NULL);
73 // nicht dass es was aendern wuerde, da die Basisklasse das auch testet und ich keine eigenen Members zu kopieren habe
74 if (&rConn == this)
75 return *this;
76
77 OTableConnection::operator=( rConn );
78 return *this;
79 }
80
81
82 //------------------------------------------------------------------------
Draw(const Rectangle & rRect)83 void ORelationTableConnection::Draw( const Rectangle& rRect )
84 {
85 DBG_CHKTHIS(ORelationTableConnection,NULL);
86 OTableConnection::Draw( rRect );
87 ORelationTableConnectionData* pData = static_cast< ORelationTableConnectionData* >(GetData().get());
88 if ( pData && (pData->GetCardinality() == CARDINAL_UNDEFINED) )
89 return;
90
91 //////////////////////////////////////////////////////////////////////
92 // Linien nach oberster Linie durchsuchen
93 Rectangle aBoundingRect;
94 long nTop = GetBoundingRect().Bottom();
95 long nTemp;
96
97 const OConnectionLine* pTopLine = NULL;
98 const ::std::vector<OConnectionLine*>* pConnLineList = GetConnLineList();
99 ::std::vector<OConnectionLine*>::const_iterator aIter = pConnLineList->begin();
100 ::std::vector<OConnectionLine*>::const_iterator aEnd = pConnLineList->end();
101 for(;aIter != aEnd;++aIter)
102 {
103 if( (*aIter)->IsValid() )
104 {
105 aBoundingRect = (*aIter)->GetBoundingRect();
106 nTemp = aBoundingRect.Top();
107 if( nTemp<nTop )
108 {
109 nTop = nTemp;
110 pTopLine = (*aIter);
111 }
112 }
113 }
114
115 //////////////////////////////////////////////////////////////////////
116 // Kardinalitaet antragen
117 if( !pTopLine )
118 return;
119
120 Rectangle aSourcePos = pTopLine->GetSourceTextPos();
121 Rectangle aDestPos = pTopLine->GetDestTextPos();
122
123 String aSourceText;
124 String aDestText;
125
126 switch( pData->GetCardinality() )
127 {
128 case CARDINAL_ONE_MANY:
129 aSourceText ='1';
130 aDestText ='n';
131 break;
132
133 case CARDINAL_MANY_ONE:
134 aSourceText ='n';
135 aDestText ='1';
136 break;
137
138 case CARDINAL_ONE_ONE:
139 aSourceText ='1';
140 aDestText ='1';
141 break;
142 }
143
144 if (IsSelected())
145 GetParent()->SetTextColor(Application::GetSettings().GetStyleSettings().GetHighlightColor());
146 else
147 GetParent()->SetTextColor(Application::GetSettings().GetStyleSettings().GetWindowTextColor());
148
149
150 GetParent()->DrawText( aSourcePos, aSourceText, TEXT_DRAW_CLIP | TEXT_DRAW_CENTER | TEXT_DRAW_BOTTOM);
151 GetParent()->DrawText( aDestPos, aDestText, TEXT_DRAW_CLIP | TEXT_DRAW_CENTER | TEXT_DRAW_BOTTOM);
152 }
153 // -----------------------------------------------------------------------------
154