📄 datemonth.c
字号:
else if (monthP->year > firstYear)
{
monthP->month = december;
monthP->year--;
}
else
return;
}
// Move foreward one month.
else
{
if (monthP->month < december)
monthP->month++;
else if (monthP->year < lastYear)
{
monthP->month = january;
monthP->year++;
}
else
return;
}
MonthViewSetTitle (monthP);
DrawMonth (monthP, drawDaySelected);
}
/***********************************************************************
*
* FUNCTION: MonthViewDoCommand
*
* DESCRIPTION: This routine preforms the menu command specified.
*
* PARAMETERS: command - menu item id
*
* RETURNED: true if
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 7/17/96 Initial Revision
* jmp 10/31/99 Move WinEraseRectangle() & DrawAppointmentsInMonth()
* into DrawMonth() itself.
*
***********************************************************************/
static Boolean MonthViewDoCommand (UInt16 command)
{
MonthPtr monthP = MonthViewGetMonthPtr();
// Preferences
if (command == MonthPreferencesCmd)
FrmPopupForm (PreferencesDialog);
// Display Options
else if (command == MonthDisplayOptionsCmd)
FrmPopupForm (DisplayDialog);
// About
else if (command == MonthSecurityCmd)
{
DoSecurity();
DrawMonth (monthP, drawDaySelected);
}
// About
else if (command == MonthGetInfoCmd)
AbtShowAbout (sysFileCDatebook);
return (true);
}
/***********************************************************************
*
* FUNCTION: MonthViewInit
*
* DESCRIPTION: This routine initialize the month view.
*
* PARAMETERS: frm - pointer of the Month View form
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 4/8/96 Initial Revision
* 2002-10-21 CS If we've got support for the lunar calendar, then
* display the lunar view push button (otherwise spread
* buttons out a bit).
* 2002-10-22 CS Highlight current view pushbutton based on the contents
* of pMonthViewButtonID.
*
***********************************************************************/
static void MonthViewInit (FormPtr frm)
{
UInt16 objIndex;
Int16 width;
MonthPtr monthP;
// Create a month object, initialize it, and store a pointer to it in the
// month gadget of the Month View.
monthP = MemPtrNew (sizeof (MonthType));
if (monthP)
{
objIndex = FrmGetObjectIndex (frm, MonthGadget);
FrmGetObjectBounds (frm, objIndex, &monthP->bounds);
width = monthP->bounds.extent.x;
monthP->bounds.extent.x = (width / daysInWeek * daysInWeek) + 1;
monthP->bounds.topLeft.x = (width - monthP->bounds.extent.x) / 2;
monthP->month = Date.month;
monthP->year = Date.year + firstYear;
FrmSetGadgetData (frm, objIndex, monthP);
MonthViewSetTitle (monthP);
// Display the Lunar View push button if we've got support for it.
if (DateSupportsLunarCalendar()) {
FrmShowObject (frm, FrmGetObjectIndex(frm, MonthLunarViewButton));
// Otherwise, spread the buttons out a bit to make use of extra space.
} else {
RectangleType lastButtonBounds;
RectangleType buttonBounds;
FrmGetObjectBounds( frm,
FrmGetObjectIndex(frm, MonthMonthViewButton),
&lastButtonBounds);
FrmGetObjectBounds( frm,
FrmGetObjectIndex(frm, MonthAgendaViewButton),
&buttonBounds);
buttonBounds.topLeft.x = ( lastButtonBounds.topLeft.x
+ lastButtonBounds.extent.x
+ 1);
FrmSetObjectBounds( frm,
FrmGetObjectIndex(frm, MonthAgendaViewButton),
&buttonBounds);
lastButtonBounds = buttonBounds;
FrmGetObjectBounds( frm,
FrmGetObjectIndex(frm, MonthGoToButton),
&buttonBounds);
buttonBounds.topLeft.x = ( lastButtonBounds.topLeft.x
+ lastButtonBounds.extent.x
+ kButtonSpacing);
FrmSetObjectBounds( frm,
FrmGetObjectIndex(frm, MonthGoToButton),
&buttonBounds);
}
// Highlight the Month View push button.
FrmSetControlGroupSelection (frm, DayViewGroup, pMonthViewButtonID);
}
TimeDisplayed = false;
}
/***********************************************************************
*
* FUNCTION: DateSetMonthView
*
* DESCRIPTION: Ensure that the next time MonthViewInit is called,
* we'll display the view associated with <buttonID>.
*
* PARAMETERS: buttonID - either MonthMonthViewButton or MonthLunarViewButton
*
* RETURNED: Nothing
*
* REVISION HISTORY:
* 2002-10-22 CS New today to support Lunar View.
*
***********************************************************************/
void DateSetMonthView(UInt16 pushButtonID)
{
if (pushButtonID == MonthLunarViewButton) {
pMonthViewButtonID = pushButtonID;
} else {
pMonthViewButtonID = MonthMonthViewButton;
}
} // DateSetMonthView
/***********************************************************************
*
* FUNCTION: MonthViewHandleEvent
*
* DESCRIPTION: This routine is the event handler for the Month View
* of the Datebook application.
*
* PARAMETERS: event - a pointer to an EventType structure
*
* RETURNED: true if the event was handled and should not be passed
* to a higher level handler.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 4/8/96 Initial Revision
* CSS 06/22/99 Standardized keyDownEvent handling
* (TxtCharIsHardKey, commandKeyMask, etc.)
* rbb 6/2/99 Added button for Agenda view
* jmp 10/6/99 Fix bug #22497: Perform a FrmDrawForm() before
* updating the rest of the form on frmUpdateEvents;
* also, replace FrmGetActiveForm() with FrmGetFormPtr()
* as that is more correct in these modern times of
* generating update events when bits fail to be allocated.
* jmp 10/31/99 Move WinEraseRectangle() & DrawAppointmentsInMonth()
* into DrawMonth() itself.
* 2002-10-22 CS Switch to Lunar View if we're displaying the Month
* View, and the user taps the Lunar View pushbutton.
* CS Switch to Month View if we're displaying the Lunar
* View, and the user taps the Month View pushbutton.
* 2002-10-23 CS Switch to Lunar View if we're displaying the Month
* View, the Lunar View exists, and the user presses
* the Datebook hard key.
*
***********************************************************************/
Boolean MonthViewHandleEvent (EventType* event)
{
UInt16 daysInMonth;
FormPtr frm;
DateType date;
Boolean handled = false;
MonthPtr monthP;
if (event->eType == penDownEvent)
{
monthP = MonthViewGetMonthPtr ();
if (MonthSelectDay (monthP, event, &date))
{
Date = date;
FrmGotoForm (DayView);
handled = true;
}
}
else if (event->eType == keyDownEvent)
{
MonthViewHideTime (true);
if (EvtKeydownIsVirtual(event))
{
if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr))
{
DateSecondsToDate (TimGetSeconds (), &date);
Date = date;
if (EventInCurrentView ||
(event->data.keyDown.modifiers & poweredOnKeyMask))
{
FrmGotoForm (DayView);
}
else if ( (pMonthViewButtonID != MonthLunarViewButton)
&& DateSupportsLunarCalendar())
{
DateSetMonthView(MonthLunarViewButton);
FrmGotoForm (MonthView);
}
else
{
FrmGotoForm (AgendaView);
}
handled = true;
EventInCurrentView = true;
}
else if (event->data.keyDown.chr == vchrPageUp)
{
monthP = MonthViewGetMonthPtr ();
MonthViewScroll (monthP, winUp);
handled = true;
EventInCurrentView = true;
}
else if (event->data.keyDown.chr == vchrPageDown)
{
monthP = MonthViewGetMonthPtr ();
MonthViewScroll (monthP, winDown);
handled = true;
EventInCurrentView = true;
}
}
}
else if (event->eType == ctlSelectEvent)
{
switch (event->data.ctlSelect.controlID)
{
case MonthDayViewButton:
case MonthWeekViewButton:
case MonthAgendaViewButton:
case MonthMonthViewButton:
case MonthLunarViewButton:
if ( event->data.ctlSelect.controlID
!= pMonthViewButtonID)
{
monthP = MonthViewGetMonthPtr ();
Date.year = monthP->year - firstYear;
Date.month = monthP->month;
daysInMonth = DaysInMonth (Date.month, Date.year + firstYear);
Date.day = min (Date.day, daysInMonth);
}
break;
}
switch (event->data.ctlSelect.controlID)
{
case MonthGoToButton:
MonthViewGotoDate ();
handled = true;
break;
case MonthDayViewButton:
FrmGotoForm (DayView);
handled = true;
break;
case MonthWeekViewButton:
FrmGotoForm (WeekView);
handled = true;
break;
case MonthMonthViewButton:
if (pMonthViewButtonID != MonthMonthViewButton)
{
DateSetMonthView(MonthMonthViewButton);
FrmGotoForm (MonthView);
handled = true;
}
break;
case MonthLunarViewButton:
if (pMonthViewButtonID != MonthLunarViewButton)
{
DateSetMonthView(MonthLunarViewButton);
FrmGotoForm (MonthView);
handled = true;
}
break;
case MonthAgendaViewButton:
FrmGotoForm (AgendaView);
handled = true;
break;
}
}
else if (event->eType == ctlRepeatEvent)
{
switch (event->data.ctlRepeat.controlID)
{
case MonthPrevButton:
monthP = MonthViewGetMonthPtr ();
MonthViewScroll (monthP, winUp);
break;
case MonthNextButton:
monthP = MonthViewGetMonthPtr ();
MonthViewScroll (monthP, winDown);
break;
}
}
else if (event->eType == menuEvent)
{
handled = MonthViewDoCommand (event->data.menu.itemID);
}
else if (event->eType == frmOpenEvent)
{
frm = FrmGetFormPtr (MonthView);
MonthViewInit (frm);
FrmDrawForm (frm);
monthP = MonthViewGetMonthPtr ();
DrawMonth (monthP, drawDaySelected);
EventInCurrentView = false;
handled = true;
}
else if (event->eType == frmUpdateEvent)
{
frm = FrmGetFormPtr (MonthView);
FrmDrawForm (frm);
monthP = MonthViewGetMonthPtr ();
DrawMonth (monthP, drawDaySelected);
handled = true;
}
else if (event->eType == frmCloseEvent)
{
monthP = MonthViewGetMonthPtr ();
if (monthP)
MemPtrFree (monthP);
}
else if (event->eType == frmTitleEnterEvent)
{
Boolean penDown;
Coord x, y;
//Wait 1/20 sec before displaying time, to avoid flicker before menu pops up
SysTaskDelay (timeDisplayWaitTicks);
PenGetPoint (&x, &y, &penDown);
if (penDown)
{
// If the pen is in the title toggle between the current date
// and the current time.
if (TimeDisplayed)
MonthViewHideTime (true);
else
MonthViewShowTime ();
}
}
else if (event->eType == nilEvent)
{
MonthViewHideTime (false);
}
return (handled);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -