void outwnd_print(const char *id, const char *tmp) { uint i; if ( (id == NULL) || (tmp == NULL) ) return; if ( !outwnd_inited ) { fputs("outwnd not initialized yet... \n", stdout); fputs(tmp, stdout); fflush(stdout); return; } if (Outwnd_no_filter_file == 1) { Outwnd_no_filter_file = 2; outwnd_print( "general", "==========================================================================\n" ); outwnd_print( "general", "DEBUG SPEW: No debug_filter.cfg found, so only general, error, and warning\n" ); outwnd_print( "general", "categories can be shown and no debug_filter.cfg info will be saved.\n" ); outwnd_print( "general", "==========================================================================\n" ); } for (i = 0; i < OutwndFilter.size(); i++) { if ( !stricmp(id, OutwndFilter[i].name) ) break; } // id found that isn't in the filter list yet if ( i == OutwndFilter.size() ) { // Only create new filters if there was a filter file if (Outwnd_no_filter_file) return; Assert( strlen(id)+1 < NAME_LENGTH ); outwnd_filter_struct new_filter; strcpy_s(new_filter.name, id); new_filter.enabled = true; OutwndFilter.push_back( new_filter ); save_filter_info(); } if ( !OutwndFilter[i].enabled ) return; if (Log_debug_output_to_file) { if (Log_fp != NULL) { fputs(tmp, Log_fp); fflush(Log_fp); } } else { fputs(tmp, stdout); fflush(stdout); } }
LRESULT CALLBACK outwnd_handler(HWND hwnd,UINT msg,WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_ACTIVATEAPP: // The application z-ordering has change // foreground application wParm will be OutputActive = (BOOL)wParam; break; case WM_CREATE: { SCROLLINFO si; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_RANGE | SIF_POS; si.nMin = 0; si.nMax = max_scroll_pos; si.nPos = max_scroll_pos; SetScrollInfo(hwnd, SB_VERT, &si, 1 ); } break; case WM_TIMER: if (scroll_wait) PostMessage(hwnd, WM_MOUSEMOVE, 0, last_mousemove); if ( Outwnd_changed ) { RECT client; GetClientRect(hOutputWnd, &client); client.top = client.bottom - nTextHeight; InvalidateRect(hOutputWnd,&client,0); } scroll_wait = 0; break; case WM_COMMAND: { int z; z = LOWORD(wParam); if (z >= ID_FILTER && z < ID_FILTER + outwnd_filter_count) { z -= ID_FILTER; outwnd_filter[z]->state = !outwnd_filter[z]->state; if ( !stricmp( outwnd_filter[z]->name, "error" ) ) { outwnd_filter[z]->state = 1; } else if ( !stricmp( outwnd_filter[z]->name, "general" ) ) { outwnd_filter[z]->state = 1; } else if ( !stricmp( outwnd_filter[z]->name, "warning" ) ) { outwnd_filter[z]->state = 1; } save_filter_info(); break; } switch (z) { case ID_COPY: outwnd_copy_marked_selection(hwnd); break; /* case ID_FIND: if (DialogBox(GetModuleHandle(NULL), "FIND_DIALOG", hOutputWnd, (int (__stdcall *)(void)) find_dlg_handler) == IDOK) { find_text_in_outwindow(mprintf_last_line, 0); } break; */ } break; } case WM_RBUTTONDOWN: { HMENU h_menu = CreatePopupMenu(); HMENU h_sub_menu = CreatePopupMenu(); POINT pt; int i; for (i=0; i<outwnd_filter_count; i++) { UINT flags = MFT_STRING; //MF_GRAYED; if ( !stricmp( outwnd_filter[i]->name, "error" ) ) { flags |= MF_GRAYED; } else if ( !stricmp( outwnd_filter[i]->name, "general" ) ) { flags |= MF_GRAYED; } else if ( !stricmp( outwnd_filter[i]->name, "warning" ) ) { flags |= MF_GRAYED; } if (outwnd_filter[i]->state) AppendMenu(h_sub_menu, flags | MF_CHECKED, ID_FILTER + i, outwnd_filter[i]->name); else AppendMenu(h_sub_menu, flags, ID_FILTER + i, outwnd_filter[i]->name); } AppendMenu(h_menu, MFT_STRING, ID_COPY, "&Copy\tEnter"); AppendMenu(h_menu, MFT_STRING, ID_FIND, "&Find Text"); AppendMenu(h_menu, MF_POPUP, (unsigned int) h_sub_menu, "Filter &Messages"); pt.x = LOWORD(lParam); pt.y = HIWORD(lParam); ClientToScreen(hwnd, &pt); TrackPopupMenu(h_menu, 0, pt.x, pt.y, 0, hwnd, NULL); DestroyMenu(h_menu); break; } case WM_LBUTTONDOWN: fix_marking_coords(marking_started_x, marking_started_y, lParam); SetCapture(hwnd); // monopolize mouse marking_active = 1; outwnd_update_marking(lParam, hwnd); break; case WM_MOUSEMOVE: last_mousemove = lParam; if (marking_active){ outwnd_update_marking(lParam, hwnd); } break; case WM_LBUTTONUP: if (marking_active) { ReleaseCapture(); marking_active = 0; outwnd_update_marking(lParam, hwnd); } break; case WM_VSCROLL: { SCROLLINFO si; int vpos = GetScrollPos( hwnd, SB_VERT ); int old_vpos=vpos; switch (LOWORD(wParam)) { case SB_LINEDOWN: vpos++; break; case SB_LINEUP: vpos--; break; case SB_THUMBPOSITION: vpos = HIWORD(wParam); break; case SB_THUMBTRACK: vpos = HIWORD(wParam); break; case SB_PAGEDOWN: vpos += nCharRows; break; case SB_PAGEUP: vpos -= nCharRows; break; } if ( vpos < 0 ) vpos = 0; else if ( vpos > max_scroll_pos ) vpos = max_scroll_pos; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_POS; si.nPos = vpos; SetScrollInfo(hwnd, SB_VERT, &si, 1 ); ScrollWindow(hwnd,0,(old_vpos-vpos)*nTextHeight,NULL,NULL); UpdateWindow(hOutputWnd); //InvalidateRect(hOutputWnd,NULL,0); } break; case WM_KEYDOWN: { SCROLLINFO si; int vpos = GetScrollPos( hwnd, SB_VERT ); int old_vpos=vpos; int nVirtKey = (int) wParam; // virtual-key code switch(nVirtKey) { case VK_DOWN: case VK_RIGHT: vpos++; break; case VK_UP: case VK_LEFT: vpos--; break; case VK_NEXT: vpos += nCharRows; break; case VK_PRIOR: vpos -= nCharRows; break; case VK_END: vpos = 0; break; case VK_HOME: vpos = max_scroll_pos; break; case VK_RETURN: outwnd_copy_marked_selection(hwnd); break; case UP_FAST: // special value we define vpos -= 5; break; case DOWN_FAST: // special value we define vpos += 5; break; } if ( vpos < 0 ) vpos = 0; else if ( vpos > max_scroll_pos ) vpos = max_scroll_pos; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_POS; si.nPos = vpos; SetScrollInfo(hwnd, SB_VERT, &si, 1 ); ScrollWindow(hwnd, 0, (old_vpos-vpos)*nTextHeight, NULL, NULL); UpdateWindow(hOutputWnd); //InvalidateRect(hOutputWnd,NULL,0); } break; case WM_SIZE: InvalidateRect(hOutputWnd,NULL,0); break; case WM_PAINT: outwnd_paint(hwnd); break; case WM_DESTROY: outwnd_disabled = 1; PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); break; } return 0; }
void outwnd_print(char *id, char *tmp) { char *sptr; char *dptr; int i, nrows, ccol; outwnd_filter_struct *temp; if(gr_screen.mode == GR_DIRECT3D){ return; } if (!outwnd_inited) return; if ( Outwnd_no_filter_file == 1 ) { Outwnd_no_filter_file = 2; outwnd_print( "general", "==========================================================================\n" ); outwnd_print( "general", "DEBUG SPEW: No debug_filter.cfg found, so only general, error, and warning\n" ); outwnd_print( "general", "categories can be shown and no debug_filter.cfg info will be saved.\n" ); outwnd_print( "general", "==========================================================================\n" ); } if (!id) id = "General"; for (i=0; i<outwnd_filter_count; i++) if (!stricmp(id, outwnd_filter[i]->name)) break; if (i == outwnd_filter_count) // new id found that's not yet in filter list { // Only create new filters if there was a filter file if ( Outwnd_no_filter_file ) { return; } if (outwnd_filter_count >= MAX_FILTERS) { Assert(outwnd_filter_count == MAX_FILTERS); // how did it get over the max? Very bad.. outwnd_printf("General", "Outwnd filter limit reached. Recycling \"%s\" to add \"%s\"", outwnd_filter[MAX_FILTERS - 1]->name, id); i--; // overwrite the last element (oldest used filter in the list) } Assert(strlen(id) < FILTER_NAME_LENGTH); outwnd_filter[i] = &real_outwnd_filter[i]; // note: this assumes the list doesn't have gaps (from deleting an element for example) strcpy(outwnd_filter[i]->name, id); outwnd_filter[i]->state = 1; outwnd_filter_count = i + 1; save_filter_info(); } // sort the filters from most recently used to oldest, so oldest ones will get recycled first temp = outwnd_filter[i]; while (i--) outwnd_filter[i + 1] = outwnd_filter[i]; i++; outwnd_filter[i] = temp; if (!outwnd_filter[i]->state) return; if (mprintf_last_line == -1 ) { for (i=0; i<SCROLL_BUFFER_SIZE;i++) { outtext[i][0] = 0; } mprintf_last_line = 0; } // printf out to the monochrome screen first if ( mono_driver != ((HANDLE)-1) ) { DWORD cbReturned; DeviceIoControl (mono_driver, (DWORD)IOCTL_MONO_PRINT, tmp, strlen(tmp), NULL, 0, &cbReturned, 0 ); } else { mono_print(tmp, strlen(tmp) ); } sptr = tmp; ccol = strlen(outtext[mprintf_last_line] ); dptr = &outtext[mprintf_last_line][ccol]; nrows = 0; #ifndef NDEBUG if ( Log_debug_output_to_file ) { if ( Log_fp != NULL ) { fputs(tmp, Log_fp); fflush(Log_fp); } } #endif while(*sptr) { if ( (*sptr == '\n') || (ccol >= MAX_LINE_WIDTH-1 ) ) { nrows++; mprintf_last_line++; if (mprintf_last_line >= SCROLL_BUFFER_SIZE ) mprintf_last_line = 0; ccol = 0; if ( *sptr != '\n' ) { outtext[mprintf_last_line][ccol] = *sptr; ccol++; } outtext[mprintf_last_line][ccol] = '\0'; dptr = &outtext[mprintf_last_line][ccol]; } else { *dptr++ = *sptr; *dptr = '\0'; ccol++; } sptr++; } if(gr_screen.mode == GR_DIRECT3D){ return; } // if ( D3D_enabled ) { // return; // Direct3D seems to hang sometimes printing to window // } if ( outwnd_disabled ){ return; } if ( !OutputActive ) { int oldpos = GetScrollPos( hOutputWnd, SB_VERT ); if ( oldpos != max_scroll_pos ) { SCROLLINFO si; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_POS; si.nPos = max_scroll_pos; SetScrollInfo(hOutputWnd, SB_VERT, &si, 1 ); InvalidateRect(hOutputWnd,NULL,0); UpdateWindow(hOutputWnd); } else { if ( nrows ) { RECT client; ScrollWindow(hOutputWnd,0,-nTextHeight*nrows,NULL,NULL); GetClientRect(hOutputWnd, &client); client.top = client.bottom - nTextHeight*(nrows+1); InvalidateRect(hOutputWnd,&client,0); UpdateWindow(hOutputWnd); } else { Outwnd_changed++; } } } }