00001
00002
00003 #include "AOLabBubbleSortContainer.h"
00004 #include "ActiveBubbleSorter.h"
00005 #include <eiklabel.h>
00006
00007 _LIT(KStartActionText, "Select menu item\nto begin sorting...");
00008 _LIT(KCancelActionText, "Select menu item\nto cancel sorting...");
00009
00010 _LIT(KSortingText, "Sorting...");
00011 _LIT(KSortingComplete, "Sorting Complete.");
00012 _LIT(KSortingError, "Sorting Error: %d");
00013 _LIT(KSortingCancelled, "Sorting cancelled.");
00014
00015
00016
00017 CAOLabBubbleSortContainer* CAOLabBubbleSortContainer::NewL(const TRect& aRect)
00018 {
00019 CAOLabBubbleSortContainer* self = new (ELeave) CAOLabBubbleSortContainer();
00020 CleanupStack::PushL(self);
00021 self->ConstructL(aRect);
00022 CleanupStack::Pop(self);
00023
00024 return self;
00025 }
00026
00027
00028
00029 void CAOLabBubbleSortContainer::ConstructL(const TRect& aRect)
00030 {
00031 CreateWindowL();
00032
00033 iTopLabel = new (ELeave) CEikLabel;
00034 iTopLabel->SetContainerWindowL( *this );
00035 iTopLabel->SetTextL(KStartActionText);
00036
00037 iBottomLabel = new (ELeave) CEikLabel;
00038 iBottomLabel->SetContainerWindowL( *this );
00039 iBottomLabel->SetTextL(KNullDesC);
00040
00041 iActiveBubbleSorter = CActiveBubbleSorter::NewL(*this);
00042
00043 SetRect(aRect);
00044 ActivateL();
00045 }
00046
00047
00048
00049 CAOLabBubbleSortContainer::~CAOLabBubbleSortContainer()
00050 {
00051 delete iActiveBubbleSorter;
00052 delete iBottomLabel;
00053 delete iTopLabel;
00054 }
00055
00056
00057
00058 void CAOLabBubbleSortContainer::SizeChanged()
00059 {
00060 iTopLabel->SetExtent( TPoint(0,0), TSize(Rect().Width(), Rect().Height()/2));
00061 iBottomLabel->SetExtent( TPoint(0,Rect().Height()/2), TSize(Rect().Width(),Rect().Height()/2));
00062 }
00063
00064
00065
00066 TInt CAOLabBubbleSortContainer::CountComponentControls() const
00067 {
00068 return 2;
00069 }
00070
00071
00072
00073 CCoeControl* CAOLabBubbleSortContainer::ComponentControl(TInt aIndex) const
00074 {
00075 switch ( aIndex )
00076 {
00077 case 0:
00078 return iTopLabel;
00079 case 1:
00080 return iBottomLabel;
00081 default:
00082 return NULL;
00083 }
00084 }
00085
00086
00087
00088 void CAOLabBubbleSortContainer::Draw(const TRect& aRect) const
00089 {
00090 CWindowGc& gc = SystemGc();
00091
00092 gc.SetPenStyle(CGraphicsContext::ENullPen);
00093 gc.SetBrushColor(KRgbGray);
00094 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00095 gc.DrawRect(aRect);
00096 }
00097
00098
00099
00100 void CAOLabBubbleSortContainer::SortL()
00101 {
00102 iIsSorting = ETrue;
00103 iTopLabel->SetTextL(KCancelActionText);
00104 iBottomLabel->SetTextL(KSortingText);
00105 DrawNow();
00106
00107 iActiveBubbleSorter->StartL();
00108 }
00109
00110
00111
00112 void CAOLabBubbleSortContainer::SortComplete(TInt aError)
00113 {
00114 iIsSorting = EFalse;
00115
00116 TBuf<20> buf;
00117 if (aError == KErrNone)
00118 {
00119 buf.Format(KSortingComplete);
00120 }
00121 else
00122 {
00123 buf.Format(KSortingError, aError);
00124 }
00125
00126 iTopLabel->SetTextL(KStartActionText);
00127 iBottomLabel->SetTextL(buf);
00128 DrawNow();
00129 }
00130
00131
00132
00133 void CAOLabBubbleSortContainer::CancelSortL()
00134 {
00135 iActiveBubbleSorter->Cancel();
00136 iIsSorting = EFalse;
00137
00138 iTopLabel->SetTextL(KStartActionText);
00139 iBottomLabel->SetTextL(KSortingCancelled);
00140 DrawNow();
00141 }
00142
00143