Buttons explanations » History » Version 4
iri, 02/22/2011 04:17 PM
| 1 | 1 | iri | h1. Buttons explanations |
|---|---|---|---|
| 2 | |||
| 3 | To create any button, you should use [[Create|_gtkButtonNew]] |
||
| 4 | |||
| 5 | How to create them ? |
||
| 6 | |||
| 7 | * A simple button with a label : |
||
| 8 | |||
| 9 | 2 | iri | <pre><code class="php"> |
| 10 | 1 | iri | typeof win = ObjGtkWidget;; |
| 11 | typeof button = ObjGtkWidget;; |
||
| 12 | |||
| 13 | fun CBbutton (obj, uparam)= |
||
| 14 | _fooS "The button has been clicked"; |
||
| 15 | _fooS strcat "user param is : " uparam; |
||
| 16 | 0;; |
||
| 17 | |||
| 18 | fun main ()= |
||
| 19 | _showconsole; |
||
| 20 | |||
| 21 | /* Create a window ...*/ |
||
| 22 | set win = ... |
||
| 23 | /* Create the button : |
||
| 24 | use _gtkButtonNew function with : |
||
| 25 | - the channel |
||
| 26 | - the parent (here a window) |
||
| 27 | - the label |
||
| 28 | - the flag. For a simple button, use SCOL_GTK_BUTTON_LABEL |
||
| 29 | - no supplemental parameter needed, so, nil it's ok */ |
||
| 30 | set button = _gtkButtonNew _channel win "My button" SCOL_GTK_BUTTON_LABEL nil; |
||
| 31 | /* Define the callback |
||
| 32 | use _gtkButtonCB with : |
||
| 33 | - the Scol object |
||
| 34 | - the reflex |
||
| 35 | - any parameter at your convenience |
||
| 36 | - the flag. To get the "clicked" signal, use SCOL_GTK_BUTTON_CB_CLICKED |
||
| 37 | It's all*/ |
||
| 38 | _gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_CLICKED; |
||
| 39 | ... |
||
| 40 | ;; |
||
| 41 | </code></pre> |
||
| 42 | 3 | iri | |
| 43 | * A button with a mnemonic : |
||
| 44 | A mnemonic is, by example, a keyboard shortcut |
||
| 45 | |||
| 46 | <pre><code class="php"> |
||
| 47 | fun CBbutton (obj, uparam)= |
||
| 48 | _fooS "The button has been clicked"; |
||
| 49 | _fooS strcat "user param is : " uparam; |
||
| 50 | 0;; |
||
| 51 | |||
| 52 | fun main ()= |
||
| 53 | _showconsole; |
||
| 54 | |||
| 55 | /* Create a window ...*/ |
||
| 56 | set win = ... |
||
| 57 | /* Create the button : |
||
| 58 | - the flag. For a simple button, use SCOL_GTK_BUTTON_MNEMONIC |
||
| 59 | - no supplemental parameter needed, so, nil it's ok */ |
||
| 60 | set button = _gtkButtonNew _channel win "My button" SCOL_GTK_BUTTON_MNEMONIC nil; |
||
| 61 | /* Define the callback |
||
| 62 | - the flag. To get the "clicked" signal, use SCOL_GTK_BUTTON_CB_CLICKED */ |
||
| 63 | _gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_CLICKED; |
||
| 64 | ... |
||
| 65 | ;; |
||
| 66 | </code></pre> |
||
| 67 | 4 | iri | |
| 68 | * A button with a stock item : |
||
| 69 | It is a same code than alabel. The name is the item. That's all. |
||
| 70 | To create the button, use the flag SCOL_GTK_BUTTON_STOCKITEM. |
||
| 71 | |||
| 72 | * A button with a link (uri) |
||
| 73 | |||
| 74 | <pre><code class="php"> |
||
| 75 | typeof win = ObjGtkWidget;; |
||
| 76 | typeof button = ObjGtkWidget;; |
||
| 77 | |||
| 78 | fun CBbutton (obj, uparam, url)= |
||
| 79 | _fooS url; |
||
| 80 | _fooS strcat "user param is : " uparam; |
||
| 81 | 0;; |
||
| 82 | |||
| 83 | fun main ()= |
||
| 84 | _showconsole; |
||
| 85 | |||
| 86 | /* Create a window ...*/ |
||
| 87 | set win = ... |
||
| 88 | /* Create the button : |
||
| 89 | - the flag. For a simple button, use SCOL_GTK_BUTTON_LINK |
||
| 90 | - set the url to the 4e argument */ |
||
| 91 | set button = _gtkButtonNew _channel win "Scolring" SCOL_GTK_BUTTON_LINK "http://www.scolring.org/; |
||
| 92 | /* Define the callback |
||
| 93 | - the flag. To get the activate signal, use SCOL_GTK_BUTTON_CB_LINKED |
||
| 94 | - the callback take one supplemental parameter : the url */ |
||
| 95 | _gtkButtonCB button @CBbutton "yes !" SCOL_GTK_BUTTON_CB_LINKED; |
||
| 96 | ... |
||
| 97 | ;; |
||
| 98 | </code></pre> |