Exemple #1
0
	LRESULT CComWnd::on_create( HWND hWnd, HINSTANCE hInstance )
	{
		SetWindowText(hWnd, COMMON_NAME_AND_VERSION);

		memory.set_notifier(this);

		struct {HWND* phwnd; UINT  id;}hwndlist[] = {
				{&_hCP,		IDC_CBO_CP},
				{&_hBR,		IDC_CBO_BR},
				{&_hPA,		IDC_CBO_CHK},
				{&_hSB,		IDC_CBO_STOP},
				{&_hDB,		IDC_CBO_DATA},
				{&_hStatus,	IDC_STATIC_STATUS},
				{&_hOpen,	IDC_BTN_OPEN},
		};

		for (int i = 0; i < sizeof(hwndlist) / sizeof(hwndlist[0]); i++){
			SMART_ENSURE(*hwndlist[i].phwnd = ::GetDlgItem(m_hWnd, hwndlist[i].id), !=NULL)(i).Fatal();
		}

		editor_recv_char()->Create(hWnd, "", WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_READONLY |
			ES_MULTILINE | ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL ,
			WS_EX_CLIENTEDGE,
			0,0,0,0, (HMENU)IDC_EDIT_RECV2);
		WNDPROC new_rich_proc = static_cast<WNDPROC>(_thunk_rich_edit.Stdcall(this, &CComWnd::RichEditProc));
		_thunk_rich_edit_old_proc = SubclassWindow(*editor_recv_char(), new_rich_proc);
		::ImmAssociateContext(*editor_recv_char(), nullptr);

		editor_recv_hex()->Attach(::GetDlgItem(hWnd, IDC_EDIT_RECV));
		editor_send()->Attach(::GetDlgItem(hWnd, IDC_EDIT_SEND));

		editor_recv_hex()->limit_text(COMMON_RECV_BUF_SIZE);
		editor_recv_char()->limit_text(COMMON_RECV_BUF_SIZE);
		editor_send()->limit_text(COMMON_SEND_BUF_SIZE);

		SendMessage(WM_SETICON, ICON_SMALL, LPARAM(LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1))));

		m_hAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR1));
		m_wndmgr.AcceleratorTranslator() = this;

		m_layout = ::layout_new(hWnd, MAKEINTRESOURCE(IDR_RCDATA2), hInstance);
		layout_visible(layout_control(m_layout, "recv_wnd_recv"), FALSE);
		layout_resize(m_layout, NULL);

		// 界面元素
		::SendMessage(_hCP, CB_SETDROPPEDWIDTH, 350, 0);
		::SetDlgItemText(m_hWnd, IDC_STATIC_TIMER, "00:00:00");
		
		// 界面预定义
		switch_simple_ui(true, false);
		switch_window_top_most(true, false);
		switch_send_data_format(true, false);
		switch_recv_data_format(true, false);
		switch_auto_send(true, false, -1);

		// 窗口关闭事件
		_window_close_handler.add([&](){
			if (_b_recv_char_edit_fullscreen){
				_b_recv_char_edit_fullscreen = false;
				switch_rich_edit_fullscreen(_b_recv_char_edit_fullscreen);
				return true;
			}
			return false;
		});

		_window_close_handler.add([&](){
			if (_comm.is_opened()){
				com_try_close(true);
				_timer.stop();
			}
			return false;
		});

		_window_close_handler.add([&](){
			save_to_config_file();
			return false;
		});

		// 相关接口
		_comm.set_notifier(this);
		_comm.counter()->set_updater(this);
		_timer.set_period(1000);
		_timer.set_timer(this);
		_timer.set_notifier(this);
		_auto_send_timer.set_period(1000);
		_auto_send_timer.set_period_timer(this);
		_auto_send_timer.set_notifier(this);

		// 接收器
		_hex_data_receiver.set_editor(&_recv_hex_edit);
		_text_data_receiver.set_editor(&_recv_char_edit);
		_comm.add_data_receiver(&_hex_data_receiver);
		_comm.add_data_receiver(&_text_data_receiver);

		com_update_item_list();
		com_add_prompt_if_no_cp_presents();

		// 从配置文件加载配置
		init_from_config_file();

		// 欢迎语
		update_status("欢迎使用 Common串口调试工具! Enjoy! :-)");

		return 0;
	}
Exemple #2
0
void
recalculate_sizes(void)
{
	struct session		*s;
	struct client		*c;
	struct window		*w;
	struct window_pane	*wp;
	u_int		 	 i, j, ssx, ssy, has, limit;
	int		 	 flag;

	for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
		s = ARRAY_ITEM(&sessions, i);
		if (s == NULL)
			continue;

		ssx = ssy = UINT_MAX;
		for (j = 0; j < ARRAY_LENGTH(&clients); j++) {
			c = ARRAY_ITEM(&clients, j);
			if (c == NULL || c->flags & CLIENT_SUSPENDED)
				continue;
			if (c->session == s) {
				if (c->tty.sx < ssx)
					ssx = c->tty.sx;
				if (c->tty.sy < ssy)
					ssy = c->tty.sy;
			}
		}
		if (ssx == UINT_MAX || ssy == UINT_MAX) {
			s->flags |= SESSION_UNATTACHED;
			continue;
		}
		s->flags &= ~SESSION_UNATTACHED;

		if (options_get_number(&s->options, "status")) {
			if (ssy == 0)
				ssy = 1;
			else
				ssy--;
		}
		if (s->sx == ssx && s->sy == ssy)
			continue;

		log_debug(
		    "session size %u,%u (was %u,%u)", ssx, ssy, s->sx, s->sy);

		s->sx = ssx;
		s->sy = ssy;
	}

	for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
		w = ARRAY_ITEM(&windows, i);
		if (w == NULL)
			continue;
		flag = options_get_number(&w->options, "aggressive-resize");

		ssx = ssy = UINT_MAX;
		for (j = 0; j < ARRAY_LENGTH(&sessions); j++) {
			s = ARRAY_ITEM(&sessions, j);
			if (s == NULL || s->flags & SESSION_UNATTACHED)
				continue;
			if (flag)
				has = s->curw->window == w;
			else
				has = session_has(s, w);
			if (has) {
				if (s->sx < ssx)
					ssx = s->sx;
				if (s->sy < ssy)
					ssy = s->sy;
			}
		}
		if (ssx == UINT_MAX || ssy == UINT_MAX) {
			w->flags |= WINDOW_HIDDEN;
			continue;
		}
		w->flags &= ~WINDOW_HIDDEN;

		limit = options_get_number(&w->options, "force-width");
		if (limit != 0 && ssx > limit)
			ssx = limit;
		limit = options_get_number(&w->options, "force-height");
		if (limit != 0 && ssy > limit)
			ssy = limit;

		if (w->sx == ssx && w->sy == ssy)
			continue;

		log_debug(
		    "window size %u,%u (was %u,%u)", ssx, ssy, w->sx, w->sy);

		layout_resize(w, ssx, ssy);
		window_resize(w, ssx, ssy);

		/*
		 * If the current pane is now not visible, move to the next
		 * that is.
		 */
		wp = w->active;
		while (!window_pane_visible(w->active)) {
			w->active = TAILQ_PREV(w->active, window_panes, entry);
			if (w->active == NULL)
				w->active = TAILQ_LAST(&w->panes, window_panes);
			if (w->active == wp)
			       break;
		}

		server_redraw_window(w);
	}
}
Exemple #3
0
	LRESULT CComWnd::on_size( int width,int height )
	{
		layout_resize(m_layout, NULL);
		return 0;
	}