Home   Notes   Contact Me

Fox Toolkit

Local

External


Strings

// string compare is not part of the class, but global operator== stuff: friend FXAPI FXint compare(const FXchar* s1,const FXchar* s2); // and case insensitive is like this: friend FXAPI FXint comparecase(const FXchar* s1,const FXchar* s2); // There are a ton of variants // string length is part of the class, but it is easy to miss it because: // Length of text in bytes FXint length() const { return *(((FXint*)str)-1); } // Change the length of the string to len void length(FXint len);

Checkbox check

Use getState() to determine if a check box is checked or not.


Dialog Window, how to close it externally

// One way of doing it: m_pDialog->handle(m_pDialog,FXSEL(SEL_COMMAND,FXDialogBox::ID_CANCEL),NULL); // Another method: getApp()->stopModal(m_pDialog,FALSE); m_pDialog->hide();

Event Routing


Redraw now

To make a widget redraw immediately (from within the GUI thread), just call its repaint() method.

To resize it immediately do a layout().

So you may need to change the widgets text then, relayout it parent, then redraw the parent to make it all look correct


FXMatrix


Asynchronously sending events to the GUI thread

Method 3

NOTE this for fox 1.7 (probably)

FOX assumes one single thread to be responsible for the User Interface related tasks. This is because certain FOX resources are not thread-safe; also, because on MS-Windows message queues from a window are tied to the thread that created that window, it is very important for portability reasons that it is always the same thread performing the User Interface tasks. You can however use any number of threads in your application, as long as they are worker threads, i.e. they do not perform User Interface functions. Synchronization between the User Interface thread and the worker threads can be performed using a synchronization object, a pipe (UNIX/LINUX) or an event object (MS-Windows). The synchronization object is passed to FXApp::addInput() so that the User Interface thread is awakened when the worker thread turns the synchronization object into a signalled state. In the more recent FOX versions (FOX 1.7 and newer), a facility has been implemented called FXMessageChannel to make this easier. Using FXMessageChannel, a worker thread can send an asynchronous message to the GUI thread, causing it to wake up and dispatch to a handler in order to process a message on the worker thread's behalf. (Older versions of FOX used FXGUISignal, which is a more limited form of this facility).

Method 2

#include <iostream> #include <fx.h> class MainWindow : public FXMainWindow { public: enum{ ID_WORK_STEP = FXMainWindow::ID_LAST, }; FXDECLARE(MainWindow); FXGUISignal guisignal; class Work : public FXThread { FXGUISignal *sg; public: Work(FXGUISignal *in_sg=NULL){sg=in_sg;}; int run(){ for(int i=0; i<10; i++) { fxsleep(500000); sg->signal(); }; return 0; }; }; Work workThread; public: MainWindow(FXApp* app) : FXMainWindow(app, ""), guisignal(app, this, ID_WORK_STEP), workThread(&guisignal) { }; MainWindow() : guisignal(getApp()) { }; ~MainWindow(){}; void create(){ FXMainWindow::create(); show(PLACEMENT_SCREEN); workThread.start(); }; long onWorkStepSignal(FXObject*, FXSelector, void*) { std::cout << "signal from thread 1" << std::endl; return 1; }; }; FXDEFMAP(MainWindow) MainWindowMap[]={ FXMAPFUNC(SEL_IO_READ, MainWindow::ID_WORK_STEP, MainWindow::onWorkStepSignal), }; FXIMPLEMENT(MainWindow, FXMainWindow, MainWindowMap, ARRAYNUMBER(MainWindowMap)); int main(int argc, char *argv[]) { FXApp app; app.init(argc,argv); MainWindow mw(&app); app.create(); return app.run(); }

Method 1

// Define an enum'd event ID something like this:
ID_EVENT_QUEUED_FROM_OTHER_THREAD

// Connect it to a handler
FXDEFMAP(MyApp) MyAppMap[]={
	...
	FXMAPFUNC( SEL_IO_READ, ID_EVENT_QUEUED_FROM_OTHER_THREAD, onCommand),
	...
};

// After you make the application associate a signal with the event:
	app->addInput( HandleSignal, INPUT_READ, this, ID_EVENT_QUEUED_FROM_OTHER_THREAD);

// When the signal is set it will call the handler in the GUI thread
onCommand

Classes


FXFoldingList

MethodDescription
void clearItems( FXbool notify = 0)Empties the tree

Iterating through leaves

void ParseTree( SGFXLayersCallback *callback, FXTreeItem *item )
{
	if (!item)
		return;
		
	while(item) {
		/* Do something with the item */
		callback->Callback( this, _tree, item );
		/* Traverse Children */
		ParseTree( callback, item->getFirst() );
		/* Get the next item */
		item=item->getNext();
	}
}

ParseTree( callback, m_tree->getFirst() );

Placement of Windows and Dialogs

Specify a placement type when you show() or execute() the window or dialog.

ValueDescription
PLACEMENT_DEFAULTPlace it at the default size and location
PLACEMENT_VISIBLEPlace window to be fully visible
PLACEMENT_CURSORPlace it under the cursor position
DEFAULT for execute()
PLACEMENT_OWNERPlace it centered on its owner
PLACEMENT_SCREENPlace it centered on the screen
PLACEMENT_MAXIMIZEDPlace it maximized to the screen size

Popup Menu

(Also known as: context menu, right button menu)

// Connect it to something (like Right mouse button)
FXDEFMAP(SessionPane) SessionPaneMap[]={
	...
	FXMAPFUNC( SEL_RIGHTBUTTONPRESS,	SessionPane::ID_LIST_SESSIONS,	SessionPane::showContextMenu),
	...
};

long SessionPane::showContextMenu( FXObject* sender, FXSelector sel, void *ptr)
{
	FXEvent* event= (FXEvent*)ptr;
	FXMenuPane *pPopupMenu = new FXMenuPane(this);

	new FXMenuCommand( pPopupMenu, "Hide this message type", NULL, this, ID_HIDE_MESSAGE_TYPE);
	new FXMenuSeparator( pPopupMenu, LAYOUT_FILL_X );

	pPopupMenu->create();
	pPopupMenu->popup(NULL, event->root_x,event->root_y);
	getApp()->runModalWhileShown(pPopupMenu);

	delete pPopupMenu;

	return 1;
}

Example Dialog Window

The Class

class ExampleDialog : public FXDialogBox
{
private:
	FXDECLARE(ExampleDialog)
	ExampleDialog() {}

public:
	ExampleDialog( FXApp *pOwner);
	~ExampleDialog(void) {}
};

FXDEFMAP(ExampleDialog) ExampleDialogMap[] = { 0 };
FXIMPLEMENT(ExampleDialog,FXDialogBox,ExampleDialogMap,ARRAYNUMBER(ExampleDialogMap))

ExampleDialog::ExampleDialog( FXApp *pOwner)
: FXDialogBox( pOwner, "Choose Run Mode", DECOR_ALL)
{
	new FXLabel( this, "Text");
	new FXButton( this, "Button");

	FXList *pList;
	pList = new FXList( this, 0, 0, LIST_NORMAL | LAYOUT_FILL_X);

	pList->appendItem( "item 1");
	pList->appendItem( "item 2");

	FXComposite *pFrame;
	pFrame = new FXHorizontalFrame( this);

	new FXButton( pFrame, "Okay", 0, this, ID_ACCEPT);
	new FXButton( pFrame, "Cancel", 0, this, ID_CANCEL);

	create();
}

Running it

	ExampleDialog dialog( foxAppPointer);
	
	// Modal:
	if ( dialog.execute()) {
	    // Okay was clicked
	} else {
	    // Dialog was cancelled
	}
	
	// Nonmodal:
	dialog.show();

Dynamically changing GUI


Subclassing

  1. You Must FXDECLARE the derived class
  2. You Must have a no parameter constructor ( it is used by serialization )
  3. You Must make an FXDEFMAP
  4. You Must FXIMPLEMENT

Subclass Example:

class SessionPane : public FXVerticalFrame
{
private:
	// You Must FXDECLARE the derived class:
	FXDECLARE(SessionPane);

	// You Must have a no parameter constructor ( it is used by serialization )
protected:
	SessionPane() {};

// Your other stuff goes here	
}

FXDEFMAP(SessionPane) SessionPaneMap[]={
	0
};

FXIMPLEMENT(SessionPane,FXVerticalFrame,SessionPaneMap,ARRAYNUMBER(SessionPaneMap))

FXList

Contains

appendItem FXint appendItem(FXListItem* item,FXbool notify=FALSE)
FXint appendItem(const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE)
clearItemsvoid FXList::clearItems(FXbool notify)
findItemFXint findItem(const FXString& text,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const;
findItemByDataFXint findItemByData(const void *ptr,FXint start=-1,FXuint flags=SEARCH_FORWARD|SEARCH_WRAP) const
getCurrentItemFXint getCurrentItem()
Returns the index of the top most selected item, returns 0 if nothing is selected (which is the same as if the first item is selected)
getCursorItemFXint getCursorItem()
Returns the index of the item under the mouse pointer. returns -1 if the mouse is not over an item
getItemFXListItem* getItem( FXint index)
getItemTextFXString getItemText(FXint index) const
getNumItemsFXint getNumItems() const
insertItemFXint insertItem(FXint index,FXListItem* item,FXbool notify=FALSE);
FXint insertItem(FXint index,const FXString& text,FXIcon *icon=NULL,void* ptr=NULL,FXbool notify=FALSE);
isItemSelectedFXBool isItemSelected( FXint index)
Returns true if the item is selected.
killSelectionvoid killSelection()
Deselects all
removeItemvoid removeItem(FXint index,FXbool notify)

Does Not Contain:


Widgets

WidgetEventsSelected Methods
FXButtonSEL_COMMANDFXuint getState() const
FXCheckButtonSetCheck( FXbool isChecked = true)
FXbool getCheck()
FXComboBoxvoid clearItems()
FXint appendItem(const FXString& text,void* ptr=NULL)
FXMatrix
FXSpinnervoid setValue(FXint value)
FXSpinner(FXComposite *p,FXint cols,FXObject *tgt=NULL,FXSelector sel=0,FXuint opts=SPIN_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=DEFAULT_PAD,FXint pr=DEFAULT_PAD,FXint pt=DEFAULT_PAD,FXint pb=DEFAULT_PAD);
FXTextFieldFXString getText() const

Message Maps

FXDEFMAP( class ) arbitraryUniqueNameOfMap[] = {
	// Single Message Handler
	FXMAPFUNC( messageType, messageId, handlerMethod)
	FXMAPFUNCS( messageType, lowestMessageId, highestMessageId, handlerMethod )
};
FXIMPLEMENT

handlerMethod

long handlerMethod( FXObject *pObj, FXSelector sel, void *???);
// pObj is the Source of the event (usually a Widget)
// FXSELID(sel) is the ID of the event that caused the handler to be called

messageType

messageTypeDescription
SEL_NONE
SEL_KEYPRESSKey pressed
SEL_KEYRELEASEKey released
SEL_LEFTBUTTONPRESSLeft mouse button pressed
SEL_LEFTBUTTONRELEASELeft mouse button released
SEL_MIDDLEBUTTONPRESSMiddle mouse button pressed
SEL_MIDDLEBUTTONRELEASEMiddle mouse button released
SEL_RIGHTBUTTONPRESSRight mouse button pressed
SEL_RIGHTBUTTONRELEASERight mouse button released
SEL_MOTIONMouse motion
SEL_ENTERMouse entered window
SEL_LEAVEMouse left window
SEL_FOCUSINFocus into window
SEL_FOCUSOUTFocus out of window
SEL_KEYMAP
SEL_UNGRABBEDLost the grab (Windows)
SEL_PAINTMust repaint window
SEL_CREATE
SEL_DESTROY
SEL_UNMAP
SEL_MAP
SEL_CONFIGUREresize
SEL_SELECTION_LOSTWidget lost selection
SEL_SELECTION_GAINEDWidget gained selection
SEL_SELECTION_REQUESTInquire selection data
SEL_RAISEDWindow to top of stack
SEL_LOWEREDWindow to bottom of stack
SEL_CLOSEClose window
SEL_DELETEDelete window
SEL_MINIMIZEIconified
SEL_RESTORENo longer iconified or maximized
SEL_MAXIMIZEMaximized
SEL_UPDATEGUI update
SEL_COMMANDGUI command
SEL_CLICKEDClicked
SEL_DOUBLECLICKEDDouble-clicked
SEL_TRIPLECLICKEDTriple-clicked
SEL_MOUSEWHEELMouse wheel
SEL_CHANGEDGUI has changed
SEL_VERIFYVerify change
SEL_DESELECTEDDeselected
SEL_SELECTEDSelected
SEL_INSERTEDInserted
SEL_REPLACEDReplaced
SEL_DELETEDDeleted
SEL_OPENEDOpened
SEL_CLOSEDClosed
SEL_EXPANDEDExpanded
SEL_COLLAPSEDCollapsed
SEL_BEGINDRAGStart a drag
SEL_ENDDRAGEnd a drag
SEL_DRAGGEDDragged
SEL_LASSOEDLassoed
SEL_TIMEOUTTimeout occurred
SEL_SIGNALSignal received
SEL_CLIPBOARD_LOSTWidget lost clipboard
SEL_CLIPBOARD_GAINEDWidget gained clipboard
SEL_CLIPBOARD_REQUESTInquire clipboard data
SEL_CHOREBackground chore
SEL_FOCUS_SELFFocus on widget itself
SEL_FOCUS_RIGHTFocus movements
SEL_FOCUS_LEFT
SEL_FOCUS_DOWN
SEL_FOCUS_UP
SEL_FOCUS_NEXT
SEL_FOCUS_PREV
SEL_DND_ENTERDrag action entering potential drop target
SEL_DND_LEAVEDrag action leaving potential drop target
SEL_DND_DROPDrop on drop target
SEL_DND_MOTIONDrag position changed over potential drop target
SEL_DND_REQUESTInquire drag and drop data
SEL_IO_READRead activity on a pipe
SEL_IO_WRITEWrite activity on a pipe
SEL_IO_EXCEPTExcept activity on a pipe
SEL_PICKEDPicked some location
SEL_QUERY_TIPMessage inquiring about tooltip
SEL_QUERY_HELPMessage inquiring about statusline help
SEL_LAST