// PointSense Calendar Widgets for Point Sense Suite // // Design by BlueOcean, community.pointui.com // // Any distribute please notify me //All using class included in ClockWidgets, no need add duplication using PushButton; class CalendarWidget : Widget { //settings String skinPath; int firstday; int appointmentDays, checkBusy; String style; Control *c; RegistryNotification timeNotify; DateTime dtDay; #region widget must have void WriteAttribute(XmlNode root) { root.SetChildValue("name", "calendar"); root.SetChildValue("id", ID); root.SetChildValue("skin", skinPath); root.SetChildValue("firstday", firstday); root.SetChildValue("appointmentdays", appointmentDays); root.SetChildValue("checkbusy", checkBusy); } void NewWidget(XmlNode attr, String newid, String fn, int x, int y) { attr.SetChildValue("name", "calendar"); attr.SetChildValue("id", newid); attr.SetChildValue("skin", fn); attr.SetChildValue("firstday", 0); attr.SetChildValue("appointmentdays", 1); attr.SetChildValue("checkbusy", 0); //If no first setting OnChanged(); FlowStack.ReturnToStart(); } #endregion void Load() { //call inherited Widget_Load(); Attribute.GetChildValue("skin", skinPath); Attribute.GetChildValue("firstday", firstday); Attribute.GetChildValue("appointmentdays", appointmentDays); Attribute.GetChildValue("checkbusy", checkBusy); LoadCalendarSetting(); if (style == "ramappointment") { dtDay.Now(); c.LoadBirthdays(); timeNotify.OnNotify = timeNotify_OnNotify; } } void LoadCalendarSetting() { XmlNode root, Setting; root.LoadFromFile(homePath + "Calendar\\" + skinPath + "\\setting.xml"); //lblDebug.SetText(skinPath); root.FindNode("theme", Setting); Setting.GetChildValue("style", style); if (style == "month") { MonthControl monthCalendar; monthCalendar.path = homePath + "Calendar\\" + skinPath + "\\"; monthCalendar.firstday = firstday; monthCalendar.widget_OnClickHold = widget_OnClickHold; Controls.Add(monthCalendar); c = monthCalendar; } else if (style == "appointment") { AppointmentControl apptCalendar; apptCalendar.path = homePath + "Calendar\\" + skinPath + "\\"; apptCalendar.appDays = appointmentDays; apptCalendar.widget_OnClickHold = widget_OnClickHold; Controls.Add(apptCalendar); c = apptCalendar; } else if (style == "ramappointment") { RamAppointmentControl apptCalendar; apptCalendar.path = homePath + "Calendar\\" + skinPath + "\\"; apptCalendar.appDays = appointmentDays; apptCalendar.widget_OnClickHold = widget_OnClickHold; Controls.Add(apptCalendar); c = apptCalendar; } } void Layout() { Widget_Layout(); SetWidthHeight(c.GetWidth(), c.GetHeight()); width = c.GetWidth(); height = c.GetHeight(); c.SetBounds(0, 0); } #region events void Activated() { if (style == "month") { if (checkBusy == 1) { c.CheckAppointment(); } c.CheckToday(); } else if (style == "appointment") { c.Activated(); } else if (style == "ramappointment") { c.Activated(); timeNotify.Start("HKLM\\System\\State\\DateTime", "Time"); } } void Deactivated() { if (style == "ramappointment") { timeNotify.Stop(); } } void timeNotify_OnNotify() { if (style == "ramappointment") { DateTime dt; dt.Now(); if (!dt.IsSameDay(dtDay)) { c.LoadBirthdays(); c.Activated(); dtDay = dt; } else if ((c.dtAppt != c.dtEmpty) && (dt >= c.dtAppt)) { c.LoadInfos(); } } } void widget_OnClickHold() { OnClickHold(this); } void ShowSetting() { if (style == "month") { MonthSettingScreen s; s.currentFirstDay = firstday; s.checkBusy = checkBusy; s.OnCheckBusyChanged = SettingScreen_OnCheckBusyChanged; s.OnFirstDayChanged = SettingScreen_OnFirstDayChanged; FlowStack.Branch(s); }else if (style == "appointment") { AppointmentSettingScreen s; s.OnDaysChanged = SettingScreen_OnDaysChanged; String a = appointmentDays; s.SetSelectedItemID(a); FlowStack.Branch(s); }else if (style == "ramappointment") { RamAppointmentSettingScreen s; s.OnDaysChanged = SettingScreen_OnDaysChanged; String a = appointmentDays; s.SetSelectedItemID(a); FlowStack.Branch(s); } } void SettingScreen_OnFirstDayChanged() { if (firstday == 0) { firstday = 1; } else { firstday = 0; } if (style == "month") { c.firstday = firstday; c.ReloadCalendar(); } OnChanged(); } void SettingScreen_OnDaysChanged(ListItem li) { appointmentDays = li.Attributes.Item("ID"); if (style == "appointment") { c.appDays = appointmentDays; c.Activated(); } else if (style == "ramappointment") { c.appDays = appointmentDays; c.LoadBirthdays(); c.Activated(); } OnChanged(); } void SettingScreen_OnCheckBusyChanged() { if (checkBusy == 0) { checkBusy = 1; } else { checkBusy = 0; } OnChanged(); } #endregion } #region MonthCalendar class MonthControl : GestureControl { //Include daynameBar and Cell, not include TopBG and Bottom BG. int firstday; //0: Mon, 1: Sun String path; Image imgTopBG, imgBottomBG, imgDayNameBG; Surface surCellSelectedBG, surCellBG, surTodayBG; int Month, Year; Control calendarCells; DateTime CurrentDate, StartDate, EndDate; Label lblMonth; PushButton butPrevious, butNext; int x, y, w, h; int todayIndex; Event OnCellClick; Event OnCellClickHold; Event widget_OnClickHold; //Label lblDebug; void Load() { SetTabStop(true); surTodayBG.LoadFromFile(path + "Calendar.Today.Cell.Background.jif"); surCellBG.LoadFromFile(path + "Calendar.Cell.Background.jif"); surCellSelectedBG.LoadFromFile(path + "Calendar.Cell.Selected.Background.jif"); x = 0 + 3; y = 0; imgTopBG.Surface.LoadFromFile(path + "Calendar.Top.Background.jif"); imgTopBG.SetTabStop(true); imgTopBG.OnClick=imgTopBG_OnClick; imgTopBG.OnClickHold = imgTopBG_OnClickHold; Controls.Add(imgTopBG); imgTopBG.SetBounds(x, y); y += imgTopBG.GetHeight(); imgDayNameBG.Surface.LoadFromFile(path + "Calendar.Day.Name.Background.jif"); Controls.Add(imgDayNameBG); imgDayNameBG.SetBounds(x, y); w = imgDayNameBG.GetWidth() / 7; h = imgDayNameBG.GetHeight(); for (int i = 0; i < 7; i++) { Label lblDayName; lblDayName.SetFont("Font.Small"); lblDayName.SetAlign("Center", "Center"); imgDayNameBG.Controls.Add(lblDayName); lblDayName.SetBounds(x + (i * w), 0, w, h); } Controls.Add(calendarCells); w = surCellBG.GetWidth(); h = surCellBG.GetHeight(); for (int i = 0; i < 6; i++) { for (int j = 0; j < 7; j++) { CalendarCell cell; cell.OnClick = Cell_OnClick; cell.OnClickHold = Cell_OnClickHold; cell.path = path; cell.Image = surCellBG; cell.ImageSelected = surCellSelectedBG; calendarCells.Controls.Add(cell); cell.SetBounds((j * w),(i * h)); } } w = 7 * surCellBG.GetWidth(); h = 6 * surCellBG.GetHeight(); calendarCells.SetWidthHeight(w, h); y += imgDayNameBG.GetHeight(); calendarCells.SetBounds(x, y); imgBottomBG.Surface.LoadFromFile(path + "Calendar.Bottom.Background.jif"); Controls.Add(imgBottomBG); y += calendarCells.GetHeight(); imgBottomBG.SetBounds(x, y); w = imgTopBG.GetWidth(); h = imgTopBG.GetHeight() + imgDayNameBG.GetHeight() + calendarCells.GetHeight() + imgBottomBG.GetHeight(); SetWidthHeight(w + 6, h); lblMonth.SetAlign("Left", "Center"); lblMonth.SetFont("Font.Title"); imgTopBG.Controls.Add(lblMonth); x = Device.AutoScaleValue(40); lblMonth.SetBounds(x,0,imgTopBG.GetWidth(), imgTopBG.GetHeight()); butPrevious.Image.LoadFromFile(path + "Button.Previous.jif"); butPrevious.ImageSelected.LoadFromFile(path + "Button.Previous.jif"); butPrevious.ImagePushed.LoadFromFile(path + "Button.Previous.Selected.jif"); butPrevious.OnClick = butPrevious_OnClick; imgTopBG.Controls.Add(butPrevious); butNext.Image.LoadFromFile(path + "Button.Next.jif"); butNext.ImageSelected.LoadFromFile(path + "Button.Next.jif"); butNext.ImagePushed.LoadFromFile(path + "Button.Next.Selected.jif"); butNext.OnClick = butNext_OnClick; imgTopBG.Controls.Add(butNext); x = imgTopBG.GetWidth() - (butNext.GetWidth() + Device.AutoScaleValue(5)); y = (imgTopBG.GetHeight() - butNext.GetHeight()) / 2; y += Device.AutoScaleValue(3); butNext.SetBounds(x, y); x -= butNext.GetWidth(); butPrevious.SetBounds(x, y); CurrentDate.Now(); ReloadCalendar(); } void ShowMonth() { String s; s = CurrentDate.ToString("MMMM yyyy"); lblMonth.SetText(s); } void CheckToday() { CalendarCell* cellPtr; DateTime dt; dt.Now(); cellPtr = calendarCells.Controls.Item(todayIndex); if (dt.IsSameDay(cellPtr.day)) { return; } cellPtr.IsToday = false; cellPtr.Image = surCellBG; for (int k = 0; k < 42; k++) { cellPtr = calendarCells.Controls.Item(k); if (dt.IsSameDay(cellPtr.day)) { if (!cellPtr.IsToday) { cellPtr.IsToday = true; cellPtr.Image = surTodayBG; todayIndex = k; return; } } } } #region event void MouseMoveUp() { int d; d = CurrentDate.GetDaysInMonth(CurrentDate.GetYear(), CurrentDate.GetMonth()); d = 0 - d; CurrentDate.AddDays(d); ReloadCalendar(); } void MouseMoveDown() { int d; d = CurrentDate.GetDaysInMonth(CurrentDate.GetYear(), CurrentDate.GetMonth()); CurrentDate.AddDays(d); ReloadCalendar(); } void Cell_OnClick(CalendarCell* cellPtr) { AppointmentScreen s; s.CurrentDate = cellPtr.day; //s.OnDone = AppointmentScreen_OnDone; FlowStack.Branch(s); } void Cell_OnClickHold(CalendarCell* cellPtr) { widget_OnClickHold(); } void imgTopBG_OnClickHold() { widget_OnClickHold(); } void butPrevious_OnClick(Control sender, int x, int y) { int d; d = CurrentDate.GetDaysInMonth(CurrentDate.GetYear(), CurrentDate.GetMonth()); d = 0 - d; CurrentDate.AddDays(d); ReloadCalendar(); } void butNext_OnClick(Control sender, int x, int y) { int d; d = CurrentDate.GetDaysInMonth(CurrentDate.GetYear(), CurrentDate.GetMonth()); CurrentDate.AddDays(d); ReloadCalendar(); } void imgTopBG_OnClick(Control sender, int x, int y) { CurrentDate.Now(); ReloadCalendar(); } #endregion void ReloadCalendar() { int i, k, day; String s; DateTime dt; DateTime dtnow; ShowMonth(); dtnow.Now(); dt = CurrentDate; i = dt.GetDay(); i -= 1; i = 0 - i; dt.AddDays(i); i = dt.GetDayOfWeek(); i = 0 - i; if (firstday==1) { i -= 1; } dt.AddDays(i); StartDate = dt; Label* lblDayName; CalendarCell* cellPtr; for (int k = 0; k < 42; k++) { cellPtr = calendarCells.Controls.Item(k); cellPtr.SetDate(dt); if (dt.GetMonth() != CurrentDate.GetMonth()) { cellPtr.SetActive(false); } else { cellPtr.SetActive(true); } if (dt.IsSameDay(dtnow)) { if (!cellPtr.IsToday) { cellPtr.IsToday = true; cellPtr.Image = surTodayBG; todayIndex = k; } } else { if (cellPtr.IsToday) { cellPtr.IsToday = false; cellPtr.Image = surCellBG; } } if (k < 7) { s = dt.ToString("dddd"); s = s.SubString(0, 3); lblDayName = imgDayNameBG.Controls.Item(k); lblDayName.SetText(s); } dt.AddDays(1); } //dt.AddDays(-1); EndDate = dt; StartDate.SetStartOfDay(); CheckAppointment(); } void CheckAppointment() { DataTable tbl; DateTime dt, dtStart, dtEnd; int i, k; CalendarCell* cellPtr; i = 0; while (i < 42) { cellPtr = calendarCells.Controls.Item(i); cellPtr.SetBusy(false); i++; } dt = CurrentDate; Appointments.GetAppointments(tbl); //tbl.SetMaxItems(42); tbl.SetSort("Start"); String filter; filter = "[End] >= <{Now} AND [Start] < <{End}"; String tmp; float f; f = StartDate.ToVariantTime(); tmp = f.ToString("%.5f"); filter.Replace("{Now}", tmp); //dt.AddDays(1); f = EndDate.ToVariantTime(); f.Trunc(); tmp = f.ToString("%.0f"); filter.Replace("{End}", tmp); k = 0; tbl.SetRestriction(filter); while (tbl.MoveNext() && k < 42) { tbl.GetValue("End", dtEnd); tbl.GetValue("Start", dtStart); dtEnd.AddDays(1); dtEnd.SetStartOfDay(); dtStart.SetStartOfDay(); i = k; cellPtr = calendarCells.Controls.Item(i); //if (dtStart >= cellPtr.day) //{ while (i < 42) { cellPtr = calendarCells.Controls.Item(i); if (dtEnd >= cellPtr.day) { if ((cellPtr.day >= dtStart) && (dtEnd >= cellPtr.day)) { cellPtr.SetBusy(true); k = i + 1; } } else { break; } i++; } //while i<42 } //while tbl } } #endregion #region CalendarDayCell class CalendarCell : Button { DateTime day; Label lblDay; bool IsToday; bool IsBusy; bool IsActive; Image imgIndicatorIcon; String path; void Load() { lblDay.SetFont("Font.Normal"); lblDay.SetAlign("Center", "Center"); imgIndicatorIcon.Surface.LoadFromFile(path + "Calendar.Indicator.jif"); Controls.Add(imgIndicatorIcon); Controls.Add(lblDay); int x, y, w, h; w = Image.GetWidth(); h = Image.GetHeight(); lblDay.SetBounds(0, 0, w, h); x = w - imgIndicatorIcon.GetWidth(); y = 0; imgIndicatorIcon.SetBounds(x, y); } void SetDate(DateTime dt) { String s; day = dt; s = day.GetDay(); lblDay.SetText(s); } void SetBusy(bool a) { IsBusy = a; imgIndicatorIcon.SetVisible(IsBusy); } ////////////////////////////////// /* void SetActive(bool a) { IsActive = a; if (IsActive) { if (day.GetDayOfWeek() < 5) { lblDay.SetColor("White"); } else if(day.Get { lblDay.SetColor("LightGray"); } } else { lblDay.SetColor("Gray"); } } */ ////////////////////////////////// void SetActive(bool a) { IsActive = a; int tmp_day; if (IsActive) { tmp_day = day.GetDayOfWeek(); if (tmp_day < 5) { lblDay.SetColor("White"); } else if(tmp_day ==5) { lblDay.SetColor("Blue"); } else { lblDay.SetColor("Red"); } } else { lblDay.SetColor("Gray"); } } ////////////////////////////////// /* void Layout() { w = GetWidth(); h = GetHeight(); lblDay.SetBounds(0, 0, w, h); if (IsBusy) { imgIndicatorIcon.Surface = imgIndicator; imgIndicatorIcon.AutoSize(); x = w - imgIndicatorIcon.GetWidth(); y = 0; imgIndicatorIcon.SetBounds(x, y); } }*/ } #endregion DayCell #region appointmentCalendar class AppointmentControl : Control { Image imgLeftBG, imgRightBG, imgIndicator, imgDDay; // Edited CustomBitmapLabel lblDate; Label lblMonth, lblApptDate, lblApptTime, lblApptSubject; String path; int x, y, w, h, padding; int ObjectID; int appDays; RegistryNotification DDay_Day, DDay_Text, DDay_From; // Add Label lblDDay_Day, lblDDay_Text, lblDDay_From; // Add Event widget_OnClickHold; void Load() { // 디데이 위젯 사용시 DDay_Start.mscr 실행 Process.Start("{ProgramFiles}\\MortScript\\MortScript.exe", "\"\\Storage Card\\Program Files\\Home2\\PointSense\\Widgets\\Calendar\\Appointment\\DDay_Start.mscr\""); imgLeftBG.Surface.LoadFromFile(path + "Calendar.Left.Background.jif"); imgLeftBG.SetTabStop(true); imgLeftBG.OnClickHold = imgLeftBG_OnClickHold; imgLeftBG.OnClick = imgLeftBG_OnClick; Controls.Add(imgLeftBG); imgRightBG.Surface.LoadFromFile(path + "Calendar.Right.Background.jif"); imgRightBG.SetTabStop(true); imgRightBG.OnClick = imgRightBG_OnClick; imgRightBG.OnClickHold = imgLeftBG_OnClickHold; Controls.Add(imgRightBG); imgIndicator.Surface.LoadFromFile(path + "Calendar.Indicator.Normal.jif"); imgRightBG.Controls.Add(imgIndicator); imgDDay.Surface.LoadFromFile(path + "DDay.Background.jif"); imgDDay.SetTabStop(true); imgDDay.OnClick = imgDDay_OnClick; imgDDay.OnClickHold = imgLeftBG_OnClickHold; Controls.Add(imgDDay); imgLeftBG.SetBounds(0, 0); y = imgLeftBG.GetHeight(); imgDDay.SetBounds(0, y + 1); x = imgLeftBG.GetWidth(); imgRightBG.SetBounds(x, 0); y = (imgRightBG.GetHeight() - imgIndicator.GetHeight()) / 2; imgIndicator.SetBounds(0, y); lblDate.FilePrefix="{Application}\\PointSense\\Theme\\b"; lblDate.SetText("31"); imgLeftBG.Controls.Add(lblDate); // Add x = Device.AutoScaleValue(17); y = Device.AutoScaleValue(24); ////////////////////////////// lblDate.SetBounds(x, y, imgLeftBG.GetWidth(), imgLeftBG.GetHeight()); lblMonth.SetAlign("Center","Top"); lblMonth.SetFont("Font.Small"); y = Device.AutoScaleValue(8); imgLeftBG.Controls.Add(lblMonth); lblMonth.SetBounds(0, y, imgLeftBG.GetWidth(), lblMonth.GetFontHeight()); w = imgRightBG.GetWidth() - (2 * padding); padding = Device.AutoScaleValue(4); // Edited y=padding; x = padding + imgIndicator.GetWidth(); lblApptDate.SetFont("Font.Medium"); // Edited imgRightBG.Controls.Add(lblApptDate); lblApptDate.SetBounds(x, y, w, lblApptDate.GetFontHeight()); lblApptTime.SetFont("Font.Normal"); // Edited imgRightBG.Controls.Add(lblApptTime); y += lblApptDate.GetFontHeight(); lblApptTime.SetBounds(x, y, w, lblApptTime.GetFontHeight()); lblApptSubject.SetFont("Font.Medium"); // Edited imgRightBG.Controls.Add(lblApptSubject); y += lblApptTime.GetFontHeight(); lblApptSubject.SetBounds(x, y, w, lblApptSubject.GetFontHeight()); w = imgLeftBG.GetWidth() + imgRightBG.GetWidth(); h = imgLeftBG.GetHeight() + imgDDay.GetHeight() + 1; SetWidthHeight(w,h); DDay_Day.OnNotify = DDay_Day_OnNotify; DDay_Text.OnNotify = DDay_Text_OnNotify; DDay_From.OnNotify = DDay_From_OnNotify; lblDDay_Day.SetAlign("Center", "Center"); lblDDay_Day.SetFont("Font.Medium"); imgDDay.Controls.Add(lblDDay_Day); lblDDay_Text.SetAlign("Left", "Center"); lblDDay_Text.SetFont("Font.Medium"); imgDDay.Controls.Add(lblDDay_Text); lblDDay_From.SetAlign("Right", "Center"); lblDDay_From.SetFont("Font.Small"); imgDDay.Controls.Add(lblDDay_From); h = imgDDay.GetHeight(); x = 5; lblDDay_Day.SetBounds(x,0,95,h); x = x + 95 + 5; lblDDay_Text.SetBounds(x,0,160,h); x = x + 160; lblDDay_From.SetBounds(x,0,160,h); StartUpdates(); } void Activated() { DateTime dt; dt.Now(); String s; s = dt.GetDay(); // Edited if(s.GetLength() == 1){ s = "0" + s; } lblDate.SetText(s); /*if (s.GetLength() >= 2) { x = Device.AutoScaleValue(15); } else { x = Device.AutoScaleValue(22); } y = Device.AutoScaleValue(22); lblDate.SetBounds(x, y, imgLeftBG.GetWidth(), imgLeftBG.GetHeight()); */ s = dt.ToString("MMM"); lblMonth.SetText(s); LoadAppointment(); } void LoadAppointment() { DataTable tbl; DateTime dt; dt.Now(); Appointments.GetAppointments(tbl); tbl.SetMaxItems(1); tbl.SetSort("Start"); String filter; filter = "[End] >= <{Now} AND [Start] < <{End}"; String tmp; float f; f = dt.ToVariantTime(); tmp = f.ToString("%.5f"); filter.Replace("{Now}", tmp); dt.AddDays(appDays); f = dt.ToVariantTime(); f.Trunc(); tmp = f.ToString("%.0f"); filter.Replace("{End}", tmp); tbl.SetRestriction(filter); dt.Now(); if (tbl.MoveNext()) { String s, s1; // Edited DateTime dtStart, dtEnd; bool isAllDay; tbl.GetValue("ObjectID", ObjectID); tbl.GetValue("Start", dtStart); tbl.GetValue("AllDayEvent", isAllDay); tbl.GetValue("End", dtEnd); tbl.GetValue("Location", s1); // Add imgIndicator.SetVisible(true); if ((dt >= dtStart) && (dt <= dtEnd)) { imgIndicator.Surface.LoadFromFile(path + "Calendar.Indicator.Expired.jif"); } else { imgIndicator.Surface.LoadFromFile(path + "Calendar.Indicator.Normal.jif"); } if (dtStart.IsSameDay(dt)||(dtStart