|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Source file for the implementation of the |
|
15 // application view class - CResourceView |
|
16 // |
|
17 // |
|
18 |
|
19 #include "ResourceHandler.h" |
|
20 |
|
21 CResourceView::CResourceView() |
|
22 { |
|
23 } |
|
24 |
|
25 CResourceView* CResourceView::NewL(const TRect& aRect, CResourceAppUi *aAppUi) |
|
26 { |
|
27 CResourceView* self = new(ELeave) CResourceView(); |
|
28 CleanupStack::PushL(self); |
|
29 self->ConstructL(aRect, aAppUi); |
|
30 CleanupStack::Pop(); |
|
31 return self; |
|
32 } |
|
33 |
|
34 CResourceView::~CResourceView() |
|
35 { |
|
36 delete iCommandButton; |
|
37 } |
|
38 |
|
39 void CResourceView::ConstructL(const TRect& aRect, CResourceAppUi* aAppUi) |
|
40 { |
|
41 // Initialisation |
|
42 iAppUi = aAppUi; |
|
43 iObjectsViewed = EObjectProcess; |
|
44 |
|
45 CreateWindowL(); |
|
46 |
|
47 // Whole extent of view |
|
48 SetRect(aRect); |
|
49 |
|
50 // Border around components in pixels |
|
51 iBorder = 1; |
|
52 |
|
53 // Place the refresh button |
|
54 iCommandButton = new(ELeave) CEikCommandButton; |
|
55 iCommandButton->SetTextL(_L("Refresh")); |
|
56 iCommandButton->SetSize(iCommandButton->MinimumSize()); |
|
57 iCommandButton->SetPosition(TPoint(Rect().Width() - iCommandButton->Size().iWidth - iBorder, iBorder)); |
|
58 iCommandButton->SetContainerWindowL(*this); |
|
59 iCommandButton->SetObserver(this); |
|
60 TInt buttonHeight = iCommandButton->Size().iHeight; |
|
61 |
|
62 // Get the title font height |
|
63 TInt titleHeight = iEikonEnv->TitleFont()->HeightInPixels(); |
|
64 TInt tablePosition = 0; |
|
65 if (titleHeight>=buttonHeight) |
|
66 tablePosition=titleHeight; |
|
67 else |
|
68 tablePosition=buttonHeight; |
|
69 |
|
70 CResourceList::ConstructL(tablePosition); |
|
71 // Activate the main window control - this will also activate the contained controls |
|
72 |
|
73 ActivateL(); |
|
74 DrawNow(); |
|
75 } |
|
76 |
|
77 |
|
78 void CResourceView::Draw(const TRect& /*aRect*/) const |
|
79 { |
|
80 CWindowGc& gc = SystemGc(); |
|
81 |
|
82 gc.Clear(); |
|
83 |
|
84 // Put title on view |
|
85 const CFont* fontUsed = iEikonEnv->TitleFont(); |
|
86 gc.UseFont(fontUsed); |
|
87 gc.SetPenColor(KRgbBlack); |
|
88 TPoint pos(iBorder,fontUsed->AscentInPixels()+iBorder); |
|
89 gc.DrawText(iTitle, pos); |
|
90 |
|
91 gc.DiscardFont(); |
|
92 } |
|
93 |
|
94 |
|
95 |
|
96 TInt CResourceView::CountComponentControls() const |
|
97 { |
|
98 return 2; |
|
99 } |
|
100 |
|
101 |
|
102 CCoeControl* CResourceView::ComponentControl(TInt aIndex) const |
|
103 { |
|
104 if (aIndex == 0) |
|
105 return iCommandButton; |
|
106 else |
|
107 return CResourceList::GetListBox(); |
|
108 } |
|
109 |
|
110 |
|
111 // for use by refresh button control |
|
112 void CResourceView::HandleControlEventL(CCoeControl* aControl,TCoeEvent /*aEventType*/) |
|
113 { |
|
114 if (aControl == iCommandButton) |
|
115 { |
|
116 UpdateView(); |
|
117 } |
|
118 } |
|
119 |
|
120 void CResourceView::InvalidateView(void) const |
|
121 { |
|
122 Window().Invalidate(Rect()); //calls Draw() |
|
123 } |
|
124 |
|
125 void CResourceView::UpdateView(void) |
|
126 { |
|
127 CResourceList::UpdateListData(); |
|
128 UpdateTitle(); |
|
129 InvalidateView(); |
|
130 } |
|
131 |
|
132 void CResourceView::UpdateTitle(void) |
|
133 { |
|
134 // assume the table data, iResourceCount and iObjectViewed data are up to date |
|
135 TBufC<20> title; |
|
136 |
|
137 // Set the title appropriately |
|
138 switch (iObjectsViewed) |
|
139 { |
|
140 case EObjectProcess: |
|
141 title = _L("Processes"); |
|
142 break; |
|
143 case EObjectThread: |
|
144 title = _L("Threads"); |
|
145 break; |
|
146 case EObjectChunk: |
|
147 title = _L("Chunks"); |
|
148 break; |
|
149 case EObjectLibrary: |
|
150 title = _L("Libraries"); |
|
151 break; |
|
152 case EObjectServer: |
|
153 title = _L("Servers"); |
|
154 break; |
|
155 case EObjectSemaphore: |
|
156 title = _L("Semaphores"); |
|
157 break; |
|
158 case EObjectMutex: |
|
159 title = _L("Mutexes"); |
|
160 break; |
|
161 case EObjectLogicalDevice: |
|
162 title = _L("Log. Devices"); |
|
163 break; |
|
164 case EObjectPhysicalDevice: |
|
165 title = _L("Phy. Devices"); |
|
166 break; |
|
167 case EObjectLogicalChannel: |
|
168 title = _L("Log. Channels"); |
|
169 break; |
|
170 case EObjectWindow: |
|
171 title = _L("Window Grps"); |
|
172 break; |
|
173 case EObjectDrive: |
|
174 title = _L("Drives"); |
|
175 break; |
|
176 case EObjectHal: |
|
177 title = _L("HALs"); |
|
178 break; |
|
179 default: break; |
|
180 } |
|
181 |
|
182 //set title and resource count |
|
183 TBuf<2> openingBracket(_L(" (")); |
|
184 TBuf<1> closingBracket(_L(")")); |
|
185 iTitle.Format(_L("%S%S%u%S"), &title, &openingBracket, iResourceCount, &closingBracket); |
|
186 } |