diff options
Diffstat (limited to 'src/VBox/Additions/haiku/VBoxTray')
-rw-r--r-- | src/VBox/Additions/haiku/VBoxTray/Makefile.kmk | 128 | ||||
-rw-r--r-- | src/VBox/Additions/haiku/VBoxTray/VBoxClipboard.cpp | 468 | ||||
-rw-r--r-- | src/VBox/Additions/haiku/VBoxTray/VBoxClipboard.h | 88 | ||||
-rw-r--r-- | src/VBox/Additions/haiku/VBoxTray/VBoxDisplay.cpp | 177 | ||||
-rw-r--r-- | src/VBox/Additions/haiku/VBoxTray/VBoxDisplay.h | 86 | ||||
-rw-r--r-- | src/VBox/Additions/haiku/VBoxTray/VBoxGuestApplication.cpp | 101 | ||||
-rw-r--r-- | src/VBox/Additions/haiku/VBoxTray/VBoxGuestApplication.h | 89 | ||||
-rw-r--r-- | src/VBox/Additions/haiku/VBoxTray/VBoxGuestDeskbarView.cpp | 297 | ||||
-rw-r--r-- | src/VBox/Additions/haiku/VBoxTray/VBoxGuestDeskbarView.h | 109 | ||||
-rw-r--r-- | src/VBox/Additions/haiku/VBoxTray/VBoxServiceDescriptor.h | 78 | ||||
-rw-r--r-- | src/VBox/Additions/haiku/VBoxTray/VBoxTray.rdef | 93 |
11 files changed, 1714 insertions, 0 deletions
diff --git a/src/VBox/Additions/haiku/VBoxTray/Makefile.kmk b/src/VBox/Additions/haiku/VBoxTray/Makefile.kmk new file mode 100644 index 00000000..96d6c52e --- /dev/null +++ b/src/VBox/Additions/haiku/VBoxTray/Makefile.kmk @@ -0,0 +1,128 @@ +# $Id: Makefile.kmk $ +## @file +# Sub-Makefile for VBoxTray, Haiku Guest Additions. +# + +# +# Copyright (C) 2012-2023 Oracle and/or its affiliates. +# +# This file is part of VirtualBox base platform packages, as +# available from https://www.virtualbox.org. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation, in version 3 of the +# License. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see <https://www.gnu.org/licenses>. +# +# SPDX-License-Identifier: GPL-3.0-only +# + +# +# This code is based on: +# +# VirtualBox Guest Additions for Haiku. +# Copyright (c) 2011 Mike Smith <mike@scgtrp.net> +# François Revol <revol@free.fr> +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +SUB_DEPTH = ../../../../.. +include $(KBUILD_PATH)/subheader.kmk + +# @todo split the tray code, +# single bin will cause problems loading gcc4 binary from a gcc2-built Deskbar! + +PROGRAMS += VBoxTray +VBoxTray_TEMPLATE = VBoxGuestR3Exe +VBoxTray_DEFS = VBOX_WITH_HGCM LOG_TO_BACKDOOR +VBoxTray_DEFS += LOG_ENABLED +VBoxTray_INCS = ../include +VBoxTray_SOURCES = \ + VBoxClipboard.cpp \ + VBoxDisplay.cpp \ + VBoxGuestApplication.cpp \ + VBoxGuestDeskbarView.cpp + +VBoxTray_SOURCES += \ + $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/clipboard-helper.cpp + +VBoxTray_LIBS = \ + be translation \ + $(VBOX_LIB_VBGL_R3) \ + $(VBOX_LIB_IPRT_GUEST_R3) \ + $(VBOX_LIB_VBGL_R3) + +VBoxTray_RSRCS += $(VBoxTray_0_OUTDIR)/VBoxTray.rsrc +VBoxTray_DEPS += $(VBoxTray_0_OUTDIR)/VBoxTray.rsrc +VBoxTray_CLEAN += $(VBoxTray_0_OUTDIR)/VBoxTray.rsrc + +# VBoxGuestApplication.cpp uses VBOX_SVN_REV. +VBoxGuestApplication.cpp_DEFS += VBOX_SVN_REV=$(VBOX_SVN_REV) +VBoxGuestApplication.cpp_DEPS = $(VBOX_SVN_REV_KMK) +VBoxGuestDeskbarView.cpp_DEFS += VBOX_SVN_REV=$(VBOX_SVN_REV) +VBoxGuestDeskbarView.cpp_DEPS = $(VBOX_SVN_REV_KMK) + +## The icon location is configurable. +VBoxTray.rdef_INCS = $(VBoxTray_0_OUTDIR) +VBoxTray.rdef_DEFS += VBOX_SVN_REV=$(VBOX_SVN_REV) \ + VBOX_HAIKU_DESKBAR_ICON_PNG=\"$(VBOX_BRAND_GUI_VBOX_16PX_PNG)\" +VBoxTray.rdef_DEPS = $(VBOX_SVN_REV_KMK) + +VBoxTray.rsrc_DEPS = VBoxTray.rdef +VBoxTray.rsrc_CLEAN = VBoxTray.rdef + + + +#XXX: cleanup! +#XXX: handle deps correctly +#XXX: -I / is due to a bug in rc with absolute paths +## Resource file. +$$(VBoxTray_0_OUTDIR)/VBoxTray.rsrc: $$(VBoxTray_DEFPATH)/VBoxTray.rdef $$(VBoxTray_DEFPATH)/Makefile.kmk | $$(dir $$@) + $(call MSG_TOOL,$(VBOX_HAIKU_RCTOOL),HaikuResources,$<,$@) + $(QUIET)cat $< | gcc -E -I $(dir $<) -I $(dir $<)/../include $(foreach name, $(INCS), -I $(name)) $(foreach dname, $(VBoxTray.rdef_DEFS), -D$(dname)) - | grep -v '^#' | $(VBOX_HAIKU_RCTOOL) -I / -I $(dir $<) -I $(dir $<)/../include -o "$@" - + + +# rc -I $(VBoxTray_DEFPATH)/../include -o $@ $< +# $(RM) -f $@ +# $(APPEND) $@ 'IDI_VIRTUALBOX ICON DISCARDABLE "$(subst /,\\,$(VBOX_WINDOWS_ADDITIONS_ICON_FILE))"' + +## The icon location is configurable. +#VBoxTray.rc_INCS = $(VBoxTray_0_OUTDIR) +#VBoxTray.rc_DEPS = $(VBoxTray_0_OUTDIR)/VBoxTray-icon.rc +#VBoxTray.rc_CLEAN = $(VBoxTray_0_OUTDIR)/VBoxTray-icon.rc + +## Icon include file. +#$$(VBoxTray_0_OUTDIR)/VBoxTray-icon.rc: $(VBOX_WINDOWS_ADDITIONS_ICON_FILE) $$(VBoxTray_DEFPATH)/Makefile.kmk | $$(dir $$@) +# $(RM) -f $@ +# $(APPEND) $@ 'IDI_VIRTUALBOX ICON DISCARDABLE "$(subst /,\\,$(VBOX_WINDOWS_ADDITIONS_ICON_FILE))"' + +include $(KBUILD_PATH)/subfooter.kmk + diff --git a/src/VBox/Additions/haiku/VBoxTray/VBoxClipboard.cpp b/src/VBox/Additions/haiku/VBoxTray/VBoxClipboard.cpp new file mode 100644 index 00000000..b500b95d --- /dev/null +++ b/src/VBox/Additions/haiku/VBoxTray/VBoxClipboard.cpp @@ -0,0 +1,468 @@ +/* $Id: VBoxClipboard.cpp $ */ +/** @file + * VBoxClipboard; Haiku Guest Additions, implementation. + */ + +/* + * Copyright (C) 2012-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +/* + * This code is based on: + * + * VirtualBox Guest Additions for Haiku. + * Copyright (c) 2011 Mike Smith <mike@scgtrp.net> + * Fran�ois Revol <revol@free.fr> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <new> +#include <Bitmap.h> +#include <BitmapStream.h> +#include <Clipboard.h> +#include <DataIO.h> +#include <Message.h> +#include <TranslationUtils.h> +#include <TranslatorFormats.h> +#include <TranslatorRoster.h> +#include <String.h> + +#include "VBoxGuestApplication.h" +#include "VBoxClipboard.h" +#include <VBoxGuestInternal.h> + +#include <iprt/mem.h> +#include <VBox/GuestHost/clipboard-helper.h> +#include <VBox/HostServices/VBoxClipboardSvc.h> +#include <VBox/log.h> + +/** @todo r=ramshankar: this hack should go eventually. */ +#ifdef DEBUG_ramshankar +# undef Log +# define Log(x) printf x +# undef LogRel +# define LogRel(x) printf x +# undef LogRelFlowFunc +# define LogRelFlowFunc(x) printf x +#endif + + +VBoxShClService::VBoxShClService() + : BHandler("VBoxShClService"), + fClientId(-1), + fServiceThreadID(-1), + fExiting(false) +{ +} + + +VBoxShClService::~VBoxShClService() +{ +} + + +status_t VBoxShClService::Connect() +{ + status_t err; + LogFlowFunc(("Connect\n")); + + int rc = VbglR3ClipboardConnect(&fClientId); + if (RT_SUCCESS(rc)) + { + err = fServiceThreadID = spawn_thread(_ServiceThreadNub, "VBoxShClService", B_NORMAL_PRIORITY, this); + if (err >= B_OK) + { + resume_thread(fServiceThreadID); + err = be_clipboard->StartWatching(BMessenger(this)); + LogFlow(("be_clipboard->StartWatching: %ld\n", err)); + if (err == B_OK) + return B_OK; + else + LogRel(("VBoxShClService: Error watching the system clipboard: %ld\n", err)); + } + else + LogRel(("VBoxShClService: Error starting service thread: %ld\n", err)); + + //rc = RTErrConvertFromErrno(err); + VbglR3ClipboardDisconnect(fClientId); + } + else + LogRel(("VBoxShClService: Error starting service thread: %d\n", rc)); + return B_ERROR; +} + + +status_t VBoxShClService::Disconnect() +{ + status_t status; + + be_clipboard->StopWatching(BMessenger(this)); + + fExiting = true; + + VbglR3ClipboardDisconnect(fClientId); + + wait_for_thread(fServiceThreadID, &status); + return B_OK; +} + + +void VBoxShClService::MessageReceived(BMessage *message) +{ + uint32_t formats = 0; + message->PrintToStream(); + switch (message->what) + { + case VBOX_GUEST_CLIPBOARD_HOST_MSG_FORMATS: + { + int rc; + uint32_t cb; + void *pv; + bool commit = false; + + if (message->FindInt32("Formats", (int32 *)&formats) != B_OK) + break; + + if (!formats) + break; + + if (!be_clipboard->Lock()) + break; + + be_clipboard->Clear(); + BMessage *clip = be_clipboard->Data(); + if (!clip) + { + be_clipboard->Unlock(); + break; + } + + if (formats & VBOX_SHCL_FMT_UNICODETEXT) + { + pv = _VBoxReadHostClipboard(VBOX_SHCL_FMT_UNICODETEXT, &cb); + if (pv) + { + char *text; + rc = RTUtf16ToUtf8((PCRTUTF16)pv, &text); + if (RT_SUCCESS(rc)) + { + BString str(text); + /** @todo user vboxClipboardUtf16WinToLin() */ + // convert Windows CRLF to LF + str.ReplaceAll("\r\n", "\n"); + // don't include the \0 + clip->AddData("text/plain", B_MIME_TYPE, str.String(), str.Length()); + RTStrFree(text); + commit = true; + } + free(pv); + } + } + + if (formats & VBOX_SHCL_FMT_BITMAP) + { + pv = _VBoxReadHostClipboard(VBOX_SHCL_FMT_BITMAP, &cb); + if (pv) + { + void *pBmp = NULL; + size_t cbBmp = 0; + rc = ShClDibToBmp(pv, cb, &pBmp, &cbBmp); + if (RT_SUCCESS(rc)) + { + BMemoryIO mio(pBmp, cbBmp); + BBitmap *bitmap = BTranslationUtils::GetBitmap(&mio); + if (bitmap) + { + BMessage bitmapArchive; + + /** @todo r=ramshankar: split this into functions with error checking as + * neccessary. */ + if ( bitmap->IsValid() + && bitmap->Archive(&bitmapArchive) == B_OK + && clip->AddMessage("image/bitmap", &bitmapArchive) == B_OK) + { + commit = true; + } + delete bitmap; + } + RTMemFree(pBmp); + } + free(pv); + } + } + + /* + * Make sure we don't bounce this data back to the host, it's impolite. It can also + * be used as a hint to applications probably. + */ + clip->AddBool("FromVirtualBoxHost", true); + if (commit) + be_clipboard->Commit(); + be_clipboard->Unlock(); + break; + } + + case VBOX_GUEST_CLIPBOARD_HOST_MSG_READ_DATA: + { + int rc; + + if (message->FindInt32("Formats", (int32 *)&formats) != B_OK) + break; + + if (!formats) + break; + if (!be_clipboard->Lock()) + break; + + BMessage *clip = be_clipboard->Data(); + if (!clip) + { + be_clipboard->Unlock(); + break; + } + clip->PrintToStream(); + + if (formats & VBOX_SHCL_FMT_UNICODETEXT) + { + const char *text; + int32 textLen; + if (clip->FindData("text/plain", B_MIME_TYPE, (const void **)&text, &textLen) == B_OK) + { + // usually doesn't include the \0 so be safe + BString str(text, textLen); + // convert from LF to Windows CRLF + str.ReplaceAll("\n", "\r\n"); + PRTUTF16 pwsz; + rc = RTStrToUtf16(str.String(), &pwsz); + if (RT_SUCCESS(rc)) + { + uint32_t cb = (RTUtf16Len(pwsz) + 1) * sizeof(RTUTF16); + + rc = VbglR3ClipboardWriteData(fClientId, VBOX_SHCL_FMT_UNICODETEXT, pwsz, cb); + //printf("VbglR3ClipboardWriteData: %d\n", rc); + RTUtf16Free(pwsz); + } + } + } + else if (formats & VBOX_SHCL_FMT_BITMAP) + { + BMessage archivedBitmap; + if (clip->FindMessage("image/bitmap", &archivedBitmap) == B_OK || + clip->FindMessage("image/x-be-bitmap", &archivedBitmap) == B_OK) + { + BBitmap *bitmap = new(std::nothrow) BBitmap(&archivedBitmap); + if (bitmap) + { + // Don't delete bitmap, BBitmapStream will. + BBitmapStream stream(bitmap); + BTranslatorRoster *roster = BTranslatorRoster::Default(); + if (roster && bitmap->IsValid()) + { + BMallocIO bmpStream; + if (roster->Translate(&stream, NULL, NULL, &bmpStream, B_BMP_FORMAT) == B_OK) + { + const void *pDib; + size_t cbDibSize; + /* Strip out the BM header */ + rc = ShClBmpGetDib(bmpStream.Buffer(), bmpStream.BufferLength(), &pDib, &cbDibSize); + if (RT_SUCCESS(rc)) + { + rc = VbglR3ClipboardWriteData(fClientId, VBOX_SHCL_FMT_BITMAP, (void *)pDib, + cbDibSize); + } + } + } + } + } + } + + be_clipboard->Unlock(); + break; + } + + case B_CLIPBOARD_CHANGED: + { + printf("B_CLIPBOARD_CHANGED\n"); + const void *data; + int32 dataLen; + if (!be_clipboard->Lock()) + break; + + BMessage *clip = be_clipboard->Data(); + if (!clip) + { + be_clipboard->Unlock(); + break; + } + + bool fromVBox; + if (clip->FindBool("FromVirtualBoxHost", &fromVBox) == B_OK && fromVBox) + { + // It already comes from the host, discard. + be_clipboard->Unlock(); + break; + } + + if (clip->FindData("text/plain", B_MIME_TYPE, &data, &dataLen) == B_OK) + formats |= VBOX_SHCL_FMT_UNICODETEXT; + + if ( clip->HasMessage("image/bitmap") + || clip->HasMessage("image/x-be-bitmap")) + { + formats |= VBOX_SHCL_FMT_BITMAP; + } + + be_clipboard->Unlock(); + + VbglR3ClipboardReportFormats(fClientId, formats); + break; + } + + case B_QUIT_REQUESTED: + fExiting = true; + break; + + default: + BHandler::MessageReceived(message); + } +} + + +status_t VBoxShClService::_ServiceThreadNub(void *_this) +{ + VBoxShClService *service = (VBoxShClService *)_this; + return service->_ServiceThread(); +} + + +status_t VBoxShClService::_ServiceThread() +{ + printf("VBoxShClService::%s()\n", __FUNCTION__); + + /* The thread waits for incoming messages from the host. */ + for (;;) + { + uint32_t u32Msg; + uint32_t u32Formats; + int rc = VbglR3ClipboardGetHostMsgOld(fClientId, &u32Msg, &u32Formats); + if (RT_SUCCESS(rc)) + { + switch (u32Msg) + { + case VBOX_SHCL_HOST_MSG_FORMATS_REPORT: + { + /* + * The host has announced available clipboard formats. Forward + * the information to the handler. + */ + LogRelFlowFunc(("VBOX_SHCL_HOST_MSG_REPORT_FORMATS u32Formats=%x\n", u32Formats)); + BMessage msg(VBOX_GUEST_CLIPBOARD_HOST_MSG_FORMATS); + msg.AddInt32("Formats", (uint32)u32Formats); + Looper()->PostMessage(&msg, this); + break; + } + + case VBOX_SHCL_HOST_MSG_READ_DATA: + { + /* The host needs data in the specified format. */ + LogRelFlowFunc(("VBOX_SHCL_HOST_MSG_READ_DATA u32Formats=%x\n", u32Formats)); + BMessage msg(VBOX_GUEST_CLIPBOARD_HOST_MSG_READ_DATA); + msg.AddInt32("Formats", (uint32)u32Formats); + Looper()->PostMessage(&msg, this); + break; + } + + case VBOX_SHCL_HOST_MSG_QUIT: + { + /* The host is terminating. */ + LogRelFlowFunc(("VBOX_SHCL_HOST_MSG_QUIT\n")); + fExiting = true; + return VERR_INTERRUPTED; + } + + default: + Log(("VBoxShClService::%s: Unsupported message from host! Message = %u\n", __FUNCTION__, u32Msg)); + } + } + else + fExiting = true; + + LogRelFlow(("processed host event rc = %d\n", rc)); + + if (fExiting) + break; + } + return 0; +} + + +void* VBoxShClService::_VBoxReadHostClipboard(uint32_t format, uint32_t *pcb) +{ + uint32_t cb = 1024; + void *pv; + int rc; + + pv = malloc(cb); + if (pv == NULL) + return NULL; + + rc = VbglR3ClipboardReadData(fClientId, format, pv, cb, pcb); + if (RT_SUCCESS(rc) && (rc != VINF_BUFFER_OVERFLOW)) + return pv; + if (rc == VINF_BUFFER_OVERFLOW) + { + free(pv); + cb = *pcb; + pv = malloc(cb); + if (pv == NULL) + return NULL; + + rc = VbglR3ClipboardReadData(fClientId, format, pv, cb, pcb); + if (RT_SUCCESS(rc) && (rc != VINF_BUFFER_OVERFLOW)) + return pv; + + free(pv); + } + return NULL; +} + diff --git a/src/VBox/Additions/haiku/VBoxTray/VBoxClipboard.h b/src/VBox/Additions/haiku/VBoxTray/VBoxClipboard.h new file mode 100644 index 00000000..ad4cabbd --- /dev/null +++ b/src/VBox/Additions/haiku/VBoxTray/VBoxClipboard.h @@ -0,0 +1,88 @@ +/* $Id: VBoxClipboard.h $ */ +/** @file + * VBoxClipboard, Haiku Guest Additions, header. + */ + +/* + * Copyright (C) 2012-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +/* + * This code is based on: + * + * VirtualBox Guest Additions for Haiku. + * Copyright (c) 2011 Mike Smith <mike@scgtrp.net> + * François Revol <revol@free.fr> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef GA_INCLUDED_SRC_haiku_VBoxTray_VBoxClipboard_h +#define GA_INCLUDED_SRC_haiku_VBoxTray_VBoxClipboard_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <Handler.h> + +class VBoxShClService : public BHandler +{ + public: + VBoxShClService(); + virtual ~VBoxShClService(); + + virtual status_t Connect(); + virtual status_t Disconnect(); + + virtual void MessageReceived(BMessage *message); + + private: + static status_t _ServiceThreadNub(void *_this); + status_t _ServiceThread(); + + void* _VBoxReadHostClipboard(uint32_t format, uint32_t *pcb); + + uint32_t fClientId; + thread_id fServiceThreadID; + bool fExiting; +}; + +#endif /* !GA_INCLUDED_SRC_haiku_VBoxTray_VBoxClipboard_h */ + diff --git a/src/VBox/Additions/haiku/VBoxTray/VBoxDisplay.cpp b/src/VBox/Additions/haiku/VBoxTray/VBoxDisplay.cpp new file mode 100644 index 00000000..5eb0a7d5 --- /dev/null +++ b/src/VBox/Additions/haiku/VBoxTray/VBoxDisplay.cpp @@ -0,0 +1,177 @@ +/* $Id: VBoxDisplay.cpp $ */ +/** @file + * VBoxDisplayService, Haiku Guest Additions, implementation. + */ + +/* + * Copyright (C) 2012-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +/* + * This code is based on: + * + * VirtualBox Guest Additions for Haiku. + * Copyright (c) 2011 Mike Smith <mike@scgtrp.net> + * François Revol <revol@free.fr> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <new> +#include <DataIO.h> +#include <Message.h> +#include <TranslationUtils.h> +#include <TranslatorFormats.h> +#include <TranslatorRoster.h> +#include <String.h> + +#include "VBoxGuestApplication.h" +#include "VBoxDisplay.h" +#include <VBoxGuestInternal.h> +#include "../VBoxVideo/common/VBoxVideo_common.h" + +#include <iprt/mem.h> +#include <VBox/log.h> + +#ifdef DEBUG_ramshankar +# undef Log +# define Log(x) printf x +# undef LogRel +# define LogRel(x) printf x +# undef LogRelFlowFunc +# define LogRelFlowFunc(x) printf x +#endif + +VBoxDisplayService::VBoxDisplayService() + : BHandler("VBoxDisplayService"), + fClientId(-1), + fServiceThreadID(-1), + fExiting(false), + fScreen(B_MAIN_SCREEN_ID) +{ +} + + +VBoxDisplayService::~VBoxDisplayService() +{ +} + + +void VBoxDisplayService::Start() +{ + status_t err; + err = fServiceThreadID = spawn_thread(_ServiceThreadNub, "VBoxDisplayService", B_NORMAL_PRIORITY, this); + if (err >= B_OK) + resume_thread(fServiceThreadID); + else + LogRel(("VBoxDisplayService: Error starting service thread: %s\n", strerror(err))); +} + + +void VBoxDisplayService::MessageReceived(BMessage *message) +{ + if (message->what == B_QUIT_REQUESTED) + fExiting = true; + else + BHandler::MessageReceived(message); +} + + +status_t VBoxDisplayService::_ServiceThreadNub(void *_this) +{ + VBoxDisplayService *service = (VBoxDisplayService *)_this; + return service->_ServiceThread(); +} + + +status_t VBoxDisplayService::_ServiceThread() +{ + LogFlow(("VBoxDisplayService::_ServiceThread")); + + VbglR3CtlFilterMask(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, 0); + VbglR3SetGuestCaps(VMMDEV_GUEST_SUPPORTS_GRAPHICS, 0); + for (;;) + { + uint32_t events; + int rc = VbglR3WaitEvent(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, 5000, &events); + if ( rc == VERR_TIMEOUT + || rc == VERR_INTERRUPTED) + continue; + + if (RT_SUCCESS(rc)) + { + uint32_t cx, cy, cBits, iDisplay; + int rc2 = VbglR3GetDisplayChangeRequest(&cx, &cy, &cBits, &iDisplay, NULL, NULL, NULL, NULL, true); + LogFlow(("rc2=%d screen %d size changed (%d, %d, %d)\n", rc2, iDisplay, cx, cy, cBits)); + + if (RT_SUCCESS(rc2)) + { + display_mode mode; + fScreen.GetMode(&mode); + if (cBits == 0) + cBits = get_depth_for_color_space(mode.space); + + mode.timing.h_display = cx; + mode.timing.v_display = cy; + mode.space = get_color_space_for_depth(cBits); + mode.virtual_width = cx; + mode.virtual_height = cy; + + /*= { + {0, cx, 0, 0, cBits * cx / 8, cy, 0, 0, cBits * cy / 8, 0}, + get_color_space_for_depth(cBits), + cx, cy, 0, 0, 0 + };*/ + + fScreen.SetMode(&mode, false); + } + } + else + fExiting = true; + + LogFlow(("processed host event rc = %d\n", rc)); + if (fExiting) + break; + } + return 0; +} + diff --git a/src/VBox/Additions/haiku/VBoxTray/VBoxDisplay.h b/src/VBox/Additions/haiku/VBoxTray/VBoxDisplay.h new file mode 100644 index 00000000..434cca51 --- /dev/null +++ b/src/VBox/Additions/haiku/VBoxTray/VBoxDisplay.h @@ -0,0 +1,86 @@ +/* $Id: VBoxDisplay.h $ */ +/** @file + * VBoxDisplayService, Haiku Guest Additions, header. + */ + +/* + * Copyright (C) 2012-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +/* + * This code is based on: + * + * VirtualBox Guest Additions for Haiku. + * Copyright (c) 2011 Mike Smith <mike@scgtrp.net> + * François Revol <revol@free.fr> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef GA_INCLUDED_SRC_haiku_VBoxTray_VBoxDisplay_h +#define GA_INCLUDED_SRC_haiku_VBoxTray_VBoxDisplay_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <Handler.h> +#include <Screen.h> + +class VBoxDisplayService : public BHandler +{ + public: + VBoxDisplayService(); + virtual ~VBoxDisplayService(); + + void Start(); + virtual void MessageReceived(BMessage *message); + + private: + static status_t _ServiceThreadNub(void *_this); + status_t _ServiceThread(); + + uint32_t fClientId; + thread_id fServiceThreadID; + volatile bool fExiting; + BScreen fScreen; +}; + +#endif /* !GA_INCLUDED_SRC_haiku_VBoxTray_VBoxDisplay_h */ + diff --git a/src/VBox/Additions/haiku/VBoxTray/VBoxGuestApplication.cpp b/src/VBox/Additions/haiku/VBoxTray/VBoxGuestApplication.cpp new file mode 100644 index 00000000..c2c26762 --- /dev/null +++ b/src/VBox/Additions/haiku/VBoxTray/VBoxGuestApplication.cpp @@ -0,0 +1,101 @@ +/* $Id: VBoxGuestApplication.cpp $ */ +/** @file + * VBoxGuestApplication, Haiku Guest Additions, implementation. + */ + +/* + * Copyright (C) 2012-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +/* + * This code is based on: + * + * VirtualBox Guest Additions for Haiku. + * Copyright (c) 2011 Mike Smith <mike@scgtrp.net> + * François Revol <revol@free.fr> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#include <iprt/log.h> + +#include <errno.h> +#include <Alert.h> +#include <Debug.h> +#include <Invoker.h> +#include <String.h> + +#include "VBoxClipboard.h" +#include "VBoxGuestApplication.h" +#include "VBoxGuestDeskbarView.h" + +VBoxGuestApplication::VBoxGuestApplication() + : BApplication(VBOX_GUEST_APP_SIG) +{ +} + + +VBoxGuestApplication::~VBoxGuestApplication() +{ +} + + +void VBoxGuestApplication::ReadyToRun() +{ + status_t err; + + err = VBoxGuestDeskbarView::AddToDeskbar(); + LogFlow(("VBoxGuestDeskbarView::ReadyToRun: AddToDeskbar returned 0x%08lx\n", err)); + exit(0); +} + + +int main(int argc, const char **argv) +{ + new VBoxGuestApplication(); + be_app->Run(); + delete be_app; + return 0; +} + diff --git a/src/VBox/Additions/haiku/VBoxTray/VBoxGuestApplication.h b/src/VBox/Additions/haiku/VBoxTray/VBoxGuestApplication.h new file mode 100644 index 00000000..d7996740 --- /dev/null +++ b/src/VBox/Additions/haiku/VBoxTray/VBoxGuestApplication.h @@ -0,0 +1,89 @@ +/* $Id: VBoxGuestApplication.h $ */ +/** @file + * VBoxGuestApplication, Haiku Guest Additions, header. + */ + +/* + * Copyright (C) 2012-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +/* + * This code is based on: + * + * VirtualBox Guest Additions for Haiku. + * Copyright (c) 2011 Mike Smith <mike@scgtrp.net> + * François Revol <revol@free.fr> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef GA_INCLUDED_SRC_haiku_VBoxTray_VBoxGuestApplication_h +#define GA_INCLUDED_SRC_haiku_VBoxTray_VBoxGuestApplication_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +/** @todo r=ramshankar; why are we including all the headers here!?? Do it in + * the .cpp please. */ +#include <Application.h> + +#include <iprt/initterm.h> +#include <iprt/string.h> + +#include <VBox/version.h> +#include <VBox/log.h> +#include <VBox/VBoxGuest.h> /** @todo use the VbglR3 interface! */ +#include <VBox/VBoxGuestLib.h> + +#include <VBoxGuestInternal.h> + +class VBoxShClService; + +class VBoxGuestApplication : public BApplication +{ + public: + VBoxGuestApplication(); + virtual ~VBoxGuestApplication(); + + virtual void ReadyToRun(); +}; + +#endif /* !GA_INCLUDED_SRC_haiku_VBoxTray_VBoxGuestApplication_h */ + diff --git a/src/VBox/Additions/haiku/VBoxTray/VBoxGuestDeskbarView.cpp b/src/VBox/Additions/haiku/VBoxTray/VBoxGuestDeskbarView.cpp new file mode 100644 index 00000000..aaba2392 --- /dev/null +++ b/src/VBox/Additions/haiku/VBoxTray/VBoxGuestDeskbarView.cpp @@ -0,0 +1,297 @@ +/* $Id: VBoxGuestDeskbarView.cpp $ */ +/** @file + * VBoxGuestDeskbarView, Haiku Guest Additions, implementation. + */ + +/* + * Copyright (C) 2012-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +/* + * This code is based on: + * + * VirtualBox Guest Additions for Haiku. + * Copyright (c) 2011 Mike Smith <mike@scgtrp.net> + * François Revol <revol@free.fr> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#include <errno.h> +#include <Alert.h> +#include <Roster.h> +#include <Debug.h> +#include <Deskbar.h> +#include <File.h> +#include <MenuItem.h> +#include <Path.h> +#include <PopUpMenu.h> +#include <Resources.h> +#include <String.h> +#include <TranslationUtils.h> + +#include "VBoxGuestDeskbarView.h" +#include "VBoxGuestApplication.h" + +#define VIEWNAME "VBoxGuestDeskbarView" + +static status_t +our_image(image_info& image) +{ + /** @todo r=ramshankar: find a way to do this without annoying the compiler, probably uintptr_t? */ + int32 cookie = 0; + while (get_next_image_info(B_CURRENT_TEAM, &cookie, &image) == B_OK) + { + if ((char *)our_image >= (char *)image.text + && (char *)our_image <= (char *)image.text + image.text_size) + return B_OK; + } + + return B_ERROR; +} + + +VBoxGuestDeskbarView::VBoxGuestDeskbarView() + : BView(BRect(0, 0, 15, 15), VIEWNAME, B_FOLLOW_NONE, + B_WILL_DRAW | B_NAVIGABLE), + fIcon(NULL), fClipboardService(NULL), fDisplayService(NULL) +{ + _Init(); +} + + +VBoxGuestDeskbarView::VBoxGuestDeskbarView(BMessage *archive) + : BView(archive), + fIcon(NULL) +{ + archive->PrintToStream(); + _Init(archive); +} + + +VBoxGuestDeskbarView::~VBoxGuestDeskbarView() +{ + delete fIcon; + if (fClipboardService) + { + fClipboardService->Disconnect(); + delete fClipboardService; + } + VbglR3Term(); +} + + +BArchivable* VBoxGuestDeskbarView::Instantiate(BMessage *data) +{ + if (!validate_instantiation(data, VIEWNAME)) + return NULL; + + return new VBoxGuestDeskbarView(data); +} + + +status_t VBoxGuestDeskbarView::Archive(BMessage *data, bool deep) const +{ + status_t err; + + err = BView::Archive(data, false); + if (err < B_OK) + { + LogRel(("VBoxGuestDeskbarView::Archive failed.rc=%08lx\n", err)); + return err; + } + data->AddString("add_on", VBOX_GUEST_APP_SIG); + data->AddString("class", "VBoxGuestDeskbarView"); + return B_OK; +} + + +void VBoxGuestDeskbarView::Draw(BRect rect) +{ + SetDrawingMode(B_OP_ALPHA); + DrawBitmap(fIcon); +} + + +void VBoxGuestDeskbarView::AttachedToWindow() +{ + BView::AttachedToWindow(); + if (Parent()) + { + SetViewColor(Parent()->ViewColor()); + SetLowColor(Parent()->LowColor()); + } + + if (fClipboardService) /* Don't repeatedly crash deskbar if vboxdev not loaded */ + { + Looper()->AddHandler(fClipboardService); + fClipboardService->Connect(); + } + + if (fDisplayService) + fDisplayService->Start(); +} + + +void VBoxGuestDeskbarView::DetachedFromWindow() +{ + BMessage message(B_QUIT_REQUESTED); + fClipboardService->MessageReceived(&message); + fDisplayService->MessageReceived(&message); +} + + +void VBoxGuestDeskbarView::MouseDown(BPoint point) +{ + int32 buttons = B_PRIMARY_MOUSE_BUTTON; + if (Looper() != NULL && Looper()->CurrentMessage() != NULL) + Looper()->CurrentMessage()->FindInt32("buttons", &buttons); + + BPoint where = ConvertToScreen(point); + + if ((buttons & B_SECONDARY_MOUSE_BUTTON) != 0) + { + BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING, false, false); + menu->SetAsyncAutoDestruct(true); + menu->SetFont(be_plain_font); + + menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED))); + menu->SetTargetForItems(this); + + menu->Go(where, true, true, true); + } +} + + +void VBoxGuestDeskbarView::MessageReceived(BMessage *message) +{ + if (message->what == B_QUIT_REQUESTED) + RemoveFromDeskbar(); + else + BHandler::MessageReceived(message); +} + + +status_t VBoxGuestDeskbarView::AddToDeskbar(bool force) +{ + BDeskbar deskbar; + status_t err; + + if (force) + RemoveFromDeskbar(); + else if (deskbar.HasItem(VIEWNAME)) + return B_OK; + + app_info info; + err = be_app->GetAppInfo(&info); + if (err < B_OK) + return err; + + BPath p(&info.ref); + return deskbar.AddItem(&info.ref); +} + + +status_t VBoxGuestDeskbarView::RemoveFromDeskbar() +{ + BDeskbar deskbar; + return deskbar.RemoveItem(VIEWNAME); +} + + +status_t VBoxGuestDeskbarView::_Init(BMessage *archive) +{ + BString toolTipText; + toolTipText << VBOX_PRODUCT << " Guest Additions "; + toolTipText << VBOX_VERSION_MAJOR << "." << VBOX_VERSION_MINOR << "." << VBOX_VERSION_BUILD; + toolTipText << "r" << VBOX_SVN_REV; + + SetToolTip(toolTipText.String()); + + image_info info; + if (our_image(info) != B_OK) + return B_ERROR; + + BFile file(info.name, B_READ_ONLY); + if (file.InitCheck() < B_OK) + return B_ERROR; + + BResources resources(&file); + if (resources.InitCheck() < B_OK) + return B_ERROR; + + const void *data = NULL; + size_t size; + //data = resources.LoadResource(B_VECTOR_ICON_TYPE, + // kNetworkStatusNoDevice + i, &size); + data = resources.LoadResource('data', 400, &size); + if (data != NULL) + { + BMemoryIO mem(data, size); + fIcon = BTranslationUtils::GetBitmap(&mem); + } + + int rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE); + if (RT_SUCCESS(rc)) + { + rc = VbglR3Init(); + if (RT_SUCCESS(rc)) + { + fClipboardService = new VBoxShClService(); + fDisplayService = new VBoxDisplayService(); + } + else + LogRel(("VBoxGuestDeskbarView::_init VbglR3Init failed. rc=%d\n", rc)); + } + else + LogRel(("VBoxGuestDeskbarView::_init RTR3InitDll failed. rc=%d\n", rc)); + return RTErrConvertToErrno(rc); +} + + +RTDECL(BView*) instantiate_deskbar_item() +{ + return new VBoxGuestDeskbarView(); +} + diff --git a/src/VBox/Additions/haiku/VBoxTray/VBoxGuestDeskbarView.h b/src/VBox/Additions/haiku/VBoxTray/VBoxGuestDeskbarView.h new file mode 100644 index 00000000..be8cfa54 --- /dev/null +++ b/src/VBox/Additions/haiku/VBoxTray/VBoxGuestDeskbarView.h @@ -0,0 +1,109 @@ +/* $Id: VBoxGuestDeskbarView.h $ */ +/** @file + * VBoxGuestDeskbarView, Haiku Guest Additions, header. + */ + +/* + * Copyright (C) 2012-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +/* + * This code is based on: + * + * VirtualBox Guest Additions for Haiku. + * Copyright (c) 2011 Mike Smith <mike@scgtrp.net> + * François Revol <revol@free.fr> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef GA_INCLUDED_SRC_haiku_VBoxTray_VBoxGuestDeskbarView_h +#define GA_INCLUDED_SRC_haiku_VBoxTray_VBoxGuestDeskbarView_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <Bitmap.h> +#include <View.h> + +#include <iprt/initterm.h> +#include <iprt/string.h> + +#include <VBox/version.h> +#include <VBox/log.h> +#include <VBox/VBoxGuest.h> /** @todo use the VbglR3 interface! */ +#include <VBox/VBoxGuestLib.h> + +#include <VBoxGuestInternal.h> +#include "VBoxClipboard.h" +#include "VBoxDisplay.h" + +#define REMOVE_FROM_DESKBAR_MSG 'vbqr' + +class VBoxGuestDeskbarView : public BView +{ + public: + VBoxGuestDeskbarView(); + VBoxGuestDeskbarView(BMessage *archive); + virtual ~VBoxGuestDeskbarView(); + + static BArchivable* Instantiate(BMessage *data); + virtual status_t Archive(BMessage *data, bool deep = true) const; + + void Draw(BRect rect); + void AttachedToWindow(); + void DetachedFromWindow(); + + virtual void MouseDown(BPoint point); + virtual void MessageReceived(BMessage *message); + + static status_t AddToDeskbar(bool force = true); + static status_t RemoveFromDeskbar(); + + private: + status_t _Init(BMessage *archive = NULL); + BBitmap *fIcon; + + VBoxShClService *fClipboardService; + VBoxDisplayService *fDisplayService; +}; + +#endif /* !GA_INCLUDED_SRC_haiku_VBoxTray_VBoxGuestDeskbarView_h */ + diff --git a/src/VBox/Additions/haiku/VBoxTray/VBoxServiceDescriptor.h b/src/VBox/Additions/haiku/VBoxTray/VBoxServiceDescriptor.h new file mode 100644 index 00000000..0a1a0e6e --- /dev/null +++ b/src/VBox/Additions/haiku/VBoxTray/VBoxServiceDescriptor.h @@ -0,0 +1,78 @@ +/* $Id: VBoxServiceDescriptor.h $ */ +/** @file + * VBoxGuestServiceDescriptor, Haiku Guest Additions, header. + */ + +/* + * Copyright (C) 2012-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +/* + * This code is based on: + * + * VirtualBox Guest Additions for Haiku. + * Copyright (c) 2011 Mike Smith <mike@scgtrp.net> + * François Revol <revol@free.fr> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef GA_INCLUDED_SRC_haiku_VBoxTray_VBoxServiceDescriptor_h +#define GA_INCLUDED_SRC_haiku_VBoxTray_VBoxServiceDescriptor_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <Handler.h> + +class VBoxShClService : public BHandler +{ + public: + VBoxShClService(); + virtual ~VBoxShClService(); +}; + +/* The shared clipboard service prototypes. */ +int VBoxShClInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread); +unsigned __stdcall VBoxShClThread(void *pInstance); +void VBoxShClDestroy(const VBOXSERVICEENV *pEnv, void *pInstance); + +#endif /* !GA_INCLUDED_SRC_haiku_VBoxTray_VBoxServiceDescriptor_h */ + diff --git a/src/VBox/Additions/haiku/VBoxTray/VBoxTray.rdef b/src/VBox/Additions/haiku/VBoxTray/VBoxTray.rdef new file mode 100644 index 00000000..f2bd244c --- /dev/null +++ b/src/VBox/Additions/haiku/VBoxTray/VBoxTray.rdef @@ -0,0 +1,93 @@ +/* $Id: VBoxTray.rdef $ */ +/** @file + * VBoxApp - Resource definition file containing version info and icon, Haiku Guest Additions. + */ + +/* + * Copyright (C) 2012-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + *----------------------------------------------------------------------------- + * + * This code is based on: + * + * VirtualBox Guest Additions for Haiku. + * Copyright (c) 2011 Mike Smith <mike@scgtrp.net> + * François Revol <revol@free.fr> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "VBoxGuestInternal.h" + +resource(1, "BEOS:APP_SIG") #'MIMS' VBOX_GUEST_APP_SIG; + +resource app_flags B_SINGLE_LAUNCH; + +/* This is done for all binaries with VBOX_HAIKU_XRES_SETVER_CMDS +resource app_version { + major = VBOX_VERSION_MAJOR, + middle = VBOX_VERSION_MINOR, + minor = VBOX_VERSION_BUILD, + + variety = B_APPV_DEVELOPMENT, + internal = VBOX_SVN_REV, + + short_info = VBOX_PRODUCT, + long_info = VBOX_PRODUCT " " VBOX_VERSION_STRING " ©2009-" VBOX_C_YEAR " " VBOX_VENDOR +}; +*/ + +/* Maybe one day ? */ +//resource(1, "BEOS:FILE_TYPES") message { +// "types" = "application/x-vnd.Be.URL.vboxsf" +//}; + +resource vector_icon { + $"6E636966060500020006023B55F13C5CD2BE755C3D78974A454E48FFCB000EB3" + $"B5FF003BFF020006023CD471BA2F923B0FF33DF6F048DA184417BB0000FBFFFF" + $"0000FF020006023C318B3A487CBD09B43EEB2D4B485C48176F0000AAFFFF0537" + $"C704016D05FF070A062231224E3E5C5248522D37260A042231224E3E5C3E3A0A" + $"0422313E3A522D37260A043E5C5248522D3E3A0A043E5E4E5E60485444080835" + $"3A393B3C4442384441493A4B444F460A04352E503750533547060A040104000A" + $"0001001001178400040A010101000A020102000A030103000A05020506123F45" + $"D10000000000003F45D1C70BA246F45D0117820004" +}; + +resource(400, "DeskbarShelfIcon.png") #'data' import VBOX_HAIKU_DESKBAR_ICON_PNG; + |