Minor fixes to comments.
[AROS.git] / rom / intuition / refreshwindowframe.c
blob2c3029a090169844de64fefe70c897ff40eda616
1 /*
2 Copyright 1995-2011, The AROS Development Team. All rights reserved.
3 Copyright 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <intuition/gadgetclass.h>
8 #include <intuition/intuitionbase.h>
9 #include <intuition/windecorclass.h>
10 #include <graphics/rpattr.h>
11 #include <cybergraphx/cybergraphics.h>
13 #include <proto/layers.h>
14 #include <proto/graphics.h>
15 #include <proto/layers.h>
17 #include <string.h>
19 #include "inputhandler_actions.h"
20 #include "intuition_intern.h"
22 // #define GADGETCLIPPING
24 #ifdef GADGETCLIPPING
25 void clipbordergadgets(struct Region *region,struct Window *w,struct IntuitionBase *IntuitionBase);
26 #endif
28 /*****************************************************************************
30 NAME */
31 #include <proto/intuition.h>
33 AROS_LH1(void, RefreshWindowFrame,
35 /* SYNOPSIS */
36 AROS_LHA(struct Window *, window, A0),
38 /* LOCATION */
39 struct IntuitionBase *, IntuitionBase, 76, Intuition)
41 /* FUNCTION
42 Redraw window borders.
44 INPUTS
45 window - pointer to a window whose borders should be redrawn
47 RESULT
49 NOTES
51 EXAMPLE
53 BUGS
55 SEE ALSO
57 INTERNALS
59 *****************************************************************************/
61 AROS_LIBFUNC_INIT
63 EnterFunc(bug("RefreshWindowFrame(window=%p)\n", window));
65 int_refreshwindowframe(window, 0, 0, IntuitionBase);
67 ReturnVoid("RefreshWindowFrame");
69 AROS_LIBFUNC_EXIT
70 } /* RefreshWindowFrame */
72 VOID int_RefreshWindowFrame(struct Window *window,
73 LONG mustbe, LONG mustnotbe, LONG mode,
74 struct IntuitionBase *IntuitionBase)
76 /* Draw a frame around the window */
77 struct LayersBase *LayersBase = GetPrivIBase(IntuitionBase)->LayersBase;
78 struct RastPort *rp = window->BorderRPort;
79 struct DrawInfo *dri;
80 struct Region *old_clipregion;
82 #ifdef GADGETCLIPPING
83 struct Region *gadgetclipregion;
84 #endif
86 WORD old_scroll_x, old_scroll_y;
88 if (!(window->Flags & WFLG_BORDERLESS))
90 dri = GetScreenDrawInfo(window->WScreen);
91 if (dri)
93 LOCK_REFRESH(window->WScreen);
94 LOCKGADGET(IntuitionBase)
95 #if 1
96 if ((rp->Layer==NULL) ||
97 ((!(window->Flags & WFLG_GIMMEZEROZERO)) && (rp->Layer != window->RPort->Layer)))
99 dprintf("RefreshWindowFrame: Window 0x%lx\n",window);
100 dprintf("RefreshWindowFrame: WLayer 0x%lx\n",window->WLayer);
101 dprintf("RefreshWindowFrame: RPort 0x%lx BorderRPort 0x%lx\n",window->RPort,window->BorderRPort);
102 dprintf("RefreshWindowFrame: RPort's layer 0x%lx BorderRPort's layer 0x%lx\n",window->RPort,window->RPort->Layer,window->BorderRPort,window->BorderRPort->Layer);
105 #endif
107 LockLayer(0,rp->Layer);
109 old_scroll_x = rp->Layer->Scroll_X;
110 old_scroll_y = rp->Layer->Scroll_Y;
112 rp->Layer->Scroll_X = 0;
113 rp->Layer->Scroll_Y = 0;
115 #ifdef GADGETCLIPPING
116 gadgetclipregion = NewRegion();
117 if (gadgetclipregion)
119 struct Rectangle rect;
121 /* add all gadgets to region */
122 clipbordergadgets(gadgetclipregion,window,IntuitionBase);
124 /* then remove them with xor */
125 rect.MinX = 0;
126 rect.MinY = 0;
127 rect.MaxX = window->Width - 1;
128 rect.MaxY = window->Height - 1;
129 XorRectRegion(gadgetclipregion,&rect);
133 old_clipregion = InstallClipRegion(rp->Layer, gadgetclipregion);
134 #else
135 old_clipregion = InstallClipRegion(rp->Layer, NULL);
136 #endif
139 struct wdpDrawWinBorder msg;
141 msg.MethodID = WDM_DRAW_WINBORDER;
142 msg.wdp_TrueColor = (((struct IntScreen *)window->WScreen)->DInfo.dri.dri_Flags & DRIF_DIRECTCOLOR);
143 msg.wdp_Window = window;
144 msg.wdp_RPort = rp;
145 msg.wdp_Flags = (mustbe == REFRESHGAD_TOPBORDER) ? WDF_DWB_TOP_ONLY : 0;
146 msg.wdp_Dri = dri;
147 msg.wdp_UserBuffer = ((struct IntWindow *)window)->DecorUserBuffer;
148 DoMethodA(((struct IntScreen *)(window->WScreen))->WinDecorObj, (Msg)&msg);
151 #ifdef GADGETCLIPPING
152 InstallClipRegion(rp->Layer,NULL);
153 #endif
155 /* Emm: RefreshWindowFrame() is documented to refresh *all* the gadgets,
156 * but when a window is activated/deactivated, only border gadgets
157 * are refreshed. */
158 #if 1
159 /* Refresh rel gadgets first, since wizard.library (burn in hell!) seems
160 * to rely on that. */
161 int_refreshglist(window->FirstGadget,
162 window,
163 NULL,
165 mustbe | REFRESHGAD_REL,
166 mustnotbe,
167 IntuitionBase);
168 int_refreshglist(window->FirstGadget,
169 window,
170 NULL,
172 mustbe,
173 mustnotbe | REFRESHGAD_REL,
174 IntuitionBase);
175 #else
176 int_refreshglist(window->FirstGadget,
177 window,
178 NULL,
180 mustbe,
181 mustnotbe,
182 IntuitionBase);
183 #endif
185 InstallClipRegion(rp->Layer,old_clipregion);
187 #ifdef GADGETCLIPPING
188 if (gadgetclipregion) DisposeRegion(gadgetclipregion);
189 #endif
191 rp->Layer->Scroll_X = old_scroll_x;
192 rp->Layer->Scroll_Y = old_scroll_y;
194 UnlockLayer(rp->Layer);
195 UNLOCKGADGET(IntuitionBase)
197 UNLOCK_REFRESH(window->WScreen);
199 FreeScreenDrawInfo(window->WScreen, (struct DrawInfo *)dri);
201 } /* if (dri) */
203 } /* if (!(win->Flags & WFLG_BORDERLESS)) */
206 #ifdef GADGETCLIPPING
207 void clipbordergadgets(struct Region *region,struct Window *w,struct IntuitionBase *IntuitionBase)
209 struct Gadget *gad;
211 for (gad = w->FirstGadget; gad; gad = gad->NextGadget)
213 BOOL qualified = FALSE;
214 WORD left,top,right,bottom;
216 top = gad->TopEdge;
217 left = gad->LeftEdge;
219 if (gad->Flags & GFLG_RELBOTTOM) top = w->Height - 1 + gad->TopEdge;
220 if (gad->Flags & GFLG_RELRIGHT) left = w->Width - 1 + gad->LeftEdge;
222 /* we need to be prepared for GFLG_GADGIMAGE and IA_Left set to -1, etc */
223 if (gad->Flags & GFLG_GADGIMAGE && gad->SelectRender)
224 left += ((struct Image *)gad->SelectRender)->LeftEdge;
226 right = left + gad->Width - 1;
227 bottom = top + gad->Height - 1;
229 /* let's do some clipping now */
231 if (left >= w->Width) continue;
232 if (top >= w->Height) continue;
233 if (right < 0) continue;
234 if (bottom < 0) continue;
236 if (left < 0) left = 0;
237 if (top < 0) top = 0;
238 if (right > w->Width) right = w->Width;
239 if (top > w->Height) top = w->Height;
241 /* sanity check */
243 if (right < left) continue;
244 if (bottom < top) continue;
246 /* clip this gadget ? */
248 if (top >= w->Height - 1 - w->BorderBottom) qualified = TRUE;
249 if (left >= w->Width - 1 - w->BorderRight) qualified = TRUE;
250 if (top + gad->Height - 1 <= w->BorderTop) qualified = TRUE;
251 if (left + gad->Width - 1 <= w->BorderLeft) qualified = TRUE;
253 if (qualified)
255 struct Rectangle rect;
257 rect.MinX = left;
258 rect.MinY = top;
259 rect.MaxX = right;
260 rect.MaxY = bottom;
262 OrRectRegion(region,&rect);
268 #endif