📄 dbview.cpp
字号:
fieldDisplayName->SetFocus(ETrue);
}
TBool CSMan2DBView::doWriteDB()
{
TBuf<50> buffer;
TInt i;
TBool retVal = EFalse;
if (dbIsOpened)
{
fieldDisplayName->GetText(buffer);
if (buffer.Length() > 0)
{
dbView.SetColL(2, buffer);
TInt j = 0;
for (i = 0; i < NUM_DATA_FIELDS; i++)
{
fieldLabels[i]->GetText(buffer);
if (buffer.Length() > 0)
{
dbView.SetColL(3 + j * 2, buffer);
fieldValues[i]->GetText(buffer);
dbView.SetColL(4 + j * 2, buffer);
j++;
}
else
{
dbView.SetColL(3 + j * 2, _L(""));
dbView.SetColL(4 + j * 2, _L(""));
}
}
TRAPD(err, dbView.PutL());
if (err)
{
dbView.Cancel();
dbView.Reset();
dbView.Close();
iEikonEnv->InfoMsg(R_TBUF_DB_ERR_SAVE);
}
}
else
iEikonEnv->InfoMsg(R_TBUF_DB_NO_DISPLAYNAME);
dbView.Close();
retVal = ETrue;
}
return retVal;
}
TBool CSMan2DBView::SaveRecord(TUint32 aIndex)
{
TBuf<50> sqlString;
TBool res = EFalse;
if (!dbIsOpened)
InitDB();
if (dbIsOpened)
{
if (currentRecordIndexIsValid)
{
if (fieldDisplayName->TextLength() == 0)
{
HBufC* dataBuffer = CEikonEnv::Static()->AllocReadResourceL(R_TBUF_MISC_DELETE_TITLE);
HBufC* dataBuffer2 = CEikonEnv::Static()->AllocReadResourceL(R_TBUF_DB_CONFIRM_DELETE);
if (CEikonEnv::Static()->QueryWinL(*dataBuffer, *dataBuffer2))
res = DeleteRecord(aIndex);
delete dataBuffer;
delete dataBuffer2;
}
else
{
// Update the record
sqlString.Format(_L("SELECT * FROM Databank WHERE Index = %u"), aIndex);
if (ReadDB(sqlString))
{
dbView.FirstL();
if (dbView.AtRow())
{
dbView.UpdateL();
res = doWriteDB();
}
}
dbView.Close();
}
}
else
{
// Insert new record
sqlString.Copy(_L("SELECT * FROM Databank WHERE Index = 0"));
if (ReadDB(sqlString))
{
dbView.InsertL();
res = doWriteDB();
}
dbView.Close();
}
}
return res;
}
void CSMan2DBView::ConstructL(const TRect& aRect)
{
oldItem = -1;
currentRecordIndex = 0;
currentRecordIndexIsValid = EFalse;
dbWindow = NULL;
fileStore = NULL;
CreateWindowL();
SetExtent(aRect.iTl, aRect.Size());
securityBase = NULL;
decryptor = NULL;
encryptor = NULL;
dbPassword.Copy(DEFAULT_PASSWORD);
//TFileName rscFile;
//RResourceFile resourceFile;
#ifdef __WINS__
dbFileName.Copy(_L("D:\\SMAN.DB"));
#else
dbFileName.Copy(CEikonEnv::Static()->EikAppUi()->Application()->AppFullName());
dbFileName.SetLength(dbFileName.Length() - 3);
dbFileName.Append(_L("DB"));
#endif
TResourceReader resourceReader;
HBufC8* dataBuffer = CEikonEnv::Static()->AllocReadResourceAsDes8L(R_ARRAY_DB_FIELDNAME);
resourceReader.SetBuffer(dataBuffer);
fieldLabelsArray = resourceReader.ReadDesCArrayL();
delete dataBuffer;
// Initialize the multi record view
cIndexListBox = new(ELeave) CEikColumnListBox;
cIndexListBox->ConstructL(this, CEikColumnListBox::EMultipleSelection);
CColumnListBoxData* listBoxColumns = ((CColumnListBoxItemDrawer*)cIndexListBox->ItemDrawer())->ColumnData();
listBoxColumns->SetColumnWidthPixelL(0, int(Size().iWidth * 0.9));
listBoxColumns->SetColumnAlignmentL(0, CGraphicsContext::ELeft);
// Hidden column. Stores the index values of each row.
listBoxColumns->SetColumnWidthPixelL(1, 0);
listBoxColumns->SetColumnAlignmentL(1, CGraphicsContext::ELeft);
cIndexListBox->CreateScrollBarFrameL();
cIndexListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
cIndexListBox->SetExtent(TPoint(0, 0), TSize(Size().iWidth, Size().iHeight - EQikToolbarHeight - 10));
controlsArray->AppendL(cIndexListBox);
// Initialize the single record view - readonly
readOnlyDisplay = new (ELeave) CGlobalTextEditor;
readOnlyDisplay->ConstructL(this, 9999, 0, CEikEdwin::EReadOnly | CEikEdwin::EDisplayOnly | CEikEdwin::EInclusiveSizeFixed, EGulFontControlAll, EGulAllFonts);
readOnlyDisplay->SetExtent(TPoint(0, 0), TSize(1, 1));
//Size().iWidth, Size().iHeight - EQikToolbarHeight - 10));
readOnlyDisplay->CreateScrollBarFrameL();
readOnlyDisplay->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto, CEikScrollBarFrame::EAuto);
controlsArray->AppendL(readOnlyDisplay);
// Initialize the single record view - non readonly
scrollableContainer = new (ELeave) CQikScrollableContainer;
scrollableContainer->SetContainerWindowL(*this);
scrollableContainer->ConstructL(ETrue);
scrollableContainer->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
scrollableContainer->OverrideColorL(EColorWindowBackground, KRgbCyan);
scrollableContainer->SetBorder(TGulBorder::ESingleGray);
controlsArray->AppendL(scrollableContainer);
fieldDisplayName = new (ELeave) CGlobalTextEditor;
fieldDisplayName->ConstructL(scrollableContainer, 1, 30, CEikEdwin::ENoAutoSelection, EGulFontControlAll, EGulAllFonts);
scrollableContainer->AddControlL(fieldDisplayName);
fieldDisplayName->SetExtent(TPoint(0, 0), TSize(1, 1));
//fieldDisplayName->SetExtent(TPoint(2, 3), TSize(Size().iWidth - scrollableContainer->ScrollBarFrame()->ScrollBarBreadth(CEikScrollBar::EHorizontal) - 2 - 5, 25));
TBuf<2> numberLabel;
//TInt previousPos = fieldDisplayName->Position().iY + fieldDisplayName->Size().iHeight + 3;
for (int i = 0; i < NUM_DATA_FIELDS; i++)
{
fieldLabelsNumbering[i] = new (ELeave) CEikLabel;
numberLabel.Format(_L("%d"), i + 1);
fieldLabelsNumbering[i]->SetTextL(numberLabel);
fieldLabelsNumbering[i]->SetContainerWindowL(*scrollableContainer);
scrollableContainer->AddControlL(fieldLabelsNumbering[i]);
fieldLabelsNumbering[i]->SetExtent(TPoint(0, 0), TSize(1, 1));
fieldLabels[i] = new (ELeave) CComboBox;
fieldLabels[i]->ConstructL(*scrollableContainer, 10, 30, 6);
fieldLabels[i]->SetArray(fieldLabelsArray, CEikComboBox::EArrayExternalOwner);
// you MUST add the control PRIOR to setting its extent! otherwise, the scrollable container will
// do crazy things with the control. to be more exact, it's not the extent but the position of
// the control
scrollableContainer->AddControlL(fieldLabels[i]);
fieldLabels[i]->SetExtent(TPoint(0, 0), TSize(1, 1));
//fieldLabels[i]->SetExtent(TPoint(fieldLabelsNumbering[i]->Position().iX + fieldLabelsNumbering[i]->Size().iWidth + 2, previousPos),
// TSize(Size().iWidth - scrollableContainer->ScrollBarFrame()->ScrollBarBreadth(CEikScrollBar::EHorizontal) - 5 - 2 - fieldLabelsNumbering[i]->Position().iX - fieldLabelsNumbering[i]->Size().iWidth, 25));
fieldValues[i] = new (ELeave) CGlobalTextEditor;
fieldValues[i]->ConstructL(scrollableContainer, 20, 50, CEikEdwin::ENoAutoSelection, EGulFontControlAll, EGulAllFonts);
fieldValues[i]->CreateScrollBarFrameL();
fieldValues[i]->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
scrollableContainer->AddControlL(fieldValues[i]);
fieldValues[i]->SetExtent(TPoint(0, 0), TSize(1, 1));
//fieldValues[i]->SetExtent(TPoint(fieldLabels[i]->Position().iX, fieldLabels[i]->Position().iY + fieldLabels[i]->Size().iHeight + 2),
// TSize(Size().iWidth - scrollableContainer->ScrollBarFrame()->ScrollBarBreadth(CEikScrollBar::EHorizontal) - 2 - 5, 60));
//previousPos = fieldValues[i]->Position().iY + fieldValues[i]->Size().iHeight + 10;
}
fieldDisplayName->SetFocus(ETrue);
//TSize minSize = scrollableContainer->MinimumPageSize();
//scrollableContainer->SetPageSize(minSize);
scrollableContainer->SetExtent(TPoint(0, 0), TSize(Size().iWidth, Size().iHeight - EQikToolbarHeight - 10));
//scrollableContainer->UpdateScrollBarsL();
//scrollableContainer->SetComponentsToInheritVisibility(ETrue);
viewId = CSMan2AppUi::EViewDB;
bjackIconPosition = TPoint(2, scrollableContainer->Position().iY + scrollableContainer->Size().iHeight);
initBJackIcon();
//ShowRecordsList(ETrue, EFalse);
currentDBView = DBView_List;
HideAllControls();
//ShowRecordsList(EFalse, EFalse);
SetZoomLevel(configData->zoomDB);
MakeVisible(EFalse);
ActivateL();
DeInitDB();
}
void CSMan2DBView::HideAllControls()
{
HideRecordsList();
HideRecordsSingle();
HideRecordsSingleReadOnly();
}
void CSMan2DBView::PositionRecordsSingleControls()
{
fieldDisplayName->SetExtent(TPoint(2, 3), TSize(Size().iWidth - scrollableContainer->ScrollBarFrame()->ScrollBarBreadth(CEikScrollBar::EHorizontal) - 2 - 5, font->HeightInPixels() * 2 + 2));
TInt previousLabelPos = fieldDisplayName->Position().iY + fieldDisplayName->Size().iHeight + 3;
for (int i = 0; i < NUM_DATA_FIELDS; i++)
{
fieldLabelsNumbering[i]->SetExtent(TPoint(2, previousLabelPos), TSize(font->CharWidthInPixels(TChar(38)) + 1, font->HeightInPixels() * 2 + 2));
fieldLabels[i]->SetExtent(TPoint(fieldLabelsNumbering[i]->Position().iX + fieldLabelsNumbering[i]->Size().iWidth, previousLabelPos),
TSize(Size().iWidth - scrollableContainer->ScrollBarFrame()->ScrollBarBreadth(CEikScrollBar::EHorizontal) - 2 - 5 - fieldLabelsNumbering[i]->Position().iX - fieldLabelsNumbering[i]->Size().iWidth, font->HeightInPixels() * 2 + 2));
fieldValues[i]->SetExtent(TPoint(fieldLabelsNumbering[i]->Position().iX, fieldLabels[i]->Position().iY + fieldLabels[i]->Size().iHeight + 2),
TSize(Size().iWidth - scrollableContainer->ScrollBarFrame()->ScrollBarBreadth(CEikScrollBar::EHorizontal) - 2 - 5, font->HeightInPixels() * 5));
previousLabelPos = fieldValues[i]->Position().iY + fieldValues[i]->Size().iHeight + 10;
}
scrollableContainer->SetPageSize(scrollableContainer->MinimumPageSize());
scrollableContainer->UpdateScrollBarsL();
}
void CSMan2DBView::SetZoomLevel(TInt zoomLevel)
{
generateZoomFont(zoomLevel);
// Set list view zoom
CTextListItemDrawer* itemDrawer = ((CTextListItemDrawer*)cIndexListBox->View()->ItemDrawer());
itemDrawer->SetFont(font);
cIndexListBox->SetItemHeightL(font->HeightInPixels() + cIndexListBox->VerticalInterItemGap());
// Set single view zoom
TInt lineSpaceTwips[3] = {150, 200, 300};
TCharFormat charFormat;
TCharFormatMask charFormatMask;
// Formatting for display name and field value
CParaFormat paraFormat;
TParaFormatMask paraFormatMask;
charFormat.iFontSpec.iHeight = ((zoomLevel - ZOOM_INCREMENT) / ZOOM_INCREMENT) * 150 + 100;
charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
charFormatMask.SetAttrib(EAttFontHeight);
charFormatMask.SetAttrib(EAttFontStrokeWeight);
paraFormat.iLineSpacingInTwips = lineSpaceTwips[(zoomLevel / ZOOM_INCREMENT) - 1];
paraFormatMask.SetAttrib(EAttLineSpacing);
fieldDisplayName->ApplyCharFormatL(charFormat, charFormatMask);
fieldDisplayName->ApplyParaFormatL(¶Format, paraFormatMask);
// Set single readonly view zoom
readOnlyDisplay->ApplyCharFormatL(charFormat, charFormatMask);
readOnlyDisplay->ApplyParaFormatL(¶Format, paraFormatMask);
// Formatting for field labels
TCharFormat labelCharFormat;
TCharFormatMask labelCharFormatMask;
CParaFormat labelParaFormat;
TParaFormatMask labelParaFormatMask;
TInt labelLineSpaceTwips[3] = {150, 200, 350};
labelCharFormat.iFontSpec.iHeight = ((zoomLevel - ZOOM_INCREMENT) / ZOOM_INCREMENT) * 150 + 100;
labelCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
labelCharFormatMask.SetAttrib(EAttFontHeight);
labelCharFormatMask.SetAttrib(EAttFontStrokeWeight);
labelParaFormat.iLineSpacingInTwips = labelLineSpaceTwips[(zoomLevel / ZOOM_INCREMENT) - 1];;
labelParaFormatMask.SetAttrib(EAttLineSpacing);
CCharFormatLayer *charFormatLayer = CCharFormatLayer::NewL(((const TCharFormat)labelCharFormat), (const TCharFormatMask)labelCharFormatMask);
CParaFormatLayer *paraFormatLayer = CParaFormatLayer::NewL(&labelParaFormat, (const TParaFormatMask)labelParaFormatMask);
TBuf<50> buffer;
for (int i = 0; i < NUM_DATA_FIELDS; i++)
{
fieldLabelsNumbering[i]->SetFont(font);
fieldLabels[i]->GetText(buffer);
CGlobalText *globalText = CGlobalText::NewL(paraFormatLayer, charFormatLayer);
globalText->InsertL(0, buffer);
// This is what the SDK says
//-------------------------------
//Sets the Edwin抯 editable content. Before calling this function you must get the iText
//pointer as iText is replaced by aText. You must also free the memory by deleting the
//previous iText contents.
//-------------------------------
// Somehow, when i tried what the SDK suggested, it doesn't work. The delete operation
// succeeds but the call to SetDocumentContentL crashes
//delete fieldLabels[i]->Edwin()->Text();
fieldLabels[i]->Edwin()->SetDocumentContentL(*globalText);
delete globalText;
fieldLabels[i]->theFont = font;
fieldValues[i]->ApplyCharFormatL(charFormat, charFormatMask);
fieldValues[i]->ApplyParaFormatL(¶Format, paraFormatMask);
}
// Reposition all the controls
PositionRecordsSingleControls();
delete charFormatLayer;
delete paraFormatLayer;
releaseFont();
configData->zoomDB = zoomLevel;
}
void CSMan2DBView::HandleControlEventL(CCoeControl* /*aControl*/, TCoeEvent /*aEventType*/)
{
}
void CSMan2DBView::swapFocus()
{
TInt j;
TBool focusFound = EFalse, focusFoundInLabel = EFalse;
for (j = 0; j < NUM_DATA_FIELDS; j++)
{
if (fieldLabels[j]->IsFocused())
{
fieldLabels[j]->SetFocus(EFalse);
fieldLabels[j]->Edwin()->SetCursorPosL(0, EFalse);
focusFound = ETrue;
focusFoundInLabel = ETrue;
break;
}
else if (fieldValues[j]->IsFocused())
{
fieldValues[j]->SetFocus(EFalse);
fieldValues[j]->SetCursorPosL(0, EFalse);
focusFound = ETrue;
break;
}
}
if (!focusFound)
{
if (fieldDisplayName->IsFocused())
{
fieldDisplayName->SetFocus(EFalse);
fieldDisplayName->SetCursorPosL(0, EFalse);
}
}
// Update the history list of the combo box
if (focusFoundInLabel)
{
TBuf<50> currentEntry;
fieldLabels[j]->GetText(currentEntry);
if (currentEntry.Length() != 0)
{
TBool found = EFalse;
TInt i;
for (i = 0; i < fieldLabelsArray->MdcaCount(); i++)
{
if (fieldLabelsArray->MdcaPoint(i).Compare(currentEntry) == 0)
{
found = ETrue;
break;
}
}
if (!found)
{
fieldLabelsArray->InsertL(0, currentEntry);
fieldLabelsArray->Delete(fieldLabelsArray->MdcaCount() - 1);
}
}
}
}
/*************************************************************
*
* Behaves like normal except
* 1) when focus is lost it will bring the cursor of the edwin to the front
* 2) it will call the dbview to unfocus the previous control
* 3) supports zooming of the list box
*
**************************************************************/
CComboBox::~CComboBox()
{
}
CComboBox::CComboBox() : CEikComboBox()
{
popoutNew = EFalse;
}
void CComboBox::SetTextListBoxZoom()
{
CTextListItemDrawer* itemDrawer = ((CTextListItemDrawer*)iPopout->View()->ItemDrawer());
itemDrawer->SetFont(theFont);
iPopout->SetItemHeightL(theFont->HeightInPixels() + iPopout->VerticalInterItemGap());
while (iPopout->View()->NumberOfItemsThatFitInRect(iPopout->Size()) > iPopout->Model()->ItemTextArray()->MdcaCount())
iPopout->SetSize(TSize(iPopout->Size().iWidth, iPopout->Size().iHeight - iPopout->ItemHeight()));
iPopout->DrawNow();
}
void CComboBox::HandleControlEventL(CCoeControl *aControl, TCoeEvent aEvent)
{
CEikComboBox::HandleControlEventL(aControl, aEvent);
if (iPopout)
{
if (!popoutNew)
{
popoutNew = ETrue;
SetTextListBoxZoom();
}
}
else
popoutNew = EFalse;
}
void CComboBox::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
if ((aPointerEvent.iType == TPointerEvent::EButton1Up) && (!IsFocused()))
{
static_cast<CSMan2AppUi*>(CEikonEnv::Static()->AppUi())->iDBView->swapFocus();
SetFocus(ETrue);
}
CEikComboBox::HandlePointerEventL(aPointerEvent);
}
/*************************************************************
*
* As per the combo box class but without zooming support since this is already
* inherent in the class
*
**************************************************************/
CGlobalTextEditor::CGlobalTextEditor() : CEikGlobalTextEditor()
{
}
void CGlobalTextEditor::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
if ((aPointerEvent.iType == TPointerEvent::EButton1Up) && (!IsFocused()))
{
static_cast<CSMan2AppUi*>(CEikonEnv::Static()->AppUi())->iDBView->swapFocus();
SetFocus(ETrue);
}
CEikGlobalTextEditor::HandlePointerEventL(aPointerEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -