riched20: Selection painting fixes.
[wine] / dlls / riched20 / paint.c
1 /*
2  * RichEdit - painting functions
3  *
4  * Copyright 2004 by Krzysztof Foltman
5  * Copyright 2005 by Phil Krylov
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "editor.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
25
26 void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, RECT *rcUpdate) {
27   ME_DisplayItem *item;
28   ME_Context c;
29   int yoffset;
30
31   editor->nSequence++;
32   yoffset = ME_GetYScrollPos(editor);
33   ME_InitContext(&c, editor, hDC);
34   SetBkMode(hDC, TRANSPARENT);
35   ME_MoveCaret(editor);
36   item = editor->pBuffer->pFirst->next;
37   c.pt.y -= yoffset;
38   while(item != editor->pBuffer->pLast) {
39     int ye;
40     assert(item->type == diParagraph);
41     ye = c.pt.y + item->member.para.nHeight;
42     if (!bOnlyNew || (item->member.para.nFlags & MEPF_REPAINT))
43     {
44       BOOL bPaint = (rcUpdate == NULL);
45       if (rcUpdate)
46         bPaint = c.pt.y<rcUpdate->bottom && 
47           c.pt.y+item->member.para.nHeight>rcUpdate->top;
48       if (bPaint)
49       {
50         ME_DrawParagraph(&c, item);
51         if (!rcUpdate || (rcUpdate->top<=c.pt.y && rcUpdate->bottom>=ye))
52           item->member.para.nFlags &= ~MEPF_REPAINT;
53       }
54     }
55     c.pt.y = ye;
56     item = item->member.para.next_para;
57   }
58   if (c.pt.y<c.rcView.bottom) {
59     RECT rc;
60     int xs = c.rcView.left, xe = c.rcView.right;
61     int ys = c.pt.y, ye = c.rcView.bottom;
62     
63     if (bOnlyNew)
64     {
65       int y1 = editor->nTotalLength-yoffset, y2 = editor->nLastTotalLength-yoffset;
66       if (y1<y2)
67         ys = y1, ye = y2+1;
68       else
69         ys = ye;
70     }
71     
72     if (rcUpdate && ys!=ye)
73     {
74       xs = rcUpdate->left, xe = rcUpdate->right;
75       if (rcUpdate->top > ys)
76         ys = rcUpdate->top;
77       if (rcUpdate->bottom < ye)
78         ye = rcUpdate->bottom;
79     }
80
81     if (ye>ys) {
82       rc.left = xs;
83       rc.top = ys;
84       rc.right = xe;
85       rc.bottom = ye;
86       FillRect(hDC, &rc, c.editor->hbrBackground);
87     }
88     if (ys == c.pt.y) /* don't overwrite the top bar */
89       ys++;
90   }
91   if (editor->nTotalLength != editor->nLastTotalLength)
92     ME_SendRequestResize(editor, FALSE);
93   editor->nLastTotalLength = editor->nTotalLength;
94   ME_DestroyContext(&c);
95 }
96
97 static void ME_MarkParagraphRange(ME_TextEditor *editor, ME_DisplayItem *p1,
98                            ME_DisplayItem *p2, int nFlags)
99 {
100   ME_DisplayItem *p3;  
101   if (p1 == p2)
102   {
103     p1->member.para.nFlags |= nFlags;
104     return;
105   }
106   if (p1->member.para.nCharOfs > p2->member.para.nCharOfs)
107     p3 = p1, p1 = p2, p2 = p3;
108     
109   p1->member.para.nFlags |= nFlags;
110   do {
111     p1 = p1->member.para.next_para;
112     p1->member.para.nFlags |= nFlags;
113   } while (p1 != p2);
114 }
115
116 static void ME_MarkOffsetRange(ME_TextEditor *editor, int from, int to, int nFlags)
117 {
118   ME_Cursor c1, c2;
119   ME_CursorFromCharOfs(editor, from, &c1);
120   ME_CursorFromCharOfs(editor, to, &c2);
121   
122   ME_MarkParagraphRange(editor, ME_GetParagraph(c1.pRun), ME_GetParagraph(c2.pRun), nFlags);
123 }
124
125 static void ME_MarkSelectionForRepaint(ME_TextEditor *editor)
126 {
127   int from, to, from2, to2, end;
128   
129   end = ME_GetTextLength(editor);
130   ME_GetSelection(editor, &from, &to);
131   from2 = editor->nLastSelStart;
132   to2 = editor->nLastSelEnd;
133   if (from<from2) ME_MarkOffsetRange(editor, from, from2, MEPF_REPAINT);
134   if (from>from2) ME_MarkOffsetRange(editor, from2, from, MEPF_REPAINT);
135   if (to<to2) ME_MarkOffsetRange(editor, to, to2, MEPF_REPAINT);
136   if (to>to2) ME_MarkOffsetRange(editor, to2, to, MEPF_REPAINT);
137
138   editor->nLastSelStart = from;
139   editor->nLastSelEnd = to;
140 }
141
142 void ME_Repaint(ME_TextEditor *editor)
143 {
144   ME_Cursor *pCursor = &editor->pCursors[0];
145
146   if (ME_WrapMarkedParagraphs(editor)) {
147     ME_UpdateScrollBar(editor);
148   }
149   if (editor->bRedraw)
150   {
151     ME_EnsureVisible(editor, pCursor->pRun);
152     UpdateWindow(editor->hWnd);
153   }
154 }
155
156 void ME_UpdateRepaint(ME_TextEditor *editor)
157 {
158 /*
159   InvalidateRect(editor->hWnd, NULL, TRUE);
160   */
161   ME_SendOldNotify(editor, EN_CHANGE);
162   ME_Repaint(editor);
163   ME_SendOldNotify(editor, EN_UPDATE);
164   ME_SendSelChange(editor);
165 }
166
167
168 void
169 ME_RewrapRepaint(ME_TextEditor *editor)
170 {
171   ME_MarkAllForWrapping(editor);
172   ME_WrapMarkedParagraphs(editor);
173   ME_UpdateScrollBar(editor);
174   ME_Repaint(editor);
175 }
176
177
178 static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText, int nChars, 
179   ME_Style *s, int *width, int nSelFrom, int nSelTo, int ymin, int cy) {
180   HDC hDC = c->hDC;
181   HGDIOBJ hOldFont;
182   COLORREF rgbOld, rgbBack;
183   int yOffset = 0, yTwipsOffset = 0;
184   hOldFont = ME_SelectStyleFont(c->editor, hDC, s);
185   rgbBack = ME_GetBackColor(c->editor);
186   if ((s->fmt.dwMask & CFM_COLOR) && (s->fmt.dwEffects & CFE_AUTOCOLOR))
187     rgbOld = SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
188   else
189     rgbOld = SetTextColor(hDC, s->fmt.crTextColor);
190   if ((s->fmt.dwMask & s->fmt.dwEffects) & CFM_OFFSET) {
191     yTwipsOffset = s->fmt.yOffset;
192   }
193   if ((s->fmt.dwMask & s->fmt.dwEffects) & (CFM_SUPERSCRIPT | CFM_SUBSCRIPT)) {
194     if (s->fmt.dwEffects & CFE_SUPERSCRIPT) yTwipsOffset = s->fmt.yHeight/3;
195     if (s->fmt.dwEffects & CFE_SUBSCRIPT) yTwipsOffset = -s->fmt.yHeight/12;
196   }
197   if (yTwipsOffset)
198   {
199     int numerator = 1;
200     int denominator = 1;
201     
202     if (c->editor->nZoomNumerator)
203     {
204       numerator = c->editor->nZoomNumerator;
205       denominator = c->editor->nZoomDenominator;
206     }
207     yOffset = yTwipsOffset * GetDeviceCaps(hDC, LOGPIXELSY) * numerator / denominator / 1440;
208   }
209   ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nChars, NULL);
210   if (width) {
211     SIZE sz;
212     GetTextExtentPoint32W(hDC, szText, nChars, &sz);
213     *width = sz.cx;
214   }
215   if (nSelFrom < nChars && nSelTo >= 0 && nSelFrom<nSelTo)
216   {
217     SIZE sz;
218     if (nSelFrom < 0) nSelFrom = 0;
219     if (nSelTo > nChars) nSelTo = nChars;
220     GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
221     x += sz.cx;
222     GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
223     PatBlt(hDC, x, ymin, sz.cx, cy, DSTINVERT);
224   }
225   SetTextColor(hDC, rgbOld);
226   ME_UnselectStyleFont(c->editor, hDC, s, hOldFont);
227 }
228
229 static void ME_DebugWrite(HDC hDC, POINT *pt, WCHAR *szText) {
230   int align = SetTextAlign(hDC, TA_LEFT|TA_TOP);
231   HGDIOBJ hFont = SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
232   COLORREF color = SetTextColor(hDC, RGB(128,128,128));
233   TextOutW(hDC, pt->x, pt->y, szText, lstrlenW(szText));
234   SelectObject(hDC, hFont);
235   SetTextAlign(hDC, align);
236   SetTextColor(hDC, color);
237 }
238
239 void ME_DrawGraphics(ME_Context *c, int x, int y, ME_Run *run, 
240                      ME_Paragraph *para, BOOL selected) {
241   SIZE sz;
242   int xs, ys, xe, ye, h, ym, width, eyes;
243   ME_GetGraphicsSize(c->editor, run, &sz);
244   xs = run->pt.x;
245   ys = y-sz.cy;
246   xe = xs+sz.cx;
247   ye = y;
248   h = ye-ys;
249   ym = ys+h/4;
250   width = sz.cx;
251   eyes = width/8;
252   /* draw a smiling face :) */
253   Ellipse(c->hDC, xs, ys, xe, ye);
254   Ellipse(c->hDC, xs+width/8, ym, x+width/8+eyes, ym+eyes);
255   Ellipse(c->hDC, xs+7*width/8-eyes, ym, xs+7*width/8, ym+eyes);
256   MoveToEx(c->hDC, xs+width/8, ys+3*h/4-eyes, NULL);
257   LineTo(c->hDC, xs+width/8, ys+3*h/4);
258   LineTo(c->hDC, xs+7*width/8, ys+3*h/4);
259   LineTo(c->hDC, xs+7*width/8, ys+3*h/4-eyes);
260   if (selected)
261   {
262     /* descent is usually (always?) 0 for graphics */
263     PatBlt(c->hDC, x, y-run->nAscent, sz.cx, run->nAscent+run->nDescent, DSTINVERT);    
264   }
265 }
266
267 static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Paragraph *para) {
268   ME_Run *run = &rundi->member.run;
269   ME_DisplayItem *start = ME_FindItemBack(rundi, diStartRow);
270   int runofs = run->nCharOfs+para->nCharOfs;
271   int nSelFrom, nSelTo;
272   const WCHAR wszSpace[] = {' ', 0};
273   
274   ME_GetSelection(c->editor, &nSelFrom, &nSelTo);
275
276   /* Draw selected end-of-paragraph mark */
277   if (run->nFlags & MERF_ENDPARA && runofs >= nSelFrom && runofs < nSelTo)
278     ME_DrawTextWithStyle(c, x, y, wszSpace, 1, run->style, NULL, 0, 1,
279                          c->pt.y + start->member.row.nYPos,
280                          start->member.row.nHeight);
281           
282   /* you can always comment it out if you need visible paragraph marks */
283   if (run->nFlags & (MERF_ENDPARA|MERF_TAB)) 
284     return;
285
286   if (run->nFlags & MERF_GRAPHICS)
287     ME_DrawGraphics(c, x, y, run, para, (runofs >= nSelFrom) && (runofs < nSelTo));
288   else
289     ME_DrawTextWithStyle(c, x, y, 
290       run->strText->szData, ME_StrVLen(run->strText), run->style, NULL, 
291         nSelFrom-runofs,nSelTo-runofs, c->pt.y+start->member.row.nYPos, start->member.row.nHeight);
292 }
293
294 COLORREF ME_GetBackColor(ME_TextEditor *editor)
295 {
296 /* Looks like I was seriously confused
297     return GetSysColor((GetWindowLong(editor->hWnd, GWL_STYLE) & ES_READONLY) ? COLOR_3DFACE: COLOR_WINDOW);
298 */
299   if (editor->rgbBackColor == -1)
300     return GetSysColor(COLOR_WINDOW);
301   else
302     return editor->rgbBackColor;
303 }
304
305 void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph) {
306   int align = SetTextAlign(c->hDC, TA_BASELINE);
307   ME_DisplayItem *p;
308   ME_Run *run;
309   ME_Paragraph *para = NULL;
310   RECT rc, rcPara;
311   int y = c->pt.y;
312   int height = 0, baseline = 0, no=0, pno = 0;
313   int xs, xe;
314   int visible = 0;
315   int nMargWidth = 0;
316   
317   c->pt.x = c->rcView.left;
318   rcPara.left = c->rcView.left;
319   rcPara.right = c->rcView.right;
320   for (p = paragraph; p!=paragraph->member.para.next_para; p = p->next) {
321     switch(p->type) {
322       case diParagraph:
323         para = &p->member.para;
324         break;
325       case diStartRow:
326         assert(para);
327         nMargWidth = (pno==0?para->nFirstMargin:para->nLeftMargin);
328         xs = c->rcView.left+nMargWidth;
329         xe = c->rcView.right-para->nRightMargin;
330         y += height;
331         rcPara.top = y;
332         rcPara.bottom = y+p->member.row.nHeight;
333         visible = RectVisible(c->hDC, &rcPara);
334         if (visible) {
335           HBRUSH hbr;
336           hbr = CreateSolidBrush(ME_GetBackColor(c->editor));
337           /* left margin */
338           rc.left = c->rcView.left;
339           rc.right = c->rcView.left+nMargWidth;
340           rc.top = y;
341           rc.bottom = y+p->member.row.nHeight;
342           FillRect(c->hDC, &rc, hbr/* c->hbrMargin */);
343           /* right margin */
344           rc.left = xe;
345           rc.right = c->rcView.right;
346           FillRect(c->hDC, &rc, hbr/* c->hbrMargin */);
347           rc.left = c->rcView.left+nMargWidth;
348           rc.right = xe;
349           FillRect(c->hDC, &rc, hbr);
350           DeleteObject(hbr);
351         }
352         if (me_debug)
353         {
354           const WCHAR wszRowDebug[] = {'r','o','w','[','%','d',']',0};
355           WCHAR buf[128];
356           POINT pt = c->pt;
357           wsprintfW(buf, wszRowDebug, no);
358           pt.y = 12+y;
359           ME_DebugWrite(c->hDC, &pt, buf);
360         }
361         
362         height = p->member.row.nHeight;
363         baseline = p->member.row.nBaseline;
364         pno++;
365         break;
366       case diRun:
367         assert(para);
368         run = &p->member.run;
369         if (visible && me_debug) {
370           rc.left = c->rcView.left+run->pt.x;
371           rc.right = c->rcView.left+run->pt.x+run->nWidth;
372           rc.top = c->pt.y+run->pt.y;
373           rc.bottom = c->pt.y+run->pt.y+height;
374           TRACE("rc = (%ld, %ld, %ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
375           if (run->nFlags & MERF_SKIPPED)
376             DrawFocusRect(c->hDC, &rc);
377           else
378             FrameRect(c->hDC, &rc, GetSysColorBrush(COLOR_GRAYTEXT));
379         }
380         if (visible)
381           ME_DrawRun(c, run->pt.x, c->pt.y+run->pt.y+baseline, p, &paragraph->member.para);
382         if (me_debug)
383         {
384           /* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
385           const WCHAR wszRunDebug[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
386           WCHAR buf[2560];
387           POINT pt;
388           pt.x = run->pt.x;
389           pt.y = c->pt.y + run->pt.y;
390           wsprintfW(buf, wszRunDebug, no, p->member.run.nFlags, p->member.run.strText->szData);
391           ME_DebugWrite(c->hDC, &pt, buf);
392         }
393         /* c->pt.x += p->member.run.nWidth; */
394         break;
395       default:
396         break;
397     }
398     no++;
399   }
400   SetTextAlign(c->hDC, align);
401 }
402
403 void ME_Scroll(ME_TextEditor *editor, int cx, int cy)
404 {
405   SCROLLINFO si;
406   HWND hWnd = editor->hWnd;
407
408   si.cbSize = sizeof(SCROLLINFO);
409   si.fMask = SIF_POS;
410   GetScrollInfo(hWnd, SB_VERT, &si);
411   si.nPos = editor->nScrollPosY -= cy;
412   SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
413   if (editor->bRedraw)
414   {
415     if (abs(cy) > editor->sizeWindow.cy)
416       InvalidateRect(editor->hWnd, NULL, TRUE);
417     else
418       ScrollWindowEx(hWnd, cx, cy, NULL, NULL, NULL, NULL, SW_ERASE|SW_INVALIDATE);
419   }
420 }
421
422 void ME_UpdateScrollBar(ME_TextEditor *editor)
423 {
424   HWND hWnd = editor->hWnd;
425   SCROLLINFO si;
426   int nOldLen = editor->nTotalLength;
427   BOOL bScrollY = (editor->nTotalLength > editor->sizeWindow.cy);
428   BOOL bUpdateScrollBars;
429   si.cbSize = sizeof(si);
430   si.fMask = SIF_POS | SIF_RANGE;
431   GetScrollInfo(hWnd, SB_VERT, &si);
432   bUpdateScrollBars = (bScrollY || editor->bScrollY)&& ((si.nMax != nOldLen) || (si.nPage != editor->sizeWindow.cy));
433   
434   if (bScrollY != editor->bScrollY)
435   {
436     si.fMask = SIF_RANGE | SIF_PAGE;
437     si.nMin = 0;
438     si.nPage = editor->sizeWindow.cy;
439     if (bScrollY) {
440       si.nMax = editor->nTotalLength;
441     } else {
442       si.nMax = 0;
443     }
444     SetScrollInfo(hWnd, SB_VERT, &si, FALSE);
445     ME_MarkAllForWrapping(editor);
446     editor->bScrollY = bScrollY;
447     ME_WrapMarkedParagraphs(editor);
448     bUpdateScrollBars = TRUE;
449   }
450   if (bUpdateScrollBars) {
451     int nScroll = 0;
452     si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
453     if (editor->nTotalLength > editor->sizeWindow.cy) {
454       si.nMax = editor->nTotalLength;
455       si.nPage = editor->sizeWindow.cy;
456       if (si.nPos > si.nMax-si.nPage) {
457         nScroll = (si.nMax-si.nPage)-si.nPos;
458         si.nPos = si.nMax-si.nPage;
459       }
460     }
461     else {
462       si.nMax = 0;
463       si.nPage = 0;
464       si.nPos = 0;
465     }
466     TRACE("min=%d max=%d page=%d pos=%d shift=%d\n", si.nMin, si.nMax, si.nPage, si.nPos, nScroll);
467     editor->nScrollPosY = si.nPos;
468     SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
469     if (nScroll)
470       ScrollWindow(hWnd, 0, -nScroll, NULL, NULL);
471   }
472 }
473
474 int ME_GetYScrollPos(ME_TextEditor *editor)
475 {
476   return editor->nScrollPosY;
477 }
478
479 void ME_EnsureVisible(ME_TextEditor *editor, ME_DisplayItem *pRun)
480 {
481   ME_DisplayItem *pRow = ME_FindItemBack(pRun, diStartRow);
482   ME_DisplayItem *pPara = ME_FindItemBack(pRun, diParagraph);
483   int y, yrel, yheight, yold;
484   HWND hWnd = editor->hWnd;
485   
486   assert(pRow);
487   assert(pPara);
488   
489   y = pPara->member.para.nYPos+pRow->member.row.nYPos;
490   yheight = pRow->member.row.nHeight;
491   yold = ME_GetYScrollPos(editor);
492   yrel = y - yold;
493   if (yrel < 0) {
494     editor->nScrollPosY = y;
495     SetScrollPos(hWnd, SB_VERT, y, TRUE);
496     if (editor->bRedraw)
497     {
498       ScrollWindow(hWnd, 0, -yrel, NULL, NULL);
499       UpdateWindow(hWnd);
500     }
501   } else if (yrel + yheight > editor->sizeWindow.cy) {
502     int newy = y+yheight-editor->sizeWindow.cy;
503     editor->nScrollPosY = newy;
504     SetScrollPos(hWnd, SB_VERT, newy, TRUE);
505     if (editor->bRedraw)
506     {
507       ScrollWindow(hWnd, 0, -(newy-yold), NULL, NULL);
508       UpdateWindow(hWnd);
509     }
510   }
511 }
512
513
514 void
515 ME_InvalidateFromOfs(ME_TextEditor *editor, int nCharOfs)
516 {
517   RECT rc;
518   int x, y, height;
519   ME_Cursor tmp;
520
521   ME_RunOfsFromCharOfs(editor, nCharOfs, &tmp.pRun, &tmp.nOffset);
522   ME_GetCursorCoordinates(editor, &tmp, &x, &y, &height);
523
524   rc.left = 0;
525   rc.top = y;
526   rc.bottom = y + height;
527   rc.right = editor->rcFormat.right;
528   InvalidateRect(editor->hWnd, &rc, FALSE);
529 }
530
531
532 void
533 ME_InvalidateSelection(ME_TextEditor *editor)
534 {
535   if (ME_IsSelection(editor) || editor->nLastSelStart != editor->nLastSelEnd)
536   {
537     int x, y, height;
538     int x2, y2, height2;
539     int last_x, last_y, last_height;
540     int last_x2, last_y2, last_height2;
541     RECT rc;
542     ME_Cursor tmp;
543   
544     ME_GetCursorCoordinates(editor, &editor->pCursors[1], &x, &y, &height);
545     ME_GetCursorCoordinates(editor, &editor->pCursors[0], &x2, &y2, &height2);
546     ME_RunOfsFromCharOfs(editor, editor->nLastSelStart, &tmp.pRun, &tmp.nOffset);
547     ME_GetCursorCoordinates(editor, &tmp, &last_x, &last_y, &last_height);
548     ME_RunOfsFromCharOfs(editor, editor->nLastSelEnd, &tmp.pRun, &tmp.nOffset);
549     ME_GetCursorCoordinates(editor, &tmp, &last_x2, &last_y2, &last_height2);
550     {
551       rc.left = 0;
552
553       rc.top = min(min(y, last_y), min(y2, last_y2));
554       rc.right = editor->rcFormat.right;
555       rc.bottom = max(max(y + height, last_y + last_height),
556                       max(y2 + height2, last_y2 + last_height2));
557       InvalidateRect(editor->hWnd, &rc, FALSE);
558     }
559   }
560   ME_GetSelection(editor, &editor->nLastSelStart, &editor->nLastSelEnd);
561 }
562
563
564 void
565 ME_QueueInvalidateFromCursor(ME_TextEditor *editor, int nCursor)
566 {
567   editor->nInvalidOfs = ME_GetCursorOfs(editor, nCursor);
568 }
569
570
571 BOOL
572 ME_SetZoom(ME_TextEditor *editor, int numerator, int denominator)
573 {
574   /* TODO: Zoom images and objects */
575
576   if (numerator != 0)
577   {
578     if (denominator == 0)
579       return FALSE;
580     if (1.0 / 64.0 > (float)numerator / (float)denominator
581         || (float)numerator / (float)denominator > 64.0)
582       return FALSE;
583   }
584   
585   editor->nZoomNumerator = numerator;
586   editor->nZoomDenominator = denominator;
587   
588   ME_RewrapRepaint(editor);
589   return TRUE;
590 }