Exemple #1
0
int populate_options(HWND hwnd)
{
	int i;
	char tmp[80];
	SendDlgItemMessage(hwnd,IDC_SELECT_OPEN,CB_RESETCONTENT,0,0);
	for(i=0;i<max_open_with;i++){
		_snprintf(tmp,sizeof(tmp),"%i",i+1);
		SendDlgItemMessage(hwnd,IDC_SELECT_OPEN,CB_ADDSTRING,0,tmp);
	}
	i=0;
	get_ini_value("OPTIONS","select_open_index",&i);
	SendDlgItemMessage(hwnd,IDC_SELECT_OPEN,CB_SETCURSEL,i,0);
	populate_caption_open(hwnd);

	SendDlgItemMessage(hwnd,IDC_COMBO_FONT,CB_RESETCONTENT,0,0);
	add_fonts(hwnd,IDC_COMBO_FONT);
	get_current_font(hwnd,IDC_COMBO_FONT);

	SendDlgItemMessage(hwnd,IDC_LISTBOX_FONT,CB_RESETCONTENT,0,0);
	add_fonts(hwnd,IDC_LISTBOX_FONT);
	get_current_font(hwnd,IDC_LISTBOX_FONT);

	i=20;
	get_ini_value("OPTIONS","match_prefix_len",&i);
	SetDlgItemInt(hwnd,IDC_MATCH_PREFIX_LEN,i,FALSE);
	i=FALSE;
	get_ini_value("OPTIONS","show_column",&i);
	if(i!=0)
		i=BST_CHECKED;
	else
		i=BST_UNCHECKED;
	CheckDlgButton(hwnd,IDC_SHOW_COLUMN,i);
	return TRUE;
}
Exemple #2
0
int load_window_size(HWND hwnd,char *section)
{
	RECT rect={0};
	int width=0,height=0,x=0,y=0,maximized=0;
	int result=FALSE;
	get_ini_value(section,"width",&width);
	get_ini_value(section,"height",&height);
	get_ini_value(section,"xpos",&x);
	get_ini_value(section,"ypos",&y);
	get_ini_value(section,"maximized",&maximized);
	if(get_nearest_monitor(x,y,width,height,&rect)){
		int flags=SWP_SHOWWINDOW;
		if((GetKeyState(VK_SHIFT)&0x8000)==0){
			if(width<50 || height<50){
				RECT tmp={0};
				GetWindowRect(hwnd,&tmp);
				width=tmp.right-tmp.left;
				height=tmp.bottom-tmp.top;
				flags|=SWP_NOSIZE;
			}
			if(!clamp_window_size(&x,&y,&width,&height,&rect))
				flags|=SWP_NOMOVE;
			if(SetWindowPos(hwnd,HWND_TOP,x,y,width,height,flags)!=0)
				result=TRUE;
		}
	}
	if(maximized)
		PostMessage(hwnd,WM_SYSCOMMAND,SC_MAXIMIZE,0);
	return result;
}
Exemple #3
0
int restore_window(HWND hwnd,const char *WINDOW_NAME)
{
	int result=FALSE;
	int x=-100,y=-100,w=0,h=0,max=0;
	get_ini_value(WINDOW_NAME,"xpos",&x);
	get_ini_value(WINDOW_NAME,"ypos",&y);
	get_ini_value(WINDOW_NAME,"width",&w);
	get_ini_value(WINDOW_NAME,"height",&h);
	get_ini_value(WINDOW_NAME,"maximized",&max);
	return set_window_pos(hwnd,x,y,w,h,max);
}
Exemple #4
0
int restore_scroll(HWND hedit,const char *WINDOW_NAME)
{
	int x=0,y=0,a=0,b=0;
	SCROLLINFO si={0};
	get_ini_value(WINDOW_NAME,"scrollx",&x);
	get_ini_value(WINDOW_NAME,"scrolly",&y);
	get_ini_value(WINDOW_NAME,"select_start",&a);
	get_ini_value(WINDOW_NAME,"select_end",&b);
	si.cbSize=sizeof(SCROLLINFO);
	si.fMask=SIF_POS;
	si.nPos=y;
	SetScrollInfo(hedit,SB_VERT,&si,TRUE);
	si.nPos=x;
	SetScrollInfo(hedit,SB_HORZ,&si,TRUE);
	SendMessage(hedit,EM_SETSEL,a,b);
	return TRUE;
}
Exemple #5
0
int restore_window_pos(HWND hwnd)
{
	const char *SECT="WINDOW";
	int x=0,y=0,w=0,h=0,maximized=0;
	if(get_ini_value(SECT,"XPOS",&x) && get_ini_value(SECT,"YPOS",&y)
		&& get_ini_value(SECT,"WIDTH",&w) && get_ini_value(SECT,"HEIGHT",&h)){
		WINDOWPLACEMENT wp={0};
		int show=SW_SHOWNORMAL;
		get_ini_value(SECT,"MAXIMIZED",&maximized);
		if(maximized)
			show=SW_SHOWMAXIMIZED;
		wp.length=sizeof(wp);
		wp.showCmd=show;
		wp.rcNormalPosition.left=x;
		wp.rcNormalPosition.top=y;
		wp.rcNormalPosition.right=x+w;
		wp.rcNormalPosition.bottom=y+h;
		clamp_window(&wp.rcNormalPosition);
		if(w>50 && h>50)
			SetWindowPlacement(hwnd,&wp);
	}
	return 0;
}
Exemple #6
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	MSG msg;
    INITCOMMONCONTROLSEX ctrls;
	HACCEL haccel;
	static char *class_name="DB_UTIL_CLASS";
	int first_instance=TRUE;
	int debug=0;

	first_instance=set_single_instance(TRUE);

	ghinstance=hInstance;
	init_ini_file();

#ifdef _DEBUG
	debug=1;
#else
	get_ini_value("SETTINGS","DEBUG",&debug);
#endif
	if(debug!=0){
		open_console();
	}

	{
		int val=0;
		get_ini_value("SETTINGS","SINGLE_INSTANCE",&val);
		if(val && (!first_instance)){
			COPYDATASTRUCT cd={0};
			HWND hdbutil;
			cd.cbData=nCmdShow;
			cd.cbData=strlen(lpCmdLine)+1;
			cd.lpData=lpCmdLine;
			hdbutil=FindWindow("DB_UTIL_CLASS",NULL);
			if(hdbutil!=0){
				int sw;
				SendMessage(hdbutil,WM_COPYDATA,hInstance,&cd);
				if (IsZoomed(hdbutil))
					sw=SW_MAXIMIZE;
				else if(IsIconic(hdbutil))
					sw=SW_RESTORE;
				else
					sw=SW_SHOW;
				ShowWindow(hdbutil,sw);
				SetForegroundWindow(hdbutil);
			}
			return TRUE;
		}
		set_single_instance(val);
	}
	init_mdi_stuff();

	LoadLibrary("RICHED20.DLL");
	LoadLibrary("Msftedit.dll");

	ctrls.dwSize=sizeof(ctrls);
    ctrls.dwICC = ICC_LISTVIEW_CLASSES|ICC_TREEVIEW_CLASSES|ICC_BAR_CLASSES;
	InitCommonControlsEx(&ctrls);
	
	InitializeCriticalSection(&mutex);

	start_worker_thread();
	start_intellisense_thread();

	setup_mdi_classes(ghinstance);
	
	ghmenu=LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
	ghmainframe=create_mainwindow(&WndProc,ghmenu,hInstance,class_name,"DB_UTIL");

	ShowWindow(ghmainframe,nCmdShow);
	UpdateWindow(ghmainframe);

	haccel=LoadAccelerators(ghinstance,MAKEINTRESOURCE(IDR_ACCELERATOR1));

	process_cmd_line(lpCmdLine);

    while(GetMessage(&msg,NULL,0,0)){
		if(!custom_dispatch(&msg))
		if(!TranslateMDISysAccel(ghmdiclient, &msg) && !TranslateAccelerator(ghmainframe,haccel,&msg)){
			TranslateMessage(&msg);
			//if(msg!=WM_MOUSEFIRST&&msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE&&msg!=WM_NOTIFY)
			if(FALSE)
			if(msg.message!=0x118&&msg.message!=WM_NCHITTEST&&msg.message!=WM_SETCURSOR&&msg.message!=WM_ENTERIDLE&&msg.message!=WM_NCMOUSEMOVE&&msg.message!=WM_MOUSEFIRST)
			{
				static DWORD tick=0;
				if((GetTickCount()-tick)>500)
					printf("--\n");
				printf("x");
				print_msg(msg.message,msg.lParam,msg.wParam,msg.hwnd);
				tick=GetTickCount();
			}
			DispatchMessage(&msg);
		}
    }
	DeleteCriticalSection(&mutex);
    return msg.wParam;
	
}
Exemple #7
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	static HWND last_focus=0;
	if(FALSE)
	//if(msg!=WM_MOUSEFIRST&&msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE&&msg!=WM_NOTIFY)
	if(msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE&&msg!=WM_MOUSEMOVE&&msg!=WM_NCMOUSEMOVE)
	{
		static DWORD tick=0;
		if((GetTickCount()-tick)>500)
			printf("--\n");
		print_msg(msg,lparam,wparam,hwnd);
		tick=GetTickCount();
	}
    switch(msg)
    {
	case WM_MENUSELECT:
		break;
	case WM_CREATE:
		{
			RECT rect={0};
			extern int keep_closed,trim_trailing,left_justify;
			get_ini_value("SETTINGS","KEEP_CLOSED",&keep_closed);
			get_ini_value("SETTINGS","TRIM_TRAILING",&trim_trailing);
			get_ini_value("SETTINGS","LEFT_JUSTIFY",&left_justify);
			load_icon(hwnd);

			load_window_size(hwnd,"MAIN_WINDOW");

			GetClientRect(hwnd,&rect);
			get_ini_value("SETTINGS","TREE_WIDTH",&tree_width);
			if(tree_width>rect.right-10 || tree_width<10){
				tree_width=rect.right/4;
				if(tree_width<12)
					tree_width=12;
			}

			ghmdiclient=create_mdiclient(hwnd,ghmenu,ghinstance);
			ghdbview=create_dbview(hwnd,ghinstance);
			ghstatusbar=CreateStatusWindow(WS_CHILD|WS_VISIBLE,"ready",hwnd,IDC_STATUS);
			create_status_bar_parts(hwnd,ghstatusbar);

			resize_main_window(hwnd,tree_width);
		}
		break;
	case WM_DROPFILES:
		process_drop(hwnd,wparam);
		break;
	case WM_COPYDATA:
		if(lparam!=0){
			COPYDATASTRUCT *cd=lparam;
			process_cmd_line(cd->lpData);
		}
		break;
	case WM_USER:
		debug_window_focus(lparam,"WM_USER");
		switch(wparam){
		case IDC_TREEVIEW:
			if(lparam!=0)
				SetFocus(lparam);
			break;
		case IDC_MDI_LISTVIEW:
			if(lparam!=0){
				last_focus=lparam;
				SetFocus(lparam);
			}
			break;
		case IDC_LV_EDIT:
			if(lparam!=0)
				last_focus=lparam;
			break;
		}
		break;
	case WM_USER+1:
		debug_window_focus(last_focus,"WMUSER+1");
		if(last_focus!=0)
			SetFocus(last_focus);
		break;
	case WM_NCACTIVATE:
		debug_window_focus(last_focus,"NCACTIVATE wparam=%08X",wparam);
		if(wparam==0){
			last_focus=GetFocus();
		}
		else{
			PostMessage(hwnd,WM_USER+1,0,0);
		}
		break;
	case WM_ACTIVATEAPP: //close any tooltip on app switch
		debug_window_focus(last_focus,"ACTIVATEAPP wparam=%08X",wparam);
		if(wparam){
			PostMessage(hwnd,WM_USER+1,0,0);
		}
		break;
	case WM_KILLFOCUS:
	case WM_RBUTTONDOWN:
	case WM_LBUTTONUP:
		if(main_drag){
			ReleaseCapture();
			main_drag=FALSE;
			write_ini_value("SETTINGS","TREE_WIDTH",tree_width);
		}
		break;
	case WM_LBUTTONDOWN:
		{
			int x=LOWORD(lparam);
			if(x>=(tree_width-10) && x<(tree_width+10)){
				SetCapture(hwnd);
				SetCursor(LoadCursor(NULL,IDC_SIZEWE));
				main_drag=TRUE;
			}
		}
		break;
	case WM_MOUSEFIRST:
		{
			int x=LOWORD(lparam);
			if(x>=(tree_width-10) && x<(tree_width+10))
				SetCursor(LoadCursor(NULL,IDC_SIZEWE));
			if(main_drag){
				RECT rect;
				GetClientRect(ghmainframe,&rect);
				if(x>10 && x<rect.right-10){
					tree_width=x;
					resize_main_window(hwnd,tree_width);
				}
			}
		}
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam)){
		case IDM_OPEN:
			if((GetKeyState(VK_SHIFT)&0x8000) || GetKeyState(VK_CONTROL)&0x8000)
				task_open_db("");
			else{
				if(does_key_exist("SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources","Journal"))
					task_open_db("UID=dba;PWD=sql;DSN=Journal");
				else
					task_open_db("");
			}
			break;
		case IDM_CLOSE:
			{
			HANDLE hroot=0;
			if(tree_find_focused_root(&hroot)){
				char str[MAX_PATH]={0};
				tree_get_db_table(hroot,str,sizeof(str),0,0,0);
				if(str[0]!=0){
					set_status_bar_text(ghstatusbar,0,"closing %s",str);
					task_close_db(str);
				}
			}
			else
				set_status_bar_text(ghstatusbar,0,"select a DB");
			}
			break;
		case IDM_SETTINGS:
			DialogBox(ghinstance,MAKEINTRESOURCE(IDD_SETTINGS),hwnd,settings_proc);
			break;
		case IDM_RECENT:
			DialogBox(ghinstance,MAKEINTRESOURCE(IDD_RECENT),hwnd,recent_proc);
			break;
		case IDM_STOP_THREAD:
			{
				int click=MessageBox(hwnd,"Are you sure you want to terminate the task?","Warning",MB_OKCANCEL|MB_SYSTEMMODAL);
				if(click==IDOK){
					terminate_worker_thread();
					stop_thread_menu(FALSE);
				}
			}
			break;
		case IDM_QUERY:
			task_new_query();
			break;
		case IDC_EXECUTE_SQL:
			task_execute_query(NULL);
			break;
		case IDM_TILE_DIALOG:
			tile_select_dialog(hwnd);
			break;
		case IDM_WINDOW_TILE:
			mdi_tile_windows_vert();
			break;
		case IDM_WINDOW_CASCADE:
			mdi_cascade_win_vert();
			break;
		case IDM_WINDOW_LRTILE:
			mdi_tile_windows_horo();
			break;
		case IDM_REFRESH_ALL:
			refresh_all_dialog(hwnd);
			break;
		case IDM_REORDER:
			reorder_win_dialog(hwnd);
			break;
		}
		break;
	case WM_SIZE:
		resize_main_window(hwnd,tree_width);
		create_status_bar_parts(ghmainframe,ghstatusbar);
		return 0;
		break;
	case WM_QUERYENDSESSION:
		return 1; //ok to end session
		break;
	case WM_ENDSESSION:
		if(wparam){
			if(!(GetKeyState(VK_SHIFT)&0x8000))
				save_window_size(hwnd,"MAIN_WINDOW");
		}
		return 0;
	case WM_CLOSE:
        break;
	case WM_DESTROY:
		if(!(GetKeyState(VK_SHIFT)&0x8000))
			save_window_size(hwnd,"MAIN_WINDOW");
		PostQuitMessage(0);
        break;
    }
	return DefFrameProc(hwnd, ghmdiclient, msg, wparam, lparam);
}
Exemple #8
0
LRESULT CALLBACK settings_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	static HWND grippy=0;
	static int font_changed=FALSE;
	static int justify_changed=FALSE;
	switch(msg){
	case WM_INITDIALOG:
		{
			extern int keep_closed;
			int val;
			get_ini_value(INI_SETTINGS,"KEEP_CLOSED",&keep_closed);
			if(!keep_closed)
				CheckDlgButton(hwnd,IDC_KEEP_CONNECTED,BST_CHECKED);
			val=0;
			get_ini_value(INI_SETTINGS,"SINGLE_INSTANCE",&val);
			if(val)
				CheckDlgButton(hwnd,IDC_SINGLE_INSTANCE,BST_CHECKED);
			val=0;
			get_ini_value(INI_SETTINGS,"DEBUG",&val);
			if(val)
				CheckDlgButton(hwnd,IDC_DEBUG,BST_CHECKED);

			get_ini_value(INI_SETTINGS,"TRIM_TRAILING",&trim_trailing);
			if(trim_trailing)
				CheckDlgButton(hwnd,IDC_TRIM_TRAILING,BST_CHECKED);

			get_ini_value(INI_SETTINGS,"LEFT_JUSTIFY",&left_justify);
			if(left_justify)
				CheckDlgButton(hwnd,IDC_LEFT_JUSTIFY,BST_CHECKED);

			get_ini_value(INI_SETTINGS,"SAVE_MDI_WIN_SIZE",&save_mdi_win_size);
			if(save_mdi_win_size)
				CheckDlgButton(hwnd,IDC_SAVE_MDI_WIN_SIZE,BST_CHECKED);

			add_fonts(hwnd,IDC_SQL_FONT);
			add_fonts(hwnd,IDC_LISTVIEW_FONT);
			add_fonts(hwnd,IDC_TREEVIEW_FONT);
			select_current_font(hwnd,IDC_SQL_FONT);
			select_current_font(hwnd,IDC_LISTVIEW_FONT);
			select_current_font(hwnd,IDC_TREEVIEW_FONT);
			font_changed=FALSE;
			justify_changed=FALSE;
		}
		grippy=create_grippy(hwnd);
		break;
	case WM_SIZE:
		grippy_move(hwnd,grippy);
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam)){
		case IDC_DEBUG:
			printf("debug %08X %08X\n",wparam,lparam);
			if(IsDlgButtonChecked(hwnd,IDC_DEBUG)==BST_CHECKED)
				open_console();
			else
				hide_console();
			break;
		case IDC_FILE_ASSOCIATIONS:
			DialogBoxParam(ghinstance,IDD_FILE_ASSOCIATIONS,hwnd,file_assoc_proc,0);
			break;
		case IDC_OPEN_INI:
			open_ini(hwnd,FALSE);
			break;
		case IDC_SQL_FONT:
			if(HIWORD(wparam)==CBN_SELENDOK){
				int i,max=get_max_table_windows();
				int font;
				char str[80]={0};
				GetDlgItemText(hwnd,IDC_SQL_FONT,str,sizeof(str));
				font=fontname_to_int(str);
				for(i=0;i<max;i++){
					HWND hedit=0;
					if(get_win_hwnds(i,NULL,&hedit,NULL)){
						SendMessage(hedit,WM_SETFONT,GetStockObject(font),0);
						InvalidateRect(hedit,NULL,TRUE);
					}
				}
				font_changed=TRUE;
			}
			break;
		case IDC_LISTVIEW_FONT:
			if(HIWORD(wparam)==CBN_SELENDOK){
				int i,max=get_max_table_windows();
				int font;
				char str[80]={0};
				GetDlgItemText(hwnd,IDC_LISTVIEW_FONT,str,sizeof(str));
				font=fontname_to_int(str);
				for(i=0;i<max;i++){
					HWND hlistview;
					if(get_win_hwnds(i,NULL,NULL,&hlistview)){
						SendMessage(hlistview,WM_SETFONT,GetStockObject(font),0);
						InvalidateRect(hlistview,NULL,TRUE);
					}
				}
				font_changed=TRUE;
			}
			break;
		case IDC_TREEVIEW_FONT:
			if(HIWORD(wparam)==CBN_SELENDOK){
				extern HWND ghtreeview;
				int font;
				char str[80]={0};
				GetDlgItemText(hwnd,IDC_TREEVIEW_FONT,str,sizeof(str));
				font=fontname_to_int(str);
				if(ghtreeview!=0){
					SendMessage(ghtreeview,WM_SETFONT,GetStockObject(font),0);
					InvalidateRect(ghtreeview,NULL,TRUE);
				}
				font_changed=TRUE;
			}
			break;
		case IDC_LEFT_JUSTIFY:
			if(HIWORD(wparam)==BN_CLICKED){
				extern int left_justify;
				int i,max=get_max_table_windows();
				if(IsDlgButtonChecked(hwnd,IDC_LEFT_JUSTIFY)==BST_CHECKED)
					left_justify=1;
				else
					left_justify=0;
				for(i=0;i<max;i++){
					HWND hlistview;
					if(get_win_hwnds(i,NULL,NULL,&hlistview))
						InvalidateRect(hlistview,NULL,TRUE);
				}
				justify_changed=TRUE;
			}
			break;
		case IDOK:
			{
			extern int keep_closed;
			char key[80],str[80];
			int i,val,ctrls[3]={IDC_SQL_FONT,IDC_LISTVIEW_FONT,IDC_TREEVIEW_FONT};
			if(IsDlgButtonChecked(hwnd,IDC_KEEP_CONNECTED)==BST_CHECKED)
				keep_closed=FALSE;
			else
				keep_closed=TRUE;
			
			write_ini_value(INI_SETTINGS,"KEEP_CLOSED",keep_closed);

			val=0;
			if(IsDlgButtonChecked(hwnd,IDC_SINGLE_INSTANCE)==BST_CHECKED)
				val=1;
			write_ini_value(INI_SETTINGS,"SINGLE_INSTANCE",val);
			set_single_instance(val);

			val=0;
			if(IsDlgButtonChecked(hwnd,IDC_DEBUG)==BST_CHECKED)
				val=1;
			write_ini_value(INI_SETTINGS,"DEBUG",val);

			
			if(IsDlgButtonChecked(hwnd,IDC_TRIM_TRAILING)==BST_CHECKED)
				trim_trailing=1;
			else
				trim_trailing=0;
			write_ini_value(INI_SETTINGS,"TRIM_TRAILING",trim_trailing);

			if(IsDlgButtonChecked(hwnd,IDC_LEFT_JUSTIFY)==BST_CHECKED)
				left_justify=1;
			else
				left_justify=0;
			write_ini_value(INI_SETTINGS,"LEFT_JUSTIFY",left_justify);

			if(IsDlgButtonChecked(hwnd,IDC_SAVE_MDI_WIN_SIZE)==BST_CHECKED)
				save_mdi_win_size=1;
			else
				save_mdi_win_size=0;
			write_ini_value(INI_SETTINGS,"SAVE_MDI_SIZE",save_mdi_win_size);

			for(i=0;i<sizeof(ctrls)/sizeof(int);i++){
				key[0]=0;
				get_control_name(ctrls[i],key,sizeof(key));
				str[0]=0;
				GetDlgItemText(hwnd,ctrls[i],str,sizeof(str));
				write_ini_str(INI_SETTINGS,key,str);
			}
			}
		case IDCANCEL:
			if(font_changed){
				int i,ctrls[3]={IDC_SQL_FONT,IDC_LISTVIEW_FONT,IDC_TREEVIEW_FONT};
				for(i=0;i<sizeof(ctrls)/sizeof(int);i++){
					char key[80],str[80];
					key[0]=0;
					get_control_name(ctrls[i],key,sizeof(key));
					str[0]=0;
					GetDlgItemText(hwnd,ctrls[i],str,sizeof(str));
					get_ini_str(INI_SETTINGS,key,str,sizeof(str));
					if(str[0]!=0){
						int max=get_max_table_windows();
						int font=fontname_to_int(str);
						if(ctrls[i]==IDC_SQL_FONT){
							int j;
							for(j=0;j<max;j++){
								HWND hedit=0;
								if(get_win_hwnds(j,NULL,&hedit,NULL)){
									SendMessage(hedit,WM_SETFONT,GetStockObject(font),0);
									InvalidateRect(hedit,NULL,TRUE);
								}
							}
						}
						else if(ctrls[i]==IDC_LISTVIEW_FONT){
							int j;
							for(j=0;j<max;j++){
								HWND hlistview;
								if(get_win_hwnds(j,NULL,NULL,&hlistview)){
									SendMessage(hlistview,WM_SETFONT,GetStockObject(font),0);
									InvalidateRect(hlistview,NULL,TRUE);
								}
							}
						}
						else if(ctrls[i]==IDC_TREEVIEW_FONT){
							extern HWND ghtreeview;
							SendMessage(ghtreeview,WM_SETFONT,GetStockObject(font),0);
						}
					}
				}
			}
			if(justify_changed){
				int i,max=get_max_table_windows();
				get_ini_value(INI_SETTINGS,"LEFT_JUSTIFY",&left_justify);
				for(i=0;i<max;i++){
					HWND hlistview;
					if(get_win_hwnds(i,NULL,NULL,&hlistview))
						InvalidateRect(hlistview,NULL,TRUE);
				}
			}
			EndDialog(hwnd,0);
			break;
		}
		break;
	}
	return 0;
}
Exemple #9
0
LRESULT CALLBACK view_context_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	static HWND grippy=0;
	int lines,dir,do_scroll=FALSE,update_scroll_pos=TRUE;
	static int divider_drag=FALSE,org_row_width=90,row_width=90,last_pos=0;
#ifdef _DEBUG
	if(FALSE)
//	if(message!=0x200&&message!=0x84&&message!=0x20&&message!=WM_ENTERIDLE)
//	if(msg!=WM_MOUSEFIRST&&msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE&&msg!=WM_DRAWITEM
//		&&msg!=WM_CTLCOLORBTN&&msg!=WM_CTLCOLOREDIT&&msg!=WM_CTLCOLORSCROLLBAR)
	if(msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE)
	{
		static DWORD tick=0;
		if((GetTickCount()-tick)>500)
			printf("--\n");
		printf("v");
		print_msg(msg,lparam,wparam);
		tick=GetTickCount();
	}
#endif	
	switch(msg)
	{
	case WM_INITDIALOG:
		grippy=create_grippy(hwnd);
		init_context_win_anchor(hwnd);
		get_ini_value("CONTEXT_WINDOW","row_width",&row_width);
		set_context_divider(hwnd,row_width);
		restore_context_rel_pos(hwnd);

		SendDlgItemMessage(hwnd,IDC_CONTEXT_SCROLLBAR,SBM_SETRANGE,0,10000);
		{
			int tabstop=21; //4 fixed chars
			SendDlgItemMessage(hwnd,IDC_CONTEXT,EM_SETTABSTOPS,1,&tabstop);
		}
		set_context_font(hwnd);
		open_file(&gfh);
		if(gfh==0){
			WCHAR str[MAX_PATH*2];
			_snwprintf(str,sizeof(str)/sizeof(WCHAR),L"cant open %s",fname);
			str[sizeof(str)/sizeof(WCHAR)-1]=0;
			MessageBoxW(hwnd,str,L"error",MB_OK);
			EndDialog(hwnd,0);
			return 0;
		}
		get_file_size(gfh,&fsize);
		_fseeki64(gfh,start_offset,SEEK_SET);
		set_scroll_pos(hwnd,IDC_CONTEXT_SCROLLBAR,gfh);
		SetFocus(GetDlgItem(hwnd,IDC_CONTEXT_SCROLLBAR));
		line_count=get_number_of_lines(hwnd,IDC_CONTEXT);
		fill_context(hwnd,IDC_CONTEXT,gfh);
		close_file(&gfh);
		last_pos=-1;
		orig_edit=SetWindowLong(GetDlgItem(hwnd,IDC_CONTEXT),GWL_WNDPROC,subclass_edit);
		orig_scroll=SetWindowLong(GetDlgItem(hwnd,IDC_CONTEXT_SCROLLBAR),GWL_WNDPROC,subclass_scroll);
		SetWindowTextW(hwnd,fname);
		return 0;
	case WM_DESTROY:
		save_context_rel_pos(hwnd);
		break;
	case WM_HELP:
		context_help(hwnd);
		return TRUE;
		break;
	case WM_SIZE:
		grippy_move(hwnd,grippy);
		set_context_divider(hwnd,row_width);
		line_count=get_number_of_lines(hwnd,IDC_CONTEXT);
		open_file(&gfh);
		fill_context(hwnd,IDC_CONTEXT,gfh);
		set_scroll_pos(hwnd,IDC_CONTEXT_SCROLLBAR,gfh);
		close_file(&gfh);
		break;
	case WM_RBUTTONDOWN:
	case WM_LBUTTONUP:
		ReleaseCapture();
		if(divider_drag){
			write_ini_value("CONTEXT_WINDOW","row_width",row_width);
			divider_drag=FALSE;
		}
		break;
	case WM_LBUTTONDOWN:
		SetCapture(hwnd);
		SetCursor(LoadCursor(NULL,IDC_SIZEWE));
		divider_drag=TRUE;
		org_row_width=row_width;
		break;
	case WM_MOUSEFIRST:
		{
			int x=LOWORD(lparam);
			SetCursor(LoadCursor(NULL,IDC_SIZEWE));
			if(divider_drag){
				RECT rect;
				GetClientRect(hwnd,&rect);
				if((rect.right-x)>25 && x>5){
					row_width=x;
					set_context_divider(hwnd,row_width);
				}
			}
		}
		break;
	case WM_MOUSEWHEEL:
		{
			short wheel=HIWORD(wparam);
			int flags=LOWORD(wparam);
			if(wheel>0){
				dir=-1;
				if(flags&MK_RBUTTON)
					lines=line_count-2;
				else
					lines=3+1;
			}
			else{
				dir=1;
				if(flags&MK_RBUTTON)
					lines=line_count-2-1;
				else
					lines=3;
			}
			do_scroll=TRUE;
		}
		break;
	case WM_VSCROLL:
		{
		int pos=HIWORD(wparam);
		switch(LOWORD(wparam)){
		case SB_TOP:
			if(GetKeyState(VK_CONTROL)&0x8000){
				last_offset=0;
				current_line=1;
			}
			else{
				last_offset=start_offset; //_fseeki64(f,start_offset,SEEK_SET);
				current_line=start_line;
			}
			lines=dir=0;
			do_scroll=TRUE;
			break;
		case SB_PAGEUP:
			dir=-1;
			lines=line_count-2;
			if(lines<=0)
				lines=1;
			do_scroll=TRUE;
			break;
		case SB_PAGEDOWN:
			dir=1;
			lines=line_count-2-1;
			if(lines<=0)
				lines=1;
			do_scroll=TRUE;
			break;
		case SB_LINEUP:
			dir=-1;
			lines=2;
			do_scroll=TRUE;
			break;
		case SB_LINEDOWN:
			dir=1;
			lines=1;
			do_scroll=TRUE;
			break;
		case SB_THUMBTRACK:
			//printf("pos=%i last_pos=%i scroll_pos=%i line_count=%i\n",HIWORD(wparam),last_pos,scroll_pos,line_count);
			if(pos<last_pos){
				dir=-1;
				lines=line_count/4;
				if(lines<=1)
					lines=2;
				do_scroll=TRUE;
			}
			else if(pos>last_pos){
				dir=1;
				lines=line_count/4;
				if(lines==0)
					lines=1;
				do_scroll=TRUE;
			}
			if(last_pos==-1)
				do_scroll=FALSE;
			last_pos=pos;
			update_scroll_pos=FALSE;
			break;
		case SB_THUMBPOSITION: //dragged and released
			dir=lines=0;
			do_scroll=TRUE;
			break;
		case SB_ENDSCROLL:
			last_pos=-1;
			break;
		}
		}
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam)){
		case IDCANCEL:
			if(divider_drag){
				divider_drag=FALSE;
				ReleaseCapture();
				set_context_divider(hwnd,org_row_width);
				row_width=org_row_width;
				return 0;
			}
			if(gfh!=0)
				fclose(gfh);
			gfh=0;
			if(orig_edit!=0)SetWindowLong(GetDlgItem(hwnd,IDC_CONTEXT),GWL_WNDPROC,orig_edit);
			EndDialog(hwnd,0);
			return 0;
		}
		break;
	}
	if(do_scroll)
		do_scroll_proc(hwnd,lines,dir,update_scroll_pos);
	return 0;
}