2 * Copyright 2005, Waldemar Kornewald <wkornew@gmx.net>
3 * Distributed under the terms of the MIT License.
6 #include "PPPDeskbarReplicant.h"
8 #include "PPPUpApplication.h"
9 #include "PPPStatusWindow.h"
10 #include <PPPInterface.h>
15 #include <PopUpMenu.h>
19 static const uint32 kMsgDisconnect
= 'DISC';
20 static const uint32 kMsgStatus
= 'STAT';
23 static const char *kLabelDisconnect
= "Disconnect";
24 static const char *kLabelStatus
= "Status";
27 PPPDeskbarReplicant::PPPDeskbarReplicant(ppp_interface_id id
)
28 : BView(BRect(0, 0, 15, 15), "PPPDeskbarReplicant", B_FOLLOW_NONE
, 0),
35 PPPDeskbarReplicant::PPPDeskbarReplicant(BMessage
*message
)
36 : BView(BRect(0, 0, 15, 15), "PPPDeskbarReplicant", B_FOLLOW_NONE
, 0)
38 message
->FindInt32("interface", reinterpret_cast<int32
*>(&fID
));
43 PPPDeskbarReplicant::~PPPDeskbarReplicant()
47 fWindow
->LockLooper();
53 PPPDeskbarReplicant::Instantiate(BMessage
*data
)
55 if(!validate_instantiation(data
, "PPPDeskbarReplicant"))
58 return new PPPDeskbarReplicant(data
);
63 PPPDeskbarReplicant::Archive(BMessage
*data
, bool deep
) const
65 BView::Archive(data
, deep
);
67 data
->AddString("add_on", APP_SIGNATURE
);
68 data
->AddInt32("interface", fID
);
74 PPPDeskbarReplicant::AttachedToWindow()
76 BMenuItem
*item
= new BMenuItem(kLabelDisconnect
, new BMessage(kMsgDisconnect
));
77 item
->SetTarget(fWindow
->StatusView());
78 fContextMenu
->AddItem(item
);
79 fContextMenu
->AddSeparatorItem();
80 item
= new BMenuItem(kLabelStatus
, new BMessage(kMsgStatus
));
81 item
->SetTarget(this);
82 fContextMenu
->AddItem(item
);
87 PPPDeskbarReplicant::MessageReceived(BMessage
*message
)
89 switch(message
->what
) {
90 case PPP_REPORT_MESSAGE
: {
92 message
->FindInt32("type", &type
);
93 if(type
== PPP_DESTRUCTION_REPORT
)
94 BDeskbar().RemoveItem(Name());
102 BView::MessageReceived(message
);
108 PPPDeskbarReplicant::MouseDown(BPoint point
)
110 Looper()->CurrentMessage()->FindInt32("buttons", &fLastButtons
);
112 if(fLastButtons
& B_SECONDARY_MOUSE_BUTTON
) {
113 ConvertToScreen(&point
);
114 fContextMenu
->Go(point
, true, true, true);
120 PPPDeskbarReplicant::MouseUp(BPoint point
)
122 if(fLastButtons
& B_PRIMARY_MOUSE_BUTTON
) {
123 // TODO: center on screen
124 // fWindow->MoveTo(center_on_screen(fWindow->Frame(), fWindow));
131 PPPDeskbarReplicant::Draw(BRect updateRect
)
133 // TODO: I want a nice blinking icon!
140 PPPDeskbarReplicant::Init()
142 BString
name("PPPDeskbarReplicant");
144 SetName(name
.String());
146 BRect
rect(50,50,380,150);
147 fWindow
= new PPPStatusWindow(rect
, fID
);
149 fContextMenu
= new BPopUpMenu("PPPContextMenu", false);
151 // watch interface destruction
152 PPPInterface
interface(fID
);
153 if(interface
.InitCheck() != B_OK
)