Here are 4 classes I wrote and/or compiled to help in making Outlook style buttons. I really didn't have any purpose in writing these classes, I just did it because I wanted to experiment with the canvas object in Realbasic. Well, the buttons turned out better then I thought they would, so I made them public. This code is freely updateable, in fact, I encourage you to update the code base. If you do improve the code, please email me the project file with comments where necessary. This project is about making the best and easiest buttons possible for as many people as possible!
Programming:
I made the methods as "open" as possible and will continue to do so. Users have to define the properties of the buttons in an Open method. If you look at the sample project you'll figure it out faster then reading the following...
Universal Properties:
textFont (buttonTextFont in CBetterPopupMenu)
me.textFont = "System"
- sets the font on the button.
textSize (buttonTextFont in CBetterPopupMenu)
me.textSize = 12
- sets the size of the font on the button .
caption
me.caption = "Button Text Here"
- sets the text that appears on the button.
autoCenterV
me.autoCenterV = true
- If true, the button will center the text/graphics vertically regardless of size.
If false, it will place the text/graphics in the default location.
state
me.state = 0
- the state of the button on open (usually 0), only has to be set on open.
0 is the normal state.
1 is up state.
2 is down state.
Universal Methods:
getSWidth()
me.width = me.getSWidth()
- gets the suggested width of the button, returns an integer.
- can be used to set the width of the button at runtime, or used to msgbox the width of the button so that it can be set in the IDE.
action()
- write the code you want fired on the action of the button here (except in the CBetterPopupMenu).
Buttons with Pictures Properties:
ResIconID
me.resIconID = 3000
- sets the icon for the button, must be a CICN resource
Button with Menu Properties:
TextFont
me.TextFont = "Geneva"
- sets the font of the menu
TextSize
me.TextSize = 9
- sets the size of the font in the menu
** All other methods in the CBetterPopupMenu Documentation **
** Contact Fabian Lidman regarding the CBetterPopupMenu (I only did the look of the button) **
_____________________________
Credit Where Credit is Due:
If you decide to use this code I ask two things. First, email me and tell me that you're using the classes. And second, please give Fabian and Me some credit if you use any of our code. I worked hard on these and I don't think that's too much to ask, is it? In your read me file or about window (if you use them) just write something like: "MS Style Button Classes by: Will Cosgrove, http://www.public.iastate.edu/~cosy". If you use the CBetterPopupMenu please also credit Fabian Lidman. Thanks!
Contact:
If you have any questions or comments feel free to write me at wcosgrov@nwciowa.edu.
Special Thanks:
Fabian Lidman - Menu Handling Code (CBetterPopupMenu 1.5)
http://www.kagi.com/fabian/
Other Code Contributors:
Jacob Lauritzen, Scott Crick, Matt Ridley
Known Issues:
On the action command you may not fire the window.close() method, this will cause RB to crash. If you want to close the window using an MSButton you have to use the CloseMSButton subclass and change it's super to the correct button style you are using. Then uncomment all the code in the mouseup event that starts with "//." After that, change the canvas' super to the subclass. Got all that?
Version History
2.1
by Will Cosgrove, Matt Ridley
- Changed icons to CICN resources and now handle the drawing of enabled, disabled, and normal states of the icon within the button classes. Original code by Fabin Lidman, modified by Matt Ridley and Me.
- Changed the CBetterPopupMenu's down arrow to be draw within the class instead of using a resource. Now is theme savvy.
- Fixed button text variables in the CBetterPopup class that I missed from the last update, oops.
2.0
By Will Cosgrove
- Reworked MS buttons to be THEME and scheme savvy. Happy times are here at last! =)
Notes:
- In systems under 8.5 the buttons will draw as if they were under Platinum with the standard RB fillColor. Feel free to add support for systems below 8.0 in the StandardColor() methods.
- As an added bonus, I believe all the color system calls being made in MSButtons are Carbon compliant.
- The button's backdrop is still a solid color, but it's theme savvy. I'm working on getting this fixed, but any help would be great.
- I one-upped MS and also made the MSCanvas savvy.
- Feel free to use the color variables in the method setColor() in the rest of your project, if applicable.
- Implemented Fabian's CBetterPopupMenu 1.5.
- In the CBetterPopupMenu the properties for the button text is now buttonText*, and the properties for the menu are Text*. The reason for the change: I didn't feel like going through all Fabian's code and changing his variables again.
- Minor line drawing inaccuracy fixed.
1.6
By Will Cosgrove
- Made MS button classes Kaleidoscope savvy (except for the disabled text, any ideas on that, let me know).
Notes:
- The buttons aren't quite as accurate, but they look a lot better with kaleidoscope running. I thought it was a decent trade-off.
- RB color calls aren't Apperance Manager savvy . =\ Hopefully they will fix that soon!
- RB's textColor call isn't correct, I'm not sure where they get it from, but on some schemes the color isn't right.
- FYI: The MS Settings button is not savvy because frankly...it has no hope because it's so nonstandard.
- Implemented Fabian's CBetterPopupMenu 1.2, fixes a menu bug.
- Added a CloseMSButton subclass. You can now close the parent window with the CloseMSButton (see know issues above).
- changed the cursor to nil when exiting buttons
- Various minor code tweaks.
1.5
by Will Cosgrove, Jacob Lauritzen, Scott Crick
- Arranged the code in a more object oriented way, opimized code.
- Corrected the MS Settings button colors, doh! And other Settings button stuff.
- Added a MS/Palm style dialog box for all to enjoy.
- Added the action() method, this method is fired on the action of the button.
- Changed the devStringWidth() method to the getSWidth() method and it now returns an int instead of void.
- The getSWidth() now returns the correct value if there is no caption on the button.
- Changed the button's text variable to caption, to better conform to...something....
- Added the ability to have the buttons be any size and draw correctly.
- Added the ability to have any size picture in the button and draw correctly.
- Added the ability to use any font.
- Added the ability to use any font size.
- Buttons now draw off-screen before being drawn on the canvas to reduce flicker.
- Modified Fabian Lidman's CBetterPopupMenu to look like a MS button and included it in the project.
1.01
by Will Cosgrove
- Fixed a bug that would cause the buttons not to enabled correctly.