diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2010-10-04 18:15:55 -0400 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2010-10-04 18:15:55 -0400 |
commit | b91b8e9098cdbdfac414ebb0e036edc962056ce8 (patch) | |
tree | 5c955157b4d0d16a1405fe16476bfc5399a47943 /sc/source/ui/view | |
parent | f7e2c840aa9d243cf0dee58713e71de895b292ce (diff) |
Ported calc-insert-current-time-sc.diff from ooo-build.
This enables quick insertion of current date and time into current
cell, via command. By default, these commands are bound to
* Ctrl-';'
* Ctrl-Shift-';'
respectively.
Diffstat (limited to 'sc/source/ui/view')
-rw-r--r-- | sc/source/ui/view/cellsh1.cxx | 8 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun6.cxx | 26 |
2 files changed, 34 insertions, 0 deletions
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index 90caf6607080..2fd7fbee2542 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -1526,6 +1526,14 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) case SID_DETECTIVE_MARK_SUCC: pTabViewShell->DetectiveMarkSucc(); break; + case SID_INSERT_CURRENT_DATE: + pTabViewShell->InsertCurrentTime( + NUMBERFORMAT_DATE, ScGlobal::GetRscString(STR_UNDO_INSERT_CURRENT_DATE)); + break; + case SID_INSERT_CURRENT_TIME: + pTabViewShell->InsertCurrentTime( + NUMBERFORMAT_TIME, ScGlobal::GetRscString(STR_UNDO_INSERT_CURRENT_TIME)); + break; case SID_SPELL_DIALOG: // pTabViewShell->DoSpellingChecker(); diff --git a/sc/source/ui/view/viewfun6.cxx b/sc/source/ui/view/viewfun6.cxx index f00c0bcde688..eaa55f50a0e2 100644 --- a/sc/source/ui/view/viewfun6.cxx +++ b/sc/source/ui/view/viewfun6.cxx @@ -34,6 +34,7 @@ #include <sfx2/dispatch.hxx> #include <vcl/msgbox.hxx> #include <vcl/sound.hxx> +#include "svl/zforlist.hxx" #include "viewfunc.hxx" #include "detfunc.hxx" @@ -49,12 +50,16 @@ #include "fusel.hxx" #include "reftokenhelper.hxx" #include "externalrefmgr.hxx" +#include "cell.hxx" #include <vector> +using ::rtl::OUString; using ::rtl::OUStringBuffer; using ::std::vector; +#define D_TIMEFACTOR 86400.0 + //================================================================== void ScViewFunc::DetectiveAddPred() @@ -274,6 +279,27 @@ void ScViewFunc::DetectiveMarkSucc() MarkAndJumpToRanges(aDestRanges); } +void ScViewFunc::InsertCurrentTime(short nCellFmt, const OUString& rUndoStr) +{ + ScViewData* pViewData = GetViewData(); + ScAddress aCurPos = pViewData->GetCurPos(); + ScDocShell* pDocSh = pViewData->GetDocShell(); + ScDocument* pDoc = pDocSh->GetDocument(); + SfxUndoManager* pUndoMgr = pDocSh->GetUndoManager(); + SvNumberFormatter* pFormatter = pDoc->GetFormatTable(); + Date aActDate; + double fDate = aActDate - *pFormatter->GetNullDate(); + Time aActTime; + double fTime = + aActTime.Get100Sec() / 100.0 + aActTime.GetSec() + + (aActTime.GetMin() * 60.0) + (aActTime.GetHour() * 3600.0); + fTime /= D_TIMEFACTOR; + pUndoMgr->EnterListAction(rUndoStr, rUndoStr); + pDocSh->GetDocFunc().PutCell(aCurPos, new ScValueCell(fDate+fTime), false); + SetNumberFormat(nCellFmt); + pUndoMgr->LeaveListAction(); +} + //--------------------------------------------------------------------------- void ScViewFunc::ShowNote( bool bShow ) |