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 SetRect(aRect);
00042 ActivateL();
00043 }
00044
00045
00046
00047 CAOLabBubbleSortContainer::~CAOLabBubbleSortContainer()
00048 {
00049 delete iBottomLabel;
00050 delete iTopLabel;
00051 }
00052
00053
00054
00055 void CAOLabBubbleSortContainer::SizeChanged()
00056 {
00057 iTopLabel->SetExtent( TPoint(0,0), TSize(Rect().Width(), Rect().Height()/2));
00058 iBottomLabel->SetExtent( TPoint(0,Rect().Height()/2), TSize(Rect().Width(),Rect().Height()/2));
00059 }
00060
00061
00062
00063 TInt CAOLabBubbleSortContainer::CountComponentControls() const
00064 {
00065 return 2;
00066 }
00067
00068
00069
00070 CCoeControl* CAOLabBubbleSortContainer::ComponentControl(TInt aIndex) const
00071 {
00072 switch ( aIndex )
00073 {
00074 case 0:
00075 return iTopLabel;
00076 case 1:
00077 return iBottomLabel;
00078 default:
00079 return NULL;
00080 }
00081 }
00082
00083
00084
00085 void CAOLabBubbleSortContainer::Draw(const TRect& aRect) const
00086 {
00087 CWindowGc& gc = SystemGc();
00088
00089 gc.SetPenStyle(CGraphicsContext::ENullPen);
00090 gc.SetBrushColor(KRgbGray);
00091 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00092 gc.DrawRect(aRect);
00093 }
00094
00095
00096
00097 void CAOLabBubbleSortContainer::SortL()
00098 {
00099 iIsSorting = ETrue;
00100 iTopLabel->SetTextL(KCancelActionText);
00101 iBottomLabel->SetTextL(KSortingText);
00102 DrawNow();
00103 }
00104
00105
00106
00107 void CAOLabBubbleSortContainer::SortComplete(TInt aError)
00108 {
00109 iIsSorting = EFalse;
00110
00111 TBuf<20> buf;
00112 if (aError == KErrNone)
00113 {
00114 buf.Format(KSortingComplete);
00115 }
00116 else
00117 {
00118 buf.Format(KSortingError, aError);
00119 }
00120
00121 iTopLabel->SetTextL(KStartActionText);
00122 iBottomLabel->SetTextL(buf);
00123 DrawNow();
00124 }
00125
00126
00127
00128 void CAOLabBubbleSortContainer::CancelSortL()
00129 {
00130 iIsSorting = EFalse;
00131
00132 iTopLabel->SetTextL(KStartActionText);
00133 iBottomLabel->SetTextL(KSortingCancelled);
00134 DrawNow();
00135 }
00136
00137