-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasteOMaticWindow.cpp
124 lines (101 loc) · 3.24 KB
/
PasteOMaticWindow.cpp
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
121
122
123
124
/*
* Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Author:
* Andras Sevcsik <[email protected]>
*/
#include "defines.h"
#include "PasteOMatic.h"
#include "PasteOMaticView.h"
#include "PasteOMaticWindow.h"
#include <Bitmap.h>
#include <Button.h>
#include <Entry.h>
#include <GraphicsDefs.h>
#include <GroupLayout.h>
#include <InterfaceDefs.h>
#include <LayoutItem.h>
#include <String.h>
#include <TextControl.h>
#include <Window.h>
#include <iostream>
using namespace std;
PasteOMaticWindow::PasteOMaticWindow() : BWindow(BRect(100, 100, 550, 148),
WINDOW_TITLE,
B_TITLED_WINDOW,
B_NOT_V_RESIZABLE |
B_NOT_ZOOMABLE |
B_ASYNCHRONOUS_CONTROLS)
{
BGroupLayout *layout;
BLayoutItem *item;
fView = new PasteOMaticView();
fTextControl = new BTextControl(BRect(0, 0, 10, 10), "fTextControl",
"link", "<- Drop something here", NULL);
fTextControl->SetEnabled(false);
fOpenButton = new BButton(BRect(10, 0, 20, 10), "fOpenButton",
"Open File" B_UTF8_ELLIPSIS,
new BMessage(MESSAGE_OPEN));
fOpenButton->MakeDefault(true);
fSettingsButton = new BButton(BRect(10, 0, 20, 10), "fSettingsButton",
"Settings" B_UTF8_ELLIPSIS,
new BMessage(MESSAGE_SETTINGS));
layout = new BGroupLayout(B_HORIZONTAL, 0);
SetLayout(layout);
layout->View()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
item = layout->AddView(static_cast<BView *> (fView));
item->SetExplicitMaxSize(BSize(48, 48));
item->SetExplicitMinSize(BSize(48, 48));
layout->AddView(static_cast<BView *> (fTextControl));
layout->AddView(static_cast<BView *> (fOpenButton));
layout->AddView(static_cast<BView *> (fSettingsButton));
SetSizeLimits(450, 10000000, 40, 10000000);
}
PasteOMaticWindow::~PasteOMaticWindow()
{
}
void PasteOMaticWindow::MessageReceived(BMessage *message)
{
switch(message->what)
{
case MESSAGE_SETTINGS:
case MESSAGE_OPEN:
fView->MessageReceived(message);
break;
case MESSAGE_PASTE_FAIL:
_UpdateStatus(message);
break;
case MESSAGE_PASTE_SUCCESS:
_UpdateStatus(message);
break;
case MESSAGE_PASTE_PROGRESS:
_UpdateProgress(message);
break;
default:
BWindow::MessageReceived(message);
}
}
bool PasteOMaticWindow::QuitRequested()
{
cout << "Bye\n";
my_app->PostMessage(B_QUIT_REQUESTED);
return true;
}
void PasteOMaticWindow::_UpdateProgress(BMessage *message)
{
int8 percentage;
BString str;
if (message->FindInt8("percentage", &percentage) == B_OK)
str << "Working (" << percentage << "%)";
else str = "Working...";
fTextControl->SetText(str);
}
void PasteOMaticWindow::_UpdateStatus(BMessage *message)
{
const char *str;
if (message->FindString("error", &str) == B_OK)
fTextControl->SetText(str);
else if (message->FindString("link", &str) == B_OK)
fTextControl->SetText(str);
}