JumpingCubeWindow::JumpingCubeWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::JumpingCubeWindow)
{
    ui->setupUi(this);
    //ui->gameDisplay->
    currentplayer = 0;
    boardWidth = 8;
    boardHeight = 8;

    board = new int*[boardWidth];
    for (int i = 0; i < boardWidth; ++i) {
      board[i] = new int[boardHeight];
      for (int j = 0; j < boardHeight; ++j) {
          board[i][j] = getNumSides(i,j);
      }
    }


    boardOwner = new int*[boardWidth];
    for (int i = 0; i < boardWidth; ++i) {
      boardOwner[i] = new int[boardHeight];
      for (int j = 0; j < boardHeight; ++j) {
          boardOwner[i][j] = -1;
      }
    }


    timer=new QTimer(this);
    connect(timer,SIGNAL(timeout()),SLOT(on_timer()));
    timer->start(500);

    exploding = false;

}
void worker_loop(int channel_fd)
{
	int epoll_fd = epoll_init();

	if(channel_fd < 0 || epoll_fd < 0)
		exit(1);

	if(epoll_add_event(epoll_fd, EPOLLIN, channel_fd) == L_HTTP_FAIL) {
		printf("add channel_fd fail\n");
		return;
	}


	while (1) {
		if(worker_epoll_start(epoll_fd, MAX_CONNECTION, channel_fd) < 0) {
			if(errno == EINTR)
				continue;
			break;
		}
	
		on_timer(epoll_fd);
	}

	close(channel_fd);
	close(epoll_fd);
}
示例#3
0
文件: timer.c 项目: nhst/trema
/**
 * Moves over the timer callback list and checks if that timer has expired. Incase it has, calls on_timer which 
 * inturn calls callback associated with that timer.
 * @param None
 * @return None
 */
void
execute_timer_events() {
  struct timespec now;
  timer_callback *callback;
  dlist_element *element, *element_next;

  debug( "Executing timer events ( timer_callbacks = %p ).", timer_callbacks );

  assert( clock_gettime( CLOCK_MONOTONIC, &now ) == 0 );
  assert( timer_callbacks != NULL );

  // TODO: timer_callbacks should be a list which is sorted by expiry time
  for ( element = timer_callbacks->next; element; element = element_next ) {
    element_next = element->next;
    callback = element->data;
    if ( callback->function != NULL
         && ( ( callback->expires_at.tv_sec < now.tv_sec )
              || ( ( callback->expires_at.tv_sec == now.tv_sec )
                   && ( callback->expires_at.tv_nsec <= now.tv_nsec ) ) ) ) {
      on_timer( callback );
    }
    if ( callback->function == NULL ) {
      xfree( callback );
      delete_dlist_element( element );
    }
  }
}
示例#4
0
static void
_execute_timer_events( int *next_timeout_usec ) {
    assert( next_timeout_usec != NULL );

    timer_read_begin();
    struct timer_info *timer = get_timer_info();
    timer_read_end();
    assert( timer != NULL );

    debug( "Executing timer events ( timer_callbacks = %p ).", timer->timer_callbacks );

    struct timespec now = { 0, 0 };
    assert( clock_gettime( CLOCK_MONOTONIC, &now ) == 0 );
    assert( timer->timer_callbacks != NULL );

    timer_callback_info *callback = NULL;
    dlist_element *element_next = NULL;
    for ( dlist_element *element = timer->timer_callbacks->next; element; element = element_next ) {
        element_next = element->next;
        callback = element->data;
        if ( callback->function != NULL ) {
            if ( TIMESPEC_LESS_THEN( &now, &callback->expires_at ) ) {
                break;
            }
            on_timer( callback, &now );
        }
        delete_dlist_element( element );
        if ( callback->function == NULL ) {
            xfree( callback );
        }
        else {
            insert_timer_callback( timer, callback );
        }
    }

    struct timespec max_timeout = { ( INT_MAX / 1000000 ), 0 };
    struct timespec min_timeout = { 0, 0 };
    if ( timer->timer_callbacks->next == NULL ) {
        TIMESPEC_TO_MICROSECONDS( &max_timeout, next_timeout_usec );
    }
    else {
        callback = timer->timer_callbacks->next->data;
        if ( TIMESPEC_LESS_THEN( &callback->expires_at, &now ) ) {
            TIMESPEC_TO_MICROSECONDS( &min_timeout, next_timeout_usec );
        }
        else {
            struct timespec timeout = { 0, 0 };
            SUB_TIMESPEC( &callback->expires_at, &now, &timeout );
            if ( TIMESPEC_LESS_THEN( &timeout, &max_timeout ) ) {
                TIMESPEC_TO_MICROSECONDS( &timeout, next_timeout_usec );
            }
            else {
                TIMESPEC_TO_MICROSECONDS( &max_timeout, next_timeout_usec );
            }
        }
    }
}
示例#5
0
 void pipeline_connector::do_connect(const std::vector< tcode::io::ip::address >& addrs ){	
     _address = addrs;
     _current_address_index = 0;
     _timer.due_time( _timeout )
         .repeat( _timeout )
         .callback( [this]( const std::error_code& ec ) {
                 on_timer(ec);
                 });
     do_connect();
     _timer.fire();
 }
示例#6
0
TmpESRExperiment::TmpESRExperiment(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TmpESRExperiment)
{
    ui->setupUi(this);
    wf=0;
    hposciloscope=0;
    timer = new QTimer(this);
   connect(ProjectManager::instance(),SIGNAL(projectChanged()),this,SLOT(onProjectChanged()));
   connect(timer,SIGNAL(timeout()),this,SLOT(on_timer()));
}
示例#7
0
TWBaseScript::MsgStatus TWCloudDrift::on_message(sScrMsg* msg, cMultiParm& reply)
{
    // Call the superclass to let it handle any messages it needs to
    MsgStatus result = TWBaseScript::on_message(msg, reply);
    if(result != MS_CONTINUE) return result;

    if(!::_stricmp(msg -> message, "Timer")) {
        return on_timer(static_cast<sScrTimerMsg*>(msg), reply);
    }

    return result;
}
示例#8
0
文件: core.cpp 项目: ferustigris/gi
/*!\func TCore
 * конструктор класса
 * \param нет
 * \return нет
 */
TCore::TCore(const QString &newPluginsDir, quint16 localPort) : address(QHostAddress::Broadcast), timer() {
//    qDebug()<<"TCore";
    this->pluginsDir = newPluginsDir;
    //уникальный типа ИД
    unique_id = 1;
    connect(&timer, SIGNAL(timeout()), this, SLOT(on_timer()));
    timer.start(1000);
    //создаем соккет
    this->localPort = localPort;
    remoutePort = 45454;
    udpSocket.bind(localPort);
    connect(&udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams()));
}
示例#9
0
文件: task.cpp 项目: SunnyGyb/rDSN
void timer_task::exec()
{
    task_state RUNNING_STATE = TASK_STATE_RUNNING;
    
    bool conti = on_timer();

    if (conti && _interval_milliseconds > 0)
    {
        if (_state.compare_exchange_strong(RUNNING_STATE, TASK_STATE_READY))
        {
            set_delay(_interval_milliseconds);            
        }        
    }
}
示例#10
0
int app::run(){
	
	while(m_brun){
		
		void* data = NULL;
		if(m_ring_buf.pop(data) == -1){
			continue;
		}
		
		app_hd * msg = (app_hd*)data;
		if(msg->type == tcp_type){
			switch(msg->event){
				case ev_sys_recv:
					on_recv(msg->u.tcp.n, msg->content, msg->length);
					break;
					
				case ev_sys_close:
					on_close(msg->u.tcp.n, *((int*)msg->content));
					delete msg->u.tcp.n;
					break;
					
				case ev_sys_accept:
					on_accept(msg->u.tcp.n);
					break;
					
				case ev_sys_connect_ok:
					on_connect(msg->u.tcp.n);
					break;
					
				case ev_sys_connect_fail:
					on_connect(msg->u.tcp.n);
					delete msg->u.tcp.n;
				break;
				
			}
		}
		else if(msg->type == timer_type){
			on_timer(msg->event, msg->u.timer.interval, msg->u.timer.ptr);
		}
		else if(msg->type == app_type){
			on_app(msg->event, msg->content, msg->length);
		}
		else{
			error_log("msg from unknown app_name(%s)\n", m_name);
		}
		free(msg);
	}
	return 0;
}
示例#11
0
void UIWidget::primary_timer_func()
{
   if (disabled) return;

   on_timer();

   std::vector<UIWidget *> children = ElementID::recast_collection<UIWidget>(get_children());

   for (auto &child : children)
      child->primary_timer_func();

   // delete the widgets who request deletion
   for (auto &child : children)
      if (child->delete_me) delete child;
}
示例#12
0
文件: view.c 项目: pstrealer/wine
static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    HTMLDocumentObj *This;

    static const WCHAR wszTHIS[] = {'T','H','I','S',0};

    if(msg == WM_CREATE) {
        This = *(HTMLDocumentObj**)lParam;
        SetPropW(hwnd, wszTHIS, This);
    }else {
        This = GetPropW(hwnd, wszTHIS);
    }

    switch(msg) {
    case WM_CREATE:
        This->hwnd = hwnd;
        break;
    case WM_PAINT:
        paint_document(This);
        break;
    case WM_SIZE:
        TRACE("(%p)->(WM_SIZE)\n", This);
        if(This->nscontainer) {
            INT ew=0, eh=0;

            if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER))) {
                ew = GetSystemMetrics(SM_CXEDGE);
                eh = GetSystemMetrics(SM_CYEDGE);
            }

            SetWindowPos(This->nscontainer->hwnd, NULL, ew, eh,
                         LOWORD(lParam) - 2*ew, HIWORD(lParam) - 2*eh,
                         SWP_NOZORDER | SWP_NOACTIVATE);
        }
        break;
    case WM_TIMER:
        return on_timer(This);
    case WM_SETFOCUS:
        TRACE("(%p) WM_SETFOCUS\n", This);
        nsIWebBrowserFocus_Activate(This->nscontainer->focus);
        break;
    case WM_MOUSEACTIVATE:
        return MA_ACTIVATE;
    }
        
    return DefWindowProcW(hwnd, msg, wParam, lParam);
}
        // Called immediately after the connection is created.
        // We keep this separate from the constructor because
        // shared_from_this may not be called from constructors.
        void run()
        {
            // Run the timer
            on_timer({});

            // Put the handshake on the timer
            timer_.expires_from_now(std::chrono::seconds(15));

            // Read the websocket handshake and send the response
            ws_.async_accept_ex(
                [](websocket::response_type& res)
                {
                    res.insert(http::field::server, "websocket-server-async");
                },
                strand_.wrap(std::bind(
                    &connection::on_accept,
                    shared_from_this(),
                    std::placeholders::_1)));
        }
示例#14
0
int app::dispatch(const app_hd * msg){
	
	if(msg->type == tcp_type){
		switch(msg->event){
			case ev_sys_recv:
				on_recv(msg->u.tcp.n, msg->content, msg->length);
				break;
				
			case ev_sys_close:
				on_close(msg->u.tcp.n, *((int*)msg->content));
				delete msg->u.tcp.n;
				break;
				
			case ev_sys_accept:
				on_accept(msg->u.tcp.n);
				break;
				
			case ev_sys_connect_ok:
				on_connect(msg->u.tcp.n);
				break;
				
			case ev_sys_connect_fail:
				on_connect(msg->u.tcp.n);
				delete msg->u.tcp.n;
			break;
			
			case ev_sys_write:
				handle_write(msg->u.tcp.n);
			break;
		}
	}
	else if(msg->type == timer_type){
		on_timer(msg->event, msg->u.timer.interval, msg->u.timer.ptr);
	}
	else if(msg->type == app_type){
		on_app(msg->event, msg->content, msg->length);
	}
	else{
		error_log("msg from unknown app_name(%s)\n", m_name);
	}
	return 0;	
}
示例#15
0
void RemoteFileCopier::Session::send_next_rpc() {
    _cntl.Reset();
    _response.Clear();
    // Not clear request as we need some fields of the previouse RPC
    off_t offset = _request.offset() + _request.count();
    const size_t max_count = 
            (!_buf) ? FLAGS_raft_max_byte_count_per_rpc : UINT_MAX;
    _cntl.set_timeout_ms(_options.timeout_ms);
    _request.set_offset(offset);
    // Read partly when throttled
    _request.set_read_partly(true);
    std::unique_lock<raft_mutex_t> lck(_mutex);
    if (_finished) {
        return;
    }
    // throttle
    size_t new_max_count = max_count;
    if (_throttle) {
        new_max_count = _throttle->throttled_by_throughput(max_count);
        if (new_max_count == 0) {
            // Reset count to make next rpc retry the previous one
            _request.set_count(0);
            AddRef();
            if (bthread_timer_add(
                        &_timer, 
                        butil::milliseconds_from_now(_options.retry_interval_ms),
                        on_timer, this) != 0) {
                lck.unlock();
                LOG(ERROR) << "Fail to add timer";
                return on_timer(this);
            }
            return;
        }
    }
    _request.set_count(new_max_count);
    _rpc_call = _cntl.call_id();
    FileService_Stub stub(_channel);
    AddRef();  // Release in on_rpc_returned
    return stub.get_file(&_cntl, &_request, &_response, &_done);
}
示例#16
0
文件: rpc.cpp 项目: floft/freetron
rpc::rpc(cppcms::service& srv, Database& db, Processor& p)
    : cppcms::rpc::json_rpc_server(srv), db(db), p(p),
      timer(srv.get_io_service()), exiting(false),
      statusThread(StatusThread(*this, exiting))
{
    // Account
    bind("account_login", cppcms::rpc::json_method(&rpc::account_login, this), method_role);
    bind("account_logout", cppcms::rpc::json_method(&rpc::account_logout, this), method_role);
    bind("account_create", cppcms::rpc::json_method(&rpc::account_create, this), method_role);
    bind("account_update", cppcms::rpc::json_method(&rpc::account_update, this), method_role);
    bind("account_delete", cppcms::rpc::json_method(&rpc::account_delete, this), method_role);

    // Forms
    bind("form_process", cppcms::rpc::json_method(&rpc::form_process, this), method_role);
    bind("form_getone", cppcms::rpc::json_method(&rpc::form_getone, this), method_role);
    bind("form_getall", cppcms::rpc::json_method(&rpc::form_getall, this), method_role);
    bind("form_delete", cppcms::rpc::json_method(&rpc::form_delete, this), method_role);
    bind("form_rename", cppcms::rpc::json_method(&rpc::form_rename, this), method_role);

    // Timeouts for getting rid of long requests
    on_timer(booster::system::error_code());
}
PaintChatWindow::PaintChatWindow(QWidget *parent, ChatId chatId, ChatWidget *chatWidget) :
	QMainWindow(parent), chatId(chatId), chatType(ChatWidget::CHATTYPE_UNKNOWN), chatWidget(chatWidget),
    ui(new Ui::PaintChatWindow)
{
    ui->setupUi(this);
    connect(ui->paintWidget,SIGNAL(haveUpdate()),SLOT(on_haveUpdate()));
    connect(ui->penWidthSpinBox,SIGNAL(valueChanged(int)),this,SLOT(penChanged()));

    ui->pushButton1px->setChecked(true);
    ui->pushButtonPen->setChecked(true);

    ui->paintWidget->color=Qt::black;
    ui->paintWidget->penWidth=1;

    timer=new QTimer(this);
    connect(timer,SIGNAL(timeout()),SLOT(on_timer()));
    timer->start(500);

    QIcon icon ;
    icon.addPixmap(QPixmap(":/images/colors.png"));
    setWindowIcon(icon);
    
    QPixmap pix(24, 24);
    pix.fill(currentColor);
    ui->pushButtonPrimaryColor->setIcon(pix);

    chatType = chatWidget->chatType();
// Disabled
//    if(chatType == ChatWidget::CHATTYPE_PRIVATE)
//    {
//        ui->label->setText(QString::fromStdString(std::string("Paintchat with ")+rsPeers->getPeerName(peerId)));
//        setWindowTitle(QString::fromStdString(rsPeers->getPeerName(peerId)+" - PaintChat"));

//        ImageResource res;
//        res.fromQImage(ui->paintWidget->getImage());
//        paintChatService->init(peerId,res);

//        ui->progressBar->hide();
//    }
    if(chatType == ChatWidget::CHATTYPE_LOBBY)
    {
        ui->progressBar->setRange(0,100);
        ui->progressBar->setValue(0);

        ChatLobbyId id;
		id = chatId.toLobbyId();
        std::string nick, lobby;

		RsGxsId gxsid;
		RsIdentityDetails details;
		rsMsgs->getIdentityForChatLobby(id, gxsid);
		for(int i=0;i<3;++i)
			if(rsIdentity->getIdDetails(gxsid,details))
				break ;
			else
				usleep(1000*300) ;
		nick = details.mNickname;

		ChatLobbyInfo info;
		rsMsgs->getChatLobbyInfo(id, info);
		lobby = info.lobby_name;

        std::string label = nick + "@" + lobby;
        ui->label->setText(QString::fromStdString(label));
        setWindowTitle(QString::fromStdString(label + " - PaintChat"));
    }

	ui->lblWarning->setVisible(false);
}
bool CDistributedObjectBase::do_timer(const TDistributedMessage* message)
{
    // callback
    return on_timer(message);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    
    PAINTSTRUCT ps;
    HDC hdc;
    
    switch (message) 
    {
    case WM_CREATE:
        {
            if (!hmWnd)
                hmWnd = hWnd;

            hdc = GetDC(hWnd);
            CBIT = GetDeviceCaps(hdc, BITSPIXEL);    
            CBYTE = CBIT/8;
            ReleaseDC(hWnd, hdc);
            
            buffer = malloc(width*height*CBYTE);
            bmp.bmType = 0;
            bmp.bmWidth = width;
            bmp.bmHeight = height;
            bmp.bmWidthBytes = width*CBYTE;
            bmp.bmPlanes = 1;
            bmp.bmBitsPixel = CBIT;
            bmp.bmBits = buffer;
            
            if (CBYTE == 4)
                fmt = COLOR_FORMAT_BGRA;
            else if (CBYTE == 3)
                fmt = COLOR_FORMAT_BGR;
            else if (CBYTE == 2)
                fmt = COLOR_FORMAT_RGB565;

            ps_initialize();

            canvas = ps_canvas_create_with_data(buffer, fmt, width, height, width*CBYTE);
            context = ps_context_create(canvas, 0);
            on_init(context, width, height);    
        }
        break;
    case WM_PAINT:
        {
            HDC mdc;
            HGDIOBJ h;
            hdc = BeginPaint(hWnd, &ps);
            
            on_draw(context);
            
            mdc = CreateCompatibleDC(hdc);
            hbmp = CreateBitmapIndirect(&bmp);
            h = SelectObject(mdc, hbmp);
            BitBlt(hdc, 0, 0, width, height, mdc, 0, 0, SRCCOPY);
            SelectObject(mdc, h);
            DeleteObject(hbmp);
            DeleteDC(mdc);
            EndPaint(hWnd, &ps);
        }
        break;
    case WM_TIMER:
        on_timer();
        break;
    case WM_SIZE:
        {
            ps_canvas* old_canvas = 0;
            width = LOWORD(lParam);
            height = HIWORD(lParam);
            free(buffer);

            if (width < 1)
                width = 1;
            if (height < 1)
                height = 1;

            buffer = malloc(width*height*CBYTE);
            bmp.bmType = 0;
            bmp.bmWidth = width;
            bmp.bmHeight = height;
            bmp.bmWidthBytes = width*CBYTE;
            bmp.bmPlanes = 1;
            bmp.bmBitsPixel = CBIT;
            bmp.bmBits = buffer;

            canvas = ps_canvas_create_with_data(buffer, fmt, width, height, width*CBYTE);
            old_canvas = ps_context_set_canvas(context, canvas);
            ps_canvas_unref(old_canvas);
            on_size(width, height);
        }
        break;
    case WM_ERASEBKGND:
        break;
    case WM_LBUTTONDOWN:
            on_mouse_event(LEFT_BUTTON_DOWN, wParam, LOWORD(lParam), HIWORD(lParam));
        break;
    case WM_MOUSEMOVE:
            on_mouse_event(MOUSE_MOVE, wParam, LOWORD(lParam), HIWORD(lParam));
        break;
    case WM_KEYDOWN:
            on_key_event(KEY_EVENT_DOWN, wParam);
        break;
    case WM_KEYUP:
            on_key_event(KEY_EVENT_UP, wParam);
        break;
    case WM_DESTROY:
        {
            on_term(context);
            ps_context_unref(context);
            ps_canvas_unref(canvas);
            ps_shutdown();
            free(buffer);
            PostQuitMessage(0);
        }
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
示例#20
0
BOOL CALLBACK item_details_config_t::on_message(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
{
	switch (msg)
	{
		/*case DM_GETDEFID:
		SetWindowLongPtr(wnd, DWL_MSGRESULT, MAKELONG(m_modal ? IDOK : IDCANCEL, DC_HASDEFID));
		return TRUE;*/
	case WM_INITDIALOG:
	{
		m_wnd = wnd;

		if (!m_modal)
		{
			modeless_dialog_manager::g_add(wnd);
			m_this->set_config_wnd(wnd);
			ShowWindow(GetDlgItem(wnd, IDOK), SW_HIDE);
			SetWindowText(GetDlgItem(wnd, IDCANCEL), L"Close");
		}

		uSetWindowText(GetDlgItem(wnd, IDC_SCRIPT), m_script);
		HWND wnd_combo = GetDlgItem(wnd, IDC_EDGESTYLE);
		ComboBox_AddString(wnd_combo, L"None");
		ComboBox_AddString(wnd_combo, L"Sunken");
		ComboBox_AddString(wnd_combo, L"Grey");
		ComboBox_SetCurSel(wnd_combo, m_edge_style);

		wnd_combo = GetDlgItem(wnd, IDC_HALIGN);
		ComboBox_AddString(wnd_combo, L"Left");
		ComboBox_AddString(wnd_combo, L"Centre");
		ComboBox_AddString(wnd_combo, L"Right");
		ComboBox_SetCurSel(wnd_combo, m_horizontal_alignment);

		wnd_combo = GetDlgItem(wnd, IDC_VALIGN);
		ComboBox_AddString(wnd_combo, L"Top");
		ComboBox_AddString(wnd_combo, L"Centre");
		ComboBox_AddString(wnd_combo, L"Bottom");
		ComboBox_SetCurSel(wnd_combo, m_vertical_alignment);

		LOGFONT lf;
		static_api_ptr_t<cui::fonts::manager>()->get_font(g_guid_item_details_font_client, lf);
		m_font_code_generator.initialise(lf, wnd, IDC_FONT_CODE);

		colour_code_gen(wnd, IDC_COLOUR_CODE, false, true);

		if (!m_modal)
		{
			SendMessage(wnd, DM_SETDEFID, IDCANCEL, NULL);
			SetFocus(GetDlgItem(wnd, IDCANCEL));
			return FALSE;
		}
		else
			return FALSE;

	}
	return FALSE;// m_modal ? FALSE : TRUE;
	case WM_DESTROY:
		if (m_timer_active)
			on_timer();
		if (!m_modal)
			m_this->set_config_wnd(NULL);
		break;
	case WM_NCDESTROY:
		m_wnd = NULL;
		if (!m_modal)
		{
			modeless_dialog_manager::g_remove(wnd);
			SetWindowLongPtr(wnd, DWL_USER, NULL);
			delete this;
		}
		break;
	case WM_ERASEBKGND:
		SetWindowLongPtr(wnd, DWL_MSGRESULT, TRUE);
		return TRUE;
	case WM_PAINT:
		ui_helpers::innerWMPaintModernBackground(wnd, GetDlgItem(wnd, IDOK));
		return TRUE;
	case WM_CTLCOLORSTATIC:
		SetBkColor((HDC)wp, GetSysColor(COLOR_WINDOW));
		SetTextColor((HDC)wp, GetSysColor(COLOR_WINDOWTEXT));
		return (BOOL)GetSysColorBrush(COLOR_WINDOW);
	case WM_CLOSE:
		if (m_modal)
		{
			SendMessage(wnd, WM_COMMAND, IDCANCEL, NULL);
			return TRUE;
		}
		break;
	case WM_TIMER:
		if (wp == timer_id) on_timer();
		break;
	case WM_COMMAND:
		switch (LOWORD(wp))
		{
		case IDOK:
			if (m_modal)
				EndDialog(wnd, 1);
			return TRUE;
		case IDCANCEL:
			if (m_modal)
				EndDialog(wnd, 0);
			else
			{
				DestroyWindow(wnd);
			}
			return TRUE;
		case IDC_GEN_COLOUR:
			colour_code_gen(wnd, IDC_COLOUR_CODE, false, false);
			break;
		case IDC_GEN_FONT:
			m_font_code_generator.run(wnd, IDC_FONT_CODE);
			break;
		case IDC_SCRIPT:
			switch (HIWORD(wp))
			{
			case EN_CHANGE:
				m_script = string_utf8_from_window(HWND(lp));
				if (!m_modal)
					start_timer();
				break;
			}
			break;
		case IDC_EDGESTYLE:
			switch (HIWORD(wp))
			{
			case CBN_SELCHANGE:
				m_edge_style = ComboBox_GetCurSel((HWND)lp);
				if (!m_modal)
				{
					m_this->set_edge_style(m_edge_style);
					cfg_item_details_edge_style = m_edge_style;
				}
				break;
			}
			break;
		case IDC_HALIGN:
			switch (HIWORD(wp))
			{
			case CBN_SELCHANGE:
				m_horizontal_alignment = ComboBox_GetCurSel((HWND)lp);
				if (!m_modal)
				{
					m_this->set_horizontal_alignment(m_horizontal_alignment);
					cfg_item_details_horizontal_alignment = m_horizontal_alignment;
				}
				break;
			}
			break;
		case IDC_VALIGN:
			switch (HIWORD(wp))
			{
			case CBN_SELCHANGE:
				m_vertical_alignment = ComboBox_GetCurSel((HWND)lp);
				if (!m_modal)
				{
					m_this->set_vertical_alignment(m_vertical_alignment);
					cfg_item_details_vertical_alignment = m_vertical_alignment;
				}
				break;
			}
			break;
		}
		break;
	}
	return FALSE;
}
static int PlatformProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
        case MSG_CREATE:
            {
                if (!hmWnd)
                    hmWnd = hWnd;

                unsigned char* pdr = 0;
                int w,h,p;
                RECT r;
                key_down = FALSE;
                GetClientRect(hWnd, &r);
#if RGB555
            sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0x7C00, 0x3E0, 0x1F, 0x8000);    
#else
            sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0xF800, 0x7E0, 0x1F, 0x00);    
#endif
                pdr = LockDC(sdc, &r, &w, &h, &p);
                UnlockDC(sdc);
#if RGB555
                fmt = COLOR_FORMAT_RGB555;
#else
                fmt = COLOR_FORMAT_RGB565;
#endif
                ps_initialize();

                canvas = ps_canvas_create_with_data(pdr, fmt, w, h, p);
                context = ps_context_create(canvas, 0);
                on_init(context, width, height);    
            }
            break;
        case MSG_TIMER:
            on_timer();
            break;
        case MSG_PAINT:
            {
                HDC hdc = BeginPaint(hWnd);
                on_draw(context);
                BitBlt(sdc, 0, 0, width, height, hdc, 0, 0, 0);
                EndPaint(hWnd, hdc);
            }
            return 0;
        case MSG_ERASEBKGND:
            return 0;
        case MSG_LBUTTONDOWN:
            {
                key_down = TRUE;
                on_mouse_event(LEFT_BUTTON_DOWN, key_conv(wParam), LOSWORD(lParam), HISWORD(lParam));
            }
            break;
        case MSG_LBUTTONUP:
            {
                key_down = FALSE;
                on_mouse_event(LEFT_BUTTON_UP, key_conv(wParam), LOSWORD(lParam), HISWORD(lParam));
            }
            break;
        case MSG_MOUSEMOVE:
            {
                DWORD k = key_conv(wParam);
                if (key_down)
                    k |= EVT_LBUTTON;
                on_mouse_event(MOUSE_MOVE, k, LOSWORD(lParam), HISWORD(lParam));
            }
            break;
        case MSG_KEYDOWN:
            on_key_event(KEY_EVENT_DOWN, get_virtual_key(wParam));
            break;
        case MSG_KEYUP:
            on_key_event(KEY_EVENT_UP, get_virtual_key(wParam));
            break;
        case MSG_SIZECHANGED:
            {
                RECT r;
                int w,h,p;
                unsigned char* pdr = 0;
                ps_canvas* old_canvas = 0;
                RECT* rc = (RECT*)lParam;
                width = RECTWP(rc);
                height = RECTHP(rc);
                if (sdc)
                    DeleteMemDC(sdc);

                if (width < 1)
                    width = 1;
                if (height < 1)
                    height = 1;
#if RGB555
            sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0x7C00, 0x3E0, 0x1F, 0x8000);    
#else
            sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0xF800, 0x7E0, 0x1F, 0x00);    
#endif
                GetClientRect(hWnd, &r);
                pdr = LockDC(sdc, &r, &w, &h, &p);
                UnlockDC(sdc);
                canvas = ps_canvas_create_with_data(pdr, fmt, w, h, p);
                old_canvas = ps_context_set_canvas(context, canvas);
                ps_canvas_unref(old_canvas);
                on_size(width, height);
            }
            break;
        case MSG_CLOSE:
            on_term(context);
            ps_context_unref(context);
            ps_canvas_unref(canvas);
            ps_shutdown();
            DeleteMemDC(sdc);
            DestroyMainWindow (hWnd);
            PostQuitMessage (hWnd);
            return 0;
    }
    return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
示例#22
0
 virtual BOOL handle_timer(HELEMENT he, TIMER_PARAMS &params)
 {
     if (params.timerId)
         return on_timer(he, params.timerId);
     return on_timer(he);
 }
示例#23
0
LRESULT
Window::on_message(HWND _hWnd, UINT message,
                       WPARAM wParam, LPARAM lParam)
{
  if (IsEmbedded() && !IsAltair()) {
    /* some older iPaqs such as the H3900 send only WM_KEYUP for
       VK_APP*, but never VK_KEYDOWN; the hx4700 has an additional set
       of undocumented key codes (0xca..0xcd) for the APP keys, but
       sends WM_KEYUP/VK_APP* additionally; the following rules
       hopefully catch all of these obscurities */
    if (message == WM_KEYUP && wParam >= 0x80)
      /* convert to WM_KEYDOWN to make all handlers catch it */
      message = WM_KEYDOWN;
    else if (message == WM_KEYDOWN && wParam >= 0x80)
      /* ignore the real WM_KEYDOWN, just in case it really happens */
      return 0;
  }

  switch (message) {
  case WM_CREATE:
    on_create();
    return 0;

  case WM_DESTROY:
    on_destroy();
    return 0;

  case WM_CLOSE:
    if (on_close())
      /* true returned: message was handled */
      return 0;
    break;

  case WM_SIZE:
    on_resize(LOWORD(lParam), HIWORD(lParam));
    return 0;

  case WM_MOUSEMOVE:
    if (on_mouse_move(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam))
      return 0;
    break;

  case WM_LBUTTONDOWN:
    if (on_mouse_down(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_LBUTTONUP:
    if (on_mouse_up(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_LBUTTONDBLCLK:
    if (!double_clicks)
      /* instead of disabling CS_DBLCLKS (which would affect all
         instances of a window class), we just translate
         WM_LBUTTONDBLCLK to WM_LBUTTONDOWN here; this even works for
         built-in window class such as BUTTON */
      return on_message(_hWnd, WM_LBUTTONDOWN, wParam, lParam);

    if (on_mouse_double(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }

    break;

#ifdef WM_MOUSEWHEEL
  case WM_MOUSEWHEEL:
    if (on_mouse_wheel(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
                       GET_WHEEL_DELTA_WPARAM(wParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;
#endif

  case WM_KEYDOWN:
    if (on_key_down(::TranscodeKey(wParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_KEYUP:
    if (on_key_up(::TranscodeKey(wParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_COMMAND:
    if (on_command(LOWORD(wParam), HIWORD(wParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_CANCELMODE:
    if (on_cancel_mode())
      return 0;
    break;

  case WM_SETFOCUS:
    on_setfocus();
    return 0;

  case WM_KILLFOCUS:
    on_killfocus();
    return 0;

  case WM_TIMER:
    if (on_timer(*(WindowTimer *)wParam))
      return 0;
    break;

  case WM_PAINT:
    if (custom_painting) {
      PaintCanvas canvas(*this);
      on_paint(canvas, canvas.get_dirty());
      return 0;
    }
    break;

  case WM_GETDLGCODE:
    if (on_key_check(wParam))
      return DLGC_WANTMESSAGE;
    break;
  }

  if (message >= WM_USER && message <= 0x7FFF && on_user(message - WM_USER))
    return 0;

  return on_unhandled_message(_hWnd, message, wParam, lParam);
}
PaintChatWindow::PaintChatWindow(QWidget *parent, std::string peerId, ChatWidget *chatWidget) :
    QMainWindow(parent), peerId(peerId), chatType(ChatWidget::CHATTYPE_UNKNOWN), chatWidget(chatWidget),
    ui(new Ui::PaintChatWindow)
{
    ui->setupUi(this);
    connect(ui->paintWidget,SIGNAL(haveUpdate()),SLOT(on_haveUpdate()));
    connect(ui->penWidthSpinBox,SIGNAL(valueChanged(int)),this,SLOT(penChanged()));

    ui->pushButton1px->setChecked(true);
    ui->pushButtonPen->setChecked(true);

    ui->paintWidget->color=Qt::black;
    ui->paintWidget->penWidth=1;

    timer=new QTimer(this);
    connect(timer,SIGNAL(timeout()),SLOT(on_timer()));
    timer->start(500);

    QIcon icon ;
    icon.addPixmap(QPixmap(":/images/colors.png"));
    setWindowIcon(icon);
    
    QPixmap pix(24, 24);
    pix.fill(currentColor);
    ui->pushButtonPrimaryColor->setIcon(pix);

    chatType = chatWidget->chatType();
    if(chatType == ChatWidget::CHATTYPE_PRIVATE)
    {
        ui->label->setText(QString::fromStdString(std::string("Paintchat with ")+rsPeers->getPeerName(peerId)));
        setWindowTitle(QString::fromStdString(rsPeers->getPeerName(peerId)+" - PaintChat"));

        ImageResource res;
        res.fromQImage(ui->paintWidget->getImage());
        paintChatService->init(peerId,res);

        ui->progressBar->hide();
    }
    if(chatType == ChatWidget::CHATTYPE_LOBBY)
    {
        ui->progressBar->setRange(0,100);
        ui->progressBar->setValue(0);

        ChatLobbyId id;
        rsMsgs->isLobbyId(peerId, id);
        std::string nick, lobby;
        std::list<ChatLobbyInfo> cil;
        rsMsgs->getChatLobbyList(cil);
        std::list<ChatLobbyInfo>::iterator it;
        for(it = cil.begin(); it != cil.end(); it++)
        {
            ChatLobbyInfo ci = *it;
            if(ci.lobby_id == id)
            {
                nick = ci.nick_name;
                lobby = ci.lobby_name;
                break;
            }
        }
        std::string label = nick + "@" + lobby;
        ui->label->setText(QString::fromStdString(label));
        setWindowTitle(QString::fromStdString(label + " - PaintChat"));
    }
}
示例#25
0
LRESULT
Window::on_message(HWND _hWnd, UINT message,
                       WPARAM wParam, LPARAM lParam)
{
  switch (message) {
  case WM_CREATE:
    return on_create() ? 0 : -1;
    break;

  case WM_DESTROY:
    if (on_destroy()) return 0;
    break;

  case WM_CLOSE:
    if (on_close())
      /* true returned: message was handled */
      return 0;
    break;

  case WM_SIZE:
    if (on_resize(LOWORD(lParam), HIWORD(lParam))) return 0;
    break;

  case WM_MOUSEMOVE:
    if (on_mouse_move(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam))
      return 0;
    break;

  case WM_LBUTTONDOWN:
    XCSoarInterface::InterfaceTimeoutReset();
    if (on_mouse_down(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_LBUTTONUP:
    XCSoarInterface::InterfaceTimeoutReset();
    if (on_mouse_up(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_LBUTTONDBLCLK:
    XCSoarInterface::InterfaceTimeoutReset();
    if (on_mouse_double(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

#ifdef WM_MOUSEWHEEL
  case WM_MOUSEWHEEL:
    XCSoarInterface::InterfaceTimeoutReset();
    if (on_mouse_wheel(GET_WHEEL_DELTA_WPARAM(wParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;
#endif

  case WM_KEYDOWN:
    XCSoarInterface::InterfaceTimeoutReset();
    if (on_key_down(wParam)) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_KEYUP:
    XCSoarInterface::InterfaceTimeoutReset();
    if (on_key_up(wParam)) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_COMMAND:
    XCSoarInterface::InterfaceTimeoutReset();
    if (on_command(LOWORD(wParam), HIWORD(wParam))) {
      /* true returned: message was handled */
      ResetDisplayTimeOut();
      return 0;
    }
    break;

  case WM_SETFOCUS:
    if (on_setfocus())
      return 0;
    break;

  case WM_KILLFOCUS:
    if (on_killfocus())
      return 0;
    break;

  case WM_TIMER:
    if (on_timer(wParam))
      return 0;
    break;
  }

  if (message >= WM_USER && message <= 0x7FFF && on_user(message - WM_USER))
    return 0;

  return on_unhandled_message(_hWnd, message, wParam, lParam);
}
示例#26
0
void RemoteFileCopier::Session::on_rpc_returned() {
    scoped_refptr<Session> ref_gurad;
    Session* this_ref = this;
    ref_gurad.swap(&this_ref);
    std::unique_lock<raft_mutex_t> lck(_mutex);
    if (_finished) {
        return;
    }
    if (_cntl.Failed()) {
        // Reset count to make next rpc retry the previous one
        _request.set_count(0);
        if (_cntl.ErrorCode() == ECANCELED) {
            if (_st.ok()) {
                _st.set_error(_cntl.ErrorCode(), _cntl.ErrorText());
                return on_finished();
            }
        }
        // Throttled reading failure does not increase _retry_times
        if (_cntl.ErrorCode() != EAGAIN && _retry_times++ >= _options.max_retry) {
            if (_st.ok()) {
                _st.set_error(_cntl.ErrorCode(), _cntl.ErrorText());
                return on_finished();
            }
        }
        AddRef();
        if (bthread_timer_add(
                    &_timer, 
                    butil::milliseconds_from_now(_options.retry_interval_ms),
                    on_timer, this) != 0) {
            lck.unlock();
            LOG(ERROR) << "Fail to add timer";
            return on_timer(this);
        }
        return;
    }
    _retry_times = 0;
    // Reset count to |real_read_size| to make next rpc get the right offset
    if (_response.has_read_size() && (_response.read_size() != 0)) {
        _request.set_count(_response.read_size());
    }
    if (_file) {
        FileSegData data(_cntl.response_attachment());
        uint64_t seg_offset = 0;
        butil::IOBuf seg_data;
        while (0 != data.next(&seg_offset, &seg_data)) {
            ssize_t nwritten = _file->write(seg_data, seg_offset);
            if (static_cast<size_t>(nwritten) != seg_data.size()) {
                LOG(WARNING) << "Fail to write into file: " << _dest_path;
                _st.set_error(EIO, "%s", berror(EIO));
                return on_finished();
            }
            seg_data.clear();
        }
    } else {
        FileSegData data(_cntl.response_attachment());
        uint64_t seg_offset = 0;
        butil::IOBuf seg_data;
        while (0 != data.next(&seg_offset, &seg_data)) {
            CHECK_GE((size_t)seg_offset, _buf->length());
            _buf->resize(seg_offset);
            _buf->append(seg_data);
        }
    }
    if (_response.eof()) {
        on_finished();
        return;
    }
    lck.unlock();
    return send_next_rpc();
}
示例#27
0
static void timer_irq_handle(unsigned int irq)
{
    printk(PR_SS_IRQ, PR_LVL_DBG1, "%s, irq = %d\n", __func__, irq);
    on_timer();
}