* Reuse calendar from shared to have a bitmore advanced panel
while holding down the mouse over the date area in Deskbar. One probably needs to clean and rebuild Deskbar to get it... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27236 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,262 @@
|
|||||||
|
/*
|
||||||
|
* Copyright Karsten Heimrich, [email protected]. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#include "CalendarMenuWindow.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <Button.h>
|
||||||
|
#include <CalendarView.h>
|
||||||
|
#include <GridLayoutBuilder.h>
|
||||||
|
#include <GroupLayout.h>
|
||||||
|
#include <GroupLayoutBuilder.h>
|
||||||
|
#include <GroupView.h>
|
||||||
|
#include <Screen.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <StringView.h>
|
||||||
|
#include <SpaceLayoutItem.h>
|
||||||
|
|
||||||
|
|
||||||
|
using BPrivate::BCalendarView;
|
||||||
|
using BPrivate::B_LOCAL_TIME;
|
||||||
|
using BPrivate::B_WEEK_START_SUNDAY;
|
||||||
|
using BPrivate::B_WEEK_START_MONDAY;
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -- FlatButton
|
||||||
|
|
||||||
|
|
||||||
|
class FlatButton : public BButton {
|
||||||
|
public:
|
||||||
|
FlatButton(const BString& label, uint32 what)
|
||||||
|
: BButton(label.String(), new BMessage(what)) {}
|
||||||
|
virtual ~FlatButton() {}
|
||||||
|
|
||||||
|
virtual void Draw(BRect updateRect);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FlatButton::Draw(BRect updateRect)
|
||||||
|
{
|
||||||
|
updateRect = Bounds();
|
||||||
|
rgb_color highColor = HighColor();
|
||||||
|
|
||||||
|
SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
FillRect(updateRect);
|
||||||
|
|
||||||
|
font_height fh;
|
||||||
|
GetFontHeight(&fh);
|
||||||
|
|
||||||
|
const char* label = Label();
|
||||||
|
const float stringWidth = StringWidth(label);
|
||||||
|
const float x = (updateRect.right - stringWidth) / 2.0f;
|
||||||
|
const float labelY = updateRect.top
|
||||||
|
+ ((updateRect.Height() - fh.ascent - fh.descent) / 2.0f)
|
||||||
|
+ fh.ascent + 1.0f;
|
||||||
|
|
||||||
|
SetHighColor(highColor);
|
||||||
|
DrawString(label, BPoint(x, labelY));
|
||||||
|
|
||||||
|
if (IsFocus()) {
|
||||||
|
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
|
||||||
|
StrokeRect(updateRect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -- CalendarMenuWindow
|
||||||
|
|
||||||
|
|
||||||
|
enum {
|
||||||
|
kInvokationMessage,
|
||||||
|
kMonthDownMessage,
|
||||||
|
kMonthUpMessage,
|
||||||
|
kYearDownMessage,
|
||||||
|
kYearUpMessage
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
CalendarMenuWindow::CalendarMenuWindow(BPoint where, bool euroDate)
|
||||||
|
: BWindow(BRect(0.0, 0.0, 100.0, 130.0), "", B_BORDERED_WINDOW,
|
||||||
|
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | B_CLOSE_ON_ESCAPE),
|
||||||
|
fYearLabel(NULL),
|
||||||
|
fMonthLabel(NULL),
|
||||||
|
fCalendarView(NULL),
|
||||||
|
fSuppressFirstClose(true)
|
||||||
|
{
|
||||||
|
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
|
||||||
|
|
||||||
|
fYearLabel = new BStringView("year", "");
|
||||||
|
fYearLabel->SetFontSize(10.0);
|
||||||
|
|
||||||
|
fMonthLabel = new BStringView("month", "");
|
||||||
|
fMonthLabel->SetFontSize(10.0);
|
||||||
|
|
||||||
|
fCalendarView = new BCalendarView(Bounds(), "calendar",
|
||||||
|
euroDate ? B_WEEK_START_MONDAY : B_WEEK_START_SUNDAY, B_FOLLOW_ALL);
|
||||||
|
fCalendarView->SetInvocationMessage(new BMessage(kInvokationMessage));
|
||||||
|
fCalendarView->SetFontSize(10.0);
|
||||||
|
|
||||||
|
BGroupLayout *layout = new BGroupLayout(B_HORIZONTAL);
|
||||||
|
SetLayout(layout);
|
||||||
|
|
||||||
|
float width, height;
|
||||||
|
fMonthLabel->GetPreferredSize(&width, &height);
|
||||||
|
|
||||||
|
BGridLayout* gridLayout = BGridLayoutBuilder(5.0)
|
||||||
|
.Add(_SetupButton("-", kMonthDownMessage, height), 0, 0)
|
||||||
|
.Add(fMonthLabel, 1, 0)
|
||||||
|
.Add(_SetupButton("+", kMonthUpMessage, height), 2, 0)
|
||||||
|
.Add(BSpaceLayoutItem::CreateGlue(), 3, 0)
|
||||||
|
.Add(_SetupButton("-", kYearDownMessage, height), 4, 0)
|
||||||
|
.Add(fYearLabel, 5, 0)
|
||||||
|
.Add(_SetupButton("+", kYearUpMessage, height), 6, 0)
|
||||||
|
.SetInsets(5.0, 0.0, 5.0, 0.0);
|
||||||
|
gridLayout->SetMinColumnWidth(1, be_plain_font->StringWidth("September"));
|
||||||
|
|
||||||
|
BGroupView* groupView = new BGroupView(B_VERTICAL, 10.0);
|
||||||
|
BView* view = BGroupLayoutBuilder(B_VERTICAL, 5.0)
|
||||||
|
.Add(gridLayout->View())
|
||||||
|
.Add(fCalendarView)
|
||||||
|
.SetInsets(5.0, 5.0, 5.0, 5.0);
|
||||||
|
groupView->AddChild(view);
|
||||||
|
AddChild(groupView);
|
||||||
|
|
||||||
|
MoveTo(where);
|
||||||
|
_UpdateUi(BDate::CurrentDate(B_LOCAL_TIME));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CalendarMenuWindow::~CalendarMenuWindow()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
CalendarMenuWindow::Show()
|
||||||
|
{
|
||||||
|
BRect screen(BScreen().Frame());
|
||||||
|
|
||||||
|
float right = screen.right;
|
||||||
|
float bottom = screen.bottom;
|
||||||
|
|
||||||
|
BRect rightTop(right / 2.0, screen.top, right, bottom / 2.0);
|
||||||
|
BRect rightBottom(right / 2.0, bottom / 2.0, right + 1.0, bottom + 1.0);
|
||||||
|
BRect leftBottom(screen.left, bottom / 2.0, right / 2.0, bottom + 1.0);
|
||||||
|
|
||||||
|
BPoint where = Frame().LeftTop();
|
||||||
|
BSize size = GetLayout()->PreferredSize();
|
||||||
|
|
||||||
|
if (rightTop.Contains(where)) {
|
||||||
|
where.x -= size.width;
|
||||||
|
} else if (leftBottom.Contains(where)) {
|
||||||
|
where.y -= (size.height + 4.0);
|
||||||
|
} else if (rightBottom.Contains(where)) {
|
||||||
|
where.x -= size.width;
|
||||||
|
where.y -= (size.height + 4.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
MoveTo(where);
|
||||||
|
fCalendarView->MakeFocus(true);
|
||||||
|
|
||||||
|
BWindow::Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
CalendarMenuWindow::WindowActivated(bool active)
|
||||||
|
{
|
||||||
|
if (active)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (mouse_mode() == 0) {
|
||||||
|
if (!active)
|
||||||
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
|
} else {
|
||||||
|
if (fSuppressFirstClose && !active) {
|
||||||
|
fSuppressFirstClose = false; return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fSuppressFirstClose && !active)
|
||||||
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
CalendarMenuWindow::MessageReceived(BMessage* message)
|
||||||
|
{
|
||||||
|
switch (message->what) {
|
||||||
|
case kInvokationMessage: {
|
||||||
|
int32 day, month, year;
|
||||||
|
message->FindInt32("day", &day);
|
||||||
|
message->FindInt32("month", &month);
|
||||||
|
message->FindInt32("year", &year);
|
||||||
|
|
||||||
|
_UpdateUi(BDate(year, month, day));
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case kMonthDownMessage: {
|
||||||
|
case kMonthUpMessage:
|
||||||
|
BDate date = fCalendarView->Date();
|
||||||
|
|
||||||
|
int32 day = date.Day();
|
||||||
|
int32 year = date.Year();
|
||||||
|
int32 month = date.Month();
|
||||||
|
|
||||||
|
month += (kMonthDownMessage == message->what) ? -1 : 1;
|
||||||
|
if (month < 1) {
|
||||||
|
year--;
|
||||||
|
month = 12;
|
||||||
|
} else if (month > 12) {
|
||||||
|
year++;
|
||||||
|
month = 1;
|
||||||
|
}
|
||||||
|
date.SetDate(year, month, day);
|
||||||
|
|
||||||
|
if (day > date.DaysInMonth())
|
||||||
|
day = date.DaysInMonth();
|
||||||
|
|
||||||
|
_UpdateUi(BDate(year, month, day));
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case kYearDownMessage: {
|
||||||
|
case kYearUpMessage:
|
||||||
|
BDate date = fCalendarView->Date();
|
||||||
|
int32 i = kYearDownMessage == message->what ? -1 : 1;
|
||||||
|
_UpdateUi(BDate(date.Year() + i, date.Month(), date.Day()));
|
||||||
|
} break;
|
||||||
|
|
||||||
|
default: {
|
||||||
|
BWindow::MessageReceived(message);
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
CalendarMenuWindow::_UpdateUi(const BDate& date)
|
||||||
|
{
|
||||||
|
if (!date.IsValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
fCalendarView->SetDate(date);
|
||||||
|
|
||||||
|
BString text;
|
||||||
|
text << date.Year();
|
||||||
|
fYearLabel->SetText(text.String());
|
||||||
|
|
||||||
|
fMonthLabel->SetText(date.LongMonthName(date.Month()).String());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BButton*
|
||||||
|
CalendarMenuWindow::_SetupButton(const char* label, uint32 what, float height)
|
||||||
|
{
|
||||||
|
FlatButton* button = new FlatButton(label, what);
|
||||||
|
button->SetExplicitMinSize(BSize(height, height));
|
||||||
|
button->SetFontSize(10.0);
|
||||||
|
|
||||||
|
return button;
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright Karsten Heimrich, [email protected]. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _CALENDAR_MENU_WINDOW_H_
|
||||||
|
#define _CALENDAR_MENU_WINDOW_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <DateTime.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
|
|
||||||
|
class BMessage;
|
||||||
|
class BStringView;
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
class BCalendarView;
|
||||||
|
}
|
||||||
|
using BPrivate::BCalendarView;
|
||||||
|
using BPrivate::BDate;
|
||||||
|
|
||||||
|
|
||||||
|
class CalendarMenuWindow : public BWindow {
|
||||||
|
public:
|
||||||
|
CalendarMenuWindow(BPoint where, bool euroDate);
|
||||||
|
virtual ~CalendarMenuWindow();
|
||||||
|
|
||||||
|
virtual void Show();
|
||||||
|
virtual void WindowActivated(bool active);
|
||||||
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _UpdateUi(const BDate& date);
|
||||||
|
BButton* _SetupButton(const char* label, uint32 what, float height);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BStringView* fYearLabel;
|
||||||
|
BStringView* fMonthLabel;
|
||||||
|
BCalendarView* fCalendarView;
|
||||||
|
bool fSuppressFirstClose;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _CALENDAR_MENU_WINDOW_H_
|
||||||
@@ -11,8 +11,18 @@ AddResources Deskbar : Deskbar.rdef icon-freelogo.rdef icons.rdef ;
|
|||||||
SubDirC++Flags -DDB_ADDONS -DOPEN_TRACKER=1
|
SubDirC++Flags -DDB_ADDONS -DOPEN_TRACKER=1
|
||||||
-D_INCLUDES_CLASS_DEVICE_MAP=1
|
-D_INCLUDES_CLASS_DEVICE_MAP=1
|
||||||
-D_SUPPORTS_RESOURCES=1
|
-D_SUPPORTS_RESOURCES=1
|
||||||
-D_SUPPORTS_FEATURE_SCRIPTING=1
|
-D_SUPPORTS_FEATURE_SCRIPTING=1 ;
|
||||||
-D_SHOW_CALENDAR_MENU_ITEM=1 ;
|
|
||||||
|
local targetLib ;
|
||||||
|
local targetSource ;
|
||||||
|
|
||||||
|
if $(TARGET_PLATFORM) = haiku {
|
||||||
|
targetLib = libshared.a ;
|
||||||
|
targetSource = CalendarMenuWindow.cpp ;
|
||||||
|
SubDirC++Flags -D_SHOW_CALENDAR_MENU_WINDOW=1 ;
|
||||||
|
} else {
|
||||||
|
SubDirC++Flags -D_SHOW_CALENDAR_MENU_ITEM=1 ;
|
||||||
|
}
|
||||||
|
|
||||||
Application Deskbar :
|
Application Deskbar :
|
||||||
BarApp.cpp
|
BarApp.cpp
|
||||||
@@ -34,7 +44,8 @@ Application Deskbar :
|
|||||||
WindowMenuItem.cpp
|
WindowMenuItem.cpp
|
||||||
ResourceSet.cpp
|
ResourceSet.cpp
|
||||||
Switcher.cpp
|
Switcher.cpp
|
||||||
: be tracker
|
$(targetSource)
|
||||||
|
: be tracker $(targetLib)
|
||||||
;
|
;
|
||||||
|
|
||||||
if $(TARGET_PLATFORM) = libbe_test {
|
if $(TARGET_PLATFORM) = libbe_test {
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ All rights reserved.
|
|||||||
# include "CalendarMenuItem.h"
|
# include "CalendarMenuItem.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _SHOW_CALENDAR_MENU_WINDOW
|
||||||
|
# include "CalendarMenuWindow.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include <PopUpMenu.h>
|
#include <PopUpMenu.h>
|
||||||
@@ -157,7 +161,7 @@ void
|
|||||||
TTimeView::GetPreferredSize(float *width, float *height)
|
TTimeView::GetPreferredSize(float *width, float *height)
|
||||||
{
|
{
|
||||||
*height = fHeight;
|
*height = fHeight;
|
||||||
|
|
||||||
GetCurrentTime();
|
GetCurrentTime();
|
||||||
GetCurrentDate();
|
GetCurrentDate();
|
||||||
|
|
||||||
@@ -166,13 +170,13 @@ TTimeView::GetPreferredSize(float *width, float *height)
|
|||||||
// overlap the bevels in the parent view.
|
// overlap the bevels in the parent view.
|
||||||
if (ShowingDate())
|
if (ShowingDate())
|
||||||
*width = fOrientation ?
|
*width = fOrientation ?
|
||||||
min_c(fMaxWidth - kHMargin, kHMargin + StringWidth(fDateStr))
|
min_c(fMaxWidth - kHMargin, kHMargin + StringWidth(fDateStr))
|
||||||
: kHMargin + StringWidth(fDateStr);
|
: kHMargin + StringWidth(fDateStr);
|
||||||
else {
|
else {
|
||||||
*width = fOrientation ?
|
*width = fOrientation ?
|
||||||
min_c(fMaxWidth - kHMargin, kHMargin + StringWidth(fTimeStr))
|
min_c(fMaxWidth - kHMargin, kHMargin + StringWidth(fTimeStr))
|
||||||
: kHMargin + StringWidth(fTimeStr);
|
: kHMargin + StringWidth(fTimeStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -358,6 +362,32 @@ TTimeView::MouseDown(BPoint point)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
snooze(15000);
|
||||||
|
}
|
||||||
|
#elif _SHOW_CALENDAR_MENU_WINDOW
|
||||||
|
bigtime_t startTime = system_time();
|
||||||
|
|
||||||
|
// use the doubleClickSpeed as a treshold
|
||||||
|
bigtime_t doubleClickSpeed;
|
||||||
|
get_click_speed(&doubleClickSpeed);
|
||||||
|
|
||||||
|
while (buttons) {
|
||||||
|
BPoint where;
|
||||||
|
GetMouse(&where, &buttons, false);
|
||||||
|
|
||||||
|
if ((system_time() - startTime) > doubleClickSpeed) {
|
||||||
|
where.y = Bounds().bottom + 4.0;
|
||||||
|
ConvertToScreen(&where);
|
||||||
|
|
||||||
|
if (where.y >= BScreen().Frame().bottom)
|
||||||
|
where.y -= (Bounds().Height() + 4.0);
|
||||||
|
|
||||||
|
CalendarMenuWindow* window = new CalendarMenuWindow(where, fEuroDate);
|
||||||
|
window->Show();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
snooze(15000);
|
snooze(15000);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -402,7 +432,7 @@ TTimeView::Pulse()
|
|||||||
|
|
||||||
Draw(Bounds());
|
Draw(Bounds());
|
||||||
fNeedToUpdate = false;
|
fNeedToUpdate = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -489,22 +519,22 @@ TTimeView::CalculateTextPlacement()
|
|||||||
BRect bounds(Bounds());
|
BRect bounds(Bounds());
|
||||||
|
|
||||||
fDateLocation.x = 0.0;
|
fDateLocation.x = 0.0;
|
||||||
fTimeLocation.x = 0.0;
|
fTimeLocation.x = 0.0;
|
||||||
|
|
||||||
BFont font;
|
BFont font;
|
||||||
GetFont(&font);
|
GetFont(&font);
|
||||||
const char* stringArray[1];
|
const char* stringArray[1];
|
||||||
stringArray[0] = fTimeStr;
|
stringArray[0] = fTimeStr;
|
||||||
BRect rectArray[1];
|
BRect rectArray[1];
|
||||||
escapement_delta delta = { 0.0, 0.0 };
|
escapement_delta delta = { 0.0, 0.0 };
|
||||||
font.GetBoundingBoxesForStrings(stringArray, 1, B_SCREEN_METRIC, &delta,
|
font.GetBoundingBoxesForStrings(stringArray, 1, B_SCREEN_METRIC, &delta,
|
||||||
rectArray);
|
rectArray);
|
||||||
|
|
||||||
fTimeLocation.y = fDateLocation.y = ceilf((bounds.Height() -
|
fTimeLocation.y = fDateLocation.y = ceilf((bounds.Height() -
|
||||||
rectArray[0].Height() + 1.0) / 2.0 - rectArray[0].top);
|
rectArray[0].Height() + 1.0) / 2.0 - rectArray[0].top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TTimeView::ShowClockOptions(BPoint point)
|
TTimeView::ShowClockOptions(BPoint point)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user