calendarui/editors/src/calenunifiededitor.cpp
branchRCL_3
changeset 19 1984aceb8774
parent 13 0f07cd1b5772
child 20 21239b3bcd78
equal deleted inserted replaced
13:0f07cd1b5772 19:1984aceb8774
   567              // command line.  We do not want to update calendars stored focus
   567              // command line.  We do not want to update calendars stored focus
   568              // in case we override any command line parameters
   568              // in case we override any command line parameters
   569              // Intentional fall through to EEikBidCancel below
   569              // Intentional fall through to EEikBidCancel below
   570              iEntryUiOutParams.iAction = ENoAction;
   570              iEntryUiOutParams.iAction = ENoAction;
   571              iEntryUiOutParams.iSpare = 0;
   571              iEntryUiOutParams.iSpare = 0;
       
   572              MCalenContext& context = iServices->Context();
       
   573              HBufC* fileNamePtr = context.GetCalAlarmEntryFileNameL();             
       
   574              TCalLocalUid localUid = context.CalAlarmLocalUidL();           
       
   575              if (fileNamePtr != NULL && !fileNamePtr->CompareF(iGlobalData->GetCalFileNameForCollectionId(context.InstanceId().iColId)) 
       
   576                      && localUid == context.InstanceId().iEntryLocalUid)
       
   577                  {
       
   578                  context.ResetCalAlarmEntryFileName();
       
   579                  break;
       
   580                  }
   572              // Fall through...
   581              // Fall through...
   573              }
   582              }
   574          case ECalenEditSeries:
   583          case ECalenEditSeries:
   575          case ECalenEditOccurrence:
   584          case ECalenEditOccurrence:
   576          case EAknCmdExit:
   585          case EAknCmdExit:
   656 // -----------------------------------------------------------------------------
   665 // -----------------------------------------------------------------------------
   657 //
   666 //
   658 TKeyResponse CCalenUnifiedEditor::OfferKeyEventL( const TKeyEvent& aKeyEvent,
   667 TKeyResponse CCalenUnifiedEditor::OfferKeyEventL( const TKeyEvent& aKeyEvent,
   659                                                   TEventCode aType )
   668                                                   TEventCode aType )
   660     {
   669     {
   661     TRACE_ENTRY_POINT;
   670     
   662     TBool isMapIconHandled = EFalse;
   671      TRACE_ENTRY_POINT;
   663     TKeyResponse keyResponse( EKeyWasNotConsumed );
   672     TKeyResponse keyResponse( EKeyWasNotConsumed );
   664     TInt ctrlid=IdOfFocusControl();
   673     TInt ctrlid=IdOfFocusControl();
   665    
   674    
   666     /* If KeyCallBack has not been called after construction 
   675     /* If KeyCallBack has not been called after construction 
   667      * (= initialization of iIdle) call it now to 
   676      * (= initialization of iIdle) call it now to 
   694                 // opened is closing the application.
   703                 // opened is closing the application.
   695                 TryExitL( ECalenCmdCloseDialog );
   704                 TryExitL( ECalenCmdCloseDialog );
   696                 keyResponse = EKeyWasConsumed;
   705                 keyResponse = EKeyWasConsumed;
   697                 break;
   706                 break;
   698             case EKeyEnter: // For Enter key
   707             case EKeyEnter: // For Enter key
       
   708             case EKeyDelete: // For Delete key
   699 				{
   709 				{
   700 				keyResponse = CAknForm::OfferKeyEventL(aKeyEvent,aType); // Let framework handle the key event
   710 				keyResponse = CAknForm::OfferKeyEventL(aKeyEvent,aType); // Let framework handle the key event
   701 				// when enter key is pressed on subject line or on location line, call AddPictureL to recalculate the map icon position properly
       
   702 				// as location field could habe moved up or down
       
   703 				if(ctrlid == ECalenEditorPlace || ctrlid == ECalenEditorSubject)
       
   704 					{
       
   705 					CCalGeoValue* geoValue = iEditorDataHandler->Entry().GeoValueL();
       
   706 					if(geoValue)
       
   707 						{
       
   708 						isMapIconHandled = ETrue;
       
   709 						AddPictureL();
       
   710 						delete geoValue;
       
   711 						}
       
   712 					}
       
   713 				}
       
   714 				break;
       
   715 			case EKeyDelete:
       
   716 				{
       
   717 				if(ctrlid == ECalenEditorPlace)
       
   718 					{
       
   719 					CCalGeoValue* geoValue = iEditorDataHandler->Entry().GeoValueL();
       
   720 					if(geoValue)
       
   721 						{
       
   722 						CEikRichTextEditor* locationControl = static_cast<CEikRichTextEditor*>(Control(ECalenEditorPlace));
       
   723 						CRichText* text = locationControl->RichText();
       
   724 						TPtrC ptr = text->Read(0,text->DocumentLength());
       
   725 						TInt pos = ptr.Locate(TChar(CEditableText::EPictureCharacter));
       
   726 						if(locationControl->CursorPos() == pos)
       
   727 							{
       
   728 							isMapIconHandled = ETrue;
       
   729 							keyResponse = EKeyWasConsumed;
       
   730 							delete geoValue;
       
   731 							break;
       
   732 							}
       
   733 						delete geoValue;
       
   734 						}
       
   735 					}
       
   736 					keyResponse = CAknForm::OfferKeyEventL(aKeyEvent,aType); // Let framework handle the key event
       
   737 				}
   711 				}
   738 				break;
   712 				break;
   739 			case EKeyBackspace:  // For back space character
   713 			case EKeyBackspace:  // For back space character
   740 				{
   714 				{
   741 				if(ctrlid == ECalenEditorPlace)
   715 				if(ctrlid == ECalenEditorPlace || ECalenEditorSubject)
   742 					{
       
   743 					CCalGeoValue* geoValue = iEditorDataHandler->Entry().GeoValueL();
       
   744 					if(geoValue)
       
   745 						{
       
   746 						CEikRichTextEditor* locationControl = static_cast<CEikRichTextEditor*>(Control(ECalenEditorPlace));
       
   747 						CRichText* text = locationControl->RichText();
       
   748 						TPtrC ptr = text->Read(0,text->DocumentLength());
       
   749 						TInt pos = ptr.Locate(TChar(CEditableText::EPictureCharacter));
       
   750 						TInt curpos = locationControl->CursorPos();
       
   751 						
       
   752 						// When only one visible character is there and picture byte is there at second position, then
       
   753 						// empty the location field and redraw the map icon
       
   754 						if(text->DocumentLength() <= 2) 
       
   755 							{
       
   756 							TBuf<1> newLocation;
       
   757 							SetEdwinTextL(ECalenEditorPlace, &newLocation);
       
   758 							keyResponse = EKeyWasConsumed;
       
   759 							delete geoValue;
       
   760 							isMapIconHandled = ETrue;
       
   761 							AddPictureL();
       
   762 							break;
       
   763 							}
       
   764 						//  when cursor position is at the end, then since, picture byte is at the end
       
   765 						// delete last but one character (for user, it looks as if last visible character is being deleted)
       
   766 						// and redraw the icon
       
   767 						 else if( curpos == pos + 1)
       
   768 							{
       
   769 							text->DeleteL(text->DocumentLength() - 2,1);
       
   770 							
       
   771 							AddPictureL();
       
   772 							locationControl->SetCursorPosL(curpos - 1, EFalse);
       
   773 							isMapIconHandled = ETrue;
       
   774 							keyResponse = EKeyWasConsumed;
       
   775 							delete geoValue;
       
   776 							break;
       
   777 							}
       
   778 						delete geoValue;
       
   779 						}
       
   780 					}
       
   781 				// This is to handle backspaces in subject field when there nore that one lines,
       
   782 				// location field will move up, hence, need to redraw the map icon
       
   783 				else if(ctrlid == ECalenEditorSubject)
       
   784 					{
   716 					{
   785 					keyResponse = CAknForm::OfferKeyEventL(aKeyEvent,aType);
   717 					keyResponse = CAknForm::OfferKeyEventL(aKeyEvent,aType);
   786 					CCalGeoValue* geoValue = iEditorDataHandler->Entry().GeoValueL();
       
   787 					if(geoValue)
       
   788 						{
       
   789 						AddPictureL();
       
   790 						isMapIconHandled = ETrue;
       
   791 						delete geoValue;
       
   792 						}
       
   793 					break;
       
   794 					}
   718 					}
       
   719 				break;
   795 				}
   720 				}
   796             case EKeyLeftArrow:
   721             case EKeyLeftArrow:
   797             case EKeyRightArrow:
   722             case EKeyRightArrow:
   798                 {
   723                 {
   799                 if( ECalenEditorEventType == IdOfFocusControl() )
   724                 if( ECalenEditorEventType == IdOfFocusControl() )
   808                 break;
   733                 break;
   809  
   734  
   810             default:
   735             default:
   811                 {
   736                 {
   812                 keyResponse = CAknForm::OfferKeyEventL(aKeyEvent,aType); 
   737                 keyResponse = CAknForm::OfferKeyEventL(aKeyEvent,aType); 
   813                 if(!isMapIconHandled)
       
   814                     {
       
   815                     if((ctrlid == ECalenEditorPlace) || (ctrlid == ECalenEditorSubject))
       
   816                         {
       
   817                         CCalGeoValue* geoValue = iEditorDataHandler->Entry().GeoValueL();
       
   818                         if(geoValue)
       
   819                             {
       
   820                             isMapIconHandled = ETrue;
       
   821                             AddPictureL();
       
   822                             delete geoValue;
       
   823                             }
       
   824                         }
       
   825                     }
       
   826                 }
   738                 }
   827                 break;
   739                 break;
   828             }
   740             }
   829         }
   741         }
   830         
   742         
  1063 void CCalenUnifiedEditor::PostLayoutDynInitL()
   975 void CCalenUnifiedEditor::PostLayoutDynInitL()
  1064     {
   976     {
  1065     TRACE_ENTRY_POINT;
   977     TRACE_ENTRY_POINT;
  1066     
   978     
  1067     SetEditableL(ETrue);
   979     SetEditableL(ETrue);
  1068     CCalGeoValue* geoValue = iEditorDataHandler->Entry().GeoValueL();
   980 
  1069 	if(geoValue)
       
  1070 		{
       
  1071 		AddPictureL();	
       
  1072 		delete geoValue;	
       
  1073 		}
       
  1074     TCallBack callback( LocaleCallback, this );
   981     TCallBack callback( LocaleCallback, this );
  1075     iLocaleChangeNotifier =
   982     iLocaleChangeNotifier =
  1076         CEnvironmentChangeNotifier::NewL( EActivePriorityLogonA, callback );
   983         CEnvironmentChangeNotifier::NewL( EActivePriorityLogonA, callback );
  1077 
   984 
  1078     iLocaleChangeNotifier->Start();
   985     iLocaleChangeNotifier->Start();
  1330         CAknForm::HandleResourceChange( aType );
  1237         CAknForm::HandleResourceChange( aType );
  1331         }
  1238         }
  1332 
  1239 
  1333     CCoeControl::HandleResourceChange( aType );
  1240     CCoeControl::HandleResourceChange( aType );
  1334     
  1241     
  1335     CCalGeoValue* geoValue = NULL;
       
  1336 	TRAP_IGNORE(geoValue = iEditorDataHandler->Entry().GeoValueL());	
       
  1337 	if(geoValue)
       
  1338 		{
       
  1339 		TRAP_IGNORE(AddPictureL());	
       
  1340 		delete geoValue;	
       
  1341 		}
       
  1342 		
       
  1343     TRACE_EXIT_POINT;
  1242     TRACE_EXIT_POINT;
  1344     }
  1243     }
  1345 
  1244 
  1346 // -----------------------------------------------------------------------------
  1245 // -----------------------------------------------------------------------------
  1347 // CCalenUnifiedEditor::DynInitMenuPaneL
  1246 // CCalenUnifiedEditor::DynInitMenuPaneL
  2707 		    }
  2606 		    }
  2708 		else // This is the new entry being created and nothing is there in location field
  2607 		else // This is the new entry being created and nothing is there in location field
  2709 			{
  2608 			{
  2710 			isReplaceLocation = EFalse;
  2609 			isReplaceLocation = EFalse;
  2711 			StoreLocationDetailsToEntryL(landmark);
  2610 			StoreLocationDetailsToEntryL(landmark);
  2712 			AddPictureL(0);
       
  2713 			}
  2611 			}
  2714 		}
  2612 		}
  2715 		
  2613 		
  2716 	TRACE_EXIT_POINT;
  2614 	TRACE_EXIT_POINT;
  2717 	}
  2615 	}
  2731 	landmark->GetLandmarkName(locationName);
  2629 	landmark->GetLandmarkName(locationName);
  2732 	TInt userResponse = ShowLocationReplaceNoticeL(locationName);
  2630 	TInt userResponse = ShowLocationReplaceNoticeL(locationName);
  2733 	if(userResponse)
  2631 	if(userResponse)
  2734 		{
  2632 		{
  2735 		StoreLocationDetailsToEntryL(landmark);
  2633 		StoreLocationDetailsToEntryL(landmark);
  2736 		AddPictureL();
       
  2737 		}
  2634 		}
  2738 		
  2635 		
  2739 	TRACE_EXIT_POINT;	
  2636 	TRACE_EXIT_POINT;	
  2740 	}
  2637 	}
  2741 
  2638 
  2795             break;
  2692             break;
  2796         default:
  2693         default:
  2797             break;
  2694             break;
  2798         }
  2695         }
  2799         StoreLocationDetailsToEntryL(landmark);
  2696         StoreLocationDetailsToEntryL(landmark);
  2800         AddPictureL(0);
       
  2801         
  2697         
  2802     TRACE_EXIT_POINT;   
  2698     TRACE_EXIT_POINT;   
  2803     }
  2699     }
  2804 
  2700 
  2805 // -----------------------------------------------------------------------------
  2701 // -----------------------------------------------------------------------------
  2846 	if(existingLocationInfo.Length())
  2742 	if(existingLocationInfo.Length())
  2847         {
  2743         {
  2848         ShowAddressUpdatedNoticeL();
  2744         ShowAddressUpdatedNoticeL();
  2849         }
  2745         }
  2850 	 
  2746 	 
  2851 	PreLayoutDynInitL();
       
  2852 	
  2747 	
  2853 	TRACE_EXIT_POINT;	
  2748 	TRACE_EXIT_POINT;	
  2854 	}
  2749 	}
  2855 	
  2750 	
  2856 // ----------------------------------------------------------------------------
  2751 // ----------------------------------------------------------------------------
  3172 // -----------------------------------------------------------------------------
  3067 // -----------------------------------------------------------------------------
  3173 // 
  3068 // 
  3174 void CCalenUnifiedEditor::LineChangedL( TInt /* aControlId */ )
  3069 void CCalenUnifiedEditor::LineChangedL( TInt /* aControlId */ )
  3175     {
  3070     {
  3176     TRACE_ENTRY_POINT;
  3071     TRACE_ENTRY_POINT;
  3177     
  3072 
  3178     CCalGeoValue* geoValue = iEditorDataHandler->Entry().GeoValueL();
       
  3179 	if(geoValue)
       
  3180 		{
       
  3181 		AddPictureL();	
       
  3182 		delete geoValue;	
       
  3183 		}
       
  3184 		
       
  3185     SetMskFromResourceL();
  3073     SetMskFromResourceL();
  3186     TRACE_EXIT_POINT;
  3074     TRACE_EXIT_POINT;
  3187     }
  3075     }
  3188 
  3076 
  3189 
  3077 
  3340         }
  3228         }
  3341     UpdateFormL();
  3229     UpdateFormL();
  3342     TRACE_EXIT_POINT;
  3230     TRACE_EXIT_POINT;
  3343     }
  3231     }
  3344 
  3232 
  3345 // -----------------------------------------------------------------------------
       
  3346 // CCalenUnifiedEditor::AddPictureL
       
  3347 // Adds Map icon onto the editors
       
  3348 // -----------------------------------------------------------------------------
       
  3349 //      
       
  3350 void CCalenUnifiedEditor::AddPictureL(TInt isNotFirstTime)
       
  3351     {
       
  3352     TRACE_ENTRY_POINT;
       
  3353     return;
       
  3354     
       
  3355     // Instantiate CMapIconPicture object 300x300 twips in size
       
  3356     CEikRichTextEditor* locationControl = static_cast<CEikRichTextEditor*>(Control(ECalenEditorPlace));
       
  3357     
       
  3358     CRichText* text = locationControl->RichText();
       
  3359     if(isNotFirstTime)
       
  3360         {
       
  3361         TPtrC ptr = text->Read(0,text->DocumentLength());
       
  3362         TInt pos = ptr.Locate(TChar(CEditableText::EPictureCharacter));
       
  3363         if(pos != -1) // If picture found, delete it so that it cna be drawn at new place
       
  3364             {
       
  3365             TRAP_IGNORE(text->DeleteL(pos,1));
       
  3366             }
       
  3367         }
       
  3368     
       
  3369     // Get the rect of the caption of ECalenEditorPlace control
       
  3370     CEikLabel* label = this->ControlCaption(ECalenEditorPlace);
       
  3371     TRect rect = label->Rect();
       
  3372     
       
  3373     CMapsIconPicture* picture = new( ELeave )CMapsIconPicture(/* TSize( 300, 300 )*/ *iServices, rect );
       
  3374     CleanupStack::PushL(picture);
       
  3375     //Prepare the picture header, which will be inserted into the rich text
       
  3376     TPictureHeader header;
       
  3377     header.iPicture = TSwizzle<CPicture>(picture);
       
  3378     
       
  3379     // Position where we insert picture is not valid as it always draws icon depending the rect we provide
       
  3380     
       
  3381         text->InsertL(text->DocumentLength(), header);
       
  3382         
       
  3383     locationControl->HandleTextChangedL();
       
  3384     CleanupStack::Pop(); // picture
       
  3385     
       
  3386     Control(ECalenEditorPlace)->DrawNow();
       
  3387     
       
  3388     TRACE_EXIT_POINT;   
       
  3389     }
       
  3390 
  3233 
  3391 // -----------------------------------------------------------------------------
  3234 // -----------------------------------------------------------------------------
  3392 // CCalenUnifiedEditor::AttachmentNamesL
  3235 // CCalenUnifiedEditor::AttachmentNamesL
  3393 // Provides all the attachments names
  3236 // Provides all the attachments names
  3394 // -----------------------------------------------------------------------------
  3237 // -----------------------------------------------------------------------------