From f7d9ae366721af4de5d019cbacb90b9c8a8fdb7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Thu, 30 Oct 2003 15:10:18 +0000 Subject: [PATCH] Added desklink git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5213 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/Jamfile | 1 + src/apps/bin/desklink/DeskButton.cpp | 178 ++++++++++++++ src/apps/bin/desklink/DeskButton.h | 50 ++++ src/apps/bin/desklink/Jamfile | 11 + src/apps/bin/desklink/VolumeSlider.cpp | 316 +++++++++++++++++++++++++ src/apps/bin/desklink/VolumeSlider.h | 55 +++++ src/apps/bin/desklink/desklink.cpp | 277 ++++++++++++++++++++++ src/apps/bin/desklink/desklink.rsrc | Bin 0 -> 2912 bytes src/apps/bin/desklink/iconfile.h | 101 ++++++++ 9 files changed, 989 insertions(+) create mode 100644 src/apps/bin/desklink/DeskButton.cpp create mode 100644 src/apps/bin/desklink/DeskButton.h create mode 100644 src/apps/bin/desklink/Jamfile create mode 100644 src/apps/bin/desklink/VolumeSlider.cpp create mode 100644 src/apps/bin/desklink/VolumeSlider.h create mode 100644 src/apps/bin/desklink/desklink.cpp create mode 100644 src/apps/bin/desklink/desklink.rsrc create mode 100644 src/apps/bin/desklink/iconfile.h diff --git a/src/apps/bin/Jamfile b/src/apps/bin/Jamfile index e6cbc46770..b2e3b507a3 100644 --- a/src/apps/bin/Jamfile +++ b/src/apps/bin/Jamfile @@ -52,6 +52,7 @@ StdBinCommands #SubInclude OBOS_TOP src apps bin gnu ; SubInclude OBOS_TOP src apps bin addattr ; SubInclude OBOS_TOP src apps bin chkbfs ; +SubInclude OBOS_TOP src apps bin desklink ; SubInclude OBOS_TOP src apps bin listdev ; SubInclude OBOS_TOP src apps bin mkdos ; SubInclude OBOS_TOP src apps bin pc ; diff --git a/src/apps/bin/desklink/DeskButton.cpp b/src/apps/bin/desklink/DeskButton.cpp new file mode 100644 index 0000000000..38328e3578 --- /dev/null +++ b/src/apps/bin/desklink/DeskButton.cpp @@ -0,0 +1,178 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// Program: desklink +// Author: Jérôme DUVAL +// Description: VolumeControl and link items in Deskbar +// Created : October 20, 2003 +// Modified by: Jérome Duval +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "DeskButton.h" + +#define OPEN_REF 'opre' +#define DO_ACTION 'doac' + +extern char *app_signature; + +DeskButton::DeskButton(BRect frame, entry_ref *entry_ref, const char *name, BList &titles, BList &actions, + uint32 resizeMask, uint32 flags) + : BView(frame, name, resizeMask, flags), + ref(*entry_ref), + titleList(titles), + actionList(actions) +{ + // Background Color + SetViewColor(184,184,184); + + //add dragger + BRect rect(Bounds()); + rect.left = rect.right-7.0; + rect.top = rect.bottom-7.0; + BDragger *dragger = new BDragger(rect, this, B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); + AddChild(dragger); + dragger->SetViewColor(B_TRANSPARENT_32_BIT); + + segments = new BBitmap(BRect(0,0,15,15), B_CMAP8); + BNodeInfo::GetTrackerIcon(&ref, segments, B_MINI_ICON); +} + + +DeskButton::DeskButton(BMessage *message) + : BView(message) +{ + message->FindRef("ref", &ref); + + BString title, action; + int32 index = 0; + while(message->FindString("title", index, &title)==B_OK + && message->FindString("action", index, &action)==B_OK) { + titleList.AddItem(new BString(title)); + actionList.AddItem(new BString(action)); + index++; + } + + segments = new BBitmap(BRect(0,0,15,15), B_CMAP8); + BNodeInfo::GetTrackerIcon(&ref, segments, B_MINI_ICON); +} + + +DeskButton::~DeskButton() +{ + delete segments; +} + + +// archiving overrides +DeskButton * +DeskButton::Instantiate(BMessage *data) +{ + if (!validate_instantiation(data, "DeskButton")) + return NULL; + return new DeskButton(data); +} + + +status_t +DeskButton::Archive(BMessage *data, bool deep) const +{ + BView::Archive(data, deep); + + data->AddRef("ref", &ref); + + for(int32 i=0; iAddString("title", *(BString*)titleList.ItemAt(i)); + data->AddString("action", *(BString*)actionList.ItemAt(i)); + } + + data->AddString("add_on", app_signature); + return B_NO_ERROR; +} + + +void +DeskButton::MessageReceived(BMessage *message) +{ + switch (message->what) { + case B_ABOUT_REQUESTED: + (new BAlert("About Desklink", "Desklink (Replicant)\n" + " Brought to you by Jérôme DUVAL.\n\n" + "OpenBeOS, 2003","OK"))->Go(); + break; + case OPEN_REF: + be_roster->Launch(&ref); + break; + case DO_ACTION: + { + BString action; + if(message->FindString("action", &action)==B_OK) { + action += " &"; + system(action.String()); + } + break; + } + default: + BView::MessageReceived(message); + break; + } +} + + +void +DeskButton::Draw(BRect rect) +{ + BView::Draw(rect); + + SetDrawingMode(B_OP_OVER); + DrawBitmap(segments); +} + + +void +DeskButton::MouseDown(BPoint point) +{ + uint32 mouseButtons; + BPoint where; + GetMouse(&where, &mouseButtons, true); + + where = ConvertToScreen(point); + + if (mouseButtons & B_SECONDARY_MOUSE_BUTTON) { + BString label = "Open "; + label += ref.name; + BPopUpMenu *menu = new BPopUpMenu("", false, false); + menu->SetFont(be_plain_font); + menu->AddItem(new BMenuItem(label.String(), new BMessage(OPEN_REF))); + if(titleList.CountItems()>0 && actionList.CountItems()>0) { + menu->AddSeparatorItem(); + for(int32 i=0; iAddString("action", *(BString*)actionList.ItemAt(i)); + menu->AddItem(new BMenuItem(((BString*)titleList.ItemAt(i))->String(), message)); + } + } + + menu->SetTargetForItems(this); + menu->Go(where, true, true, BRect(where - BPoint(4, 4), + where + BPoint(4, 4))); + } else if (mouseButtons & B_PRIMARY_MOUSE_BUTTON) { + be_roster->Launch(&ref); + } +} diff --git a/src/apps/bin/desklink/DeskButton.h b/src/apps/bin/desklink/DeskButton.h new file mode 100644 index 0000000000..80b799fccf --- /dev/null +++ b/src/apps/bin/desklink/DeskButton.h @@ -0,0 +1,50 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// Program: desklink +// Author: Jérôme DUVAL +// Description: VolumeControl and link items in Deskbar +// Created : October 20, 2003 +// Modified by: Jérome Duval +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +#ifndef DESKBUTTON_H +#define DESKBUTTON_H + +#include +#include +#include + +class DeskButton : public BView { +public: + DeskButton(BRect frame, entry_ref *ref, const char *name, BList &titleList, BList &actionList, + uint32 resizeMask = B_FOLLOW_ALL, + uint32 flags = B_WILL_DRAW | B_NAVIGABLE | B_PULSE_NEEDED); + + DeskButton(BMessage *); + // BMessage * based constructor needed to support archiving + virtual ~DeskButton(); + + // archiving overrides + static DeskButton *Instantiate(BMessage *data); + virtual status_t Archive(BMessage *data, bool deep = true) const; + + // misc BView overrides + virtual void MouseDown(BPoint); + + virtual void Draw(BRect ); + + virtual void MessageReceived(BMessage *); +private: + BBitmap * segments; + entry_ref ref; + BList actionList, titleList; +}; + + +#endif diff --git a/src/apps/bin/desklink/Jamfile b/src/apps/bin/desklink/Jamfile new file mode 100644 index 0000000000..c867f1b6e0 --- /dev/null +++ b/src/apps/bin/desklink/Jamfile @@ -0,0 +1,11 @@ +SubDir OBOS_TOP src apps bin desklink ; + +AddResources desklink : desklink.rsrc ; + +BinCommand desklink : + desklink.cpp + VolumeSlider.cpp + DeskButton.cpp + : be media + ; + diff --git a/src/apps/bin/desklink/VolumeSlider.cpp b/src/apps/bin/desklink/VolumeSlider.cpp new file mode 100644 index 0000000000..91bb78da7b --- /dev/null +++ b/src/apps/bin/desklink/VolumeSlider.cpp @@ -0,0 +1,316 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// Program: desklink +// Author: Jérôme DUVAL +// Description: VolumeControl and link items in Deskbar +// Created : October 20, 2003 +// Modified by: Jérome Duval +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "VolumeSlider.h" +#include "iconfile.h" + +#define VOLUME_CHANGED 'vlcg' + +VolumeSlider::VolumeSlider(BRect frame) + : BWindow(frame, "VolumeSlider", B_BORDERED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_WILL_ACCEPT_FIRST_CLICK, 0), + aOutNode(NULL), + paramWeb(NULL), + mixerParam(NULL) +{ + //Make sure it's not outside the screen. + const int32 kMargin = 3; + BRect windowRect=ConvertToScreen(Bounds()); + BRect screenFrame(BScreen(B_MAIN_SCREEN_ID).Frame()); + if (screenFrame.right < windowRect.right + kMargin) + MoveBy(- kMargin - windowRect.right + screenFrame.right, 0); + if (screenFrame.bottom < windowRect.bottom + kMargin) + MoveBy(0, - kMargin - windowRect.bottom + screenFrame.bottom); + if (screenFrame.left > windowRect.left - kMargin) + MoveBy(kMargin + screenFrame.left - windowRect.left, 0); + if (screenFrame.top > windowRect.top - kMargin) + MoveBy(0, kMargin + screenFrame.top - windowRect.top); + + float value = 0.0; + + aOutNode = new media_node(); + + status_t err; + BMediaRoster* roster = BMediaRoster::Roster(&err); + + if(roster && (err==B_OK)) { + if((err = roster->GetAudioOutput(aOutNode)) == B_OK) { + if((err = roster->GetParameterWebFor(*aOutNode, ¶mWeb)) == B_OK) { + + //Finding the Mixer slider in the audio output ParameterWeb + int32 numParams = paramWeb->CountParameters(); + BParameter* p = NULL; + for (int i = 0; i < numParams; i++) { + p = paramWeb->ParameterAt(i); + printf("%i %s\n", i, p->Name()); + if (!strcmp(p->Name(), "Master")) { + for (; i < numParams; i++) { + p = paramWeb->ParameterAt(i); + if (strcmp(p->Kind(), B_MASTER_GAIN)) p=NULL; + else break; + } + break; + } else p = NULL; + } + if (p==NULL) { + printf("Could not find the mixer.\n"); + exit(1); + } else if(p->Type()!=BParameter::B_CONTINUOUS_PARAMETER) { + printf("Mixer is unknown.\n"); + exit(2); + } + + mixerParam= dynamic_cast(p); + min = mixerParam->MinValue(); + max = mixerParam->MaxValue(); + step = mixerParam->ValueStep(); + + float chanData[2]; + bigtime_t lastChange; + size_t size = sizeof(chanData); + + mixerParam->GetValue( &chanData, &size, &lastChange ); + + value = (chanData[0]-min)*100/(max-min); + } else { + printf("No parameter web\n"); + } + } else { + printf("No Audio output\n"); + } + } else { + printf("No Media Roster\n"); + } + + if(err!=B_OK) { + delete aOutNode; + aOutNode = NULL; + } + + BBox *box = new BBox(Bounds(), "sliderbox", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER); + AddChild(box); + + slider = new SliderView(box->Bounds().InsetByCopy(1, 1), new BMessage(VOLUME_CHANGED), + mixerParam ? "Volume" : "No Media Server", B_FOLLOW_LEFT | B_FOLLOW_TOP, value); + box->AddChild(slider); + + slider->SetTarget(this); + + SetPulseRate(100); +} + + +VolumeSlider::~VolumeSlider() +{ + delete paramWeb; + BMediaRoster* roster = BMediaRoster::CurrentRoster(); + if(roster && aOutNode) + roster->ReleaseNode(*aOutNode); +} + + +void +VolumeSlider::WindowActivated(bool active) +{ + if (!active) { + Lock(); + Quit(); + } +} + + +void +VolumeSlider::MessageReceived(BMessage *msg) +{ + switch (msg->what) { + case VOLUME_CHANGED: + { + printf("VOLUME_CHANGED\n"); + if(mixerParam) { + float chanData[2]; + bigtime_t lastChange; + size_t size = sizeof(chanData); + + mixerParam->GetValue( &chanData, &size, &lastChange ); + + for( int i=0; i<2; i++) { + chanData[i] = (slider->Value() * (max - min) / 100) / step * step + min; + } + + PRINT(("Min value: %f Max Value: %f\nData: %f %f\n", mixerParam->MinValue(), mixerParam->MaxValue(), chanData[0], chanData[1])); + mixerParam->SetValue(&chanData, sizeof(chanData), 0); + + beep(); + } + + Quit(); + break; + } + default: + BWindow::MessageReceived(msg); // not a slider message, not our problem + } +} + +#define REDZONESTART 151 + + +SliderView::SliderView(BRect rect, BMessage *msg, const char *title, uint32 resizeFlags, int32 value) + : BControl(rect, "slider", NULL, msg, resizeFlags, B_WILL_DRAW | B_PULSE_NEEDED), + leftBitmap(BRect(0, 0, kLeftWidth - 1, kLeftHeight - 1), B_CMAP8), + rightBitmap(BRect(0, 0, kRightWidth - 1, kRightHeight - 1), B_CMAP8), + buttonBitmap(BRect(0, 0, kButtonWidth - 1, kButtonHeight - 1), B_CMAP8), + fTrackingX(11 + (192-11) * value / 100), + fTitle(title) +{ + leftBitmap.SetBits(kLeftBits, kLeftWidth * kLeftHeight, 0, B_CMAP8); + rightBitmap.SetBits(kRightBits, kRightWidth * kRightHeight, 0, B_CMAP8); + buttonBitmap.SetBits(kButtonBits, kButtonWidth * kButtonHeight, 0, B_CMAP8); + + SetTracking(true); + SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); + SetValue(value); +} + + +SliderView::~SliderView() +{ + +} + + +void +SliderView::Pulse() +{ + uint32 mouseButtons; + BPoint where; + GetMouse(&where, &mouseButtons, true); + + // button not pressed, exit + if (! (mouseButtons & B_PRIMARY_MOUSE_BUTTON)) { + SetTracking(false); + SetValue( (fTrackingX - 11) / (192-11) * 100 ); + Invoke(); + } +} + + +void +SliderView::Draw(BRect updateRect) +{ + SetHighColor(189,186,189); + StrokeLine(BPoint(11,1), BPoint(192,1)); + SetHighColor(0,0,0); + StrokeLine(BPoint(11,2), BPoint(192,2)); + SetHighColor(255,255,255); + StrokeLine(BPoint(11,14), BPoint(192,14)); + SetHighColor(231,227,231); + StrokeLine(BPoint(11,15), BPoint(192,15)); + + SetLowColor(ViewColor()); + + SetDrawingMode(B_OP_OVER); + + DrawBitmapAsync(&leftBitmap, BPoint(5,1)); + DrawBitmapAsync(&rightBitmap, BPoint(193,1)); + + float right = (fTrackingX < REDZONESTART) ? fTrackingX : REDZONESTART; + SetHighColor(99,151,99); + FillRect(BRect(11,3,right,4)); + SetHighColor(156,203,156); + FillRect(BRect(11,5,right,13)); + if(right == REDZONESTART) { + SetHighColor(156,101,99); + FillRect(BRect(REDZONESTART,3,fTrackingX,4)); + SetHighColor(255,154,156); + FillRect(BRect(REDZONESTART,5,fTrackingX,13)); + } + SetHighColor(156,154,156); + FillRect(BRect(fTrackingX,3,192,13)); + + BFont font; + float width = font.StringWidth(fTitle); + + SetHighColor(49,154,49); + DrawString(fTitle, BPoint(11 + (192-11-width)/2, 12)); + + DrawBitmapAsync(&buttonBitmap, BPoint(fTrackingX-5,3)); + + Sync(); + + SetDrawingMode(B_OP_COPY); +} + + +void +SliderView::MouseMoved(BPoint point, uint32 transit, const BMessage *message) +{ + if (!IsTracking()) + return; + + uint32 mouseButtons; + BPoint where; + GetMouse(&where, &mouseButtons, true); + + // button not pressed, exit + if (! (mouseButtons & B_PRIMARY_MOUSE_BUTTON)) { + Invoke(); + SetTracking(false); + } + + if (!Bounds().InsetBySelf(2,2).Contains(point)) + return; + + fTrackingX = point.x; + if(fTrackingX < 11) + fTrackingX = 11; + if(fTrackingX > 192) + fTrackingX = 192; + Draw(Bounds()); + Flush(); + +} + + +void +SliderView::MouseUp(BPoint point) +{ + if (!IsTracking()) + return; + + SetValue( (point.x - 11) / (192-11) * 100 ); + if(Value()<0) + SetValue(0); + if(Value()>100) + SetValue(100); + + Invoke(); + SetTracking(false); + fTrackingX = point.x; + if(fTrackingX < 11) + fTrackingX = 11; + if(fTrackingX > 192) + fTrackingX = 192; + Draw(Bounds()); + Flush(); +} diff --git a/src/apps/bin/desklink/VolumeSlider.h b/src/apps/bin/desklink/VolumeSlider.h new file mode 100644 index 0000000000..c34c26bfdf --- /dev/null +++ b/src/apps/bin/desklink/VolumeSlider.h @@ -0,0 +1,55 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// Program: desklink +// Author: Jérôme DUVAL +// Description: VolumeControl and link items in Deskbar +// Created : October 20, 2003 +// Modified by: Jérome Duval +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +#ifndef VOLUMESLIDER_H +#define VOLUMESLIDER_H + +#include +#include +#include +#include + +class SliderView : public BControl +{ +public: + SliderView(BRect rect, BMessage *msg, const char* title, uint32 resizeFlags, int32 value); + ~SliderView(); + virtual void Draw(BRect); + virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *message); + virtual void MouseUp(BPoint point); + virtual void Pulse(); +private: + BBitmap leftBitmap, rightBitmap, buttonBitmap; + float fTrackingX; + const char* fTitle; +}; + +class VolumeSlider : public BWindow +{ +public: + VolumeSlider(BRect frame); + ~VolumeSlider(); + + void MessageReceived(BMessage*); + void WindowActivated(bool active); +private: + media_node *aOutNode; + BParameterWeb* paramWeb; + BContinuousParameter* mixerParam; + float min, max, step; + SliderView *slider; +}; + +#endif diff --git a/src/apps/bin/desklink/desklink.cpp b/src/apps/bin/desklink/desklink.cpp new file mode 100644 index 0000000000..90018f6b37 --- /dev/null +++ b/src/apps/bin/desklink/desklink.cpp @@ -0,0 +1,277 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2003, OpenBeOS +// +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// +// Program: desklink +// Author: Jérôme DUVAL +// Description: VolumeControl and link items in Deskbar +// Created : October 20, 2003 +// Modified by: Jérome Duval +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "VolumeSlider.h" +#include "DeskButton.h" +#include "iconfile.h" + +#define MEDIA_SETTINGS 'mese' +#define SOUND_SETTINGS 'sose' +#define OPEN_MEDIA_PLAYER 'omep' + +const char *app_signature = "application/x-vnd.be.desklink"; +// the application signature used by the replicant to find the supporting +// code + +class _EXPORT VCButton; + // the dragger part has to be exported + +class VCButton : public BView { +public: + VCButton(BRect frame, const char *name, + uint32 resizeMask = B_FOLLOW_ALL, + uint32 flags = B_WILL_DRAW | B_NAVIGABLE | B_PULSE_NEEDED); + + VCButton(BMessage *); + // BMessage * based constructor needed to support archiving + virtual ~VCButton(); + + // archiving overrides + static VCButton *Instantiate(BMessage *data); + virtual status_t Archive(BMessage *data, bool deep = true) const; + + + // misc BView overrides + virtual void MouseDown(BPoint); + virtual void MouseUp(BPoint); + + virtual void Draw(BRect ); + + virtual void MessageReceived(BMessage *); +private: + BBitmap * segments; + VolumeSlider *volumeSlider; +}; + +// +// This is the exported function that will be used by Deskbar +// to create and add the replicant +// +extern "C" _EXPORT BView* instantiate_deskbar_item(); + +BView * +instantiate_deskbar_item() +{ + return new VCButton(BRect(0, 0, 16, 16), "VCButton"); +} + + +VCButton::VCButton(BRect frame, const char *name, + uint32 resizeMask, uint32 flags) + : BView(frame, name, resizeMask, flags) +{ + // Background Bitmap + segments = new BBitmap(BRect(0, 0, kSpeakerWidth - 1, kSpeakerHeight - 1), B_COLOR_8_BIT); + segments->SetBits(kSpeakerBits, kSpeakerWidth*kSpeakerHeight, 0, B_COLOR_8_BIT); + // Background Color + SetViewColor(184,184,184); + + //add dragger + BRect rect(Bounds()); + rect.left = rect.right-7.0; + rect.top = rect.bottom-7.0; + BDragger *dragger = new BDragger(rect, this, B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); + AddChild(dragger); + dragger->SetViewColor(B_TRANSPARENT_32_BIT); +} + + +VCButton::VCButton(BMessage *message) + : BView(message), + volumeSlider(NULL) +{ + // Background Bitmap + segments = new BBitmap(BRect(0, 0, 16 - 1, 16 - 1), B_COLOR_8_BIT); + segments->SetBits(kSpeakerBits, 16*16, 0, B_COLOR_8_BIT); +} + + +VCButton::~VCButton() +{ + delete segments; +} + + +// archiving overrides +VCButton * +VCButton::Instantiate(BMessage *data) +{ + if (!validate_instantiation(data, "VCButton")) + return NULL; + return new VCButton(data); +} + + +status_t +VCButton::Archive(BMessage *data, bool deep) const +{ + BView::Archive(data, deep); + + data->AddString("add_on", app_signature); + return B_NO_ERROR; +} + + +void +VCButton::MessageReceived(BMessage *message) +{ + switch (message->what) { + case B_ABOUT_REQUESTED: + (new BAlert("About Volume Control", "Volume Control (Replicant)\n" + " Brought to you by Jérôme DUVAL.\n\n" + "OpenBeOS, 2003","OK"))->Go(); + break; + case OPEN_MEDIA_PLAYER: + // launch the media player app + be_roster->Launch("application/x-vnd.Be.MediaPlayer"); + break; + case MEDIA_SETTINGS: + // launch the media prefs app + be_roster->Launch("application/x-vnd.Be.MediaPrefs"); + break; + case SOUND_SETTINGS: + // launch the sounds prefs app + be_roster->Launch("application/x-vnd.Be.SoundsPrefs"); + break; + default: + BView::MessageReceived(message); + break; + } +} + + +void +VCButton::Draw(BRect rect) +{ + BView::Draw(rect); + + SetDrawingMode(B_OP_OVER); + DrawBitmap(segments); +} + + +void +VCButton::MouseDown(BPoint point) +{ + uint32 mouseButtons; + BPoint where; + GetMouse(&where, &mouseButtons, true); + + where = ConvertToScreen(point); + + if (mouseButtons & B_SECONDARY_MOUSE_BUTTON) { + BPopUpMenu *menu = new BPopUpMenu("", false, false); + menu->SetFont(be_plain_font); + menu->AddItem(new BMenuItem("Media Settings...", new BMessage(MEDIA_SETTINGS))); + menu->AddItem(new BMenuItem("Sound Settings...", new BMessage(SOUND_SETTINGS))); + menu->AddSeparatorItem(); + menu->AddItem(new BMenuItem("Open MediaPlayer", new BMessage(OPEN_MEDIA_PLAYER))); + + menu->SetTargetForItems(this); + menu->Go(where, true, true, BRect(where - BPoint(4, 4), + where + BPoint(4, 4))); + } else if (mouseButtons & B_PRIMARY_MOUSE_BUTTON) { + // Show VolumeSlider + volumeSlider = new VolumeSlider(BRect(where.x,where.y,where.x+207,where.y+19)); + volumeSlider->Show(); + } +} + + +void +VCButton::MouseUp(BPoint point) +{ + if(volumeSlider) { + volumeSlider->Lock(); + volumeSlider->Quit(); + delete volumeSlider; + volumeSlider = NULL; + } +} + + + + +int +main(int, char **argv) +{ + BApplication app(app_signature); + bool atLeastOnePath = false; + BList titleList; + BList actionList; + + for(int32 i=1; argv[i]!=NULL; i++) { + + if (strncmp(argv[i], "cmd=", 4) == 0) { + BString *title = new BString(argv[i] + 4); + int32 index = title->FindFirst(':'); + if(index<=0) { + printf("desklink: usage: cmd=title:action\n"); + } else { + title->Truncate(index); + BString *action = new BString(argv[i] + 4); + action->Remove(0, index+1); + titleList.AddItem(title); + actionList.AddItem(action); + } + continue; + } + + atLeastOnePath = true; + + BEntry entry(argv[i], true); + if(!entry.Exists()) { + printf("desklink: cannot find '%s'\n", argv[i]); + return 1; + } + + entry_ref ref; + entry.GetRef(&ref); + + status_t err; + err = BDeskbar().AddItem(new DeskButton(BRect(0, 0, 16, 16), &ref, "DeskButton", + titleList, actionList)); + + if(err!=B_OK) { + printf("desklink: Deskbar refuses link to '%s': %s\n", argv[i], strerror(err)); + } + + titleList.MakeEmpty(); + actionList.MakeEmpty(); + } + + if (!atLeastOnePath) { + // print a simple usage string + printf( "usage: desklink { [ cmd=title:action ... ] path } ...\n"); + return 1; + } + + return 0; +} diff --git a/src/apps/bin/desklink/desklink.rsrc b/src/apps/bin/desklink/desklink.rsrc new file mode 100644 index 0000000000000000000000000000000000000000..e4219a0503213e0f41f7fbbd18735a5f671bd3b7 GIT binary patch literal 2912 zcmWFvW?*0t@ONPaQZ69O1|-M;AiWGgy)T&|W@Ioz*dXEmKmZb_1$#9Y1H(q3!65V3 zurn~QK&)Zd0A#OVf^Z^$YUH5eWk9wvlsyy37J{-t6fNC3YCi4Kz-ZWxhV5t?7)=8s zAr0_?JUI$RLtqGmKw?2bPG)jqNoIbYeuZvXUW#5)s$NQJadu8-UN!@!tW&CPYED{e zMQU*vc^=Al}W#(LEU4egn1P z!k~&k%|AheqA=H>U{8NPxUyhhPhXHZpq42wLRqk