Fix bug 231280 (printing not honoring OS date format). Patch by Constantine

A. Murenin <cnst.bmo@bugmail.mojo.ru>, r=jshin, sr=roc, a=chofmann
This commit is contained in:
bzbarsky%mit.edu 2004-02-16 05:31:25 +00:00
Родитель c2c321c9e1
Коммит 2379629a94
4 изменённых файлов: 38 добавлений и 54 удалений

Просмотреть файл

@ -59,13 +59,7 @@
// DateTime Includes
#include "nsDateTimeFormatCID.h"
#include "nsIDateTimeFormat.h"
#include "nsIServiceManager.h"
#include "nsILocale.h"
#include "nsLocaleCID.h"
#include "nsILocaleService.h"
static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
#define OFFSET_NOT_SET -1
@ -490,27 +484,21 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
}
// Create current Date/Time String
nsresult rv;
nsCOMPtr<nsILocale> locale;
nsCOMPtr<nsILocaleService> localeSvc = do_GetService(kLocaleServiceCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = localeSvc->GetApplicationLocale(getter_AddRefs(locale));
if (NS_SUCCEEDED(rv) && locale) {
nsCOMPtr<nsIDateTimeFormat> dateTime;
rv = nsComponentManager::CreateInstance(kDateTimeFormatCID,
NULL,
NS_GET_IID(nsIDateTimeFormat),
(void**) getter_AddRefs(dateTime));
if (NS_SUCCEEDED(rv)) {
nsAutoString dateString;
time_t ltime;
time( &ltime );
if (NS_SUCCEEDED(dateTime->FormatTime(locale, kDateFormatShort, kTimeFormatNoSeconds, ltime, dateString))) {
PRUnichar * uStr = ToNewUnicode(dateString);
SetDateTimeStr(uStr); // memory will be freed
}
}
}
if (!mDateFormatter)
mDateFormatter = do_CreateInstance(kDateTimeFormatCID);
NS_ENSURE_TRUE(mDateFormatter, NS_ERROR_FAILURE);
nsAutoString formattedDateString;
time_t ltime;
time( &ltime );
if (NS_SUCCEEDED(mDateFormatter->FormatTime(nsnull /* nsILocale* locale */,
kDateFormatShort,
kTimeFormatNoSeconds,
ltime,
formattedDateString))) {
PRUnichar * uStr = ToNewUnicode(formattedDateString);
SetDateTimeStr(uStr); // memory will be freed
}
}

Просмотреть файл

@ -41,6 +41,7 @@
#include "nsContainerFrame.h"
#include "nsIPrintSettings.h"
#include "nsIPrintOptions.h"
#include "nsIDateTimeFormat.h"
//-----------------------------------------------
// This class maintains all the data that
@ -186,6 +187,9 @@ protected:
nscoord mSelectionHeight;
nscoord mYSelOffset;
// I18N date formatter service which we'll want to cache locally.
nsCOMPtr<nsIDateTimeFormat> mDateFormatter;
private:
void CacheBackground(nsIPresContext* aPresContext);

Просмотреть файл

@ -59,13 +59,7 @@
// DateTime Includes
#include "nsDateTimeFormatCID.h"
#include "nsIDateTimeFormat.h"
#include "nsIServiceManager.h"
#include "nsILocale.h"
#include "nsLocaleCID.h"
#include "nsILocaleService.h"
static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
#define OFFSET_NOT_SET -1
@ -490,27 +484,21 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext,
}
// Create current Date/Time String
nsresult rv;
nsCOMPtr<nsILocale> locale;
nsCOMPtr<nsILocaleService> localeSvc = do_GetService(kLocaleServiceCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = localeSvc->GetApplicationLocale(getter_AddRefs(locale));
if (NS_SUCCEEDED(rv) && locale) {
nsCOMPtr<nsIDateTimeFormat> dateTime;
rv = nsComponentManager::CreateInstance(kDateTimeFormatCID,
NULL,
NS_GET_IID(nsIDateTimeFormat),
(void**) getter_AddRefs(dateTime));
if (NS_SUCCEEDED(rv)) {
nsAutoString dateString;
time_t ltime;
time( &ltime );
if (NS_SUCCEEDED(dateTime->FormatTime(locale, kDateFormatShort, kTimeFormatNoSeconds, ltime, dateString))) {
PRUnichar * uStr = ToNewUnicode(dateString);
SetDateTimeStr(uStr); // memory will be freed
}
}
}
if (!mDateFormatter)
mDateFormatter = do_CreateInstance(kDateTimeFormatCID);
NS_ENSURE_TRUE(mDateFormatter, NS_ERROR_FAILURE);
nsAutoString formattedDateString;
time_t ltime;
time( &ltime );
if (NS_SUCCEEDED(mDateFormatter->FormatTime(nsnull /* nsILocale* locale */,
kDateFormatShort,
kTimeFormatNoSeconds,
ltime,
formattedDateString))) {
PRUnichar * uStr = ToNewUnicode(formattedDateString);
SetDateTimeStr(uStr); // memory will be freed
}
}

Просмотреть файл

@ -41,6 +41,7 @@
#include "nsContainerFrame.h"
#include "nsIPrintSettings.h"
#include "nsIPrintOptions.h"
#include "nsIDateTimeFormat.h"
//-----------------------------------------------
// This class maintains all the data that
@ -186,6 +187,9 @@ protected:
nscoord mSelectionHeight;
nscoord mYSelOffset;
// I18N date formatter service which we'll want to cache locally.
nsCOMPtr<nsIDateTimeFormat> mDateFormatter;
private:
void CacheBackground(nsIPresContext* aPresContext);