Sourceforge.net - The VCF's Project Host
   The VCF Website Home   |   Online Discussion Forums   |   Sourceforge.net Project Page   

6.8. ApplicationKit

6.8.1. What kinds of controls(or widgets) are there in the VCF?
6.8.2. How do I create a Timer ?
6.8.3. What is the bare minimum necessary to create a new control ?
6.8.4. What's the difference between a heavyweight and lightweight control ?
6.8.5. How do I override events on my control ?
6.8.6. How do I trap mouse events for my custom control ?
6.8.7. What method do I override to draw or paint the control ?
6.8.8. How do I make a window visible or show up?
6.8.9. How do I close a window?
6.8.10. How do I delete the memory for a Window or Dialog instance that I created ?
6.8.11. Can existing controls be customized?
6.8.12. How do add owner draw support to menu items?
6.8.13. Can I use threads in my GUI built with the ApplicationKit? If so what's the best way to do this?
6.8.14. Can I change the parent of a control at runtime?
6.8.15. How do I set the position of a Control? What about the width and/or height?
6.8.16. How do I add a context menu?
6.8.17. How can I send an event asynchronously to an event handler? Is there some equivalent to Window's PostMessage?
6.8.18. How do I add a menu bar and menu items?
6.8.19. How do I create and display a modal dialog?
6.8.20. How do I show a message in a modal dialog, such as an error message?
6.8.21. How do I tell what the top level window it?
6.8.22. How to I get my control to refresh?
6.8.23. How do I make a control disabled (or enabled)? How do I tell if it's already enabled?
6.8.24. How do I make a floating top level window apear with no borders or caption/title bar (like a splash screen)?
6.8.25. How do I set the focus to a particular control? How do I tell which control is currently focused?
6.8.26. How do I support drag and drop?
6.8.27. How do I change the cursor of a Control?
6.8.28. How do I add support for hot key combinations (like Ctrl+"C")?
6.8.29. How do I add scrolling support for a control?
6.8.30. Can I make my own cursor? If so how?
6.8.31. What's the difference bewteen a Component, Control, Frame, Dialog and Window?
6.8.32. How do I make a control keep all the mouse events? Is there something analgous to Win32's ::SetCapture GTK's gdk_pointer_grab()?
6.8.1.

What kinds of controls(or widgets) are there in the VCF?

A pretty wide variety. Most of the common, standard controls like edit boxs (referred to as a TextControl in the VCF), tree controls, list controls, table controls, toolbars, tab controls, and so on. For a more comprehensive listing see Controls listing in the ApplicationKit section.

6.8.2.

How do I create a Timer ?

Create an instance of a time component, add an event handler to it's TimerPulse delegate. This will be fired for each timer event that occurs. You can set the frequency of the timer event by passing in a millisecond value to TimerComponent::setTimeoutInterval (). To activate the timer you need to call the TimerComponent::setActivated() function and pass in true. For example:

		
//if you don't pass in an owner here in the 
//you need to add the timer as a component 
somewhere else
TimerComponent* timer = new TimerComponent( /*some component owner*/ ); 
timer->TimerPulse += 
	new GenericEventHandler<SomeClass>( this, &SomeClass::myTimerRoutine, "myTimerRoutine" );
timer->setTimeoutInterval( 100 );
timer->setActivated( true ); //timer will start - SomeClass::myTimerRoutine will get called every 100 ms

				

6.8.3.

What is the bare minimum necessary to create a new control ?

You simply need to create a new instance, set it's bounds, and add it to a parent. For example:

				
Control* parent = //get some parent control or window
TextControl* textCtrl = new TextControl();
textCtrl->setBounds( 10, 20, 100, 25 );
parent->getContainer()->add( textCtrl );
				

6.8.4.

What's the difference between a heavyweight and lightweight control ?

The basic idea to understand is that a heavy weight control represents a full native windowing system control, and thus it has it's own set of resources (as specificed by the underlying windowing system). In Win32 terms, this means that each heavyweight control has an HWND and HDC associated with it (as would any window that you create in Win32). In linux systems that use GTK, this mean that each heavyweight control has it's own GtkWidget (and it's associated GdkWindow handle). Thus heavyweight controls receive user interface events directly from the windowing systems, where they are caught by the VCF peer implementation(s), translated into VCF event's and then dispatched to the VCF control. In contrast, lightweight controls do NOT have their own windowing system control resources. Instead they share these resources with the first heavyweight parent that contains the lightweight control. The VCF takes care of simulating events to lightweight controls, so from the perspective of the developer, the difference is basically non-existant.

6.8.5.

How do I override events on my control ?

Depending on the event you can either override the virtual method, or add an event handler to the event's delegate. For example, if you want to customize mouse handling on a control, you can override the Control::mouseDown() or Control::mouseMove, etc functions.

6.8.6.

How do I trap mouse events for my custom control ?

If you want to ensure that your control continues to receive events after the cursor has moved beyond it's bounds, then you need to call Control::keepMouseEvents(). When you're ready to relinquish control then you must call Control::releaseMouseEvents(). As a rule it's best to call the former during a mouse down event, and the latter during a mouse up.

6.8.7.

What method do I override to draw or paint the control ?

Override the control's paint() method. You will be passed in a GraphicsContext that you can then paint on.

6.8.8.

How do I make a window visible or show up?

Call Window::show() or Control::setVisible( true ). The former is the preferred way to do this.

6.8.9.

How do I close a window?

Call the Window::close() function.

6.8.10.

How do I delete the memory for a Window or Dialog instance that I created ?

You don't. It's deleted for you automatically. If you create a Window on the heap (which you should), do not delete it! You'll end up with double delete errors and crash your program at runtime.

6.8.11.

Can existing controls be customized?

Yes. Simply create a new class and derive from the control you're interested in. Alternately you can simply add event handler's to the delegates you're interested in and acheive most of yoru customization this way.

6.8.12.

How do add owner draw support to menu items?

Create a new menu item class and derive from DefaultMenuItem and add in custom paint methods.

6.8.13.

Can I use threads in my GUI built with the ApplicationKit? If so what's the best way to do this?

Yes. Create threads to do a chunk of work, and then communicate the results back to the main UI thread through the UIToolkit's postEvent function. See the vcf/examples/ThreadsInGUI example for more information about this. Also see ApplicationKit's Posting Events section.

6.8.14.

Can I change the parent of a control at runtime?

Yes. You can simply add the control to a new container, and the control will be removed form it's old container and parent, and added to it's new one.

6.8.15.

How do I set the position of a Control? What about the width and/or height?

Call the control's Control::setBounds(). Alternately you can set each of the individual value separately by calling Control::setLeft(), Control::setTop(), Control::setWidth() or Control::setHeight().

6.8.16.

How do I add a context menu?

Create a PopupMenu instance, populate it, and then set the control's popup menu by calling Control::setPopupMenu(). For example:

				
Control* someControl = //get a control
PopupMenu* contextMenu = new PopupMenu(someControl); //sets the popup menu's owner
MenuItem* root = contextMenu->getRootMenuItem();
DefaultMenuItem* pmItem1 = new DefaultMenuItem( "Hello", root,contextMenu );
DefaultMenuItem* pmItem2 = new DefaultMenuItem( "There!", root,contextMenu );
someControl->setPopupMenu( contextMenu );
				

When the control detects a context menu mouse event, it will popup the popup menu you've assigned it.

6.8.17.

How can I send an event asynchronously to an event handler? Is there some equivalent to Window's PostMessage?

Use the UIToolkit's postEvent() function. This is the VCF's equivalent to Windows PostMessage(). See the ApplicationKit's Posting Events section for more information about how to do this.

6.8.18.

How do I add a menu bar and menu items?

An answer.

6.8.19.

How do I create and display a modal dialog?

An answer.

6.8.20.

How do I show a message in a modal dialog, such as an error message?

An answer.

6.8.21.

How do I tell what the top level window it?

An answer.

6.8.22.

How to I get my control to refresh?

Call the control's repaint() method.

6.8.23.

How do I make a control disabled (or enabled)? How do I tell if it's already enabled?

You can enable/disable the control by calling the control's Control::setEnabled() function and pass in true or false. Passing in true will enable the control, passing false will disable it. You can determine if it's alread enabled or not by calling the control's Control::isEnabled() function.

6.8.24.

How do I make a floating top level window apear with no borders or caption/title bar (like a splash screen)?

Set the frame's framestyle and whether or not it's the topmost frame. You do this by calling Frame::setFrameStyle() with a style of fstNoBorderFixed. See the ApplicationKit's Frame Usage section for more on this. You then set the frame as topmost by call the frame's Frame::setFrameTopmost( true );

6.8.25.

How do I set the focus to a particular control? How do I tell which control is currently focused?

Call the control's Control::setFocused(). You can determine the currently focused control by calling the static Control::getCurrentFocusedControl().

6.8.26.

How do I support drag and drop?

An answer.

6.8.27.

How do I change the cursor of a Control?

An answer.

6.8.28.

How do I add support for hot key combinations (like Ctrl+"C")?

An answer.

6.8.29.

How do I add scrolling support for a control?

An answer.

6.8.30.

Can I make my own cursor? If so how?

An answer.

6.8.31.

What's the difference bewteen a Component, Control, Frame, Dialog and Window?

An answer.

6.8.32.

How do I make a control keep all the mouse events? Is there something analgous to Win32's ::SetCapture GTK's gdk_pointer_grab()?

An answer.

6.8.1. MVC

6.8.1.1. How do I create a View?
6.8.1.2. Does my custom View have to derive from VCF::Object?
6.8.1.3. How do I add my view to a model?
6.8.1.4. Where do I get the Model from?
6.8.1.5. What kind of Model should I create?
6.8.1.6. Are there default implementations to use when creating models or view? Is there a preferred model class to create or use or derive from? What about for a View?
6.8.1.7. What are Items?
6.8.1.8. Is an Item a View?
6.8.1.9. Can a control have more than one View?
6.8.1.10. Can a View have child views?
6.8.1.11. How do I subscribe to a Model's change notification?
6.8.1.12. Can I do this if I'm a View?
6.8.1.13. I need to modify my model's data from multiple threads, can I do this? What's the best way? Are there patterns to use?
6.8.1.1.

How do I create a View?

An answer.

6.8.1.2.

Does my custom View have to derive from VCF::Object?

An answer.

6.8.1.3.

How do I add my view to a model?

An answer.

6.8.1.4.

Where do I get the Model from?

An answer.

6.8.1.5.

What kind of Model should I create?

An answer.

6.8.1.6.

Are there default implementations to use when creating models or view? Is there a preferred model class to create or use or derive from? What about for a View?

An answer.

6.8.1.7.

What are Items?

An answer.

6.8.1.8.

Is an Item a View?

An answer.

6.8.1.9.

Can a control have more than one View?

An answer.

6.8.1.10.

Can a View have child views?

An answer.

6.8.1.11.

How do I subscribe to a Model's change notification?

An answer.

6.8.1.12.

Can I do this if I'm a View?

An answer.

6.8.1.13.

I need to modify my model's data from multiple threads, can I do this? What's the best way? Are there patterns to use?

An answer.

   Comments or Suggestions?    License Information