TOffice97Button
ReadMe
By
Jonathan Hosking
V1.9 (1/3/2000)
Table
of Contents
What
is the TOffice97Button Component?
How
to install the TOffice97Button component
TOffice97Button Reference
Revision History
Future Ideas
Other Components
Contacting Me
What is
the TOffice97Button component?
The TOffice97Button
component is a new component I have written for Delphi and C++Builder. It looks
and acts like the controls (Buttons, radiobuttons, up buttons and down buttons)
that appear in the Office Assistant balloons in Office 97 and Office 2000. It
can be fully customised if desired. It has the following features: -
- Fully customisable
source code, which can be edited if necessary.
- "Active"
border & button glyphs, which change depending on the state of the control.
- "Active"
button glyphs can be easily modified, positioned and turned on or off.
- Control can
act like any control that appears in the Office Assistant balloons in Office
97 and Office 2000.
- A popup menu
can be used with the control.
- Fully compatible
with the TButton component. (It has all the properties and events of the TButton
component)
- Works on Windows
95 and NT. (I have not tested it with Windows 98)
- Compact size,
only occupying 47KB when compiled in Delphi 1.0! (42KB in Delphi 5.0!)
The component code
was written by modifying some code for an Internet Explorer-style button, written
by Dave Jewell. Code from the TButton component was also used to write some
handling routines and the code for creating a disabled bitmap was taken from
the RX Library v2.40. The code works fine on Delphi 1.0, 2.0, 4.0, 5.0 and C++Builder
3.0, but I have not tested it with other versions.
You are free to
distribute the code, but you may NOT sell it. If you modify the code, you must
include me in the acknowledgements. If you do want your ideas or modifications
to be incorporated into the latest version, send them to the address at the
end of this document.
Thanks to Kambiz
for adding bi-directional support and for the auto height adjustment routines.
How to
install the TOffice97Button component
To unzip the TOffice97Button
component, assuming [Program Path] is the path to Delphi or C++Builder,
follow these steps: -
- Unzip the file
OFFBTN97.ZIP to any directory, using the directory switch (This is
VERY important).
- Copy the file
OFFBTN.PAS to the directory [Program Path]\Source\Samples.
- If you want
documentation, copy the file OFFBTN97.HTM to the directory [Program
Path]\Bin, if you are using Delphi 1.0. Otherwise, copy it to the directory
[Program Path]\Help.
- If you are
using Delphi 1.0, copy the files in the 16-Bit directory of this Zip
to the directory [Program Path]\Source\Samples. Otherwise copy the
files in the 32-Bit directory of this Zip to the directory [Program
Path]\Source\Samples.
You can now install
the component into the component library. Ignore the 3 compiler warnings about
variables not being initialised. Follow the procedure for the version of Delphi
or C++Builder that you are using.
Delphi
1.0:
- Click on Options
and then select Install Components.
- In the Install
Components dialog, click Add. In the next dialog, click Browse
and open the file OFFBTN.PAS.
- Click Ok
to install the component.
Delphi
2.0:
This procedure
should also work with C++Builder 1.0, but I'm not sure.
- Click on Component
and select Install.
- In the Install
Components dialog, click Add. In the next dialog, click Browse
and open the file OFFBTN.PAS.
- Click Ok
to install the component.
Delphi
4.0:
- Click on Tools
and select Environment Options.
- In the next
dialog, click on the Library tab and add the full path of the TOffice97Button
source code to the Library Path edit box. Then click Ok.
- Click on Component
and select Install Component.
- In the Install
Component dialog, click on the Into existing package tab. Click
on the first Browse button and open the file OFFBTN.PAS. Then
click on the second Browse button and open the file DCLUSR40.DPK.
Finally, click Ok to install the component.
Delphi
5.0:
- Click on Tools
and select Environment Options.
- In the next
dialog, click on the Library tab and add the full path of the TOffice97Button
source code to the Library Path edit box. Then click Ok.
- Click on Component
and select Install Component.
- In the Install
Component dialog, click on the Into existing package tab. Click
on the first Browse button and open the file OFFBTN.PAS. Then
click on the second Browse button and open the file DCLUSR50.DPK.
Finally, click Ok to install the component.
C++Builder
3.0:
This procedure
should also work, with minor modifications, with Delphi 3.0 and C++Builder 4.0,
but I'm not sure.
- Click on Tools
and select Environment Options.
- In the next
dialog, click on the Library tab and add the full path of the TOffice97Button
source code to the Library Path edit box. Then click Ok.
- Click on Component
and select Install Component.
- In the Install
Component dialog, click on the Into existing package tab. Click
on the first Browse button and open the file OFFBTN.PAS. Then
click on the second Browse button and open the file DCLUSR35.BPK.
Finally, click Ok to install the component.
TOffice97Button
Reference
Remarks:
You may wonder
why 2 resource files are used with this component. There are several explanations
for this: -
- The DCR file
could not be linked in, because doing so would cause a "Duplicate Resource
Identifier" error.
- The bitmaps
in the RES file have to be linked in, otherwise they won't display properly.
They can't be in the DCR file, as this would mean linking the DCR file, which
would cause the error described above.
- A RES file
can't be used alone, as the error described above would occur and the component's
icon would not be displayed.
The bitmaps used
to indicate the status of the control can be edited by opening the file OFFBTN.RES.
These bitmaps are the default bitmaps for every TOffice97Button component, so
any changes will be global. The bitmaps are stored in the following names: -
- OFFICE_1
– Active state bitmap. (Button)
- OFFICE_2
– Disabled state bitmap. (Button)
- OFFICE_3
– Down state bitmap. (Button)
- OFFICE_4
– Inactive state bitmap. (Button)
- OFFICE_5
– Active state bitmap. (Radiobutton)
- OFFICE_6
– Disabled state bitmap. (Radiobutton)
- OFFICE_7
– Down state bitmap. (Radiobutton)
- OFFICE_8
– Inactive state bitmap. (Radiobutton)
- OFFICE_9
– Active state bitmap. (Up Button)
- OFFICE_10
– Disabled state bitmap. (Up Button)
- OFFICE_11
– Down state bitmap. (Up Button)
- OFFICE_12
– Inactive state bitmap. (Up Button)
- OFFICE_13
– Active state bitmap. (Down Button)
- OFFICE_14
– Disabled state bitmap. (Down Button)
- OFFICE_15
– Down state bitmap. (Down Button)
- OFFICE_16
– Inactive state bitmap. (Down Button)
- OFFICE_17
– Active state bitmap. (Office 2000 Radiobutton)
- OFFICE_18
– Disabled state bitmap. (Office 2000 Radiobutton)
- OFFICE_19
– Down state bitmap. (Office 2000 Radiobutton)
- OFFICE_20
– Inactive state bitmap. (Office 2000 Radiobutton)
The assumed transparent
colour of the bitmaps is clBlack. This can be changed by modifying the
fTransparentColor variable in the TOffice97Button.Create(AOwner: TComponent)
constructor, or by modifying the TransparentColor property.
It is not advisable
to reduce the control size. If you do, the control may not display exactly as
it should. Text may disappear if the control becomes too small. There shouldn't
be any fatal errors if the control size is decreased. You also should not delete
any of the bitmaps, or rename them, as this will probably cause errors.
When the ControlType
property is set to anything other than bsButton, the control frame is
not drawn and the focus is drawn in the Office 97 style. It is also a fixed
size when text is word-wrapped, unless you change the control size.
Early versions
of the component used the cmFocusChanged message to handle focus control.
This was eventually replaced by the wmKillFocus and wmLostFocus
messages in version 1.4, fixing a very annoying bug. However, the cmFocusChanged
message is still called, to update the control, when the Default property
is set.
If you are upgrading
the component to version 1.9 or later of the control, you may find that the
glyphs on any TOffice97Buttons disappear. If this happens, toggle the Office2000Look
property on and off.
Known
Problems:
There are currently
no problems with the control.
Key Properties:
- property
About: TOffBtnAbout default abNone;
If
you set this to abAbout, the component information is shown.
- property
ActiveColor: TColor default $00808080;
The
colour of the control outline when it is active.
- property
ActiveGlyph: TBitmap;
The
glyph to be displayed when the control is active. If the property is empty,
the default active glyph is used.
- property
ActiveOutlineColor: TColor default clWhite;
The
colour of the inside control outline when it is active.
- property
ActiveOutlineColor2: TColor default $00D6E7E7;
The
colour of the second inside control outline when it is active.
- property
Align;
Determines
how the control is aligned within its parent.
- property
AutoHeight: Boolean default True;
If
this is set to True, the control automatically adjusts its own height.
- property
BiDiMode;
Determines
if the control uses bi-directional support.
- property
Cancel: Boolean;
If
this is set to True, the OnClick event occurs when you press
ESC.
- property
Caption: TCaption;
This
is what text appears in the control.
- property
Color;
Determines
the colour of the control. The default ($00CCFFFF) is a yellowish
colour.
- property
ControlType: TOffBtnType default bsButton;
Determines
the type of control that is displayed.
- property
Default: Boolean default False;
If
this is set to True, the OnClick event occurs when you press
ENTER, even if the control isn't selected.
- property
DisabledGlyph: TBitmap;
The
glyph to be displayed when the control is disabled. If the property is empty,
the default disabled glyph is used.
- property
DownActiveGlyph: TBitmap;
The
glyph to be displayed when the control is active and clicked. If the property
is empty, the default active and clicked glyph is used.
- property
DragCursor;
Determines
the mouse pointer that is displayed when an object is dragged over the control.
- property
DragMode;
If
this is set to automatic, the control can be dragged and dropped at any time.
If this is set to manual, the control can only be dragged when the BeginDrag
method is called.
- property
Enabled;
If
this is set to False, the control cannot be used until this is set
to true.
- property
Font;
Determines
the font that is used in the control.
- property
InactiveColor: TColor default clSilver;
The
colour of the control outline when it is inactive.
- property
InactiveGlyph: TBitmap;
The
glyph to be displayed when the control is inactive. If the property is empty,
the default inactive glyph is used.
- property
ModalResult: TModalResult default 0;
If
this is not set to 0, the form containing the control closes and the
value of ModalResult is sent to whatever called the ShowModal
method for that form.
- property
Office2000Look: Boolean default True;
Determines
if an Office 2000 look is applied to the control.
- property
ParentBiDiMode;
If
this is set to True, the control uses the BiDiMode used by its
parent.
- property
ParentFont;
If
this is set to True, the control uses the font used by its parent.
- property
ParentShowHint;
If
this is set to True, the parent of the control displays the hints.
- property
PopupMenu;
If
this is set, right clicking the control displays the set popup menu.
- property
Position: TGlyphPosition default bsLeft;
This
determines the position of the glyph on the control. When the ControlType
property is not set to bsButton, the only accepted values are bsTop
and bsBottom.
- property
ShowGlyph: Boolean default True;
If
this is set to False, the glyph is not displayed on the control.
- property
ShowHint;
If
this is set to True, the control displays its own popup hints.
- property
TabOrder;
This
determines the order in which the controls in the parent are selected.
- property
TabStop default True;
If
this is set to False, the Tab key can't be used to select the
control focus.
- property
TransparentColor: TColor default clBlack;
Determines
the transparent colour of the glyph.
- property
UseCustomGlyphs: Boolean default False;
If
this is set to True, the custom glyphs will be displayed instead of
the default glyphs.
- property
Visible;
If
this is set to False, the control cannot be seen.
- property
WordWrap: Boolean default True;
If
this is set to True, the text is word wrapped. If you set the ControlType
property to anything other than bsButton, the Office 97 focus is used.
Key Events:
- property
OnClick: TNotifyEvent;
Occurs
when the control is selected.
- property
OnDblClick: TNotifyEvent;
Occurs
when the control is double-clicked.
- property
OnDragDrop: TNotifyEvent;
Occurs
when an object being dragged is dropped.
- property
OnDragOver: TNotifyEvent;
Occurs
when an object is dragged over the control.
- property
OnEndDrag: TNotifyEvent;
Occurs
whenever the dragging of an object ends, either by dropping the object or
by cancelling the dragging.
- property
OnEnter: TNotifyEvent;
Occurs
when the control becomes active.
- property
OnExit: TNotifyEvent;
Occurs
when the input focus switches from the control to another control.
- property
OnKeyDown: TNotifyEvent;
Occurs
when a key is pressed while the control has focus.
- property
OnKeyPress: TNotifyEvent;
Occurs
when a key is pressed.
- property
OnKeyUp: TNotifyEvent;
Occurs
when a key, that was pressed, is released.
- property
OnMouseDown: TNotifyEvent;
Occurs
when a mouse button is pressed with the pointer over the control.
- property
OnMouseEnter: TNotifyEvent;
Occurs
when the mouse enters the control.
- property
OnMouseExit: TNotifyEvent;
Occurs
when the mouse leaves the control.
- property
OnMouseMove: TNotifyEvent;
Occurs
when the pointer is moved whilst over the control.
- property
OnMouseUp: TNotifyEvent;
Occurs
when a mouse button that was pressed is released with the pointer over the
control.
Revision
History
V1.9 (1/2/2000)
- New ActiveOutlineColor2
and Office2000Look properties added, adding
Office 2000 features to the control.
- The default
value of Color is now $00CCFFFF.
- The default
value of ActiveColor is now $00808080.
V1.82 (22/12/1999)
- Bug Fixed –
The control had a slight bug in the keyboard routines. Thanks to Kambiz
for fixing it.
- Bug Fixed -
The control did not work properly with modal forms. This was due to the mouse
being captured when it should not have been.
- Changed the
default value of the Color property to the actual colour ($00E1FFFF).
V1.81 (21/11/1999)
- Bug Fixed –
The auto height adjustment code had a few inaccuracies. Thanks to Kambiz
for fixing it.
V1.8 (30/10/1999)
- New BiDiMode
and ParentBiDiMode properties added, allowing bi-directional support.
Thanks to Kambiz
for providing the code.
- New AutoHeight
property added, allowing the control to automatically adjust its own height.
Thanks to Kambiz
for providing the code.
V1.7 (04/09/1999)
- Delphi 5.0 is
now supported.
V1.69 (17/08/1999)
- Added a message
hook to help reduce flickering.
V1.68 (12/08/1999)
- Bug Fixed –
The control now correctly recognises C++Builder 4.0.
- Updated the
drawing routines to reduce flicker on the control.
V1.67 (25/05/1999)
- C++Builder 3.0
is now supported.
- Code documentation
has been slightly improved, though there is still more room for improvement.
V1.66 (16/03/1999)
- Bug Fixed –
The control state didn't update correctly when using modal forms.
V1.65 (19/02/1999)
- Bug Fixed –
Wouldn't compile in Delphi 3.0 and 4.0 due to difference between TCustomForm
and TForm. It should now compile all right.
V1.64 (22/01/1999)
- Bug Fixed –
An error was generated when the user displayed only text using a control style
other than bsButton.
- The text is
positioned slightly more accurately to improve the control's appearance.
V1.63 (09/12/1998)
- Bug Fixed –
The keyboard routines didn't work correctly due to an error in the focus handling
routines.
- New About
property added, allowing the user to display information about the component.
V1.62 (30/08/1998)
- Bug Fixed –
The positioning routine did not work correctly for bsBottom or bsRight.
- Bug Fixed –
If the control was too small to accommodate any text, it produced errors.
V1.61 (05/05/1998)
- Bug Fixed –
The control did not work correctly when it was top of or below other TOffice97Button
components.
V1.6 (26/02/1998)
- New UseCustomGlyphs
property added, allowing custom glyphs to be turned on or off.
- The control
now uses a new transparent routine to draw the glyphs. This is a lot better
than the method used in previous versions.
- The control
uses new routine to create a disabled bitmap if one is not already specified.
V1.5 (08/02/1998)
- New WordWrap
property added, allowing text to be word wrapped, if required.
- The control
now uses the Office 97 focus when the ControlStyle property is not
set to bsButton. The control should now look almost exactly like the
real thing.
V1.4 (01/02/1998)
- Bug Fixed –
The control did not update itself when switching between windows. This is
the most annoying bug, to date, to have been fixed!
- The focus now
looks like it should when the control is in the bsDown state.
- The control
painting procedures have been slightly improved.
V1.3 (27/01/1998)
- The control
now uses a new control frame, improving its appearance.
- The default
values of Height and Width are now 23 and 70.
V1.2 (26/01/1998)
- The control
now uses 256 colour glyphs, improving the appearance.
- New ControlType
property added, allowing the user to display any control (Button, radiobutton,
up button and down button) that appears in the Office Assistant balloons in
Office 97. As each type of control uses different glyphs, there are now even
more bitmaps, which has dramatically increased the size of the RES file.
- The default
value of Color is now $00CEFFFF.
- The default
value of TransparentColor is now clBlack.
- The default
value of ActiveColor is now clGray.
- The default
value of InactiveColor is now clSilver.
V1.1 (01/01/1998)
- Bug Fixed –
If the Default property was set to true, the control didn't respond
to the Enter key when it didn't have the focus.
- The control
now uses a new routine to draw the focus. This is better than the old routine
used in previous versions, as the new focus looks similar to a real focus.
- The control
now only updates itself when necessary.
- New ActiveGlyph,
DisabledGlyph, DownActiveGlyph and InactiveGlyph properties
added, allowing the user to use custom glyphs without modifying the OFFBTN.RES
file.
- New events added,
including OnDragDrop, OnDragOver, OnEndDrag, OnEnter,
OnExit, OnKeyDown, OnKeyPress and OnKeyUp.
- New PopupMenu
property added, allowing the control to use popup menus.
- New Position
property added, allowing the glyph to be positioned on the control in 4 different
places.
- New ShowGlyph
property added, allowing the user to turn the glyphs on or off.
- Other new properties
added, including DragCursor, DragMode, ModalResult and
TransparentColor.
V1.01 (10/12/1997)
- Bug Fixed –
When the user clicked the control and released the mouse button, the control
acted as if it had been clicked again.
- Code is now
documented in some areas to show what is happening, although most remains
undocumented.
V1.0 (09/12/1997)
Future
Ideas
I currently only
have one idea for future versions of the TOffice97Button component. It is listed
below: -
- Improved control
updating, so it doesn't flicker unnecessarily.
Other
Components
Below is a list
other components that I have written: -
- TLCD99 – A control
that looks like an LCD display.
- TOffice97Balloon
– A control that looks and acts like the Office Assistant balloons in Office
97.
- TYearPlanner
– A control that looks like a year planner.
Contacting
Me
I am currently
on the Internet. If you have any bug reports, comments, ideas, modifications,
etc. then you can Email me at the address given below. You can also go to my
web site to find out the latest information on my components.
Email: - jonathan@the-hoskings.freeserve.co.uk
WWW:
http://www.the-hoskings.freeserve.co.uk/