Purpose:
To provide programmers using Win32lib the ability to create buttons with color, caption and
graphics.
Credits:
ColoredButtons was developed using Euphoria, Win32lib and IDE developmental tools
Andy Drummond supplied many tips for drawing buttons as well as ideas to enhance colored buttons
and a trick to prevent w32HClick of real M$ button being handled twice.
Rajesh Deshpande suggested placing Graphic on colored button, obtaining Hint text from the actual
createEx button, changing caption color when pressed, new Caption Postion 3 which means center
caption and graphic as a unit, suggested use of repaintFG when button is not completely repainted if another
window partially covers button, suggested improvements and helped me in use of icon and bitmap from
Bernie Ryan's win32eru package.
Bernie Ryan for reminding me about and_bits to get BS_MULTILINE and Flat style
Roland Stowasser informed me that getWindowInfo did not work on Win95 and suggested I use getControlStyles.
Stephen ? informed me about usage of ClearWindow.
Gregory Haberek suggested adding text rotation
Thomas Parslow for the irregular.ew lib for drawing Elliptic and RoundedRectangle buttons.
Chris Cuvier gave me assistence removing a stray pixel near non-rectangular buttons.
License:
You may use this file in any application for free but should acknowledge myself as original author. You may modify
to include additional routines but I do ask that you send me a copy so that I might upgrade for other people's use.
To Do:
capability to rotate graphic as option when caption is rotated; may be restricted to 90 degree rotations
capability to rotate rectangular button as option when caption is rotated
Method:
Colored Buttons are emulated buttons built with Child Window and Pixmap controls and an
array holding original button Id and a generated Id for the colored button with all
information needed to color and manage the button.
Restrictions:
Colored buttons may be used in place of createEx buttons where permitted by Windows[tm] except
placing a coloredbutton on another button (colored or not) or on ReBarBand.
Using classDefaults on Window control will produce unpredictable appearance of colored buttons.
Tips and Tricks:
If you have a message_box or another window in your program that covers colored buttons when the window
is moved or dismissed the colored button may not be entirely repainted. When this happens code repaintFG(Window Id)
after your message_box statement or after moving another window.
If you see button sitting inside itself, you might need to add the statement clearWindow(id) prior to any forceCBPaint(id) or remove any classDefault statements for Window control.
Code forceCBPaint(id) after coding setVisible, setEnable, setCheck
If you make your button elliptical and rotate the caption the button will appear to rotate as well unless you have a graphic.
Problems:
Drawing arc around corners of RoundedRectangle and the arc around Elliptical buttons is not smooth and there may be gaps.
Required include file
At the top of your program, or at least before any of the following routines, include coloredButtons.ew which includes Irregular.ew
Getting Started
To set up a colored button you would first define all the controls, including the buttons which
would later be colored, via createEx statements in the normal way. After all your controls are defined,
for each button you desire color, add the following statement which builds an entry in the
ColoredButtonInformation array.
translateToColoredButton(integer Id, object graphic_filename, object disabled_graphic_filename)
Note:
Style and ExStyle params from your createEx'd button will be ignored except for BS_MULTILINE and #8000 (FlatButton).
If you have other Style or ExStyle please contact me and I'll investigate if it can be added.
If your button class is PictureButton or TogglePicture, colored buttons can not determine BS_MULTILINE
or #8000 from Style and you must use multilineCBCaption and/or changeCBClass
You may have colored buttons on more than one window.
You may place each of the translateToColoredButton statements after the button control it is to
replace instead of after all the createEx statements but be sure all button controls to be colored are translated prior to your program routines.
If you have a Hint for your actual buttons, colored button will acquire the hint.
If you have assigned a font for your actual buttons, colored button will acquire the font.
If you change your actual button's Font via setFont or setCreateFont, the colored button will initially
use that font.
There is a way to use your own routines which can
access the ColoredButtonInformation array and force a w32HPaint event if necessary.
After all your controls are createEx'd and translateToColoredButton added, use the following statement to open and paint the colored buttons.
initiateColoredButtons()
In the routines that follow you may assign multiple Id by enclosing the Id in brackets separated by commas like so:{id,id,id}. If you enter {} for Id, all colored buttons will be affected. Most routines also have a corresponding routine for all ids in case you do not like using {} to denote all ids. In all cases where Id is referenced it is the Id, or Name, of the createEx button.
addCBGraphic(integer id, integer which, object graphic)
You can change the graphic and/or the disable graphic during execution of your program.
addCBXpmmerGraphic(integer id, integer which, object graphic)
You can change the graphic and/or the disable graphic during execution of your program.
assignParentBackColor(object Id, integer color)
If you move, resize or setVisible w32False your colored button and there is left at the original position and size a
box of the wrong color, coloredbuttons.ew did not locate the parent color and you must tell coloredbuttons.ew
about the color.
Note:
If you have a colored button on a Group control which does not have color and the Group is on a Window
which does have color be sure to add color to your Group control or use this routine. Eventually
coloredbuttons.ew will provide for this situation.
If you have several controls within a parent, each one will use this statement.
If all your colored buttons are on the same parent and the parent has color, you may use
assignAllParentBackColor(integer color)
Following are routines to manage and manipulate colored buttons.
changeBorderThickness(object Id, integer thickness)
changeAllBorderThickness(integer thicknessX)
This routine is the same as above, except works for all colored buttons.
changeCBColor(object Id, integer buttonState, integer color)
changeAllCBColor(integer buttonState, integer color)
This routine is the same as above, except works for all colored buttons.
changeCBTextColor(object Id, integer buttonState, integer color)
changeAllCBTextColor(integer color)
This routine is the same as above, except works for all colored buttons.
centerVerticallyCBText(object Id, integer how)
centerAllVerticallyCBText(object Id, integer how)
This routine is the same as above, except works for all colored buttons.
moveCBCaption(object Id, integer placement)
Note:
Right placement allows room for caption to move when button is pressed.
When placement is 3 and there is not room for the entire graphic to show when positioned at left, it is forced to show. Same rule
applies to right side. This means if your caption is long it might have a portion overlayed by the graphic.
moveAllCBCaption(integer placement)
This routine is the same as above, except works for all colored buttons.
changeCBCaption(object Id, sequence newCaption)
changeAllCBCaption(sequence newCaption)
This routine is the same as above, except works for all colored buttons.
multilineCBCaption(object Id, integer how)
multilineAllCBCaption(integer how)
This routine is the same as above, except works for all colored buttons.
showCBCaption(object Id, integer showStatus
showAllCBCaption(integer whereIs)
This routine is the same as above, except works for all colored buttons.
moveCBGraphic(object Id, integer position)
Note:
Right placement allows room for graphic to move when button is pressed.
moveAllCBGraphic(integer position)
This routine is the same as above, except works for all colored buttons.
setCBHint(object Id, sequence hint)
Note:
Hint will be obtained from the actual CreateEx button. You may use this routine when
you want to change the hint while your program is running.
setAllCBHint(sequence hint)
This routine is the same as above, except works for all colored buttons.
setCBFont(object Id, sequence facename, integer pts, integer attribute)
Note:
Font will be obtained from the actual CreateEx button. You may use this routine when
you want to change the font while your program is running.
setAllCBFont(sequence facename, integer pts, integer attribute)
This routine is the same as above, except works for all colored buttons.
setCBDefaultFont(object Id)
setAllCBDefaultCBFont()
This routine is the same as above, except works for all colored buttons.
changeCBClass(object Id, sequence newclass)
changeAllCBClass(sequence newclass)
This routine is the same as above, except works for all colored buttons.
setNonGrayDisable(object Id, integer state)
state is w32True to disable and w32False to enable
The disabled state does not have a gray-ed out caption.
setCBFocus(object Id)
The routine will issue a setFocus for Id.
changeCBButtonType(object Id, sequence style, integer corner size)
changeAllCBButtonType(sequence style, integer corner size)
This routine is the same as above, except works for all colored buttons.
setCBFontAngle(object Id, integer angle)
setAllCBFontAngle(integer angle)
Same as above except works for all colored buttons.
forceCBPaint(object Id)
This routine is used only in the event you need to code something that affects the
colored button such that a w32HPaint event needs to be invoked.
Examples would be using setVisible, setEnable, setCheck
ColoredButtons.ew can access w32HEvent and w32HLostFocus handlers for the createEx'd button as well as setRect, isVisible and isEnabled statements. use setCBFocus( button id) instead of setFocus. Internally w32HPaint and w32HMouse handlers are used.
Using your own routines to manipulate colored buttons
This is the way you would set a button visible/invisible.
procedure setButtonVisible(integer id, integer state)
setVisible(id, state)
forceCBPaint(id)
end procedure