260 likes | 361 Views
Introduction to Systems Programming (CS 0449). User Interface Elements (UIE) - Resources Palm OS resources ( Ch.4—PDA Programming in C Book & Ch.6,7 PalmOS Bible Book ). Forms Alerts Menus Tables Lists Pop-up Triggers Buttons Repeating Buttons Selector Triggers Push Buttons.
E N D
Introduction to Systems Programming(CS 0449) User Interface Elements (UIE) - Resources Palm OS resources (Ch.4—PDA Programming in C Book & Ch.6,7 PalmOS Bible Book)
Forms Alerts Menus Tables Lists Pop-up Triggers Buttons Repeating Buttons Selector Triggers Push Buttons Check Boxes Slides Labels Form Bitmaps Fields Graffiti Shift Indicator Scroll Bars Gadgets Palm OS Resources-User Interface Elements
Palm Resources (User Interface Elements) • Push buttons • Check boxes • Sliders, scrollbars • LabelsLook Up: • Form bitmaps • TextFields • Forms • Alerts • Menus • Tables • Lists/Popup • Buttons
Resource Files //This is a file used by PilRC to create a .prc file. #include "helloRsc.h" APPLICATIONICONNAME ID 100 "Hello 1" APPLICATION ID 1 "49p1" VERSION ID 1 "1.0.0g" ICONFAMILY "largeicon_1bpp.bmp" "largeicon_2bpp.bmp" "" "largeicon_8bpp.bmp" TRANSPARENT 0 255 0 SMALLICONFAMILY "smallicon_1bpp.bmp" "smallicon_2bpp.bmp" "" "smallicon_8bpp.bmp" TRANSPARENT 0 255 0
Resource Files (2) // Here we define the form that we need for our program. FORMIDMainForm AT (0 0 160 160) //more details next USABLE BEGIN TITLE "Hello World" END ALERTIDByeAlert //more details after next INFORMATION BEGIN TITLE "Hello World Alert" MESSAGE "Goodbye, my friend !" BUTTONS "OK" END
Resource Files (3) BITMAP ID MyBitmap "picture.bmp" COMPRESS FORMIDMainForm AT (0 0 160 160) USABLE BEGIN TITLE "Hello World“ TABLE IDMainTableAT (0 16 160 121) ROWS 11COLUMNS 9COLUMNWIDTHS 12 25 12 18 12 33 17 20 9 LABEL "Enter your name here:" AUTOID AT (0 17) FONT 1 FIELD ID MyFieldName AT (PrevLeft PrevBottom 159 13) UNDERLINED AUTOSHIFT MAXCHARS 40 BUTTON "Hello" ID MyButtonHi AT (1 147 AUTO AUTO) BUTTON "Bye" ID MyButtonBye AT (PrevRight+5 PrevTop AUTO AUTO) FORMBITMAP AT (7 19) BITMAP MyBitmap END
Programming User Interface Elements - ALERT Programming Alerts An Alert resource dialog box could be either 1.Information. (i) 2.Confirmation. (?) 3.Warning. (!) 4.Error. (x) ALERTIDHelloAlert INFORMATION BEGIN TITLE “Hello World” (i) MESSAGE “Good Day To you, My Friend, ^1 !” BUTTONS “OK” END // ^1 resource ID –first arg in FrmCustomAlert(HelloAlert, “yourname”) ALERT IDDeleteAlert CONFIRMATION BEGIN TITLE “Please Confirm deletion” (?) MESSAGE “About to delete ^1 records from ^2 category!” “Proceed?” BUTTONS “OK” “Cancel” END // ^2 –2nd arg in FrmCustomAlert(DeleteAlert,”5”, business”, NULL) FrmAlert ( ) is equivalent to FrmCustonAlert(AlertID, NULL, NULL, NULL) –does not take ^1, ^2, ^3 To include ^`, ^2, ^3, then use FrmCustomALert
Programming User Interface Elements - ALERT ALERTIDWarningAlert WARNING BEGIN TITLE “Warning Alert Dialog Box” (!) MESSAGE “Are you sure you want to delete, ^1 !” BUTTONS “Yes” “NO” END // ^1 resource ID –first arg in FrmCustomAlert(WarningAlert) ALERT IDErrorAlert ERROR BEGIN TITLE ”Password Dialog Box” (x) MESSAGE “Incorrect Password” BUTTONS “OK” END
Creating Resources – Adding Objects to a Form Resource • BUTTONS: BUTTON “label” ID resourceID AT (Left Top Width Height) AT Positions:AUTO, CENTER, CENTER@<number>, RIGHT@<number>, BOTTOM@<number>, PREVLEFT, PREVRIGHT, PREVTOP, PREVBOTTOM, PREVWIDTH,PREVHEIGHT. 2) PUSHBUTTONS: PUSHBUTTON “HEX” ID Hex GROUP 1 PUSHBUTTON “DEC” ID Dec GROUP 1 3) CHECKBOXES: CHECKBOX“label” ID resourceID AT(Left Top Width Height)
Creating Resources – Adding Objects to a Form Resource 4) Fields: FIELD “label” ID resourceID AT (Left Top Width Height) [ USABLE | NONUSABLE ] [LEFTALIGN | RIGHTALIGN] [ FONT fontnumber ] [EDITABLE | NONEDITABLE] [ UNDERLINED] [ SINGLELINE | MULTIPLELINES] [DYNAMICSIZE] MAXCHARSmaxChars [ AUTOSHIFT ] [NUMERIC] [HASSCROLLBAR] [DYNAMICSIZE]– causes field to out fldheightChangedEvent onto the queue whenever user input causes field to scroll. [ AUTOSHIFT ]– tells system to perform graffiti auto shifting in the field. [HASSCROLLBAR] – update scrollbar constantly.
Creating Resources – Adding Objects to a Form Resource • BUTTONS: BUTTON “label” ID resourceID AT (Left Top Width Height) AT Positions: AUTO, CENTER, CENTER@<number>, RIGHT@<number>, BOTTOM@<number>, PREVLEFT, PREVRIGHT, PREVTOP, PREVBOTTOM, PREVWIDTH,PREVHEIGHT. 2) PUSHBUTTONS: PUSHBUTTON “HEX” ID Hex GROUP 1 PUSHBUTTON “DEC” ID Dec GROUP 1 3) CHECKBOXES: HEXDEC CHECKBOX“label” ID resourceID AT(Left Top Width Height) • BUTTONS: BUTTON “label” ID resourceID AT (Left Top Width Height) AT Positions: AUTO, CENTER, CENTER@<number>, RIGHT@<number>, BOTTOM@<number>, PREVLEFT, PREVRIGHT, PREVTOP, PREVBOTTOM, PREVWIDTH,PREVHEIGHT. 2) PUSHBUTTONS: PUSHBUTTON “HEX” ID Hex GROUP 1 PUSHBUTTON “DEC” ID Dec GROUP 1 3) CHECKBOXES: HEXDEC CHECKBOX“label” ID resourceID AT(Left Top Width Height) HEX DEC
Creating Resources – Adding Objects to a Form Resource 4) Text Fields: Enter your name: ______________ FIELD “label” ID resourceID AT (Left Top Width Height) [ USABLE | NONUSABLE ] [LEFTALIGN | RIGHTALIGN] [ FONT fontnumber ] [EDITABLE | NONEDITABLE] [ UNDERLINED] [ SINGLELINE | MULTIPLELINES] [DYNAMICSIZE] MAXCHARSmaxChars [ AUTOSHIFT ] [NUMERIC] [HASSCROLLBAR] [DYNAMICSIZE]– causes field to out fldheightChangedEvent onto the queue whenever user input causes field to scroll. [ AUTOSHIFT ]– tells system to perform graffiti auto shifting in the field. [HASSCROLLBAR] – update scrollbar constantly.
Programming User Interface Elements – Forms FORM ID MainForm AT (0 0 160 160) USABLE | MODAL BEGIN TITLE "CS 0449 Calculator“ FIELD ID InputFld AT(14 20 130 24) FONT 0 UNDERLINED SINGLELINE MAXCHARS 8 BUTTON "1" ID One BUTTON "F" ID HexF PUSHBUTTON “HEX” ID Hex GROUP 1 PUSHBUTTON “DEC” ID Dec GROUP 1 BUTTON "Exit" ID Exit END
Programming User Interface Elements - Forms Programming Forms 1-Switch to a new form: Erase current form and display a new one (Full-SCREEN, VIEWS-Modeless, or USABLE) 2-Display a modal dialog box: A quick prompt for user input. i.e. delete confirmation dialog box (POP-UP, MODAL-DIALOGS) - MODAL: forms and windows ignore taps outside them. User must finish the dialog and exit the form. FORM ID MainForm AT (0 0 160 160) USABLE BEGIN TITLE "CS 0449 Calculator“ FIELD ID InputFld AT(14 20 130 24) FONT 0 UNDERLINED SINGLELINE MAXCHARS 8 BUTTON "1" ID One BUTTON "F" ID HexF PUSHBUTTON “HEX” ID Hex GROUP 1 PUSHBUTTON “DEC” ID Dec GROUP 1 BUTTON "Exit" ID Exit END FORM ID MainForm AT (0 0 160 160) MODAL DEFAULTBTNID MyDeleteButtonID BEGIN TITLE “Delete Book“ LABEL “Delete Selected Book Record?” BUTTON “OK" ID DeleteBookOK BUTTON “Cancel” ID DeleteBookCancel END
Programming User Interface Elements - Forms • Programming Forms • 1-Switch to a new form:Erase current form and display a new one. • 2-Display a modal dialog box:A quick prompt for user input, • i.e. delete confirmation dialog box. • To switch forms call: • FrmGotoForm( MyOtherFormID ) • What happens in OS? • frmColseEvent is sent to the current form • FrmHandleEvent()takes care of this event • frmLoadEvent is sent toMyOtherForm • from yourAppHandleEvent() call: • FrmInitForm() • FrmSetActiveForm() • FrmSetEventHandler() • FrmOpenEvent -- respond by callingFrmDrawForm()
Event Driven Architecture PalmMain() Events AppEventLoop() • FrmDispatchEvent() • frmColseEvent • FrmHandleEvent() AppHandleEvent() • frmLoadEvent • FrmInitForm() • FrmSetActiveForm() • FrmSetEventHandler() MainFormHandleEvent() frmOpenEvent FrmDrawForm()
Hiding and Showing Form Objects (page 270 – Palm OS Bible) // Hides MyButtonID when MyHideBushbuttonID tapped // ... in your FormHandleEvent() ... and Handling Control Groups (pp.273) on pushbuttons and check boxes. if( event -> eType == ctlSelectEvent ) { switch ( event . data . ctlSelect . controlID ) { //see what button is tapped case MyHidePushButtonID : form = GetActiveForm( ); //get active form buttonIndex =FrmGetObjectIndex( form, MyButton); ctl = GetObjectPtr (MyHidePushButtonID); if( CtlGetValue ( ctl ) ) FrmHideObject( form, buttonIndex ); //Hide Pushbutton else FrmShowObject( form, buttonIndex ); //Show Pushbutton break; case MyButton : . . .//do something when user taps MyButton } Related Slides for CsCalProject
Adding TABLE to Form // ...in the resource file, add to the form definition FORM ID MainForm AT (0 0 160 160) USABLE BEGIN TITLE “Tables“ TABLE IDMainTableAT (0 16 160 121) ROWS 11COLUMNS 9COLUMNWIDTHS 12 25 12 18 12 33 17 20 9 BUTTON “HideRows” ID MainHideRowsButton AT(1 147 50 12) BUTTON “HideColumns” ID MainHideColumnsButton AT(56 147 64 12) LIST “X” “Y” “Z” ID MainList AT(120 141 19 33) NONUSABLE VISIBLEITEMS 3 . . . END
TABLE Item Types(ref: table page 397) typedef struct{ //inTable.h TableItemStyleType itemType; FontID fontID; Int16 intValue; Char *ptr; } TableItemType; Item Type Editable by User TableItemType Fields Used by This type checkboxTableItem Yes intValue customTableItem Yes None, although you may store data in the intValue and ptr fields if required by yourapplication dataTableItem No intValue labelTableItem No ptr numericTableItem No intValue popupTriggerTableItem Yes intValue, ptr textTableItem Yes fontID, ptr textWithNoteTableItem Yes fontID, ptr narrowTextTableItem Yes fontID, intValue, ptr
PalmOS Table Functions: Set/Retrieve Values TblSetItemStyle(params) -- Set value of the table item’s itemType field Given a pointer to the table, the row and column of the item to set, and the type desired. params= (ptr to table, row of cell to set, column of cell to set, TableItemStyleType value) TblSetItemFont( ) -- Set fontID for a table item. TblSetItemInt( ) -- Set the intValue. TblSetItemPtr( ) -- Set the ptr field. TblGetItemFont( ) – Retrieve the fontID for a table item. TblGetItemInt( ) – Retrieve the intValue. TblGetItemPtr( ) -- Retrieve the ptr field. Given a pointer to the table, the row & column of the desired table item.
Initializing a Table -Usually,initializing the table is when handling the form’s frmOpenEvent -In the given table sample code, -MainFormHandleEventinitializes the form in the MainFormInit static Boolean MainFormHandleEvent(EventPtr event) { Boolean handled = false; FormPtr form; switch (event->eType) { case frmOpenEvent: form = FrmGetActiveForm(); MainFormInit(form); FrmDrawForm(form); handled = true; //other event handling omitted default: break; } return handled; } Click to seeMainFormInit()function Table sample codes: Table.cMainFormInit() MainFormHandleEvent
Initializing a Table Array in StartApplication // allocate new memory handle for each array element and filling the handle’s contents with single training null. static Err StartApplication(void) { Int16 i, j; for (i = 0; i < numTextColumns; i++) { //num of columns for (j = 0; j < numTableRows; j++) { //num of rows Char *str; gTextHandles[i][j] = MemHandleNew(1); str = MemHandleLock(gTextHandles[i][j]); *str = '\0'; MemHandleUnlock(gTextHandles[i][j]); } } return false; }
Creating Menu Resourcepg 244, PalmOS Bible MENU ID MyMenuID BEGIN PULLDOWN "Edit" BEGIN MENUITEM "Copy" ID MyMenuCopyID "C" MENUITEM "Paste" ID MyMenuPasteID "P" END PULLDOWN "Help" BEGIN MENUITEM "Help" ID MyMenuHelpID "H" MENUITEM SEPARATOR MENUITEM "About" ID MyMenuAboutID "A" END END
Adding Menu to Form // ...in the resource file, add to the form definition FORM ID MainForm AT (0 0 160 160) MENUID MyMenuID USABLE BEGIN TITLE "CsCalc by Leo" . . . END
Programming Menuspg 296, PalmOS Bible // ... in your FormHandleEvent() if( event -> eType == menuEvent ) { switch ( event . data . menu . itemID ) { case MyMenuCopyID : // Do your copy business break; case MyMenuPasteID : // Do your paste business break; . . . } }
Using Standard Edit Menu • Sometimes we can use resources that are built in Palm OS, such as Edit menu • We still have to define the menu resource, using the correct IDs • We do not need to write code, it is built in PalmOS • Details in PalmOS Bible, pg 247.