Project

General

Profile

Buttons explanations » History » Revision 4

Revision 3 (iri, 02/22/2011 03:46 PM) → Revision 4/10 (iri, 02/22/2011 04:17 PM)

h1. Buttons explanations 

 To create any button, you should use [[Create|_gtkButtonNew]] 

 How to create them ? 

 * A simple button with a label : 

 <pre><code class="php"> 
 typeof win = ObjGtkWidget;; 
 typeof button = ObjGtkWidget;; 

 fun CBbutton (obj, uparam)= 
	 _fooS "The button has been clicked"; 
	 _fooS strcat "user param is : " uparam; 
	 0;; 
	
 fun main ()= 
	 _showconsole; 
	
	 /* Create a window ...*/ 
	 set win = ... 
	 /* Create the button :  
	 use _gtkButtonNew function with : 
	 - the channel 
	 - the parent (here a window) 
	 - the label 
	 - the flag. For a simple button, use SCOL_GTK_BUTTON_LABEL 
	 - no supplemental parameter needed, so, nil it's ok */ 
	 set button = _gtkButtonNew _channel win "My button" SCOL_GTK_BUTTON_LABEL nil; 
	 /* Define the callback  
	 use _gtkButtonCB with : 
	 - the Scol object 
	 - the reflex 
	 - any parameter at your convenience 
	 - the flag. To get the "clicked" signal, use SCOL_GTK_BUTTON_CB_CLICKED 
	 It's all*/ 
	 _gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_CLICKED; 
	 ... 
	 ;; 
 </code></pre> 

 * A button with a mnemonic : 
 A mnemonic is, by example, a keyboard shortcut 

 <pre><code class="php"> 
 fun CBbutton (obj, uparam)= 
	 _fooS "The button has been clicked"; 
	 _fooS strcat "user param is : " uparam; 
	 0;; 
	
 fun main ()= 
	 _showconsole; 
	
	 /* Create a window ...*/ 
	 set win = ... 
	 /* Create the button :  
	 - the flag. For a simple button, use SCOL_GTK_BUTTON_MNEMONIC 
	 - no supplemental parameter needed, so, nil it's ok */ 
	 set button = _gtkButtonNew _channel win "My button" SCOL_GTK_BUTTON_MNEMONIC nil; 
	 /* Define the callback  
	 - the flag. To get the "clicked" signal, use SCOL_GTK_BUTTON_CB_CLICKED */ 
	 _gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_CLICKED; 
	 ... 
	 ;; 
 </code></pre> 

 * A button with a stock item : 
 It is a same code than alabel. The name is the item. That's all. 
 To create the button, use the flag SCOL_GTK_BUTTON_STOCKITEM. 

 * A button with a link (uri) 

 <pre><code class="php"> 
 typeof win = ObjGtkWidget;; 
 typeof button = ObjGtkWidget;; 

 fun CBbutton (obj, uparam, url)= 
	 _fooS url; 
	 _fooS strcat "user param is : " uparam; 
	 0;; 
	
 fun main ()= 
	 _showconsole; 
	
	 /* Create a window ...*/ 
	 set win = ... 
	 /* Create the button :  
	 - the flag. For a simple button, use SCOL_GTK_BUTTON_LINK 
	 - set the url to the 4e argument */ 
	 set button = _gtkButtonNew _channel win "Scolring" SCOL_GTK_BUTTON_LINK "http://www.scolring.org/; 
	 /* Define the callback  
	 - the flag. To get the activate signal, use SCOL_GTK_BUTTON_CB_LINKED  
	 - the callback take one supplemental parameter : the url */ 
	 _gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_LINKED; 
	 ... 
	 ;; 
 </code></pre>