PtModalStart () PtModalEnd (start_number)
PtModalStart returns an integer used as the start-number for PtModalEnd.
PtModalEnd returns t if modal processing was successfully exited.
PtModalStart initiates modal processing, which halts the current event loop and starts a new loop. This is useful for creating a dialog box where the user must make some input before accessing any other widget in the interface. To block and unblock other windows, you have to use the Pt_BLOCKED resource, as demonstrated in the example below. When the dialog or other use of modal processing is finished, the modal event loop is exited by calling PtModalEnd.
This example, ex_PtModalStart.g, is included in the product distribution.
#!/usr/cogent/bin/phgamma /* This example creates a window with a label you can drag, and a "Freeze" button. Pressing the "Freeze" button initiates PtModalStart() and opens another window, with an "Unfreeze" button. Until the "Unfreeze" button is pressed, the first window is frozen. */ require_lisp("PhotonWidgets"); PtInit(nil); //The main window. win = new(PtWindow); win.SetArea(300,50,250,250); PtRealizeWidget(win); lab = new(PtLabel); lab.text_string = "Drag Me"; lab.SetPos(90, 30); PtRealizeWidget(lab); button1 = new(PtButton); button1.text_string = "Freeze label and open message"; button1.SetPos(30, 75); PtAttachCallback(button1, Pt_CB_ACTIVATE, #doOpen()); PtRealizeWidget(button1); exitbut = new(PtButton); exitbut.SetPos(110, 175); exitbut.text_string = "Exit"; PtAttachCallback(exitbut,Pt_CB_ACTIVATE,#exit_program(1)); PtRealizeWidget(exitbut); //Functions to start and end modal state. function PhabModalLoop(done) { local count = nil; protect { count = PtModalStart(); while(!eval(done)) PtProcessEvent(); } unwind { if(count != nil) PtModalEnd(count); } } function doOpen() { make_msg(); done = nil; win.flags = Pt_BLOCKED; PhabModalLoop(eval(done)); } function doClose() { done = t; win.flags = cons(Pt_BLOCKED, nil); } //The modal_state window. /* This function makes the modal_state window using a PtMessage widget.*/ function make_msg() { win2 = new(PtMessage); win2.msg_text = "Press Cancel to continue.\nPress Print to print this\nmessage and continue.\n "; win2.msg_title = "The message."; win2.flags = Pt_MSG_CENTER_ON_PARENT; win2.msg_button1 = "Cancel"; win2.msg_button2 = "Print"; PtAttachCallback(win2, Pt_CB_MSG_BUTTON2, `princ(@win2.msg_text, "\n")); PtAttachCallback(win2, Pt_CB_MSG_BUTTON2, #doClose()); PtAttachCallback(win2, Pt_CB_MSG_BUTTON1, #doClose()); PtRealizeWidget(win2); } /* An alternate way to make the window, using a PtWindow widget. If used, the following lines must be added... to doOpen() : PtRealizeWidget(win2); to doClose() : PtUnrealizeWidget(win2); and the line : make_msg(); should be removed from doOpen(). win2 = new(PtWindow); win2.SetArea(440,100,100,80); lab2 = new(PtLabel); lab2.text_string = "Press button to continue."; button2 = new(PtButton); button2.text_string = "Unfreeze"; button2.SetPos(40, 30); PtAttachCallback(button2, Pt_CB_ACTIVATE, #doClose()); */ //Functions to create a drag_able widget. DraggedWidget := nil; method PtWidget.StartDrag () { DraggedWidget = self; PtInitDrag (self, nil, Ph_TRACK_DRAG | Ph_DRAG_TRACK); } function handle_drag () { local event = cbinfo.event, rect; if (event.type == Ph_EV_DRAG) { if (event.subtype == Ph_EV_DRAG_COMPLETE || event.subtype == Ph_EV_DRAG_MOVE) { if (DraggedWidget) { rect = TranslateRect (event_data.drag_event.rect, event.translation); DraggedWidget.SetPos (rect.ul.x, rect.ul.y); } if (event.subtype == Ph_EV_DRAG_COMPLETE) DraggedWidget = nil; } } } PtAttachCallback(win,Pt_CB_RAW,#handle_drag(),Ph_EV_DRAG); PtAttachCallback(lab,Pt_CB_RAW,#widget.StartDrag(),Ph_EV_BUT_PRESS); PtMainLoop();
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.