int Window::listen_event(int event_mask, grEvent* grevent) { acquire_sem(_locker); _event_queue.Lock(); BMessage* m = _event_queue.NextMessage(); if (!_event_queue.IsEmpty()) release_sem(_locker); _event_queue.Unlock(); grevent->type = gr_key_down; grevent->key = (grKey)m->what; delete m; return 0; }
status_t WPASupplicantApp::_EnqueueAndNotify(BMessage *message) { if (!fEventQueue.Lock()) return B_ERROR; fEventQueue.AddMessage(message); fEventQueue.Unlock(); return _NotifyEventLoop(); }
/*! \brief Adds an IsAppRegistered() request to the given map. If something goes wrong, the method deletes the request. \param map The map the request shall be added to. \param key The key under which to add the request. \param request The request message to be added. */ void TRoster::_AddIARRequest(IARRequestMap& map, int32 key, BMessage* request) { IARRequestMap::iterator it = map.find(key); BMessageQueue* requests = NULL; if (it == map.end()) { requests = new(nothrow) BMessageQueue(); if (!requests) { delete request; return; } map[key] = requests; } else requests = it->second; requests->AddMessage(request); }
void BWebPage::skipToLastMessage(BMessage*& message) { // NOTE: All messages that are fast-forwarded like this // need to be flagged with the intended target BWebPage, // or else we steal or process messages intended for another // BWebPage here! bool first = true; BMessageQueue* queue = Looper()->MessageQueue(); int32 index = 0; while (BMessage* nextMessage = queue->FindMessage(message->what, index)) { BHandler* target = 0; nextMessage->FindPointer("target", reinterpret_cast<void**>(&target)); if (target != this) { index++; continue; } if (!first) delete message; message = nextMessage; queue->RemoveMessage(message); first = false; } }
void ArpRemoteTerminal::MessageReceived(BMessage *message) { ArpD(cdb << ADH << "ArpRemoteTerminal::MessageReceived: " << *message << endl); switch( message->what ) { case TERM_XFER_TEXT_MSG: { #if 1 const ichar* txt = NULL; long len=0; int32 idx=0; while( message->FindData("text", B_ASCII_TYPE, idx, (const void**)&txt, &len) == B_NO_ERROR ) { if( txt && len > 0 ) { Emulator().EmulateToTTY(txt,len); } idx++; } message->SendReply(B_NO_REPLY); #else int32 recpos = 0; BMessage* curmsg = Window()->DetachCurrentMessage(); BMessageQueue* queue = Window()->MessageQueue(); while( curmsg ) { ichar* txt = NULL; long len=0; int32 idx=0; while( curmsg->FindData("text", B_ASCII_TYPE, idx, &txt, &len) == B_NO_ERROR ) { if( txt ) { if( recpos + len > sizeof(receiveBuffer) ) { if( recpos > 0 ) { Emulator().EmulateToTTY(&receiveBuffer[0],recpos); recpos = 0; } } if( len > sizeof(receiveBuffer) ) { Emulator().EmulateToTTY(txt,len); } else { memcpy(&receiveBuffer[recpos],txt,len); recpos += len; } } idx++; } delete curmsg; curmsg = NULL; if( queue ) { curmsg = queue->FindMessage((int32)0); if( curmsg && curmsg->what == TERM_XFER_TEXT_MSG ) { curmsg = queue->NextMessage(); } else curmsg = NULL; } } if( recpos > 0 ) { Emulator().EmulateToTTY(&receiveBuffer[0],recpos); } return; #endif } break; case TERM_RESET_MSG: { bool hard = false; if( message->FindBool("hard", &hard) != B_OK ) hard = false; Emulator().Reset(hard); TermClean(); // HACK: The emulator often changes the terminal's mode // flags after calling its reset, leaving any active // settings view with incorrect settings. Until we can // do better at tracking state changes, for this situation // send another update to the settings view. if( HaveWatchers() ) { BMessage config; if( GetConfiguration(&config) == B_NO_ERROR ) { ArpD(cdb << ADH << "Reporting change: " << config << endl); ReportChange(&config); } } } break; case TERM_START_SESSION_MSG: { StartSession(); TermClean(); Owner().SendMessage(message); } break; case TERM_END_SESSION_MSG: { EndSession(); TermClean(); Owner().SendMessage(message); } break; case TERM_REQUEST_STATUS_MSG: { int32 rows,cols; TermGetSize(&rows,&cols); SendSizeMsg(rows,cols); SendEmulatorsMsg(); } break; case TERM_WINDOW_SIZE_MSG: { int32 rows,cols; TermGetFixedSize(&rows,&cols); message->FindInt32("rows",&rows); message->FindInt32("columns",&cols); TermSetFixedSize(rows,cols); } break; case TERM_SELECT_EMULATION_MSG: { BMenuItem* item = NULL; if( message->FindPointer("source",(void**)&item) ) item = NULL; BMenu* menu = NULL; if( item ) menu = item->Menu(); int32 num=0; type_code type; if( !message->GetInfo("name",&type,&num) ) { for( int i=0; i<num; i++ ) { const char* str; if( !message->FindString("name",i,&str) ) { delete SetEmulator(str); if( !IsDefaultEmulator() ) { if( menu ) CheckEmulationMenu(menu); return; } } } } if( menu ) CheckEmulationMenu(menu); } break; case ARP_PUT_CONFIGURATION_MSG: { BMessage config; if( message->FindMessage("settings",&config) == B_NO_ERROR ) { PutConfiguration(&config); } else { inherited::MessageReceived(message); } } break; case TERM_ADD_WATCHER_MSG: { BMessenger w; if( message->FindMessenger("watch",&w) == B_NO_ERROR ) { AddWatcher(w); BMessage config; if( GetConfiguration(&config) == B_NO_ERROR ) { ReportChange(&config, &w); } } else { inherited::MessageReceived(message); } } break; case TERM_REM_WATCHER_MSG: { BMessenger w; if( message->FindMessenger("watch",&w) == B_NO_ERROR ) { RemWatcher(w); } else { inherited::MessageReceived(message); } } break; default: inherited::MessageReceived(message); } }
void ObjectView::MessageReceived(BMessage *inMsg) { BPoint delta(0, 0), where(0, 0); if (inMsg->WasDropped()) { where = inMsg->DropPoint(&delta); ConvertFromScreen(&where); } switch (inMsg->what) { case REDISPLAY_OBJECT: { BRect r; BMessageQueue *q = Window()->MessageQueue(); BMessage *m=nullptr; if (inMsg->HasRect("rect")) { r = inMsg->FindRect("rect"); } else { r = Bounds(); } for (int count=0; m=q->FindMessage(REDISPLAY_OBJECT, count); count++) { ObjectView *ov=nullptr; m->FindPointer("object", (void**)&ov); if (ov == this) { BRect s; if (m->HasRect("rect")) { s = m->FindRect("rect"); s.left = Min(s.left,r.left); s.right = Max(s.right, r.right); m->ReplaceRect("rect", s); } else { s = r; m->AddRect("rect", s); } return; } } Draw(r); break; } case SET_COLOR: { rgb_color *p; ssize_t sz; inMsg->FindData("color", B_RAW_TYPE, (const void **)&p, &sz); color.red = p->red; color.green = p->green; color.blue = p->blue; ReDraw(); break; } case SET_DISPLAY_MODE: { rgb_color *p; int32 md = inMsg->FindInt32("display mode"); SetDisplayMode(md); break; } default: BView::MessageReceived(inMsg); break; } }
void BWebPage::MessageReceived(BMessage* message) { switch (message->what) { case HANDLE_SHUTDOWN: // NOTE: This message never arrives here when the BApplication is already // processing B_QUIT_REQUESTED. Then the view will be detached and instruct // the BWebPage handler to shut itself down, but BApplication will not // process additional messages. That's why the windows containing WebViews // are detaching the views already in their QuitRequested() hooks and // LauncherApp calls these hooks already in its own QuitRequested() hook. Looper()->RemoveHandler(this); delete this; // TOAST! return; case HANDLE_LOAD_URL: handleLoadURL(message); break; case HANDLE_RELOAD: handleReload(message); break; case HANDLE_GO_BACK: handleGoBack(message); break; case HANDLE_GO_FORWARD: handleGoForward(message); break; case HANDLE_STOP_LOADING: handleStop(message); break; case HANDLE_SET_VISIBLE: handleSetVisible(message); break; case HANDLE_DRAW: { bool first = true; BMessageQueue* queue = Looper()->MessageQueue(); BRect updateRect; message->FindRect("update rect", &updateRect); int32 index = 0; while (BMessage* nextMessage = queue->FindMessage(message->what, index)) { BHandler* target = 0; nextMessage->FindPointer("target", reinterpret_cast<void**>(&target)); if (target != this) { index++; continue; } if (!first) { delete message; first = false; } message = nextMessage; queue->RemoveMessage(message); BRect rect; message->FindRect("update rect", &rect); updateRect = updateRect | rect; } paint(updateRect, false); break; } case HANDLE_FRAME_RESIZED: skipToLastMessage(message); handleFrameResized(message); break; case HANDLE_FOCUSED: handleFocused(message); break; case HANDLE_ACTIVATED: handleActivated(message); break; case B_MOUSE_MOVED: skipToLastMessage(message); // fall through case B_MOUSE_DOWN: case B_MOUSE_UP: handleMouseEvent(message); break; case B_MOUSE_WHEEL_CHANGED: handleMouseWheelChanged(message); break; case B_KEY_DOWN: case B_KEY_UP: handleKeyEvent(message); break; case HANDLE_CHANGE_ZOOM_FACTOR: handleChangeZoomFactor(message); break; case HANDLE_FIND_STRING: handleFindString(message); break; case HANDLE_SET_STATUS_MESSAGE: { BString status; if (message->FindString("string", &status) == B_OK) setStatusMessage(status); break; } case HANDLE_RESEND_NOTIFICATIONS: handleResendNotifications(message); break; case HANDLE_SEND_EDITING_CAPABILITIES: handleSendEditingCapabilities(message); break; case HANDLE_SEND_PAGE_SOURCE: handleSendPageSource(message); break; case B_REFS_RECEIVED: { RefPtr<FileChooser>* chooser; if (message->FindPointer("chooser", reinterpret_cast<void**>(&chooser)) == B_OK) { entry_ref ref; BPath path; Vector<String> filenames; for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) { path.SetTo(&ref); filenames.append(String(path.Path())); } (*chooser)->chooseFiles(filenames); delete chooser; } break; } case B_CANCEL: { int32 oldWhat; BFilePanel* panel; if (message->FindPointer("source", reinterpret_cast<void**>(&panel)) == B_OK && message->FindInt32("old_what", &oldWhat) == B_OK && oldWhat == B_REFS_RECEIVED) { // TODO: Eventually it would be nice to reuse the same file panel... // At least don't leak the file panel for now. delete panel; } break; } default: BHandler::MessageReceived(message); } }