#include #include #include #include #include #include "framework.h" static void sample_guilayout() { PRIVATE_MESSAGE msg; PRIVATE_MESSAGE msgadd; PRIVATE_MESSAGE msgdel; int nb; glocal.nb = 10; ("sample guilayout"); guiform(); setuparea1(true); guiend(); guigroup("People"); setuparea2(true); guiend(); guinewline(); guiform(); setuparea3(false); guiend(); guidispolast (GUI_H_CENTER,2,GUI_V_TOP,1); DIALOG dia; PRIVATE_MESSAGE msgadd; dia.new_button ("add","Add a record",msgadd); dia.newline(); PRIVATE_MESSAGE msgdel; dia.new_button ("del","Del a record",msgdel); PRIVATE_MESSAGE msglog; dia.new_button ("Log window","Show the log window",msglog); dia.waitfor (mayend); dia.waitfor (ending); int nof=0; while (1){ MENU_STATUS code = dia.edit ("","You control the other list",help_nil,nof,0); if (code == MENU_MESSAGE){ if (dialog_testmessage (msgadd)){ dialog_sendmessage (glocal.msgadd); }else if (dialog_testmessage (msgdel)){ dialog_sendmessage (glocal.msgdel); }else if (dialog_testmessage (msglog)){ if (!isareaalive(3)){ callarea3(); } }else if (dialog_testmessage (mayend)){ endok(); }else if (dialog_testmessage (ending)){ break; } } } PRIVATE_MESSAGE *mayend; PRIVATE_MESSAGE *ending; _F_guilayout *c; glocal.mayend = &mayend; glocal.ending = &ending; glocal.c = this; ("list","Some records",help_nil); newf_head ("Name\tAddress\tPhone"); waitfor (glocal.msgadd); waitfor (glocal.msgdel); waitfor (*glocal.mayend); waitfor (*glocal.ending); for (int i=0; i if (dialog_testmessage(glocal.msgadd)){ glocal.nb++; }else if (dialog_testmessage(glocal.msgdel)){ glocal.nb--; }else if (dialog_testmessage(*glocal.mayend)){ if (xconf_yesno ("Ending","A you sure you want to end",help_nil)==MENU_YES){ glocal.c->endok(); } }else if (dialog_testmessage(*glocal.ending)){ endedit(); } DIALOG dia; SSTRING txt; dia.waitfor (glocal.msgadd); dia.waitfor (glocal.msgdel); dia.waitfor (mayend); dia.waitfor (ending); dia.newf_textarea (NULL,txt,40,5); int nof = 0; while (1){ MENU_STATUS code = dia.edit ("","",help_nil,nof ,MENUBUT_CANCEL); if (code == MENU_CANCEL){ break; }else if (code == MENU_MESSAGE){ if (dialog_testmessage(ending)){ break; }else if (dialog_testmessage(mayend)){ endok(); }else if (dialog_testmessage(glocal.msgadd)){ txt.append ("One line was added\n"); dia.reload(); }else if (dialog_testmessage(glocal.msgdel)){ txt.append ("One line was deleted\n"); dia.reload(); } } } } // #Specification: sample / FRAMEWORK / quit-without-save /* This presents a typical usage of the FRAMEWORK component. It is a multi-document text editor. Each text is presented in a notebook page. (the text editor is dummy). This sample shows how to use the FRAMEWORK and how to deal with the quit-without-save issue where the FRAMEWORK asks all document if they are ready to quit or not */ static void sample_framework() { ("sample"); xconf_notice ( "This is a sample program\n" "showing the framework TLMP component\n" "Written by Jacques Gélinas\n" "jack@solucorp.qc.ca"); topmenu ("File"); menuentry (1,"Load"); menuentry (2,"Save"); menuentry (3,"Save as"); menuentry (99,"Quit"); endmenu(); topmenu ("Options"); menuentry (901,"Preferences"); endmenu(); helpmenu(); endmenu(); if (id == 99){ end(); }else if (id == 1){ newdocument (); } newbutton (1,"icon1","button1","long text button1"); newbutton (2,"icon2","button2","long text button2"); xconf_notice ("You selected the button %d",id); DIALOG dia; info.msgs.waitfor (dia); SSTRING tmp; tmp.setfrom ("This is a document"); dia.newf_textarea (NULL,tmp,60,20); int nof = 0; while (1){ MENU_STATUS code = dia.edit ("Some text","",help_nil,nof,0); if (code == MENU_MESSAGE){ if (info.msgs.is_ending()){ break; }else if (info.msgs.is_mayend()){ dia.save(); if (xconf_yesno ("Forget changes", "Quit without saving",help_nil)==MENU_YES){ endok(); } } } } frame.newdocument(); frame.loop(); } // #Specend: // #Specification: sample / FRAMEWORK / using layout /* Here is a more complex example. This time, we create our own layout. Area1 is associated with a notebook, area2 also and area3 is at the bottom and present a text field. Every time we add a document, it is added to area1 and then area2 and area1 again and so on. The letter a is appended to the text field in area3. And a message is printed on the status line. The status line clears itself 3 seconds later. */ static void sample_framework2() { PRIVATE_MESSAGE msg; int selarea; glocal.selarea = 0; ("many document areas"); layout_area1(true); layout_area2(true); layout_newline(); layout_area3(false); layout_dispolast (GUI_H_LEFT,2,GUI_V_CENTER,1); xconf_notice ( "This is a sample program\n" "showing the framework TLMP component\n" "Written by Jacques Gélinas\n" "jack@solucorp.qc.ca"); topmenu ("File"); menuentry (1,"Load"); menuentry (2,"Save"); menuentry (3,"Save as"); menuentry (99,"Quit"); endmenu(); topmenu ("Options"); menuentry (901,"Preferences"); endmenu(); helpmenu(); endmenu(); if (id == 99){ end(); }else if (id == 1){ glocal.selarea++; // We start a new document in one area or the other newdocument (NULL,(glocal.selarea & 1) ? 1 : 2); dialog_sendmessage (glocal.msg); } DIALOG dia; info.msgs.waitfor (dia); SSTRING tmp; tmp.setfrom ("This is a document"); dia.newf_textarea (NULL,tmp,40,10); int nof = 0; while (1){ MENU_STATUS code = dia.edit ("Some text","",help_nil,nof,0); if (code == MENU_MESSAGE){ if (info.msgs.is_ending()){ break; }else if (info.msgs.is_mayend()){ dia.save(); if (xconf_yesno ("Forget changes", "Quit without saving",help_nil)==MENU_YES){ endok(); } } } } DIALOG dia; SSTRING s; dia.newf_str ("Some info",s); int nof = 0; info.msgs.waitfor (dia); dia.waitfor (glocal.msg); while (true){ MENU_STATUS code = dia.edit("","",help_nil,nof,0); if (code == MENU_MESSAGE){ if (must_end(info.msgs)){ break; }else{ s.append ("a"); dia.reload(); } } } // Display a message for 3 seconds every time a new document is // loaded glocal SSTRING s; (ending); dia.newf_str (NULL,glocal.s,50); dia.set_lastreadonly(); dia.waitfor (glocal.msg); glocal.s = "A new document was loaded"; settimer (3); glocal.s = ""; frame.newdocument(NULL,1); frame.loop(); } // #Specification: sample / FRAMEWORK / framework inside framework /* Here is a more complex example. Several FRAMEWORK inside one. To make things simple, we are reusing the same FRAMEWORK 4 times. */ static void sample_framework3() { ("framework inside framework"); #if 1 layout_book(); layout_page("Page1"); layout_area1(false); layout_end(); layout_page("Page2"); layout_area2(false); layout_end(); #endif #if 0 layout_page("Page3"); layout_area3(false); layout_end(); layout_page("Page4"); layout_area4(false); layout_end(); #endif layout_end(); xconf_notice ( "This is a sample program\n" "showing frameworks inside a framework\n" "Written by Jacques Gélinas\n" "jack@solucorp.qc.ca"); topmenu ("File"); menuentry (99,"Quit"); endmenu(); helpmenu(); endmenu(); if (id == 99){ end(); } glocal int noarea = noarea; if (0){ DIALOG dia; SSTRING s; s.setfromf ("nbdoc %d area %d",info.nbdocument,noarea); dia.newf_str ("A string",s); int nof = 0; /* We tell our dialog it must wait for some messages to participate in the quit protocol. A dialog failing to do so will prevent the framework from exiting. */ info.msgs.waitfor (dia); while (1){ dia.edit ("","",help_nil,nof,0); if (must_end(info.msgs)){ break; } } }else{ (info); layout_area1(false); layout_area2(false); layout_newline(); layout_area3(false); layout_area4(false); DIALOG dia; SSTRING s; dia.newf_str ("A string",s); int nof = 0; info.msgs.waitfor (dia); while (1){ dia.edit ("","",help_nil,nof,0); /* This is where we are testing the two messages sent by the framework. One asks if we accept to end. The other tells us this is it and we MUST end. */ if (info.msgs.is_mayend()){ SSTRING tmp; tmp.setfromf ("This is sub-document %d in page %d" ,noarea,glocal.noarea); if (framework_quitok ("Quit without save",tmp.get())){ endok(); } }else if (info.msgs.is_ending()){ break; } } sub.loop(); } frame.loop(); } // #Specend: // #Specbeg: sample / FRAMEWORK / restarting documents /* This shows how a multi-document editor can resume operation from one session to the other. The trick is to use setdocumentid to record a meaningful info about the document and getdocumentids() to learn about all active document at the end of the session. We will show a simple multi document editor. Note it can't save anything to disk. */ static void sample_docid(int argc, char *argv[]) { ("restart documents"); SSTRING *name = (SSTRING*)info.data; setdocumentid (name->get()); DIALOG dia; info.msgs.waitfor (dia); glocal SSTRING tmp; (name->get(),false); glocal.tmp.append (line); dia.newf_textarea (NULL,glocal.tmp,60,20); int nof = 0; while (1){ MENU_STATUS code = dia.edit (name->get(),"",help_none,nof,0); if (code == MENU_MESSAGE){ if (info.msgs.is_ending()){ break; }else if (info.msgs.is_mayend()){ endok(); } } } delete name; if (argc == 0){ // We reload all the documents SSTRINGS tb; linuxconf_getall ("document","list",tb,false); for (int i=0; i // #Specend: int main (int argc, char *argv[]) { int ret = (argc, argv,"tlmpwork"); xconf_error(msg); xconf_notice ( "sample guilayout\n" "sample framework\n" "sample framework2\n" "sample framework3\n" "sample docids\n"); if (argc < 1){ usage(); }else if (strcmp(argv[0],"guilayout")==0){ sample_guilayout(); }else if (strcmp(argv[0],"framework")==0){ sample_framework(); }else if (strcmp(argv[0],"framework2")==0){ sample_framework2(); }else if (strcmp(argv[0],"framework3")==0){ sample_framework3(); }else if (strcmp(argv[0],"docids")==0){ sample_docid(argc-1,argv+1); } return 0; return ret; }