static void openOK(GtkObject *object, gpointer data) { GtkFileSelection *fileselection = GTK_FILE_SELECTION(data); GtkWidget *app = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(fileselection), "app")); Context *context = (Context *) gtk_object_get_data(GTK_OBJECT(app), "context"); gchar *fileName = g_strdup(gtk_file_selection_get_filename(fileselection)); pf_flow *newPara; gtk_widget_destroy(GTK_WIDGET(fileselection)); newPara = pf_factory(fileName, font, guiSupport); if (newPara != NULL) { gchar *title = prettyTitle(fileName); GtkWidget *area = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(app), "area")); if (context->paragraph != NULL) { pf_close(context->paragraph); } context->paragraph = newPara; gtk_window_set_title(GTK_WINDOW(app), title); gtk_widget_hide(area); pf_breakLines(context->paragraph, context->width, context->height); gtk_widget_show_all(area); g_free(title); } g_free(fileName); }
/***************************************************************** 函数原型:zbClerkFileInit(void) 功能描述:操作员文件初始化 参数描述: 返回值: OK ? NOTOK 作 者: 刘及华 日 期: 2012-11-24 修改历史: 日期 修改人 修改描述 ------ --------- ------------- *****************************************************************/ char zbClerkFileInit(void) { char upd=1; uchar i; uchar ucOpenID; uchar ucRet; if (pf_exist((void *)clerkFileName, &ucOpenID)==FALSE) { ucRet = pf_creat((void *)clerkFileName, sizeof(CLERK_STRUCT)); upd=1; } else { ucRet = pf_close(ucOpenID); upd=0; } // if (ucRet!=EM_SUCCESS) // { // lcddisperr((void *)"员工名单初始化失败"); // return notok; // } memset(&clerk_list, 0, sizeof(clerk_list)); if (upd) { for (i=0; i<MAX_CLERK_NUM; i++) { clerk_list[i].id[0] = '0'; clerk_list[i].id[1] = '0'+i; // memset(clerk_list[i].id, '0'+i, 2); clerk_list[i].right = ID_OPERATOR; memset(clerk_list[i].pw,'0'+i,4); } //set the default // memset(clerk_list[9].id,'8',2); // memcpy(clerk_list[9].pw,"22446868",8); // clerk_list[9].right=ID_SUPERVISOR; ////////////////////////////////////////////////////////////////////////// // memset(clerk_list[0].id,'0',2); // memset(clerk_list[0].pw,'0',6); // clerk_list[0].right=ID_MANAGER; ////////////////////////////////////////////////////////////////////////// // strcpy((void *)&clerk_list[1].id[0], "01"); // memset(clerk_list[1].pw,'1',4); // clerk_list[1].right=ID_OPERATOR; zbClerkSaveFile(); } zbClerkReadFile(); return ok; }
/***************************************************************** 函数原型:zbClerkReadFile(void) 功能描述:操作员文件初始化 参数描述: 返回值: OK ? NOTOK 作 者: 刘及华 日 期: 2012-11-24 修改历史: 日期 修改人 修改描述 ------ --------- ------------- *****************************************************************/ char zbClerkReadFile(void) { uchar ucOpenID; uint uiRecnum; pf_open((void *)clerkFileName, &ucOpenID); pf_read(ucOpenID, 1, 1, &uiRecnum, (uchar *)clerk_list); pf_close(ucOpenID); return TRUE; }
/***************************************************************** 函数原型:zbClerkSaveFile(void) 功能描述:操作员文件初始化 参数描述: 返回值: OK ? NOTOK 作 者: 刘及华 日 期: 2012-11-24 修改历史: 日期 修改人 修改描述 ------ --------- ------------- *****************************************************************/ char zbClerkSaveFile(void) { // uchar ucret; uchar ucOpenID; pf_open((void *)clerkFileName, &ucOpenID); pf_write(ucOpenID, 0, (uchar *)clerk_list); pf_close(ucOpenID); return TRUE; }
void closeSample(GtkWidget *app) { Context *context = (Context *) gtk_object_get_data(GTK_OBJECT(app), "context"); if (context->paragraph != NULL) { pf_close(context->paragraph); } DELETE_ARRAY(context); appList = g_slist_remove(appList, app); gtk_widget_destroy(app); if (appList == NULL) { gtk_main_quit(); } }
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; Context *context; static le_int32 windowCount = 0; static fm_fontMap *fontMap = NULL; static rs_surface *surface = NULL; static gs_guiSupport *guiSupport = NULL; static le_font *font = NULL; switch (message) { case WM_CREATE: { LEErrorCode fontStatus = LE_NO_ERROR; hdc = GetDC(hwnd); guiSupport = gs_gdiGuiSupportOpen(); surface = rs_gdiRenderingSurfaceOpen(hdc); fontMap = fm_gdiFontMapOpen(surface, "FontMap.GDI", 24, guiSupport, &fontStatus); font = le_scriptCompositeFontOpen(fontMap); if (LE_FAILURE(fontStatus)) { ReleaseDC(hwnd, hdc); return -1; } context = NEW_ARRAY(Context, 1); context->width = 600; context->height = 400; context->paragraph = pf_factory("Sample.txt", font, guiSupport); SetWindowLongPtr(hwnd, 0, (LONG_PTR) context); windowCount += 1; ReleaseDC(hwnd, hdc); PrettyTitle(hwnd, "Sample.txt"); return 0; } case WM_SIZE: { context = (Context *) GetWindowLongPtr(hwnd, 0); context->width = LOWORD(lParam); context->height = HIWORD(lParam); InitParagraph(hwnd, context); return 0; } case WM_VSCROLL: { SCROLLINFO si; le_int32 vertPos; si.cbSize = sizeof si; si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_VERT, &si); vertPos = si.nPos; switch (LOWORD(wParam)) { case SB_TOP: si.nPos = si.nMin; break; case SB_BOTTOM: si.nPos = si.nMax; break; case SB_LINEUP: si.nPos -= 1; break; case SB_LINEDOWN: si.nPos += 1; break; case SB_PAGEUP: si.nPos -= si.nPage; break; case SB_PAGEDOWN: si.nPos += si.nPage; break; case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; default: break; } si.fMask = SIF_POS; SetScrollInfo(hwnd, SB_VERT, &si, TRUE); GetScrollInfo(hwnd, SB_VERT, &si); context = (Context *) GetWindowLongPtr(hwnd, 0); if (context->paragraph != NULL && si.nPos != vertPos) { ScrollWindow(hwnd, 0, pf_getLineHeight(context->paragraph) * (vertPos - si.nPos), NULL, NULL); UpdateWindow(hwnd); } return 0; } case WM_PAINT: { PAINTSTRUCT ps; SCROLLINFO si; le_int32 firstLine, lastLine; hdc = BeginPaint(hwnd, &ps); SetBkMode(hdc, TRANSPARENT); si.cbSize = sizeof si; si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_VERT, &si); firstLine = si.nPos; context = (Context *) GetWindowLongPtr(hwnd, 0); if (context->paragraph != NULL) { rs_gdiRenderingSurfaceSetHDC(surface, hdc); // NOTE: si.nPos + si.nPage may include a partial line at the bottom // of the window. We need this because scrolling assumes that the // partial line has been painted. lastLine = min (si.nPos + (le_int32) si.nPage, pf_getLineCount(context->paragraph) - 1); pf_draw(context->paragraph, surface, firstLine, lastLine); } EndPaint(hwnd, &ps); return 0; } case WM_COMMAND: switch (LOWORD(wParam)) { case IDM_FILE_OPEN: { OPENFILENAMEA ofn; char szFileName[MAX_PATH], szTitleName[MAX_PATH]; static char szFilter[] = "Text Files (.txt)\0*.txt\0" "All Files (*.*)\0*.*\0\0"; ofn.lStructSize = sizeof (OPENFILENAMEA); ofn.hwndOwner = hwnd; ofn.hInstance = NULL; ofn.lpstrFilter = szFilter; ofn.lpstrCustomFilter = NULL; ofn.nMaxCustFilter = 0; ofn.nFilterIndex = 0; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.lpstrFileTitle = szTitleName; ofn.nMaxFileTitle = MAX_PATH; ofn.lpstrInitialDir = NULL; ofn.lpstrTitle = NULL; ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST; ofn.nFileOffset = 0; ofn.nFileExtension = 0; ofn.lpstrDefExt = "txt"; ofn.lCustData = 0L; ofn.lpfnHook = NULL; ofn.lpTemplateName = NULL; szFileName[0] = '\0'; if (GetOpenFileNameA(&ofn)) { pf_flow *newParagraph; hdc = GetDC(hwnd); rs_gdiRenderingSurfaceSetHDC(surface, hdc); newParagraph = pf_factory(szFileName, font, guiSupport); if (newParagraph != NULL) { context = (Context *) GetWindowLongPtr(hwnd, 0); if (context->paragraph != NULL) { pf_close(context->paragraph); } context->paragraph = newParagraph; InitParagraph(hwnd, context); PrettyTitle(hwnd, szTitleName); InvalidateRect(hwnd, NULL, TRUE); } } //ReleaseDC(hwnd, hdc); return 0; } case IDM_FILE_EXIT: case IDM_FILE_CLOSE: SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; case IDM_HELP_ABOUTLAYOUTSAMPLE: MessageBox(hwnd, TEXT("Windows Layout Sample 0.1\n") TEXT("Copyright (C) 2016 and later: Unicode, Inc. and others. License & terms of use: http://www.unicode.org/copyright.html\n") TEXT("Author: Eric Mader"), szAppName, MB_ICONINFORMATION | MB_OK); return 0; } break; case WM_DESTROY: { context = (Context *) GetWindowLongPtr(hwnd, 0); if (context != NULL && context->paragraph != NULL) { pf_close(context->paragraph); } DELETE_ARRAY(context); if (--windowCount <= 0) { le_fontClose(font); rs_gdiRenderingSurfaceClose(surface); gs_gdiGuiSupportClose(guiSupport); PostQuitMessage(0); } return 0; } default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; }
void TCredits::Init(TWindowStyle& style) { TWindow::Init(style); mCreditsTime = style.GetInt("time"); mCreditsIntroPause = style.GetInt("intropause"); mColumnGap = style.GetInt("columngap"); mColumnWidth = style.GetInt("columnwidth"); ASSERT(mColumnWidth); ASSERT(mColumnGap); ASSERT(mCreditsTime); mFont = style.GetString( "font",""); mFontSize = (int)style.GetNumber( "fontsize", 16 ); mFontColor = style.GetColor( "fontcolor", white); TColor headerColor = style.GetColor( "headercolor", white); mHeaderColorHex.format("%02x%02x%02x%02x", (int)(headerColor.r * 255), (int)(headerColor.g * 255), (int)(headerColor.b * 255), (int)(headerColor.a * 255)); mCreditsFile = style.GetString("file",""); TFile* fp = pf_open(mCreditsFile.c_str(), kReadText); str col1="\n"; str col2="\n"; str col3="\n"; const int kSize= 1024; char buffer[kSize]; while (pf_gets(fp, buffer, kSize)) { buffer[strlen(buffer)-1]=0; char* sep = strchr(buffer, '|'); if (sep) { *sep= 0; sep++; col1 += CreditLine(buffer, mHeaderColorHex); col2 += CreditLine(sep, mHeaderColorHex); col3 += str("\n"); } else { col1 += str("\n"); col2 += str("\n"); col3 += CreditLine(buffer, mHeaderColorHex); } } pf_close(fp); int space = GetWindowHeight(); for (uint32_t i=0; i<space / mFontSize; i++) { col1 += "\n"; col2 += "\n"; col3 += "\n"; } mText1 = TTextGraphic::Create(col1+col1, mColumnWidth, space, TText::kHAlignCenter, mFont.c_str(), mFontSize, mFontColor); mText2 = TTextGraphic::Create(col2+col2, mColumnWidth, space, TText::kHAlignCenter, mFont.c_str(), mFontSize, mFontColor); mText3 = TTextGraphic::Create(col3+col3, mColumnWidth*2+mColumnGap, space, TText::kHAlignCenter, mFont.c_str(), mFontSize, mFontColor); TRect bounds; mText1->GetTextBounds(&bounds); mHeight = bounds.mY2/2; mStart = 0; StartWindowAnimation(16); }