source: tags/cvs_2_svn/TESTAWT/TB_extern.cxx

Last change on this file was 5390, checked in by westram, 16 years ago
  • TAB-Ex
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.9 KB
Line 
1// see awdemo for a (slightly out of date) demonstration of direct graphics without
2// canvas support
3
4/* -----------------------------------------------------------------
5 * Module:                        TESTBED/TB_extern.cxx
6 *
7 * Description:  the meat of this demonstration of AWT and WINDOW
8 *               use - careful, as we had to start tons of stuff
9 *               to get here, even if we'll never need most of it
10 *               (trees, db, ...)
11 *
12 *  See AWT, PH_dtree, ...  for a larger example
13 * -----------------------------------------------------------------
14 */
15
16/*
17 * $Header$
18 *
19 * $Log$
20 * Revision 1.6  2008/06/06 12:23:34  westram
21 * - TAB-Ex
22 *
23 * Revision 1.5  2007/12/17 23:06:05  boehnel
24 *
25 * "0 -> NULL"
26 *
27 * Revision 1.4  2004/06/30 17:34:01  westram
28 * - zoom.bitmap -> pzoom.bitmap
29 *
30 * Revision 1.3  2002/12/17 10:36:40  westram
31 * valgrinded
32 *
33 * Revision 1.2  2001/06/06 18:34:19  westram
34 * changes for color groups (working for gene map)
35 *
36 * Revision 1.1.1.1  2000/11/23 09:41:16  westram
37 * Erster Import
38 *
39 * Revision 1.2  1995/03/13  16:53:19  jakobi
40 * *** empty log message ***
41 *
42 */
43
44#include <stdio.h>
45#include <stdlib.h>
46
47// string functions and db stuff
48#include <arbdb.h>
49#include <arbdbt.h>
50
51// window stuff
52#include <aw_root.hxx>
53#include <aw_window.hxx>
54#include <aw_awars.hxx>
55// here we set some stuff for zoomtext and other defaults
56#include <aw_preset.hxx>
57#include <awt_preset.hxx>
58
59// ton's of stuff for canvas support (which simply should allow
60// us to concentrate on our core functions instead of doing
61// lowlevel display games)
62#include <awt_canvas.hxx>
63#include "awt_tree.hxx"
64#include "awt_dtree.hxx"
65
66// more stuff, just needed to startup the filerequester
67// awt.hxx is req'd for filereq
68#include <awt.hxx>
69//#include <awt_nds.hxx>
70#include <awt_tree_cb.hxx>
71
72#include "tb_extern.hxx"
73
74
75/* -----------------------------------------------------------------
76 * Class:                        AWT_graphic_testbed
77 *
78 * Description:                  derived class to interface with AWT.
79 *                               these routines display our graphics
80 * -----------------------------------------------------------------
81 */
82
83AWT_graphic_testbed::AWT_graphic_testbed(void):AWT_graphic() {
84    exports.dont_fit_x = 0;
85    exports.dont_fit_y = 0;
86    exports.left_offset = 100;
87    exports.right_offset = 100;
88    exports.top_offset = 30;
89    exports.bottom_offset = 30;
90}
91
92// this is used for evaluating commands/actions in the canvas,
93// necessary dummies (input in the canvas, ...)
94// see AWT_dtree,cxx:AWT_graphic_tree
95void AWT_graphic_testbed::command(AW_device *device, AWT_COMMAND_MODE cmd, int button, AW_key_mod key_modifier, char key_char, AW_event_type type, AW_pos x, AW_pos y, AW_clicked_line *cl, AW_clicked_text *ct) {
96    AWUSE(device); AWUSE(cmd); AWUSE(button); AWUSE(type);
97    AWUSE(x); AWUSE(y); AWUSE(cl); AWUSE(ct);
98}
99
100// called by canvas to display/create the objects to be displayed
101// canvas simply calls us, it would be our job here to box larger subparts and
102// ask clip, whether we really have to look into that box (see WINDOW/AW_xfigfont.hxx/zoomtext1 as example)
103void AWT_graphic_testbed::show(AW_device *device) {
104    // central cross
105    device->line(AWT_GC_CURSOR,-1.0,0.0,1.0,0.0,AW_ALL,0,0);
106    device->line(AWT_GC_CURSOR,0.0,1.0,0.0,-1.0,AW_ALL,0,0);
107    // title
108    device->text(AWT_GC_CURSOR, "testforme", -1.0, -1.0, 0.0, AW_SCREEN, 0, 0);
109    // set devices for this text (just don't move fixed sized text (like standard text) into the size device...)
110    AW_bitset bitset=AW_SCREEN;
111    if (tbd_bitset) bitset=tbd_bitset;
112    // run the test function
113    if(tbd_function)
114        device->zoomtext((int)tbd_gc,tbd_string,tbd_x,tbd_y,tbd_height,
115                         tbd_alignment,tbd_rotation,bitset,
116                         tbd_cl1,tbd_cl2);
117    else
118        device->zoomtext4line((int)tbd_gc,tbd_string,tbd_height,
119                              tbd_x0,tbd_y0,tbd_x1,tbd_y1,
120                              tbd_alignmentx,tbd_alignmenty,bitset,
121                              tbd_cl1,tbd_cl2);
122}
123
124// necessary dummy, otherwise cc would theatralically cry 'virtual class' and die
125void AWT_graphic_testbed::info(AW_device *device, AW_pos x, AW_pos y, AW_clicked_line *cl, AW_clicked_text *ct) {
126    aw_message("INFO MESSAGE");
127    AWUSE(device); AWUSE(x); AWUSE(y); AWUSE(cl); AWUSE(ct);
128}
129
130
131//
132// presets
133//
134
135
136// a small gc manager is needed to tell AW_presets what we like to offer in the userinterface ...
137AW_gc_manager AWT_graphic_testbed::init_devices(AW_window *window, AW_device * device, AWT_canvas *canvas ,AW_CL cl) {
138    AW_gc_manager preset_window =
139        AW_manage_GC(window, device, AWT_GC_CURSOR, AWT_GC_CURSOR+5, AW_GCM_DATA_AREA,
140                     (AW_CB)AWT_resize_cb, (AW_CL)canvas, cl,
141                     false, // no color groups
142                     "",
143                     "CURSOR",
144                     "SELECTED",
145                     "SEL. & NOT",
146                     "NOT SEL.",
147                     "ETC",
148                     NULL);
149    return preset_window;
150}
151
152
153//
154// testbed stuff: userinterface related routines - callback, etc
155//
156
157void tb_exit(AW_window *aw_window) {
158    AWUSE(aw_window);
159    exit(0);
160}
161
162// generate and show current gfx - the "TEST" button
163void tb_action(AW_window *aw_window,AW_CL canvas) {
164    AW_device *device=aw_window->get_device(AW_MIDDLE_AREA);
165    tb_reload(aw_window->get_root(), (AWT_canvas *)canvas);
166}
167
168// generate current gfx
169AWT_graphic *tb_gen_gfx(void) {
170    AWT_graphic_testbed *gfx = new AWT_graphic_testbed;
171    return (AWT_graphic *)gfx;
172}
173
174// (re)display gfx (canvas then calls ->show)
175void tb_reload(AW_root *awr, AWT_canvas *canvas) {
176    AWUSE(awr);
177    canvas->zoom_reset();
178    AWT_expose_cb(0,canvas,0);
179}
180
181// here we create the main window, menues, ... and a physical zoom mode
182AW_window * create_tb_main_window(AW_root *awr) {
183    AW_gc_manager aw_gc_manager; // not used?
184    AWT_graphic *gfx=tb_gen_gfx();
185
186    AW_window_menu_modes *awm = new AW_window_menu_modes();
187    awm->init(awr,"ARB_TB", 800,600,0,0);
188
189    awm->button_length(5);
190
191    // dummy tree
192    AWT_canvas *canvas = new AWT_canvas(gb_main,(AW_window *)awm,gfx,aw_gc_manager) ;
193    tb_reload(awr,canvas);// load it for the first time...
194
195    awm->create_menu(       0,   "File",     "F", "nt_file.hlp",  F_ALL );
196    awm->insert_menu_topic(0,"Save Defaults (in ~/.arb_prop/testawt.awt)","D","savedef.hlp",F_ALL, (AW_CB) AW_save_defaults, 0, 0 );
197    awm->insert_menu_topic(0,"Reset Physical Zoom", "P","rst_phys_zoom.hlp",F_ALL, (AW_CB)NT_reset_pzoom_cb, (AW_CL) canvas, 0 );
198    awm->insert_menu_topic( 0, "Quit",                              "Q","quit.hlp", F_ALL, (AW_CB)tb_exit,  0, 0 );
199
200    // PJ restructured preferences
201    awm->create_menu(0,"Properties","r","properties.hlp", F_ALL);
202    awm->insert_menu_topic(0,"Application: Fonts, etc",             "F","props_frame.hlp",  F_ALL, AW_POPUP, (AW_CL)AWT_preset_window, 0 );
203    awm->insert_menu_topic(0,"TestSetup",                           "T","nt_props_tree.hlp",F_ALL, AW_POPUP, (AW_CL)tb_preset_tree_window, 0);
204    awm->insert_menu_topic(0,"DataDisplay: Fonts, etc",             "D","nt_props_data.hlp",F_ALL, AW_POPUP, (AW_CL)AW_create_gc_window, (AW_CL)aw_gc_manager );
205
206    awm->create_mode( 0, "pzoom.bitmap", "mode_pzoom.hlp", F_ALL, (AW_CB)nt_mode_event,
207                      (AW_CL)canvas,
208                      (AW_CL)AWT_MODE_ZOOM
209                      );
210
211
212    awm->at(5,2);
213    awm->auto_space(0,-2);
214    awm->shadow_width(1);
215
216    int db_actx,db_acty;
217    awm->get_at_position( &db_actx,&db_acty );
218    awm->callback(tb_action,(AW_CL) canvas);
219    awm->button_length(20);
220    awm->create_button("Test","Test");
221
222    awm->at_newline();
223    awm->auto_space(-2,-2);
224
225    awm->at_newline();
226    int db_specx,db_specy;
227    awm->get_at_position( &db_specx,&db_specy );
228    awm->set_info_area_height( db_specy+6 );
229
230    awm->set_bottom_area_height( 0 );
231
232    return (AW_window *)awm;
233
234}
235
236// parameter setup panel for the user
237AW_window *tb_preset_tree_window( AW_root *root )  {
238
239    AW_window_simple *aws = new AW_window_simple;
240    const int       tabstop = 400;
241
242    // window sizes
243
244    aws->init( root, "Test Options", 600, 600, 400, 300 );
245    aws->label_length( 25 );
246    aws->button_length( 20 );
247
248    aws->at           ( 10,10 );
249    aws->auto_space(10,10);
250    aws->callback     ( AW_POPDOWN );
251    aws->create_button( "CLOSE", "CLOSE", "C" );
252
253    // aws->callback     ( (AW_CB0)AW_save_defaults );
254    // aws->create_button( "SAVE", "SAVE", "S" );
255    aws->at_newline();
256
257    // No Help, as we usually do not know the associated help file from within presets of AW Lib
258
259    aws->create_option_menu( "vectorfont/active", "Data font type", "1" );
260    aws->insert_option        ( "Use vectorfont",     " ", (int) 1);
261    aws->insert_option        ( "Use standard font",  " ", (int) 0);
262    aws->update_option_menu();
263    aws->at_newline();
264
265    AW_preset_create_scale_chooser(aws,"vectorfont/userscale","VF: absolute scaling");
266    aws->create_input_field( "vectorfont/userscale",6);
267    aws->at_newline();
268
269    aws->create_button("Testdataset","Testdataset");
270    aws->at_newline();
271
272    aws->create_option_menu("tbd_function","Vector font type","1");
273    aws->insert_option("Zoomtext"," ", (int) 1);
274    aws->insert_option("Zoomtext4Line"," ", (int) 0);
275    aws->update_option_menu();
276    aws->at_newline();
277
278    // WARNING: labels are just labels for other elements, so don't tab here...
279
280    aws->label("GC");
281    aws->create_input_field("tbd_gc",10);
282    aws->at_newline();
283
284    aws->label("String");
285    aws->create_input_field("tbd_string",10);
286    aws->at_newline();
287
288    aws->label("Height");
289    aws->create_input_field("tbd_height",10);
290    aws->at_newline();
291
292    aws->label("Bitset");
293    aws->create_input_field("tbd_bitset",10);
294    aws->at_newline();
295
296    aws->label("CL1");
297    aws->create_input_field("tbd_cl1",10);
298    aws->at_newline();
299
300    aws->label("CL2");
301    aws->create_input_field("tbd_cl2",10);
302    aws->at_newline();
303
304    aws->create_button(0,"Zoomtext Parameters");
305
306    aws->at_newline();
307
308    aws->label("x/y");
309    aws->create_input_field("tbd_x",10);
310    aws->at_x(tabstop);
311    aws->create_input_field("tbd_y",10);
312    aws->at_newline();
313
314    aws->label("alignment");
315    aws->create_input_field("tbd_alignment",10);
316    aws->at_newline();
317
318    aws->label("rotation");
319    aws->create_input_field("tbd_rotation",10);
320    aws->at_newline();
321
322    aws->create_button(0,"Zoomtext4line Parameters");
323    aws->at_newline();
324
325    aws->label("x0/y0 x1/y1");
326    aws->create_input_field("tbd_x0",10);
327    aws->at_x(tabstop);
328    aws->create_input_field("tbd_y0",10);
329    aws->at_x(tabstop);
330    aws->at_newline();
331    aws->label(" ");
332    aws->create_input_field("tbd_x1",10);
333    aws->at_x(tabstop);
334    aws->create_input_field("tbd_y1",10);
335    aws->at_newline();
336
337    aws->label("alignment x/y");
338    aws->create_input_field("tbd_alignmentx",10);
339    aws->at_x(tabstop);
340    aws->create_input_field("tbd_alignmenty",10);
341    aws->at_newline();
342
343    aws->window_fit();
344    return (AW_window *)aws;
345
346}
Note: See TracBrowser for help on using the repository browser.