Esempio n. 1
0
//****************************************************************************
void CTerminal::resize_terminal_pixels(uint new_dx, uint new_dy)
{
   resize(new_dx, new_dy); //  dialog is actually drawn a few pixels too small for text
   set_terminal_dimens() ;  //  do this *after* resize()
   resize_column(new_dx-25) ; //  make this narrower than new_dx, to allow for scroll bar
}
Esempio n. 2
0
LRESULT CALLBACK insert_dlg_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	static TABLE_WINDOW *win=0;
	static HWND hlistview=0,hgrippy=0,hedit=0;
	static HFONT hfont=0;
	static WNDPROC origlistview=0;
	if(FALSE)
	{
		static DWORD tick=0;
		if((GetTickCount()-tick)>500)
			printf("--\n");
		if(hwnd==hlistview)
			printf("-");
		print_msg(msg,lparam,wparam,hwnd);
		tick=GetTickCount();
	}
	if(origlistview!=0 && hwnd==hlistview){
		if(msg==WM_GETDLGCODE){
			return DLGC_WANTARROWS;
		}
		return CallWindowProc(origlistview,hwnd,msg,wparam,lparam);
	}
	switch(msg){
	case WM_INITDIALOG:
		if(lparam==0){
			EndDialog(hwnd,0);
			break;
		}
		hedit=0;
		win=lparam;
		hlistview=CreateWindow(WC_LISTVIEW,"",WS_TABSTOP|WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE|LVS_REPORT|LVS_SHOWSELALWAYS,
                                     0,0,
                                     0,0,
                                     hwnd,
                                     IDC_LIST1,
                                     ghinstance,
                                     NULL);
		if(hlistview!=0){
			ListView_SetExtendedListViewStyle(hlistview,LVS_EX_FULLROWSELECT);
			hfont=SendMessage(win->hlistview,WM_GETFONT,0,0);
			if(hfont!=0)
				SendMessage(hlistview,WM_SETFONT,hfont,0);
			populate_insert_dlg(hwnd,hlistview,win);
			ListView_SetItemState(hlistview,0,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
			origlistview=SetWindowLong(hlistview,GWL_WNDPROC,(LONG)insert_dlg_proc);
		}
		set_title(hwnd,win);
		hgrippy=create_grippy(hwnd);
		resize_insert_dlg(hwnd);
		break;
	case WM_NOTIFY:
		{
			NMHDR *nmhdr=lparam;
			if(nmhdr!=0){
				switch(nmhdr->code){
				case NM_DBLCLK:
					if(hedit==0 && nmhdr->hwndFrom==hlistview)
						SendMessage(hwnd,WM_COMMAND,IDOK,0);
					break;
				case  LVN_COLUMNCLICK:
					{
						static sort_dir=0;
						NMLISTVIEW *nmlv=lparam;
						if(nmlv!=0){
							sort_listview(hlistview,sort_dir,nmlv->iSubItem);
							sort_dir=!sort_dir;
						}
					}
					break;
				case LVN_KEYDOWN:
					if(nmhdr->hwndFrom==hlistview)
					{
						LV_KEYDOWN *key=lparam;
						switch(key->wVKey){
						case VK_DOWN:
						case VK_RIGHT:
						case VK_NEXT:
							{
								int count,row_sel;
								count=ListView_GetItemCount(hlistview);
								row_sel=ListView_GetSelectionMark(hlistview);
								if(count>0 && row_sel==count-1)
									SetFocus(GetDlgItem(hwnd,IDOK));
							}
							break;
						case VK_DELETE:
							clear_selected_items(hlistview);
							break;
						case VK_F5:
							if(task_insert_row(win,hlistview))
								SetWindowText(GetDlgItem(hwnd,IDOK),"Busy");
							break;
						case 'A':
							if(GetKeyState(VK_CONTROL)&0x8000){
								int i,count;
								count=ListView_GetItemCount(hlistview);
								for(i=0;i<count;i++){
									ListView_SetItemState(hlistview,i,LVIS_SELECTED,LVIS_SELECTED);
								}
								break;
							}
						default:
							{
								int ignore=FALSE;
								if(!is_entry_key(key->wVKey))
									ignore=TRUE;
								if(GetKeyState(VK_CONTROL)&0x8000)
									ignore=TRUE;
								if(ignore)
									return 1;
							}
						case ' ':
						case VK_F2:
						case VK_INSERT:
							{
								int row_sel=ListView_GetSelectionMark(hlistview);
								if(row_sel>=0 && hedit==0){
									hedit=CreateWindow("EDIT","",WS_THICKFRAME|WS_TABSTOP|WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE|
											ES_LEFT|ES_AUTOHSCROLL,
											0,0,
											0,0,
											hwnd,
											IDC_EDIT1,
											ghinstance,
											NULL);
									if(hedit!=0){
										RECT rect={0},crect={0};
										int x,y,w,h;
										ListView_GetItemRect(hlistview,row_sel,&rect,LVIR_BOUNDS);
										lv_get_col_rect(hlistview,DATA_POS,&crect);
										x=crect.left-2;
										y=rect.top-2;
										w=crect.right-crect.left+8;
										h=rect.bottom-rect.top+8;
										SetWindowPos(hedit,HWND_TOP,x,y,w,h,0);
										if(hfont!=0)
											SendMessage(hedit,WM_SETFONT,hfont,0);
										if(is_entry_key(key->wVKey)){
											char str[2];
											char c=tolower(key->wVKey);
											if((GetKeyState(VK_SHIFT)&0x8000) || (GetKeyState(VK_CAPITAL)&1))
												c=toupper(c);
											str[0]=c;
											str[1]=0;
											SetWindowText(hedit,str);
											SendMessage(hedit,EM_SETSEL,1,1);

										}else{
											populate_edit_control(hlistview,hedit,row_sel);
										}
										SetFocus(hedit);
										wporigtedit=SetWindowLong(hedit,GWL_WNDPROC,(LONG)sc_edit);
									}
								}
							}
							break;
						}

					}
					break;
				}

			}
		}
		break;
	case WM_HSCROLL:
		if(lparam==hgrippy)
			SetFocus(hlistview);
		break;
	case WM_USER:
		if(hedit!=0 && lparam==hedit){
			hedit=0;
			SetFocus(hlistview);
		}
		else if(lparam==hlistview){
			if(wparam==IDOK){
				add_row_tablewindow(win,hlistview);
			}
			else
				SetFocus(GetDlgItem(hwnd,IDCANCEL));

			SetWindowText(GetDlgItem(hwnd,IDOK),"OK");
		}
		break;
	case WM_SIZE:
		resize_insert_dlg(hwnd);
		grippy_move(hwnd,hgrippy);
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam)){
		case IDOK:
			if(hedit!=0){
				if(GetFocus()==hedit){
					char str[80]={0};
					int count,row_sel=ListView_GetSelectionMark(hlistview);
					GetWindowText(hedit,str,sizeof(str));
					resize_column(hwnd,hlistview,str,1);
					lv_update_data(hlistview,row_sel,DATA_POS,str);
					SendMessage(hedit,WM_CLOSE,0,0);
					count=ListView_GetItemCount(hlistview);
					if(row_sel < (count-1)){
						ListView_SetItemState(hlistview,row_sel,0,LVIS_SELECTED|LVIS_FOCUSED);
						row_sel++;
						ListView_SetItemState(hlistview,row_sel,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
						ListView_SetSelectionMark(hlistview,row_sel);
					}
					hedit=0;
				}
				break;
			}
			else if(GetFocus()==hlistview){
				static LV_KEYDOWN lvk={0};
				lvk.hdr.hwndFrom=hlistview;
				lvk.hdr.code=LVN_KEYDOWN;
				lvk.wVKey=VK_INSERT;
				SendMessage(hwnd,WM_NOTIFY,0,&lvk);
				break;
			}
			else{
				if(task_insert_row(win,hlistview))
					SetWindowText(GetDlgItem(hwnd,IDOK),"Busy");

			}
			break;
		case IDCANCEL:
			if(hedit!=0){
				SendMessage(hedit,WM_CLOSE,0,0);
				hedit=0;
				break;
			}
			EndDialog(hwnd,0);
			break;
		}
		break;	
	}
	return 0;
}