From 9a1b626481df1933957d1938eb675d08a3a31e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Mon, 14 Jan 2008 00:36:23 +0100 Subject: [PATCH] wordpad: Add basic ruler. --- programs/wordpad/De.rc | 4 +- programs/wordpad/En.rc | 4 +- programs/wordpad/Fr.rc | 4 +- programs/wordpad/Hu.rc | 4 +- programs/wordpad/Ko.rc | 4 +- programs/wordpad/Nl.rc | 4 +- programs/wordpad/No.rc | 6 +- programs/wordpad/Pl.rc | 4 +- programs/wordpad/Ru.rc | 4 +- programs/wordpad/Tr.rc | 4 +- programs/wordpad/print.c | 170 +++++++++++++++++++++++++++++++++++-- programs/wordpad/wordpad.c | 49 +++++++++-- programs/wordpad/wordpad.h | 17 ++-- 13 files changed, 251 insertions(+), 27 deletions(-) diff --git a/programs/wordpad/De.rc b/programs/wordpad/De.rc index 079d63dadfc..a870533bda5 100644 --- a/programs/wordpad/De.rc +++ b/programs/wordpad/De.rc @@ -64,6 +64,7 @@ BEGIN BEGIN MENUITEM "&Toolbar", ID_TOGGLE_TOOLBAR MENUITEM "&Formatbar", ID_TOGGLE_FORMATBAR + MENUITEM "&Ruler", ID_TOGGLE_RULER MENUITEM "&Statusbar", ID_TOGGLE_STATUSBAR MENUITEM SEPARATOR MENUITEM "&Options . . .", ID_VIEWPROPERTIES @@ -168,7 +169,8 @@ BEGIN GROUPBOX "Toolbars", 0, 150, 10, 120, 85 CHECKBOX "&Toolbar", IDC_PAGEFMT_TB, 160, 20, 80, 15 CHECKBOX "&Formatbar", IDC_PAGEFMT_FB, 160, 38, 80, 15 - CHECKBOX "&Statusbar", IDC_PAGEFMT_SB, 160, 56, 80, 15 + CHECKBOX "&Ruler", IDC_PAGEFMT_RU, 160, 56, 80, 15 + CHECKBOX "&Statusbar", IDC_PAGEFMT_SB, 160, 74, 80, 15 LTEXT "", IDC_PAGEFMT_ID, 0,0,0,0 END diff --git a/programs/wordpad/En.rc b/programs/wordpad/En.rc index a2b26f6cdb2..67cd9ac3ba9 100644 --- a/programs/wordpad/En.rc +++ b/programs/wordpad/En.rc @@ -64,6 +64,7 @@ BEGIN BEGIN MENUITEM "&Toolbar", ID_TOGGLE_TOOLBAR MENUITEM "&Formatbar", ID_TOGGLE_FORMATBAR + MENUITEM "&Ruler", ID_TOGGLE_RULER MENUITEM "&Statusbar", ID_TOGGLE_STATUSBAR MENUITEM SEPARATOR MENUITEM "&Options . . .", ID_VIEWPROPERTIES @@ -168,7 +169,8 @@ BEGIN GROUPBOX "Toolbars", 0, 150, 10, 120, 85 CHECKBOX "&Toolbar", IDC_PAGEFMT_TB, 160, 20, 80, 15 CHECKBOX "&Formatbar", IDC_PAGEFMT_FB, 160, 38, 80, 15 - CHECKBOX "&Statusbar", IDC_PAGEFMT_SB, 160, 56, 80, 15 + CHECKBOX "&Ruler", IDC_PAGEFMT_RU, 160, 56, 80, 15 + CHECKBOX "&Statusbar", IDC_PAGEFMT_SB, 160, 74, 80, 15 LTEXT "", IDC_PAGEFMT_ID, 0,0,0,0 END diff --git a/programs/wordpad/Fr.rc b/programs/wordpad/Fr.rc index f7ee5029f1b..ff3da1e29a2 100644 --- a/programs/wordpad/Fr.rc +++ b/programs/wordpad/Fr.rc @@ -64,6 +64,7 @@ BEGIN BEGIN MENUITEM "&Barre d'outils", ID_TOGGLE_TOOLBAR MENUITEM "&Barre de format", ID_TOGGLE_FORMATBAR + MENUITEM "&Ruler", ID_TOGGLE_RULER MENUITEM "&Barre d'état", ID_TOGGLE_STATUSBAR MENUITEM SEPARATOR MENUITEM "&Options...", ID_VIEWPROPERTIES @@ -168,7 +169,8 @@ BEGIN GROUPBOX "Barres d'outils", 0, 150, 10, 120, 85 CHECKBOX "&Barre d'outils", IDC_PAGEFMT_TB, 160, 20, 80, 15 CHECKBOX "Barre de &format", IDC_PAGEFMT_FB, 160, 38, 80, 15 - CHECKBOX "Barre de &statut", IDC_PAGEFMT_SB, 160, 56, 80, 15 + CHECKBOX "&Ruler", IDC_PAGEFMT_RU, 160, 56, 80, 15 + CHECKBOX "Barre de &statut", IDC_PAGEFMT_SB, 160, 74, 80, 15 LTEXT "", IDC_PAGEFMT_ID, 0,0,0,0 END diff --git a/programs/wordpad/Hu.rc b/programs/wordpad/Hu.rc index 0070d867e31..34ec7cc1d77 100644 --- a/programs/wordpad/Hu.rc +++ b/programs/wordpad/Hu.rc @@ -64,6 +64,7 @@ BEGIN BEGIN MENUITEM "&Toolbar", ID_TOGGLE_TOOLBAR MENUITEM "&Formatbar", ID_TOGGLE_FORMATBAR + MENUITEM "&Ruler", ID_TOGGLE_RULER MENUITEM "&Statusbar", ID_TOGGLE_STATUSBAR MENUITEM SEPARATOR MENUITEM "&Options . . .", ID_VIEWPROPERTIES @@ -168,7 +169,8 @@ BEGIN GROUPBOX "Toolbars", 0, 150, 10, 120, 85 CHECKBOX "&Toolbar", IDC_PAGEFMT_TB, 160, 20, 80, 15 CHECKBOX "&Formatbar", IDC_PAGEFMT_FB, 160, 38, 80, 15 - CHECKBOX "&Statusbar", IDC_PAGEFMT_SB, 160, 56, 80, 15 + CHECKBOX "&Ruler", IDC_PAGEFMT_RU, 160, 56, 80, 15 + CHECKBOX "&Statusbar", IDC_PAGEFMT_SB, 160, 74, 80, 15 LTEXT "", IDC_PAGEFMT_ID, 0,0,0,0 END diff --git a/programs/wordpad/Ko.rc b/programs/wordpad/Ko.rc index 9ef5d598b8b..58a0c99ebed 100644 --- a/programs/wordpad/Ko.rc +++ b/programs/wordpad/Ko.rc @@ -66,6 +66,7 @@ BEGIN BEGIN MENUITEM "µµ±¸¹Ù(&T)", ID_TOGGLE_TOOLBAR MENUITEM "Çü½Ä¹Ù(&F)", ID_TOGGLE_FORMATBAR + MENUITEM "&Ruler", ID_TOGGLE_RULER MENUITEM "»óŹÙ(&S)", ID_TOGGLE_STATUSBAR MENUITEM SEPARATOR MENUITEM " ¿É¼Ç(&O) . . .", ID_VIEWPROPERTIES @@ -170,7 +171,8 @@ BEGIN GROUPBOX " µµ±¸¹Ù", 0, 150, 10, 120, 85 CHECKBOX "µµ±¸¹Ù(&T)", IDC_PAGEFMT_TB, 160, 20, 80, 15 CHECKBOX "Çü½Ä¹Ù(&F)", IDC_PAGEFMT_FB, 160, 38, 80, 15 - CHECKBOX "»óŹÙ(&S)", IDC_PAGEFMT_SB, 160, 56, 80, 15 + CHECKBOX "&Ruler", IDC_PAGEFMT_RU, 160, 56, 80, 15 + CHECKBOX "»óŹÙ(&S)", IDC_PAGEFMT_SB, 160, 74, 80, 15 LTEXT "", IDC_PAGEFMT_ID, 0,0,0,0 END diff --git a/programs/wordpad/Nl.rc b/programs/wordpad/Nl.rc index 52f826ecaa4..d2c1a0fddb7 100644 --- a/programs/wordpad/Nl.rc +++ b/programs/wordpad/Nl.rc @@ -64,6 +64,7 @@ BEGIN BEGIN MENUITEM "&Toolbar", ID_TOGGLE_TOOLBAR MENUITEM "&Formatbar", ID_TOGGLE_FORMATBAR + MENUITEM "&Ruler", ID_TOGGLE_RULER MENUITEM "&Statusbar", ID_TOGGLE_STATUSBAR MENUITEM SEPARATOR MENUITEM "&Options . . .", ID_VIEWPROPERTIES @@ -168,7 +169,8 @@ BEGIN GROUPBOX "Toolbars", 0, 150, 10, 120, 85 CHECKBOX "&Toolbar", IDC_PAGEFMT_TB, 160, 20, 80, 15 CHECKBOX "&Formatbar", IDC_PAGEFMT_FB, 160, 38, 80, 15 - CHECKBOX "&Statusbar", IDC_PAGEFMT_SB, 160, 56, 80, 15 + CHECKBOX "&Ruler", IDC_PAGEFMT_RU, 160, 56, 80, 15 + CHECKBOX "&Statusbar", IDC_PAGEFMT_SB, 160, 74, 80, 15 LTEXT "", IDC_PAGEFMT_ID, 0,0,0,0 END diff --git a/programs/wordpad/No.rc b/programs/wordpad/No.rc index 5907e44d895..4e258fd1e70 100644 --- a/programs/wordpad/No.rc +++ b/programs/wordpad/No.rc @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 by Alexander N. Sørnes + * Copyright 2006-2008 by Alexander N. Sørnes * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -64,6 +64,7 @@ BEGIN BEGIN MENUITEM "Verk&tøylinje", ID_TOGGLE_TOOLBAR MENUITEM "&Formatlinje", ID_TOGGLE_FORMATBAR + MENUITEM "&Linjal", ID_TOGGLE_RULER MENUITEM "&Statuslinje", ID_TOGGLE_STATUSBAR MENUITEM SEPARATOR MENUITEM "&Alternativer . . .", ID_VIEWPROPERTIES @@ -168,7 +169,8 @@ BEGIN GROUPBOX "Verktøylinjer", 0, 150, 10, 120, 85 CHECKBOX "&Verktøylinje", IDC_PAGEFMT_TB, 160, 20, 80, 15 CHECKBOX "&Formatlinje", IDC_PAGEFMT_FB, 160, 38, 80, 15 - CHECKBOX "&Statuslinje", IDC_PAGEFMT_SB, 160, 56, 80, 15 + CHECKBOX "&Linjal", IDC_PAGEFMT_RU, 160, 56, 80, 15 + CHECKBOX "&Statuslinje", IDC_PAGEFMT_SB, 160, 74, 80, 15 LTEXT "", IDC_PAGEFMT_ID, 0,0,0,0 END diff --git a/programs/wordpad/Pl.rc b/programs/wordpad/Pl.rc index 54384337e3e..e52203b3d59 100644 --- a/programs/wordpad/Pl.rc +++ b/programs/wordpad/Pl.rc @@ -65,6 +65,7 @@ BEGIN BEGIN MENUITEM "&Toolbar", ID_TOGGLE_TOOLBAR MENUITEM "&Formatbar", ID_TOGGLE_FORMATBAR + MENUITEM "&Ruler", ID_TOGGLE_RULER MENUITEM "&Statusbar", ID_TOGGLE_STATUSBAR MENUITEM SEPARATOR MENUITEM "&Options . . .", ID_VIEWPROPERTIES @@ -169,7 +170,8 @@ BEGIN GROUPBOX "Toolbars", 0, 150, 10, 120, 85 CHECKBOX "&Toolbar", IDC_PAGEFMT_TB, 160, 20, 80, 15 CHECKBOX "&Formatbar", IDC_PAGEFMT_FB, 160, 38, 80, 15 - CHECKBOX "&Statusbar", IDC_PAGEFMT_SB, 160, 56, 80, 15 + CHECKBOX "&Ruler", IDC_PAGEFMT_RU, 160, 56, 80, 15 + CHECKBOX "&Statusbar", IDC_PAGEFMT_SB, 160, 74, 80, 15 LTEXT "", IDC_PAGEFMT_ID, 0,0,0,0 END diff --git a/programs/wordpad/Ru.rc b/programs/wordpad/Ru.rc index 978e96919aa..5a55d3c371d 100644 --- a/programs/wordpad/Ru.rc +++ b/programs/wordpad/Ru.rc @@ -63,6 +63,7 @@ BEGIN BEGIN MENUITEM "Ïàíåëü &èíñòðóìåíòîâ", ID_TOGGLE_TOOLBAR MENUITEM "Ï&àíåëü ôîðìàòèðîâàíèÿ", ID_TOGGLE_FORMATBAR + MENUITEM "&Ruler", ID_TOGGLE_RULER MENUITEM "&Ñòðîêà ñîñòîÿíèÿ", ID_TOGGLE_STATUSBAR MENUITEM SEPARATOR MENUITEM "&Ïàðàìåòðû . . .", ID_VIEWPROPERTIES @@ -167,7 +168,8 @@ BEGIN GROUPBOX "Ïàíåëè", 0, 150, 10, 120, 85 CHECKBOX "&Èíñòðóìåíòîâ", IDC_PAGEFMT_TB, 160, 20, 80, 15 CHECKBOX "&Ôîðìàòèðîâàíèÿ", IDC_PAGEFMT_FB, 160, 38, 80, 15 - CHECKBOX "&Ñòðîêà ñîñòîÿíèÿ", IDC_PAGEFMT_SB, 160, 56, 80, 15 + CHECKBOX "&Ruler", IDC_PAGEFMT_RU, 160, 56, 80, 15 + CHECKBOX "&Ñòðîêà ñîñòîÿíèÿ", IDC_PAGEFMT_SB, 160, 74, 80, 15 LTEXT "", IDC_PAGEFMT_ID, 0,0,0,0 END diff --git a/programs/wordpad/Tr.rc b/programs/wordpad/Tr.rc index 60cf300e742..01671279367 100644 --- a/programs/wordpad/Tr.rc +++ b/programs/wordpad/Tr.rc @@ -67,6 +67,7 @@ BEGIN BEGIN MENUITEM "&Toolbar", ID_TOGGLE_TOOLBAR MENUITEM "&Formatbar", ID_TOGGLE_FORMATBAR + MENUITEM "&Ruler", ID_TOGGLE_RULER MENUITEM "&Statusbar", ID_TOGGLE_STATUSBAR MENUITEM SEPARATOR MENUITEM "&Options . . .", ID_VIEWPROPERTIES @@ -171,7 +172,8 @@ BEGIN GROUPBOX "Toolbars", 0, 150, 10, 120, 85 CHECKBOX "&Toolbar", IDC_PAGEFMT_TB, 160, 20, 80, 15 CHECKBOX "&Formatbar", IDC_PAGEFMT_FB, 160, 38, 80, 15 - CHECKBOX "&Statusbar", IDC_PAGEFMT_SB, 160, 56, 80, 15 + CHECKBOX "&Ruler", IDC_PAGEFMT_RU, 160, 56, 80, 15 + CHECKBOX "&Statusbar", IDC_PAGEFMT_SB, 160, 74, 80, 15 LTEXT "", IDC_PAGEFMT_ID, 0,0,0,0 END diff --git a/programs/wordpad/print.c b/programs/wordpad/print.c index e44039e91fc..3fb2d7a8afd 100644 --- a/programs/wordpad/print.c +++ b/programs/wordpad/print.c @@ -1,7 +1,7 @@ /* * Wordpad implementation - Printing and print preview functions * - * Copyright 2007 by Alexander N. Sørnes + * Copyright 2007-2008 by Alexander N. Sørnes * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -130,23 +130,23 @@ static HDC make_dc(void) static LONG twips_to_centmm(int twips) { - return MulDiv(twips, 1000, 567); + return MulDiv(twips, 1000, TWIPS_PER_CM); } LONG centmm_to_twips(int mm) { - return MulDiv(mm, 567, 1000); + return MulDiv(mm, TWIPS_PER_CM, 1000); } static LONG twips_to_pixels(int twips, int dpi) { - float ret = ((float)twips / ((float)567 * 2.54)) * (float)dpi; + float ret = ((float)twips / ((float)TWIPS_PER_CM * 2.54)) * (float)dpi; return (LONG)ret; } static LONG devunits_to_twips(int units, int dpi) { - float ret = ((float)units / (float)dpi) * (float)567 * 2.54; + float ret = ((float)units / (float)dpi) * (float)TWIPS_PER_CM * 2.54; return (LONG)ret; } @@ -254,6 +254,25 @@ static void char_from_pagenum(HWND hEditorWnd, FORMATRANGE *fr, int page) } } +static HWND get_ruler_wnd(HWND hMainWnd) +{ + return GetDlgItem(GetDlgItem(hMainWnd, IDC_REBAR), IDC_RULER); +} + +void redraw_ruler(HWND hRulerWnd) +{ + RECT rc; + + GetClientRect(hRulerWnd, &rc); + InvalidateRect(hRulerWnd, &rc, TRUE); +} + +static void update_ruler(HWND hRulerWnd) +{ + SendMessageW(hRulerWnd, WM_USER, 0, 0); + redraw_ruler(hRulerWnd); +} + static void print(LPPRINTDLGW pd, LPWSTR wszFileName) { FORMATRANGE fr; @@ -340,6 +359,7 @@ void dialog_printsetup(HWND hMainWnd) margins.bottom = centmm_to_twips(ps.rtMargin.bottom); devMode = ps.hDevMode; devNames = ps.hDevNames; + update_ruler(get_ruler_wnd(hMainWnd)); } } @@ -394,6 +414,7 @@ void dialog_print(HWND hMainWnd, LPWSTR wszFileName) devMode = pd.hDevMode; devNames = pd.hDevNames; print(&pd, wszFileName); + update_ruler(get_ruler_wnd(hMainWnd)); } } @@ -456,6 +477,145 @@ BOOL preview_isactive(void) return preview.page != 0; } +static void add_ruler_units(HDC hdcRuler, RECT* drawRect, BOOL NewMetrics, long EditLeftmost) +{ + static HDC hdc; + + if(NewMetrics) + { + static HBITMAP hBitmap; + int i, x, y, RulerTextEnd; + int CmPixels; + int QuarterCmPixels; + HFONT hFont; + WCHAR FontName[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0}; + + if(hdc) + { + DeleteDC(hdc); + DeleteObject(hBitmap); + } + + hdc = CreateCompatibleDC(hdc); + + CmPixels = twips_to_pixels(TWIPS_PER_CM, GetDeviceCaps(hdc, LOGPIXELSX)); + QuarterCmPixels = (int)((float)CmPixels / 4.0); + + hBitmap = CreateCompatibleBitmap(hdc, drawRect->right, drawRect->bottom); + SelectObject(hdc, hBitmap); + FillRect(hdc, drawRect, GetStockObject(WHITE_BRUSH)); + + hFont = CreateFontW(10, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FontName); + + SelectObject(hdc, hFont); + SetBkMode(hdc, TRANSPARENT); + SetTextAlign(hdc, TA_CENTER); + y = (int)(((float)drawRect->bottom - (float)drawRect->top) / 2.0) + 1; + RulerTextEnd = drawRect->right - EditLeftmost + 1; + for(i = 1, x = EditLeftmost; x < (drawRect->right - EditLeftmost + 1); i ++) + { + WCHAR str[3]; + WCHAR format[] = {'%','d',0}; + int x2 = x; + + x2 += QuarterCmPixels; + if(x2 > RulerTextEnd) + break; + + MoveToEx(hdc, x2, y, NULL); + LineTo(hdc, x2, y+2); + + x2 += QuarterCmPixels; + if(x2 > RulerTextEnd) + break; + + MoveToEx(hdc, x2, y - 3, NULL); + LineTo(hdc, x2, y + 3); + + x2 += QuarterCmPixels; + if(x2 > RulerTextEnd) + break; + + MoveToEx(hdc, x2, y, NULL); + LineTo(hdc, x2, y+2); + + x += CmPixels; + if(x > RulerTextEnd) + break; + + wsprintfW(str, format, i); + TextOutW(hdc, x, 5, str, lstrlenW(str)); + } + DeleteObject(hFont); + } + + BitBlt(hdcRuler, 0, 0, drawRect->right, drawRect->bottom, hdc, 0, 0, SRCAND); +} + +static void paint_ruler(HWND hWnd, long EditLeftmost, BOOL NewMetrics) +{ + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hWnd, &ps); + HDC hdcPrint = make_dc(); + RECT printRect = get_print_rect(hdcPrint); + RECT drawRect; + HBRUSH hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU)); + + GetClientRect(hWnd, &drawRect); + FillRect(hdc, &drawRect, hBrush); + + drawRect.top += 3; + drawRect.bottom -= 3; + drawRect.left = EditLeftmost; + drawRect.right = twips_to_pixels(printRect.right - margins.left, GetDeviceCaps(hdc, LOGPIXELSX)); + FillRect(hdc, &drawRect, GetStockObject(WHITE_BRUSH)); + + drawRect.top--; + drawRect.bottom++; + DrawEdge(hdc, &drawRect, EDGE_SUNKEN, BF_RECT); + + drawRect.left = drawRect.right - 1; + drawRect.right = twips_to_pixels(printRect.right + margins.right - margins.left, GetDeviceCaps(hdc, LOGPIXELSX)); + DrawEdge(hdc, &drawRect, EDGE_ETCHED, BF_RECT); + + drawRect.left = 0; + drawRect.top = 0; + add_ruler_units(hdc, &drawRect, NewMetrics, EditLeftmost); + + SelectObject(hdc, GetStockObject(BLACK_BRUSH)); + DeleteObject(hBrush); + DeleteDC(hdcPrint); + EndPaint(hWnd, &ps); +} + +LRESULT CALLBACK ruler_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + static WNDPROC pPrevRulerProc; + static long EditLeftmost; + static BOOL NewMetrics; + + switch(msg) + { + case WM_USER: + if(wParam) + { + EditLeftmost = ((POINTL*)wParam)->x; + pPrevRulerProc = (WNDPROC)lParam; + } + NewMetrics = TRUE; + break; + + case WM_PAINT: + paint_ruler(hWnd, EditLeftmost, NewMetrics); + break; + + default: + return CallWindowProcW(pPrevRulerProc, hWnd, msg, wParam, lParam); + } + + return 0; +} + LRESULT print_preview(HWND hMainWnd) { FORMATRANGE fr; diff --git a/programs/wordpad/wordpad.c b/programs/wordpad/wordpad.c index 4d46ca5d2e6..e4a65026eb3 100644 --- a/programs/wordpad/wordpad.c +++ b/programs/wordpad/wordpad.c @@ -2,7 +2,7 @@ * Wordpad implementation * * Copyright 2004 by Krzysztof Foltman - * Copyright 2007 by Alexander N. Sørnes + * Copyright 2007-2008 by Alexander N. Sørnes * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -600,7 +600,7 @@ static void set_toolbar_state(int bandId, BOOL show) SendMessageW(hwndReBar, RB_SETBANDINFO, index, (LPARAM)&rbbinfo); } - if(bandId == BANDID_TOOLBAR || bandId == BANDID_FORMATBAR) + if(bandId == BANDID_TOOLBAR || bandId == BANDID_FORMATBAR || bandId == BANDID_RULER) store_bar_state(bandId, show); } @@ -618,6 +618,7 @@ static void set_bar_states(void) set_toolbar_state(BANDID_FONTLIST, is_bar_visible(BANDID_FORMATBAR)); set_toolbar_state(BANDID_SIZELIST, is_bar_visible(BANDID_FORMATBAR)); set_toolbar_state(BANDID_FORMATBAR, is_bar_visible(BANDID_FORMATBAR)); + set_toolbar_state(BANDID_RULER, is_bar_visible(BANDID_RULER)); set_statusbar_state(is_bar_visible(BANDID_STATUSBAR)); update_window(); @@ -912,7 +913,9 @@ static INT_PTR CALLBACK formatopts_proc(HWND hWnd, UINT message, WPARAM wParam, CheckDlgButton(hWnd, IDC_PAGEFMT_TB, TRUE); if(barState[ps->lParam] & (1 << BANDID_FORMATBAR)) CheckDlgButton(hWnd, IDC_PAGEFMT_FB, TRUE); - if(barState[ps->lParam] & (BANDID_STATUSBAR)) + if(barState[ps->lParam] & (1 << BANDID_RULER)) + CheckDlgButton(hWnd, IDC_PAGEFMT_RU, TRUE); + if(barState[ps->lParam] & (1 << BANDID_STATUSBAR)) CheckDlgButton(hWnd, IDC_PAGEFMT_SB, TRUE); } break; @@ -928,6 +931,7 @@ static INT_PTR CALLBACK formatopts_proc(HWND hWnd, UINT message, WPARAM wParam, case IDC_PAGEFMT_TB: case IDC_PAGEFMT_FB: + case IDC_PAGEFMT_RU: case IDC_PAGEFMT_SB: CheckDlgButton(hWnd, LOWORD(wParam), !IsDlgButtonChecked(hWnd, LOWORD(wParam))); @@ -960,6 +964,11 @@ static INT_PTR CALLBACK formatopts_proc(HWND hWnd, UINT message, WPARAM wParam, else barState[id] &= ~(1 << BANDID_FORMATBAR); + if(IsDlgButtonChecked(hWnd, IDC_PAGEFMT_RU)) + barState[id] |= (1 << BANDID_RULER); + else + barState[id] &= ~(1 << BANDID_RULER); + if(IsDlgButtonChecked(hWnd, IDC_PAGEFMT_SB)) barState[id] |= (1 << BANDID_STATUSBAR); else @@ -1182,7 +1191,7 @@ static void dialog_find(LPFINDREPLACEW fr, BOOL replace) static int current_units_to_twips(float number) { - int twips = (int)(number * 567); + int twips = (int)(number * TWIPS_PER_CM); return twips; } @@ -1195,7 +1204,7 @@ static void append_current_units(LPWSTR buffer) static void number_with_units(LPWSTR buffer, int number) { - float converted = (float)number / 567; + float converted = (float)number / TWIPS_PER_CM; char string[MAX_STRING_LEN]; sprintf(string, "%.2f ", converted); @@ -1547,7 +1556,7 @@ static int context_menu(LPARAM lParam) static LRESULT OnCreate( HWND hWnd, WPARAM wParam, LPARAM lParam) { - HWND hToolBarWnd, hFormatBarWnd, hReBarWnd, hFontListWnd, hSizeListWnd; + HWND hToolBarWnd, hFormatBarWnd, hReBarWnd, hFontListWnd, hSizeListWnd, hRulerWnd; HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); HANDLE hDLL; TBADDBITMAP ab; @@ -1651,6 +1660,16 @@ static LRESULT OnCreate( HWND hWnd, WPARAM wParam, LPARAM lParam) SendMessageW(hReBarWnd, RB_INSERTBAND, -1, (LPARAM)&rbb); + hRulerWnd = CreateWindowExW(0, WC_STATICW, NULL, WS_VISIBLE | WS_CHILD, + 0, 0, 200, 10, hReBarWnd, (HMENU)IDC_RULER, hInstance, NULL); + + + rbb.hwndChild = hRulerWnd; + rbb.wID = BANDID_RULER; + rbb.fStyle |= RBBS_BREAK; + + SendMessageW(hReBarWnd, RB_INSERTBAND, -1, (LPARAM)&rbb); + hDLL = LoadLibraryW(wszRichEditDll); if(!hDLL) { @@ -2133,6 +2152,11 @@ static LRESULT OnCommand( HWND hWnd, WPARAM wParam, LPARAM lParam) update_window(); break; + case ID_TOGGLE_RULER: + set_toolbar_state(BANDID_RULER, !is_bar_visible(BANDID_RULER)); + update_window(); + break; + case ID_DATETIME: { HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); @@ -2216,6 +2240,8 @@ static LRESULT OnInitPopupMenu( HWND hWnd, WPARAM wParam, LPARAM lParam ) CheckMenuItem(hMenu, ID_TOGGLE_STATUSBAR, MF_BYCOMMAND|IsWindowVisible(hwndStatus) ? MF_CHECKED : MF_UNCHECKED); + CheckMenuItem(hMenu, ID_TOGGLE_RULER, MF_BYCOMMAND|(is_bar_visible(BANDID_RULER)) ? MF_CHECKED : MF_UNCHECKED); + gt.flags = GTL_NUMCHARS; gt.codepage = 1200; textLength = SendMessageW(hEditorWnd, EM_GETTEXTLENGTHEX, (WPARAM)>, 0); @@ -2241,6 +2267,7 @@ static LRESULT OnSize( HWND hWnd, WPARAM wParam, LPARAM lParam ) HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR); HWND hwndStatusBar = GetDlgItem(hWnd, IDC_STATUSBAR); HWND hwndReBar = GetDlgItem(hWnd, IDC_REBAR); + HWND hRulerWnd = GetDlgItem(hWnd, IDC_RULER); int rebarHeight = 0; int rebarRows = 2; @@ -2274,6 +2301,8 @@ static LRESULT OnSize( HWND hWnd, WPARAM wParam, LPARAM lParam ) MoveWindow(hwndEditor, 0, rebarHeight, rc.right, rc.bottom-nStatusSize-rebarHeight, TRUE); } + redraw_ruler(hRulerWnd); + return DefWindowProcW(hWnd, WM_SIZE, wParam, lParam); } @@ -2364,6 +2393,9 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hOldInstance, LPSTR szCmdPar WNDCLASSW wc; MSG msg; RECT rc; + UINT_PTR hPrevRulerProc; + HWND hRulerWnd; + POINTL EditPoint; static const WCHAR wszAccelTable[] = {'M','A','I','N','A','C','C','E','L', 'T','A','B','L','E','\0'}; @@ -2395,6 +2427,11 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hOldInstance, LPSTR szCmdPar get_default_printer_opts(); target_device(hMainWnd, wordWrap[reg_formatindex(fileFormat)]); + hRulerWnd = GetDlgItem(GetDlgItem(hMainWnd, IDC_REBAR), IDC_RULER); + SendMessageW(GetDlgItem(hMainWnd, IDC_EDITOR), EM_POSFROMCHAR, (WPARAM)&EditPoint, 0); + hPrevRulerProc = SetWindowLongPtrW(hRulerWnd, GWLP_WNDPROC, (UINT_PTR)ruler_proc); + SendMessageW(hRulerWnd, WM_USER, (WPARAM)&EditPoint, hPrevRulerProc); + HandleCommandLine(GetCommandLineW()); while(GetMessageW(&msg,0,0,0)) diff --git a/programs/wordpad/wordpad.h b/programs/wordpad/wordpad.h index 57e8e8e0e95..1e270e08981 100644 --- a/programs/wordpad/wordpad.h +++ b/programs/wordpad/wordpad.h @@ -1,6 +1,6 @@ /* * Copyright 2004 by Krzysztof Foltman - * Copyright 2007 by Alexander N. Sørnes + * Copyright 2007-2008 by Alexander N. Sørnes * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,6 +19,8 @@ #define MAX_STRING_LEN 255 +#define TWIPS_PER_CM 567 + #define ID_FILE_EXIT 1000 #define ID_FILE_OPEN 1001 #define ID_FILE_SAVE 1002 @@ -75,6 +77,7 @@ #define ID_TOGGLE_TOOLBAR 1500 #define ID_TOGGLE_FORMATBAR 1501 #define ID_TOGGLE_STATUSBAR 1502 +#define ID_TOGGLE_RULER 1503 #define PREVIEW_BUTTONS 4 @@ -106,10 +109,11 @@ #define IDC_PAGEFMT_TB 100 #define IDC_PAGEFMT_FB 101 -#define IDC_PAGEFMT_SB 102 -#define IDC_PAGEFMT_WW 103 -#define IDC_PAGEFMT_WM 104 -#define IDC_PAGEFMT_ID 105 +#define IDC_PAGEFMT_RU 102 +#define IDC_PAGEFMT_SB 103 +#define IDC_PAGEFMT_WW 104 +#define IDC_PAGEFMT_WM 105 +#define IDC_PAGEFMT_ID 106 #define ID_DATETIME 1600 #define ID_PARAFORMAT 1601 @@ -133,6 +137,7 @@ #define IDC_TABSTOPS 2012 #define IDC_FONTLIST 2013 #define IDC_SIZELIST 2014 +#define IDC_RULER 2015 #define IDD_DATETIME 2100 #define IDD_NEWFILE 2101 @@ -199,6 +204,8 @@ LRESULT print_preview(HWND); void get_default_printer_opts(void); void registry_set_pagemargins(HKEY); void registry_read_pagemargins(HKEY); +LRESULT CALLBACK ruler_proc(HWND, UINT, WPARAM, LPARAM); +void redraw_ruler(HWND); int reg_formatindex(WPARAM); void registry_read_filelist(HWND);