Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "RTableConnection.hxx"
21 : #include <tools/debug.hxx>
22 : #include "RelationTableView.hxx"
23 : #include <vcl/svapp.hxx>
24 : #include <vcl/settings.hxx>
25 : #include "ConnectionLine.hxx"
26 :
27 : using namespace dbaui;
28 : // class ORelationTableConnection
29 0 : ORelationTableConnection::ORelationTableConnection( ORelationTableView* pContainer,
30 : const TTableConnectionData::value_type& pTabConnData )
31 0 : :OTableConnection( pContainer, pTabConnData )
32 : {
33 0 : }
34 :
35 0 : ORelationTableConnection::ORelationTableConnection( const ORelationTableConnection& rConn )
36 0 : : OTableConnection( rConn )
37 : {
38 : // no own members, thus the base class functionality is enough
39 0 : }
40 :
41 0 : ORelationTableConnection& ORelationTableConnection::operator=( const ORelationTableConnection& rConn )
42 : {
43 : // this doesn't change anything, since the base class tests this, too and I don't have my own members to copy
44 0 : if (&rConn == this)
45 0 : return *this;
46 :
47 0 : OTableConnection::operator=( rConn );
48 0 : return *this;
49 : }
50 :
51 0 : void ORelationTableConnection::Draw(vcl::RenderContext& rRenderContext, const Rectangle& rRect )
52 : {
53 0 : OTableConnection::Draw(rRenderContext, rRect);
54 0 : ORelationTableConnectionData* pData = static_cast< ORelationTableConnectionData* >(GetData().get());
55 0 : if (pData && (pData->GetCardinality() == CARDINAL_UNDEFINED))
56 0 : return;
57 :
58 : // search lines for top line
59 0 : Rectangle aBoundingRect;
60 0 : long nTop = GetBoundingRect().Bottom();
61 : long nTemp;
62 :
63 0 : const OConnectionLine* pTopLine = NULL;
64 0 : const ::std::vector<OConnectionLine*>& rConnLineList = GetConnLineList();
65 0 : std::vector<OConnectionLine*>::const_iterator aIter = rConnLineList.begin();
66 0 : std::vector<OConnectionLine*>::const_iterator aEnd = rConnLineList.end();
67 :
68 0 : for(;aIter != aEnd;++aIter)
69 : {
70 0 : if( (*aIter)->IsValid() )
71 : {
72 0 : aBoundingRect = (*aIter)->GetBoundingRect();
73 0 : nTemp = aBoundingRect.Top();
74 0 : if(nTemp < nTop)
75 : {
76 0 : nTop = nTemp;
77 0 : pTopLine = (*aIter);
78 : }
79 : }
80 : }
81 :
82 : // cardinality
83 0 : if (!pTopLine)
84 0 : return;
85 :
86 0 : Rectangle aSourcePos = pTopLine->GetSourceTextPos();
87 0 : Rectangle aDestPos = pTopLine->GetDestTextPos();
88 :
89 0 : OUString aSourceText;
90 0 : OUString aDestText;
91 :
92 0 : switch (pData->GetCardinality())
93 : {
94 : case CARDINAL_ONE_MANY:
95 0 : aSourceText = "1";
96 0 : aDestText = "n";
97 0 : break;
98 :
99 : case CARDINAL_MANY_ONE:
100 0 : aSourceText = "n";
101 0 : aDestText = "1";
102 0 : break;
103 :
104 : case CARDINAL_ONE_ONE:
105 0 : aSourceText = "1";
106 0 : aDestText = "1";
107 0 : break;
108 : }
109 :
110 0 : if (IsSelected())
111 0 : rRenderContext.SetTextColor(Application::GetSettings().GetStyleSettings().GetHighlightColor());
112 : else
113 0 : rRenderContext.SetTextColor(Application::GetSettings().GetStyleSettings().GetWindowTextColor());
114 :
115 0 : rRenderContext.DrawText(aSourcePos, aSourceText, DrawTextFlags::Clip | DrawTextFlags::Center | DrawTextFlags::Bottom);
116 0 : rRenderContext.DrawText(aDestPos, aDestText, DrawTextFlags::Clip | DrawTextFlags::Center | DrawTextFlags::Bottom);
117 : }
118 :
119 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|