00001 /* 00002 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions are met: 00006 * 00007 * * Redistributions of source code must retain the above copyright notice, this 00008 * list of conditions and the following disclaimer. 00009 * * Redistributions in binary form must reproduce the above copyright notice, 00010 * this list of conditions and the following disclaimer in the documentation 00011 * and/or other materials provided with the distribution. 00012 * * Neither the name of Nokia Corporation nor the names of its contributors 00013 * may be used to endorse or promote products derived from this software 00014 * without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00017 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00018 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00019 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00020 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00021 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00022 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00023 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00024 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00025 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 * 00027 * Description: 00028 */ 00029 00030 // INCLUDE FILES 00031 #include "BluetoothPMPExampleRTEContainer.h" 00032 #include "BluetoothPMPExampleRichtexteditorrte.h" 00033 00034 // ---------------------------------------------------------------------------- 00035 // CBluetoothPMPExampleRTEContainer::NewL(const TRect& aRect) 00036 // 00037 // Symbian OS 2 phase constructor. 00038 // ---------------------------------------------------------------------------- 00039 CBluetoothPMPExampleRTEContainer* CBluetoothPMPExampleRTEContainer::NewL(const TRect& aRect) 00040 { 00041 CBluetoothPMPExampleRTEContainer* self = CBluetoothPMPExampleRTEContainer::NewLC(aRect); 00042 CleanupStack::Pop(self); 00043 return self; 00044 } 00045 00046 // ---------------------------------------------------------------------------- 00047 // CBluetoothPMPExampleRTEContainer::NewLC(const TRect& aRect) 00048 // 00049 // Symbian OS 2 phase constructor. 00050 // ---------------------------------------------------------------------------- 00051 CBluetoothPMPExampleRTEContainer* CBluetoothPMPExampleRTEContainer::NewLC(const TRect& aRect) 00052 { 00053 CBluetoothPMPExampleRTEContainer* self = new (ELeave) CBluetoothPMPExampleRTEContainer; 00054 CleanupStack::PushL(self); 00055 self->ConstructL(aRect); 00056 return self; 00057 } 00058 00059 // --------------------------------------------------------- 00060 // CBluetoothPMPExampleRTEContainer::ConstructL(const TRect& aRect) 00061 // Symbian OS two phased constructor. 00062 // --------------------------------------------------------- 00063 // 00064 void CBluetoothPMPExampleRTEContainer::ConstructL(const TRect& aRect) 00065 { 00066 CreateWindowL(); 00067 00068 iRte = CRichTextEditorRTE::NewL(); 00069 iRte->SetContainerWindowL(*this); 00070 // Scroll bars 00071 iRte->CreateScrollBarFrameL()->SetScrollBarVisibilityL( 00072 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn); 00073 iRte->UpdateScrollBarsL(); 00074 00075 ActivateL(); 00076 00077 // Set the windows size 00078 // NOTE: To call this after ActivateL() is solution to get 00079 // scrollbarframe width in SizeChanged() method. 00080 SetRect(aRect); 00081 } 00082 00083 CBluetoothPMPExampleRTEContainer::~CBluetoothPMPExampleRTEContainer() 00084 { 00085 delete iRte; 00086 } 00087 00088 void CBluetoothPMPExampleRTEContainer::DrawUnderlinedTextL( const TDesC& aText ) 00089 { 00090 iRte->SetTextUnderlineOn(ETrue); 00091 DrawTextWithoutCarriageL(aText); 00092 iRte->SetTextUnderlineOn(EFalse); 00093 iRte->UpdateScrollBarsL(); 00094 } 00095 00096 void CBluetoothPMPExampleRTEContainer::DrawLineL() 00097 { 00098 iRte->DrawLineL(); 00099 iRte->UpdateScrollBarsL(); 00100 } 00101 00102 TInt CBluetoothPMPExampleRTEContainer::GetScrollbarWidth() const 00103 { 00104 TInt scrollbarWidth = iRte->ScrollBarFrame()-> 00105 ScrollBarBreadth(CEikScrollBar::EVertical); 00106 // If scrollbars are not drawn yet, the width remains zero. In this 00107 // case, an intentionally magical number is returned. 00108 if (scrollbarWidth == 0) 00109 { 00110 scrollbarWidth = 8; 00111 } 00112 00113 return scrollbarWidth; 00114 } 00115 00116 void CBluetoothPMPExampleRTEContainer::Draw( const TRect& /*aRect*/ ) const 00117 { 00118 CWindowGc& gc = SystemGc(); 00119 gc.Clear(); 00120 } 00121 00122 void CBluetoothPMPExampleRTEContainer::SizeChanged() 00123 { 00124 TRect rect = Rect(); 00125 TInt scrollbarWidth = GetScrollbarWidth(); 00126 iRte->SetExtent(TPoint(0, 0), 00127 TSize(rect.Width() - scrollbarWidth, rect.Height())); 00128 iRte->UpdateScrollBarsL(); 00129 } 00130 00131 void CBluetoothPMPExampleRTEContainer::DrawTextL( const TDesC& aText ) 00132 { 00133 iRte->AddTextL( aText ); 00134 iRte->UpdateScrollBarsL(); 00135 } 00136 00137 void CBluetoothPMPExampleRTEContainer::DrawTextWithoutCarriageL( const TDesC& aText ) 00138 { 00139 iRte->DrawTextWithoutCarriageL(aText); 00140 iRte->UpdateScrollBarsL(); 00141 } 00142 00143 void CBluetoothPMPExampleRTEContainer::AddCarriageReturnL() 00144 { 00145 iRte->AddCarriageReturnL(KCarriageReturnToEnd); 00146 iRte->UpdateScrollBarsL(); 00147 } 00148 00149 TInt CBluetoothPMPExampleRTEContainer::CountComponentControls() const 00150 { 00151 return 1; // return number of controls inside this container 00152 } 00153 00154 CCoeControl* CBluetoothPMPExampleRTEContainer::ComponentControl(TInt aIndex) const 00155 { 00156 switch ( aIndex ) 00157 { 00158 case 0: 00159 return iRte; 00160 default: 00161 return NULL; 00162 } 00163 } 00164 00165 TKeyResponse CBluetoothPMPExampleRTEContainer::OfferKeyEventL( 00166 const TKeyEvent& aKeyEvent,TEventCode aType) 00167 { 00168 if (iRte) 00169 return iRte->OfferKeyEventL(aKeyEvent, aType); 00170 else 00171 return CCoeControl::OfferKeyEventL(aKeyEvent, aType); 00172 } 00173 00174 void CBluetoothPMPExampleRTEContainer::ShowMessageL(const TDesC& aMsg) 00175 { 00176 DrawTextL(aMsg); 00177 } 00178 00179 void CBluetoothPMPExampleRTEContainer::ClearScreenL() 00180 { 00181 iRte->ClearScreenL(); 00182 iRte->UpdateScrollBarsL(); 00183 } 00184