3
3
* All rights reserved. Distributed under the terms of the MIT license.
4
4
*/
5
5
6
- #include < Alert.h>
7
6
#include < Bitmap.h>
7
+ #include < Catalog.h>
8
8
#include < Looper.h>
9
9
#include < MessageRunner.h>
10
10
#include < Roster.h>
11
11
#include < String.h>
12
12
#include < StringView.h>
13
13
14
- #include " App.h"
15
14
#include " ForecastDeskbarView.h"
16
15
#include " ForecastView.h"
17
16
#include " Util.h"
18
17
18
+ #undef B_TRANSLATION_CONTEXT
19
+ #define B_TRANSLATION_CONTEXT " ForecastDeskbarView"
20
+
19
21
const uint32 kUpdateForecastMessage = ' Updt' ;
20
22
const float kToolTipDelay = 1000000 ; /* 1000000ms = 1s*/
23
+ int fMaxHeight ;
21
24
25
+ extern " C" _EXPORT BView* instantiate_deskbar_item (float maxWidth, float maxHeight);
22
26
23
27
ForecastDeskbarView::ForecastDeskbarView (BRect viewSize, ForecastView* forecastView)
24
28
:
@@ -28,6 +32,13 @@ ForecastDeskbarView::ForecastDeskbarView(BRect viewSize, ForecastView* forecastV
28
32
fMessageRunner = NULL ;
29
33
}
30
34
35
+ ForecastDeskbarView::ForecastDeskbarView (BMessage* archive)
36
+ :
37
+ BView(archive)
38
+ {
39
+ fMessageRunner = NULL ;
40
+ }
41
+
31
42
32
43
ForecastDeskbarView::~ForecastDeskbarView ()
33
44
{
@@ -48,17 +59,16 @@ ForecastDeskbarView::AttachedToWindow()
48
59
AdoptParentColors ();
49
60
}
50
61
51
- extern " C" _EXPORT BView* instantiate_deskbar_item ();
52
62
53
-
54
- BView*
55
- instantiate_deskbar_item ()
63
+ extern " C" _EXPORT BView*
64
+ instantiate_deskbar_item (float maxWidth, float maxHeight)
56
65
{
66
+ fMaxHeight = maxHeight;
57
67
BMessage settings;
58
68
LoadSettings (settings);
59
69
ForecastDeskbarView* view = new ForecastDeskbarView (
60
- BRect (0 , 0 , 16 , 16 ),
61
- new ForecastView (BRect (0 , 0 , 0 , 0 ),
70
+ BRect (0 , 0 , maxHeight, maxHeight),
71
+ new ForecastView (BRect (0 , 0 , 0 , 0 ),
62
72
&settings));
63
73
entry_ref appRef;
64
74
settings.FindRef (" appLocation" , &appRef);
@@ -73,11 +83,11 @@ ForecastDeskbarView::Draw(BRect drawRect)
73
83
BView::Draw (drawRect);
74
84
75
85
SetDrawingMode (B_OP_OVER);
76
- // TO-DO: Try with
86
+ // TO-DO: Try with
77
87
// SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
78
88
BBitmap* bitmap = fForecastView ->GetWeatherIcon (static_cast <weatherIconSize>(1 ));
79
89
if (bitmap)
80
- DrawBitmapAsync (bitmap, BPoint ( 0 , 0 ) );
90
+ DrawBitmapAsync (bitmap, drawRect );
81
91
SetDrawingMode (B_OP_COPY);
82
92
}
83
93
@@ -88,24 +98,21 @@ ForecastDeskbarView::Instantiate(BMessage* archive)
88
98
if (!validate_instantiation (archive, " ForecastDeskbarView" ))
89
99
return NULL ;
90
100
91
- return reinterpret_cast <BArchivable*>(instantiate_deskbar_item ());
101
+ return reinterpret_cast <BArchivable*>(instantiate_deskbar_item (fMaxHeight , fMaxHeight ));
92
102
}
93
103
94
104
95
105
void
96
106
ForecastDeskbarView::MessageReceived (BMessage* message)
97
107
{
98
108
if (message->what == kUpdateForecastMessage ) {
99
- BString weatherDetailsText;
100
- weatherDetailsText << " Temperature: "
101
- << FormatString (fForecastView ->Unit (),
102
- fForecastView ->Temperature ())
103
- << " \n " ;
104
- weatherDetailsText << " Condition: " << fForecastView ->GetCondition ()
105
- << " \n " ;
106
- weatherDetailsText << " Location: " << fForecastView ->CityName ();
107
- SetToolTip (weatherDetailsText.String ());
108
-
109
+ BString tooltip;
110
+ BString temperature = FormatString (fForecastView ->Unit (), fForecastView ->Temperature ()).String ();
111
+ tooltip.SetToFormat (B_TRANSLATE (" Temperature: %s\n Condition: %s\n Location: %s" ),
112
+ temperature.String (),
113
+ fForecastView ->CityName ().String (),
114
+ fForecastView ->GetStatus ().String ());
115
+ SetToolTip (tooltip);
109
116
Invalidate ();
110
117
} else
111
118
BView::MessageReceived (message);
0 commit comments