LRESULT CALLBACK options_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) { static HWND grippy=0; switch(msg) { case WM_INITDIALOG: grippy=create_grippy(hwnd); init_options_win_anchor(hwnd); restore_options_rel_pos(hwnd); SendDlgItemMessage(hwnd,IDC_MATCH_PREFIX_LEN,EM_LIMITTEXT,4,0); populate_options(hwnd); return 0; case WM_DESTROY: save_options_rel_pos(hwnd); break; case WM_SIZE: grippy_move(hwnd,grippy); resize_options(hwnd); InvalidateRect(hwnd,NULL,TRUE); break; case WM_DRAWITEM: break; case WM_HELP: show_options_help(hwnd); return TRUE; break; case WM_COMMAND: switch(LOWORD(wparam)){ case IDC_SELECT_OPEN: if(HIWORD(wparam)==CBN_SELENDOK) populate_caption_open(hwnd); break; case IDC_COMBO_FONT: if(HIWORD(wparam)==CBN_SELENDOK){ int font; char str[80]={0}; GetDlgItemText(hwnd,IDC_COMBO_FONT,str,sizeof(str)); font=fontname_to_int(str); SendDlgItemMessage(GetParent(hwnd),IDC_COMBO_SEARCH,WM_SETFONT,GetStockObject(font),0); SendDlgItemMessage(GetParent(hwnd),IDC_COMBO_REPLACE,WM_SETFONT,GetStockObject(font),0); SendDlgItemMessage(GetParent(hwnd),IDC_COMBO_PATH,WM_SETFONT,GetStockObject(font),0); SendDlgItemMessage(GetParent(hwnd),IDC_COMBO_MASK,WM_SETFONT,GetStockObject(font),0); } break; case IDC_LISTBOX_FONT: if(HIWORD(wparam)==CBN_SELENDOK){ int font; char str[80]={0}; GetDlgItemText(hwnd,IDC_LISTBOX_FONT,str,sizeof(str)); font=fontname_to_int(str); SendDlgItemMessage(GetParent(hwnd),IDC_LIST1,WM_SETFONT,GetStockObject(font),0); reset_line_width(); InvalidateRect(GetDlgItem(GetParent(hwnd),IDC_LIST1),NULL,TRUE); } break; case IDC_OPEN_INI: open_ini(hwnd,GetKeyState(VK_CONTROL)&0x8000); break; case IDC_APPLY: save_options(hwnd); break; case IDOK: save_options(hwnd); EndDialog(hwnd,TRUE); return 0; case IDCANCEL: save_select_open(hwnd); EndDialog(hwnd,0); return 0; } break; } return 0; }
LRESULT CALLBACK install_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) { static char *path_param=0; static char local_path[MAX_PATH]={0}; static char appdata_path[MAX_PATH]={0}; static HWND grippy=0; switch(msg){ case WM_INITDIALOG: { RECT rect={0}; path_param=lparam; local_path[0]=0; GetCurrentDirectory(sizeof(local_path),local_path); SetWindowText(GetDlgItem(hwnd,IDC_TXT_LOCAL),local_path); appdata_path[0]=0; get_appdata_folder(appdata_path,sizeof(appdata_path)); SetWindowText(GetDlgItem(hwnd,IDC_TXT_APPDATA),appdata_path); grippy=create_grippy(hwnd); resize_install_dlg(hwnd); if(GetWindowRect(GetDesktopWindow(),&rect)!=0){ int cx,cy; cx=(rect.left+rect.right)/2; cy=(rect.top+rect.bottom)/2; if(GetWindowRect(hwnd,&rect)!=0){ int w,h; w=rect.right-rect.left; h=rect.bottom-rect.top; SetWindowPos(hwnd,NULL,cx-w/2,cy-h/2,0,0,SWP_NOSIZE); } } } break; case WM_SIZE: resize_install_dlg(hwnd); grippy_move(hwnd,grippy); break; case WM_COMMAND: switch(LOWORD(wparam)){ case IDC_USE_LOCAL: if(path_param!=0) strncpy(path_param,local_path,MAX_PATH); EndDialog(hwnd,1); break; case IDC_USE_APPDATA: if(path_param!=0){ CreateDirectory(appdata_path,NULL); strncpy(path_param,appdata_path,MAX_PATH); } EndDialog(hwnd,2); break; case IDCANCEL: case IDC_NO_INI: if(path_param!=0) path_param[0]=0; EndDialog(hwnd,3); break; } break; } return 0; }
LRESULT CALLBACK recent_proc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) { static HWND grippy=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_INITDIALOG: if(load_recent(hwnd,IDC_LIST1)>0){ SendDlgItemMessage(hwnd,IDC_LIST1,LB_SETCURSEL,0,0); SetFocus(GetDlgItem(hwnd,IDC_LIST1)); } else SetFocus(GetDlgItem(hwnd,IDC_RECENT_EDIT)); SendDlgItemMessage(hwnd,IDC_RECENT_EDIT,EM_LIMITTEXT,1024,0); grippy=create_grippy(hwnd); resize_recent_window(hwnd); { RECT crect={0},wrect={0}; GetClientRect(hwnd,&crect); GetClientRect(ghmainframe,&wrect); if(crect.right<wrect.right) SetWindowPos(hwnd,NULL,0,0,wrect.right,crect.bottom,SWP_NOMOVE|SWP_NOZORDER); } break; case WM_VKEYTOITEM: switch(LOWORD(wparam)){ case VK_INSERT: { char str[1024]={0}; GetDlgItemText(hwnd,IDC_RECENT_EDIT,str,sizeof(str)); } break; case VK_DELETE: { int item; item=SendDlgItemMessage(hwnd,IDC_LIST1,LB_GETCURSEL,0,0); if(item>=0){ char str[1024]={0}; SendDlgItemMessage(hwnd,IDC_LIST1,LB_GETTEXT,item,str); str[sizeof(str)-1]=0; if(delete_connect_str(str)) load_recent(hwnd,IDC_LIST1); item--; if(item<0) item=0; SendDlgItemMessage(hwnd,IDC_LIST1,LB_SETCURSEL,item,0); } } break; case VK_RETURN: break; } return -1; break; case WM_SIZE: grippy_move(hwnd,grippy); resize_recent_window(hwnd); break; case WM_COMMAND: switch(LOWORD(wparam)){ case IDC_ADD: { char str[1024]={0}; GetDlgItemText(hwnd,IDC_RECENT_EDIT,str,sizeof(str)); if(str[0]!=0){ add_connect_str(str); load_recent(hwnd,IDC_LIST1); } } break; case IDC_DELETE: SendMessage(hwnd,WM_VKEYTOITEM,VK_DELETE,0); break; case IDC_LIST1: if(HIWORD(wparam)==LBN_SELCHANGE){ char str[1024]={0}; int item; item=SendDlgItemMessage(hwnd,IDC_LIST1,LB_GETCURSEL,0,0); if(item>=0){ SendDlgItemMessage(hwnd,IDC_LIST1,LB_GETTEXT,item,str); SetDlgItemText(hwnd,IDC_RECENT_EDIT,str); } break; } if(HIWORD(wparam)!=LBN_DBLCLK) break; case IDOK: { char str[1024]={0}; int item; HWND focus=GetFocus(); if(GetDlgItem(hwnd,IDC_RECENT_EDIT)==focus){ SendMessage(hwnd,WM_COMMAND,IDC_ADD,0); break; } if(GetDlgItem(hwnd,IDC_LIST1)!=focus) break; item=SendDlgItemMessage(hwnd,IDC_LIST1,LB_GETCURSEL,0,0); if(item>=0){ SendDlgItemMessage(hwnd,IDC_LIST1,LB_GETTEXT,item,str); if(str[0]!=0){ char *s=str; if(str[0]=='>') s++; task_open_db(s); EndDialog(hwnd,0); } } } break; case IDCANCEL: EndDialog(hwnd,0); break; } break; } return 0; }
LRESULT CALLBACK MainDlg(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam) { static HWND grippy=0; static int col=0,dir=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) //if(msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE) { static DWORD tick=0; if((GetTickCount()-tick)>500) printf("--\n"); printf("*"); print_msg(msg,lparam,wparam); tick=GetTickCount(); } #endif switch(msg) { case WM_INITDIALOG: 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); ListView_SetExtendedListViewStyle(hlistview,LVS_EX_FULLROWSELECT); populate_list(hlistview,TRUE); sort_listview(hlistview,dir,col); grippy=create_grippy(hwnd); PostMessage(hwnd,WM_SIZE,0,0); //dump_main(hwnd); break; case WM_HELP: show_main_help(hwnd,(HELPINFO *)lparam); return TRUE; break; case WM_SIZE: grippy_move(hwnd,grippy); resize_main(hwnd); break; case WM_CONTEXTMENU: break; case WM_NOTIFY: { NMHDR *nmhdr=lparam; if(nmhdr!=0 && nmhdr->idFrom==IDC_LIST1){ LV_HITTESTINFO lvhit={0}; switch(nmhdr->code){ case NM_DBLCLK: GetCursorPos(&lvhit.pt); ScreenToClient(nmhdr->hwndFrom,&lvhit.pt); if(ListView_SubItemHitTest(nmhdr->hwndFrom,&lvhit)>=0) do_regjump(hlistview); break; case NM_RCLICK: case NM_CLICK: GetCursorPos(&lvhit.pt); ScreenToClient(nmhdr->hwndFrom,&lvhit.pt); if(ListView_SubItemHitTest(nmhdr->hwndFrom,&lvhit)>=0){ } printf("item = %i\n",lvhit.iSubItem); break; case LVN_ITEMCHANGED: { } break; case LVN_KEYDOWN: { } break; case LVN_COLUMNCLICK: { NMLISTVIEW *nmlv=lparam; col=nmlv->iSubItem; dir=!dir; sort_listview(hlistview,dir,col); } break; } } } break; case WM_VKEYTOITEM: switch(LOWORD(wparam)){ case '0':case '1':case'2':case'3':case'4':case'5': break; } return -1; break; case WM_CHARTOITEM: switch(wparam){ case 'z': break; case 'x': break; } break; case WM_COMMAND: switch(LOWORD(wparam)){ case IDC_REFRESH: { RECT rect={0}; RECT newrect={0}; int dx,dy,mark; ListView_GetItemRect(hlistview,0,&rect,LVIR_BOUNDS); mark=ListView_GetSelectionMark(hlistview); populate_list(hlistview,FALSE); sort_listview(hlistview,dir,col); ListView_GetItemRect(hlistview,0,&newrect,LVIR_BOUNDS); dx=-rect.left+newrect.left; dy=-rect.top+newrect.top; ListView_Scroll(hlistview,dx,dy); if(mark>=0) ListView_SetItemState(hlistview,mark,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED); SetFocus(hlistview); } break; case IDC_INFO: do_regjump(hlistview); break; case IDOK: break; case IDCANCEL: DestroyWindow(hwnd); PostQuitMessage(0); return TRUE; break; } break; case WM_QUERYENDSESSION: SetWindowLong(hwnd,DWL_MSGRESULT,TRUE); //ok to end session return TRUE; case WM_ENDSESSION: if(wparam){ SetWindowLong(hwnd,DWL_MSGRESULT,0); DestroyWindow(hwnd); PostQuitMessage(0); return TRUE; } break; case WM_CLOSE: DestroyWindow(hwnd); PostQuitMessage(0); return TRUE; break; } return 0; }
LRESULT CALLBACK MainDlg(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam) { PAINTSTRUCT ps; BITMAPINFO bmi; char str[255]; static int timer=FALSE; static int xpos=0,ypos=0,LMB=FALSE,dx=0,dy=0; static HWND hview=0; static HGLRC hglrc=0; static HDC hdc=0; int i; #ifdef _DEBUG // if(message!=0x200&&message!=0x84&&message!=0x20&&message!=WM_ENTERIDLE) // debug_printf("message=%08X wparam=%08X lparam=%08X\n",message,wparam,lparam); #endif switch(message) { case WM_INITDIALOG: bufA=malloc(bwidth*bheight*bdepth); bufB=malloc(bwidth*bheight*bdepth); if(bufA==0 || bufB==0) MessageBox(hwnd,"malloc failed","error",MB_OK); else{ memset(bufB,0,bwidth*bheight*bdepth); rand_fill(bufA,bwidth,bheight,bdepth); } create_grippy(hwnd); BringWindowToTop(hwnd); BringWindowToTop(hwnd); update_title(hwnd); SendMessage(hwnd,WM_KEYDOWN,VK_TAB,0); SendMessage(hwnd,WM_LBUTTONDOWN,0,0); create_view_windows(hwnd,&hview); init_ogl(hview,&hglrc,&hdc); resize_view(hwnd,hview); break; case WM_SIZE: { int w,h; w=LOWORD(lparam); h=HIWORD(lparam); grippy_move(hwnd); resize_view(hwnd,hview); reshape(w,h); } break; case WM_TIMER: if(LMB) handle_click(xpos,ypos); display_view1(hview,hglrc); break; case WM_COMMAND: switch(LOWORD(wparam)) { case IDC_ONTOP: SetWindowPos(hwnd,IsDlgButtonChecked(hwnd,LOWORD(wparam))? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE ); break; case WM_DESTROY: #ifndef _DEBUG if(MessageBox(hwnd,"Sure you want to quit?","QUIT",MB_OKCANCEL)!=IDOK) break; #endif PostQuitMessage(0); break; } break; case WM_PAINT: /* hdc=BeginPaint(hwnd,&ps); memset(&bmi,0,sizeof(BITMAPINFO)); bmi.bmiHeader.biBitCount=24; bmi.bmiHeader.biWidth=BUF_WIDTH; bmi.bmiHeader.biHeight=BUF_HEIGHT; bmi.bmiHeader.biPlanes=1; bmi.bmiHeader.biSize=40; if(stretch) StretchDIBits(hdc,0,0,client_rect.right,client_rect.bottom,0,0,BUF_WIDTH,BUF_HEIGHT,buffer,&bmi,DIB_RGB_COLORS,SRCCOPY); else SetDIBitsToDevice(hdc,0,0,BUF_WIDTH,BUF_HEIGHT,0,0,0,BUF_WIDTH,buffer,&bmi,DIB_RGB_COLORS); screen_updated=TRUE; EndPaint(hwnd,&ps); */ break; case WM_CLOSE: case WM_QUIT: PostQuitMessage(0); break; case WM_DROPFILES: break; case WM_RBUTTONDOWN: case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: xpos=LOWORD(lparam); ypos=HIWORD(lparam); break; case WM_MOUSEMOVE: { int x,y; int key=wparam; x=LOWORD(lparam); y=HIWORD(lparam); if(key&MK_LBUTTON){ x=xpos-x; ry=x; y=ypos-y; rx=y; printf("rz=%.1f ry=%.1f\n",rx,ry); } if(key&MK_RBUTTON){ x=xpos-x; rz=-x; printf("z=%.1f\n",rz); } update_title(hwnd); } break; case WM_MOUSEWHEEL: if(wparam&0x80000000) SendMessage(hwnd,WM_KEYDOWN,VK_NEXT,0); else SendMessage(hwnd,WM_KEYDOWN,VK_PRIOR,0); break; case WM_KEYUP: break; case WM_KEYDOWN: { int ctrl=GetKeyState(VK_CONTROL)&0x8000; int shift=GetKeyState(VK_SHIFT)&0x8000; #ifdef _DEBUG // debug_printf("message=%08X wparam=%08X lparam=%08X\n",message,wparam,lparam); #endif switch(wparam) { case VK_INSERT: clear_screen(); break; case 0xBD: case 0xBB: break; case 'Q': rx=ry=rz=0; printf("angles reset\n"); break; case 'W': break; case 0xC0: rand_fill(swap?bufB:bufA,bwidth,bheight,bdepth); break; case 'K': set_offsety(1); break; case 'L': set_offsety(-1); break; case 'X': if(shift) scale+=10; else scale++; printf("scale=%i\n",scale); break; case 'Z': if(shift) scale-=10; else scale--; printf("scale=%i\n",scale); break; //case 0xC0: change_direction(0); rx=ry=rz=0; break; case '0': case '1': //tube(); frame_step=1; break; case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': change_direction(wparam-'0'); break; case VK_SPACE: break; case VK_TAB: if(timer) KillTimer(hwnd,1); else SetTimer(hwnd,1,60,NULL); timer=!timer; break; case VK_F1: display_help(hwnd); break; /* case VK_F2: i=CreateDialog(ghInstance,MAKEINTRESOURCE(IDD_DIALOG2),hwnd,request_value); ShowWindow(i,SW_SHOWNORMAL); debug_printf("return =%i\r\n",i); break;*/ case VK_F5: break; case VK_F9: stretch=!stretch; break; case 0xDEADBEEF: break; case VK_DOWN: if(GetKeyState(VK_CONTROL)&0x8000) move_center(3); else if(GetKeyState(VK_SHIFT)&0x8000) change_direction(12); else change_direction(2); break; case VK_UP: if(GetKeyState(VK_CONTROL)&0x8000) move_center(4); else if(GetKeyState(VK_SHIFT)&0x8000) change_direction(11); else change_direction(1); break; case VK_LEFT: if(GetKeyState(VK_CONTROL)&0x8000) move_center(1); else if(GetKeyState(VK_SHIFT)&0x8000) change_direction(14); else change_direction(4); break; case VK_RIGHT: if(GetKeyState(VK_CONTROL)&0x8000) move_center(2); else if(GetKeyState(VK_SHIFT)&0x8000) change_direction(13); else change_direction(3); break; case VK_ADD: break; case VK_SUBTRACT: break; case VK_NEXT: //page key if(GetKeyState(VK_CONTROL)&0x8000) ; else if(GetKeyState(VK_SHIFT)&0x8000) ; change_direction(100); break; case VK_PRIOR: //page key if(GetKeyState(VK_CONTROL)&0x8000) ; else if(GetKeyState(VK_SHIFT)&0x8000) ; change_direction(100); break; case VK_HOME: change_direction(5); break; case VK_END: ; break; case ZOOM_IN_KEY: //[ if(GetKeyState(VK_SHIFT)&0x8000){ if(GetKeyState(VK_CONTROL)&0x8000) ; else ; } else ; break; case ZOOM_OUT_KEY: //] if(GetKeyState(VK_SHIFT)&0x8000){ if(GetKeyState(VK_CONTROL)&0x8000) ; else ; } else ; break; case 0xBE: //> if(GetKeyState(VK_SHIFT)&0x8000){ if(GetKeyState(VK_CONTROL)&0x8000) ; else ; } else ; break; case 0xBC: //< if(GetKeyState(VK_SHIFT)&0x8000){ if(GetKeyState(VK_CONTROL)&0x8000) ; else ; } else ; break; case 'V': if(GetKeyState(VK_CONTROL)&0x8000){ if(OpenClipboard(NULL)){ char *p=GetClipboardData(CF_TEXT); if(p!=0){ strncpy(str,p,sizeof(str)); SetDlgItemText(hwnd,IDC_EDIT1,str); } CloseClipboard(); } } break; case VK_ESCAPE: if(MessageBox(hwnd,"Sure you want to quit?","QUIT",MB_OKCANCEL)==IDOK) PostQuitMessage(0); break; } update_title(hwnd); } break; } return 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; }
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; }
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; }