-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMonthWindow.cpp
More file actions
112 lines (91 loc) · 2.42 KB
/
MonthWindow.cpp
File metadata and controls
112 lines (91 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Calendar Control version 2.5
// by Al.V. Sarikov.
// Kherson, Ukraine, 2006.
// E-mail: avix@ukrpost.net.
// Home page: http://avix.pp.ru.
// Control which allows to work with dates:
// enter date to text field and choose it from calendar.
// Distributed under BSD license (see LICENSE file).
#include <Point.h>
#include <Screen.h>
#include <String.h>
#include <StringView.h>
#include <Window.h>
#include "MonthView.cpp"
class MonthWindow: public BWindow
{
public:
MonthWindow(BPoint LT, BMessenger *msng, int day, int month, int year,
int first_year, int last_year);
virtual void MessageReceived(BMessage *msg);
virtual bool QuitRequested(void);
virtual void WindowActivated(bool active);
private:
MonthView *myMonthView;
BMessenger *messenger;
int first_year;
int last_year;
};
MonthWindow::MonthWindow(BPoint LT, BMessenger *msng, int day, int month, int year, int first_year, int last_year)
:BWindow(BRect(LT,BPoint(LT.x+200,LT.y+200)),"MonthWindowAViX",
B_BORDERED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_MOVABLE|B_AVOID_FOCUS)
{
this->first_year=first_year;
this->last_year=last_year;
myMonthView = new MonthView(day, month, year, first_year, last_year);
AddChild(myMonthView);
myMonthView->MakeFocus(true);
messenger = msng;
BRect screenFrame = BScreen(this).Frame();
if(LT.x < 0)
LT.x = 0;
if(LT.x > screenFrame.right - Bounds().Width())
LT.x = screenFrame.right - Bounds().Width();
if(LT.y > screenFrame.bottom - Bounds().Height())
LT.y = screenFrame.bottom - Bounds().Height();
MoveTo(LT);
Show();
}
void MonthWindow::MessageReceived(BMessage *msg)
{
if(msg->what=='MVME')
{
// Is date correct?
int32 day, month, year;
if(msg->FindInt32("day",&day)!=B_OK) return;
if(msg->FindInt32("month",&month)!=B_OK) return;
if(msg->FindInt32("year",&year)!=B_OK) return;
if(year<first_year || year>last_year) return;
if(month<1 || month>12) return;
int32 tmp;
tmp=31;
if(month==4 || month==6 || month==9 || month==11)
tmp=30;
else if(month==2)
{
if(year%4==0)
{
if(year%100==0 && year%400!=0)
tmp=28;
else
tmp=29;
}
else
tmp=28;
}
if(day<1 || day>tmp) return;
messenger->SendMessage(msg);
Quit();
}
else
BWindow::MessageReceived(msg);
}
bool MonthWindow::QuitRequested(void)
{
return true;
}
void MonthWindow::WindowActivated(bool active)
{
// exit if unfocused
if(!active) Quit();
}