home *** CD-ROM | disk | FTP | other *** search
Wrap
/* * Demo-Programm für die CF-Lib */ #include <cflib.h> #include "demo.h" /* in pdlg.c */ extern void test_pdlg(bool win); /* --------------------------------------------------------------------------- */ OBJECT *menu, *objdial, *popdial, *wicon, *popups, *about; WDIALOG *wdial; bool quit; int msg[8], vdi_handle; int event, msx, msy, mbutton, kstate, mclick, kreturn, win_handle; bool modal = FALSE; int id = 1, pts = 10; static void handle_msg(int *msg); /* --------------------------------------------------------------------------- */ /* * Ein Dummy-Fenster, da₧ einfach nur da ist, damit man sieht, da₧ bei * app-modalen Dialogen Redraw-, Move- und Size-Aktionen ausgewertet * werden. */ void redraw_win(int handle, int xc, int yc, int wc, int hc) { GRECT t1,t2; int temp[4]; hide_mouse(); wind_update(TRUE); t2.g_x = xc; t2.g_y = yc; t2.g_w = wc; t2.g_h = hc; wind_get_grect(handle, WF_FIRSTXYWH, &t1); vsf_color(vdi_handle, 0); wind_get(handle, WF_WORKXYWH, &temp[0], &temp[1], &temp[2], &temp[3]); temp[2] += temp[0] - 1; temp[3] += temp[1] - 1; while (t1.g_w && t1.g_h) { if (rc_intersect(&t2, &t1)) { set_clipping(vdi_handle, t1.g_x, t1.g_y, t1.g_w, t1.g_h, TRUE); v_bar(vdi_handle, temp); } wind_get(handle, WF_NEXTXYWH, &t1.g_x, &t1.g_y, &t1.g_w, &t1.g_h); } wind_update(FALSE); show_mouse(); } void open_win(void) { int work_out[57]; vdi_handle = open_vwork(work_out); win_handle = wind_create((NAME|MOVER|CLOSER|SIZER), gl_desk.g_x, gl_desk.g_y, gl_desk.g_w, gl_desk.g_h); wind_set_str(win_handle, WF_NAME, " Fenster "); wind_open(win_handle, 100, 100, 350, 150); } void win_msg(int *msg) { if (msg[3] == win_handle) { switch (msg[0]) { case WM_CLOSED : wind_close(win_handle); break; case WM_BOTTOMED: wind_set(win_handle, WF_BOTTOM, 0, 0, 0, 0); break; case WM_REDRAW: redraw_win(win_handle, msg[4], msg[5], msg[6], msg[7]); break; case WM_NEWTOP: case WM_TOPPED: wind_set(win_handle, WF_TOP, 0, 0, 0, 0); break; case WM_MOVED: wind_set(win_handle, WF_CURRXYWH, msg[4], msg[5], msg[6], msg[7]); break; case WM_SIZED: wind_set(win_handle, WF_CURRXYWH, msg[4], msg[5], msg[6], msg[7]); break; } } } /* --------------------------------------------------------------------------- */ void modal_dial(void) { int x, y, w, h, antw, edit; wind_update(BEG_UPDATE); form_center(objdial, &x, &y, &w, &h); form_dial(FMD_START, x, y, w, h, x, y, w, h); objc_draw(objdial, ROOT, MAX_DEPTH, x, y, w, h); edit = EDIT1; do { antw = cf_form_do(objdial, &edit); } while (antw != ENDE && antw != UNDO); set_state(objdial, antw, SELECTED, FALSE); form_dial(FMD_FINISH, x, y, w, h, x, y, w, h); wind_update(END_UPDATE); if (antw == ENDE) quit = TRUE; } /* --------------------------------------------------------------------------- */ void appmodal_dial(void) { void *mdial; bool close = FALSE; int id, exit_obj; mdial = open_mdial(objdial, EDIT1); while (!close) { exit_obj = do_mdial(mdial); switch (exit_obj) { case EXITBUT : do_walert(1, 2, "[1][Mdial ist re-entrant!][Toll]", "Alert"); break; case ENDE : quit = TRUE; close = TRUE; break; case HELP : id = appl_find("ST-GUIDE"); if (id > 0) send_vastart(id, "*:\\cf-lib.hyp"); break; case UNDO : close = TRUE; break; } if (get_flag(objdial, exit_obj, EXIT)) set_state(objdial, exit_obj, SELECTED, FALSE); if (!close) redraw_mdobj(mdial, exit_obj); } close_mdial(mdial); } /* --------------------------------------------------------------------------- */ POPUP pop; void nonmodal_open_cb(WDIALOG *wd) { char str[10]; /* dynamisches Popup anlegen */ set_string(wd->tree, P1TEXT, "bla"); create_popup(&pop, 5, 23, " zeile1"); append_popup(&pop, " zeile2zeile2"); append_popup(&pop, " zeile3zeile3zeile3"); get_string(popups, 20/*POPF1*/, str); set_string(wd->tree, P2BOX, str); } bool nonmodal_exit_cb(WDIALOG *wd, int obj) { bool close = FALSE; int y; char s[30]; switch (obj) { case P1STR : break; case P1BOX : y = handle_popup(wd->tree, P1BOX, pop.tree, 0, POP_OPEN); if (y > 0) { get_string(pop.tree, y, s); set_string(wd->tree, P1TEXT, s+1); redraw_wdobj(wd, P1TEXT); } break; case P2STR : case P2BOX : if (obj == P2STR) handle_popup(wd->tree, P2BOX, popups, FUNCPOP, POP_CYCLE); else handle_popup(wd->tree, P2BOX, popups, FUNCPOP, POP_OPEN); break; case WD_CLOSER : close = TRUE; debug("Closer ohne UNDO-Button!\n"); break; } if (close) free_popup(&pop); return close; } /* --------------------------------------------------------------------------- */ void fsel_cb(char *path, char *name) { /* hier laufen die Dateinamen/Pfade bei einer Mehrfach-Dateiselektion auf */ } /* --------------------------------------------------------------------------- */ void handle_menu(int title, int item) { switch (item) { case MABOUT : simple_mdial(about, 0); break; case MFSEL : { char path[50] = "", name[50] = ""; if (select_file(path, name, "", "Dateiauswahl im Fenster", fsel_cb) && (path[0] != EOS)) debug(" %s%s\n", path, name); } break; case MENDE : quit = TRUE; break; case MDIAL1 : if (modal) modal_dial(); else appmodal_dial(); break; case MDIAL2 : open_wdial(wdial, -1, -1); break; case MALERT : if (modal) do_alert(1, 2, "[1][Dies ist ein modaler Alert.][OK|UNDO]"); else do_walert(1, 3, "[3][Dies ist ein Alert im Fenster.|Mit Text in der zweiten Zeile|und drei Buttons.|Und UNDO auf Abbruch!][Ja|Nein|Abbruch]", " Fenster-Alert "); break; case MFONTSEL : if (!do_fontsel((FS_M_MAGX|FS_M_XFSL), "Im Fenster", &id, &pts) && (id == -1)) { do_walert(1, 0, "[3][Keine Fontauswahl verfügbar!][OK]", "Alert"); id = 1; pts = 10; } break; case MPDLG : test_pdlg(!modal); break; case MASCII : set_asciitable_strings("Aktueller Font", ""); ascii_table(id, 10); break; case MMODAL : case MFENSTER : if (!modal && item == MMODAL) modal = TRUE; else if (modal && item == MFENSTER) modal = FALSE; menu_icheck(menu, MMODAL, modal); menu_icheck(menu, MFENSTER, !modal); if (modal) set_mdial_wincb(0L); else set_mdial_wincb(handle_msg); break; default: if (title == TSCUT) { char str[50], s2[50]; get_string(menu, item, str); sprintf(s2, "[1][%s][OK]", str); do_walert(1, 0, s2, "Menü: Shortcuts"); } break; } menu_tnormal(menu, title, 1); } static void handle_msg(int *msg) { if (!message_wdial(msg)) { switch (msg[0]) { case MN_SELECTED: handle_menu(msg[3], msg[4]); break; case WM_CLOSED : case WM_BOTTOMED: case WM_REDRAW: case WM_NEWTOP: case WM_TOPPED: case WM_MOVED: case WM_SIZED : win_msg(msg); break; case AP_TERM : quit = TRUE; break; } } } /* --------------------------------------------------------------------------- */ extern void cf_use_all_userdefs(bool all); void main(void) { OBJECT *tree; init_app("demo.rsc"); rsrc_gaddr(R_TREE, MENUTREE, &menu); create_menu(menu); menu_icheck(menu, MMODAL, modal); menu_icheck(menu, MFENSTER, !modal); rsrc_gaddr(R_TREE, OBJDIAL, &objdial); fix_dial(objdial); rsrc_gaddr(R_TREE, POPDIAL, &tree); fix_dial(tree); rsrc_gaddr(R_TREE, WINICON, &wicon); wdial = create_wdial(tree, wicon, P1TEXT, nonmodal_open_cb, nonmodal_exit_cb); rsrc_gaddr(R_TREE, POPUPS, &popups); fix_menu(popups); rsrc_gaddr(R_TREE, ABOUT, &about); fix_menu(about); set_string(about, A_PL, CFLIB_PATCHLEVEL); rsrc_gaddr(R_TREE, PRN_SUB, &tree); fix_dial(tree); if (!modal) set_mdial_wincb(handle_msg); open_win(); quit = FALSE; while (!quit) { mbutton = 0; event = evnt_multi(MU_MESAG|MU_BUTTON|MU_KEYBD, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, msg, 0, &msx, &msy, &mbutton, &kstate, &kreturn, &mclick); if (event & MU_MESAG) handle_msg(msg); if (event & MU_BUTTON) { if (!click_wdial(mclick, msx, msy, kstate, mbutton)) ; } if (event & MU_KEYBD) { if (!key_wdial(kreturn, kstate)) { int title, item; if (is_menu_key(kreturn, kstate, &title, &item)) handle_menu(title, item); } } } delete_wdial(wdial); wind_close(win_handle); wind_delete(win_handle); v_clsvwk(vdi_handle); delete_menu(); exit_app(0); }