summaryrefslogtreecommitdiff
path: root/sc/source/ui
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2010-10-04 18:15:55 -0400
committerKohei Yoshida <kyoshida@novell.com>2010-10-04 18:15:55 -0400
commitb91b8e9098cdbdfac414ebb0e036edc962056ce8 (patch)
tree5c955157b4d0d16a1405fe16476bfc5399a47943 /sc/source/ui
parentf7e2c840aa9d243cf0dee58713e71de895b292ce (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')
-rw-r--r--sc/source/ui/inc/viewfunc.hxx2
-rw-r--r--sc/source/ui/src/globstr.src8
-rw-r--r--sc/source/ui/view/cellsh1.cxx8
-rw-r--r--sc/source/ui/view/viewfun6.cxx26
4 files changed, 44 insertions, 0 deletions
diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx
index 05a168606f46..301c3e5663f7 100644
--- a/sc/source/ui/inc/viewfunc.hxx
+++ b/sc/source/ui/inc/viewfunc.hxx
@@ -328,6 +328,8 @@ public:
void DetectiveMarkPred();
void DetectiveMarkSucc();
+ void InsertCurrentTime(short nCellFmt, const ::rtl::OUString& rUndoStr);
+
void ShowNote( bool bShow = true );
inline void HideNote() { ShowNote( false ); }
void EditNote();
diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src
index 6c15762bda6a..2fd50d5f97f3 100644
--- a/sc/source/ui/src/globstr.src
+++ b/sc/source/ui/src/globstr.src
@@ -1738,5 +1738,13 @@ Resource RID_GLOBSTR
{
Text [ en-US ] = "DataPilot table needs at least two rows of data to create or refresh." ;
};
+ String STR_UNDO_INSERT_CURRENT_DATE
+ {
+ Text [ en-US ] = "Insert Current Date";
+ };
+ String STR_UNDO_INSERT_CURRENT_TIME
+ {
+ Text [ en-US ] = "Insert Current Time";
+ };
};
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 )