| 1 | // |
|---|
| 2 | // TxWin, Textmode Windowing Library |
|---|
| 3 | // |
|---|
| 4 | // Original code Copyright (c) 1995-2005 Fsys Software and Jan van Wijk |
|---|
| 5 | // |
|---|
| 6 | // ========================================================================== |
|---|
| 7 | // |
|---|
| 8 | // This file contains Original Code and/or Modifications of Original Code as |
|---|
| 9 | // defined in and that are subject to the GNU Lesser General Public License. |
|---|
| 10 | // You may not use this file except in compliance with the License. |
|---|
| 11 | // BY USING THIS FILE YOU AGREE TO ALL TERMS AND CONDITIONS OF THE LICENSE. |
|---|
| 12 | // A copy of the License is provided with the Original Code and Modifications, |
|---|
| 13 | // and is also available at http://www.dfsee.com/txwin/lgpl.htm |
|---|
| 14 | // |
|---|
| 15 | // This library is free software; you can redistribute it and/or modify |
|---|
| 16 | // it under the terms of the GNU Lesser General Public License as published |
|---|
| 17 | // by the Free Software Foundation; either version 2.1 of the License, |
|---|
| 18 | // or (at your option) any later version. |
|---|
| 19 | // |
|---|
| 20 | // This library is distributed in the hope that it will be useful, |
|---|
| 21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 23 | // See the GNU Lesser General Public License for more details. |
|---|
| 24 | // |
|---|
| 25 | // You should have received a copy of the GNU Lesser General Public License |
|---|
| 26 | // along with this library; (lgpl.htm) if not, write to the Free Software |
|---|
| 27 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 28 | // |
|---|
| 29 | // Questions on TxWin licensing can be directed to: txwin@fsys.nl |
|---|
| 30 | // |
|---|
| 31 | // ========================================================================== |
|---|
| 32 | // |
|---|
| 33 | // TX generic Widget collection, to be included in STD or USER dialogs |
|---|
| 34 | // |
|---|
| 35 | // Author: J. van Wijk |
|---|
| 36 | // |
|---|
| 37 | // JvW 24-01-2005 Initial version, check-boxes to be added to File-Dialog |
|---|
| 38 | |
|---|
| 39 | #include <txlib.h> // public interface |
|---|
| 40 | #include <txwpriv.h> // txwa anchor interface |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | #define TXWD_GENWIDGET 0xffff0900 // base help-id generic widget |
|---|
| 44 | #define TXGW_H_CHECKBOX 0x0001 // help offset check-boxes |
|---|
| 45 | #define TXGW_H_RADIOBUT 0x0002 // help offset radio-buttons |
|---|
| 46 | #define TXGW_H_ENTFIELD 0x0003 // help offset entry-fields |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | //- Note this is the generic help, only used when no user-defined |
|---|
| 50 | //- help-ID is supplied on the initialization of the widgets |
|---|
| 51 | //- The index is equal to the CLASS value for the control |
|---|
| 52 | static char *genwidgethelp[] = |
|---|
| 53 | { |
|---|
| 54 | "#000, Generic Widget help", |
|---|
| 55 | "", |
|---|
| 56 | " The generic widget is a set of dialog-controls that can be", |
|---|
| 57 | " included in standard dialogs (like the File-Dialog) and in", |
|---|
| 58 | " other user dialogs to enhance functionality without too much", |
|---|
| 59 | " specific codeing.", |
|---|
| 60 | "", |
|---|
| 61 | " The behaviour of the widget controls (check-boxes etc) is", |
|---|
| 62 | " largely defined by the generic-widget code, and the usage", |
|---|
| 63 | " of the contained information by the dialog (or application)." |
|---|
| 64 | "", |
|---|
| 65 | "", "", "", "", "", "", "", "", "", "", "", "", |
|---|
| 66 | "", |
|---|
| 67 | TXHELPITEM(002, "Generic Widget Static text") |
|---|
| 68 | " This is a generic Widget STATIC control", |
|---|
| 69 | "", |
|---|
| 70 | " It is OUTPUT only, so you should not have", |
|---|
| 71 | " been able to call up help on such a control :-)", |
|---|
| 72 | "", |
|---|
| 73 | TXHELPITEM(003, "Generic Widget Static line") |
|---|
| 74 | " This is a generic Widget STLINE control", |
|---|
| 75 | "", |
|---|
| 76 | " It is OUTPUT only, so you should not have", |
|---|
| 77 | " been able to call up help on such a control :-)", |
|---|
| 78 | "", |
|---|
| 79 | TXHELPITEM(005, "Generic Widget Entryfield") |
|---|
| 80 | " This is a generic Widget BUTTON control, there are 3 types:", |
|---|
| 81 | "", |
|---|
| 82 | " An entryfield is used for numeric or text input on a single line.", |
|---|
| 83 | "", |
|---|
| 84 | " For the meaning of this specific entryfield, refer to the global", |
|---|
| 85 | " help available for the whole dialog by pressing <F1> again ...", |
|---|
| 86 | "", |
|---|
| 87 | TXHELPITEM(006, "Generic Widget Texview") |
|---|
| 88 | " This is a generic Widget TEXTVIEW control", |
|---|
| 89 | "", |
|---|
| 90 | " A textview is used to display multiple lines of text, and", |
|---|
| 91 | " allows scrolling to view text that falls outside the window", |
|---|
| 92 | "", |
|---|
| 93 | " For the meaning of this specific textview, refer to the global", |
|---|
| 94 | " help available for the whole dialog by pressing <F1> again ...", |
|---|
| 95 | "", |
|---|
| 96 | TXHELPITEM(007, "Generic Widget Button") |
|---|
| 97 | " This is a generic Widget BUTTON control, there are 3 types:", |
|---|
| 98 | "", |
|---|
| 99 | " - A checkbox is used for simple ON/OFF properties in a dialog.", |
|---|
| 100 | " - A radiobutton is used in a group of ON/OFF properties", |
|---|
| 101 | " - A push-button is used to start an action", |
|---|
| 102 | "", |
|---|
| 103 | " You can toggle the value of checkbox or radiobutton by using", |
|---|
| 104 | " the SPACEBAR when it has the focus, as indicated by the cursor.", |
|---|
| 105 | "", |
|---|
| 106 | " For the meaning of this specific button, refer to the global", |
|---|
| 107 | " help available for the whole dialog by pressing <F1> again ...", |
|---|
| 108 | "", |
|---|
| 109 | TXHELPITEM(008, "Generic Widget Listbox") |
|---|
| 110 | " This is a generic Widget LISTBOX control", |
|---|
| 111 | "", |
|---|
| 112 | " A listbox is used to present a list of choices to the user", |
|---|
| 113 | " and allow one or more selections to be made.", |
|---|
| 114 | "", |
|---|
| 115 | " For the meaning of this specific listbox, refer to the global", |
|---|
| 116 | " help available for the whole dialog by pressing <F1> again ...", |
|---|
| 117 | "", |
|---|
| 118 | TXHELPITEM(999, "End of Generic Widget help") |
|---|
| 119 | "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", |
|---|
| 120 | NULL |
|---|
| 121 | }; |
|---|
| 122 | |
|---|
| 123 | /*****************************************************************************/ |
|---|
| 124 | // Initialize generic-widget data structures |
|---|
| 125 | /*****************************************************************************/ |
|---|
| 126 | BOOL txwInitGenericWidgets |
|---|
| 127 | ( |
|---|
| 128 | void |
|---|
| 129 | ) |
|---|
| 130 | { |
|---|
| 131 | BOOL rc = TRUE; // function return |
|---|
| 132 | |
|---|
| 133 | ENTER(); |
|---|
| 134 | |
|---|
| 135 | txwRegisterHelpText( TXWD_GENWIDGET, "Generic Widget help", genwidgethelp); |
|---|
| 136 | |
|---|
| 137 | BRETURN (rc); |
|---|
| 138 | } // end 'txwInitGenericWidgets' |
|---|
| 139 | /*---------------------------------------------------------------------------*/ |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | /*****************************************************************************/ |
|---|
| 143 | // Terminate all generic-widget data structures |
|---|
| 144 | /*****************************************************************************/ |
|---|
| 145 | void txwTermGenericWidgets |
|---|
| 146 | ( |
|---|
| 147 | void |
|---|
| 148 | ) |
|---|
| 149 | { |
|---|
| 150 | ENTER(); |
|---|
| 151 | |
|---|
| 152 | //- nothing to do yet |
|---|
| 153 | |
|---|
| 154 | VRETURN(); |
|---|
| 155 | } // end 'txwTermGenericWidgets' |
|---|
| 156 | /*---------------------------------------------------------------------------*/ |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | /*****************************************************************************/ |
|---|
| 160 | // Get number of lines and columns taken by a widget group |
|---|
| 161 | /*****************************************************************************/ |
|---|
| 162 | short txwWidgetSize // RET nr of lines taken |
|---|
| 163 | ( |
|---|
| 164 | TXGW_DATA *gwdata, // IN generic widget data |
|---|
| 165 | short toplines, // IN empty lines at top |
|---|
| 166 | short *hsize // OUT nr of columns taken |
|---|
| 167 | ) // or NULL if not needed |
|---|
| 168 | { |
|---|
| 169 | short rc = 0; // function return |
|---|
| 170 | short ww = 0; // nr of columns |
|---|
| 171 | |
|---|
| 172 | ENTER(); |
|---|
| 173 | |
|---|
| 174 | if (gwdata != NULL) // widget data ? |
|---|
| 175 | { |
|---|
| 176 | TXWIDGET *wg; // data for one widget |
|---|
| 177 | int w; // widget counter |
|---|
| 178 | |
|---|
| 179 | for (w = 0; w < gwdata->count; w++) // itterate over widgets |
|---|
| 180 | { |
|---|
| 181 | wg = &(gwdata->widget[w]); // widget array element |
|---|
| 182 | |
|---|
| 183 | if ((wg->flags & TXWI_DISABLED) == 0) |
|---|
| 184 | { |
|---|
| 185 | rc = max( wg->vpos + wg->vsize, rc); // find max lines |
|---|
| 186 | ww = max( wg->hpos + wg->hsize, ww); // find max columns |
|---|
| 187 | } |
|---|
| 188 | } |
|---|
| 189 | if (hsize != NULL) // columns wanted ? |
|---|
| 190 | { |
|---|
| 191 | *hsize = ww; |
|---|
| 192 | } |
|---|
| 193 | rc += toplines; |
|---|
| 194 | } |
|---|
| 195 | RETURN (rc); |
|---|
| 196 | } // end 'txwWidgetSize ' |
|---|
| 197 | /*---------------------------------------------------------------------------*/ |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | /*****************************************************************************/ |
|---|
| 201 | // Create specified controls for this Generic Widget instance |
|---|
| 202 | /*****************************************************************************/ |
|---|
| 203 | ULONG txwCreateWidgets |
|---|
| 204 | ( |
|---|
| 205 | TXWHANDLE dframe, // IN parent window (dialog) |
|---|
| 206 | TXGW_DATA *gw, // INOUT generic widget data |
|---|
| 207 | short line, // IN UL-corner lines |
|---|
| 208 | short col // IN UL-corner column |
|---|
| 209 | ) // allows multiple widget groups |
|---|
| 210 | { |
|---|
| 211 | ULONG rc = NO_ERROR; // function return |
|---|
| 212 | |
|---|
| 213 | ENTER(); |
|---|
| 214 | TRACES(("dframe:%8.8lx gw:%8.8lx\n", dframe, gw)); |
|---|
| 215 | |
|---|
| 216 | if (txwIsWindow( TXHWND_DESKTOP)) // is there a desktop ? |
|---|
| 217 | { |
|---|
| 218 | TXWINDOW window; // setup window data |
|---|
| 219 | TXWIDGET *wg; // data for one widget |
|---|
| 220 | int w; // widget counter |
|---|
| 221 | |
|---|
| 222 | for (w = 0; w < gw->count; w++) // itterate over widgets |
|---|
| 223 | { |
|---|
| 224 | wg = &(gw->widget[w]); // widget array element |
|---|
| 225 | |
|---|
| 226 | if ((wg->flags & TXWI_DISABLED) == 0) |
|---|
| 227 | { |
|---|
| 228 | txwSetupWindowData( wg->vpos + line, wg->hpos + col, |
|---|
| 229 | wg->vsize, wg->hsize, wg->style, |
|---|
| 230 | (wg->helpid) ? wg->helpid : |
|---|
| 231 | (gw->helpid) ? gw->helpid : |
|---|
| 232 | wg->class + TXWD_GENWIDGET, |
|---|
| 233 | ' ', ' ', TXWSCHEME_COLORS, |
|---|
| 234 | (wg->title ) ? wg->title : "", "", |
|---|
| 235 | &window); |
|---|
| 236 | switch (wg->class) // shallow copy class-data |
|---|
| 237 | { |
|---|
| 238 | case TXW_STATIC: window.st = wg->st; break; |
|---|
| 239 | case TXW_STLINE: window.sl = wg->sl; break; |
|---|
| 240 | case TXW_ENTRYFIELD: window.ef = wg->ef; break; |
|---|
| 241 | case TXW_TEXTVIEW: window.tv = wg->tv; break; |
|---|
| 242 | case TXW_BUTTON: window.bu = wg->bu; break; |
|---|
| 243 | case TXW_LISTBOX: window.lb = wg->lb; break; |
|---|
| 244 | } |
|---|
| 245 | wg->hwnd = txwCreateWindow( dframe, wg->class, dframe, 0, &window, |
|---|
| 246 | (wg->winproc) ? wg->winproc : txwDefWindowProc); |
|---|
| 247 | txwSetWindowPtr( wg->hwnd, TXQWP_USER, gw); // make data available |
|---|
| 248 | txwSetWindowUShort( wg->hwnd, TXQWS_GROUP, wg->group); |
|---|
| 249 | txwSetWindowUShort( wg->hwnd, TXQWS_ID, (wg->winid) ? wg->winid : |
|---|
| 250 | gw->basewid + w); |
|---|
| 251 | } |
|---|
| 252 | } |
|---|
| 253 | } |
|---|
| 254 | RETURN (rc); |
|---|
| 255 | } // end 'txwCreateWidgets' |
|---|
| 256 | /*--------------------------------------------------------------------------- */ |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | #if defined (NEVER) // template for user WinProc |
|---|
| 260 | /*****************************************************************************/ |
|---|
| 261 | // Default Window procedure, for a Generic Widgets control |
|---|
| 262 | /*****************************************************************************/ |
|---|
| 263 | ULONG txwWidgetWinProc // RET result |
|---|
| 264 | ( |
|---|
| 265 | TXWHANDLE hwnd, // IN current window |
|---|
| 266 | ULONG msg, // IN message id |
|---|
| 267 | ULONG mp1, // IN msg param 1 |
|---|
| 268 | ULONG mp2 // IN msg param 2 |
|---|
| 269 | ) |
|---|
| 270 | { |
|---|
| 271 | ULONG rc = NO_ERROR; |
|---|
| 272 | |
|---|
| 273 | ENTER(); |
|---|
| 274 | if (hwnd != 0) |
|---|
| 275 | { |
|---|
| 276 | TXGW_DATA *gw = txwQueryWindowPtr( hwnd, TXQWP_USER); |
|---|
| 277 | |
|---|
| 278 | TRCMSG( hwnd, msg, mp1, mp2); |
|---|
| 279 | if (gw != NULL) // valid widget data ? |
|---|
| 280 | { |
|---|
| 281 | TXWHANDLE owner = txwQueryWindow( hwnd, TXQW_OWNER); |
|---|
| 282 | USHORT wid = txwQueryWindowUShort( hwnd, TXQWS_ID); |
|---|
| 283 | int w = wid - gw->basewid; |
|---|
| 284 | |
|---|
| 285 | switch (msg) |
|---|
| 286 | { |
|---|
| 287 | default: |
|---|
| 288 | rc = txwDefWindowProc( hwnd, msg, mp1, mp2); |
|---|
| 289 | break; |
|---|
| 290 | } |
|---|
| 291 | } |
|---|
| 292 | else |
|---|
| 293 | { |
|---|
| 294 | rc = TX_INVALID_DATA; |
|---|
| 295 | } |
|---|
| 296 | } |
|---|
| 297 | else |
|---|
| 298 | { |
|---|
| 299 | rc = TX_INVALID_HANDLE; |
|---|
| 300 | } |
|---|
| 301 | RETURN( rc); |
|---|
| 302 | } // end 'txwWidgetWinProc' |
|---|
| 303 | /*---------------------------------------------------------------------------*/ |
|---|
| 304 | #endif |
|---|
| 305 | |
|---|
| 306 | /*****************************************************************************/ |
|---|
| 307 | // Display generic widget dialog, adding standard empty canvas to the widgets |
|---|
| 308 | /*****************************************************************************/ |
|---|
| 309 | ULONG txwWidgetDialog |
|---|
| 310 | ( |
|---|
| 311 | TXWHANDLE parent, // IN parent window |
|---|
| 312 | TXWHANDLE owner, // IN owner window |
|---|
| 313 | TXWINPROC dlgproc, // IN dialog proc or NULL |
|---|
| 314 | void *usrdata, // IN window data (QWP_USER) |
|---|
| 315 | char *title, // IN title for the dialog |
|---|
| 316 | ULONG flags, // IN specification flags |
|---|
| 317 | USHORT focus, // IN focus to index 0..n-1 |
|---|
| 318 | TXGW_DATA *gwdata // INOUT generic widget data |
|---|
| 319 | ) |
|---|
| 320 | { |
|---|
| 321 | ULONG rc = TX_INVALID_HANDLE; // function return |
|---|
| 322 | |
|---|
| 323 | ENTER(); |
|---|
| 324 | TRACES(("parent:%8.8lx owner:%8.8lx title:'%s'\n", parent, owner, title)); |
|---|
| 325 | TRACES(("gwdata:%8.8lx\n", gwdata)); |
|---|
| 326 | |
|---|
| 327 | if ((txwIsWindow( TXHWND_DESKTOP)) && // is there a desktop ? |
|---|
| 328 | (gwdata != NULL)) // and widget data ? |
|---|
| 329 | { |
|---|
| 330 | TXRECT position; // reference size/position |
|---|
| 331 | TXWHANDLE pframe; // prompt-box frame |
|---|
| 332 | TXWINDOW window; // setup window data |
|---|
| 333 | ULONG style; |
|---|
| 334 | USHORT phsize; // parent window width |
|---|
| 335 | USHORT pvsize; // parent window height |
|---|
| 336 | short ll = 0; // vertical size |
|---|
| 337 | short ww = 0; // horizontal size |
|---|
| 338 | |
|---|
| 339 | ll = txwWidgetSize( gwdata, 0, &ww); // get widget sizes |
|---|
| 340 | txwQueryWindowRect( parent, FALSE, &position); |
|---|
| 341 | phsize = position.right; |
|---|
| 342 | pvsize = position.bottom; |
|---|
| 343 | |
|---|
| 344 | if (position.left + ww + 6 < phsize) |
|---|
| 345 | { |
|---|
| 346 | position.right = ww + 4; |
|---|
| 347 | position.left = phsize - ww -4; |
|---|
| 348 | if (flags & TXWD_HCENTER) |
|---|
| 349 | { |
|---|
| 350 | position.left /= 2; // center horizontally |
|---|
| 351 | } |
|---|
| 352 | } |
|---|
| 353 | if (position.top + ll + 6 < pvsize) |
|---|
| 354 | { |
|---|
| 355 | position.bottom = ll + 4; |
|---|
| 356 | position.top += 1; |
|---|
| 357 | if (flags & TXPB_VCENTER) |
|---|
| 358 | { |
|---|
| 359 | position.top += ((pvsize - position.bottom) * 2 / 5); // center vertically |
|---|
| 360 | } |
|---|
| 361 | } |
|---|
| 362 | TRECTA( "pos/size", (&position)); |
|---|
| 363 | |
|---|
| 364 | style = TXWS_DIALOG | TXWS_DISABLED | TXCS_CLOSE_BUTTON; |
|---|
| 365 | if (flags & TXPB_MOVEABLE) |
|---|
| 366 | { |
|---|
| 367 | style |= TXWS_MOVEABLE; // make frame move/sizeable |
|---|
| 368 | } |
|---|
| 369 | txwSetupWindowData( |
|---|
| 370 | position.top, // upper left corner |
|---|
| 371 | position.left, |
|---|
| 372 | position.bottom, // vertical size |
|---|
| 373 | position.right, // horizontal size |
|---|
| 374 | style | TXWS_CAST_SHADOW, // window frame style |
|---|
| 375 | gwdata->helpid, // messagebox help |
|---|
| 376 | ' ', ' ', TXWSCHEME_COLORS, |
|---|
| 377 | title, txwstd_footer, |
|---|
| 378 | &window); |
|---|
| 379 | |
|---|
| 380 | if ((focus < gwdata->count) && |
|---|
| 381 | (gwdata->widget[focus].winid != 0)) // explicit window-ID |
|---|
| 382 | { |
|---|
| 383 | window.dlgFocusID = gwdata->widget[focus].winid; |
|---|
| 384 | } |
|---|
| 385 | else // calculated window-ID |
|---|
| 386 | { |
|---|
| 387 | window.dlgFocusID = gwdata->basewid + focus; // field to get focus |
|---|
| 388 | } |
|---|
| 389 | window.st.buf = NULL; // NO artwork attached |
|---|
| 390 | pframe = txwCreateWindow( parent, TXW_CANVAS, 0, 0, &window, NULL); |
|---|
| 391 | |
|---|
| 392 | if ((rc = txwCreateWidgets( pframe, gwdata, 1, 1)) == NO_ERROR) |
|---|
| 393 | { |
|---|
| 394 | rc = txwDlgBox( parent, owner, |
|---|
| 395 | (dlgproc) ? dlgproc : txwDefDlgProc, |
|---|
| 396 | pframe, usrdata); |
|---|
| 397 | } |
|---|
| 398 | } |
|---|
| 399 | RETURN (rc); |
|---|
| 400 | } // end 'txwWidgetDialog' |
|---|
| 401 | /*---------------------------------------------------------------------------*/ |
|---|