forked from leavengood/Haiku-Browser
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBrowserToolbar.cpp
More file actions
120 lines (92 loc) · 3.56 KB
/
BrowserToolbar.cpp
File metadata and controls
120 lines (92 loc) · 3.56 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
113
114
115
116
117
118
119
120
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright 2009, Maxime Simon, simon.maxime@gmail.com
// All rights reserved.
//
// Distributed under the terms of the MIT License.
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include "BrowserToolbar.h"
#include "BitmapHelper.h"
#include "BrowserIcons.h"
#include "Constants.h"
#include "ToolbarView.h"
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <string.h>
BrowserToolbar::BrowserToolbar()
: BView("main toolbar", B_WILL_DRAW),
fIconSize(BRect(0, 0, 23, 23))
{
_DrawViews();
}
BrowserToolbar::~BrowserToolbar()
{
}
void
BrowserToolbar::ChangeReloadStopButton(bool loading)
{
if (loading && strcmp(fReloadStopButton->Name(), "Reload") == 0) {
fReloadStopButton->SetName("Stop");
fReloadStopButton->SetBitmaps(RetrieveBitmap(kStopIconUp, fIconSize),
RetrieveBitmap(kStopIconDown, fIconSize));
fReloadStopButton->SetMessage(new BMessage(kMsgNavStop));
} else if (!loading && strcmp(fReloadStopButton->Name(), "Stop") == 0) {
fReloadStopButton->SetName("Reload");
fReloadStopButton->SetBitmaps(RetrieveBitmap(kReloadIconUp, fIconSize),
RetrieveBitmap(kReloadIconDown, fIconSize));
fReloadStopButton->SetMessage(new BMessage(kMsgNavReload));
}
}
void
BrowserToolbar::_DrawViews()
{
// Back
BBitmap *iconUp = RetrieveBitmap(kBackIconUp, fIconSize);
BBitmap *iconDown = RetrieveBitmap(kBackIconDown, fIconSize);
BitmapButton *back = new BitmapButton(BRect(0, 0, 1, 1), "Back",
iconUp, iconDown, new BMessage(kMsgNavBack));
back->SetExplicitMinSize(BSize(fIconSize.Width(), fIconSize.Height()));
back->SetExplicitMaxSize(BSize(fIconSize.Width(), fIconSize.Height()));
// Forward
iconUp = RetrieveBitmap(kForwardIconUp, fIconSize);
iconDown = RetrieveBitmap(kForwardIconDown, fIconSize);
BitmapButton *forward = new BitmapButton(BRect(0, 0, 1, 1), "Forward",
iconUp, iconDown, new BMessage(kMsgNavForward));
forward->SetExplicitMinSize(BSize(fIconSize.Width(), fIconSize.Height()));
forward->SetExplicitMaxSize(BSize(fIconSize.Width(), fIconSize.Height()));
// Reload - Stop
iconUp = RetrieveBitmap(kReloadIconUp, fIconSize);
iconDown = RetrieveBitmap(kReloadIconDown, fIconSize);
fReloadStopButton = new BitmapButton(BRect(0, 0, 1, 1), "Reload",
iconUp, iconDown, new BMessage(kMsgNavReload));
fReloadStopButton->SetExplicitMinSize(BSize(fIconSize.Width(), fIconSize.Height()));
fReloadStopButton->SetExplicitMaxSize(BSize(fIconSize.Width(), fIconSize.Height()));
// Location bar
fLocationBar = new BTextControl("location bar", NULL, "about:blank", new BMessage(kMsgNavGoURL));
font_height fontHeight;
GetFontHeight(&fontHeight);
float height = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
BSize locationBarSize;
locationBarSize.SetHeight(height + 10);
fLocationBar->SetExplicitMinSize(locationBarSize);
fLocationBar->SetExplicitMaxSize(locationBarSize);
// Go
iconUp = RetrieveBitmap(kGoIconUp, fIconSize);
iconDown = RetrieveBitmap(kGoIconDown, fIconSize);
BitmapButton *go = new BitmapButton(BRect(0, 0, 1, 1), "Go",
iconUp, iconDown, new BMessage(kMsgNavGoURL));
go->SetExplicitMinSize(BSize(fIconSize.Width(), fIconSize.Height()));
go->SetExplicitMaxSize(BSize(fIconSize.Width(), fIconSize.Height()));
// Set the layout
SetLayout(new BGroupLayout(B_HORIZONTAL));
ToolbarView *view = new ToolbarView();
AddChild(BGroupLayoutBuilder(view)
.Add(back)
.Add(forward)
.Add(fReloadStopButton)
.Add(fLocationBar, B_SIZE_UNLIMITED)
.Add(go)
.SetInsets(5, 5, 5, 5)
);
}