void MainWindow::on_actionNew_triggered() { CheckSave(); m_file_name.clear(); m_ui->txtedit->setPlainText(""); m_saved.clear(); UpdateStatusBar(); }
void MainWindow::on_actionOpen_triggered() { CheckSave(); m_saved.clear(); QString file = QFileDialog::getOpenFileName(this, "Open a file", "", "Fake (*.fk)"); if(!file.isEmpty()) { Openfile(file); } UpdateStatusBar(); }
void BookmarksManagerDialog::handleCurrentBMChanged (const QModelIndex& current, const QModelIndex& previous) { if (CheckSave (previous)) return; if (!current.isValid ()) return; QStandardItem *item = BMModel_->itemFromIndex (current); if (!item || !CurrentEditor_) return; CurrentEditor_->SetIdentifyingData (item->data ().toMap ()); }
void CFLTKEditor::Close() { if (!CheckSave()) return; if (m_iCurEditorID < 0 || m_iCurEditorID >= int(m_mEditorData.Count()) ) return; DeleteEditor(m_iCurEditorID); if (m_iCurEditorID > 0) { m_iCurEditorID--; SetCurEditor(m_iCurEditorID); } else if (m_iCurEditorID >= int(m_mEditorData.Count())) { char pcName[100]; NewEditor(); m_iCurEditorID = 0; SetCurEditor(m_iCurEditorID); GetFilename() = ""; sprintf(pcName, "Untitled %d", sm_iNewFileNo++); GetName() = pcName; GetPath() = "./"; GetTextBuffer()->select(0, GetTextBuffer()->length()); GetTextBuffer()->remove_selection(); IsFileChanged() = false; GetTextBuffer()->call_modify_callbacks(); SetTitle(); } UpdateFileList(); }
void MainWindow::closeEvent(QCloseEvent * event) { CheckSave(); event->accept(); }
void MainWindow::on_MainWindow_destroyed(QObject *arg1) { CheckSave(); }
void MainWindow::on_MainWindow_destroyed() { CheckSave(); }
void MainWindow::on_actionQuit_triggered() { CheckSave(); exit(0); }
int main() { goods *root = NULL;//pointer to the root product of the tree goods **prev; goods *product; goods *search; //pointers for freeing memory goods *delete1; goods *delete2; int value;//star location int q; for(q = 0; q < 4; q++) { //save some products in memory product = NULL; product = malloc(sizeof(struct goods)); if(product != NULL) { if(q == 0) { strcpy(product->product_name, "APPLES"); product->code = 852; product->price = 1.25; product->supply = 30; } if(q == 1) { strcpy(product->product_name, "MILK"); product->code = 123; product->price = 2; product->supply = 30; } if(q == 2) { strcpy(product->product_name, "JUICE"); product->code = 121; product->price = 2.39; product->supply = 30; } if(q == 3) { strcpy(product->product_name, "CHOCOLATE"); product->code = 567; product->price = 1.5; product->supply = 30; } product->left = NULL; product->right = NULL; prev = &root; search = root; while(search != NULL) { if(search->code < product->code) { prev = &search->right; search = search->right; } else if(search->code > product->code) { prev = &search->left; search = search->left; } } *prev = product; } else { printf("Not enough memory to start program!"); getch(); goto out; } } do { value = Menu(); //turn on cursor SetCursorType(NORMAL_CURSOR); switch(value) { case 0: EnterProd(&root); break; case 1: DeleteProd(&root); break; case 2: FindProd(&root); break; case 3: SellProd(&root); break; case 4: DisplayProd(&root); break; case 5: LoadProd(&root); break; case 6: SaveProd(&root); break; case 7: CheckSave(z, &root); break; } }while(value != 7); out:; //free allocated memory for all products with a help of recursion FreeBST(root); root = NULL; return 0; }
/****************************************************************************** * FontEditCommand(hBox, id) * * purpose: interprets menu id and calls appropriate function to do the task * * params: HWND hBox : handle to main window * WORD id : menu command id * returns: none * * side effects: plenty * *****************************************************************************/ VOID FontEditCommand( HWND hBox, WORD id ) { CHAR * szError; /* String for error messages */ LONG w; DWORD y, i, j; BOOL fRepaint = FALSE; HMENU hMenu; DLGPROC lpprocAboutDlg; MSG message; szError = ""; /* No Errors yet */ switch (id) { case FONT_EXIT: if (!CheckSave()) /* See if any files need saving */ break; /* Window's being destroyed. */ if (fLoaded) /* 4/8/87 Linsh added */ DeleteBitmap(); /* Get rid of memory DC */ PostQuitMessage(0); /* Cause application to be terminated */ break; case FONT_HELP_CONTENTS: WinHelp(hFont, gszHelpFile, HELP_CONTENTS, 0L); break; case FONT_HELP_SEARCH: /* * Tell winhelp to be sure this app's help file is current, * then invoke a search with an empty starting key. */ WinHelp(hFont, gszHelpFile, HELP_FORCEFILE, 0); WinHelp(hFont, gszHelpFile, HELP_PARTIALKEY, (DWORD)(LPSTR)""); break; case FONT_ABOUT: lpprocAboutDlg = (DLGPROC)AboutDlg; DialogBox (hInst, vszABOUT, hBox, lpprocAboutDlg); FreeProcInstance (lpprocAboutDlg); break; case FONT_LOAD: /* Check File Name */ case FONT_NEW : if (!CheckSave()) /* See if current font needs saving */ return; /* to prevent scrambling of Show window chars, Bring back Show ** window to parent window's client area before invoking the dialog */ if (CommDlgOpen(hBox,&ofstrFile,szNewFile,szExt,szFontFile,id) == FALSE) { InvalidateRect(hFont, (LPRECT)NULL, FALSE); UpdateWindow(hFont); return; } /* else drop thru */ case FONT_START: /* Here if file name passed as argument */ InvalidateRect(hFont, (LPRECT)NULL, FALSE); UpdateWindow(hFont); szError = FontLoad (szNewFile, &ofstrFile); /* Hack : needed to remove umwanted WM_MOUSEMOVE messages from the * queue. * Apparently, Windows needs to reposition the mouse after a dialog * is ended with a mouse double-click (releases mouse capture?) for * which a couple of WM_MOUSEMOVEs may get sent to parent app. * These mess with the edit box below the dialog if they happen to * overlap. */ PeekMessage((LPMSG) &message, hBox, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE); if (fLoaded) /* If loaded then do a few things */ { jChar = iChar = 65; /* Show an A */ if ((BYTE)iChar > (BYTE)font.LastChar) jChar = iChar = font.FirstChar; /* .. if we can */ swH = 15; /* Good bet to make A visible */ fEdited = fChanged = FALSE; ResizeShow(); /* Set Box to proper size */ ScrollFont(); /* Set thumb */ CharToBox(iChar); } FontRename(szError); SetFocus(hBox); return; case FONT_SAVE: if (!NewFile) { if (fLoaded && fChanged) { lstrcpy((LPSTR)szNewFile, (LPSTR)szFontFileFull); BoxToChar(iChar); /* Just in case */ szError = FontSave (szNewFile, &ofstrFile); FontRename(szError); /* Rename or Print Error */ return; } else return; } /* else file has been opened by selecting NEW... on menu. * Fall thro' and bring up SaveAs dialog minus default * filename in edit window */ case FONT_SAVEAS: BoxToChar(iChar); /* Just in case */ if (CommDlgSaveAs (hInst, hBox, &ofstrFile, szNewFile, szExt, szFontFile) == TRUE) { szError = FontSave (szNewFile, &ofstrFile); FontRename (szError); /* Rename or Print Error */ } /* to prevent scrambling of Show window chars, repaint show window after dialog is brought down */ InvalidateRect (hFont, (LPRECT)NULL, TRUE); UpdateWindow (hFont); return; case FONT_HEADER: /* to prevent scrambling of Show window chars, * repaint show window after dialog is invoked */ DialogBox(hInst, (LPSTR)vszDHeader, hBox, lpHeaderProc); InvalidateRect(hFont, (LPRECT)NULL, TRUE); UpdateWindow(hFont); return; case FONT_RESIZE: /* to prevent scrambling of Show window chars, repaint show window after dialog is brought down */ if (DialogBox(hInst, (LPSTR)vszDResize, hBox, lpReSizeProc)) { /* BoxToChar(iChar);*/ /* save current before resizing */ ResizeShow(); /* New Font Display Size */ CharToBox(iChar); /* New Box display */ } InvalidateRect(hFont, (LPRECT)NULL, TRUE); UpdateWindow(hFont); return; case FONT_COPY: /* Copy to Clipboard */ BoxToChar(iChar); /* Just in case */ ToClipboard(iChar, wBox, kBox); break; case FONT_PASTE: /* Paste in Character form Clipboard */ BoxBackup(); /* In case we change our minds */ ptA.x = ptA.y = 0; wBox = ClipboardToBox(ptA, wBox, kBox, TRUE); fRepaint = TRUE; break; case WIDER_LEFT: case WIDER_RIGHT: case WIDER_BOTH: case NARROWER_LEFT: case NARROWER_RIGHT: case NARROWER_BOTH: case WIDTH: w = newWidth = wBox; if (font.Family & 1) /* Variable width or else */ { switch (id) { case WIDER_BOTH: w++; case WIDER_LEFT: case WIDER_RIGHT: w++; break; case NARROWER_BOTH: w--; case NARROWER_LEFT: case NARROWER_RIGHT: w--; break; case WIDTH: if (DialogBox(hInst, (LPSTR)vszDWidth, hBox, lpWidthProc)) w = newWidth; break; } if (w < 0 || w >= wBoxLim) { MessageBox(hBox, (LPSTR)vszEdLimits0To64, (LPSTR)szAppName, MB_OK | MB_ICONASTERISK); break; /* Out of range! quit */ } if (w > (LONG) font.MaxWidth) { if (IDOK == MessageBox(hBox, (LPSTR)vszMaxWidthIncrease, (LPSTR)szAppName, MB_OKCANCEL | MB_ICONQUESTION)) font.MaxWidth = (WORD)w; else break; } BoxBackup(); /* In case we change our minds */ wBox = (WORD)w; /* Reset width */ fRepaint = TRUE; /* Signal redraw */ switch (id) { case WIDER_LEFT: #ifdef DBCS //DBCS_FIX DupCol(0, kBoxLim - 1); for (y = 0; y < kBoxLim; y++) matBox[0][y] = FALSE; /* Clear left column */ break; #endif case WIDER_BOTH: /* Shift character one right */ DupCol(0, kBoxLim - 1); for (y = 0; y < kBoxLim; y++) matBox[wBox -1][y] = FALSE; /* Clear right column */ for (y = 0; y < kBoxLim; y++) matBox[0][y] = FALSE; /* Clear left column */ break; case NARROWER_LEFT: case NARROWER_BOTH: /* Shift character one left */ if (wBox) { /* .. unless width is already 0 */ for (j = 0; j <= kBox - 1; j++) for (i = 0; i <= wBox - 1; i++) matBox[i][j] = matBox[i + 1][j]; break; } } } else { MessageBox(hBox, (LPSTR)vszCannotChangeWidth, (LPSTR)szAppName, MB_OK | MB_ICONASTERISK); } break; case ROW_ADD: case ROW_DEL: case COL_ADD: case COL_DEL: /* set cursor to "+" shaped cursor */ SetCapture (hBox); /* so that cursor doesn't get restored before we are done */ hOldCursor = SetCursor (LoadCursor (NULL, IDC_CROSS)); fCaptured = TRUE; cursor = id; break; case BOX_CLEAR: case BOX_FILL: case BOX_INV: case BOX_HATCH: case BOX_LEFTRIGHT: case BOX_TOPBOTTOM: case BOX_COPY: case BOX_PASTE: /* Get one o' da funky cursors */ SetCapture(hBox); hOldCursor = SetCursor(LoadCursor(hInst, MAKEINTRESOURCE(id))); fStartRubberBand = TRUE; CharRectDimensions((LPRECT)&FontRect); cursor = id; break; case BOX_REFRESH: /* Go get old version of character */ BoxBackup(); /* In case we change our minds */ CharToBox(iChar); hMenu = GetMenu(hBox); EnableMenuItem(hMenu, BOX_UNDO, MF_ENABLED); /* Can Unrefresh! */ break; case BOX_UNDO: BoxRestore(); hMenu = GetMenu(hBox); EnableMenuItem(hMenu, BOX_REFRESH, MF_ENABLED); fRepaint = TRUE; break; } if (fRepaint) { fEdited = fChanged = TRUE; InvalidateRect(hBox, (LPRECT)NULL, TRUE); } }
/****************************************************************************** * long APIENTRY FontEditWndProc(hBox, message, wParam, lParam) * * purpose: Master controller for Fontedit's all-encompassing main window * * params : same as for all window functions * * side effects: countless * *****************************************************************************/ LONG APIENTRY FontEditWndProc( HWND hBox, WORD message, WPARAM wParam, LONG lParam ) { PAINTSTRUCT ps; HMENU hMenu; WORD mf; POINT pt; RECT BoxRect; switch (message) { case WM_CLOSE: if (!CheckSave()) /* See if any files need saving */ break; /* Window's being destroyed. */ if (fLoaded) /* 4/8/87 Linsh added */ DeleteBitmap(); /* Get rid of memory DC */ DestroyWindow(hFont); DestroyWindow(hBox); break; case WM_DESTROY: PostQuitMessage(0); /* Cause application to be terminated */ break; case WM_QUERYENDSESSION: if (CheckSave()) /* See if any files need saving */ return TRUE; break; case WM_ENDSESSION: if (fLoaded) DeleteBitmap(); /* Get rid of memory DC */ break; case WM_SIZE: /* Window's size is changing. lParam contains the width ** and height, in the low and high words, respectively. ** wParam contains SIZENORMAL for "normal" size changes, ** SIZEICONIC when the window is being made iconic, and ** SIZEFULLSCREEN when the window is being made full screen. */ switch (wParam) { case SIZEFULLSCREEN: case SIZENORMAL: ResizeShow(); if (kStuff != GetkStuff()) /* Did it change ? */ ResizeShow(); /* Yes resize again */ break; } break; case WM_MOVE: /* Tell popup to move with us. */ if (!IsIconic(hBox)) ResizeShow(); break; case WM_PAINT: /* Time for the window to draw itself. */ BeginPaint(hBox, (LPPAINTSTRUCT)&ps); FontEditPaint(hBox, ps.hdc); EndPaint(hBox, (LPPAINTSTRUCT)&ps); break; case WM_COMMAND: /* A menu item has been selected, or a control is notifying * its parent. wParam is the menu item value (for menus), * or control ID (for controls). For controls, the low word * of lParam has the window handle of the control, and the hi * word has the notification code. For menus, lParam contains * 0L. */ FontEditCommand(hBox, GET_WM_COMMAND_ID(wParam, lParam)); break; /* Data interchange request. */ case WM_CUT: case WM_COPY: case WM_PASTE: case WM_CLEAR: case WM_UNDO: case WM_RENDERFORMAT: case WM_RENDERALLFORMATS: case WM_DESTROYCLIPBOARD: case WM_DRAWCLIPBOARD: break; case WM_INITMENU: hMenu = GetMenu(hBox); /* Gray menu if no clipboard bitmap */ mf = (WORD)(IsClipboardFormatAvailable(CF_BITMAP) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(hMenu, BOX_PASTE, mf); EnableMenuItem(hMenu, FONT_PASTE, mf); break; /* For each of following mouse window messages, wParam contains ** bits indicating whether or not various virtual keys are down, ** and lParam is a POINT containing the mouse coordinates. The ** keydown bits of wParam are: MK_LBUTTON (set if Left Button is ** down); MK_RBUTTON (set if Right Button is down); MK_SHIFT (set ** if Shift Key is down); MK_ALTERNATE (set if Alt Key is down); ** and MK_CONTROL (set if Control Key is down). */ case WM_LBUTTONDOWN: MPOINT2POINT(MAKEMPOINT(lParam), pt); if (fStartRubberBand) { /* a green signal to rubberband a rectangle for the * Fill menu command rectangle now has null dimensions. * Snap the current mouse point to nearest grid * intersection thus defining upper left corner of * rectangle */ if (PtInRect((LPRECT)&FontRect, pt)) { pt = SnapPointToGrid(pt); rectRubber.top = pt.y *scale+ptBox.y+1; rectRubber.bottom = (pt.y+1)*scale+ptBox.y-2; rectRubber.left = pt.x *scale+ptBox.x+1; rectRubber.right = (pt.x+1)*scale+ptBox.x-2; hDst = InitialiseRubberBandingRect(hBox); DrawRubberBand(hDst, &rectRubber, R2_XORPEN); } else { fStartRubberBand = fRubberBanding = FALSE; ReleaseCapture(); } } /* do operation depending upon current active command, * but not if we just added/deleted a row/column. */ if (!fJustZapped) { if (fStartRubberBand) { pt.x *= scale; pt.y *= scale; MouseInBox(hBox, message, pt); } else { MPOINT2POINT(MAKEMPOINT(lParam), pt); MouseInBox(hBox, message, pt); } } break; case WM_LBUTTONUP: /* Get other corner of rectangle */ fJustZapped = FALSE; if (fRubberBanding) { /* if rubberbanding for the Fill menu command, * terminate proceedings and clean up */ DrawRubberBand(hDst, &rectRubber, R2_NOT); EndRubberBandingRect(hDst); if (cursor) { ReadRect(); } } if (fCaptured ) { /* if cursor is + shaped, restore it to default */ ReleaseCapture(); SetCursor (hOldCursor); } break; case WM_RBUTTONDOWN: case WM_RBUTTONUP: break; case WM_MOUSEMOVE: /* If mouse is down */ MPOINT2POINT(MAKEMPOINT(lParam), pt); if ((fRubberBanding) && (wParam & MK_LBUTTON)) { /* if any of Fill menu commands is active ** (AND the mouse key depressed) draw a rubberband ** a rectangle with the mouse movements */ /* get current square number */ pt = SnapPointToGrid(pt); /* calculate grid for new square */ BoxRect.top = pt.y *scale+ptBox.y+1; BoxRect.bottom = (pt.y+1)*scale+ptBox.y-2; BoxRect.left = pt.x *scale+ptBox.x+1; BoxRect.right = (pt.x+1)*scale+ptBox.x-2; /* erase old mark */ DrawRubberBand(hDst, &rectRubber, R2_NOT); /* limit rubber band to box */ if (BoxRect.right > scale * (LONG)wBox + ptBox.x) BoxRect.right = scale * wBox + ptBox.x; if (BoxRect.bottom > scale * (LONG)kBox + ptBox.y) BoxRect.bottom = scale * kBox + ptBox.y; if (BoxRect.top < 0) BoxRect.top = 1; if (BoxRect.left < 0) BoxRect.left = 1; if (ptA.x == pt.x) { rectRubber.right = BoxRect.right; rectRubber.left = BoxRect.left; } if (ptA.y == pt.y) { rectRubber.bottom = BoxRect.bottom; rectRubber.top = BoxRect.top; } /* almost an IntersectRect */ if (ptA.x >= pt.x) rectRubber.left = BoxRect.left; else rectRubber.right = BoxRect.right; if (ptA.y >= pt.y) rectRubber.top = BoxRect.top; else rectRubber.bottom = BoxRect.bottom; /* Draw new mark */ DrawRubberBand(hDst, &rectRubber, R2_XORPEN); } else { /* if not "Fill"ing(AND mouse key depressed, * paint with the mouse movements */ if ((wParam & MK_LBUTTON) && cursor == FALSE && fJustZapped == FALSE) MouseInBox(hBox, message, pt); } break; case WM_LBUTTONDBLCLK: case WM_RBUTTONDBLCLK: break; default: /* Everything else comes here. This call MUST exist ** in your window proc. */ return(DefWindowProc(hBox, message, wParam, lParam)); break; } /* A window proc should always return something */ return(0L); }