1/* 2 * Copyright 1999-2009 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Jeremy Friesner 7 */ 8 9 10#include "CommandExecutor.h" 11 12#include <stdio.h> 13#include <string.h> 14#include <stdlib.h> 15 16#include <image.h> 17 18#include "ShortcutsFilterConstants.h" 19#include "CommandActuators.h" 20 21 22CommandExecutor::CommandExecutor() 23 : 24 BLooper("Shortcuts commands executor") 25{ 26} 27 28 29CommandExecutor::~CommandExecutor() 30{ 31} 32 33 34// Returns true if it is returning valid results into (*setBegin) and 35// (*setEnd). If returning true, (*setBegin) now points to the first char in a 36// new word, and (*setEnd) now points to the char after the last char in the 37// word, which has been set to a NUL byte. 38bool 39CommandExecutor::GetNextWord(char** setBegin, char** setEnd) const 40{ 41 char* next = *setEnd; 42 // we'll start one after the end of the last one... 43 44 while (next++) { 45 if (*next == '\0') 46 return false; // no words left! 47 else if (*next <= ' ') 48 *next = '\0'; 49 else 50 break; // found a non-whitespace char! 51 } 52 53 *setBegin = next; 54 // we found the first char! 55 56 while (next++) { 57 if (*next <= ' ') { 58 *next = '\0'; // terminate the word 59 *setEnd = next; 60 return true; 61 } 62 } 63 64 return false; 65 // should never get here, actuatorually 66} 67 68 69void 70CommandExecutor::MessageReceived(BMessage* message) 71{ 72 switch(message->what) { 73 case B_UNMAPPED_KEY_DOWN: 74 case B_KEY_DOWN: 75 { 76 BMessage actuatorMessage; 77 void* asyncData; 78 if ((message->FindMessage("act", &actuatorMessage) == B_OK) 79 && (message->FindPointer("adata", &asyncData) == B_OK)) { 80 BArchivable* archivedObject 81 = instantiate_object(&actuatorMessage); 82 if (archivedObject != NULL) { 83 CommandActuator* actuator 84 = dynamic_cast<CommandActuator*>(archivedObject); 85 86 if (actuator) 87 actuator->KeyEventAsync(message, asyncData); 88 delete archivedObject; 89 } 90 } 91 break; 92 } 93 } 94} 95