Checking in some input-related stuff Marc sent me awhile ago
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3924 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+299
-155
@@ -1,155 +1,299 @@
|
|||||||
/***********************************************************************
|
//------------------------------------------------------------------------------
|
||||||
* AUTHOR: nobody <baron>
|
// Copyright (c) 2001-2002, OpenBeOS
|
||||||
* FILE: Input.cpp
|
//
|
||||||
* DATE: Sun Dec 16 15:57:43 2001
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* DESCR:
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
***********************************************************************/
|
// to deal in the Software without restriction, including without limitation
|
||||||
#include "Input.h"
|
// 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:
|
||||||
* Method: BInputDevice::~BInputDevice()
|
//
|
||||||
* Descr:
|
// The above copyright notice and this permission notice shall be included in
|
||||||
*/
|
// all copies or substantial portions of the Software.
|
||||||
BInputDevice::~BInputDevice()
|
//
|
||||||
{
|
// 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
|
||||||
* Method: BInputDevice::Name()
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
* Descr:
|
// DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
//
|
||||||
const char *
|
// File Name: Input.cpp
|
||||||
BInputDevice::Name() const
|
// Author: Marc Flerackers ([email protected])
|
||||||
{
|
// Description: Functions and class to manage input devices.
|
||||||
return NULL;
|
//------------------------------------------------------------------------------
|
||||||
}
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
#include <malloc.h>
|
||||||
/*
|
#include <string.h>
|
||||||
* Method: BInputDevice::Type()
|
|
||||||
* Descr:
|
// System Includes -------------------------------------------------------------
|
||||||
*/
|
#include <Input.h>
|
||||||
input_device_type
|
#include <Message.h>
|
||||||
BInputDevice::Type() const
|
#include <Errors.h>
|
||||||
{
|
#include <List.h>
|
||||||
input_device_type dummy;
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
return dummy;
|
|
||||||
}
|
// Local Includes --------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
/*
|
|
||||||
* Method: BInputDevice::IsRunning()
|
// Globals ---------------------------------------------------------------------
|
||||||
* Descr:
|
|
||||||
*/
|
BMessenger *input_server=NULL;
|
||||||
bool
|
|
||||||
BInputDevice::IsRunning() const
|
_IMPEXP_BE status_t _control_input_server_(BMessage *command, BMessage *reply);
|
||||||
{
|
|
||||||
bool dummy;
|
/*static bool PrintNameAndDelete(void *ptr)
|
||||||
|
{
|
||||||
return dummy;
|
if(ptr)
|
||||||
}
|
{
|
||||||
|
BInputDevice *dev = (BInputDevice *)ptr;
|
||||||
|
printf("* %s : %s\n", dev->Name(), dev->IsRunning() ? "running" : "not running");
|
||||||
/*
|
delete dev;
|
||||||
* Method: BInputDevice::Start()
|
return false;
|
||||||
* Descr:
|
}
|
||||||
*/
|
|
||||||
status_t
|
return true;
|
||||||
BInputDevice::Start()
|
}
|
||||||
{
|
|
||||||
status_t dummy;
|
void PrintDevices()
|
||||||
|
{
|
||||||
return dummy;
|
BList devices;
|
||||||
}
|
|
||||||
|
status_t err = get_input_devices(&devices);
|
||||||
|
|
||||||
/*
|
if(err != B_OK)
|
||||||
* Method: BInputDevice::Stop()
|
printf("Error while getting input devices\n");
|
||||||
* Descr:
|
else
|
||||||
*/
|
{
|
||||||
status_t
|
devices.DoForEach(PrintNameAndDelete);
|
||||||
BInputDevice::Stop()
|
devices.MakeEmpty();
|
||||||
{
|
}
|
||||||
status_t dummy;
|
}*/
|
||||||
|
|
||||||
return dummy;
|
//------------------------------------------------------------------------------
|
||||||
}
|
BInputDevice *find_input_device(const char *name)
|
||||||
|
{
|
||||||
|
BMessage command('Ifdv');
|
||||||
/*
|
BMessage reply;
|
||||||
* Method: BInputDevice::Control()
|
|
||||||
* Descr:
|
command.AddString("device", name);
|
||||||
*/
|
|
||||||
status_t
|
status_t err = _control_input_server_(&command, &reply);
|
||||||
BInputDevice::Control(uint32 code,
|
|
||||||
BMessage *message)
|
if (err != B_OK)
|
||||||
{
|
return NULL;
|
||||||
status_t dummy;
|
|
||||||
|
BInputDevice *dev = new BInputDevice;
|
||||||
return dummy;
|
|
||||||
}
|
const char *device;
|
||||||
|
int32 type;
|
||||||
|
|
||||||
/*
|
reply.FindString("device", &device);
|
||||||
* Method: BInputDevice::Start()
|
reply.FindInt32("type", &type);
|
||||||
* Descr:
|
|
||||||
*/
|
dev->set_name_and_type(device, (input_device_type)type);
|
||||||
status_t
|
|
||||||
BInputDevice::Start(input_device_type type)
|
return dev;
|
||||||
{
|
}
|
||||||
status_t dummy;
|
//------------------------------------------------------------------------------
|
||||||
|
status_t get_input_devices(BList *list)
|
||||||
return dummy;
|
{
|
||||||
}
|
list->MakeEmpty();
|
||||||
|
|
||||||
|
BMessage command('Ifdv');
|
||||||
/*
|
BMessage reply;
|
||||||
* Method: BInputDevice::Stop()
|
|
||||||
* Descr:
|
status_t err = _control_input_server_(&command, &reply);
|
||||||
*/
|
|
||||||
status_t
|
if (err != B_OK)
|
||||||
BInputDevice::Stop(input_device_type type)
|
return err;
|
||||||
{
|
|
||||||
status_t dummy;
|
const char *name;
|
||||||
|
int32 type;
|
||||||
return dummy;
|
int32 i = 0;
|
||||||
}
|
|
||||||
|
while (reply.FindString("device", i, &name) == B_OK)
|
||||||
|
{
|
||||||
/*
|
reply.FindInt32("type", i++, &type);
|
||||||
* Method: BInputDevice::Control()
|
|
||||||
* Descr:
|
BInputDevice *dev = new BInputDevice;
|
||||||
*/
|
|
||||||
status_t
|
dev->set_name_and_type(name, (input_device_type)type);
|
||||||
BInputDevice::Control(input_device_type type,
|
|
||||||
uint32 code,
|
list->AddItem(dev);
|
||||||
BMessage *message)
|
}
|
||||||
{
|
|
||||||
status_t dummy;
|
return err;
|
||||||
|
}
|
||||||
return dummy;
|
//------------------------------------------------------------------------------
|
||||||
}
|
status_t watch_input_devices(BMessenger target, bool start)
|
||||||
|
{
|
||||||
|
BMessage command('Iwdv');
|
||||||
/*
|
BMessage reply;
|
||||||
* Method: BInputDevice::BInputDevice()
|
|
||||||
* Descr:
|
command.AddMessenger("target", target);
|
||||||
*/
|
command.AddBool("start", start);
|
||||||
BInputDevice::BInputDevice()
|
|
||||||
{
|
return _control_input_server_(&command, &reply);
|
||||||
}
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
BInputDevice::~BInputDevice()
|
||||||
/*
|
{
|
||||||
* Method: BInputDevice::set_name_and_type()
|
if (fName)
|
||||||
* Descr:
|
free (fName);
|
||||||
*/
|
}
|
||||||
void
|
//------------------------------------------------------------------------------
|
||||||
BInputDevice::set_name_and_type(const char *name,
|
const char *BInputDevice::Name() const
|
||||||
input_device_type type)
|
{
|
||||||
{
|
return fName;
|
||||||
}
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
input_device_type BInputDevice::Type() const
|
||||||
|
{
|
||||||
|
return fType;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
bool BInputDevice::IsRunning() const
|
||||||
|
{
|
||||||
|
if (!fName)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
BMessage command('Idvr');
|
||||||
|
BMessage reply;
|
||||||
|
|
||||||
|
command.AddString("device", fName);
|
||||||
|
|
||||||
|
return _control_input_server_(&command, &reply) == B_OK;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
status_t BInputDevice::Start()
|
||||||
|
{
|
||||||
|
if (!fName)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
BMessage command('Istd');
|
||||||
|
BMessage reply;
|
||||||
|
|
||||||
|
command.AddString("device", fName);
|
||||||
|
|
||||||
|
return _control_input_server_(&command, &reply);
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
status_t BInputDevice::Stop()
|
||||||
|
{
|
||||||
|
if (!fName)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
BMessage command('Ispd');
|
||||||
|
BMessage reply;
|
||||||
|
|
||||||
|
command.AddString("device", fName);
|
||||||
|
|
||||||
|
return _control_input_server_(&command, &reply);
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
status_t BInputDevice::Control(uint32 code, BMessage *message)
|
||||||
|
{
|
||||||
|
if (!fName)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
BMessage command('Icnd');
|
||||||
|
BMessage reply;
|
||||||
|
|
||||||
|
command.AddString("device", fName);
|
||||||
|
command.AddInt32("code", code);
|
||||||
|
command.AddMessage("message", message);
|
||||||
|
|
||||||
|
message->MakeEmpty();
|
||||||
|
|
||||||
|
status_t err = _control_input_server_(&command, &reply);
|
||||||
|
|
||||||
|
if (err == B_OK)
|
||||||
|
reply.FindMessage("message", message);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
status_t BInputDevice::Start(input_device_type type)
|
||||||
|
{
|
||||||
|
BMessage command('Istd');
|
||||||
|
BMessage reply;
|
||||||
|
|
||||||
|
command.AddInt32("type", type);
|
||||||
|
|
||||||
|
return _control_input_server_(&command, &reply);
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
status_t BInputDevice::Stop(input_device_type type)
|
||||||
|
{
|
||||||
|
BMessage command('Ispd');
|
||||||
|
BMessage reply;
|
||||||
|
|
||||||
|
command.AddInt32("type", type);
|
||||||
|
|
||||||
|
return _control_input_server_(&command, &reply);
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
status_t BInputDevice::Control(input_device_type type, uint32 code,
|
||||||
|
BMessage *message)
|
||||||
|
{
|
||||||
|
BMessage command('Icnd');
|
||||||
|
BMessage reply;
|
||||||
|
|
||||||
|
command.AddInt32("type", type);
|
||||||
|
command.AddInt32("code", code);
|
||||||
|
command.AddMessage("message", message);
|
||||||
|
|
||||||
|
message->MakeEmpty();
|
||||||
|
|
||||||
|
status_t err = _control_input_server_(&command, &reply);
|
||||||
|
|
||||||
|
if (err == B_OK)
|
||||||
|
reply.FindMessage("message", message);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
BInputDevice::BInputDevice()
|
||||||
|
{
|
||||||
|
fName = NULL;
|
||||||
|
fType = B_UNDEFINED_DEVICE;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
void BInputDevice::set_name_and_type(const char *name, input_device_type type)
|
||||||
|
{
|
||||||
|
if (fName)
|
||||||
|
{
|
||||||
|
free (fName);
|
||||||
|
fName = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name)
|
||||||
|
fName = strdup(name);
|
||||||
|
|
||||||
|
fType = type;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
status_t _control_input_server_(BMessage *command, BMessage *reply)
|
||||||
|
{
|
||||||
|
if (!input_server)
|
||||||
|
input_server = new BMessenger;
|
||||||
|
|
||||||
|
if (!input_server->IsValid())
|
||||||
|
*input_server = BMessenger("Application/x-vnd.Be-input_server", -1, NULL);
|
||||||
|
|
||||||
|
status_t err = input_server->SendMessage(command, reply);
|
||||||
|
|
||||||
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
if (reply->FindInt32("status", err) != B_OK)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ INTERFACE_KIT_SOURCE =
|
|||||||
Deskbar.cpp
|
Deskbar.cpp
|
||||||
Font.cpp
|
Font.cpp
|
||||||
Globals.cpp
|
Globals.cpp
|
||||||
|
Input.cpp
|
||||||
Picture.cpp
|
Picture.cpp
|
||||||
PictureButton.cpp
|
PictureButton.cpp
|
||||||
Point.cpp
|
Point.cpp
|
||||||
|
|||||||
Reference in New Issue
Block a user