Disabling a Window (Rectangle): Difference between revisions
No edit summary |
Soren Ager (talk | contribs) m Formatting |
||
Line 1: | Line 1: | ||
Written by [[Roman Stangl]] | |||
== The problem == | |||
If you create your own window controls, you can of course logically | |||
disable your controls with the OS/2 PM API <B>WinDisableWindow()</B>, | disable your controls with the OS/2 PM API <B>WinDisableWindow()</B>, | ||
however it would be nice if you would draw your controls similar to | however it would be nice if you would draw your controls similar to | ||
Line 10: | Line 9: | ||
differently, as shown in Figure 1.a. | differently, as shown in Figure 1.a. | ||
Enabled style : <IMG SRC="styleenabled.gif" ALT="An enabled | |||
scrollbutton" WIDTH=24 HEIGHT=24 ALIGN="absmiddle"> | scrollbutton" WIDTH=24 HEIGHT=24 ALIGN="absmiddle"> | ||
Disabled style: <IMG SRC="styledisabled.gif" ALT="An enabled | |||
scrollbutton" WIDTH=24 HEIGHT=24 ALIGN="absmiddle"> | scrollbutton" WIDTH=24 HEIGHT=24 ALIGN="absmiddle"> | ||
< | <small>Figure 1.a: Window Styles.</small> | ||
Figure 1.a: Window Styles. | |||
</ | |||
The following function <B>DisableWindowRect()</B> is an example of how | |||
you can draw your control in a disabled style. | you can draw your control in a disabled style. | ||
== A DisableWindowRect() function == | |||
As your control would draw into a rectangle inside a presentation space, | |||
you pass to <B>DisableWindowRect()</B> your control's rectangle to disable | you pass to <B>DisableWindowRect()</B> your control's rectangle to disable | ||
the whole control, or a subrectangle to just disable a part of your | the whole control, or a subrectangle to just disable a part of your | ||
Line 32: | Line 29: | ||
all that controls into the single window's presentation space. | all that controls into the single window's presentation space. | ||
Now, let's concentrate on the actual implementation of | |||
<B>DisableWindowRect()</B> which is shown in Figure 2.a. | <B>DisableWindowRect()</B> which is shown in Figure 2.a. | ||
/*------------------------------------------------------------------------ | /*------------------------------------------------------------------------ | ||
* This procedure disables a rectangle by drawing a halftoned background | * This procedure disables a rectangle by drawing a halftoned background | ||
Line 61: | Line 58: | ||
return(NO_ERROR); | return(NO_ERROR); | ||
} | } | ||
< | <small>Figure 2.a: DisableWindowRect().</small> | ||
Figure 2.a: DisableWindowRect(). | |||
</ | |||
You may notice the casting. As a <B>RECTANGLE</B> structure consists of 2 | You may notice the casting. As a <B>RECTANGLE</B> structure consists of 2 | ||
Line 72: | Line 66: | ||
variables by applying above casts. | variables by applying above casts. | ||
Figure 2.b shows how you would invoke <B>DisableWindowRect()</B>. The | |||
sample invocation passes the presentation space your control will be drawn | sample invocation passes the presentation space your control will be drawn | ||
into, the rectangle you want to draw in a disabled style, and the | into, the rectangle you want to draw in a disabled style, and the | ||
background color active in your presentation space. | background color active in your presentation space. | ||
< | DisableWindowRect(pHP->hpsSession, prectlScrollLeft, SYSCLR_DIALOGBACKGROUND); | ||
Figure 2.b: DisableWindowRect call. | |||
</ | <small>Figure 2.b: DisableWindowRect call.</small> | ||
The rectangle will be filled with a halftoned box of the background color, | The rectangle will be filled with a halftoned box of the background color, | ||
that is every odd pixel will be reset to the background color. | that is every odd pixel will be reset to the background color. | ||
== Credits == | |||
Some ideas to solve that problem have been published in the OS/2 | |||
development fora on the IBMPC conference disk. | development fora on the IBMPC conference disk. | ||
Revision as of 16:12, 18 November 2004
Written by Roman Stangl
The problem
If you create your own window controls, you can of course logically disable your controls with the OS/2 PM API WinDisableWindow(), however it would be nice if you would draw your controls similar to standard OS/2 controls. For example, the right-scrollbutton may be drawn differently, as shown in Figure 1.a.
Enabled style : <IMG SRC="styleenabled.gif" ALT="An enabled scrollbutton" WIDTH=24 HEIGHT=24 ALIGN="absmiddle">
Disabled style: <IMG SRC="styledisabled.gif" ALT="An enabled scrollbutton" WIDTH=24 HEIGHT=24 ALIGN="absmiddle">
Figure 1.a: Window Styles.
The following function DisableWindowRect() is an example of how you can draw your control in a disabled style.
A DisableWindowRect() function
As your control would draw into a rectangle inside a presentation space, you pass to DisableWindowRect() your control's rectangle to disable the whole control, or a subrectangle to just disable a part of your window. The latter is useful when you draw a window that seems to consist of multiple controls, but to save resources (e.g. window handles) you draw all that controls into the single window's presentation space.
Now, let's concentrate on the actual implementation of DisableWindowRect() which is shown in Figure 2.a.
/*------------------------------------------------------------------------ * This procedure disables a rectangle by drawing a halftoned background * colored box into the rectangle. * Req: * hpsDestination The presentation space to blit icon into * prectlDestination * The target rectangle to draw halftoned box into * ulBackgroundColor * The background color to be used * Ret: * ulRc .......... Return code: NO_ERROR no error, PMERR_* otherwise * Ref: \*------------------------------------------------------------------------ ULONG DisableWindowRect(HPS hpsDestination, RECTL *prectlDestination, ULONG ulBackgroundColor) { GpiSetPattern(hpsDestination, PATSYM_HALFTONE); GpiSetColor(hpsDestination, ulBackgroundColor); GpiMove(hpsDestination, (POINTL *)(&prectlDestination->xLeft)); GpiBox(hpsDestination, DRO_OUTLINEFILL, (POINTL *)(&prectlDestination->xRight), 0, 0); GpiSetPattern(hpsDestination, PATSYM_SOLID); return(NO_ERROR); }
Figure 2.a: DisableWindowRect().
You may notice the casting. As a RECTANGLE structure consists of 2 POINTL structures, the first for the lower left and the second for the upper right edge of the rectangle, you can save some temporary variables by applying above casts.
Figure 2.b shows how you would invoke DisableWindowRect(). The sample invocation passes the presentation space your control will be drawn into, the rectangle you want to draw in a disabled style, and the background color active in your presentation space.
DisableWindowRect(pHP->hpsSession, prectlScrollLeft, SYSCLR_DIALOGBACKGROUND);
Figure 2.b: DisableWindowRect call.
The rectangle will be filled with a halftoned box of the background color, that is every odd pixel will be reset to the background color.
Credits
Some ideas to solve that problem have been published in the OS/2 development fora on the IBMPC conference disk.