1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: The private implementation of AlfHostAPI. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "alfhostapiimpl.h" |
|
20 #include <alf/alfwidgetcontrol.h> |
|
21 #include <alf/ialflayoutmanager.h> |
|
22 #include <alf/alfexceptions.h> |
|
23 |
|
24 namespace Alf |
|
25 { |
|
26 |
|
27 AlfHostAPIImpl::AlfHostAPIImpl(): mBaseLayout(NULL), mHostControl(NULL) |
|
28 { |
|
29 } |
|
30 |
|
31 |
|
32 AlfHostAPIImpl::~AlfHostAPIImpl() |
|
33 { |
|
34 } |
|
35 |
|
36 OSN_EXPORT IAlfInterfaceBase* AlfHostAPIImpl::makeInterface( |
|
37 const IfId& aType ) |
|
38 { |
|
39 UString param(aType.mImplementationId); |
|
40 if ( param == IAlfHostAPI::type().mImplementationId ) |
|
41 { |
|
42 return static_cast<IAlfHostAPI*>( this ); |
|
43 } |
|
44 return 0; |
|
45 } |
|
46 |
|
47 void AlfHostAPIImpl::setHostControl(CAlfWidgetControl& aControl) |
|
48 { |
|
49 mHostControl = &aControl; |
|
50 } |
|
51 |
|
52 void AlfHostAPIImpl::setConnection(CAlfWidgetControl& aControl, AlfRole aRole) |
|
53 { |
|
54 if (mHostControl) |
|
55 { |
|
56 // Remove previous host connection from connected control |
|
57 if(aControl.Host()) |
|
58 { |
|
59 CAlfWidgetControl* parentControl = dynamic_cast<CAlfWidgetControl*>(aControl.Host()); |
|
60 if(parentControl) |
|
61 { |
|
62 parentControl->hostAPI().removeConnection(aControl); |
|
63 } |
|
64 } |
|
65 |
|
66 // Add connection from host control to connected control |
|
67 TRAPD(err, mHostControl->AddConnectionL(&aControl,aRole)); |
|
68 if(err != KErrNone) |
|
69 { |
|
70 ALF_THROW(AlfException, err, "AlfHostAPIImpl::setConnection() - AddConnectionL() failed."); |
|
71 } |
|
72 |
|
73 // Update layout of host control if a child control was connected |
|
74 if (aRole == EChild && mBaseLayout.get()) |
|
75 { |
|
76 mBaseLayout->updateChildLayout(&aControl); |
|
77 } |
|
78 } |
|
79 } |
|
80 |
|
81 CAlfWidgetControl* AlfHostAPIImpl::getConnection(int aIndex) const |
|
82 { |
|
83 if (mHostControl) |
|
84 { |
|
85 //AlfControl doesn't perform bound checks. |
|
86 if (aIndex >=0 && aIndex < mHostControl->ConnectionCount()) |
|
87 { |
|
88 return (static_cast<CAlfWidgetControl*>(&(mHostControl->Connection(aIndex)))); |
|
89 } |
|
90 } |
|
91 return 0; //NULL is not defined in osncore |
|
92 } |
|
93 |
|
94 int AlfHostAPIImpl::getConnectionCount() const |
|
95 { |
|
96 int connectionCount = 0; |
|
97 if (mHostControl) |
|
98 { |
|
99 connectionCount = mHostControl->ConnectionCount(); |
|
100 } |
|
101 return connectionCount; |
|
102 } |
|
103 |
|
104 int AlfHostAPIImpl::getConnectionIndex(CAlfWidgetControl& aControl) const |
|
105 { |
|
106 return mHostControl->FindConnection(&aControl); |
|
107 } |
|
108 |
|
109 void AlfHostAPIImpl::removeConnection(CAlfWidgetControl& aControl) |
|
110 { |
|
111 if (mHostControl) |
|
112 { |
|
113 mHostControl->RemoveConnection(&aControl); |
|
114 if (getBaseLayout()) |
|
115 { |
|
116 getBaseLayout()->childRemoved(&aControl); |
|
117 } |
|
118 } |
|
119 } |
|
120 |
|
121 void AlfHostAPIImpl::setBaseLayout(IAlfLayoutManager& aLayout) |
|
122 { |
|
123 if(mHostControl) |
|
124 { |
|
125 mBaseLayout.reset(&aLayout); |
|
126 mBaseLayout->createLayout(*mHostControl, 0, 0); |
|
127 } |
|
128 } |
|
129 |
|
130 IAlfLayoutManager* AlfHostAPIImpl::getBaseLayout() const |
|
131 { |
|
132 return mBaseLayout.get(); |
|
133 } |
|
134 |
|
135 } //namespace alf |
|
136 |
|
137 |
|
138 |
|