//Window procedure for year/month window.
static DWORD MonthWndProc(HANDLE hWnd,UINT message,WORD wParam,DWORD lParam)
{
    static int month   = 5;

    switch(message)
    {
    case WM_CREATE:
        DrawButton(hWnd,ID_PREV,ID_NEXT);
        break;
    case WM_DRAW:
        DrawMonth(hWnd,month);
        break;
    case WM_COMMAND:
        switch(wParam)
        {
        case ID_PREV:
            if(month == 1)
            {
                month = 12;
            }
            else
            {
                month --;
            }
            break;
        case ID_NEXT:
            if(month == 12)
            {
                month = 1;
            }
            else
            {
                month ++;
            }
            break;
        default:
            break;
        }
        DrawMonth(hWnd,month);
        break;
    case WM_SETMONTH:
        break;
    default:
        break;
    }
    return DefWindowProc(hWnd,message,wParam,lParam);
}
void OnCalendarPaint(HWND hwndDlg)
{
	//refresh 
	PAINTSTRUCT ps;
	BeginPaint(hwndDlg, &ps);			
	DrawMonth(hwndDlg,ps.hdc); 
	EndPaint(hwndDlg, &ps);
	return;
}
Exemple #3
0
void MonthWindowView::MouseUp(BPoint p)
{
 if(!MousePressed) return;
 
 if(cursorPressed.Contains(p))
 {
  // here it is needed to send dayPressed, cyear, cmonth
  // to window and leave
  BMessage *msg=new BMessage('MVME');
  msg->AddInt32("day",dayPressed);
  msg->AddInt32("month",cmonth);
  msg->AddInt32("year",cyear);
  Window()->PostMessage(msg);
  
  // added to draw a box around selected date
  NewMonth = true;
  cday = dayPressed;
  DrawMonth();
 }
 else MousePressed=false;
}
Exemple #4
0
void MonthWindowView::MessageReceived(BMessage *msg)
{
 switch(msg->what)
 {
  case 'YEA0': // year before
  {
   if(cyear<=first_year) break;
   cyear--;
   NewMonth=true;
   BString s("");
   if(cyear<10) s.Append("000");
   else if(cyear<100) s.Append("00");
   else if(cyear<1000) s.Append("0");
   s<<cyear;
   yearStringView->SetText(s.String());
   
   if(cmonth==2) if(cday==29) // one can do simplier: if cday==29, then make
                              // cday=28, because two leap years one after other can't be
   {
    if(cyear%4!=0) cday=28;
    else if(cyear%100==0 && cyear%400!=0) cday=28;
   }
   
   DrawMonth();
   break;
  }
  case 'YEA1': // year after
  {
   if(cyear>=last_year) break;
   cyear++;
   NewMonth=true;
   BString s("");
   if(cyear<10) s.Append("000");
   else if(cyear<100) s.Append("00");
   else if(cyear<1000) s.Append("0");
   s<<cyear;
   yearStringView->SetText(s.String());
   
   if(cmonth==2) if(cday==29)
   {
    if(cyear%4!=0) cday=28;
    else if(cyear%100==0 && cyear%400!=0) cday=28;
   }
   
   DrawMonth();
   break;
  }
  case 'MON0': // month before
  {
   if(cmonth>1) cmonth--;
   else if(cyear>first_year)
   {
    cmonth=12;
    cyear--;
    
    BString s("");
    if(cyear<10) s.Append("000");
    else if(cyear<100) s.Append("00");
    else if(cyear<1000) s.Append("0");
    s<<cyear;
    yearStringView->SetText(s.String());
   }
   else break; // nothing is changed
   
   NewMonth=true;
   monthStringView->SetText(monthNames[cmonth-1]);
   
   if(cmonth==2)
   {
    int tmpday=28;
    if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) tmpday=29;
    if(cday>tmpday) cday=tmpday;
   }
   else if(cday>monthDays[cmonth-1]) cday=monthDays[cmonth-1];
   
   DrawMonth();
   break;
  }
  case 'MON1': // month after
  {
   if(cmonth<12) cmonth++;
   else if(cyear<last_year)
   {
    cmonth=1;
    cyear++;
    
    BString s("");
    if(cyear<10) s.Append("000");
    else if(cyear<100) s.Append("00");
    else if(cyear<1000) s.Append("0");
    s<<cyear;
    yearStringView->SetText(s.String());
   }
   else break; // nothing is changed
   
   NewMonth=true;
   monthStringView->SetText(monthNames[cmonth-1]);
   
   if(cmonth==2)
   {
    int tmpday=28;
    if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) tmpday=29;
    if(cday>tmpday) cday=tmpday;
   }
   else if(cday>monthDays[cmonth-1]) cday=monthDays[cmonth-1];
   
   DrawMonth();
   break;
  }
  case 'TODA': // to place to today's date
  {
   if(tyear<first_year || tyear>last_year) break;
   
   NewMonth=true;
   
   cyear=tyear;
   cmonth=tmonth;
   cday=tday;
   
   BString s("");
   if(cyear<10) s.Append("000");
   else if(cyear<100) s.Append("00");
   else if(cyear<1000) s.Append("0");
   s<<cyear;
   yearStringView->SetText(s.String());
   monthStringView->SetText(monthNames[cmonth-1]);
   
   DrawMonth();
   break;
  }
  default:
   BView::MessageReceived(msg);
 }
}
Exemple #5
0
void MonthWindowView::AttachedToWindow(void)
{
 SetFont(be_plain_font);
 
 SetViewColor(VIEW_COLOR);
 
 // Calculate size of cell needed for number of day of month
 font_height h;
 be_plain_font->GetHeight(&h);
 h_cell=(int)(h.ascent+h.descent+h.leading+6);
 w_cell=StringWidth("4")*4;
 
 

#ifdef __LANG_RUSSIAN
 
 BString s("");
 s<<tday;
 s.Append(" ");
 switch(tmonth)
 {
  case 1:
  {
   s.Append("января ");
   break;
  }
  case 2:
  {
   s.Append("февраля ");
   break;
  }
  case 3:
  {
   s.Append("марта ");
   break;
  }
  case 4:
  {
   s.Append("апреля ");
   break;
  }
  case 5:
  {
   s.Append("мая ");
   break;
  }
  case 6:
  {
   s.Append("июня ");
   break;
  }
  case 7:
  {
   s.Append("июля ");
   break;
  }
  case 8:
  {
   s.Append("августа ");
   break;
  }
  case 9:
  {
   s.Append("сентября ");
   break;
  }
  case 10:
  {
   s.Append("октября ");
   break;
  }
  case 11:
  {
   s.Append("ноября ");
   break;
  }
  case 12:
  {
   s.Append("декабря ");
   break;
  }
 }
 s<<tyear;
 s.Append(" г.");

#else // localized, english and french
 
 BString s("");
 s<<tday;
 s.Append(" ");
 s.Append(monthNames[tmonth-1]);
 s.Append(" ");
 s<<tyear;

#endif
 
 msng=new BMessenger(this);
 todayStringView=new MouseSenseStringView(new BMessage('TODA'), msng,
                                          BRect(10,10,100,100),"todayMStringViewAViX",
                                          s.String());
 AddChild(todayStringView);
 todayStringView->ResizeToPreferred();
 todayStringView->SetViewColor(VIEW_COLOR);
 
 monthStringView=new BStringView(BRect(10,10,100,100),"monthStringViewAViX",
                                 monthNames[8]);
 monthStringView->SetAlignment(B_ALIGN_CENTER);
 AddChild(monthStringView);
 monthStringView->ResizeToPreferred();
 monthStringView->SetText(monthNames[cmonth-1]);
 monthStringView->SetViewColor(VIEW_COLOR);
 
 s.SetTo("");
 if(cyear<10) s.Append("000");
 else if(cyear<100) s.Append("00");
 else if(cyear<1000) s.Append("0");
 s<<cyear;
 
 yearStringView=new BStringView(BRect(10,10,100,100),"yearStringViewAViX",
                                "0000");
 AddChild(yearStringView);
 yearStringView->ResizeToPreferred();
 yearStringView->SetText(s.String());
 yearStringView->SetViewColor(VIEW_COLOR);
 
 ResizeTo(w_cell*7+1,h_cell*7+3+16+yearStringView->Bounds().bottom+todayStringView->Bounds().bottom);
 Window()->ResizeTo(Bounds().right, Bounds().bottom);
 
 yearMStringView[0]=new MouseSenseStringView(new BMessage('YEA0'),msng,
                                             BRect(10,10,100,100),
                                             "yearMStringViewAViX0",
                                             "<<");
 AddChild(yearMStringView[0]);
 yearMStringView[0]->ResizeToPreferred();
 yearMStringView[0]->SetViewColor(VIEW_COLOR);
 
 yearMStringView[1]=new MouseSenseStringView(new BMessage('YEA1'),msng,
                                             BRect(10,10,100,100),
                                             "yearMStringViewAViX1",
                                             ">>");
 AddChild(yearMStringView[1]);
 yearMStringView[1]->ResizeToPreferred();
 yearMStringView[1]->SetViewColor(VIEW_COLOR);
 
 monthMStringView[0]=new MouseSenseStringView(new BMessage('MON0'),msng,
                                              BRect(10,10,100,100),
                                              "monthMStringViewAViX0",
                                              "<<");
 AddChild(monthMStringView[0]);
 monthMStringView[0]->ResizeToPreferred();
 monthMStringView[0]->SetViewColor(VIEW_COLOR);
 
 monthMStringView[1]=new MouseSenseStringView(new BMessage('MON1'),msng,
                                              BRect(10,10,100,100),
                                              "monthMStringViewAViX1",
                                              ">>");
 AddChild(monthMStringView[1]);
 monthMStringView[1]->ResizeToPreferred();
 monthMStringView[1]->SetViewColor(VIEW_COLOR);
 
 todayStringView->MoveTo((Bounds().right-todayStringView->Bounds().right)/2,
                         Bounds().bottom-todayStringView->Bounds().bottom-2);
 if(tyear<first_year || tyear>last_year) todayStringView->SetHighColor(NOACTIVE_COLOR);
  
 yearMStringView[1]->MoveTo(Bounds().right-yearMStringView[1]->Bounds().right,5);
 yearStringView->MoveTo(yearMStringView[1]->Frame().left-yearStringView->Bounds().right,5);
 yearMStringView[0]->MoveTo(yearStringView->Frame().left-yearMStringView[0]->Bounds().right,5);
 
 
 monthStringView->MoveTo((yearMStringView[0]->Frame().left-monthStringView->Bounds().right)/2,5);
 monthMStringView[0]->MoveTo(monthStringView->Frame().left-monthMStringView[0]->Bounds().right,5);
 monthMStringView[1]->MoveTo(monthStringView->Frame().right,5);
 
 which_focused=2; // days of month
 
 
 Bmp=new BBitmap(BRect(Frame()),B_RGB32,true);
 BmpView=new BView(Bmp->Bounds(),"BV",0,B_WILL_DRAW);
 Bmp->AddChild(BmpView);
 
 Bmp->Lock();
 BmpView->SetHighColor(VIEW_COLOR);
 BmpView->FillRect(BmpView->Frame());
 
 BmpView->SetHighColor(LINE_COLOR);
 BmpView->StrokeLine(BPoint(3,todayStringView->Frame().top-5),
                     BPoint(Bounds().right-3,todayStringView->Frame().top-5));
 BmpView->StrokeLine(BPoint(3,yearStringView->Frame().bottom+2),
                     BPoint(Bounds().right-3,yearStringView->Frame().bottom+2));
 BmpView->SetHighColor(0,0,0,0);
 
 float y=yearStringView->Frame().bottom+h_cell;
 float x=0;
 for(int i=0;i<7;i++)
 {
  BmpView->DrawString(weekdayNames[i],BPoint(x+(w_cell-StringWidth(weekdayNames[i]))/2,y));
  x+=w_cell;
 }
 
 BmpView->Sync();
 Bmp->Unlock();
 DrawMonth();
}