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