📄 icon.c
字号:
/* -*-Mode:C; tab-width:4; indent-tabs-mode:t; c-file-style:"stroustrup";-*- *///// Project : progect// Desc. : Icon support code.// $Id: icon.c,v 1.12 2003/12/04 04:38:16 rick_price Exp $//#include "progect.h"#include "xb.h"#include "task.h"#include "icon.h"#include "MemoDB.h"#include "progectRsc.h"UInt8 numIconLoaded = 0;IconType loadedIcon[MAX_ICONS];/**************************************************************************** * Name : initializeIcon * Desc : initialize and load icon * Parm : * Out : * Auth : seagull, 23.09.2000 JST ***************************************************************************/void initializeIcon(void){ DmOpenRef memodb; if (! MemoGetDatabase(&memodb, dmModeReadOnly)) { UInt16 i; UInt16 numRec = DmNumRecords(memodb); for (i = 0; i < numRec; i++) { MemHandle h; MemoDBRecordType *rcd; UInt16 attr; // get the memo's attr DmRecordInfo(memodb, i, &attr, NULL, NULL); // if it's not deleted if (attr & dmRecAttrDelete) continue; h = DmQueryRecord(memodb, i); if (!h) continue; rcd = MemHandleLock(h); if ((! StrNCompare(&rcd->note, "DATEBK3\n", 8)) || (! StrNCompare(&rcd->note, "ALTDATEBK3\n", 8))) { UInt8* p = &rcd->note + 8; while (*p) { UInt16 n; if (*p != '#') { // skip invalid line while (*p && *p != '\n') p++; if (! *p) break; p++; continue; } // copy and skip description // NOTE: 1st char is shortcut. p++; loadedIcon[numIconLoaded].shortcut = *p++; for (n = 0; *p && *p != '\n' && *p != '=' && n < 31; n++) loadedIcon[numIconLoaded].desc[n] = *p++; loadedIcon[numIconLoaded].desc[n] = '\0'; if (*p == '=') { // copy image p++; for (n = 0; n < 8; n++) { UInt8 bits; // load higher 4 bits if (*p >= '0' && *p <= '9') bits = *p - '0'; else if (*p >= 'a' && *p <= 'f') bits = *p - 'a' + 10; else if (*p >= 'A' && *p <= 'F') bits = *p - 'A' + 10; else break; // found invalid character p++; // load lower 4 bits bits <<= 4; if (*p >= '0' && *p <= '9') bits += *p - '0'; else if (*p >= 'a' && *p <= 'f') bits += *p - 'a' + 10; else if (*p >= 'A' && *p <= 'F') bits += *p - 'A' + 10; else break; // found invalid character p++; loadedIcon[numIconLoaded].image[n] = bits; } if (n == 8) // all succeded { if (++numIconLoaded >= MAX_ICONS) break; } } while (*p && *p != '\n') // skip junk p++; if (*p == '\n') p++; } MemHandleUnlock(h); break; } MemHandleUnlock(h); } DmCloseDatabase(memodb); }} // void initializeIcon(void)/**************************************************************************** * Name : DrawIcon * Desc : Draw an icon image * Parm : * -> icon id * -> x, y * Out : * Auth : seagull, 25.09.2000 JST ***************************************************************************/void drawIcon(UInt8 id, int x, int y){ if (id >= getNumIconsLoaded()) return ; // currently MONO image only. if (OSCaps.ver35) { UInt16 err; UInt8 n; BitmapType* bmp = BmpCreate(getIconWidth(id), getIconHeight(id), getIconColorDepth(id), NULL, &err); UInt16* dstbits = BmpGetBits(bmp); UInt8* srcbits = getIconImage(id); for (n = 0; n < getIconDataLength(id); n++) *(dstbits++) = *(srcbits++) << 8; WinDrawBitmap(bmp, x, y); BmpDelete(bmp); } else { UInt8 *srcbits = getIconImage(id); RectangleType pixel; UInt8 n, i; for (n = 0; n < 8; n++) { for (i = 0; i < 8; i++) { if (srcbits[n] & 1 << (7 - i)) { RctSetRectangle(&pixel, x + i, y + n, 1, 1); WinDrawRectangle(&pixel, 0); } } } }} // void DrawIcon(UInt8 id, int x, int y)/**************************************************************************** ** Icon select dialog functions ****************************************************************************//**************************************************************************** * Name : onDrawIconColumn * Desc : Custom draw procedure for icon select table * Parm : all parameters is pass from PalmOS * -> table object * -> row, column * -> clipping rect * Out : * Auth : seagull, 23.09.2000 JST ***************************************************************************/static void onDrawIconColumn(void *tableP, Int16 row, Int16 column, RectangleType *bounds){ UInt16 id = TblGetItemInt(tableP, row, column); if (id >= getNumIconsLoaded()) return ; // erase the row if (!OSCaps.ver35) { WinEraseRectangle(bounds, 0); } drawIcon(id, bounds->topLeft.x, bounds->topLeft.y); FntSetFont(stdFont); DrawTruncText(getIconDesc(id), bounds->topLeft.x + getIconWidth(id) + 1, bounds->topLeft.y, bounds->extent.x - getIconWidth(id) - 1);}/**************************************************************************** * Name : UpdateIconTable * Desc : update icon select table * Parm : * -> top visible row * Out : * Auth : seagull, 24.09.2000 JST ***************************************************************************/static void UpdateIconTable(UInt16 toprow){ TablePtr table = GetObjectPtr(IconSelectTable); int i; int item = toprow * 2; int rows = TblGetNumberOfRows(table); for (i = 0; i < rows; i++) { TblSetItemInt(table, i, 0, item++); TblSetItemStyle(table, i, 0, customTableItem); TblSetItemInt(table, i, 1, item++); TblSetItemStyle(table, i, 1, customTableItem); TblSetRowSelectable(table, i, true); } TblSetColumnUsable(table, 0, true); TblSetColumnUsable(table, 1, true); TblSetCustomDrawProcedure(table, 0, onDrawIconColumn); TblSetCustomDrawProcedure(table, 1, onDrawIconColumn); TblHasScrollBar(table, true); SclSetScrollBar(GetObjectPtr(Scr_SelectIcon), toprow, 0, (getNumIconsLoaded() + 1) / 2 - 11, rows); TblDrawTable(table); SclDrawScrollBar(GetObjectPtr(Scr_SelectIcon) ); TblUnhighlightSelection(table);}/**************************************************************************** * Name : FrmIconSelectHandleEvent * Desc : event hander for icon select dialog * Parm : * -> event object * Out : * Auth : seagull, 23.09.2000 JST ***************************************************************************/Boolean FrmIconSelectHandleEvent (EventPtr e){ FormPtr frm; TablePtr table; frm = FrmGetActiveForm(); table = GetObjectPtr(IconSelectTable); switch (e->eType) { case frmOpenEvent: FrmDrawForm(frm); UpdateIconTable(0); return true; case sclRepeatEvent: UpdateIconTable(e->data.sclRepeat.newValue); return true; case ctlSelectEvent: switch (e->data.ctlSelect.controlID) { case Btn_Remove: TaskRemoveExtraChunk(gdbP, gActualTask, Extra_Icon, 0); default: break; case Btn_Ok: { Int16 row, col; UInt16 iconid; if (TblGetSelection(table, &row, &col) ) { iconid = TblGetItemInt(table, row, col); TaskSetExtraChunk(gdbP, gActualTask, Extra_Icon, 0, &iconid, sizeof(iconid)); } } } FrmUpdateForm(FrmTaskEdit, frmTaskEditReturnFromIconSelect); FrmReturnToForm(0); return true; case tblSelectEvent: if (TblGetItemInt(e->data.tblSelect.pTable, e->data.tblSelect.row, e->data.tblSelect.column) >= getNumIconsLoaded()) { TblUnhighlightSelection(e->data.tblSelect.pTable); return true; } break; case keyDownEvent: if (e->data.keyDown.chr == vchrPageDown || e->data.keyDown.chr == vchrPageUp) { ScrollBarPtr scrl = GetObjectPtr(Scr_SelectIcon); Int16 curr, min, max, page, newpos; SclGetScrollBar(scrl, &curr, &min, &max, &page); newpos = (e->data.keyDown.chr == vchrPageDown)? (curr + page) : (curr - page); if (newpos < min) newpos = min; if (newpos > max) newpos = max; if (newpos != curr) UpdateIconTable(newpos); } default: break; } return false;} // static Boolean FrmMainHandleEvent (EventPtr e)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -