Jump to content

Disabling a Window (Rectangle): Difference between revisions

From EDM2
Prokushev (talk | contribs)
No edit summary
 
Ak120 (talk | contribs)
mNo edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<P>Written by <A HREF="../common/authors/rstangl.html">Roman Stangl</A>
''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: [[Image:styleenabled.gif]]
*Disabled style: [[Image:styledisabled.gif]]
''Figure 1.a: Window Styles.''


<H2>The problem</H2>
The following function '''DisableWindowRect()''' is an example of how you can draw your control in a disabled style.


<P>If you create your own window controls, you can of course logically
== A DisableWindowRect() function ==
disable your controls with the OS/2 PM API <B>WinDisableWindow()</B>,
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.
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.


<P>Enabled style : <IMG SRC="styleenabled.gif" ALT="An enabled
Now, let's concentrate on the actual implementation of '''DisableWindowRect()''' which is shown in Figure 2.a.
scrollbutton" WIDTH=24 HEIGHT=24 ALIGN="absmiddle">
 
<P>Disabled style: <IMG SRC="styledisabled.gif" ALT="An enabled
scrollbutton" WIDTH=24 HEIGHT=24 ALIGN="absmiddle">
 
<P><FONT SIZE=2>
Figure 1.a: Window Styles.
</FONT>
 
<P>The following function <B>DisableWindowRect()</B> is an example of how
you can draw your control in a disabled style.
 
<H2>A DisableWindowRect() function</H2>
 
<P>As your control would draw into a rectangle inside a presentation space,
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
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.
 
<P> Now, let's concentrate on the actual implementation of
<B>DisableWindowRect()</B> which is shown in Figure 2.a.
 
<pre><SMALL>
   /*------------------------------------------------------------------------
   /*------------------------------------------------------------------------
   * This procedure disables a rectangle by drawing a halftoned background
   * This procedure disables a rectangle by drawing a halftoned background
Line 55: Line 32:
     GpiSetPattern(hpsDestination, PATSYM_HALFTONE);
     GpiSetPattern(hpsDestination, PATSYM_HALFTONE);
     GpiSetColor(hpsDestination, ulBackgroundColor);
     GpiSetColor(hpsDestination, ulBackgroundColor);
     GpiMove(hpsDestination, (POINTL *)(&amp;prectlDestination-&gt;xLeft));
     GpiMove(hpsDestination, (POINTL *)(&prectlDestination->xLeft));
     GpiBox(hpsDestination, DRO_OUTLINEFILL,
     GpiBox(hpsDestination, DRO_OUTLINEFILL,
           (POINTL *)(&amp;prectlDestination-&gt;xRight), 0, 0);
           (POINTL *)(&prectlDestination->xRight), 0, 0);
     GpiSetPattern(hpsDestination, PATSYM_SOLID);
     GpiSetPattern(hpsDestination, PATSYM_SOLID);
     return(NO_ERROR);
     return(NO_ERROR);
   }
   }
</SMALL></pre>
''Figure 2.a: DisableWindowRect().''
 
<FONT SIZE=2>
Figure 2.a: DisableWindowRect().
</FONT>
 
You may notice the casting.  As a <B>RECTANGLE</B> structure consists of 2
<B>POINTL</B> 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.
 
<P>Figure 2.b shows how you would invoke <B>DisableWindowRect()</B>.  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.
 
<pre><SMALL>
DisableWindowRect(pHP-&gt;hpsSession, prectlScrollLeft, SYSCLR_DIALOGBACKGROUND);
</SMALL></pre>


<FONT SIZE=2>
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: DisableWindowRect call.
</FONT>


The rectangle will be filled with a halftoned box of the background color,
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.
that is every odd pixel will be reset to the background color.
DisableWindowRect(pHP->hpsSession, prectlScrollLeft, SYSCLR_DIALOGBACKGROUND);
''Figure 2.b: DisableWindowRect call.''


<H2>Credits</H2>
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.


<P>Some ideas to solve that problem have been published in the OS/2
== Credits ==
development fora on the IBMPC conference disk.
Some ideas to solve that problem have been published in the OS/2 development fora on the IBMPC conference disk.


<P><A HREF="mailto:rstangl@vnet.ibm.com">Roman Stangl</A>
[[Category:PM Articles]]

Latest revision as of 15:32, 10 October 2022

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:
  • Disabled style:

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.